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

Password:

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

OMOUSECR.CPP

Go to the documentation of this file.
00001 //Filename    : OMOUSECR.CPP
00002 //Description : Object Cursor Resource
00003 
00004 #include <OMOUSECR.H>
00005 #include <ALL.H>
00006 #include <OSYS.H>
00007 #include <OINFO.H>
00008 #include <OVGA.H>
00009 #include <ODB.H>
00010 #include <OMOUSE.H>
00011 #include <OWORLDMT.H>
00012 #include <OBLOB2W.H>
00013 #include <OBOX.H>
00014 
00015 //---------- define constant ------------//
00016 
00017 #define CURSOR_DBF    DIR_RES"CURSOR.RES"
00018 
00019 //---------- Begin of function MouseCursor::MouseCursor --------//
00020 
00021 MouseCursor::MouseCursor() {
00022     memset( this, 0, sizeof(MouseCursor) );
00023 }
00024 
00025 //----------- End of function MouseCursor::MouseCursor ------//
00026 
00027 //---------- Begin of function MouseCursor::~MouseCursor --------//
00028 
00029 MouseCursor::~MouseCursor() {
00030     deinit();
00031 }
00032 
00033 //----------- End of function MouseCursor::~MouseCursor ------//
00034 
00035 //---------- Begin of function MouseCursor::init --------//
00037 void MouseCursor::init() {
00038     //----- open plant material bitmap resource file -------//
00039 
00040     String str;
00041 
00042     str  = DIR_RES;
00043     str += "I_CURSOR.RES";
00044 
00045     res_bitmap.init_imported(str,1);                // 1-read all into buffer
00046 
00047     //------- load database information --------//
00048 
00049     load_cursor_info();
00050 
00051     // ------ init save_scr, save_back_scr, merge_buf -------//
00052 
00053     save_scr = new Blob2DW;
00054     save_back_scr = new Blob2DW;
00055     merge_buf = new Blob2DW;
00056 
00057     init_flag=1;
00058 }
00059 
00060 //----------- End of function MouseCursor::init ------//
00061 
00062 //---------- Begin of function MouseCursor::deinit --------//
00063 
00064 void MouseCursor::deinit() {
00065     if( init_flag ) {
00066         mem_del(cursor_info_array);
00067 
00068         if( save_scr ) {
00069             delete save_scr;
00070             save_scr = NULL;
00071         }
00072 
00073         if( save_back_scr ) {
00074             delete save_back_scr;
00075             save_back_scr = NULL;
00076         }
00077 
00078         if( merge_buf ) {                             // buffer for merging save screen from the front and back buffers
00079             delete merge_buf;
00080             merge_buf = NULL;
00081         }
00082 
00083         init_flag = 0;
00084         icon_ptr  = NULL;
00085         // ###### begin Gilbert 18/8 #####//
00086         cur_icon = 0;
00087         // ###### end Gilbert 18/8 #####//
00088     }
00089 }
00090 
00091 //----------- End of function MouseCursor::deinit ------//
00092 
00093 //------- Begin of function MouseCursor::load_cursor_info -------//
00095 void MouseCursor::load_cursor_info() {
00096     CursorRec     *cursorRec;
00097     CursorInfo     *cursorInfo;
00098     int         i;
00099     long        bitmapOffset;
00100     Database    dbCursor(CURSOR_DBF, 1);            // 1-read all into the buffer
00101 
00102     cursor_count = (short) dbCursor.rec_count();
00103     cursor_info_array = (CursorInfo*) mem_add( sizeof(CursorInfo)*cursor_count );
00104 
00105     //-------- read in PLANTBMP.DBF -------//
00106 
00107     memset( cursor_info_array, 0, sizeof(CursorInfo) * cursor_count );
00108 
00109     for( i=0 ; i<cursor_count ; i++ ) {
00110         cursorRec  = (CursorRec*) dbCursor.read(i+1);
00111         cursorInfo = cursor_info_array+i;
00112 
00113         memcpy( &bitmapOffset, cursorRec->bitmap_ptr, sizeof(long) );
00114 
00115         cursorInfo->bitmap_ptr = res_bitmap.read_imported(bitmapOffset);
00116 
00117         cursorInfo->hot_spot_x = m.atoi( cursorRec->hot_spot_x, cursorRec->HOT_SPOT_LEN );
00118         cursorInfo->hot_spot_y = m.atoi( cursorRec->hot_spot_y, cursorRec->HOT_SPOT_LEN );
00119     }
00120 }
00121 
00122 //--------- End of function MouseCursor::load_cursor_info ---------//
00123 
00124 //--------- Begin of function MouseCursor::set_icon ------------//
00130 void MouseCursor::set_icon(int cursorId) {
00131     if(box.progress_val>0)
00132         if(info.prerun_year==1) {
00133             cursorId=CURSOR_WAITING;
00134         }
00135 
00136     if( !init_flag )
00137         return;
00138 
00139     //-------- hide the cursor first ----------//
00140 
00141     int hideAllFlag = hide_all_flag;
00142 
00143     if( !hideAllFlag )                              // if the mouse has been hiden before, don't hide and show it
00144         mouse.hide();
00145 
00146     //------------ set cursor icon ------------//
00147 
00148     CursorInfo* cursorInfo = cursor_info_array+cursorId-1;
00149 
00150     icon_ptr   = cursorInfo->bitmap_ptr;
00151     hot_spot_x = cursorInfo->hot_spot_x;
00152     hot_spot_y = cursorInfo->hot_spot_y;
00153 
00154     err_when( !icon_ptr );
00155 
00156     icon_width  = *((short*)icon_ptr);
00157     icon_height = *((short*)icon_ptr+1);
00158 
00159     // ###### begin Gilbert 18/8 #####//
00160     cur_icon = cursorId;
00161     // ###### end Gilbert 18/8 #####//
00162 
00163     //------- allocate buffer for screen saving ------//
00164 
00165     save_scr->clear();
00166     save_scr->resize( 0, 0, icon_width, icon_height );
00167     save_back_scr->clear();
00168     save_back_scr->resize(0, 0, icon_width, icon_height);
00169     merge_buf->clear();
00170     merge_buf->resize(0, 0, icon_width,icon_height);
00171 
00172     //------------ redisplay cursor -----------//
00173 
00174     if( !hideAllFlag ) {
00175         if( vga_front.dd_buf ) {
00176             mouse.show();
00177             sys.blt_virtual_buf();
00178         }
00179     }
00180 }
00181 
00182 //----------- End of function MouseCursor::set_icon -------------//
00183 
00184 //----------- Begin of function MouseCursor::set_frame --------//
00191 void MouseCursor::set_frame(char frameFlag, char buildTrack) {
00192     if( frame_flag == frameFlag )
00193         return;
00194 
00195     frame_flag  = frameFlag;
00196     frame_shown = 0;
00197 }
00198 
00199 //----------- End of function MouseCursor::set_frame -------//
00200 
00201 //----------- Begin of function MouseCursor::set_frame_border --------//
00202 
00203 void MouseCursor::set_frame_border(int borderX1, int borderY1, int borderX2, int borderY2) {
00204     frame_border_x1 = borderX1;
00205     frame_border_y1 = borderY1;
00206     frame_border_x2 = borderX2;
00207     frame_border_y2 = borderY2;
00208 }
00209 
00210 //----------- End of function MouseCursor::set_frame_border -------//
00211 
00212 //----------- Begin of function MouseCursor::process --------//
00213 
00214 void MouseCursor::process(int curX, int curY) {
00215     if( processing_flag || !icon_ptr)               // it is being nested call by interrupt
00216         return;                                       // when another instance of process is
00217     // being run.
00218     if( !vga_front.dd_buf )
00219         return;
00220 
00221     processing_flag = 1;                            // Prevent nested call
00222 
00223     //---------- store screen area ------------//
00224 
00225     if( cursor_shown )                              // restore screen
00226         vga_front.put_bitmapW( max(cur_x1,0), max(cur_y1,0), save_scr->bitmap_ptr() );
00227 
00228     //Kevin ::0909 restore the stored area to back buffer
00230 
00231     //---- only the zoom map can be framed, limit the frame inside that area ----//
00232 
00233     if( frame_flag ) {
00234         curX = max(curX, ZOOM_X1);
00235         curY = max(curY, ZOOM_Y1);
00236         curX = min(curX, ZOOM_X2);
00237         curY = min(curY, ZOOM_Y2);
00238 
00239         process_frame(curX, curY);
00240     }
00241 
00242     //------- update cursor postions ----------//
00243 
00244     cur_x1 = curX - hot_spot_x;                     // handle the offset of the hot site
00245     cur_y1 = curY - hot_spot_y;
00246     cur_x2 = cur_x1 + icon_width  - 1;
00247     cur_y2 = cur_y1 + icon_height - 1;
00248 
00249     //------- save screen and put cursor -------//
00250 
00251     if( hide_all_flag || ( hide_area_flag &&
00252                            is_touch( hide_x1, hide_y1, hide_x2, hide_y2 ) ) ) {
00253         cursor_shown = 0;
00254     }
00255     else {
00256         //---- if the cursor is across the screen border -----//
00257 
00258         if( cur_x1 < 0 || cur_x2 >= VGA_WIDTH || cur_y1 < 0 || cur_y2 >= VGA_HEIGHT ) {
00259             vga_front.read_bitmapW( max(cur_x1,0), max(cur_y1,0),
00260                                     min(cur_x2,VGA_WIDTH-1), min(cur_y2,VGA_HEIGHT-1), save_scr->bitmap_ptr() );
00261 
00262             vga_front.put_bitmap_area_trans( cur_x1, cur_y1, icon_ptr,
00263                                              max(0,cur_x1)-cur_x1, max(0,cur_y1)-cur_y1,
00264                                              min(VGA_WIDTH-1,cur_x2)-cur_x1, min(VGA_HEIGHT-1,cur_y2)-cur_y1 );
00265         }
00266         else {                                        //----- if the whole cursor is on the screen -----//
00267             vga_front.read_bitmapW( cur_x1, cur_y1, cur_x2, cur_y2, save_scr->bitmap_ptr() );
00268             // must use PutIcon instead of PutArea for background masking
00269             vga_front.put_bitmap_trans( cur_x1, cur_y1, icon_ptr );
00270         }
00271 
00272         cursor_shown = 1;
00273     }
00274 
00275     //------------------------------------------//
00276 
00277     processing_flag = 0;                            // cancel prevention of nested call
00278 }
00279 
00280 //----------- End of function MouseCursor::process -------//
00281 
00282 //-------- Begin of function MouseCursor::process_frame --------//
00283 
00284 void MouseCursor::process_frame(int curX, int curY) {
00285     //---- restore the screen area overwritten by the last frame ---//
00286 
00287     if( frame_shown ) {
00288         vga_front.put_bitmapW( frame_x1, frame_y1, frame_top_save_scr    );
00289         vga_front.put_bitmapW( frame_x1, frame_y2, frame_bottom_save_scr );
00290         vga_front.put_bitmapW( frame_x1, frame_y1, frame_left_save_scr   );
00291         vga_front.put_bitmapW( frame_x2, frame_y1, frame_right_save_scr  );
00292     }
00293 
00294     //---------- update frame position ----------//
00295 
00296     if( !frame_shown ) {                            // a new frame
00297         frame_origin_x = curX;
00298         frame_origin_y = curY;
00299 
00300         frame_x1 = curX;
00301         frame_y1 = curY;
00302         frame_x2 = curX;
00303         frame_y2 = curY;
00304     }
00305     else {                                          // update the postion of the existing frame
00306         //---------- update frame position ----------//
00307 
00308         if( curX > frame_origin_x ) {
00309             if( curY > frame_origin_y ) {               // stretching towards the lower right end
00310                 frame_x1 = frame_origin_x;
00311                 frame_y1 = frame_origin_y;
00312                 frame_x2 = curX;
00313                 frame_y2 = curY;
00314             }
00315             else {                                      // stretching towards the upper right end
00316                 frame_x1 = frame_origin_x;
00317                 frame_y1 = curY;
00318                 frame_x2 = curX;
00319                 frame_y2 = frame_origin_y;
00320             }
00321         }
00322         else {
00323             if( curY > frame_origin_y ) {               // stretching towards the lower left end
00324                 frame_x1 = curX;
00325                 frame_y1 = frame_origin_y;
00326                 frame_x2 =  frame_origin_x;
00327                 frame_y2 = curY;
00328             }
00329             else {                                      // stretching towards the upper left end
00330                 frame_x1 = curX;
00331                 frame_y1 = curY;
00332                 frame_x2 = frame_origin_x;
00333                 frame_y2 = frame_origin_y;
00334             }
00335         }
00336     }
00337 
00338     //------- save the screen area and display the frame ------//
00339 
00340     disp_frame(&vga_front);
00341 }
00342 
00343 //----------- End of function MouseCursor::process_frame -------//
00344 
00345 //----------- Begin of function MouseCursor::disp_frame --------//
00346 
00347 void MouseCursor::disp_frame(VgaBuf* vgaBufPtr) {
00348     //------- save the screen area that will be overwriteen -------//
00349 
00350     vgaBufPtr->read_bitmapW( frame_x1, frame_y1, frame_x2, frame_y1, frame_top_save_scr );
00351     vgaBufPtr->read_bitmapW( frame_x1, frame_y2, frame_x2, frame_y2, frame_bottom_save_scr );
00352     vgaBufPtr->read_bitmapW( frame_x1, frame_y1, frame_x1, frame_y2, frame_left_save_scr );
00353     vgaBufPtr->read_bitmapW( frame_x2, frame_y1, frame_x2, frame_y2, frame_right_save_scr );
00354 
00355     //---------- draw the rectagular frame now -----------//
00356 
00357     vgaBufPtr->rect( frame_x1, frame_y1, frame_x2, frame_y2, 1, OWN_SELECT_FRAME_COLOR );
00358 
00359     //---------- set frame flag ----------//
00360 
00361     frame_shown = 1;
00362 }
00363 
00364 //----------- End of function MouseCursor::disp_frame -------//
00365 
00366 //----------- Begin of function MouseCursor::disp_back_buf --------//
00370 void MouseCursor::disp_back_buf(int bltX1, int bltY1, int bltX2, int bltY2) {
00371     if( !icon_ptr )
00372         return;
00373 
00374     //-------- display frame on the back buffer ----//
00375 
00376     if( frame_flag )
00377         disp_frame(&vga_back);
00378 
00379     //----- display mouse cursor on the back buffer ----//
00380 
00381     if( is_touch(bltX1, bltY1, bltX2, bltY2) ) {
00382         //--- save the back buffer area which will be overwritten ---//
00383 
00384         int x1 = max(cur_x1,bltX1);
00385         int y1 = max(cur_y1,bltY1);
00386         int x2 = min(cur_x2,bltX2);
00387         int y2 = min(cur_y2,bltY2);
00388 
00389         vga_back.read_bitmapW( x1, y1, x2, y2, save_back_scr->bitmap_ptr() );
00390 
00391         //--- merge the save area of the back buf with the front buf's save area ---//
00392 
00393         // save_scr width  : min(cur_x2,VGA_WIDTH-1) -max(cur_x1,0)+1;
00394         // save_scr height : min(cur_y2,VGA_HEIGHT-1)-max(cur_y1,0)+1;
00395 
00396         // IMGbltW( save_scr->buf_ptr(), min(cur_x2,VGA_WIDTH-1) -max(cur_x1,0)+1, x1-max(cur_x1,0), y1-max(cur_y1,0), save_back_scr->bitmap_ptr() );           // +4 is the width & height info
00397         // +4 is the width & height info
00398         IMGbltW( save_scr->buf_ptr(), sizeof(short) * (min(cur_x2,VGA_WIDTH-1) -max(cur_x1,0)+1), x1-max(cur_x1,0), y1-max(cur_y1,0), save_back_scr->bitmap_ptr() );
00399 
00400         //--------- display the mouse cursor now -----------//
00401 
00402         if( cur_x1 < bltX1 || cur_x2 > bltX2 || cur_y1 < bltY1 || cur_y2 > bltY2 ) {
00403             vga_back.put_bitmap_area_trans( cur_x1, cur_y1, icon_ptr,
00404                                             max(bltX1,cur_x1)-cur_x1, max(bltY1,cur_y1)-cur_y1,
00405                                             min(bltX2,cur_x2)-cur_x1, min(bltY2,cur_y2)-cur_y1 );
00406         }
00407 
00408         //---- the whole sprite is inside the view area ------//
00409 
00410         else {
00411             vga_back.put_bitmap_trans(cur_x1, cur_y1, icon_ptr);
00412         }
00413 
00414         cursor_shown = 1;
00415     }
00416 }
00417 
00418 //----------- End of function MouseCursor::disp_back_buf -------//
00419 
00420 //--------- Begin of function MouseCursor::is_touch ------------//
00426 int MouseCursor::is_touch(int x1, int y1, int x2, int y2) {
00427     return (( cur_y1 <=  y1 && cur_y2 >=  y1 ) ||
00428             (  y1 <= cur_y1 &&  y2 >= cur_y1 )) &&
00429         (( cur_x1 <=  x1 && cur_x2 >=  x1 ) ||
00430          (  x1 <= cur_x1 &&  x2 >= cur_x1 ));
00431 }
00432 
00433 //--------- End of function MouseCursor::is_touch -----------//
00434 
00435 // ####### begin Gilbert 18/8 ########//
00436 //--------- Begin of function MouseCursor::restore_icon ------------//
00437 void MouseCursor::restore_icon(int newCursorId) {
00438     if(box.progress_val>0)
00439         if(info.prerun_year==1) {
00440             newCursorId=CURSOR_WAITING;
00441         }
00442 
00443     if( newCursorId == 0) {
00444         err_here();
00445 
00446         // should restore to invisible cursor ?
00447         if( !hide_all_flag )
00448             mouse.hide();
00449         cur_icon = 0;
00450         icon_ptr = NULL;
00451     }
00452     else if( cur_icon == 0 || newCursorId != cur_icon ) {
00453         set_icon(newCursorId);
00454     }
00455 }
00456 
00457 //--------- End of function MouseCursor::restore_icon ------------//
00458 // ####### end Gilbert 18/8 ########//

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