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

Password:

Oworld_z.cpp Source File
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

Oworld_z.cpp

Go to the documentation of this file.
00001 //Filename   : OWORLD_Z.CPP
00002 //Description: ZoomMatrix class
00003 
00004 #include <KEY.H>
00005 #include <OVGA.H>
00006 #include <OSYS.H>
00007 #include <OCONFIG.H>
00008 #include <OMOUSE.H>
00009 #include <OMATRIX.H>
00010 #include <OWORLD.H>
00011 #include <OFIRM.H>
00012 #include <OFIRMRES.H>
00013 #include <COLCODE.H>
00014 #include <OLOG.H>
00015 
00016 //------------ Begin of function ZoomMatrix::ZoomMatrix ---------------//
00017 
00018 ZoomMatrix::ZoomMatrix() {
00019     next_scroll_time = 0;
00020 }
00021 
00022 //------------ End of function ZoomMatrix::ZoomMatrix ---------------//
00023 
00024 //------------ Begin of function ZoomMatrix::draw_all ---------------//
00025 
00026 void ZoomMatrix::draw_all() {
00027     Matrix::draw_all();
00028 }
00029 
00030 //------------ End of function ZoomMatrix::draw_all ---------------//
00031 
00032 //------------ Begin of function ZoomMatrix::draw_update ---------------//
00033 
00034 void ZoomMatrix::draw_update() {
00035     //Matrix::draw_all();               //temp for debug fred 0611
00036 }
00037 
00038 //-------------- End of function ZoomMatrix::draw_update --------------//
00039 
00040 #if(GAME_VERSION>=200)
00041 void ZoomMatrix::draw_text() {
00042     // Matrix::draw_text();
00043 
00044     if( config.disp_building_label ) {
00045         // draw text on firm
00046 
00047         for( int firmRecno = 1; firmRecno <= firm_array.size(); ++firmRecno ) {
00048             if( firm_array.is_deleted(firmRecno) )
00049                 continue;
00050             Firm *firmPtr = firm_array[firmRecno];
00051             if( firmPtr->name_on_map() ) {
00052                 put_center_text( (firmPtr->abs_rect[zoom_level].x1+firmPtr->abs_rect[zoom_level].x2)/2,
00053                                  (firmPtr->abs_rect[zoom_level].y1+firmPtr->abs_rect[zoom_level].y2)/2,
00054                                  firmPtr->name_on_map() );
00055             }
00056         }
00057     }
00058 }
00059 #endif
00060 
00061 //------------ Begin of function ZoomMatrix::detect ---------------//
00062 
00063 int ZoomMatrix::detect() {
00064     if( detect_scroll() )
00065         return 1;
00066 
00067     return detect_select();                         // detect selecting a firm
00068 }
00069 
00070 //-------------- End of function ZoomMatrix::detect ---------------//
00071 
00072 //--------- Begin of function ZoomMatrix::detect_scroll ---------//
00077 int ZoomMatrix::detect_scroll() {
00078     // just scrolled not too long ago, wait for a little while before next scroll.
00079     if( next_scroll_time && m.get_time() < next_scroll_time )
00080         return 0;
00081 
00082     int rc=0;
00083 
00084     //----- scroll left -----//
00085 
00086     if( mouse.cur_x == mouse.bound_x1 || mouse.key_code==KEY_LEFT ) {
00087         world.map_matrix.scroll(-1,0);
00088         rc = 1;
00089     }
00090 
00091     //---- scroll right -----//
00092 
00093     if( mouse.cur_x == mouse.bound_x2 || mouse.key_code==KEY_RIGHT ) {
00094         world.map_matrix.scroll(1,0);
00095         rc = 1;
00096     }
00097 
00098     //---- scroll top -------//
00099 
00100     if( mouse.cur_y == mouse.bound_y1 || mouse.key_code==KEY_UP ) {
00101         world.map_matrix.scroll(0,-1);
00102         rc = 1;
00103     }
00104 
00105     //---- scroll bottom ----//
00106 
00107     if( mouse.cur_y == mouse.bound_y2 || mouse.key_code==KEY_DOWN ) {
00108         world.map_matrix.scroll(0,1);
00109         rc = 1;
00110     }
00111 
00112     //----- set next scroll time based on scroll_speed -----//
00113     //
00114     // slowest scroll speed: 500/1  = 500 milliseconds or 1/2 second
00115     // fastest scroll speed: 500/10 = 50  milliseconds or 1/20 second
00116     //
00117     //------------------------------------------------------//
00118     // ## chwong 1207
00119     if( rc )
00120         next_scroll_time = m.get_time() + 500/(config.scroll_speed+1);
00121 
00122     return rc;
00123 }
00124 
00125 //----------- End of function ZoomMatrix::detect_scroll -----------//
00126 
00127 //--------- Begin of function ZoomMatrix::detect_select ------------//
00128 
00129 int ZoomMatrix::detect_select() {
00130     int absClickX = abs_top_x + (mouse.cur_x-win_x1);
00131     int absClickY = abs_top_y + (mouse.cur_y-win_y1);
00132 
00133     firm_array.touched_recno = 0;
00134 
00135     // ## chwg062499
00136     int i,j,dispCount = disp_sort_array.size();
00137 
00138     for( i=dispCount ;i>=1; i-- ) {
00139         DisplaySort* displaySortPtr = (DisplaySort*) disp_sort_array.get(i);
00140         //              if(!displaySortPtr)
00141         //                      continue;
00142 
00143         if(displaySortPtr->object_type!=OBJECT_FIRM)
00144             continue;
00145 
00146         j=displaySortPtr->object_recno;
00147 
00148         Firm *firmPtr;
00149         if( firm_array.is_deleted(j) )
00150             continue;
00151 
00152         firmPtr = firm_array[j];
00153 
00154         //------ if the mouse is over the building ------//
00155         if( firmPtr->abs_rect[zoom_level].is_inside( absClickX, absClickY ) ) {
00156 
00157             //------ if the pixel which is pointed by cursor of the building image is not transparent ------//
00158             FirmInfo* firmInfo = firm_res[firmPtr->firm_id];
00159             //-------- check if the firm is within the view area --------//
00160             //                  int bmpWidth  = firmInfo->bitmap_width[zoom_level];
00161             //                  int bmpHeight = firmInfo->bitmap_height[zoom_level];
00162             char* bmpPtr  = firmInfo->bitmap_ptr[zoom_level];
00163 
00164             // - world.active_zoom_matrix->win_x1 + world.active_zoom_matrix->abs_top_x;
00165             int cur_x = absClickX - firmPtr->abs_rect[zoom_level].x1;
00166             // - world.active_zoom_matrix->win_y1 + world.active_zoom_matrix->abs_top_y;
00167             int cur_y = absClickY - firmPtr->abs_rect[zoom_level].y1;
00168             /*
00169               String s=m.format(cur_x,1);
00170               s+=",";
00171               s+=m.format(cur_y,1);
00172               s+=",";
00173               s+=m.format(IMGgetTransDecompress(bmpPtr,cur_x,cur_y) ,1);
00174               DEBUG_LOG(s);
00175             */
00176             if(IMGgetTransDecompress(bmpPtr,cur_x,cur_y)==TRANSPARENT_CODE)
00177                 continue;
00178             //------ if building is the toppest ------//
00179 
00180             firm_array.touched_recno     = j;
00181             // the frame id. which the building is being touched
00182             firm_array.touched_frame_count = sys.frame_count;
00183 
00184             //------ if the mouse clicks on the building ------//
00185 
00186             int rc=mouse.any_click( win_x1,win_y1,win_x2,win_y2, LEFT_BUTTON );
00187 
00188             if( rc==1 ) {
00189                 firm_array.select_firm(j);
00190                 sys.redraw_all_flag = 1;
00191                 return 1;
00192             }
00193 
00194             //--- double-click to bring up the firm's detail report ----//
00195 
00196             else if( rc==2 ) {
00197                 firm_array[j]->double_click_firm();
00198                 return 1;
00199             }
00200             return 0;
00201         }
00202     }
00203 
00204     return 0;
00205 }
00206 
00207 //---------- End of function ZoomMatrix::detect_select -----------//

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