Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions workspace/all/battery/battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,9 @@ void renderPage()
// monochrome is more MinUI, but some colours are nice
const bool ilikeitcolourful = true;
if(ilikeitcolourful) {
white_pixel_color = SDL_MapRGB(screen->format, 255, 255, 255);
red_pixel_color = SDL_MapRGB(screen->format, 255, 170, 170);
blue_pixel_color = SDL_MapRGB(screen->format, 89, 167, 255);
white_pixel_color = SDL_MapRGBA(screen->format, 255, 255, 255, 255);
red_pixel_color = SDL_MapRGBA(screen->format, 255, 170, 170, 255);
blue_pixel_color = SDL_MapRGBA(screen->format, 89, 167, 255, 255);
pixel_color = white_pixel_color;
}

Expand Down
200 changes: 171 additions & 29 deletions workspace/all/common/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,47 +110,57 @@ SDL_Color ALT_BUTTON_TEXT_COLOR;
// Function to convert hex color code to RGB and set the values
static inline uint32_t HexToUint(const char *hexColor)
{
int r, g, b;
sscanf(hexColor, "%02x%02x%02x", &r, &g, &b);
return SDL_MapRGB(gfx.screen->format, r, g, b);
int r, g, b, a = 255; // Default alpha value to 255 (fully opaque)
// hex color code may or may not have alpha channel, so we need to handle both cases
if (strlen(hexColor) == 8) // If the hex color code has alpha channel
{
sscanf(hexColor, "%02x%02x%02x%02x", &r, &g, &b, &a);
}
else // If the hex color code does not have alpha channel
{
sscanf(hexColor, "%02x%02x%02x", &r, &g, &b);
}
return SDL_MapRGBA(gfx.screen->format, r, g, b, a);
}

static inline uint32_t HexToUint32_unmapped(const char *hexColor)
{
// Convert the hex string to an unsigned long
uint32_t value = (uint32_t)strtoul(hexColor, NULL, 16);
return value;
// Convert the hex string to an unsigned long
uint32_t value = (uint32_t)strtoul(hexColor, NULL, 16);
return value;
}

static inline void rgb_unpack(uint32_t col, int *r, int *g, int *b)
static inline void rgba_unpack(uint32_t col, int *r, int *g, int *b, int *a)
{
*r = (col >> 16) & 0xff;
*g = (col >> 8) & 0xff;
*b = col & 0xff;
*r = (col >> 24) & 0xff;
*g = (col >> 16) & 0xff;
*b = (col >> 8) & 0xff;
*a = col & 0xff;
}

static inline uint32_t rgb_pack(int r, int g, int b)
static inline uint32_t rgba_pack(int r, int g, int b, int a)
{
return (r << 16) + (g << 8) + b;
return (r << 24) + (g << 16) + (b << 8) + a;
}

static inline uint32_t mapUint(uint32_t col)
{
int r, g, b;
rgb_unpack(col, &r, &g, &b);
return SDL_MapRGB(gfx.screen->format, r, g, b);
int r, g, b, a;
rgba_unpack(col, &r, &g, &b, &a);
return SDL_MapRGBA(gfx.screen->format, r, g, b, a);
}

static inline uint32_t UintMult(uint32_t color, uint32_t modulate_rgb)
static inline uint32_t UintMult(uint32_t color, uint32_t modulate_rgba)
{
SDL_Color dest = uintToColour(color);
SDL_Color modulate = uintToColour(modulate_rgb);
SDL_Color modulate = uintToColour(modulate_rgba);

dest.r = (int)dest.r * modulate.r / 255;
dest.g = (int)dest.g * modulate.g / 255;
dest.b = (int)dest.b * modulate.b / 255;
dest.a = (int)dest.a * modulate.a / 255;

return (dest.r << 16) | (dest.g << 8) | dest.b;
return (dest.r << 24) | (dest.g << 16) | (dest.b << 8) | dest.a;
}

///////////////////////////////
Expand Down Expand Up @@ -370,10 +380,15 @@ SDL_Surface *GFX_init(int mode)
RGB_DARK_GRAY = SDL_MapRGB(gfx.screen->format, TRIAD_DARK_GRAY);

