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

Password:

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

ovga.cpp

Go to the documentation of this file.
00001 //Filename    : OVGA.CPP
00002 //Description : VGA manipulation functions (Direct Draw version)
00003 
00004 #define DEBUG_LOG_LOCAL 1
00005 
00006 #include <windowsx.h>
00007 
00008 #include <ALL.H>
00009 #include <IMGFUN.H>
00010 #include <COLCODE.H>
00011 #include <OMOUSE.H>
00012 #include <OMOUSECR.H>
00013 #include <OCOLTBL.H>
00014 #include <OFILE.H>
00015 #include <OSYS.H>
00016 #include <OVGA.H>
00017 #include <OLOG.H>
00018 #include <OVGALOCK.H>
00019 #include <OSYS.H>
00020 //-------- Define constant --------//
00021 
00022 #define UP_OPAQUE_COLOR       (VGA_GRAY+10)
00023 #define DOWN_OPAQUE_COLOR     (VGA_GRAY+13)
00024 
00025 //------ Define static class member vars ---------//
00026 
00027 char    Vga::use_back_buf = 0;
00028 char    Vga::opaque_flag  = 0;
00029 VgaBuf* Vga::active_buf   = &vga_front;           // default: front buffer
00030 // ##### begin Gilbert 26/04/2001 ######//
00031 // static short * mouse_back_buffer_storage_bitmap;
00032 // ##### end Gilbert 26/04/2001 ######//
00033 
00034 char    low_video_memory_flag = 0;
00035 extern "C" {
00036     short transparent_code_w;
00037 }
00038 
00039 //-------- Begin of function Vga::Vga ----------//
00040 
00041 Vga::Vga() {
00042     memset( this, 0, sizeof(Vga) );
00043     // ##### begin Gilbert 26/04/2001 ######//
00044     // mouse_back_buffer_storage_bitmap=NULL;
00045     // ##### end Gilbert 26/04/2001 ######//
00046     vga_color_table = new ColorTable;
00047     dont_blt =0;                                    // ## chwg021999
00048 }
00049 
00050 //-------- End of function Vga::Vga ----------//
00051 
00052 //-------- Begin of function Vga::~Vga ----------//
00053 
00054 Vga::~Vga() {
00055     deinit();                                       // 1-is final
00056 
00057     delete vga_color_table;
00058 
00059     err_when( back_up_pal );                        // this must be free up immediately after its use
00060 }
00061 
00062 //-------- End of function Vga::~Vga ----------//
00063 
00064 //-------- Begin of function Vga::init ----------//
00065 
00066 BOOL Vga::init() {
00067     char* warnStr = "Warning: Due to the low memory of your display card, "
00068         "you may experience problems when you quit the game or "
00069         "switch tasks during the game. "
00070         "To avoid this problem, set your Windows display "
00071         "to 800x600 16-bit color mode before running the game.";
00072 
00073     //--------- Initialize DirectDraw object --------//
00074 
00075     if( !init_dd() )
00076         return FALSE;
00077 
00078     // get current display mode
00079     DDSURFACEDESC2 ddsd;
00080     DDSCAPS2  ddsCaps;
00081     DWORD    dwTotal;
00082     DWORD    dwFree;
00083 
00084     memset(&ddsd, 0, sizeof(ddsd) );
00085     ddsd.dwSize = sizeof(ddsd);
00086     ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY;
00087 
00088     if( dd_obj->GetDisplayMode(&ddsd) == DD_OK &&
00089         dd_obj->GetAvailableVidMem(&ddsCaps, &dwTotal, &dwFree) == DD_OK ) {
00090         if( dwFree < (DWORD) VGA_WIDTH*VGA_HEIGHT*VGA_BPP/8 &&
00091             !(ddsd.dwWidth==(DWORD)VGA_WIDTH && ddsd.dwHeight==(DWORD)VGA_HEIGHT && (ddsd.ddpfPixelFormat.dwRGBBitCount == (DWORD)VGA_BPP)) ) {
00092             // not enough memory except same video mode
00093 
00094             ShowCursor(TRUE);
00095             // approximation of video memory required, actual video memory used should be calculated from vga_(true)_front->buf_pitch()
00096 
00097             /*
00098               extern char new_config_dat_flag;
00099 
00100               if( new_config_dat_flag )
00101               {
00102               MessageBox(sys.main_hwnd, warnStr,
00103               WIN_TITLE, MB_OK | MB_ICONWARNING | MB_SETFOREGROUND );
00104               }
00105             */
00106             low_video_memory_flag = 1;
00107 
00108             ShowCursor(FALSE);
00109         }
00110     }
00111 
00112     if( !set_mode(VGA_WIDTH, VGA_HEIGHT) )
00113         return FALSE;
00114 
00115     return TRUE;
00116 }
00117 
00118 //-------- End of function Vga::init ----------//
00119 
00120 //-------- Begin of function Vga::init_dd ----------//
00121 
00122 BOOL Vga::init_dd() {
00123     if(dd_obj)                                      // the Direct Draw object has been initialized already
00124         return TRUE;
00125 
00126     //--------- Create direct draw object --------//
00127 
00128     DEBUG_LOG("Attempt DirectDrawCreate");
00129     LPDIRECTDRAW dd1Obj;
00130     int rc = DirectDrawCreate( NULL, &dd1Obj, NULL );
00131     DEBUG_LOG("DirectDrawCreate finish");
00132 
00133     if( rc != DD_OK ) {
00134 #ifdef DEBUG
00135         debug_msg("DirectDrawCreate failed err=%d", rc);
00136 #endif
00137         return FALSE;
00138     }
00139 
00140     //-------- Query DirectDraw2 interface --------//
00141 
00142     DEBUG_LOG("Attempt Query DirectDraw4");
00143     rc = dd1Obj->QueryInterface(IID_IDirectDraw4, (void **)&dd_obj);
00144     DEBUG_LOG("Query DirectDraw4 finish");
00145     if( rc != DD_OK ) {
00146 #ifdef DEBUG
00147         debug_msg("Query DirectDraw4 failed err=%d", rc);
00148 #endif
00149         dd1Obj->Release();
00150         return FALSE;
00151     }
00152 
00153     dd1Obj->Release();
00154 
00155     //-----------------------------------------------------------//
00156     // Convert it to a plain window
00157     //-----------------------------------------------------------//
00158 
00159     DWORD   dwStyle;
00160     dwStyle = GetWindowStyle(sys.main_hwnd);
00161     dwStyle |= WS_POPUP;
00162     dwStyle &= ~(WS_OVERLAPPED | WS_CAPTION | WS_THICKFRAME | WS_MINIMIZEBOX);
00163     SetWindowLong(sys.main_hwnd, GWL_STYLE, dwStyle);
00164 
00165     //-----------------------------------------------------------//
00166     // grab exclusive mode if we are going to run as fullscreen
00167     // otherwise grab normal mode.
00168     //-----------------------------------------------------------//
00169 
00170     DEBUG_LOG("Attempt DirectDraw SetCooperativeLevel");
00171 
00172     if( sys.use_true_front == 2 ) {                 // window mode
00173         rc = dd_obj->SetCooperativeLevel( sys.main_hwnd,
00174                                           DDSCL_NORMAL );
00175     }
00176     else {
00177         rc = dd_obj->SetCooperativeLevel( sys.main_hwnd,
00178                                           DDSCL_EXCLUSIVE |
00179                                           DDSCL_FULLSCREEN );
00180     }
00181 
00182     DEBUG_LOG("DirectDraw SetCooperativeLevel finish");
00183 
00184     if( rc != DD_OK ) {
00185 #ifdef DEBUG
00186         debug_msg("SetCooperativeLevel failed err=%d", rc);
00187 #endif
00188         return FALSE;
00189     }
00190 
00191     return TRUE;
00192 }
00193 
00194 //-------- End of function Vga::init_dd ----------//
00195 
00196 //-------- Begin of function Vga::set_mode ----------//
00197 
00198 BOOL Vga::set_mode(int w, int h) {
00199     HRESULT rc;
00200 
00201     if( sys.use_true_front == 2 ) {                 // window mode
00202     }
00203     else {
00204 
00205         //-------------- set Direct Draw mode ---------------//
00206 
00207         DEBUG_LOG("Attempt DirectDraw SetDisplayMode");
00208         // IDirectDraw2::SetDisplayMode requires 5 parameters
00209         rc = dd_obj->SetDisplayMode( w, h, VGA_BPP, 0, 0);
00210         DEBUG_LOG("DirectDraw SetDisplayMode finish");
00211 
00212         if( rc != DD_OK ) {
00213 #ifdef DEBUG
00214             debug_msg("SetMode failed err=%d", rc);
00215 #endif
00216             return FALSE;
00217         }
00218     }
00219 
00220     //----------- get the pixel format flag -----------//
00221 
00222     DDSURFACEDESC2 ddsd;
00223     memset(&ddsd, 0, sizeof(ddsd) );
00224     ddsd.dwSize = sizeof(ddsd);
00225 
00226     pixel_format_flag = -1;
00227 
00228     if( dd_obj->GetDisplayMode(&ddsd) == DD_OK && ddsd.dwFlags & DDSD_PIXELFORMAT ) {
00229         if( ddsd.ddpfPixelFormat.dwFlags & DDPF_RGB
00230             && ddsd.ddpfPixelFormat.dwRGBBitCount == (DWORD)VGA_BPP ) {
00231             if( ddsd.ddpfPixelFormat.dwRBitMask == 0x001fL
00232                 && ddsd.ddpfPixelFormat.dwGBitMask == 0x001fL << 5
00233                 && ddsd.ddpfPixelFormat.dwBBitMask == 0x001fL << 10 ) {
00234                 pixel_format_flag = PIXFORM_RGB_555;
00235             }
00236             else if( ddsd.ddpfPixelFormat.dwRBitMask == 0x001fL
00237                      && ddsd.ddpfPixelFormat.dwGBitMask == 0x003fL << 5
00238                      && ddsd.ddpfPixelFormat.dwBBitMask == 0x001fL << 11 ) {
00239                 pixel_format_flag = PIXFORM_RGB_565;
00240             }
00241             else if( ddsd.ddpfPixelFormat.dwBBitMask == 0x001fL
00242                      && ddsd.ddpfPixelFormat.dwGBitMask == 0x001fL << 5
00243                      && ddsd.ddpfPixelFormat.dwRBitMask == 0x001fL << 10 ) {
00244                 pixel_format_flag = PIXFORM_BGR_555;
00245             }
00246             else if( ddsd.ddpfPixelFormat.dwBBitMask == 0x001fL
00247                      && ddsd.ddpfPixelFormat.dwGBitMask == 0x003fL << 5
00248                      && ddsd.ddpfPixelFormat.dwRBitMask == 0x001fL << 11 ) {
00249                 pixel_format_flag = PIXFORM_BGR_565;
00250             }
00251         }
00252 
00253         if( sys.use_true_front == 2 ) {               // window mode
00254             if( ddsd.dwWidth < VGA_WIDTH || ddsd.dwHeight < VGA_HEIGHT ) {
00255                 MessageBox( sys.main_hwnd, "Desktop resolution too small",
00256                             WIN_TITLE, MB_OK | MB_ICONWARNING | MB_SETFOREGROUND );
00257                 return FALSE;
00258             }
00259         }
00260     }
00261 
00262     if( pixel_format_flag == -1 ) {
00263         MessageBox(sys.main_hwnd, "Cannot determine the pixel format of this display mode.",
00264                    WIN_TITLE, MB_OK | MB_ICONWARNING | MB_SETFOREGROUND );
00265 
00266         if( sys.use_true_front == 2 ) {               // window mode
00267             return FALSE;                               // require supported pixel format in window mode
00268         }
00269 
00270         pixel_format_flag = PIXFORM_BGR_565;
00271     }
00272 
00273     // assembly functions to initalize effect processing
00274 
00275     INITeffect(pixel_format_flag);
00276     INITbright(pixel_format_flag);
00277 
00278     //----------- display the system cursor -------------//
00279 
00280     SetCursor(NULL);
00281 
00282     return TRUE;
00283 }
00284 
00285 //-------- End of function Vga::set_mode ----------//
00286 
00287 //-------- Begin of function Vga::deinit ----------//
00288 
00289 void Vga::deinit() {
00290     // ##### begin Gilbert 26/04/2001 ######//
00291     // %% Begin Ho0909
00292     //  if(mouse_back_buffer_storage_bitmap)
00293     //  {       mem_del(mouse_back_buffer_storage_bitmap);
00294     //          mouse_back_buffer_storage_bitmap=NULL;
00295     //  }
00296     // %% End Ho0909
00297     // ##### end Gilbert 26/04/2001 ######//
00298 
00299     release_pal();
00300 
00301     if( dd_obj ) {
00302         //DEBUG_LOG("Attempt vga.dd_obj->RestoreDisplayMode()");
00303         // dd_obj->RestoreDisplayMode();
00304         //DEBUG_LOG("vga.dd_obj->RestoreDisplayMode() finish");
00305 
00306         DEBUG_LOG("Attempt vga.dd_obj->Release()");
00307         dd_obj->Release();
00308         DEBUG_LOG("vga.dd_obj->Release() finish");
00309         dd_obj = NULL;
00310     }
00311 
00312 }
00313 
00314 //-------- End of function Vga::deinit ----------//
00315 
00316 //--------- Start of function Vga::load_pal ----------//
00317 //
00318 // Load the palette from a file and set it to the front buf.
00319 //
00320 BOOL Vga::load_pal(char* fileName) {
00321     char palBuf[256][3];
00322     File palFile;
00323 
00324     palFile.file_open(fileName);
00325     palFile.file_seek(8);                           // bypass the header info
00326     palFile.file_read(palBuf, 256*3);
00327     palFile.file_close();
00328 
00329     //--- Create a Direct Draw Palette and associate it with the front buffer ---//
00330 
00331     if( dd_pal == NULL ) {
00332         for(int i=0; i<256; i++) {
00333             pal_entry_buf[i].peRed   = palBuf[i][0];
00334             pal_entry_buf[i].peGreen = palBuf[i][1];
00335             pal_entry_buf[i].peBlue  = palBuf[i][2];
00336         }
00337 
00338         HRESULT rc = dd_obj->CreatePalette( DDPCAPS_8BIT, pal_entry_buf, &dd_pal, NULL );
00339 
00340         if( rc != DD_OK )
00341             return FALSE;
00342     }
00343 
00344     init_color_table();
00345     init_gray_remap_table();
00346 
00347     // set global variable
00348     transparent_code_w = translate_color(TRANSPARENT_CODE);
00349 
00350     return TRUE;
00351 }
00352 
00353 //----------- End of function Vga::load_pal ----------//
00354 
00355 //--------- Start of function Vga::init_color_table ----------//
00356 
00357 void Vga::init_color_table() {
00358     //----- initialize interface color table -----//
00359 
00360     PalDesc palDesc( (unsigned char*) pal_entry_buf, sizeof(PALETTEENTRY), 256, 8);
00361     vga_color_table->generate_table_fast( MAX_BRIGHTNESS_ADJUST_DEGREE, palDesc, ColorTable::bright_func );
00362 
00363     default_remap_table = (short *)vga_color_table->get_table(0);
00364 }
00365 
00366 //----------- End of function Vga::init_color_table ----------//
00367 
00368 //--------- Start of function Vga::release_pal ----------//
00369 
00370 void Vga::release_pal() {
00371     // ##### begin Gilbert 16/9 #######//
00372     if( dd_pal ) {
00373         while( dd_pal->Release() );
00374         dd_pal = NULL;
00375     }
00376     // ##### end Gilbert 16/9 #######//
00377 }
00378 
00379 //----------- End of function Vga::release_pal ----------//
00380 
00381 //-------- Begin of function Vga::activate_pal ----------//
00385 void Vga::activate_pal(VgaBuf* vgaBufPtr) {
00386     vgaBufPtr->activate_pal(dd_pal);
00387 }
00388 
00389 //--------- End of function Vga::activate_pal ----------//
00390 
00391 //-------- Begin of function Vga::adjust_brightness ----------//
00399 void Vga::adjust_brightness(int changeValue) {
00400     //---- find out the maximum rgb value can change without affecting the contrast ---//
00401 
00402     int          i;
00403     int          newRed, newGreen, newBlue;
00404     PALETTEENTRY palBuf[256];
00405 
00406     //------------ change palette now -------------//
00407 
00408     for( i=0 ; i<256 ; i++ ) {
00409         newRed   = (int)pal_entry_buf[i].peRed   + changeValue;
00410         newGreen = (int)pal_entry_buf[i].peGreen + changeValue;
00411         newBlue  = (int)pal_entry_buf[i].peBlue  + changeValue;
00412 
00413         palBuf[i].peRed   = min(255, max(newRed,0) );
00414         palBuf[i].peGreen = min(255, max(newGreen,0) );
00415         palBuf[i].peBlue  = min(255, max(newBlue,0) );
00416     }
00417 
00418     //------------ set palette ------------//
00419 
00420     vga_front.temp_unlock();
00421 
00422     dd_pal->SetEntries( 0, 0, 256, palBuf );
00423 
00424     vga_front.temp_restore_lock();
00425 }
00426 
00427 //--------- End of function Vga::adjust_brightness ----------//
00428 
00429 //--------- Begin of function Vga::blt_buf ----------//
00438 
00439 BOOL Vga::blt_buf(int x1, int y1, int x2, int y2, int putBackCursor) {
00440     // ## Begin chwg 021999:: do nothing while using on-line help or pop-up news.
00441     if (dont_blt) return FALSE;
00442     if (sys.no_true_output_flag) return FALSE;
00443     // ## End chwg 021999
00444 
00445     int restoreCursor = 0;
00446     short mouseBackBufferStorageBitmap[2+64*64];    // size for 64x64 bitmap
00447 
00448     if( putBackCursor ) {
00449         // ##### begin Gilbert 24/04/2001 ######//
00450         // reduce save area here
00451         if( !mouse_cursor.hide_all_flag && mouse_cursor.cur_icon
00452             && m.is_touch(x1,y1,x2,y2, mouse_cursor.cur_x1,mouse_cursor.cur_y1,mouse_cursor.cur_x2,mouse_cursor.cur_y2) ) {
00453             mouse_cursor.hide_area_flag = 0;            // do not call mouse.hide_area() which will double paint the cursor
00454 
00455             mouse_cursor.hide_x1 = x1;
00456             mouse_cursor.hide_y1 = y1;
00457             mouse_cursor.hide_x2 = x2;
00458             mouse_cursor.hide_y2 = y2;
00459 
00460             //-------- put mouse cursor ---------//
00461             // ## Begin chwg 0909:: save area
00462             //if(mouse_back_buffer_storage_bitmap)
00463             //{ mem_del(mouse_back_buffer_storage_bitmap);
00464             //mouse_back_buffer_storage_bitmap=NULL;
00465             //}
00466             // mouse_back_buffer_storage_bitmap=vga_back.save_area(x1, y1, x2, y2, mouse_back_buffer_storage_bitmap);
00467             // backup the overlap area
00468             err_when( BitmapW::size(min(x2,mouse_cursor.cur_x2)-max(x1,mouse_cursor.cur_x1)+1,min(y2,mouse_cursor.cur_y2)-max(y1,mouse_cursor.cur_y1)) > sizeof(mouseBackBufferStorageBitmap) );
00469             vga_back.read_bitmapW( max(x1,mouse_cursor.cur_x1), max(y1,mouse_cursor.cur_y1),
00470                                    min(x2,mouse_cursor.cur_x2), min(y2,mouse_cursor.cur_y2), mouseBackBufferStorageBitmap );
00471             // ## End chwg 0909
00472             mouse_cursor.disp_back_buf(x1, y1, x2, y2);
00473             restoreCursor = 1;                          // rest_area mouse_back_buffer_storage_bitmap later
00474         }
00475         // ##### end Gilbert 24/04/2001 ######//
00476     }
00477     else {
00478         mouse.hide_area(x1, y1, x2, y2);
00479     }
00480 
00481     //--------------------------------------//
00482     // ###### begin Gilbert 12/9 #######//
00483     //  vga_front.blt_buf_fast( &vga_back, x1, y1, x2, y2 );
00484     // use directx blt function
00485     vga_front.temp_unlock();
00486     vga_back.temp_unlock();
00487     RECT rect = { x1, y1, x2+1, y2+1 };
00488     vga_front.dd_buf->BltFast( x1, y1, vga_back.dd_buf, &rect, DDBLTFAST_NOCOLORKEY );
00489     vga_back.temp_restore_lock();
00490     vga_front.temp_restore_lock();
00491     // ###### end Gilbert 12/10 #######//
00492     //--------------------------------------//
00493 
00494     if( putBackCursor ) {
00495         // ##### begin Gilbert 24/04/2001 #####//
00496         if( restoreCursor ) {
00497             // %% Begin Ho 0909:: restore the damaged back buffer
00498             // vga_back.rest_area(mouse_back_buffer_storage_bitmap,0,0);
00499             // %%End Ho 0909
00500             vga_back.put_bitmapW( max(x1,mouse_cursor.cur_x1), max(y1,mouse_cursor.cur_y1),
00501                                   mouseBackBufferStorageBitmap );
00502             mouse_cursor.hide_area_flag = 0;            // do not call mouse.show_area() which will double paint the cursor
00503         }
00504         // ##### end Gilbert 24/04/2001 #####//
00505     }
00506     else {
00507         mouse.show_area();
00508     }
00509     return TRUE;
00510 }
00511 
00512 //---------- End of function Vga::blt_buf ----------//
00513 
00514 //----------- Begin of function Vga::d3_panel_up ------------//
00522 void Vga::d3_panel_up(int x1,int y1,int x2,int y2,int vgaFrontOnly,int drawBorderOnly) {
00523     err_when( x1>x2 || y1>y2 || x1<0 || y1<0 || x2>=VGA_WIDTH || y2>=VGA_HEIGHT );
00524 
00525     VgaBuf* vgaBuf;
00526 
00527     if( vgaFrontOnly )
00528         vgaBuf = &vga_front;
00529     else
00530         vgaBuf = &vga_back;
00531 
00532     if(sys.no_true_output_flag)
00533         vgaBuf = &vga_back;
00534 
00535     if( !drawBorderOnly ) {
00536         if( Vga::opaque_flag )
00537             vgaBuf->bar(x1+1, y1+1, x2-1, y2-1, UP_OPAQUE_COLOR);
00538         else
00539             vgaBuf->adjust_brightness(x1+1, y1+1, x2-1, y2-1, IF_UP_BRIGHTNESS_ADJUST);
00540     }
00541 
00542     mouse.hide_area( x1,y1,x2,y2 );
00543 
00544     //--------- white border on top and left sides -----------//
00545 
00546     // top side
00547     vgaBuf->bar_fast( x1+1,y1,x2,y1, IF_LIGHT_BORDER_COLOR );
00548     // left side
00549     vgaBuf->bar_fast( x1,y1,x1,y2  , IF_LIGHT_BORDER_COLOR );
00550 
00551     //--------- black border on bottom and right sides -----------//
00552 
00553     // bottom side
00554     vgaBuf->bar_fast( x1+1,y2,x2,y2, IF_DARK_BORDER_COLOR );
00555     // right side
00556     vgaBuf->bar_fast( x2,y1+1,x2,y2, IF_DARK_BORDER_COLOR );
00557 
00558     //-------------------------------------------//
00559 
00560     mouse.show_area();
00561 
00562     //----- blt the area from the back buffer to the front buffer ------//
00563 
00564     if( !vgaFrontOnly && !use_back_buf )            // only blt the back to the front is the active buffer is the front
00565         vga.blt_buf(x1, y1, x2, y2, 0);
00566 }
00567 
00568 //------------- End of function Vga::d3_panel_up ------------//
00569 
00570 //----------- Begin of function Vga::d3_panel_down ------------//
00578 void Vga::d3_panel_down(int x1,int y1,int x2,int y2,int vgaFrontOnly,int drawBorderOnly) {
00579     err_when( x1>x2 || y1>y2 || x1<0 || y1<0 || x2>=VGA_WIDTH || y2>=VGA_HEIGHT );
00580 
00581     VgaBuf* vgaBuf;
00582 
00583     if( vgaFrontOnly )
00584         vgaBuf = &vga_front;
00585     else
00586         vgaBuf = &vga_back;
00587 
00588     if(sys.no_true_output_flag)
00589         vgaBuf = &vga_back;
00590 
00591     if( !drawBorderOnly ) {
00592         if( Vga::opaque_flag )
00593             vgaBuf->bar(x1+1, y1+1, x2-1, y2-1, DOWN_OPAQUE_COLOR);
00594         else
00595             vgaBuf->adjust_brightness(x1+1, y1+1, x2-1, y2-1, IF_DOWN_BRIGHTNESS_ADJUST);
00596     }
00597 
00598     mouse.hide_area( x1,y1,x2,y2 );
00599 
00600     //--------- white border on top and left sides -----------//
00601 
00602     // top side
00603     vgaBuf->bar_fast( x1+1,y1,x2,y1, IF_DARK_BORDER_COLOR );
00604     // left side
00605     vgaBuf->bar_fast( x1,y1,x1,y2  , IF_DARK_BORDER_COLOR );
00606 
00607     //--------- black border on bottom and right sides -----------//
00608 
00609     // bottom side
00610     vgaBuf->bar_fast( x1+1,y2,x2,y2, IF_LIGHT_BORDER_COLOR );
00611     // right side
00612     vgaBuf->bar_fast( x2,y1+1,x2,y2, IF_LIGHT_BORDER_COLOR );
00613 
00614     //-------------------------------------------//
00615 
00616     mouse.show_area();
00617 
00618     //----- blt the area from the back buffer to the front buffer ------//
00619 
00620     if( !vgaFrontOnly && !use_back_buf )            // only blt the back to the front is the active buffer is the front
00621         vga.blt_buf(x1, y1, x2, y2, 0);
00622 }
00623 
00624 //------------- End of function Vga::d3_panel_down ------------//
00625 
00626 //----------- Begin of function Vga::d3_panel2_up ------------//
00634 void Vga::d3_panel2_up(int x1,int y1,int x2,int y2,int vgaFrontOnly,int drawBorderOnly) {
00635     err_when( x1>x2 || y1>y2 || x1<0 || y1<0 || x2>=VGA_WIDTH || y2>=VGA_HEIGHT );
00636 
00637     VgaBuf* vgaBuf;
00638 
00639     if( vgaFrontOnly )
00640         vgaBuf = &vga_front;
00641     else
00642         vgaBuf = &vga_back;
00643 
00644     if(sys.no_true_output_flag)
00645         vgaBuf = &vga_back;
00646 
00647     if( !drawBorderOnly )
00648         vgaBuf->adjust_brightness(x1+2, y1+2, x2-3, y2-3, IF_UP_BRIGHTNESS_ADJUST);
00649 
00650     mouse.hide_area( x1,y1,x2,y2 );
00651 
00652     //--------- white border on top and left sides -----------//
00653 
00654     vgaBuf->bar_fast( x1,y1,x2-3,y1+1,0x9a );
00655     vgaBuf->draw_pixel(x2-2, y1, 0x9a);
00656     vgaBuf->bar_fast( x1,y1+2,x1+1,y2-3, 0x9a );    // left side
00657     vgaBuf->draw_pixel(x1, y2-2, 0x9a);
00658 
00659     //--------- black border on bottom and right sides -----------//
00660 
00661     vgaBuf->bar_fast( x2-2,y1+2,x2-1,y2-1, 0x90 );  // bottom side
00662     vgaBuf->draw_pixel(x2-1, y1+1, 0x90);
00663     vgaBuf->bar_fast( x1+2,y2-2,x2-3,y2-1, 0x90 );  // right side
00664     vgaBuf->draw_pixel(x1+1, y2-1, 0x90);
00665 
00666     //--------- junction between white and black border --------//
00667     vgaBuf->draw_pixel(x2-1, y1, 0x97);
00668     vgaBuf->draw_pixel(x2-2, y1+1, 0x97);
00669     vgaBuf->draw_pixel(x1, y2-1, 0x97);
00670     vgaBuf->draw_pixel(x1+1, y2-2, 0x97);
00671 
00672     //--------- gray shadow on bottom and right sides -----------//
00673     vgaBuf->bar_fast( x2, y1+1, x2, y2, 0x97);
00674     vgaBuf->bar_fast( x1+1, y2, x2-1, y2, 0x97);
00675 
00676     //-------------------------------------------//
00677 
00678     mouse.show_area();
00679 
00680     //----- blt the area from the back buffer to the front buffer ------//
00681 
00682     if( !vgaFrontOnly && !use_back_buf )            // only blt the back to the front is the active buffer is the front
00683         vga.blt_buf(x1, y1, x2, y2, 0);
00684 }
00685 
00686 //------------- End of function Vga::d3_panel_up ------------//
00687 
00688 //----------- Begin of function Vga::d3_panel2_down ------------//
00696 void Vga::d3_panel2_down(int x1,int y1,int x2,int y2,int vgaFrontOnly,int drawBorderOnly) {
00697     err_when( x1>x2 || y1>y2 || x1<0 || y1<0 || x2>=VGA_WIDTH || y2>=VGA_HEIGHT );
00698 
00699     VgaBuf* vgaBuf;
00700 
00701     if( vgaFrontOnly )
00702         vgaBuf = &vga_front;
00703     else
00704         vgaBuf = &vga_back;
00705 
00706     if(sys.no_true_output_flag)
00707         vgaBuf = &vga_back;
00708 
00709     if( !drawBorderOnly )
00710         vgaBuf->adjust_brightness(x1+2, y1+2, x2-3, y2-3, IF_DOWN_BRIGHTNESS_ADJUST);
00711 
00712     mouse.hide_area( x1,y1,x2,y2 );
00713 
00714     //--------- black border on top and left sides -----------//
00715 
00716     vgaBuf->bar_fast( x1,y1,x2-3,y1+1,0x90 );
00717     vgaBuf->draw_pixel(x2-2, y1, 0x90);
00718     vgaBuf->bar_fast( x1,y1+2,x1+1,y2-3, 0x90 );    // left side
00719     vgaBuf->draw_pixel(x1, y2-2, 0x90);
00720 
00721     //--------- while border on bottom and right sides -----------//
00722 
00723     vgaBuf->bar_fast( x2-2,y1+2,x2-1,y2-1, 0x9a );  // bottom side
00724     vgaBuf->draw_pixel(x2-1, y1+1, 0x9a);
00725     vgaBuf->bar_fast( x1+2,y2-2,x2-3,y2-1, 0x9a );  // right side
00726     vgaBuf->draw_pixel(x1+1, y2-1, 0x9a);
00727 
00728     //--------- junction between white and black border --------//
00729     vgaBuf->draw_pixel(x2-1, y1, 0x97);
00730     vgaBuf->draw_pixel(x2-2, y1+1, 0x97);
00731     vgaBuf->draw_pixel(x1, y2-1, 0x97);
00732     vgaBuf->draw_pixel(x1+1, y2-2, 0x97);
00733 
00734     //--------- remove shadow, copy from back  -----------//
00735     vgaBuf->bar_fast( x2, y1+1, x2, y2, 0x9c);
00736     vgaBuf->bar_fast( x1+1, y2, x2-1, y2, 0x9c);
00737 
00738     mouse.show_area();
00739 
00740     //----- blt the area from the back buffer to the front buffer ------//
00741 
00742     if( !vgaFrontOnly && !use_back_buf )            // only blt the back to the front is the active buffer is the front
00743         vga.blt_buf(x1, y1, x2, y2, 0);
00744 }
00745 
00746 //------------- End of function Vga::d3_panel2_down ------------//
00747 
00748 //------------- Start of function Vga::separator --------------//
00749 //
00750 // Draw a VGA separator line
00751 //
00752 // Syntax : separator( x1, y1, x2, y2 )
00753 //
00754 // int x1,y1       - the top left vertex of the separator
00755 // int x2,y2       - the bottom right vertex of the separator
00756 //
00757 void Vga::separator(int x1, int y1, int x2, int y2) {
00758     err_when( x1>x2 || y1>y2 || x1<0 || y1<0 || x2>=VGA_WIDTH || y2>=VGA_HEIGHT );
00759 
00760     if( y1+1==y2 ) {                                // horizontal line
00761         vga_front.adjust_brightness(x1, y1, x2, y1, IF_UP_BRIGHTNESS_ADJUST);
00762         vga_front.adjust_brightness(x1, y2, x2, y2, IF_DOWN_BRIGHTNESS_ADJUST);
00763     }
00764     else {
00765         vga_front.adjust_brightness(x1, y1, x1, y2, IF_UP_BRIGHTNESS_ADJUST);
00766         vga_front.adjust_brightness(x2, y1, x2, y2, IF_DOWN_BRIGHTNESS_ADJUST);
00767     }
00768 }
00769 
00770 //--------------- End of function Vga::separator --------------//
00771 
00772 //----------- Begin of function Vga::init_gray_remap_table ----------//
00776 void Vga::init_gray_remap_table() {
00777     //------ create a color to gray-scale remap table ------//
00778 
00779 #define FIRST_GRAY_COLOR   0x90
00780 #define GRAY_SCALE_COUNT   16                   // no. of gray colors
00781 
00782     // #define FIRST_GRAY_COLOR   0x96
00783     // #define GRAY_SCALE_COUNT   10    // no. of gray colors
00784 
00785     PALETTEENTRY* palEntry = vga.pal_entry_buf;
00786     int i, grayIndex;
00787 
00788     for( i=0 ; i<256 ; i++, palEntry++ ) {
00789         //--------------------------------------------------------//
00790         //
00791         // How to calculate the gray index (0-31)
00792         //
00793         // formula is : grey = red * 0.3 + green * 0.59 + blue * 0.11
00794         //              the range of the result value is 0-255
00795         //              this value is then divided by 8 to 0-31
00796         //
00797         //--------------------------------------------------------//
00798 
00799         grayIndex = ((int)palEntry->peRed * 30 + (int)palEntry->peGreen * 59 +
00800                      (int)palEntry->peBlue * 11) / 100 / (256/GRAY_SCALE_COUNT);
00801 
00802         gray_remap_table[i] = FIRST_GRAY_COLOR + grayIndex;
00803     }
00804 }
00805 
00806 //--------- End of function Vga::init_gray_remap_table -----------//
00807 
00808 int Vga::make_pixel(BYTE red, BYTE green, BYTE blue) {
00809     return IMGmakePixel((blue << 16) + (green << 8) + red);
00810 }
00811 
00812 int Vga::make_pixel(RGBColor *rgb) {
00813     int u;
00814     memcpy(&u, rgb, sizeof(RGBColor));
00815     return IMGmakePixel(u);
00816 }
00817 
00818 void Vga::decode_pixel(int p, RGBColor *rgb) {
00819     int u = IMGdecodePixel(p);
00820     memcpy(rgb, &u, sizeof(RGBColor));
00821 }

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