1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
// draw rectangle
#include "portab.h"
#include "surface.h"
#include "ngraph.h"
#include "ags.h"
int gr_drawrect(surface_t *dst, int x, int y, int w, int h, int r, int g, int b) {
BYTE *dp;
int i;
int col = 0;
if (FALSE == gr_clip_xywh(dst, &x, &y, &w, &h)) {
return NG;
}
dp = GETOFFSET_PIXEL(dst, x, y);
switch(dst->depth) {
case 8:
col = r; break;
case 15:
col = PIX15(r, g, b); break;
case 16:
col = PIX16(r, g, b); break;
case 24:
case 32:
col = PIX24(r, g, b); break;
}
switch(dst->depth) {
case 8:
/* top */
for (i = 0; i < w; i++) {
*((BYTE *)dp + i) = col;
}
/* side */
h-=2;
for (i = 0; i < h; i++) {
dp += dst->bytes_per_line;
*((BYTE *)dp) = col;
*((BYTE *)dp + w - 1) = col;
}
/* bottom */
dp += dst->bytes_per_line;
for (i = 0; i < w; i++) {
*((BYTE *)dp + i) = col;
}
break;
case 15:
case 16:
/* top */
for (i = 0; i < w; i++) {
*((WORD *)dp + i) = col;
}
/* side */
h-=2;
for (i = 0; i < h; i++) {
dp += dst->bytes_per_line;
*((WORD *)dp) = col;
*((WORD *)dp + w - 1) = col;
}
/* bottom */
dp += dst->bytes_per_line;
for (i = 0; i < w; i++) {
*((WORD *)dp + i) = col;
}
break;
case 24:
case 32:
/* top */
for (i = 0; i < w; i++) {
*((DWORD *)dp + i) = col;
}
/* side */
h-=2;
for (i = 0; i < h; i++) {
dp += dst->bytes_per_line;
*((DWORD *)dp) = col;
*((DWORD *)dp + w - 1) = col;
}
/* bottom */
dp += dst->bytes_per_line;
for (i = 0; i < w; i++) {
*((DWORD *)dp + i) = col;
}
break;
}
return OK;
}
|