asset_rgbs[ASSET_WHITE_PILL] = RGB_WHITE;
asset_rgbs[ASSET_WHITE_RECT] = RGB_WHITE;
asset_rgbs[ASSET_BLACK_PILL] = RGB_BLACK;
asset_rgbs[ASSET_BLACK_RECT] = RGB_BLACK;
asset_rgbs[ASSET_DARK_GRAY_PILL] = RGB_DARK_GRAY;
asset_rgbs[ASSET_DARK_GRAY_RECT] = RGB_DARK_GRAY;
asset_rgbs[ASSET_OPTION] = RGB_DARK_GRAY;
asset_rgbs[ASSET_OPTION_RECT] = RGB_DARK_GRAY;
asset_rgbs[ASSET_BUTTON] = RGB_WHITE;
asset_rgbs[ASSET_BUTTON_RECT] = RGB_WHITE;
asset_rgbs[ASSET_PAGE_BG] = RGB_WHITE;
asset_rgbs[ASSET_STATE_BG] = RGB_WHITE;
asset_rgbs[ASSET_PAGE] = RGB_BLACK;
Expand All @@ -387,8 +402,13 @@ SDL_Surface *GFX_init(int mode)
asset_rects[ASSET_WHITE_PILL] = (SDL_Rect){SCALE4(1, 1, 30, 30)};
asset_rects[ASSET_BLACK_PILL] = (SDL_Rect){SCALE4(33, 1, 30, 30)};
asset_rects[ASSET_DARK_GRAY_PILL] = (SDL_Rect){SCALE4(65, 1, 30, 30)};
asset_rects[ASSET_WHITE_RECT] = (SDL_Rect){SCALE4(1+14, 1, 2, 30)}; // two pixels wide, middle of the asset
asset_rects[ASSET_BLACK_RECT] = (SDL_Rect){SCALE4(33+14, 1, 2, 30)}; // two pixels wide, middle of the asset
asset_rects[ASSET_DARK_GRAY_RECT] = (SDL_Rect){SCALE4(65+14, 1, 2, 30)}; // two pixels wide, middle of the asset
asset_rects[ASSET_OPTION] = (SDL_Rect){SCALE4(97, 1, 20, 20)};
asset_rects[ASSET_OPTION_RECT] = (SDL_Rect){SCALE4(97+9, 1, 2, 20)}; // two pixels wide, middle of the asset
asset_rects[ASSET_BUTTON] = (SDL_Rect){SCALE4(1, 33, 20, 20)};
asset_rects[ASSET_BUTTON_RECT] = (SDL_Rect){SCALE4(1+9, 33, 2, 20)}; // two pixels wide, middle of the asset
asset_rects[ASSET_PAGE_BG] = (SDL_Rect){SCALE4(64, 33, 15, 15)};
asset_rects[ASSET_STATE_BG] = (SDL_Rect){SCALE4(23, 54, 8, 8)};
asset_rects[ASSET_PAGE] = (SDL_Rect){SCALE4(39, 54, 6, 6)};
Expand Down Expand Up @@ -1347,13 +1367,13 @@ void GFX_freeAAScaler(void)

///////////////////////////////

SDL_Color /*GFX_*/ uintToColour(uint32_t colour)
SDL_Color /*GFX_*/ uintToColour(uint32_t rgba)
{
SDL_Color tempcol;
tempcol.a = 255;
tempcol.r = (colour >> 16) & 0xFF;
tempcol.g = (colour >> 8) & 0xFF;
tempcol.b = colour & 0xFF;
tempcol.r = (rgba >> 24) & 0xFF;
tempcol.g = (rgba >> 16) & 0xFF;
tempcol.b = (rgba >> 8) & 0xFF;
tempcol.a = rgba & 0xFF;
return tempcol;
}

Expand Down Expand Up @@ -1646,21 +1666,71 @@ void GFX_blitSurfaceColor(SDL_Surface *src, SDL_Rect *src_rect, SDL_Surface *dst
else if (asset_color == THEME_COLOR7)
asset_color = THEME_COLOR7_255;

SDL_Color tint = uintToColour(asset_color);

SDL_Color restore;
Uint8 restore_a;
SDL_BlendMode restore_blend;
SDL_GetSurfaceColorMod(src, &restore.r, &restore.g, &restore.b);
SDL_SetSurfaceColorMod(src,
(asset_color >> 16) & 0xFF,
(asset_color >> 8) & 0xFF,
asset_color & 0xFF);
SDL_GetSurfaceAlphaMod(src, &restore_a);
SDL_GetSurfaceBlendMode(src, &restore_blend);

SDL_SetSurfaceColorMod(src, tint.r, tint.g, tint.b);
SDL_SetSurfaceAlphaMod(src, tint.a);
SDL_SetSurfaceBlendMode(src, SDL_BLENDMODE_BLEND);
SDL_BlitSurface(src, src_rect, dst, dst_rect);
SDL_SetSurfaceColorMod(src, restore.r, restore.g, restore.b);
SDL_SetSurfaceAlphaMod(src, restore_a);
SDL_SetSurfaceBlendMode(src, restore_blend);
}
else
{
SDL_BlitSurface(src, src_rect, dst, dst_rect);
}
}

