Adjusted to be closer to concept art

This commit is contained in:
Adubbz 2018-02-21 18:32:32 +11:00
parent 8119d078e5
commit cc0e0da0e9
3 changed files with 159 additions and 59 deletions

View File

@ -17,6 +17,11 @@ void menuEntryFree(menuEntry_s* me) {
me->icon_gfx = NULL; me->icon_gfx = NULL;
} }
if (me->icon_gfx_small) {
free(me->icon_gfx_small);
me->icon_gfx_small = NULL;
}
if (me->nacp) { if (me->nacp) {
free(me->nacp); free(me->nacp);
me->nacp = NULL; me->nacp = NULL;
@ -301,6 +306,78 @@ void menuEntryParseIcon(menuEntry_s* me) {
memcpy(me->icon_gfx, imageptr, imagesize); memcpy(me->icon_gfx, imageptr, imagesize);
njDone(); njDone();
me->icon_gfx_small = downscaleIcon(me->icon_gfx);
}
uint8_t *downscaleIcon(const uint8_t *image) {
uint8_t *out = (uint8_t*)malloc(140*140*3);
if (out == NULL) {
return NULL;
}
int tmpx, tmpy;
int pos;
float sourceX, sourceY;
int destWidth = 140, destHeight = 140;
float xScale = 256.0 / (float)destWidth;
float yScale = 256.0 / (float)destHeight;
int pixelX, pixelY;
uint8_t r1, r2, r3, r4;
uint8_t g1, g2, g3, g4;
uint8_t b1, b2, b3, b4;
float fx, fy, fx1, fy1;
int w1, w2, w3, w4;
for (tmpx=0; tmpx<destWidth; tmpx++) {
for (tmpy=0; tmpy<destHeight; tmpy++) {
sourceX = tmpx * xScale;
sourceY = tmpy * yScale;
pixelX = (int)sourceX;
pixelY = (int)sourceY;
// get colours from four surrounding pixels
pos = ((pixelY + 0) * 256 + pixelX + 0) * 3;
r1 = image[pos+0];
g1 = image[pos+1];
b1 = image[pos+2];
pos = ((pixelY + 0) * 256 + pixelX + 1) * 3;
r2 = image[pos+0];
g2 = image[pos+1];
b2 = image[pos+2];
pos = ((pixelY + 1) * 256 + pixelX + 0) * 3;
r3 = image[pos+0];
g3 = image[pos+1];
b3 = image[pos+2];
pos = ((pixelY + 1) * 256 + pixelX + 1) * 3;
r4 = image[pos+0];
g4 = image[pos+1];
b4 = image[pos+2];
// determine weights
fx = sourceX - pixelX;
fy = sourceY - pixelY;
fx1 = 1.0f - fx;
fy1 = 1.0f - fy;
w1 = (int)(fx1*fy1*256.0);
w2 = (int)(fx*fy1*256.0);
w3 = (int)(fx1*fy*256.0);
w4 = (int)(fx*fy*256.0);
// set output pixels
pos = ((tmpy*destWidth) + tmpx) * 3;
out[pos+0] = (uint8_t)((r1 * w1 + r2 * w2 + r3 * w3 + r4 * w4) >> 8);
out[pos+1] = (uint8_t)((g1 * w1 + g2 * w2 + g3 * w3 + g4 * w4) >> 8);
out[pos+2] = (uint8_t)((b1 * w1 + b2 * w2 + b3 * w3 + b4 * w4) >> 8);
}
}
return out;
} }
void menuEntryParseNacp(menuEntry_s* me) { void menuEntryParseNacp(menuEntry_s* me) {

View File

@ -26,21 +26,23 @@ static void drawImage(int x, int y, int width, int height, const uint8_t *image)
} }
} }
uint8_t *folder_icon_small;
uint8_t *switchicon_questionmark_small;
static void drawEntry(menuEntry_s* me, int n, int is_active) { static void drawEntry(menuEntry_s* me, int n, int is_active) {
int x, y; int x, y;
int start_y = 96 + 108 - 32;//*(n % 2); int start_y = 720 - 100 - 140;//*(n % 2);
int end_y = start_y + 288; int end_y = start_y + 140 + 32;
int start_x = 64 + (256+16)*n;//(n / 2); int start_x = 64 + (140 + 40) * n;//(n / 2);
int end_x = /*1280 - 64*/start_x + 256; int end_x = start_x + 140;
uint8_t *imageptr = NULL; const uint8_t *smallimg = NULL;
const uint8_t *largeimg = NULL;
char tmpstr[1024]; char tmpstr[1024];
color_t border_color0 = MakeColor(255, 255, 255, 255); color_t border_color = MakeColor(255, 255, 255, 255);
color_t border_color1 = MakeColor(255, 255, 255, 255);
if (is_active) { if (is_active) {
border_color0 = MakeColor(171, 224, 245, 255); border_color = MakeColor(73, 103, 169, 255);
border_color1 = MakeColor(189, 228, 242, 255);
} }
//{ //{
@ -53,23 +55,21 @@ static void drawEntry(menuEntry_s* me, int n, int is_active) {
} }
//DrawPixelRaw(x, start_y , border_color0); //DrawPixelRaw(x, start_y , border_color0);
DrawPixelRaw(x, end_y , border_color0); DrawPixelRaw(x, end_y , border_color);
DrawPixelRaw(x, start_y-1, border_color0); DrawPixelRaw(x, start_y-1, border_color);
DrawPixelRaw(x, end_y +1, border_color0); DrawPixelRaw(x, end_y +1, border_color);
DrawPixelRaw(x, start_y-2, border_color0); DrawPixelRaw(x, start_y-2, border_color);
DrawPixelRaw(x, end_y +2, border_color0); DrawPixelRaw(x, end_y +2, border_color);
DrawPixelRaw(x, start_y-3, border_color);
DrawPixelRaw(x, end_y +3, border_color);
if (is_active) { if (is_active) {
DrawPixelRaw(x, start_y-3, border_color0); DrawPixelRaw(x, start_y-3, border_color);
DrawPixelRaw(x, end_y +3, border_color0); DrawPixelRaw(x, end_y +3, border_color);
DrawPixelRaw(x, start_y-4, border_color0); DrawPixelRaw(x, start_y-4, border_color);
DrawPixelRaw(x, end_y +4, border_color0); DrawPixelRaw(x, end_y +4, border_color);
DrawPixelRaw(x, start_y-5, border_color1); DrawPixelRaw(x, start_y-5, border_color);
DrawPixelRaw(x, end_y +5, border_color1); DrawPixelRaw(x, end_y +5, border_color);
}
else {
DrawPixelRaw(x, start_y-3, border_color1);
DrawPixelRaw(x, end_y +3, border_color1);
} }
} }
@ -81,23 +81,19 @@ static void drawEntry(menuEntry_s* me, int n, int is_active) {
break; break;
} }
DrawPixelRaw(start_x , y, border_color0); DrawPixelRaw(start_x , y, border_color);
DrawPixelRaw(end_x , y, border_color0); DrawPixelRaw(end_x , y, border_color);
DrawPixelRaw(start_x-1, y, border_color0); DrawPixelRaw(start_x-1, y, border_color);
DrawPixelRaw(end_x +1, y, border_color0); DrawPixelRaw(end_x +1, y, border_color);
DrawPixelRaw(start_x-2, y, border_color0); DrawPixelRaw(start_x-2, y, border_color);
DrawPixelRaw(end_x +2, y, border_color0); DrawPixelRaw(end_x +2, y, border_color);
DrawPixelRaw(start_x-3, y, border_color);
DrawPixelRaw(end_x +3, y, border_color);
if (is_active) { if (is_active) {
DrawPixelRaw(start_x-3, y, border_color0); DrawPixelRaw(start_x-4, y, border_color);
DrawPixelRaw(end_x +3, y, border_color0); DrawPixelRaw(end_x +4, y, border_color);
DrawPixelRaw(start_x-4, y, border_color0); DrawPixelRaw(start_x-5, y, border_color);
DrawPixelRaw(end_x +4, y, border_color0);
DrawPixelRaw(start_x-5, y, border_color1);
}
else {
DrawPixelRaw(start_x-3, y, border_color1);
//DrawPixelRaw(end_x +3, y, border_color1);
} }
} }
//} //}
@ -108,24 +104,40 @@ static void drawEntry(menuEntry_s* me, int n, int is_active) {
} }
} }
if (me->icon_gfx) if (me->icon_gfx_small && me->icon_gfx) {
imageptr = me->icon_gfx; smallimg = me->icon_gfx_small;
else if (me->type == ENTRY_TYPE_FOLDER) largeimg = me->icon_gfx;
imageptr = (uint8_t*)folder_icon_bin; }
else else if (me->type == ENTRY_TYPE_FOLDER) {
imageptr = (uint8_t*)switchicon_questionmark_bin; smallimg = folder_icon_small;
largeimg = folder_icon_bin;
}
else {
smallimg = switchicon_questionmark_small;
largeimg = switchicon_questionmark_bin;
}
if (imageptr) drawImage(start_x, start_y+32, 256, 256, imageptr); if (smallimg) {
drawImage(start_x, start_y + 32, 140, 140, smallimg);
}
if (is_active && largeimg) {
drawImage(740, 100, 256, 256, largeimg);
}
DrawTextTruncate(tahoma12, start_x + 8, start_y + 8, MakeColor(64, 64, 64, 255), me->name, 256 - 32, "..."); DrawTextTruncate(tahoma12, start_x + 8, start_y + 8, MakeColor(64, 64, 64, 255), me->name, 256 - 32, "...");
if (is_active) { if (is_active) {
start_x = 64; start_x = 200;
start_y = 96 + 32 + 288 + 64; start_y = 155;
DrawText(tahoma24, start_x, start_y, MakeColor(255, 255, 255, 255), me->name);
memset(tmpstr, 0, sizeof(tmpstr)); memset(tmpstr, 0, sizeof(tmpstr));
snprintf(tmpstr, sizeof(tmpstr)-1, "Name: %s\nAuthor: %s\nVersion: %s", me->name, me->author, me->version); snprintf(tmpstr, sizeof(tmpstr)-1, "Author: %s", me->author);
DrawText(tahoma12, start_x, start_y, MakeColor(255, 255, 255, 255), tmpstr); DrawText(tahoma12, start_x, start_y + 28 + 30, MakeColor(255, 255, 255, 255), tmpstr);
memset(tmpstr, 0, sizeof(tmpstr));
snprintf(tmpstr, sizeof(tmpstr)-1, "Version: %s", me->version);
DrawText(tahoma12, start_x, start_y + 28 + 30 + 18 + 6, MakeColor(255, 255, 255, 255), tmpstr);
} }
} }
@ -139,13 +151,16 @@ void menuStartup() {
#endif #endif
menuScan(path); menuScan(path);
folder_icon_small = downscaleIcon(folder_icon_bin);
switchicon_questionmark_small = downscaleIcon(switchicon_questionmark_bin);
} }
color_t waveBlendAdd(color_t a, color_t b, float alpha) { color_t waveBlendAdd(color_t a, color_t b, float alpha) {
return MakeColor(a.r+(b.r*alpha), a.g+b.g*alpha, a.b + b.b*alpha, 255); return MakeColor(a.r+(b.r*alpha), a.g+b.g*alpha, a.b + b.b*alpha, 255);
} }
const int ENABLE_WAVE_BLENDING = 1; const int ENABLE_WAVE_BLENDING = 0;
double timer; double timer;
void drawWave(float timer, color_t color, float height, float phase, float speed) { void drawWave(float timer, color_t color, float height, float phase, float speed) {
@ -161,7 +176,13 @@ void drawWave(float timer, color_t color, float height, float phase, float speed
for (y=wave_top_y; y<720; y++) { for (y=wave_top_y; y<720; y++) {
alpha = clamp(y-wave_top_y, 0.0, 1.0) * 0.3; alpha = clamp(y-wave_top_y, 0.0, 1.0) * 0.3;
existing_color = FetchPixelColor(x, y); existing_color = FetchPixelColor(x, y);
new_color = ENABLE_WAVE_BLENDING ? waveBlendAdd(existing_color, color, alpha) : color;
if (ENABLE_WAVE_BLENDING || alpha < 0.3) {
new_color = waveBlendAdd(existing_color, color, alpha);
}
else {
new_color = color;
}
DrawPixelRaw(x, y, new_color); DrawPixelRaw(x, y, new_color);
} }
@ -181,14 +202,14 @@ void menuLoop() {
} }
} }
DrawText(tahoma24, 64, 64, MakeColor(255, 255, 255, 255), "The Homebrew Launcher"); drawWave(timer, MakeColor(73, 103, 169, 255), 320.0, 0.0, 3.0);
DrawText(tahoma12, 64 + 256 + 128 + 128, 64 + 16, MakeColor(255, 255, 255, 255), "v1.0.0"); drawWave(timer, MakeColor(66, 154, 159, 255), 300.0, 2.0, 3.5);
DrawText(tahoma12, 64 + 256 + 128 + 128, 64 + 16 + 16, MakeColor(255, 255, 255, 255), menu->dirname); drawWave(timer, MakeColor(96, 204, 204, 255), 280.0, 4.0, -2.5);
timer += 0.05;
drawWave(timer, MakeColor(73, 103, 169, 255), 160.0, 0.0, 3.0); DrawText(tahoma24, 40, 30, MakeColor(255, 255, 255, 255), "hbl");
drawWave(timer, MakeColor(66, 154, 159, 255), 150.0, 2.0, 3.5); DrawText(tahoma12, 40 + 46, 30 + 16, MakeColor(255, 255, 255, 255), "v1.0.0");
drawWave(timer, MakeColor(96, 204, 204, 255), 140.0, 4.0, -2.5); DrawText(tahoma12, 40, 720 - 32 - 16, MakeColor(255, 255, 255, 255), menu->dirname);
timer += 0.025;
if (menu->nEntries==0) if (menu->nEntries==0)
{ {

View File

@ -45,6 +45,7 @@ struct menuEntry_s_tag
uint8_t *icon; uint8_t *icon;
size_t icon_size; size_t icon_size;
uint8_t *icon_gfx; uint8_t *icon_gfx;
uint8_t *icon_gfx_small;
NacpStruct *nacp; NacpStruct *nacp;
}; };
@ -54,6 +55,7 @@ void menuEntryFree(menuEntry_s* me);
bool fileExists(const char* path); bool fileExists(const char* path);
bool menuEntryLoad(menuEntry_s* me, const char* name, bool shortcut); bool menuEntryLoad(menuEntry_s* me, const char* name, bool shortcut);
void menuEntryParseIcon(menuEntry_s* me); void menuEntryParseIcon(menuEntry_s* me);
uint8_t *downscaleIcon(const uint8_t *image);
void menuEntryParseNacp(menuEntry_s* me); void menuEntryParseNacp(menuEntry_s* me);
menu_s* menuGetCurrent(void); menu_s* menuGetCurrent(void);