Virtual U.org
Get Personal Training on VU Today
    
Top shadow
 
 register/help
User Name:

Password:

OWORLD_M.CPP Source File
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

OWORLD_M.CPP

Go to the documentation of this file.
00001 //Filename   : OWORLD_M.CPP
00002 //Description: MapMatrix class
00003 
00004 #include <OVGA.H>
00005 #include <OSYS.H>
00006 #include <OMOUSE.H>
00007 #include <OWORLD.H>
00008 
00009 //------------ Begin of function MapMatrix::draw_all ---------------//
00010 
00011 void MapMatrix::draw_all() {
00012     Matrix::draw_all();
00013 
00014     draw_zoom_box(1);                               // 1-use vga_back
00015 }
00016 
00017 //------------ End of function MapMatrix::draw_all ---------------//
00018 
00019 //------------ Begin of function MapMatrix::draw_update ---------------//
00020 
00021 void MapMatrix::draw_update() {
00022 }
00023 
00024 //-------------- End of function MapMatrix::draw_update --------------//
00025 
00026 //------------ Begin of function MapMatrix::draw_zoom_box ---------------//
00027 
00028 void MapMatrix::draw_zoom_box(int useVgaBack) {
00029     static short colorIndex = 0;
00030     static short colorAdd = 1;
00031 
00032     int boxX1, boxY1, boxX2, boxY2;
00033 
00034     loc_to_abs_center_left( boxX1, boxY1, world.active_zoom_matrix->top_x_loc,
00035                             world.active_zoom_matrix->top_y_loc );
00036 
00037     boxX1 = boxX1 - abs_top_x + MAP_X1;
00038     boxY1 = boxY1 - abs_top_y + MAP_Y1;
00039 
00040     boxX2 = boxX1 + (ZOOM_WIDTH  * loc_width  / world.active_zoom_matrix->loc_width) - 1;
00041     boxY2 = boxY1 + (ZOOM_HEIGHT * loc_height / world.active_zoom_matrix->loc_height) - 1;
00042 
00043     //-----------------------------------------//
00044 
00045     colorIndex += colorAdd;
00046 
00047     if( colorIndex >= 6 )
00048         colorAdd = -1;
00049 
00050     else if( colorIndex <= 0 )
00051         colorAdd = 1;
00052 
00053     colorIndex=0;                                   //BUGHERE
00054 
00055     if( useVgaBack )
00056         vga_back.rect( boxX1, boxY1, boxX2, boxY2, 2, V_ORANGE+colorIndex);
00057     else
00058         vga_front.rect( boxX1, boxY1, boxX2, boxY2, 2, V_ORANGE+colorIndex);
00059 }
00060 
00061 //-------------- End of function MapMatrix::draw_zoom_box --------------//
00062 
00063 //------------ Begin of function MapMatrix::detect ---------------//
00064 
00065 int MapMatrix::detect() {
00066     //--- if press left button, select zoom area ----//
00067 
00068     enum {                                          // effective when click on an outter area of the box
00069         EFFECTIVE_BORDER = 15
00070     };
00071 
00072     if(mouse.single_click(win_x1-EFFECTIVE_BORDER,win_y1-EFFECTIVE_BORDER,win_x2+EFFECTIVE_BORDER,win_y2+EFFECTIVE_BORDER, LEFT_BUTTON)) {
00073         /*
00074           int clickX = max(mouse.cur_x, win_x1);
00075           clickX = min(mouse.cur_x, win_x2);
00076           int clickY = max(mouse.cur_y, win_y1);
00077           clickY = min(mouse.cur_y, win_y2);
00078           //---- if the click position results in a zoom window that goes beyond the map, reposition it ----//
00079           int zoomFrameWidth  = (ZOOM_WIDTH * loc_width / world.active_zoom_matrix->loc_width);
00080           int zoomFrameHeight = (ZOOM_HEIGHT * loc_height / world.active_zoom_matrix->loc_height);
00081           if( clickX + zoomFrameWidth - 1 > win_x2 )
00082           clickX = win_x2 - zoomFrameWidth + 1;
00083           if( clickY + zoomFrameHeight - 1 > win_y2 )
00084           clickY = win_y2 - zoomFrameHeight + 1;
00085           //----------------------------------------------//
00086           int absX = abs_top_x + (clickX-win_x1);
00087           int absY = abs_top_y + (clickY-win_y1);
00088           //-------- convert to absolute positions -------//
00089         */
00090         int zoomFrameWidth  = (ZOOM_WIDTH * loc_width / world.active_zoom_matrix->loc_width);
00091         int zoomFrameHeight = (ZOOM_HEIGHT * loc_height / world.active_zoom_matrix->loc_height);
00092 
00093         int absX = (mouse.cur_x-win_x1)-zoomFrameWidth/2;
00094         int absY = (mouse.cur_y-win_y1)-zoomFrameHeight/2;
00095         absX=max(absX,1);
00096         absY=max(absY,1);
00097         absX=min(absX,win_x2-win_x1-zoomFrameWidth+1);
00098         absY=min(absY,win_y2-win_y1-zoomFrameHeight+1);
00099         absX+=abs_top_x;
00100         absY+=abs_top_y;
00101 
00102         int locX, locY;
00103         static int old_locX=-1,old_locY=-1;
00104 
00105         abs_to_loc( locX, locY, absX, absY );
00106 
00107         if(locX!=old_locX)
00108             if(locY!=old_locY) {
00109                 // chwg0401
00110                 world.active_zoom_matrix->set_top_loc( locX, locY );
00111                 // begin chwg0401
00112                 //                              if(world.zoom_level==1)
00113                 //                                      world.zoom2_matrix.set_top_loc( locX*ZOOM2_LOC_WIDTH/ZOOM1_LOC_WIDTH,
00114                 //                                                                                                      locY*ZOOM2_LOC_HEIGHT/ZOOM1_LOC_HEIGHT );
00115                 //                              else
00116                 //                                      world.zoom1_matrix.set_top_loc(  locX*ZOOM1_LOC_WIDTH/ZOOM2_LOC_WIDTH,
00117                 //                                                                                                      locY*ZOOM1_LOC_HEIGHT/ZOOM2_LOC_HEIGHT );
00118                 // end chwg0401
00119             }
00120         old_locX=locX;
00121         old_locY=locY;
00122         //              world.active_zoom_matrix->set_top_loc( locX, locY );
00123         sys.redraw_zoom_flag = 1;
00124 
00125         return 1;
00126     }
00127 
00128     if( mouse.press_area(win_x1-EFFECTIVE_BORDER,win_y1-EFFECTIVE_BORDER,win_x2+EFFECTIVE_BORDER,win_y2+EFFECTIVE_BORDER, LEFT_BUTTON )) {
00129         int zoomFrameWidth  = (ZOOM_WIDTH * loc_width / world.active_zoom_matrix->loc_width);
00130         int zoomFrameHeight = (ZOOM_HEIGHT * loc_height / world.active_zoom_matrix->loc_height);
00131 
00132         int absX = (mouse.cur_x-win_x1)-zoomFrameWidth/2;
00133         int absY = (mouse.cur_y-win_y1)-zoomFrameHeight/2;
00134 
00135         absX=max(absX,1);
00136         absY=max(absY,1);
00137         absX=min(absX,win_x2-win_x1-zoomFrameWidth+1);
00138         absY=min(absY,win_y2-win_y1-zoomFrameHeight+1);
00139         absX+=abs_top_x;
00140         absY+=abs_top_y;
00141 
00142         //-------- convert to absolute positions -------//
00143 
00144         int locX, locY;
00145         static int old_locX=-1,old_locY=-1;
00146 
00147         abs_to_loc( locX, locY, absX, absY );
00148 
00149         if(locX!=old_locX)
00150             if(locY!=old_locY) {
00151                 // chwg0401
00152                 world.active_zoom_matrix->set_top_loc( locX, locY );
00153                 // begin chwg0401
00154                 //                              if(world.zoom_level==1)
00155                 //                                      world.zoom2_matrix.set_top_loc( locX*ZOOM2_LOC_WIDTH/ZOOM1_LOC_WIDTH,
00156                 //                                                                                                      locY*ZOOM2_LOC_HEIGHT/ZOOM1_LOC_HEIGHT );
00157                 //                              else
00158                 //                                      world.zoom1_matrix.set_top_loc(  locX*ZOOM1_LOC_WIDTH/ZOOM2_LOC_WIDTH,
00159                 //                                                                                                      locY*ZOOM1_LOC_HEIGHT/ZOOM2_LOC_HEIGHT );
00160                 // end chwg0401
00161             }
00162         old_locX=locX;
00163         old_locY=locY;
00164 
00165         sys.redraw_zoom_flag = 1;
00166 
00167         return 1;
00168     }
00169 
00170     return 0;
00171 }
00172 
00173 //-------------- End of function MapMatrix::detect ---------------//
00174 
00175 //------------ Begin of function MapMatrix::scroll ---------------//
00176 
00177 void MapMatrix::scroll(int scrollX, int scrollY) {
00178     //---- scroll the zoom view area as if scrolling the zoom box ----//
00179 
00180     int boxX1, boxY1;
00181 
00182     loc_to_abs_center_left( boxX1, boxY1, world.active_zoom_matrix->top_x_loc,
00183                             world.active_zoom_matrix->top_y_loc );
00184 
00185     boxX1 = boxX1 - abs_top_x + MAP_X1;
00186     boxY1 = boxY1 - abs_top_y + MAP_Y1;
00187 
00188     int boxWidth  = (ZOOM_WIDTH  * loc_width  / world.active_zoom_matrix->loc_width);
00189     int boxHeight = (ZOOM_HEIGHT * loc_height / world.active_zoom_matrix->loc_height);
00190 
00191     //-------- scroll the box now --------//
00192 
00193     boxX1 += scrollX * loc_width;
00194     boxY1 += scrollY * loc_height;
00195 
00196     if( boxX1 < MAP_X1 )
00197         boxX1 = MAP_X1;
00198 
00199     if( boxY1 < MAP_Y1 )
00200         boxY1 = MAP_Y1;
00201 
00202     if( boxX1 + boxWidth - 1 > MAP_X2 )
00203         boxX1 = MAP_X2 - boxWidth + 1;
00204 
00205     if( boxY1 + boxHeight - 1 > MAP_Y2 )
00206         boxY1 = MAP_Y2 - boxHeight + 1;
00207 
00208     //------ set new top locations and redraw -----//
00209 
00210     int absX = boxX1 - MAP_X1 + abs_top_x;
00211     int absY = boxY1 - MAP_Y1 + abs_top_y;
00212 
00213     int locX, locY;
00214 
00215     abs_to_loc( locX, locY, absX, absY );
00216 
00217     world.active_zoom_matrix->set_top_loc( locX, locY );
00218 
00219     // begin chwg0401
00220     //  if(world.zoom_level==1)
00221     //          world.zoom2_matrix.set_top_loc( locX*ZOOM2_LOC_WIDTH/ZOOM1_LOC_WIDTH,
00222     //                                                                                                  locY*ZOOM2_LOC_HEIGHT/ZOOM1_LOC_HEIGHT );
00223     //  else
00224     //          world.zoom1_matrix.set_top_loc(  locX*ZOOM1_LOC_WIDTH/ZOOM2_LOC_WIDTH,
00225     //                                                                                                  locY*ZOOM1_LOC_HEIGHT/ZOOM2_LOC_HEIGHT );
00226     // end chwg0401
00227 
00228     sys.redraw_zoom_flag = 1;
00229 }
00230 
00231 //-------------- End of function MapMatrix::scroll --------------//

Generated on Fri Aug 23 01:38:36 2002 for VirtualU by doxygen1.2.17