static void GFX_blitSurfaceColorScaled(SDL_Surface *src, SDL_Rect *src_rect, SDL_Surface *dst, SDL_Rect *dst_rect, uint32_t asset_color)
{
if (asset_color != RGB_WHITE)
{
if (asset_color == THEME_COLOR1)
asset_color = THEME_COLOR1_255;
else if (asset_color == THEME_COLOR2)
asset_color = THEME_COLOR2_255;
else if (asset_color == THEME_COLOR3)
asset_color = THEME_COLOR3_255;
else if (asset_color == THEME_COLOR4)
asset_color = THEME_COLOR4_255;
else if (asset_color == THEME_COLOR5)
asset_color = THEME_COLOR5_255;
else if (asset_color == THEME_COLOR6)
asset_color = THEME_COLOR6_255;
else if (asset_color == THEME_COLOR7)
asset_color = THEME_COLOR7_255;

SDL_Color tint = uintToColour(asset_color);

SDL_Color restore;
Uint8 restore_a;
SDL_BlendMode restore_blend;
SDL_GetSurfaceColorMod(src, &restore.r, &restore.g, &restore.b);
SDL_GetSurfaceAlphaMod(src, &restore_a);
SDL_GetSurfaceBlendMode(src, &restore_blend);

SDL_SetSurfaceColorMod(src, tint.r, tint.g, tint.b);
SDL_SetSurfaceAlphaMod(src, tint.a);
SDL_SetSurfaceBlendMode(src, SDL_BLENDMODE_BLEND);
SDL_BlitScaled(src, src_rect, dst, dst_rect);
SDL_SetSurfaceColorMod(src, restore.r, restore.g, restore.b);
SDL_SetSurfaceAlphaMod(src, restore_a);
SDL_SetSurfaceBlendMode(src, restore_blend);
}
else
{
SDL_BlitScaled(src, src_rect, dst, dst_rect);
}
}

