OVGABUF2.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873
  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 : OVGABUF2.CPP
  21. //Description : OVGABUF direct draw surface class - part 2
  22. #include <ALL.h>
  23. #include <IMGFUN.h>
  24. #include <OMOUSE.h>
  25. #include <OPOWER.h>
  26. #include <OCOLTBL.h>
  27. #include <OVGA.h>
  28. #include <OVGABUF.h>
  29. #include <OIMGRES.h>
  30. #include <OFONT.h>
  31. //------- Define static class member vars ---------//
  32. char VgaBuf::color_light =(char)0x9E; // color of the light panel side
  33. char VgaBuf::color_dark =(char)0x99; // color of the dark panel side
  34. char VgaBuf::color_up =(char)0x9D; // color of up_panel surface
  35. char VgaBuf::color_down =(char)0x9C; // color of down_panel surface
  36. char VgaBuf::color_push =(char)0x9B; // color of pushed button surface
  37. char VgaBuf::color_border=(char)0x98; // color of the border
  38. //------------- Begin of function VgaBuf::bar --------------//
  39. //
  40. // Draw a bar without bliting
  41. //
  42. // Syntax : bar( x1, y1, x2, y2, color )
  43. //
  44. // <int> x1,y1 - the top left vertex of the bar
  45. // <int> x2,y2 - the bottom right vertex of the bar
  46. // <int> color index - the index of a 256 color palette
  47. //
  48. void VgaBuf::bar(int x1,int y1,int x2,int y2,int colorCode)
  49. {
  50. err_when( !buf_locked );
  51. if( is_front )
  52. mouse.hide_area(x1,y1,x2,y2);
  53. IMGbar(buf_ptr(), buf_pitch(), x1, y1, x2, y2, colorCode);
  54. if( is_front )
  55. mouse.show_area();
  56. }
  57. //--------------- End of function VgaBuf::bar --------------//
  58. //------------- Begin of function VgaBuf::pixelize --------------//
  59. //
  60. // Put an area of evenly distributed pixels on the given area.
  61. //
  62. // <int> x1,y1 - the top left vertex of the bar
  63. // <int> x2,y2 - the bottom right vertex of the bar
  64. // <int> colorCode - colorCode of the pixels
  65. //
  66. void VgaBuf::pixelize(int x1,int y1,int x2,int y2,int colorCode)
  67. {
  68. err_when( !buf_locked );
  69. if( is_front )
  70. mouse.hide_area(x1,y1,x2,y2);
  71. //---------------------------------------//
  72. // ###### begin Gilbert 7/7 #########//
  73. int bufPitch = buf_pitch();
  74. int x, y, lineRemainBytes = bufPitch - (x2-x1+1);
  75. char* writePtr = buf_ptr() + bufPitch * y1 + x1;
  76. for( y=y1 ; y<=y2 ; y++ )
  77. {
  78. if( y&1 )
  79. {
  80. writePtr+=bufPitch;
  81. }
  82. else
  83. {
  84. for( x=x1 ; x<=x2 ; x++, writePtr++ )
  85. {
  86. if( x&1 )
  87. *writePtr = colorCode;
  88. }
  89. writePtr+=lineRemainBytes;
  90. }
  91. }
  92. // ###### end Gilbert 7/7 #########//
  93. //---------------------------------------//
  94. if( is_front )
  95. mouse.show_area();
  96. }
  97. //--------------- End of function VgaBuf::pixelize --------------//
  98. //------------- Begin of function VgaBuf::rect --------------//
  99. //
  100. // Draw a rect on VGA screen
  101. //
  102. // Syntax : rect( x1, y1, x2, y2, lineWidth, color )
  103. //
  104. // int x1,y1 - the top left vertex of the rect
  105. // int x2,y2 - the bottom right vertex of the rect
  106. // int lineThick - thickness of the lines of the rect
  107. // int color - the color of the rect
  108. //
  109. void VgaBuf::rect(int x1,int y1,int x2,int y2,int lt, int color)
  110. {
  111. lt--;
  112. bar(x1,y1,x2,y1+lt,color);
  113. bar(x1,y1,x1+lt,y2,color);
  114. bar(x1,y2-lt,x2,y2,color);
  115. bar(x2-lt,y1,x2,y2,color);
  116. }
  117. //--------------- End of function VgaBuf::rect --------------//
  118. //------------- Start of function VgaBuf::d3_rect --------------//
  119. //
  120. // Draw a d3 rect on VGA screen
  121. //
  122. // Syntax : d3_rect( x1, y1, x2, y2, lineWidth, color )
  123. //
  124. // int x1,y1 - the top left vertex of the d3_rect
  125. // int x2,y2 - the bottom right vertex of the d3_rect
  126. void VgaBuf::d3_rect(int x1,int y1,int x2,int y2)
  127. {
  128. rect( x1+1, y1+1, x2, y2, 1, V_WHITE );
  129. rect( x1, y1, x2-1, y2-1, 1, VGA_GRAY+8 );
  130. }
  131. //--------------- End of function VgaBuf::d3_rect --------------//
  132. /*
  133. //------------- Start of function VgaBuf::tile --------------//
  134. //
  135. // Fill an area with a specific tile
  136. //
  137. // <int> x1,y1 - the top left vertex of the tile
  138. // <int> x2,y2 - the bottom right vertex of the tile
  139. // <char*> tileName - the name of the tile
  140. //
  141. void VgaBuf::tile(int x1,int y1,int x2,int y2,char* tileName)
  142. {
  143. if( image_init_flag )
  144. {
  145. err_if( x1>x2 || y1>y2 || x1<0 || y1<0 || x2>=image_width || y2>=image_height )
  146. err_now( "VgaBuf::tile (image)" );
  147. char* tilePtr = icon_sym.get_ptr(tileName);
  148. if( tilePtr )
  149. IMGtile(x1,y1,x2,y2,tilePtr);
  150. }
  151. else
  152. {
  153. err_if( x1>x2 || y1>y2 || x1<0 || y1<0 || x2>=VGA_WIDTH || y2>=VGA_HEIGHT )
  154. err_now( "VgaBuf::tile (direct)" );
  155. if( is_front )
  156. mouse.hide_area( x1,y1,x2,y2 );
  157. char* tilePtr = icon_sym.get_ptr(tileName);
  158. if( tilePtr )
  159. VGAtile(x1,y1,x2,y2,tilePtr);
  160. if( is_front )
  161. mouse.show_area();
  162. }
  163. }
  164. //--------------- End of function VgaBuf::tile --------------//
  165. */
  166. //------------- Start of function VgaBuf::separator --------------//
  167. //
  168. // Draw a VGA separator line
  169. //
  170. // Syntax : separator( x1, y1, x2, y2 )
  171. //
  172. // int x1,y1 - the top left vertex of the separator
  173. // int x2,y2 - the bottom right vertex of the separator
  174. //
  175. void VgaBuf::separator(int x1, int y1, int x2, int y2)
  176. {
  177. if( y1+1==y2 ) // horizontal line
  178. {
  179. bar( x1, y1, x2, y1, V_WHITE );
  180. bar( x1, y2, x2, y2, color_dark );
  181. }
  182. else
  183. {
  184. bar( x1, y1, x1, y2, V_WHITE );
  185. bar( x2, y1, x2, y2, color_dark );
  186. }
  187. }
  188. //--------------- End of function VgaBuf::separator --------------//
  189. //------------- Start of function VgaBuf::indicator --------------//
  190. //
  191. // <int> x1, y1, x2, y2 = coordination of the indicator
  192. // <float> curValue = the value of the bar
  193. // <float> maxValue = max value, the bar width = maxBarWidth * curValue / maxValue
  194. // <int> indiColor = color of the indicator
  195. // [int] backColor = background color
  196. // (default : vga.color_down)
  197. // (-2 if don't paint background color)
  198. //
  199. void VgaBuf::indicator(int x1, int y1, int x2, int y2, float curValue,
  200. float maxValue, int indiColor, int backColor)
  201. {
  202. if( backColor == -1 )
  203. backColor = color_down;
  204. if( curValue > maxValue )
  205. curValue = maxValue;
  206. if( curValue > 0 )
  207. {
  208. int barWidth = (int) ((float)(x2-x1) * curValue / maxValue);
  209. int halfHeight = (y2-y1+1)/2-1;
  210. int tx2 = x1+barWidth;
  211. int y;
  212. indiColor+=halfHeight;
  213. for( y=y1 ; y<y1+halfHeight ; y++, indiColor-- )
  214. bar( x1, y, tx2, y, indiColor );
  215. for( ; y<=y2 ; y++, indiColor++ )
  216. bar( x1, y, tx2, y, indiColor );
  217. if( backColor != -2 ) // -2 if don't paint background color
  218. {
  219. if( x1+barWidth < x2 )
  220. bar( x1+barWidth+1, y1, x2, y2, backColor );
  221. }
  222. }
  223. else
  224. {
  225. if( backColor != -2 ) // -2 if don't paint background color
  226. bar( x1, y1, x2, y2, backColor );
  227. }
  228. }
  229. //--------------- End of function VgaBuf::indicator --------------//
  230. //------------- Start of function VgaBuf::indicator --------------//
  231. //
  232. // <int> barType = bar style, bit 0 = disp curValue, bit 1 = disp '/' and maxValue, bit 2 = longer bar, bit 3 = use another back buffer
  233. // <int> x1, y1 = coordination of the indicator
  234. // <float> curValue = the value of the bar
  235. // <float> maxValue = max value, the bar width = maxBarWidth * curValue / maxValue
  236. // <int> colorScheme = color of the indicator // not used
  237. //
  238. void VgaBuf::indicator(int barType, int x1, int y1, float curValue, float maxValue, int colorScheme)
  239. {
  240. // -------- get indicator bar background ------------//
  241. const unsigned int TEMP_BUFFER_SIZE = 0x2000;
  242. static char tempBuffer[TEMP_BUFFER_SIZE];
  243. char *bgPtr = image_button.get_ptr(barType & 4 ? (char*)"V_HP-BX" : (char*)"V_PW-BX");
  244. if( !bgPtr )
  245. {
  246. err_here();
  247. return;
  248. }
  249. // -------- calculate the boundary or the indicator ---------//
  250. int width = *(short *)bgPtr;
  251. int height = *(((short *)bgPtr) + 1);
  252. int bufferX1 = x1;
  253. int bufferY1 = y1;
  254. char *destPtr = buf_ptr();
  255. int destPitch = buf_pitch();
  256. if(barType & 8)
  257. {
  258. if( width * height + 2*sizeof(short) < TEMP_BUFFER_SIZE )
  259. {
  260. bufferX1 = 0;
  261. bufferY1 = 0;
  262. destPtr = tempBuffer;
  263. *(short *)destPtr = width;
  264. destPtr += sizeof(short);
  265. *(short *)destPtr = height;
  266. destPtr += sizeof(short);
  267. destPitch = width;
  268. }
  269. else
  270. {
  271. barType &= ~8; // indicator too big, directly write to the buffer
  272. }
  273. }
  274. int x2 = x1 + width -1;
  275. int y2 = y1 + height -1;
  276. int bufferX2 = bufferX1 + width -1;
  277. int bufferY2 = bufferY1 + height -1;
  278. // -------- draw background ---------//
  279. if( is_front )
  280. mouse.hide_area(x1, y1, x2, y2 );
  281. IMGblt( destPtr, destPitch, bufferX1, bufferY1, bgPtr);
  282. const int barLeftMargin = 5;
  283. const int barRightMargin = 5;
  284. const int barTopMargin = 5;
  285. const int barBottomMargin = 5;
  286. // ---------- draw energy bar ----------//
  287. if( curValue > maxValue )
  288. curValue = maxValue;
  289. int barWidth = int( (width - barLeftMargin - barRightMargin ) * curValue / maxValue);
  290. int barX1 = bufferX1 + barLeftMargin;
  291. int barX2 = barX1 + barWidth - 1;
  292. int barHeight = height - (barTopMargin + barBottomMargin);
  293. int barY1 = bufferY1 + barTopMargin;
  294. unsigned int lc = 0;
  295. static unsigned char lineColor[8] =
  296. { VGA_LIGHT_BLUE, VGA_LIGHT_BLUE+1, VGA_DARK_BLUE, VGA_LIGHT_BLUE+2,
  297. VGA_DARK_BLUE+1, VGA_LIGHT_BLUE+3, VGA_DARK_BLUE+2, VGA_DARK_BLUE+3 };
  298. if( barWidth > 0 )
  299. {
  300. if(barHeight >= 8)
  301. {
  302. int bY1 = barY1;
  303. for( int c = 0; c < 8; ++c)
  304. {
  305. int bY2 = bY1 + (lc+ barHeight -1)/8;
  306. IMGbar(destPtr, destPitch, barX1, bY1, barX2, bY2, lineColor[c] );
  307. lc += barHeight;
  308. bY1 += lc / 8;
  309. lc %= 8;
  310. }
  311. }
  312. else
  313. {
  314. for( int y = 0; y < barHeight; ++y)
  315. {
  316. int c = lc/barHeight;
  317. IMGbar(destPtr, destPitch, barX1, barY1+y, barX2, barY1+y, lineColor[c]);
  318. lc += 8;
  319. }
  320. }
  321. }
  322. // ---------- display value ----------//
  323. if( barType & 3)
  324. {
  325. String str;
  326. if( barType & 1)
  327. str = (int) curValue;
  328. if( barType & 2)
  329. {
  330. str += "/";
  331. str += (int) maxValue;
  332. }
  333. font_hitpoint.center_put_to_buffer( destPtr, destPitch, bufferX1, bufferY1, bufferX2, bufferY2, str);
  334. }
  335. if(barType & 8)
  336. {
  337. put_bitmap(x1, y1, tempBuffer);
  338. }
  339. // ---------------------------------- //
  340. if( is_front )
  341. mouse.show_area();
  342. }
  343. //------------- End of function VgaBuf::indicator --------------//
  344. //------------- Start of function VgaBuf::v_indicator --------------//
  345. //
  346. // Vertical indicator, all parameters are same as indicator() except
  347. // it is vertical.
  348. //
  349. // <int> x1, y1, x2, y2 = coordination of the indicator
  350. // <float> curValue = the value of the bar
  351. // <float> maxValue = max value, the bar width = maxBarWidth * curValue / maxValue
  352. // <int> indiColor = color of the indicator
  353. // [int] backColor = background color
  354. // (default : vga.color_down)
  355. //
  356. void VgaBuf::v_indicator(int x1, int y1, int x2, int y2, float curValue,
  357. float maxValue, int indiColor, int backColor)
  358. {
  359. if( backColor == -1 )
  360. backColor = color_down;
  361. if( curValue > 0 )
  362. {
  363. int barHeight = (int) ((float)(y2-y1) * curValue / maxValue);
  364. int halfWidth = (x2-x1+1)/2-1;
  365. int ty1 = max(y2-barHeight,y1); // when curValue>0, even the actual bar width < 1, one pixel will also be painted
  366. int x;
  367. indiColor+=halfWidth;
  368. for( x=x1 ; x<x1+halfWidth ; x++, indiColor-- )
  369. bar( x, ty1, x, y2, indiColor );
  370. for( ; x<=x2 ; x++, indiColor++ )
  371. bar( x, ty1, x, y2, indiColor );
  372. if( y1 < y2-barHeight )
  373. bar( x1, y1, x2, y2-barHeight-1, backColor );
  374. }
  375. else
  376. {
  377. bar( x1, y1, x2, y2, backColor );
  378. }
  379. }
  380. //--------------- End of function VgaBuf::v_indicator --------------//
  381. //---------- Begin of function VgaBuf::line -------------//
  382. //
  383. // Draw a line
  384. //
  385. // <int> x1,y1,x2,y2 = the coordination of the line
  386. // <int> lineColor = color of the line
  387. //
  388. void VgaBuf::line(int x1,int y1,int x2,int y2,int lineColor)
  389. {
  390. if( is_front )
  391. mouse.hide_area( x1,y1,x2,y2 ); // if the mouse cursor is in that area, hide it
  392. IMGline(buf_ptr(), buf_pitch(), buf_width(), buf_height(), x1, y1, x2, y2, lineColor);
  393. if( is_front )
  394. mouse.show_area();
  395. }
  396. //------------ End of function VgaBuf::line -------------//
  397. //---------- Begin of function VgaBuf::thick_line -------------//
  398. //
  399. // Draw a thick line
  400. //
  401. // <int> x1,y1,x2,y2 = the coordination of the line
  402. // <int> lineColor = color of the line
  403. //
  404. void VgaBuf::thick_line(int x1,int y1,int x2,int y2,int lineColor)
  405. {
  406. err_when( x1<0 || y1<0 || x2>=VGA_WIDTH || y2>=VGA_HEIGHT );
  407. if( is_front )
  408. mouse.hide_area( x1,y1,x2,y2 ); // if the mouse cursor is in that area, hide it
  409. if( y1-y2 > abs(x2-x1) ) // keep thickness of the line to 3
  410. {
  411. IMGline(buf_ptr(), buf_pitch(), buf_width(), buf_height(), x1 , y1-1, x2 , y2-1, lineColor );
  412. IMGline(buf_ptr(), buf_pitch(), buf_width(), buf_height(), x1 , y1 , x2 , y2 , lineColor );
  413. IMGline(buf_ptr(), buf_pitch(), buf_width(), buf_height(), x1 , y1+1, x2 , y2+1, lineColor );
  414. IMGline(buf_ptr(), buf_pitch(), buf_width(), buf_height(), x1+1, y1+1, x2+1, y2+1, lineColor );
  415. }
  416. else if( y2-y1 > abs(x2-x1) )
  417. {
  418. IMGline(buf_ptr(), buf_pitch(), buf_width(), buf_height(), x1+1, y1-1, x2+1, y2-1, lineColor );
  419. IMGline(buf_ptr(), buf_pitch(), buf_width(), buf_height(), x1 , y1-1, x2 , y2-1, lineColor );
  420. IMGline(buf_ptr(), buf_pitch(), buf_width(), buf_height(), x1 , y1 , x2 , y2 , lineColor );
  421. IMGline(buf_ptr(), buf_pitch(), buf_width(), buf_height(), x1 , y1+1, x2 , y2+1, lineColor );
  422. }
  423. else
  424. {
  425. IMGline(buf_ptr(), buf_pitch(), buf_width(), buf_height(), x1, y1-1, x2, y2-1, lineColor );
  426. IMGline(buf_ptr(), buf_pitch(), buf_width(), buf_height(), x1, y1 , x2, y2 , lineColor );
  427. IMGline(buf_ptr(), buf_pitch(), buf_width(), buf_height(), x1, y1+1, x2, y2+1, lineColor );
  428. }
  429. if( is_front )
  430. mouse.show_area();
  431. }
  432. //------------ End of function VgaBuf::thick_line -------------//
  433. //----------- Begin of function VgaBuf::d3_panel_up ------------//
  434. //
  435. // Draw a Ms windows style 3D panel
  436. //
  437. // thickness can be 1-4
  438. //
  439. // <int> x1,y1,x2,y2 = the four vertex of the panel
  440. // [int] thick = thickness of the border
  441. // (default:2)
  442. // [int] paintCentre = paint the center area of the plane or not
  443. // pass 0 if the area has just been painted with bar()
  444. // (default:1)
  445. //
  446. void VgaBuf::d3_panel_up(int x1,int y1,int x2,int y2,int t,int paintCentre)
  447. {
  448. // int i,x,y;
  449. err_when( x1>x2 || y1>y2 || x1<0 || y1<0 || x2>=VGA_WIDTH || y2>=VGA_HEIGHT );
  450. if( is_front )
  451. mouse.hide_area( x1,y1,x2,y2 );
  452. //------------------------------------------------//
  453. // ####### begin Gilbert 12/7 ##########//
  454. if( paintCentre )
  455. bar(x1+2, y1+2, x2-3, y2-3, color_up ); // center
  456. //--------- white border on top and left sides -----------//
  457. bar(x1,y1,x2-3,y1+1,0x9a );
  458. draw_pixel(x2-2, y1, 0x9a);
  459. bar(x1,y1+2,x1+1,y2-3, 0x9a ); // left side
  460. draw_pixel(x1, y2-2, 0x9a);
  461. //--------- black border on bottom and right sides -----------//
  462. bar(x2-2,y1+2,x2-1,y2-1, 0x90 ); // bottom side
  463. draw_pixel(x2-1, y1+1, 0x90);
  464. bar(x1+2,y2-2,x2-3,y2-1, 0x90 ); // right side
  465. draw_pixel(x1+1, y2-1, 0x90);
  466. //--------- junction between white and black border --------//
  467. draw_pixel(x2-1, y1, 0x97);
  468. draw_pixel(x2-2, y1+1, 0x97);
  469. draw_pixel(x1, y2-1, 0x97);
  470. draw_pixel(x1+1, y2-2, 0x97);
  471. //--------- gray shadow on bottom and right sides -----------//
  472. bar(x2, y1+1, x2, y2, 0x97);
  473. bar(x1+1, y2, x2-1, y2, 0x97);
  474. //-------------------------------------------//
  475. // ######## end Gilbert 12/7 ##########//
  476. if( is_front )
  477. mouse.show_area();
  478. }
  479. //------------- End of function VgaBuf::d3_panel_up ------------//
  480. //----------- Begin of function VgaBuf::d3_panel_down ------------//
  481. //
  482. // Draw a Ms windows style 3D panel with panel pushed downwards
  483. //
  484. // <int> x1,y1,x2,y2 = the four vertex of the panel
  485. // [int] thick = thickness of the border
  486. // (default:2)
  487. // [int] paintCentre = paint the center area of the plane or not
  488. // pass 0 if the area has just been painted with bar()
  489. // (default:1)
  490. //
  491. void VgaBuf::d3_panel_down(int x1,int y1,int x2,int y2,int t,int paintCentre)
  492. {
  493. err_when( x1>x2 || y1>y2 || x1<0 || y1<0 || x2>=VGA_WIDTH || y2>=VGA_HEIGHT );
  494. if( is_front )
  495. mouse.hide_area( x1,y1,x2,y2 );
  496. //---------- main center area -----------//
  497. // ####### begin Gilbert 12/7 ##########//
  498. if( paintCentre )
  499. bar(x1+2, y1+2, x2-3, y2-3, color_down ); // center
  500. //--------- black border on top and left sides -----------//
  501. bar(x1,y1,x2-3,y1+1,0x90 );
  502. draw_pixel(x2-2, y1, 0x90);
  503. bar(x1,y1+2,x1+1,y2-3, 0x90 ); // left side
  504. draw_pixel(x1, y2-2, 0x90);
  505. //--------- while border on bottom and right sides -----------//
  506. bar(x2-2,y1+2,x2-1,y2-1, 0x9a ); // bottom side
  507. draw_pixel(x2-1, y1+1, 0x9a);
  508. bar(x1+2,y2-2,x2-3,y2-1, 0x9a ); // right side
  509. draw_pixel(x1+1, y2-1, 0x9a);
  510. //--------- junction between white and black border --------//
  511. draw_pixel(x2-1, y1, 0x97);
  512. draw_pixel(x2-2, y1+1, 0x97);
  513. draw_pixel(x1, y2-1, 0x97);
  514. draw_pixel(x1+1, y2-2, 0x97);
  515. //--------- remove shadow, copy from back -----------//
  516. bar(x2, y1+1, x2, y2, 0x9c);
  517. bar(x1+1, y2, x2-1, y2, 0x9c);
  518. // ####### end Gilbert 12/7 ##########//
  519. //----------- show mouse ----------//
  520. if( is_front )
  521. mouse.show_area();
  522. }
  523. //------------- End of function VgaBuf::d3_panel_down ------------//
  524. //----------- Begin of function VgaBuf::d3_panel_up_clear ------------//
  525. //
  526. // clear the center of the either up or down panel
  527. //
  528. // <int> x1,y1,x2,y2 = the four vertex of the panel
  529. // [int] thick = thickness of the border
  530. // (default:2)
  531. //
  532. void VgaBuf::d3_panel_up_clear(int x1,int y1,int x2,int y2,int t)
  533. {
  534. // ####### begin Gilbert 15/7 #########//
  535. // bar( x1+t, y1+t, x2-t, y2-t, color_up );
  536. bar(x1+2, y1+2, x2-3, y2-3, color_up );
  537. // ####### end Gilbert 15/7 #########//
  538. }
  539. //------------- End of function VgaBuf::d3_panel_up_clear ------------//
  540. //----------- Begin of function VgaBuf::d3_panel_down_clear ------------//
  541. //
  542. // clear the center of the either up or down panel
  543. //
  544. // <int> x1,y1,x2,y2 = the four vertex of the panel
  545. // [int] thick = thickness of the border
  546. // (default:2)
  547. //
  548. void VgaBuf::d3_panel_down_clear(int x1,int y1,int x2,int y2,int t)
  549. {
  550. // ####### begin Gilbert 15/7 #########//
  551. // bar( x1+t, y1+t, x2-t, y2-t, color_down );
  552. bar(x1+2, y1+2, x2-3, y2-3, color_down );
  553. // ####### end Gilbert 15/7 #########//
  554. }
  555. //------------- End of function VgaBuf::d3_panel_down_clear ------------//
  556. //----------- Begin of function VgaBuf::adjust_brightness ------------//
  557. //
  558. // clear the center of the either up or down panel
  559. //
  560. // <int> x1,y1,x2,y2 = the four vertex of the panel
  561. // <int> adjustDegree = the degree of brightness to adjust
  562. // (a value from -10 to 10)
  563. //
  564. void VgaBuf::adjust_brightness(int x1,int y1,int x2,int y2,int adjustDegree)
  565. {
  566. if( is_front )
  567. mouse.hide_area( x1,y1,x2,y2 );
  568. err_when( adjustDegree < -MAX_BRIGHTNESS_ADJUST_DEGREE ||
  569. adjustDegree > MAX_BRIGHTNESS_ADJUST_DEGREE );
  570. unsigned char* colorRemapTable = vga.vga_color_table->get_table(adjustDegree);
  571. remap_bar(x1, y1, x2, y2, colorRemapTable);
  572. if( is_front )
  573. mouse.show_area();
  574. }
  575. //------------- End of function VgaBuf::adjust_brightness ------------//
  576. //----------- Begin of function VgaBuf::draw_d3_up_border ------------//
  577. //
  578. // Draw interface border.
  579. //
  580. void VgaBuf::draw_d3_up_border(int x1,int y1,int x2,int y2)
  581. {
  582. err_when( x1>x2 || y1>y2 || x1<0 || y1<0 || x2>=VGA_WIDTH || y2>=VGA_HEIGHT );
  583. if( is_front )
  584. mouse.hide_area( x1,y1,x2,y2 );
  585. //--------- white border on top and left sides -----------//
  586. IMGbar( buf_ptr(), buf_pitch(), x1+1,y1,x2,y1, IF_LIGHT_BORDER_COLOR ); // top side
  587. IMGbar( buf_ptr(), buf_pitch(), x1,y1,x1,y2 , IF_LIGHT_BORDER_COLOR ); // left side
  588. //--------- black border on bottom and right sides -----------//
  589. IMGbar( buf_ptr(), buf_pitch(), x1+1,y2,x2,y2, IF_DARK_BORDER_COLOR ); // bottom side
  590. IMGbar( buf_ptr(), buf_pitch(), x2,y1+1,x2,y2, IF_DARK_BORDER_COLOR ); // right side
  591. //-------------------------------------------//
  592. if( is_front )
  593. mouse.show_area();
  594. }
  595. //------------- End of function VgaBuf::draw_d3_up_border ------------//
  596. //----------- Begin of function VgaBuf::draw_d3_down_border ------------//
  597. //
  598. // Draw interface border.
  599. //
  600. void VgaBuf::draw_d3_down_border(int x1,int y1,int x2,int y2)
  601. {
  602. err_when( x1>x2 || y1>y2 || x1<0 || y1<0 || x2>=VGA_WIDTH || y2>=VGA_HEIGHT );
  603. if( is_front )
  604. mouse.hide_area( x1,y1,x2,y2 );
  605. //--------- white border on top and left sides -----------//
  606. IMGbar( buf_ptr(), buf_pitch(), x1+1,y1,x2,y1, IF_DARK_BORDER_COLOR ); // top side
  607. IMGbar( buf_ptr(), buf_pitch(), x1,y1,x1,y2 , IF_DARK_BORDER_COLOR ); // left side
  608. //--------- black border on bottom and right sides -----------//
  609. IMGbar( buf_ptr(), buf_pitch(), x1+1,y2,x2,y2, IF_LIGHT_BORDER_COLOR ); // bottom side
  610. IMGbar( buf_ptr(), buf_pitch(), x2,y1+1,x2,y2, IF_LIGHT_BORDER_COLOR ); // right side
  611. //-------------------------------------------//
  612. if( is_front )
  613. mouse.show_area();
  614. }
  615. //------------- End of function VgaBuf::draw_d3_down_border ------------//
  616. //------------- Begin of function VgaBuf::blt_buf ------------//
  617. // copy put whole part of a vgaBuf to (x1,y1) of this VgaBuf
  618. void VgaBuf::blt_buf( VgaBuf *srcBuf, int x1, int y1 )
  619. {
  620. char *srcPtr = srcBuf->buf_ptr();
  621. int srcWidth = srcBuf->buf_width();
  622. int srcPitch = srcBuf->buf_pitch();
  623. int srcHeight = srcBuf->buf_height();
  624. char *destPtr = buf_ptr();
  625. int destPitch = buf_pitch();
  626. if( srcWidth & 1)
  627. {
  628. // odd number
  629. /* Original Visual C++ assembly code for reference
  630. _asm
  631. {
  632. mov eax, y1
  633. imul destPitch
  634. add eax, x1
  635. mov edi, eax
  636. add edi, destPtr
  637. mov esi, srcPtr
  638. mov ecx, srcHeight
  639. blt_buf_1:
  640. push ecx
  641. mov ecx, srcWidth
  642. rep movsb
  643. sub esi, srcWidth
  644. sub edi, srcWidth
  645. add esi, srcPitch
  646. add edi, destPitch
  647. pop ecx
  648. loop blt_buf_1
  649. }
  650. */
  651. __asm__ __volatile__ (
  652. "imull %1\n\t"
  653. "addl %2, %%eax\n\t"
  654. "movl %%eax, %%edi\n\t"
  655. "addl %3, %%edi\n"
  656. "blt_buf_1:\n\t"
  657. "pushl %%ecx\n\t"
  658. "movl %6, %%ecx\n\t"
  659. "rep movsb\n\t"
  660. "subl %6, %%esi\n\t"
  661. "subl %6, %%edi\n\t"
  662. "addl %7, %%esi\n\t"
  663. "addl %8, %%edi\n\t"
  664. "popl %%ecx\n\t"
  665. "loop blt_buf_1\n\t"
  666. :
  667. : "a"(y1), "m"(destPitch), "m"(x1), "m"(destPtr), "S"(srcPtr), "c"(srcHeight), "m"(srcWidth),
  668. "m"(srcPitch), "m"(destPitch)
  669. : "%edi","memory"
  670. );
  671. }
  672. else
  673. {
  674. // even number
  675. /* Original Visual C++ assembly code for reference
  676. _asm
  677. {
  678. mov eax, y1
  679. imul destPitch
  680. add eax, x1
  681. mov edi, eax
  682. add edi, destPtr
  683. mov esi, srcPtr
  684. mov ecx, srcHeight
  685. blt_buf_2:
  686. push ecx
  687. mov ecx, srcWidth
  688. shr ecx, 1
  689. rep movsw
  690. sub esi, srcWidth
  691. sub edi, srcWidth
  692. add esi, srcPitch
  693. add edi, destPitch
  694. pop ecx
  695. loop blt_buf_2
  696. }
  697. */
  698. __asm__ __volatile__ (
  699. "imull %1\n\t"
  700. "addl %2, %%eax\n\t"
  701. "movl %%eax, %%edi\n\t"
  702. "addl %3, %%edi\n"
  703. "blt_buf_2:\n\t"
  704. "pushl %%ecx\n\t"
  705. "movl %6, %%ecx\n\t"
  706. "shrl $1, %%ecx\n\t"
  707. "rep movsb\n\t"
  708. "subl %6, %%esi\n\t"
  709. "subl %6, %%edi\n\t"
  710. "addl %7, %%esi\n\t"
  711. "addl %8, %%edi\n\t"
  712. "popl %%ecx\n\t"
  713. "loop blt_buf_2\n\t"
  714. :
  715. : "a"(y1),"m"(destPitch),"m"(x1),"m"(destPtr),"S"(srcPtr),"c"(srcHeight),"m"(srcWidth),
  716. "m"(srcPitch),"m"(destPitch)
  717. : "%edi","memory"
  718. );
  719. }
  720. }
  721. //------------- End of function VgaBuf::blt_buf ------------//