Skip to content

Commit b9bd178

Browse files
Merge pull request #1 from OperationNT414C/OperationNT414C-patch-1
Ofsset and background image fix / Alpha highlight feature
2 parents 64da9a6 + d6f5c51 commit b9bd178

3 files changed

Lines changed: 66 additions & 27 deletions

File tree

source/config.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ void setColor(u8 *cfgColor, const char *color) {
2727
cfgColor[2] = (u8) (l & 0xFF);
2828
}
2929

30+
void setColorAlpha(u8 *cfgColor, const char *color) {
31+
if ( (color[6] >= '0' && color[6] <= '9') || (color[6] >= 'A' && color[6] <= 'F') || (color[6] >= 'a' && color[6] <= 'f') )
32+
{
33+
long l = strtoul(color, NULL, 16);
34+
cfgColor[0] = (u8) (l >> 8 & 0xFF);
35+
cfgColor[1] = (u8) (l >> 16 & 0xFF);
36+
cfgColor[2] = (u8) (l >> 24 & 0xFF);
37+
cfgColor[3] = (u8) (l & 0xFF);
38+
}
39+
else
40+
{
41+
setColor(cfgColor, color);
42+
cfgColor[3] = 0xFF;
43+
}
44+
}
45+
3046
static char *ini_buffer_reader(char *str, int num, void *stream) {
3147
buffer_ctx *ctx = (buffer_ctx *) stream;
3248
int idx = 0;
@@ -92,8 +108,8 @@ static int handler(void *user, const char *section, const char *name,
92108
setColor(config->bgTop2, item);
93109
} else if (MATCH("theme", "bgBottom")) {
94110
setColor(config->bgBot, item);
95-
} else if (MATCH("theme", "highlight")) {
96-
setColor(config->highlight, item);
111+
} else if (MATCH("theme", "highlight")) {
112+
setColorAlpha(config->highlight, item);
97113
} else if (MATCH("theme", "borders")) {
98114
setColor(config->borders, item);
99115
} else if (MATCH("theme", "font1")) {
@@ -239,7 +255,10 @@ void configSave() {
239255
size += snprintf(cfg+size, 256, "bgTop1=%02X%02X%02X;\n", config->bgTop1[0], config->bgTop1[1], config->bgTop1[2]);
240256
size += snprintf(cfg+size, 256, "bgTop2=%02X%02X%02X;\n", config->bgTop2[0], config->bgTop2[1], config->bgTop2[2]);
241257
size += snprintf(cfg+size, 256, "bgBottom=%02X%02X%02X;\n", config->bgBot[0], config->bgBot[1], config->bgBot[2]);
242-
size += snprintf(cfg+size, 256, "highlight=%02X%02X%02X;\n", config->highlight[0], config->highlight[1], config->highlight[2]);
258+
if ( config->highlight[3] < 0xFF )
259+
size += snprintf(cfg+size, 256, "highlight=%02X%02X%02X%02X;\n", config->highlight[2], config->highlight[1], config->highlight[0], config->highlight[3]);
260+
else
261+
size += snprintf(cfg+size, 256, "highlight=%02X%02X%02X;\n", config->highlight[0], config->highlight[1], config->highlight[2]);
243262
size += snprintf(cfg+size, 256, "borders=%02X%02X%02X;\n", config->borders[0], config->borders[1], config->borders[2]);
244263
size += snprintf(cfg+size, 256, "font1=%02X%02X%02X;\n", config->fntDef[0], config->fntDef[1], config->fntDef[2]);
245264
size += snprintf(cfg+size, 256, "font2=%02X%02X%02X;\n", config->fntSel[0], config->fntSel[1], config->fntSel[2]);
@@ -250,7 +269,7 @@ void configSave() {
250269
size += snprintf(cfg+size, 256, "[entry];\n");
251270
size += snprintf(cfg+size, 256, "title=%s;\n", config->entries[i].title);
252271
size += snprintf(cfg+size, 256, "path=%s;\n", config->entries[i].path);
253-
size += snprintf(cfg+size, 256, "offset=%ld;\n", config->entries[i].offset);
272+
size += snprintf(cfg+size, 256, "offset=%x;\n", (int)config->entries[i].offset);
254273
size += snprintf(cfg+size, 256, "key=%i;\n\n", config->entries[i].key);
255274
}
256275
#ifdef ARM9

source/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ typedef struct {
3636
u8 bgTop1[3];
3737
u8 bgTop2[3];
3838
u8 bgBot[3];
39-
u8 highlight[3];
39+
u8 highlight[4];
4040
u8 borders[3];
4141
u8 fntDef[3];
4242
u8 fntSel[3];

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)