void GFX_blitAssetColor(int asset, SDL_Rect *src_rect, SDL_Surface *dst, SDL_Rect *dst_rect, uint32_t asset_color)
{

Expand All @@ -1685,6 +1755,47 @@ void GFX_blitAsset(int asset, SDL_Rect *src_rect, SDL_Surface *dst, SDL_Rect *ds
{
GFX_blitAssetColor(asset, src_rect, dst, dst_rect, RGB_WHITE);
}

static void GFX_fillRectBlend(SDL_Surface *dst, const SDL_Rect *rect, uint32_t mapped_color)
{
if (!dst || !rect || rect->w <= 0 || rect->h <= 0)
return;

Uint8 r, g, b, a;
SDL_GetRGBA(mapped_color, dst->format, &r, &g, &b, &a);

SDL_Surface *tmp = SDL_CreateRGBSurfaceWithFormat(0, rect->w, rect->h,
32, SDL_PIXELFORMAT_ARGB8888);
if (!tmp)
return;

SDL_SetSurfaceBlendMode(tmp, SDL_BLENDMODE_BLEND);
SDL_FillRect(tmp, NULL, SDL_MapRGBA(tmp->format, r, g, b, a));

SDL_Rect dst_rect = *rect;
SDL_BlitSurface(tmp, NULL, dst, &dst_rect);
SDL_FreeSurface(tmp);
}

static int GFX_pillRectAsset(int asset)
{
switch (asset)
{
case ASSET_WHITE_PILL:
return ASSET_WHITE_RECT;
case ASSET_BLACK_PILL:
return ASSET_BLACK_RECT;
case ASSET_DARK_GRAY_PILL:
return ASSET_DARK_GRAY_RECT;
case ASSET_BUTTON:
return ASSET_BUTTON_RECT;
case ASSET_OPTION:
return ASSET_OPTION_RECT;
default:
return -1;
}
}

void GFX_blitPillColor(int asset, SDL_Surface *dst, SDL_Rect *dst_rect, uint32_t asset_color, uint32_t fill_color)
{
int x = dst_rect->x;
Expand All @@ -1704,8 +1815,19 @@ void GFX_blitPillColor(int asset, SDL_Surface *dst, SDL_Rect *dst_rect, uint32_t
x += r;
if (w > 0)
{
// SDL_FillRect(dst, &(SDL_Rect){x,y,w,h}, UintMult(fill_color, asset_color));
SDL_FillRect(dst, &(SDL_Rect){x, y, w, h}, asset_color);
int rect_asset = GFX_pillRectAsset(asset);
if (rect_asset >= 0)
{
uint32_t center_color = (fill_color != RGB_WHITE) ? fill_color : asset_color;
SDL_Rect src_rect = asset_rects[rect_asset];
SDL_Rect center_dst = {x, y, w, h};
GFX_blitSurfaceColorScaled(gfx.assets, &src_rect, dst, &center_dst, center_color);
}
else
{
// Fallback for non-pill assets that still use this helper.
GFX_fillRectBlend(dst, &(SDL_Rect){x, y, w, h}, asset_color);
}
x += w;
}
GFX_blitAssetColor(asset, &(SDL_Rect){r, 0, r, h}, dst, &(SDL_Rect){x, y}, asset_color);
Expand Down Expand Up @@ -2216,6 +2338,26 @@ int GFX_blitButtonGroup(char **pairs, int primary, SDL_Surface *dst, int align_r
return ow;
}

void GFX_blitTopCurtain(SDL_Surface* dst)
{
// blit a top curtain to the screen, which is a semi-transparent black rectangle at the top of the screen
int opacity = CFG_getGameSwitcherCurtain() * 255 / 100; // convert percentage to 0-255 range
if(opacity <= 0)
return; // no need to draw if fully transparent
SDL_Rect rect = {0, 0, dst->w, SCALE1(PADDING+PILL_SIZE+PADDING)};
GFX_fillRectBlend(dst, &rect, SDL_MapRGBA(dst->format, 0, 0, 0, opacity));
}

void GFX_blitBottomCurtain(SDL_Surface* dst)
{
// blit a bottom curtain to the screen, which is a semi-transparent black rectangle at the bottom of the screen
int opacity = CFG_getGameSwitcherCurtain() * 255 / 100; // convert percentage to 0-255 range
if(opacity <= 0)
return; // no need to draw if fully transparent
SDL_Rect rect = {0, dst->h - SCALE1(PADDING+PILL_SIZE+PADDING), dst->w, SCALE1(PADDING+PILL_SIZE+PADDING)};
GFX_fillRectBlend(dst, &rect, SDL_MapRGBA(dst->format, 0, 0, 0, opacity));
}

#define MAX_TEXT_LINES 16
void GFX_sizeText(TTF_Font *font, const char *str, int leading, int *w, int *h)
{
Expand Down
9 changes: 8 additions & 1 deletion workspace/all/common/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,13 @@ enum {
ASSET_WHITE_PILL,
ASSET_BLACK_PILL,
ASSET_DARK_GRAY_PILL,
ASSET_WHITE_RECT,
ASSET_BLACK_RECT,
ASSET_DARK_GRAY_RECT,
ASSET_OPTION,
ASSET_OPTION_RECT,
ASSET_BUTTON,
ASSET_BUTTON_RECT,
ASSET_PAGE_BG,
ASSET_STATE_BG,
ASSET_PAGE,
Expand Down Expand Up @@ -281,7 +286,7 @@ SDL_Surface* GFX_init(int mode);

void GFX_setMode(int mode);
int GFX_hdmiChanged(void);
SDL_Color /*GFX_*/ uintToColour(uint32_t colour);
SDL_Color /*GFX_*/ uintToColour(uint32_t rgba);

#define GFX_clear PLAT_clearVideo // (SDL_Surface* screen)
#define GFX_clearAll PLAT_clearAll // (void)
Expand Down Expand Up @@ -352,6 +357,8 @@ void GFX_blitMessage(TTF_Font* font, char* msg, SDL_Surface* dst, SDL_Rect* dst_

int GFX_blitHardwareGroup(SDL_Surface* dst, int show_setting);
void GFX_blitHardwareHints(SDL_Surface* dst, int show_setting);
void GFX_blitTopCurtain(SDL_Surface* dst);
void GFX_blitBottomCurtain(SDL_Surface* dst);

typedef enum {
INDICATOR_BRIGHTNESS = 1,
Expand Down
Loading
Loading