Skip to content

Commit d6f5c51

Browse files
Alpha highlight/background image fix
1 parent 7dbc26d commit d6f5c51

1 file changed

Lines changed: 42 additions & 22 deletions

File tree

source/gfx.c

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818

1919
u8 *gfxGetFramebuffer(gfxScreen_t screen, gfx3dSide_t side, u16 *width, u16 *height) {
2020
if (screen == GFX_TOP) {
21-
*width = 240;
22-
*height = 400;
21+
if (width) *width = 240;
22+
if (height) *height = 400;
2323
return PTR_TOP_SCREEN_BUF;
2424
} else {
25-
*width = 240;
26-
*height = 320;
25+
if (width) *width = 240;
26+
if (height) *height = 320;
2727
return PTR_BOT_SCREEN_BUF;
2828
}
2929
}
@@ -132,7 +132,7 @@ void gfxFillColorGradient(gfxScreen_t screen, gfx3dSide_t side, u8 rgbColorStart
132132
}
133133
}
134134

135-
void _gfxDrawRectangle(gfxScreen_t screen, gfx3dSide_t side, u8 rgbColor[3], s16 x, s16 y, u16 width, u16 height) {
135+
void _gfxDrawRectangle(gfxScreen_t screen, gfx3dSide_t side, u8 rgbColor[4], s16 x, s16 y, u16 width, u16 height) {
136136
u16 fbWidth, fbHeight;
137137
u8 *fbAdr = gfxGetFramebuffer(screen, side, &fbWidth, &fbHeight);
138138

@@ -150,23 +150,43 @@ void _gfxDrawRectangle(gfxScreen_t screen, gfx3dSide_t side, u8 rgbColor[3], s16
150150
if (x + width >= fbWidth)width = fbWidth - x;
151151
if (y + height >= fbHeight)height = fbHeight - y;
152152

153-
u8 colorLine[width * 3];
154-
155-
int j;
156-
for (j = 0; j < width; j++) {
157-
colorLine[j * 3 + 0] = rgbColor[2];
158-
colorLine[j * 3 + 1] = rgbColor[1];
159-
colorLine[j * 3 + 2] = rgbColor[0];
160-
}
161-
162-
fbAdr += fbWidth * 3 * y;
163-
for (j = 0; j < height; j++) {
164-
memcpy(&fbAdr[x * 3], colorLine, width * 3);
165-
fbAdr += fbWidth * 3;
166-
}
167-
}
168-
169-
void gfxDrawRectangle(gfxScreen_t screen, gfx3dSide_t side, u8 rgbColor[3], s16 x, s16 y, u16 width, u16 height) {
153+
if ( rgbColor[3] == 0xFF )
154+
{
155+
u8 colorLine[width * 3];
156+
157+
int j;
158+
for (j = 0; j < width; j++) {
159+
colorLine[j * 3 + 0] = rgbColor[2];
160+
colorLine[j * 3 + 1] = rgbColor[1];
161+
colorLine[j * 3 + 2] = rgbColor[0];
162+
}
163+
164+
fbAdr += fbWidth * 3 * y;
165+
for (j = 0; j < height; j++) {
166+
memcpy(&fbAdr[x * 3], colorLine, width * 3);
167+
fbAdr += fbWidth * 3;
168+
}
169+
}
170+
else
171+
{
172+
float alpha = (float)rgbColor[3] / 255.f;
173+
float one_minus_alpha = 1.f - alpha;
174+
int i, j;
175+
fbAdr += fbWidth * 3 * y;
176+
for (j = 0; j < height; j++)
177+
{
178+
for (i = 0; i < width; i++)
179+
{
180+
fbAdr[3*(i+x)+0] = (u8)(alpha*(float)rgbColor[0]+one_minus_alpha*(float)fbAdr[3*(i+x)+0]);
181+
fbAdr[3*(i+x)+1] = (u8)(alpha*(float)rgbColor[1]+one_minus_alpha*(float)fbAdr[3*(i+x)+1]);
182+
fbAdr[3*(i+x)+2] = (u8)(alpha*(float)rgbColor[2]+one_minus_alpha*(float)fbAdr[3*(i+x)+2]);
183+
}
184+
fbAdr += fbWidth * 3;
185+
}
186+
}
187+
}
188+
189+
void gfxDrawRectangle(gfxScreen_t screen, gfx3dSide_t side, u8 rgbColor[4], s16 x, s16 y, u16 width, u16 height) {
170190
_gfxDrawRectangle(screen, side, rgbColor, 240 - y, x, height, width);
171191
}
172192

0 commit comments

Comments
 (0)