00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "gui/graphics.h"
00019
00020 DW svga_buf[600*800] __attribute__((aligned (_4KB)));
00021
00022 DW xRes = 0, yRes = 0, bpp = 0;
00023 DD svgabuf = (DD)&svga_buf[0];
00024 DD physvgabuf = 0;
00025
00026 boolean graphics = _false;
00027
00028 COLOR mouseimg[16][16];
00029
00030 void initgraphics(DW _xRes, DW _yRes, DW _bpp, DD _svgabuf)
00031 {
00032 DB i, j ;
00033 if(_xRes == 0 || _yRes == 0 || _bpp == 0 || _svgabuf == 0)
00034 return;
00035
00036 xRes = _xRes;
00037 yRes = _yRes;
00038 bpp = _bpp;
00039 svgabuf = (DD)&svga_buf[0];
00040 physvgabuf = _svgabuf;
00041
00042 graphics = _true;
00043 }
00044
00045 void setScreen(COLOR c)
00046 {
00047 DD i, j;
00048
00049 if(!chkGraphicsInited())
00050 return;
00051
00052
00053 for(i = 0 ; i < xRes ; i++)
00054 {
00055 for(j=0 ;j< yRes ; j++)
00056 {
00057 setPixel(i,j,c);
00058 }
00059 }
00060 }
00061
00062 void setPixel(DW x, DW y, COLOR c)
00063 {
00064 normalize(x,y);
00065 *((DW *)(svgabuf + x + xRes*y)) = c;
00066 }
00067
00068 COLOR getPixel(DW x, DW y)
00069 {
00070 normalize(x,y);
00071 return *((DW *)(svgabuf + x + xRes*y));
00072 }
00073
00074 void drawChar(DW x, DW y, DW index)
00075 {
00076 DW i = 0, j = 0;
00077 COLOR c;
00078
00079 x %= xRes;
00080 y %= yRes;
00081
00082 for(i = 0 ; i < CHARROWS ; i++)
00083 {
00084 for(j = 0 ; j < CHARCOLS ; j++)
00085 {
00086 c = charset[index-32][i][j];
00087 if(c)
00088 setPixel(x+j,y+i,0x0);
00089 }
00090 }
00091
00092 }
00093
00094
00095 void rect(DW x, DW y, DW width, DW height)
00096 {
00097 DD i, j;
00098
00099 if(!chkGraphicsInited())
00100 return;
00101
00102 for(i = x ; i < (x+width) ; i++)
00103 {
00104 for(j = y ; j < (y+height) ; j++)
00105 {
00106 setPixel(i,j,0xFFFF);
00107 }
00108 }
00109 }
00110
00111 void charrect(DW x,DW y,DW width,DW height,DB ch)
00112 {
00113 fillrect(x,y,width,height,0xFFFF);
00114 drawChar(x+2,y+2,ch);
00115 }
00116
00117 void drawMousePtr(DW x,DW y)
00118 {
00119 DW i,j;
00120
00121 if(!graphics)
00122 return;
00123
00124 x %= xRes;
00125 y %= yRes;
00126
00127 restoreImage(mcurx,mcury);
00128 mvMini2Svga(mcurx,mcury,16,16);
00129
00130 getimage(x,y,16,16,mouseimg);
00131
00132
00133
00134
00135
00136 for(i = x ; i < x+16 ; i++)
00137 {
00138 for(j = y ; j < y+16 ; j++)
00139 {
00140 if(mouseptr[j-y][i-x])
00141 {
00142 setPixel(i,j,0x0);
00143 }
00144 }
00145 }
00146
00147 mvMini2Svga(x,y,16,16);
00148 }
00149
00150 void restoreImage(DW x, DW y)
00151 {
00152 putimage(x,y,16,16,mouseimg);
00153 }
00154
00155 void getimage(DW x, DW y,DW width, DW height, COLOR *buffer)
00156 {
00157 DW i, j;
00158
00159 for(i = x ; i < x+width ; i++)
00160 {
00161 for(j = y; j < y+height ; j++)
00162 {
00163 buffer[(i-x)+(j-y)*width] = getPixel(i,j);
00164 }
00165 }
00166 }
00167
00168 void putimage(DW x, DW y,DW width, DW height, COLOR *buffer)
00169 {
00170 DW i, j;
00171
00172 for(i = x ; i < x+width ; i++)
00173 {
00174 for(j = y; j < y+height ; j++)
00175 {
00176 setPixel(i,j,buffer[(i-x)+(j-y)*width]);
00177 }
00178 }
00179 }
00180
00181 void drawstring(DW x,DW y,char *title)
00182 {
00183 SDB i;
00184 for(i = 0 ; i < strlen(title) ; i++)
00185 drawChar(x+i*7,y,title[i]);
00186 }
00187
00188 void fillrect(DW x,DW y,DW width,DW height,COLOR fill)
00189 {
00190 DD i, j;
00191
00192 if(!chkGraphicsInited())
00193 return;
00194
00195 for(i = x ; i < (x+width) ; i++)
00196 {
00197 for(j = y ; j < (y+height) ; j++)
00198 {
00199 setPixel(i,j,fill);
00200 }
00201 }
00202 }
00203
00204
00205 void mvBuf2Svga()
00206 {
00207 DD i;
00208
00209 if(!graphics)
00210 return;
00211
00212 memcpy((void *)physvgabuf,(void *)svgabuf,(DD)800*1200);
00213 }
00214
00215
00216 void mvMini2Svga(DW _x, DW _y, DW _width, DW _height)
00217 {
00218 DW i, j;
00219
00220 for(j = 0 ; j < _height ; j++)
00221 {
00222 for(i = 0 ; i < _width ; i++)
00223 {
00224 *(DW *)(physvgabuf + (j+_y) * xRes * 2 + (i+_x) * 2 ) = *(DW *)(svgabuf + (j+_y) * xRes * 2 + (i+_x) * 2 );
00225 }
00226 }
00227
00228 }
00229
00230 void emboss3D(DW x, DW y, DW width, DW height,DB flags,boolean in_or_out, DB emboss_size)
00231 {
00232 DB i;
00233 COLOR c1, c2;
00234
00235 if(emboss_size == 0)
00236 emboss_size = DEFAULT_EMBOSS_SIZE;
00237
00238 switch(in_or_out)
00239 {
00240 case _false:
00241 c1 = LIGHT_COLOR;
00242 c2 = DARK_COLOR;
00243 break;
00244
00245 case _true:
00246 c1 = DARK_COLOR;
00247 c2 = LIGHT_COLOR;
00248 break;
00249 }
00250
00251 if(flags == 0)
00252 {
00253 flags = TOP|LEFT|BOTTOM|RIGHT;
00254 }
00255
00256 for(i = 0 ; i < emboss_size ; i++)
00257 {
00258
00259 if(flags & TOP)
00260 line(x+i,y+i,x+width-i,y+i,c1);
00261
00262
00263 if(flags & LEFT)
00264 line(x+i,y+i,x+i,y+height-i,c1);
00265
00266
00267 if(flags & BOTTOM)
00268 line(x+i,y+height-i,x+width-i,y+height-i,c2);
00269
00270
00271 if(flags & RIGHT)
00272 line(x+width-i,y+i,x+width-i,y+height-i,c2);
00273 }
00274
00275 }
00276
00277 void line(SDW x0, SDW y0, SDW x1, SDW y1, COLOR color)
00278 {
00279 SDW dy = y1 - y0;
00280 SDW dx = x1 - x0;
00281 SDW stepx, stepy;
00282 SDW i;
00283
00284 if (dy < 0) { dy = -dy; stepy = -1; } else { stepy = 1; }
00285 if (dx < 0) { dx = -dx; stepx = -1; } else { stepx = 1; }
00286
00287 setPixel( x0, y0, color);
00288 setPixel( x1, y1, color);
00289 if (dx > dy) {
00290 SDW length = (dx - 1) >> 2;
00291 SDW extras = (dx - 1) & 3;
00292 SDW incr2 = (dy << 2) - (dx << 1);
00293 if (incr2 < 0) {
00294 SDW c = dy << 1;
00295 SDW incr1 = c << 1;
00296 SDW d = incr1 - dx;
00297 for (i = 0; i < length; i++) {
00298 x0 += stepx;
00299 x1 -= stepx;
00300 if (d < 0) {
00301 setPixel( x0, y0, color);
00302 setPixel( x0 += stepx, y0, color);
00303 setPixel( x1, y1, color);
00304 setPixel( x1 -= stepx, y1, color);
00305 d += incr1;
00306 } else {
00307 if (d < c) {
00308 setPixel( x0, y0, color);
00309 setPixel( x0 += stepx, y0 += stepy, color);
00310 setPixel( x1, y1, color);
00311 setPixel( x1 -= stepx, y1 -= stepy, color);
00312 } else {
00313 setPixel( x0, y0 += stepy, color);
00314 setPixel( x0 += stepx, y0, color);
00315 setPixel( x1, y1 -= stepy, color);
00316 setPixel( x1 -= stepx, y1, color);
00317 }
00318 d += incr2;
00319 }
00320 }
00321 if (extras > 0) {
00322 if (d < 0) {
00323 setPixel( x0 += stepx, y0, color);
00324 if (extras > 1) setPixel( x0 += stepx, y0, color);
00325 if (extras > 2) setPixel( x1 -= stepx, y1, color);
00326 } else
00327 if (d < c) {
00328 setPixel( x0 += stepx, y0, color);
00329 if (extras > 1) setPixel( x0 += stepx, y0 += stepy, color);
00330 if (extras > 2) setPixel( x1 -= stepx, y1, color);
00331 } else {
00332 setPixel( x0 += stepx, y0 += stepy, color);
00333 if (extras > 1) setPixel( x0 += stepx, y0, color);
00334 if (extras > 2) setPixel( x1 -= stepx, y1 -= stepy, color);
00335 }
00336 }
00337 } else {
00338 SDW c = (dy - dx) << 1;
00339 SDW incr1 = c << 1;
00340 SDW d = incr1 + dx;
00341 for (i = 0; i < length; i++) {
00342 x0 += stepx;
00343 x1 -= stepx;
00344 if (d > 0) {
00345 setPixel( x0, y0 += stepy, color);
00346 setPixel( x0 += stepx, y0 += stepy, color);
00347 setPixel( x1, y1 -= stepy, color);
00348 setPixel( x1 -= stepx, y1 -= stepy, color);
00349 d += incr1;
00350 } else {
00351 if (d < c) {
00352 setPixel( x0, y0, color);
00353 setPixel( x0 += stepx, y0 += stepy, color);
00354 setPixel( x1, y1, color);
00355 setPixel( x1 -= stepx, y1 -= stepy, color);
00356 } else {
00357 setPixel( x0, y0 += stepy, color);
00358 setPixel( x0 += stepx, y0, color);
00359 setPixel( x1, y1 -= stepy, color);
00360 setPixel( x1 -= stepx, y1, color);
00361 }
00362 d += incr2;
00363 }
00364 }
00365 if (extras > 0) {
00366 if (d > 0) {
00367 setPixel( x0 += stepx, y0 += stepy, color);
00368 if (extras > 1) setPixel( x0 += stepx, y0 += stepy, color);
00369 if (extras > 2) setPixel( x1 -= stepx, y1 -= stepy, color);
00370 } else
00371 if (d < c) {
00372 setPixel( x0 += stepx, y0, color);
00373 if (extras > 1) setPixel( x0 += stepx, y0 += stepy, color);
00374 if (extras > 2) setPixel( x1 -= stepx, y1, color);
00375 } else {
00376 setPixel( x0 += stepx, y0 += stepy, color);
00377 if (extras > 1) setPixel( x0 += stepx, y0, color);
00378 if (extras > 2) {
00379 if (d > c)
00380 setPixel( x1 -= stepx, y1 -= stepy, color);
00381 else
00382 setPixel( x1 -= stepx, y1, color);
00383 }
00384 }
00385 }
00386 }
00387 } else {
00388 SDW length = (dy - 1) >> 2;
00389 SDW extras = (dy - 1) & 3;
00390 SDW incr2 = (dx << 2) - (dy << 1);
00391 if (incr2 < 0) {
00392 SDW c = dx << 1;
00393 SDW incr1 = c << 1;
00394 SDW d = incr1 - dy;
00395 for (i = 0; i < length; i++) {
00396 y0 += stepy;
00397 y1 -= stepy;
00398 if (d < 0) {
00399 setPixel( x0, y0, color);
00400 setPixel( x0, y0 += stepy, color);
00401 setPixel( x1, y1, color);
00402 setPixel( x1, y1 -= stepy, color);
00403 d += incr1;
00404 } else {
00405 if (d < c) {
00406 setPixel( x0, y0, color);
00407 setPixel( x0 += stepx, y0 += stepy, color);
00408 setPixel( x1, y1, color);
00409 setPixel( x1 -= stepx, y1 -= stepy, color);
00410 } else {
00411 setPixel( x0 += stepx, y0, color);
00412 setPixel( x0, y0 += stepy, color);
00413 setPixel( x1 -= stepx, y1, color);
00414 setPixel( x1, y1 -= stepy, color);
00415 }
00416 d += incr2;
00417 }
00418 }
00419 if (extras > 0) {
00420 if (d < 0) {
00421 setPixel( x0, y0 += stepy, color);
00422 if (extras > 1) setPixel( x0, y0 += stepy, color);
00423 if (extras > 2) setPixel( x1, y1 -= stepy, color);
00424 } else
00425 if (d < c) {
00426 setPixel( stepx, y0 += stepy, color);
00427 if (extras > 1) setPixel( x0 += stepx, y0 += stepy, color);
00428 if (extras > 2) setPixel( x1, y1 -= stepy, color);
00429 } else {
00430 setPixel( x0 += stepx, y0 += stepy, color);
00431 if (extras > 1) setPixel( x0, y0 += stepy, color);
00432 if (extras > 2) setPixel( x1 -= stepx, y1 -= stepy, color);
00433 }
00434 }
00435 } else {
00436 SDW c = (dx - dy) << 1;
00437 SDW incr1 = c << 1;
00438 SDW d = incr1 + dy;
00439 for (i = 0; i < length; i++) {
00440 y0 += stepy;
00441 y1 -= stepy;
00442 if (d > 0) {
00443 setPixel( x0 += stepx, y0, color);
00444 setPixel( x0 += stepx, y0 += stepy, color);
00445 setPixel( x1 -= stepy, y1, color);
00446 setPixel( x1 -= stepx, y1 -= stepy, color);
00447 d += incr1;
00448 } else {
00449 if (d < c) {
00450 setPixel( x0, y0, color);
00451 setPixel( x0 += stepx, y0 += stepy, color);
00452 setPixel( x1, y1, color);
00453 setPixel( x1 -= stepx, y1 -= stepy, color);
00454 } else {
00455 setPixel( x0 += stepx, y0, color);
00456 setPixel( x0, y0 += stepy, color);
00457 setPixel( x1 -= stepx, y1, color);
00458 setPixel( x1, y1 -= stepy, color);
00459 }
00460 d += incr2;
00461 }
00462 }
00463 if (extras > 0) {
00464 if (d > 0) {
00465 setPixel( x0 += stepx, y0 += stepy, color);
00466 if (extras > 1) setPixel( x0 += stepx, y0 += stepy, color);
00467 if (extras > 2) setPixel( x1 -= stepx, y1 -= stepy, color);
00468 } else
00469 if (d < c) {
00470 setPixel( x0, y0 += stepy, color);
00471 if (extras > 1) setPixel( x0 += stepx, y0 += stepy, color);
00472 if (extras > 2) setPixel( x1, y1 -= stepy, color);
00473 } else {
00474 setPixel( x0 += stepx, y0 += stepy, color);
00475 if (extras > 1) setPixel( x0, y0 += stepy, color);
00476 if (extras > 2) {
00477 if (d > c)
00478 setPixel( x1 -= stepx, y1 -= stepy, color);
00479 else
00480 setPixel( x1, y1 -= stepy, color);
00481 }
00482 }
00483 }
00484 }
00485 }
00486 }
00487
00488 boolean iswithin(DW x,DW y,DW stx,DW sty,DW width,DW height)
00489 {
00490 if( (x >= stx) && ( x <= stx + width) )
00491 {
00492 if((y >= sty) && ( y <= sty + height))
00493 return _true;
00494 else
00495 return _false;
00496 }
00497 else
00498 return _false;
00499 }
00500
00501 void cprint(DW x,DW y,char *title,COLOR c)
00502 {
00503 DW i = 0, j = 0, k = 0;
00504
00505 x %= xRes;
00506 y %= yRes;
00507
00508 for(i = 0 ; i < strlen(title) ; i++)
00509 {
00510 for(j = 0 ; j < CHARROWS ; j++)
00511 {
00512 for(k = 0 ; k < CHARCOLS ; k++)
00513 {
00514 if(charset[title[i]-32][j][k])
00515 setPixel(x+i*7+k,y+j,c);
00516 }
00517 }
00518 }
00519 }
00520