OVGA.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. /*
  2. * Seven Kingdoms: Ancient Adversaries
  3. *
  4. * Copyright 1997,1998 Enlight Software Ltd.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. //Filename : OVGA.CPP
  21. //Description : VGA manipulation functions (Direct Draw version)
  22. #define DEBUG_LOG_LOCAL 1
  23. #include <windowsx.h>
  24. #include <ALL.h>
  25. #include <IMGFUN.h>
  26. #include <OMOUSE.h>
  27. #include <OMOUSECR.h>
  28. #include <OCOLTBL.h>
  29. #include <OFILE.h>
  30. #include <OSYS.h>
  31. #include <OVGA.h>
  32. #include <OLOG.h>
  33. // ##### begin Gilbert 16/9 #######//
  34. #include <OVGALOCK.h>
  35. // ##### end Gilbert 16/9 #######//
  36. //-------- Define constant --------//
  37. #define UP_OPAQUE_COLOR (VGA_GRAY+10)
  38. #define DOWN_OPAQUE_COLOR (VGA_GRAY+13)
  39. //------ Define static class member vars ---------//
  40. char Vga::use_back_buf = 0;
  41. char Vga::opaque_flag = 0;
  42. VgaBuf* Vga::active_buf = &vga_front; // default: front buffer
  43. char low_video_memory_flag = 0;
  44. //-------- Begin of function Vga::Vga ----------//
  45. Vga::Vga()
  46. {
  47. memset( this, 0, sizeof(Vga) );
  48. vga_color_table = new ColorTable;
  49. }
  50. //-------- End of function Vga::Vga ----------//
  51. //-------- Begin of function Vga::~Vga ----------//
  52. Vga::~Vga()
  53. {
  54. deinit(); // 1-is final
  55. delete vga_color_table;
  56. err_when( back_up_pal ); // this must be free up immediately after its use
  57. }
  58. //-------- End of function Vga::~Vga ----------//
  59. //-------- Begin of function Vga::init ----------//
  60. BOOL Vga::init()
  61. {
  62. char* warnStr = "Warning: Due to the low memory of your display card, "
  63. "you may experience problems when you quit the game or "
  64. "switch tasks during the game. "
  65. "To avoid this problem, set your Windows display "
  66. "to 800x600 256 color mode before running the game.";
  67. //--------- Initialize DirectDraw object --------//
  68. if( !init_dd() )
  69. return FALSE;
  70. // get current display mode
  71. DDSURFACEDESC ddsd;
  72. DDSCAPS ddsCaps;
  73. DWORD dwTotal;
  74. DWORD dwFree;
  75. memset(&ddsd, 0, sizeof(ddsd) );
  76. ddsd.dwSize = sizeof(ddsd);
  77. ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY;
  78. if( dd_obj->GetDisplayMode(&ddsd) == DD_OK &&
  79. dd_obj->GetAvailableVidMem(&ddsCaps, &dwTotal, &dwFree) == DD_OK )
  80. {
  81. if( dwFree < VGA_WIDTH*VGA_HEIGHT*VGA_BPP/8 &&
  82. !(ddsd.dwWidth==VGA_WIDTH && ddsd.dwHeight==VGA_HEIGHT && (ddsd.ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED8)) )
  83. {
  84. // not enough memory except same video mode
  85. ShowCursor(TRUE);
  86. // approximation of video memory required, actual video memory used should be calculated from vga_(true)_front->buf_pitch()
  87. extern char new_config_dat_flag;
  88. if( new_config_dat_flag )
  89. {
  90. MessageBox(sys.main_hwnd, warnStr,
  91. WIN_TITLE, MB_OK | MB_ICONWARNING | MB_SETFOREGROUND );
  92. }
  93. low_video_memory_flag = 1;
  94. ShowCursor(FALSE);
  95. }
  96. }
  97. if( !set_mode() )
  98. {
  99. MessageBox( sys.main_hwnd,
  100. "Unable to change to 800x600x8bpp video mode. "
  101. "Your display might not support this video mode.",
  102. WIN_TITLE,
  103. MB_OK | MB_ICONWARNING | MB_SETFOREGROUND );
  104. return FALSE;
  105. }
  106. return TRUE;
  107. }
  108. //-------- End of function Vga::init ----------//
  109. //-------- Begin of function Vga::init_dd ----------//
  110. BOOL Vga::init_dd()
  111. {
  112. if(dd_obj) // the Direct Draw object has been initialized already
  113. return TRUE;
  114. //--------- Create direct draw object --------//
  115. DEBUG_LOG("Attempt DirectDrawCreate");
  116. LPDIRECTDRAW dd1Obj;
  117. int rc = DirectDrawCreate( NULL, &dd1Obj, NULL );
  118. DEBUG_LOG("DirectDrawCreate finish");
  119. if( rc != DD_OK )
  120. {
  121. #ifdef DEBUG
  122. debug_msg("DirectDrawCreate failed err=%d", rc);
  123. #endif
  124. return FALSE;
  125. }
  126. //-------- Query DirectDraw2 interface --------//
  127. DEBUG_LOG("Attempt Query DirectDraw2");
  128. rc = dd1Obj->QueryInterface(IID_IDirectDraw2, (void **)&dd_obj);
  129. DEBUG_LOG("Query DirectDraw2 finish");
  130. if( rc != DD_OK )
  131. {
  132. #ifdef DEBUG
  133. debug_msg("Query DirectDraw2 failed err=%d", rc);
  134. #endif
  135. dd1Obj->Release();
  136. return FALSE;
  137. }
  138. dd1Obj->Release();
  139. return TRUE;
  140. }
  141. //-------- End of function Vga::init_dd ----------//
  142. //-------- Begin of function Vga::set_mode ----------//
  143. BOOL Vga::set_mode()
  144. {
  145. DWORD dwStyle;
  146. HRESULT rc;
  147. //-----------------------------------------------------------//
  148. // Convert it to a plain window
  149. //-----------------------------------------------------------//
  150. dwStyle = GetWindowStyle(sys.main_hwnd);
  151. dwStyle |= WS_POPUP;
  152. dwStyle &= ~(WS_OVERLAPPED | WS_CAPTION | WS_THICKFRAME | WS_MINIMIZEBOX);
  153. SetWindowLong(sys.main_hwnd, GWL_STYLE, dwStyle);
  154. //-----------------------------------------------------------//
  155. // grab exclusive mode if we are going to run as fullscreen
  156. // otherwise grab normal mode.
  157. //-----------------------------------------------------------//
  158. DEBUG_LOG("Attempt DirectDraw SetCooperativeLevel");
  159. rc = dd_obj->SetCooperativeLevel( sys.main_hwnd,
  160. DDSCL_EXCLUSIVE |
  161. DDSCL_FULLSCREEN );
  162. DEBUG_LOG("DirectDraw SetCooperativeLevel finish");
  163. if( rc != DD_OK )
  164. {
  165. #ifdef DEBUG
  166. debug_msg("SetCooperativeLevel failed err=%d", rc);
  167. #endif
  168. return FALSE;
  169. }
  170. //-------------- set Direct Draw mode ---------------//
  171. DEBUG_LOG("Attempt DirectDraw SetDisplayMode");
  172. // ###### begin Gilbert 25/7 #######//
  173. // IDirectDraw2::SetDisplayMode requires 5 parameters
  174. rc = dd_obj->SetDisplayMode( VGA_WIDTH, VGA_HEIGHT, VGA_BPP, 0, 0);
  175. // ###### end Gilbert 25/7 #######//
  176. DEBUG_LOG("DirectDraw SetDisplayMode finish");
  177. if( rc != DD_OK )
  178. {
  179. #ifdef DEBUG
  180. debug_msg("SetMode failed err=%d", rc);
  181. #endif
  182. return FALSE;
  183. }
  184. //----------- display the system cursor -------------//
  185. SetCursor(NULL);
  186. return TRUE;
  187. }
  188. //-------- End of function Vga::set_mode ----------//
  189. //-------- Begin of function Vga::deinit ----------//
  190. void Vga::deinit()
  191. {
  192. release_pal();
  193. if( dd_obj )
  194. {
  195. //DEBUG_LOG("Attempt vga.dd_obj->RestoreDisplayMode()");
  196. // dd_obj->RestoreDisplayMode();
  197. //DEBUG_LOG("vga.dd_obj->RestoreDisplayMode() finish");
  198. DEBUG_LOG("Attempt vga.dd_obj->Release()");
  199. dd_obj->Release();
  200. DEBUG_LOG("vga.dd_obj->Release() finish");
  201. dd_obj = NULL;
  202. }
  203. }
  204. //-------- End of function Vga::deinit ----------//
  205. //--------- Start of function Vga::load_pal ----------//
  206. //
  207. // Load the palette from a file and set it to the front buf.
  208. //
  209. BOOL Vga::load_pal(char* fileName)
  210. {
  211. char palBuf[256][3];
  212. File palFile;
  213. palFile.file_open(fileName);
  214. palFile.file_seek(8); // bypass the header info
  215. palFile.file_read(palBuf, 256*3);
  216. palFile.file_close();
  217. //--- Create a Direct Draw Palette and associate it with the front buffer ---//
  218. if( dd_pal == NULL )
  219. {
  220. for(int i=0; i<256; i++)
  221. {
  222. pal_entry_buf[i].peRed = palBuf[i][0];
  223. pal_entry_buf[i].peGreen = palBuf[i][1];
  224. pal_entry_buf[i].peBlue = palBuf[i][2];
  225. }
  226. HRESULT rc = dd_obj->CreatePalette( DDPCAPS_8BIT, pal_entry_buf, &dd_pal, NULL );
  227. if( rc != DD_OK )
  228. return FALSE;
  229. }
  230. init_color_table();
  231. init_gray_remap_table();
  232. return TRUE;
  233. }
  234. //----------- End of function Vga::load_pal ----------//
  235. //--------- Start of function Vga::init_color_table ----------//
  236. void Vga::init_color_table()
  237. {
  238. //----- initialize interface color table -----//
  239. PalDesc palDesc( (unsigned char*) pal_entry_buf, sizeof(PALETTEENTRY), 256, 8);
  240. vga_color_table->generate_table( MAX_BRIGHTNESS_ADJUST_DEGREE, palDesc, ColorTable::bright_func );
  241. }
  242. //----------- End of function Vga::init_color_table ----------//
  243. //--------- Start of function Vga::release_pal ----------//
  244. void Vga::release_pal()
  245. {
  246. // ##### begin Gilbert 16/9 #######//
  247. if( dd_pal )
  248. {
  249. while( dd_pal->Release() );
  250. dd_pal = NULL;
  251. }
  252. // ##### end Gilbert 16/9 #######//
  253. }
  254. //----------- End of function Vga::release_pal ----------//
  255. //-------- Begin of function Vga::activate_pal ----------//
  256. //
  257. // we are getting the palette focus, select our palette
  258. //
  259. void Vga::activate_pal(VgaBuf* vgaBufPtr)
  260. {
  261. vgaBufPtr->activate_pal(dd_pal);
  262. }
  263. //--------- End of function Vga::activate_pal ----------//
  264. //-------- Begin of function Vga::adjust_brightness ----------//
  265. //
  266. // <int> changeValue - the value to add to the RGB values of
  267. // all the colors in the palette.
  268. // the value can be from -255 to 255.
  269. //
  270. // <int> preserveContrast - whether preserve the constrast or not
  271. //
  272. void Vga::adjust_brightness(int changeValue)
  273. {
  274. //---- find out the maximum rgb value can change without affecting the contrast ---//
  275. int i;
  276. int newRed, newGreen, newBlue;
  277. PALETTEENTRY palBuf[256];
  278. //------------ change palette now -------------//
  279. for( i=0 ; i<256 ; i++ )
  280. {
  281. newRed = (int)pal_entry_buf[i].peRed + changeValue;
  282. newGreen = (int)pal_entry_buf[i].peGreen + changeValue;
  283. newBlue = (int)pal_entry_buf[i].peBlue + changeValue;
  284. palBuf[i].peRed = min(255, max(newRed,0) );
  285. palBuf[i].peGreen = min(255, max(newGreen,0) );
  286. palBuf[i].peBlue = min(255, max(newBlue,0) );
  287. }
  288. //------------ set palette ------------//
  289. vga_front.temp_unlock();
  290. dd_pal->SetEntries( 0, 0, 256, palBuf );
  291. vga_front.temp_restore_lock();
  292. }
  293. //--------- End of function Vga::adjust_brightness ----------//
  294. //--------- Begin of function Vga::blt_buf ----------//
  295. //
  296. // Blt the back buffer to the front buffer.
  297. //
  298. // <int> x1, y1, x2, y2 - the coordinations of the area to be blit
  299. // [int] putBackCursor - whether put a mouse cursor onto the back buffer
  300. // before blitting.
  301. // (default: 1)
  302. //
  303. BOOL Vga::blt_buf(int x1, int y1, int x2, int y2, int putBackCursor)
  304. {
  305. if( putBackCursor )
  306. {
  307. mouse_cursor.hide_area_flag = 0; // do not call mouse.hide_area() which will double paint the cursor
  308. mouse_cursor.hide_x1 = x1;
  309. mouse_cursor.hide_y1 = y1;
  310. mouse_cursor.hide_x2 = x2;
  311. mouse_cursor.hide_y2 = y2;
  312. //-------- put mouse cursor ---------//
  313. mouse_cursor.disp_back_buf(x1, y1, x2, y2);
  314. }
  315. else
  316. {
  317. mouse.hide_area(x1, y1, x2, y2);
  318. }
  319. //--------------------------------------//
  320. IMGcopy( vga_front.buf_ptr(), vga_front.buf_pitch(),
  321. vga_back.buf_ptr(), vga_back.buf_pitch(), x1, y1, x2, y2 );
  322. //--------------------------------------//
  323. if( putBackCursor )
  324. mouse_cursor.hide_area_flag = 0; // do not call mouse.show_area() which will double paint the cursor
  325. else
  326. mouse.show_area();
  327. return TRUE;
  328. }
  329. //---------- End of function Vga::blt_buf ----------//
  330. //----------- Begin of function Vga::d3_panel_up ------------//
  331. //
  332. // <int> x1,y1,x2,y2 = the four vertex of the panel
  333. // [int] vgaFrontOnly = do all the bitmap processing on the front buffer only
  334. // (default: 0)
  335. // [int] drawBorderOnly = draw border only, do not brighten the center area
  336. // (default: 0)
  337. //
  338. void Vga::d3_panel_up(int x1,int y1,int x2,int y2,int vgaFrontOnly,int drawBorderOnly)
  339. {
  340. err_when( x1>x2 || y1>y2 || x1<0 || y1<0 || x2>=VGA_WIDTH || y2>=VGA_HEIGHT );
  341. VgaBuf* vgaBuf;
  342. if( vgaFrontOnly )
  343. vgaBuf = &vga_front;
  344. else
  345. vgaBuf = &vga_back;
  346. if( !drawBorderOnly )
  347. {
  348. if( Vga::opaque_flag )
  349. vgaBuf->bar(x1+1, y1+1, x2-1, y2-1, UP_OPAQUE_COLOR);
  350. else
  351. vgaBuf->adjust_brightness(x1+1, y1+1, x2-1, y2-1, IF_UP_BRIGHTNESS_ADJUST);
  352. }
  353. mouse.hide_area( x1,y1,x2,y2 );
  354. //--------- white border on top and left sides -----------//
  355. IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x1+1,y1,x2,y1, IF_LIGHT_BORDER_COLOR ); // top side
  356. IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x1,y1,x1,y2 , IF_LIGHT_BORDER_COLOR ); // left side
  357. //--------- black border on bottom and right sides -----------//
  358. IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x1+1,y2,x2,y2, IF_DARK_BORDER_COLOR ); // bottom side
  359. IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x2,y1+1,x2,y2, IF_DARK_BORDER_COLOR ); // right side
  360. //-------------------------------------------//
  361. mouse.show_area();
  362. //----- blt the area from the back buffer to the front buffer ------//
  363. if( !vgaFrontOnly && !use_back_buf ) // only blt the back to the front is the active buffer is the front
  364. vga.blt_buf(x1, y1, x2, y2, 0);
  365. }
  366. //------------- End of function Vga::d3_panel_up ------------//
  367. //----------- Begin of function Vga::d3_panel_down ------------//
  368. //
  369. // <int> x1,y1,x2,y2 = the four vertex of the panel
  370. // [int] vgaFrontOnly = do all the bitmap processing on the front buffer only
  371. // (default: 0)
  372. // [int] drawBorderOnly = draw border only, do not brighten the center area
  373. // (default: 0)
  374. //
  375. void Vga::d3_panel_down(int x1,int y1,int x2,int y2,int vgaFrontOnly,int drawBorderOnly)
  376. {
  377. err_when( x1>x2 || y1>y2 || x1<0 || y1<0 || x2>=VGA_WIDTH || y2>=VGA_HEIGHT );
  378. VgaBuf* vgaBuf;
  379. if( vgaFrontOnly )
  380. vgaBuf = &vga_front;
  381. else
  382. vgaBuf = &vga_back;
  383. if( !drawBorderOnly )
  384. {
  385. if( Vga::opaque_flag )
  386. vgaBuf->bar(x1+1, y1+1, x2-1, y2-1, DOWN_OPAQUE_COLOR);
  387. else
  388. vgaBuf->adjust_brightness(x1+1, y1+1, x2-1, y2-1, IF_DOWN_BRIGHTNESS_ADJUST);
  389. }
  390. mouse.hide_area( x1,y1,x2,y2 );
  391. //--------- white border on top and left sides -----------//
  392. IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x1+1,y1,x2,y1, IF_DARK_BORDER_COLOR ); // top side
  393. IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x1,y1,x1,y2 , IF_DARK_BORDER_COLOR ); // left side
  394. //--------- black border on bottom and right sides -----------//
  395. IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x1+1,y2,x2,y2, IF_LIGHT_BORDER_COLOR ); // bottom side
  396. IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x2,y1+1,x2,y2, IF_LIGHT_BORDER_COLOR ); // right side
  397. //-------------------------------------------//
  398. mouse.show_area();
  399. //----- blt the area from the back buffer to the front buffer ------//
  400. if( !vgaFrontOnly && !use_back_buf ) // only blt the back to the front is the active buffer is the front
  401. vga.blt_buf(x1, y1, x2, y2, 0);
  402. }
  403. //------------- End of function Vga::d3_panel_down ------------//
  404. //----------- Begin of function Vga::d3_panel2_up ------------//
  405. //
  406. // <int> x1,y1,x2,y2 = the four vertex of the panel
  407. // [int] vgaFrontOnly = do all the bitmap processing on the front buffer only
  408. // (default: 0)
  409. // [int] drawBorderOnly = draw border only, do not brighten the center area
  410. // (default: 0)
  411. //
  412. void Vga::d3_panel2_up(int x1,int y1,int x2,int y2,int vgaFrontOnly,int drawBorderOnly)
  413. {
  414. err_when( x1>x2 || y1>y2 || x1<0 || y1<0 || x2>=VGA_WIDTH || y2>=VGA_HEIGHT );
  415. VgaBuf* vgaBuf;
  416. if( vgaFrontOnly )
  417. vgaBuf = &vga_front;
  418. else
  419. vgaBuf = &vga_back;
  420. if( !drawBorderOnly )
  421. vgaBuf->adjust_brightness(x1+2, y1+2, x2-3, y2-3, IF_UP_BRIGHTNESS_ADJUST);
  422. mouse.hide_area( x1,y1,x2,y2 );
  423. //--------- white border on top and left sides -----------//
  424. IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x1,y1,x2-3,y1+1,0x9a );
  425. vgaBuf->draw_pixel(x2-2, y1, 0x9a);
  426. IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x1,y1+2,x1+1,y2-3, 0x9a ); // left side
  427. vgaBuf->draw_pixel(x1, y2-2, 0x9a);
  428. //--------- black border on bottom and right sides -----------//
  429. IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x2-2,y1+2,x2-1,y2-1, 0x90 ); // bottom side
  430. vgaBuf->draw_pixel(x2-1, y1+1, 0x90);
  431. IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x1+2,y2-2,x2-3,y2-1, 0x90 ); // right side
  432. vgaBuf->draw_pixel(x1+1, y2-1, 0x90);
  433. //--------- junction between white and black border --------//
  434. vgaBuf->draw_pixel(x2-1, y1, 0x97);
  435. vgaBuf->draw_pixel(x2-2, y1+1, 0x97);
  436. vgaBuf->draw_pixel(x1, y2-1, 0x97);
  437. vgaBuf->draw_pixel(x1+1, y2-2, 0x97);
  438. //--------- gray shadow on bottom and right sides -----------//
  439. IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x2, y1+1, x2, y2, 0x97);
  440. IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x1+1, y2, x2-1, y2, 0x97);
  441. //-------------------------------------------//
  442. mouse.show_area();
  443. //----- blt the area from the back buffer to the front buffer ------//
  444. if( !vgaFrontOnly && !use_back_buf ) // only blt the back to the front is the active buffer is the front
  445. vga.blt_buf(x1, y1, x2, y2, 0);
  446. }
  447. //------------- End of function Vga::d3_panel_up ------------//
  448. //----------- Begin of function Vga::d3_panel2_down ------------//
  449. //
  450. // <int> x1,y1,x2,y2 = the four vertex of the panel
  451. // [int] vgaFrontOnly = do all the bitmap processing on the front buffer only
  452. // (default: 0)
  453. // [int] drawBorderOnly = draw border only, do not brighten the center area
  454. // (default: 0)
  455. //
  456. void Vga::d3_panel2_down(int x1,int y1,int x2,int y2,int vgaFrontOnly,int drawBorderOnly)
  457. {
  458. err_when( x1>x2 || y1>y2 || x1<0 || y1<0 || x2>=VGA_WIDTH || y2>=VGA_HEIGHT );
  459. VgaBuf* vgaBuf;
  460. if( vgaFrontOnly )
  461. vgaBuf = &vga_front;
  462. else
  463. vgaBuf = &vga_back;
  464. if( !drawBorderOnly )
  465. vgaBuf->adjust_brightness(x1+2, y1+2, x2-3, y2-3, IF_DOWN_BRIGHTNESS_ADJUST);
  466. mouse.hide_area( x1,y1,x2,y2 );
  467. //--------- black border on top and left sides -----------//
  468. IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x1,y1,x2-3,y1+1,0x90 );
  469. vgaBuf->draw_pixel(x2-2, y1, 0x90);
  470. IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x1,y1+2,x1+1,y2-3, 0x90 ); // left side
  471. vgaBuf->draw_pixel(x1, y2-2, 0x90);
  472. //--------- while border on bottom and right sides -----------//
  473. IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x2-2,y1+2,x2-1,y2-1, 0x9a ); // bottom side
  474. vgaBuf->draw_pixel(x2-1, y1+1, 0x9a);
  475. IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x1+2,y2-2,x2-3,y2-1, 0x9a ); // right side
  476. vgaBuf->draw_pixel(x1+1, y2-1, 0x9a);
  477. //--------- junction between white and black border --------//
  478. vgaBuf->draw_pixel(x2-1, y1, 0x97);
  479. vgaBuf->draw_pixel(x2-2, y1+1, 0x97);
  480. vgaBuf->draw_pixel(x1, y2-1, 0x97);
  481. vgaBuf->draw_pixel(x1+1, y2-2, 0x97);
  482. //--------- remove shadow, copy from back -----------//
  483. IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x2, y1+1, x2, y2, 0x9c);
  484. IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x1+1, y2, x2-1, y2, 0x9c);
  485. mouse.show_area();
  486. //----- blt the area from the back buffer to the front buffer ------//
  487. if( !vgaFrontOnly && !use_back_buf ) // only blt the back to the front is the active buffer is the front
  488. vga.blt_buf(x1, y1, x2, y2, 0);
  489. }
  490. //------------- End of function Vga::d3_panel2_down ------------//
  491. //------------- Start of function Vga::separator --------------//
  492. //
  493. // Draw a VGA separator line
  494. //
  495. // Syntax : separator( x1, y1, x2, y2 )
  496. //
  497. // int x1,y1 - the top left vertex of the separator
  498. // int x2,y2 - the bottom right vertex of the separator
  499. //
  500. void Vga::separator(int x1, int y1, int x2, int y2)
  501. {
  502. err_when( x1>x2 || y1>y2 || x1<0 || y1<0 || x2>=VGA_WIDTH || y2>=VGA_HEIGHT );
  503. if( y1+1==y2 ) // horizontal line
  504. {
  505. vga_front.adjust_brightness(x1, y1, x2, y1, IF_UP_BRIGHTNESS_ADJUST);
  506. vga_front.adjust_brightness(x1, y2, x2, y2, IF_DOWN_BRIGHTNESS_ADJUST);
  507. }
  508. else
  509. {
  510. vga_front.adjust_brightness(x1, y1, x1, y2, IF_UP_BRIGHTNESS_ADJUST);
  511. vga_front.adjust_brightness(x2, y1, x2, y2, IF_DOWN_BRIGHTNESS_ADJUST);
  512. }
  513. }
  514. //--------------- End of function Vga::separator --------------//
  515. //----------- Begin of function Vga::init_gray_remap_table ----------//
  516. //
  517. // Initialize a gray remap table for VgaBuf::convert_gray to use.
  518. //
  519. void Vga::init_gray_remap_table()
  520. {
  521. //------ create a color to gray-scale remap table ------//
  522. #define FIRST_GRAY_COLOR 0x90
  523. #define GRAY_SCALE_COUNT 16 // no. of gray colors
  524. // #define FIRST_GRAY_COLOR 0x96
  525. // #define GRAY_SCALE_COUNT 10 // no. of gray colors
  526. PALETTEENTRY* palEntry = vga.pal_entry_buf;
  527. int i, grayIndex;
  528. for( i=0 ; i<256 ; i++, palEntry++ )
  529. {
  530. //--------------------------------------------------------//
  531. //
  532. // How to calculate the gray index (0-31)
  533. //
  534. // formula is : grey = red * 0.3 + green * 0.59 + blue * 0.11
  535. // the range of the result value is 0-255
  536. // this value is then divided by 8 to 0-31
  537. //
  538. //--------------------------------------------------------//
  539. grayIndex = ((int)palEntry->peRed * 30 + (int)palEntry->peGreen * 59 +
  540. (int)palEntry->peBlue * 11) / 100 / (256/GRAY_SCALE_COUNT);
  541. gray_remap_table[i] = FIRST_GRAY_COLOR + grayIndex;
  542. }
  543. }
  544. //--------- End of function Vga::init_gray_remap_table -----------//