First version

This commit is contained in:
Philip Minakov 2026-05-19 23:06:04 +04:00
commit 884d11f014
No known key found for this signature in database
GPG key ID: 932F1B884934DB0F
15 changed files with 1537 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
/.idea/
/build_elf/

11
CMakeLists.txt Normal file
View file

@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.28.2)
if(BUILD_TARGET STREQUAL "elf")
include(../sdk/config.cmake)
project(sieelf_89_theme_engine C)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
add_subdirectory(elf)
elseif(BUILD_TARGET STREQUAL "patch")
project(patch_89_theme_engine C)
add_subdirectory(patch)
endif()

21
README.md Normal file
View file

@ -0,0 +1,21 @@
# 89 Theme Engine – Native ELF Theme Engine for Siemens Mobile Phones
89 Theme Engine is a native ELF daemon that replaces the standard UI theme system. It builds the entire interface from a single wallpaper image plus a skin file (.89), allowing full customisation of colours, borders, overlays, and more.
## Building
The SDK must be located at `../sdk` relative to the project root.
```bash
mkdir build_elf && cd build_elf
cmake .. -DBUILD_TARGET=elf
make
```
## Usage
1. Copy `89ThemeEngine.elf` to `X:\ZBin\daemons\`. The ELF runs as a daemon.
2. **Associate the `.89` extension** with `89ThemeEngine.elf`:
- **RUN** → `89ThemeEngine.elf` – applies the theme.
- **ALTRUN** → `CfgEdit.elf` – allows editing the skin file.
3. Run the ELF once manually. It will create a default skin file named `Default.89` in the same folder as the ELF.
4. Click on a `.89` file (e.g., `Default.89`).
The ELF will parse the skin, combine it with the current wallpaper, and apply the theme immediately.

9
elf/CMakeLists.txt Normal file
View file

@ -0,0 +1,9 @@
link_libraries(crt crt_helper gcc c m)
file(GLOB_RECURSE SOURCES "src/*.c")
add_definitions(-DSWILIB_MODERN)
add_executable(89ThemeEngine_ELKA ${SOURCES})
target_sdk_setup(89ThemeEngine_ELKA ELKA)
target_compile_options(89ThemeEngine_ELKA BEFORE PUBLIC -std=c11 -Wall -Werror)
set_target_properties(89ThemeEngine_ELKA PROPERTIES OUTPUT_NAME "89ThemeEngine")

22
elf/src/config.c Normal file
View file

@ -0,0 +1,22 @@
#include <swilib.h>
#include "config.h"
CONFIG CFG = {
{CFG_STR_UTF8, "Skin path", 3, 127},
"0:\\Skins\\Red.89",
{CFG_CHECKBOX, "Apply skin on startup", 0, 1},
0,
{CFG_UINT, "Skin apply delay (ms)", 500, 10000},
1500,
{CFG_UINT, "Separator icon id", 0, 2000},
1335,
};
char CFG_PATH[] = "?:\\zbin\\etc\\89ThemeEngine.bcfg";
void Config_Init() {
CFG_PATH[0] = BCFG_GetDefaultDisk();
if (BCFG_LoadConfig(CFG_PATH, &CFG, sizeof(CFG)) == -1) {
BCFG_SaveConfig(CFG_PATH, &CFG, sizeof(CFG));
}
}

19
elf/src/config.h Normal file
View file

@ -0,0 +1,19 @@
#pragma once
#include <cfg_items.h>
typedef struct {
const CFG_HDR cfghdr_0;
char skin_path[128];
const CFG_HDR cfghdr_1;
int auto_apply;
const CFG_HDR cfghdr_2;
int apply_delay_ms;
const CFG_HDR cfghdr_3;
int separator_icon_id;
} CONFIG;
extern CONFIG CFG;
extern char CFG_PATH[];
void Config_Init();

374
elf/src/img_utils.c Normal file
View file

@ -0,0 +1,374 @@
#include <swilib.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MergeIMGHDR ((void (*)(IMGHDR *, IMGHDR *))(0xa094d0dc | 1))
#define RGB565_TRANSPARENT_COLOR 0xE000
static void RGB565_to_ARGB8888(uint8_t dest[4], uint16_t pixel) {
if (pixel == RGB565_TRANSPARENT_COLOR) {
memset(dest, 0, 4);
return;
}
uint8_t r = (pixel >> 11) & 0x1F;
uint8_t g = (pixel >> 5) & 0x3F;
uint8_t b = pixel & 0x1F;
r = (r << 3) | (r >> 2);
g = (g << 2) | (g >> 4);
b = (b << 3) | (b >> 2);
dest[0] = b;
dest[1] = g;
dest[2] = r;
dest[3] = 0xFF;
}
static uint16_t ARGB8888_to_RGB565(const uint8_t src[4]) {
if (src[3] == 0) {
return RGB565_TRANSPARENT_COLOR;
}
const uint8_t r = src[2] >> 3;
const uint8_t g = src[1] >> 2;
const uint8_t b = src[0] >> 3;
return (r << 11) | (g << 5) | b;
}
static void BlendPixel(uint8_t dest_pixel[4], const uint8_t src_pixel[4]) {
const uint8_t alpha = src_pixel[3];
if (alpha == 0) { // transparent
} else if (alpha == 0xFF) {
dest_pixel[0] = src_pixel[0];
dest_pixel[1] = src_pixel[1];
dest_pixel[2] = src_pixel[2];
dest_pixel[3] = 0xFF;
} else {
const uint8_t inv = 0xFF - alpha;
dest_pixel[0] = (src_pixel[0] * alpha + dest_pixel[0] * inv) / 0xFF;
dest_pixel[1] = (src_pixel[1] * alpha + dest_pixel[1] * inv) / 0xFF;
dest_pixel[2] = (src_pixel[2] * alpha + dest_pixel[2] * inv) / 0xFF;
dest_pixel[3] = alpha + (dest_pixel[3] * inv) / 0xFF;
}
}
static void NormalizeRange(uint16_t *start, uint16_t *end) {
if (*start > *end) {
uint16_t t = *start;
*start = *end;
*end = t;
}
}
static void ConvertPhoneColor(uint8_t dest[4], const uint8_t src[4]) {
memcpy(dest, src, 4);
const int alpha = dest[3];
dest[3] = (alpha * 0xFF + 50) / 0x64;
}
static int IMGHDR_IsValid(const IMGHDR *img) {
return (img && img->bitmap && img->bpnum == IMGHDR_TYPE_ARGB8888);
}
int IMGHDR_Clone(IMGHDR *dest, const IMGHDR *src) {
if (!dest || !src || !src->bitmap || dest == src) {
return 0;
}
const size_t size = CalcBitmapSize((short)src->w, (short)src->h, src->bpnum);
uint8_t *dest_b = malloc(size);
if (!dest_b) {
return 0;
}
if (dest->bitmap) {
mfree(dest->bitmap);
}
memcpy(dest_b, src->bitmap, size);
memcpy(dest, src, sizeof(IMGHDR));
dest->bitmap = dest_b;
return 1;
}
IMGHDR *IMGHDR_ARGB8888_to_RGB565(const IMGHDR *src) {
if (!IMGHDR_IsValid(src)) {
return NULL;
}
IMGHDR *img = malloc(sizeof(IMGHDR));
if (img) {
memcpy(img, src, sizeof(IMGHDR));
img->bpnum = IMGHDR_TYPE_RGB565;
const size_t size = CalcBitmapSize((short)img->w, (short)img->h, img->bpnum);
img->bitmap = malloc(size);
if (!img->bitmap) {
mfree(img);
return NULL;
}
uint16_t *dest_b = (uint16_t*)img->bitmap;
const uint8_t *src_b = src->bitmap;
for (int i = 0; i < img->w * img->h; i++) {
dest_b[i] = ARGB8888_to_RGB565(src_b + i * 4);
}
}
return img;
}
IMGHDR *IMGHDR_CropVertical(const IMGHDR *src, uint16_t crop_y, uint16_t crop_h) {
if (!src || !src->bitmap || src->bpnum != IMGHDR_TYPE_RGB565) {
return NULL;
}
if (crop_y + crop_h > src->h || crop_h == 0) {
return NULL;
}
IMGHDR *img = malloc(sizeof(IMGHDR));
if (img) {
memcpy(img, src, sizeof(IMGHDR));
img->h = crop_h;
const size_t size = CalcBitmapSize((short)img->w, (short)img->h, IMGHDR_TYPE_ARGB8888);
img->bitmap = malloc(size);
if (!img->bitmap) {
mfree(img);
return NULL;
}
img->bpnum = IMGHDR_TYPE_ARGB8888;
for (int i = 0; i < img->h * src->w; i++) {
uint8_t *dest_b = img->bitmap + i * 4;
uint8_t *src_b = src->bitmap + (crop_y * src->w + i) * 2;
RGB565_to_ARGB8888(dest_b, *(uint16_t*)src_b);
}
}
return img;
}
IMGHDR *IMGHDR_CreateSolid(uint16_t w, uint16_t h, const uint8_t rgba[4]) {
IMGHDR *img = malloc(sizeof(IMGHDR));
if (img) {
img->w = w;
img->h = h;
img->bpnum = IMGHDR_TYPE_ARGB8888;
const size_t size = CalcBitmapSize((short)w, (short)h, IMGHDR_TYPE_ARGB8888);
img->bitmap = malloc(size);
if (!img->bitmap) {
mfree(img);
return NULL;
}
uint8_t color[4];
ConvertPhoneColor(color, rgba);
for (int i = 0; i < w * h; i++) {
uint8_t *pixel = img->bitmap + i * 4;
pixel[0] = color[2];
pixel[1] = color[1];
pixel[2] = color[0];
pixel[3] = color[3];
}
}
return img;
}
IMGHDR *IMGHDR_CreateGlowMask(uint16_t w, uint16_t h, const uint8_t rgba[4]) {
IMGHDR *mask = malloc(sizeof(IMGHDR));
mask->w = w;
mask->h = h;
mask->bpnum = IMGHDR_TYPE_ARGB8888;
mask->bitmap = malloc(w * h * 4);
if (!mask->bitmap) {
mfree(mask);
return NULL;
}
uint8_t color[4];
ConvertPhoneColor(color, rgba);
const float cx = w / 2.0f;
const float cy = h / 2.0f;
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
const float dx = (x - cx) / cx;
const float dy = (y - cy) / cy;
const float dist = sqrtf(dx * dx + dy * dy);
float alphaFactor = 1.0f - dist * dist;
if (alphaFactor < 0) alphaFactor = 0;
const uint8_t alpha = (uint8_t)(alphaFactor * color[3]);
uint8_t *pixel = mask->bitmap + (y * w + x) * 4;
pixel[0] = color[2];
pixel[1] = color[1];
pixel[2] = color[0];
pixel[3] = alpha;
}
}
return mask;
}
void IMGHDR_Blend(IMGHDR *dest, const IMGHDR *overlay) {
if (!IMGHDR_IsValid(dest) || !IMGHDR_IsValid(overlay)) {
return;
}
if (dest->w != overlay->w || dest->h != overlay->h) {
return;
}
for (int i = 0; i < dest->w * dest->h; i++) {
BlendPixel(dest->bitmap + i * 4, overlay->bitmap + i * 4);
}
}
void IMGHDR_DrawHLine(IMGHDR *dest, uint16_t x, uint16_t y, uint16_t x2, int flags, const uint8_t rgba[4]) {
if (!IMGHDR_IsValid(dest)) {
return;
}
uint16_t start = x;
uint16_t end = x2;
NormalizeRange(&start, &end);
if (start == end) {
return;
}
if (start >= dest->w || end >= dest->w || y >= dest->h) {
return;
}
if (rgba[3] == 0x00) {
return;
}
uint8_t color[4];
ConvertPhoneColor(color, rgba);
const int count = end - start + 1;
uint8_t *pixel = dest->bitmap + (y * dest->w + start) * 4;
for (int i = 0; i < count; i++) {
if (flags & LINE_DOTTED && (i % 2) != 0) {
continue;
}
BlendPixel(pixel + i * 4, (uint8_t[4]){color[2], color[1], color[0], color[3]});
}
}
void IMGHDR_DrawVLine(IMGHDR *dest, uint16_t x, uint16_t y, uint16_t y2, int flags, const uint8_t rgba[4]) {
if (!IMGHDR_IsValid(dest)) {
return;
}
uint16_t start = y;
uint16_t end = y2;
NormalizeRange(&start, &end);
if (start == end) {
return;
}
if (start >= dest->h || end >= dest->h || x >= dest->w) {
return;
}
if (rgba[3] == 0x00) {
return;
}
uint8_t color[4];
ConvertPhoneColor(color, rgba);
const int count = end - start + 1;
uint8_t *pixel = dest->bitmap + (start * dest->w + x) * 4;
for (int i = 0; i < count; i++, pixel += dest->w * 4) {
if (flags & LINE_DOTTED && (i % 2) != 0) {
continue;
}
BlendPixel(pixel, (uint8_t[4]){color[2], color[1], color[0], color[3]});
}
}
void IMGHDR_DrawBorder(IMGHDR *dest, uint16_t x, uint16_t y, uint16_t x2, uint16_t y2, int flags, const uint8_t rgba[4]) {
IMGHDR_DrawHLine(dest, x, y, x2, flags, rgba);
IMGHDR_DrawHLine(dest, x, y2, x2, flags, rgba);
IMGHDR_DrawVLine(dest, x, y + 1, y2 - 1, flags, rgba);
IMGHDR_DrawVLine(dest, x2, y + 1, y2 - 1, flags, rgba);
}
void IMGHDR_BoxBlur(IMGHDR *dest, int radius) {
if (!IMGHDR_IsValid(dest)) {
return;
}
if (radius <= 0) {
return;
}
const int w = dest->w;
const int h = dest->h;
const size_t size = (size_t)w * h * 4;
uint8_t *tmp = malloc(size);
if (!tmp) {
return;
}
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
int sum[4] = {0};
int count = 0;
for (int dx = -radius; dx <= radius; dx++) {
int nx = x + dx;
if (nx < 0 || nx >= w) continue;
uint8_t *p = dest->bitmap + (y * w + nx) * 4;
sum[0] += p[0];
sum[1] += p[1];
sum[2] += p[2];
sum[3] += p[3];
count++;
}
uint8_t *d = tmp + (y * w + x) * 4;
d[0] = sum[0] / count;
d[1] = sum[1] / count;
d[2] = sum[2] / count;
d[3] = sum[3] / count;
}
}
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
int sum[4] = {0};
int count = 0;
for (int dy = -radius; dy <= radius; dy++) {
int ny = y + dy;
if (ny < 0 || ny >= h) continue;
uint8_t *p = tmp + (ny * w + x) * 4;
sum[0] += p[0];
sum[1] += p[1];
sum[2] += p[2];
sum[3] += p[3];
count++;
}
uint8_t *d = dest->bitmap + (y * w + x) * 4;
d[0] = sum[0] / count;
d[1] = sum[1] / count;
d[2] = sum[2] / count;
d[3] = sum[3] / count;
}
}
free(tmp);
}
void IMGHDR_TransparentV(IMGHDR *dest, uint16_t y, uint16_t y2) {
if (!IMGHDR_IsValid(dest)) {
return;
}
uint16_t start = y;
uint16_t end = y2;
NormalizeRange(&start, &end);
if (start >= dest->h || end >= dest->h) {
return;
}
for (int i = start; i <= end; i++) {
uint8_t *row = dest->bitmap + (i * dest->w) * 4;
for (int x = 0; x < dest->w; x++) {
row[x * 4 + 3] = 0x00;
}
}
}
void IMGHDR_TransparentH(IMGHDR *dest, uint16_t x, uint16_t x2) {
if (!IMGHDR_IsValid(dest)) {
return;
}
uint16_t start = x;
uint16_t end = x2;
NormalizeRange(&start, &end);
if (start >= dest->w || end >= dest->w) {
return;
}
for (int y = 0; y < dest->h; y++) {
uint8_t *row = dest->bitmap + (y * dest->w) * 4;
for (int i = start; i <= end; i++) {
row[i * 4 + 3] = 0x00;
}
}
}
void FreeIMGHDR(IMGHDR *img) {
if (img) {
mfree(img->bitmap);
mfree(img);
}
}

17
elf/src/img_utils.h Normal file
View file

@ -0,0 +1,17 @@
#pragma once
#include <swilib.h>
int IMGHDR_Clone(IMGHDR *dest, const IMGHDR *src);
IMGHDR *IMGHDR_ARGB8888_to_RGB565(const IMGHDR *src);
IMGHDR *IMGHDR_CropVertical(const IMGHDR *src, uint16_t crop_y, uint16_t crop_h);
IMGHDR *IMGHDR_CreateSolid(uint16_t w, uint16_t h, const uint8_t rgba[4]);
IMGHDR *IMGHDR_CreateGlowMask(uint16_t w, uint16_t h, const uint8_t rgba[4]);
void IMGHDR_Blend(IMGHDR *dest, const IMGHDR *overlay);
void IMGHDR_DrawHLine(IMGHDR *dest, uint16_t x, uint16_t y, uint16_t x2, int flags, const uint8_t rgba[4]);
void IMGHDR_DrawVLine(IMGHDR *dest, uint16_t x, uint16_t y, uint16_t y2, int flags, const uint8_t rgba[4]);
void IMGHDR_DrawBorder(IMGHDR *dest, uint16_t x, uint16_t y, uint16_t x2, uint16_t y2, int flags, const uint8_t rgba[4]);
void IMGHDR_BoxBlur(IMGHDR *dest, int radius);
void IMGHDR_TransparentV(IMGHDR *dest, uint16_t y, uint16_t y2);
void IMGHDR_TransparentH(IMGHDR *dest, uint16_t x, uint16_t x2);
void FreeIMGHDR(IMGHDR *img);

13
elf/src/ipc.c Normal file
View file

@ -0,0 +1,13 @@
#include <swilib.h>
#include "ipc.h"
const char *IPC_NAME = "89ThemeEngine";
void IPC_SendMessage(int submess, IPC_DATA *data) {
static IPC_REQ ipc;
IPC_REQ *p = &ipc;
p->name_to = IPC_NAME;
p->name_from = IPC_NAME;
p->data = data;
GBS_SendMessage(MMI_CEPID, MSG_IPC, submess, p);
}

16
elf/src/ipc.h Normal file
View file

@ -0,0 +1,16 @@
#pragma once
enum {
IPC_RUN,
IPC_APPLY_THEME,
};
typedef struct {
void *data0;
void *data1;
void *data2;
} IPC_DATA;
void IPC_SendMessage(int submess, IPC_DATA *data);
extern const char *IPC_NAME;

225
elf/src/main.c Normal file
View file

@ -0,0 +1,225 @@
#include <swilib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ipc.h"
#include "skin.h"
#include "theme.h"
#include "config.h"
#define REGISTRY_CLIENT_MSG_ID 0x9991
#define REGISTRY_HMI_ID_WALLPAPER 0x65
typedef struct {
CSM_RAM csm;
int reg_client_id;
char skin_path[128];
int popup_gui_id;
int please_wait_gui_id;
GBSTMR tmr_apply_theme;
} MAIN_CSM;
const int minus11 =- 11;
unsigned short maincsm_name_body[140];
int ShowWait() {
return ShowWaitBox(0x11, (int)"Applying theme...");
}
void RegClient(MAIN_CSM *csm) {
if (csm->reg_client_id == - 1) {
REG_CLIENT client = { 0 };
client.cepid = MMI_CEPID;
client.msg_id = REGISTRY_CLIENT_MSG_ID;
client.hmi_keys = (short[]){REGISTRY_HMI_ID_WALLPAPER};
client.hmi_keys_count = 1;
csm->reg_client_id = Registry_RegClient(&client);
if (csm->reg_client_id < 0) {
MsgBoxError(0x11, (int)"Failed to register client with Registry");
csm->reg_client_id = -1;
}
}
}
void ApplyTheme(MAIN_CSM *csm) {
if (Skin_Load(csm->skin_path) == 0) {
const int err = Theme_Apply();
if (err == 0) {
RegClient(csm);
ShowMSG(0x11, (int)"Theme has been applied");
} else {
char msg[32];
sprintf(msg, "Failed to apply theme, error %d", err);
ShowMSG(0x11, (int)msg);
}
} else {
MsgBoxError(0x11, (int)"Error loading skin");
}
GeneralFunc_flag1(csm->please_wait_gui_id, 1);
csm->please_wait_gui_id = 0;
}
void ApplyThemeTimerProc(GBSTMR *tmr) {
IPC_SendMessage(IPC_APPLY_THEME, NULL);
}
void ApplyThemeTimer(MAIN_CSM *csm) {
GBS_StartTimerProc(&csm->tmr_apply_theme, MsToTicks(CFG.apply_delay_ms), ApplyThemeTimerProc);
}
void ApplyThemeYesNo(const int no) {
if (!no) {
IPC_SendMessage(IPC_APPLY_THEME, NULL);
}
}
int GetDefaultSkinPath(char *dest, const char *exe_path) {
const char *p = strrchr(exe_path, '\\');
if (p) {
const size_t len = p - exe_path;
strncpy(dest, exe_path, len);
dest[len] = '\0';
strcat(dest, "\\Default.89");
return 1;
}
return 0;
}
int OnMessage(CSM_RAM *data, GBS_MSG *msg) {
MAIN_CSM *csm = (MAIN_CSM*)data;
if (msg->msg == MSG_IPC) {
const IPC_REQ *ipc = msg->data0;
if (strcmpi(ipc->name_to, IPC_NAME) == 0) {
const IPC_DATA *ipc_data = ipc->data;
if (msg->submess == IPC_RUN) {
const int csm_id = (int)ipc_data->data0;
const char *exe_path = ipc_data->data1;
const char *file_path = ipc_data->data2;
if (csm->csm.id != csm_id) {
CloseCSM(csm_id);
if (*file_path) {
strcpy(csm->skin_path, file_path);
if (!csm->popup_gui_id) {
csm->popup_gui_id = MsgBoxYesNo(0x11, (int)"Apply theme?", ApplyThemeYesNo);
}
} else {
char path[128];
if (GetDefaultSkinPath(path, exe_path)) {
Skin_Save(path);
}
}
return 0;
}
if (CFG.auto_apply && strlen(CFG.skin_path)) {
strcpy(csm->skin_path, CFG.skin_path);
ApplyThemeTimer(csm);
}
} else if (msg->submess == IPC_APPLY_THEME) {
if (!csm->please_wait_gui_id) {
csm->please_wait_gui_id = ShowWait();
SUBPROC(ApplyTheme, csm);
} else {
MsgBoxError(0x11, (int)"Theme is already being applied");
}
}
}
} else if (msg->msg == MSG_GUI_DESTROYED) {
const int gui_id = (int)msg->data0;
if (gui_id == csm->popup_gui_id) {
csm->popup_gui_id = 0;
}
} else if (msg->msg == MSG_RECONFIGURE_REQ) {
if (strcmpi(msg->data0, CFG_PATH) == 0) {
Config_Init();
ShowMSG(0x11, (int)"89ThemeEngine config updated!");
} else if (strcmpi(msg->data0, csm->skin_path) == 0) {
IPC_SendMessage(IPC_APPLY_THEME, NULL);
}
} else if (msg->msg == REGISTRY_CLIENT_MSG_ID) {
ApplyThemeTimer(csm);
}
return 1;
}
void OnCreate(CSM_RAM *data) {
MAIN_CSM *csm = (MAIN_CSM*)data;
csm->reg_client_id = -1;
csm->csm.state = CSM_STATE_OPEN;
}
void OnClose(CSM_RAM *data) {
MAIN_CSM *csm = (MAIN_CSM*)data;
if (csm->reg_client_id != -1) {
Registry_UnregClient(csm->reg_client_id);
}
GBS_DelTimer(&(csm->tmr_apply_theme));
GeneralFunc_flag1(csm->popup_gui_id, 1);
GeneralFunc_flag1(csm->please_wait_gui_id, 1);
SUBPROC(kill_elf);
}
const struct {
CSM_DESC maincsm;
WSHDR maincsm_name;
} MAINCSM = {
{
OnMessage,
OnCreate,
#ifdef NEWSGOLD
0,
0,
0,
0,
#endif
OnClose,
sizeof(MAIN_CSM),
1,
&minus11
},
{
maincsm_name_body,
NAMECSM_MAGIC1,
NAMECSM_MAGIC2,
0x0,
139,
0
}
};
void UpdateCSMname(void) {
wsprintf((WSHDR *)(&MAINCSM.maincsm_name), "89ThemeEngine");
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmain"
int main(const char *exe_path, const char *file_path) {
Config_Init();
UpdateCSMname();
LockSched();
const MAIN_CSM main_csm = { 0 };
CSM_RAM *save_cmpc = CSM_root()->csm_q->current_msg_processing_csm;
CSM_root()->csm_q->current_msg_processing_csm = CSM_root()->csm_q->csm.first;
const int csm_id = CreateCSM(&MAINCSM.maincsm, &main_csm, 0);
CSM_root()->csm_q->current_msg_processing_csm = save_cmpc;
UnlockSched();
static char s_exe_path[128];
static char s_file_path[128];
static IPC_DATA data = { 0 };
data.data0 = (void*)csm_id;
strcpy(s_exe_path, exe_path);
data.data1 = s_exe_path;
if (file_path) {
strcpy(s_file_path, file_path);
} else {
*s_file_path = 0;
}
data.data2 = s_file_path;
IPC_SendMessage(IPC_RUN, &data);
return 0;
}
#pragma GCC diagnostic pop

160
elf/src/skin.c Normal file
View file

@ -0,0 +1,160 @@
#include <swilib.h>
#include "skin.h"
SKIN_T SKIN = {
{
{CFG_LEVEL, "General", 1, 0},
{CFG_COLOR, "Select border color", 0, 0},
{0xD0, 0x20, 0x20, 0x64},
{CFG_COLOR, "Separator color", 0, 0},
{0x92, 0x01, 0x02, 0x64},
{CFG_LEVEL, "", 0, 0},
}, {
{CFG_LEVEL, "Status bar", 1, 0},
{CFG_CHECKBOX, "Blur", 0, 1},
0,
{CFG_UINT, "Blur radius", 0, 10},
0,
{CFG_CHECKBOX, "Overlay", 0, 1},
1,
{CFG_COLOR, "Overlay color", 0, 0},
{0x00, 0x00, 0x00, 0x64},
{CFG_LEVEL, "", 0, 0},
}, {
{CFG_LEVEL, "Headline", 1, 0},
{CFG_CHECKBOX, "Blur", 0, 1},
1,
{CFG_UINT, "Blur radius", 1, 10},
2,
{CFG_CHECKBOX, "Overlay", 0, 1},
0,
{CFG_COLOR, "Overlay color", 0, 0},
{0x00, 0x00, 0x00, 0x64},
{CFG_CBOX, "Border", 0, SKIN_HEADLINE_BORDER_COUNT},
SKIN_HEADLINE_BORDER_BOTTOM,
{{"Off"}, {"Bottom"}, {"Top + Bottom"}},
{CFG_UINT, "Border width", 1, 240},
228,
{CFG_COLOR, "Border color", 0, 0},
{0xD0, 0x20, 0x20, 0x50},
{CFG_COLOR, "Text color", 0, 0},
{0xFF, 0xFF, 0xFF, 0x64},
{CFG_LEVEL, "", 0, 0},
}, {
{CFG_LEVEL, "Body", 1, 0},
{CFG_CHECKBOX, "Blur", 0, 1},
1,
{CFG_UINT, "Blur radius", 1, 10},
2,
{CFG_CHECKBOX, "Overlay", 0, 1},
0,
{CFG_COLOR, "Overlay color", 0, 0},
{0x00, 0x00, 0x00, 0x64},
{CFG_COLOR, "Main text color", 0, 0},
{0xFF, 0xFF, 0xFF, 0x64},
{CFG_COLOR, "Disabled text color", 0, 0},
{0x90, 0x90, 0x90, 0x64},
{CFG_COLOR, "Edit header text color", 0, 0},
{0xB0, 0x00, 0x00, 0x64},
{CFG_COLOR, "Edit text color", 0, 0},
{0xFF, 0xFF, 0xFF, 0x64},
{CFG_LEVEL, "", 0, 0},
}, {
{CFG_LEVEL, "Tabs", 1, 0},
{CFG_COLOR, "Selected color", 0, 0},
{0x92, 0x01, 0x02, 0x64},
{CFG_CHECKBOX, "Separator", 0, 1},
1,
{CFG_UINT, "Separator width", 1, 240},
228,
{CFG_COLOR, "Separator color", 0, 0},
{0xD0, 0x20, 0x20, 0x50},
{CFG_LEVEL, "", 0, 0},
}, {
{CFG_LEVEL, "Bottom", 1, 0},
{CFG_CHECKBOX, "Blur", 0, 1},
1,
{CFG_UINT, "Blur radius", 1, 10},
2,
{CFG_CHECKBOX, "Overlay", 0, 1},
0,
{CFG_COLOR, "Overlay color", 0, 0},
{0x00, 0x00, 0x00, 0x64},
{CFG_CHECKBOX, "Border", 0, 1},
1,
{CFG_COLOR, "Border color", 0, 0},
{0xD0, 0x20, 0x20, 0x50},
{CFG_COLOR, "Text color", 0, 0},
{0xFF, 0xFF, 0xFF, 0x64},
{CFG_LEVEL, "", 0, 0},
}, {
{CFG_LEVEL, "Selection", 1, 0},
{CFG_COLOR, "Background color", 0, 0},
{0x2A, 0x01, 0x02, 0x60},
{CFG_CHECKBOX, "Border", 0, 1},
1,
{CFG_COLOR, "Border color", 0, 0},
{0x5A, 0x01, 0x02, 0x64},
{CFG_COLOR, "Selected text color", 0, 0},
{0xFF, 0xFF, 0xFF, 0x64},
{CFG_COLOR, "Unselected text color", 0, 0},
{0xEA, 0xEA, 0xEA, 0x64},
{CFG_LEVEL, "", 0, 0},
}, {
{CFG_LEVEL, "Popup", 1, 0},
{CFG_CHECKBOX, "Blur", 0, 1},
1,
{CFG_UINT, "Blur radius", 0, 10},
2,
{CFG_CHECKBOX, "Overlay", 0, 1},
0,
{CFG_COLOR, "Overlay color", 0, 0},
{0x00, 0x00, 0x00, 0x64},
{CFG_CHECKBOX, "Border", 0, 1},
1,
{CFG_COLOR, "Border color", 0, 0},
{0xD0, 0x20, 0x20, 0x50},
{
{CFG_LEVEL, "Options", 1, 0},
{CFG_CHECKBOX, "Header separator", 0, 1},
1,
{CFG_UINT, "Header separator width", 1, 240},
226,
{CFG_LEVEL, "", 0, 0},
},
{CFG_LEVEL, "", 0, 0},
}, {
{CFG_LEVEL, "Scroll bar", 1, 0},
{CFG_COLOR, "Background color", 0, 0},
{0x00, 0x00, 0x00, 0x5A},
{CFG_COLOR, "Slider color", 0, 0},
{0x92, 0x01, 0x02, 0x64},
{CFG_LEVEL, "", 0, 0},
}, {
{CFG_LEVEL, "Progress bar", 1, 0},
{CFG_COLOR, "Background color", 0, 0},
{0x00, 0x00, 0x00, 0x58},
{CFG_COLOR, "Foreground color", 0, 0},
{0xD0, 0x20, 0x20, 0x60},
{CFG_LEVEL, "", 0, 0},
}, {
{CFG_LEVEL, "Calendar", 1, 0},
{CFG_COLOR, "Day background color", 0, 0},
{0x00, 0x00, 0x00, 0x60},
{CFG_COLOR, "Weekend background color", 0, 0},
{0x50, 0x01, 0x02, 0x60},
{CFG_COLOR, "Event background color", 0, 0},
{0xB0, 0x20, 0x20, 0x60},
{CFG_COLOR, "Foreground color", 0, 0},
{0xFF, 0xFF, 0xFF, 0x64},
{CFG_LEVEL, "", 0, 0},
}
};
int Skin_Save(const char *path) {
return BCFG_SaveConfig(path, &SKIN, sizeof(SKIN));
}
int Skin_Load(const char *path) {
return BCFG_LoadConfig(path, &SKIN, sizeof(SKIN));
}

258
elf/src/skin.h Normal file
View file

@ -0,0 +1,258 @@
#pragma once
#include <swilib.h>
#include <cfg_items.h>
enum {
SKIN_HEADLINE_BORDER_OFF,
SKIN_HEADLINE_BORDER_BOTTOM,
SKIN_HEADLINE_BORDER_TOP_BOTTOM,
SKIN_HEADLINE_BORDER_COUNT,
};
#pragma pack(push, 1)
typedef struct {
const CFG_HDR cfghdr_b;
// Select border
const CFG_HDR cfghdr_0;
uint8_t select_border_col[4];
// Separator color
const CFG_HDR cfghdr_1;
uint8_t separator_col[4];
const CFG_HDR cfghdr_e;
} SKIN_GENERAL;
typedef struct {
const CFG_HDR cfghdr_b;
// Blur
const CFG_HDR cfghdr_0;
int blur;
// Blur radius
const CFG_HDR cfghdr_1;
int blur_radius;
// Overlay
const CFG_HDR cfghdr_2;
int overlay;
// Overlay color
const CFG_HDR cfghdr_3;
uint8_t overlay_col[4];
const CFG_HDR cfghdr_e;
} SKIN_STATUS_BAR;
typedef struct {
const CFG_HDR cfghdr_b;
// Blur
const CFG_HDR cfghdr_0;
int blur;
// Blur radius
const CFG_HDR cfghdr_1;
int blur_radius;
// Overlay
const CFG_HDR cfghdr_2;
int overlay;
// Overlay color
const CFG_HDR cfghdr_3;
uint8_t overlay_col[4];
// Border
const CFG_HDR cfghdr_4;
int border;
const CFG_CBOX_ITEM cfgcbox_4[3];
// Border width
const CFG_HDR cfghdr_5;
unsigned int border_width;
// Border color
const CFG_HDR cfghdr_6;
uint8_t border_col[4];
// Text color
const CFG_HDR cfghdr_7;
uint8_t text_col[4];
const CFG_HDR cfghdr_e;
} SKIN_HEADLINE;
typedef struct {
const CFG_HDR cfghdr_b;
// Blur
const CFG_HDR cfghdr_0;
int blur;
// Blur radius
const CFG_HDR cfghdr_1;
int blur_radius;
// Overlay
const CFG_HDR cfghdr_2;
int overlay;
// Overlay color
const CFG_HDR cfghdr_3;
uint8_t overlay_col[4];
// Main text color
const CFG_HDR cfghdr_4;
uint8_t main_text_col[4];
// Disabled text color
const CFG_HDR cfghdr_5;
uint8_t disabled_text_col[4];
// Edit header text color
const CFG_HDR cfghdr_6;
uint8_t edit_header_text_col[4];
// Edit text color
const CFG_HDR cfghdr_7;
uint8_t edit_text_col[4];
const CFG_HDR cfghdr_e;
} SKIN_BODY;
typedef struct {
const CFG_HDR cfghdr_b;
const CFG_HDR cfghdr_0;
uint8_t selected_bg_col[4];
// Separator
const CFG_HDR cfghdr_1;
int separator;
// Separator width
const CFG_HDR cfghdr_2;
int separator_width;
// Separator color
const CFG_HDR cfghdr_3;
uint8_t separator_col[4];
const CFG_HDR cfghdr_e;
} SKIN_TABS;
typedef struct {
const CFG_HDR cfghdr_b;
// Blur
const CFG_HDR cfghdr_0;
int blur;
// Blur radius
const CFG_HDR cfghdr_1;
int blur_radius;
// Overlay
const CFG_HDR cfghdr_2;
int overlay;
// Overlay color
const CFG_HDR cfghdr_3;
uint8_t overlay_col[4];
// Border
const CFG_HDR cfghdr_4;
int border;
// Border color
const CFG_HDR cfghdr_5;
uint8_t border_col[4];
// Text color
const CFG_HDR cfghdr_6;
uint8_t text_col[4];
const CFG_HDR cfghdr_e;
} SKIN_BOTTOM;
typedef struct {
const CFG_HDR cfghdr_b;
const CFG_HDR cfghdr_0;
// Background color
uint8_t bg_col[4];
// Border
const CFG_HDR cfghdr_1;
int border;
// Border color
const CFG_HDR cfghdr_2;
uint8_t border_col[4];
// Selected text color
const CFG_HDR cfghdr_3;
uint8_t selected_text_col[4];
// Unselected text color
const CFG_HDR cfghdr_4;
uint8_t unselected_text_col[4];
const CFG_HDR cfghdr_e;
} SKIN_SELECTION;
typedef struct {
const CFG_HDR cfghdr_b;
// Header separator
const CFG_HDR cfghdr_0;
int header_separator;
// Header separator width
const CFG_HDR cfghdr_1;
unsigned int header_separator_width;
const CFG_HDR cfghdr_e;
} SKIN_POPUP_OPTIONS;
typedef struct {
const CFG_HDR cfghdr_b;
// Blur
const CFG_HDR cfghdr_0;
int blur;
// Blur radius
const CFG_HDR cfghdr_1;
int blur_radius;
// Overlay
const CFG_HDR cfghdr_2;
int overlay;
// Overlay color
const CFG_HDR cfghdr_3;
uint8_t overlay_col[4];
// Border
const CFG_HDR cfghdr_4;
int border;
// Border color
const CFG_HDR cfghdr_5;
uint8_t border_col[4];
// Options
SKIN_POPUP_OPTIONS options;
const CFG_HDR cfghdr_e;
} SKIN_POPUP;
typedef struct {
const CFG_HDR cfghdr_b;
// Background color
const CFG_HDR cfghdr_0;
uint8_t bg_col[4];
// Slider color
const CFG_HDR cfghdr_1;
uint8_t slider_col[4];
const CFG_HDR cfghdr_e;
} SKIN_SCROLL_BAR;
typedef struct {
const CFG_HDR cfghdr_b;
// Background color
const CFG_HDR cfghdr_0;
uint8_t bg_col[4];
// Foreground color
const CFG_HDR cfghdr_1;
uint8_t fg_col[4];
const CFG_HDR cfghdr_e;
} SKIN_PROGRESS_BAR;
typedef struct {
const CFG_HDR cfghdr_b;
// Day background color
const CFG_HDR cfghdr_0;
uint8_t day_bg_col[4];
const CFG_HDR cfghdr_1;
// Weekend background color
uint8_t weekend_bg_col[4];
const CFG_HDR cfghdr_2;
// Event background color
uint8_t event_bg_col[4];
const CFG_HDR cfghdr_3;
// Foreground color
uint8_t fg_col[4];
const CFG_HDR cfghdr_e;
} SKIN_CALENDAR;
typedef struct {
SKIN_GENERAL general;
SKIN_STATUS_BAR status_bar;
SKIN_HEADLINE headline;
SKIN_BODY body;
SKIN_TABS tabs;
SKIN_BOTTOM bottom;
SKIN_SELECTION selection;
SKIN_POPUP popup;
SKIN_SCROLL_BAR scroll_bar;
SKIN_PROGRESS_BAR progress_bar;
SKIN_CALENDAR calendar;
} SKIN_T;
#pragma pack(pop)
extern SKIN_T SKIN;
int Skin_Save(const char *path);
int Skin_Load(const char *path);

387
elf/src/theme.c Normal file
View file

@ -0,0 +1,387 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <swilib.h>
#include "skin.h"
#include "config.h"
#include "img_utils.h"
#define BODY_TAB_SEPARATOR_Y 33
#define POPUP_OPTIONS_CLEAR_H 5
#define POPUP_OPTIONS_SEPARATOR_Y 34
#define POPUP_FEEDBACK_CROP_Y 40
#define POPUP_FEEDBACK_CLEAR_W 4
#define POPUP_FEEDBACK_CLEAR_H 28
#define Cs_SetColor(id, rgba) RscMgr_CsSetColor(id - 100, rgba)
#define Cs_Update() RscMgr_CsUpdate()
static uint16_t InjectImage(IMGHDR *dest, const IMGHDR *wallpaper, int crop_y) {
uint8_t *bitmap = (dest) ? dest->bitmap : NULL;
if (bitmap) {
IMGHDR *new_img = IMGHDR_CropVertical(wallpaper, crop_y, dest->h);
if (new_img) {
memcpy(dest, new_img, sizeof(IMGHDR));
mfree(bitmap);
mfree(new_img);
return dest->h;
}
}
return 0;
}
static int InjectImageSolid(IMGHDR *dest, const uint8_t rgba[4]) {
uint8_t *bitmap = (dest) ? dest->bitmap : NULL;
if (bitmap) {
IMGHDR *new_img = IMGHDR_CreateSolid(dest->w, dest->h, rgba);
if (new_img) {
memcpy(dest, new_img, sizeof(IMGHDR));
mfree(bitmap);
mfree(new_img);
return dest->h;
}
}
return 0;
}
static void ConvertImage(IMGHDR *image) {
IMGHDR *img = IMGHDR_ARGB8888_to_RGB565(image);
if (img) {
mfree(image->bitmap);
memcpy(image, img, sizeof(IMGHDR));
mfree(img);
}
}
static IMGHDR *PrepareBgImage(IMGHDR *dest, const IMGHDR *wallpaper, uint16_t crop_y,
int blur, int blur_radius, int overlay, const uint8_t *overlay_col) {
if (!dest || !dest->bitmap) {
return NULL;
}
uint16_t w = 0, h = 0;
h = InjectImage(dest, wallpaper, crop_y);
if (!h) {
return NULL;
}
w = dest->w;
if (blur) {
IMGHDR_BoxBlur(dest, blur_radius);
}
if (overlay) {
IMGHDR *img_overlay = IMGHDR_CreateSolid(w, h, overlay_col);
if (img_overlay) {
IMGHDR_Blend(dest, img_overlay);
FreeIMGHDR(img_overlay);
}
}
return dest;
}
static int ApplyGeneral() {
PIT_ResetImage(CFG.separator_icon_id);
const IMGHDR *separator = GetPITaddr(CFG.separator_icon_id);
if (separator) {
IMGHDR *new_separator = IMGHDR_CreateSolid(separator->w, separator->h, (uint8_t [4]){0x00, 0x00, 0x00, 0x00});
if (!new_separator) {
return CFG.separator_icon_id;
}
IMGHDR_DrawHLine(new_separator, 0, 0, new_separator->w - 1, LINE_DOTTED, SKIN.general.separator_col);
PIT_SetImage(CFG.separator_icon_id, new_separator);
}
Cs_SetColor(TPC_SELECT_BORDER, SKIN.general.select_border_col);
Cs_SetColor(TPC_SEPARATOR, SKIN.general.separator_col);
return 0;
}
static int ApplyStatusBar(const IMGHDR *wallpaper, uint16_t *crop_y) {
const int theme_cache_id = TCI_STATUS_BAR_STANDARD;
IMGHDR *status_bar = PrepareBgImage(GetIMGHDRFromThemeCache(theme_cache_id), wallpaper, *crop_y,
SKIN.status_bar.blur, SKIN.status_bar.blur_radius,
SKIN.status_bar.overlay, SKIN.status_bar.overlay_col);
if (!status_bar) {
return theme_cache_id;
}
ConvertImage(status_bar);
*crop_y += status_bar->h;
return 0;
}
static int ApplyHeadline(const IMGHDR *wallpaper, uint16_t *crop_y) {
int theme_cache_id = TCI_HEADLINE_DEFAULT;
IMGHDR *headline_default = PrepareBgImage(GetIMGHDRFromThemeCache(theme_cache_id), wallpaper, *crop_y,
SKIN.headline.blur, SKIN.headline.blur_radius,
SKIN.headline.overlay, SKIN.headline.overlay_col);
if (!headline_default) {
return theme_cache_id;
}
if (SKIN.headline.border) {
const int border_w = (int)SKIN.headline.border_width - 1;
const int border_x = (ScreenW() - border_w) / 2;
const int border_x2 = border_x + border_w;
if (SKIN.headline.border == SKIN_HEADLINE_BORDER_BOTTOM) {
IMGHDR_DrawHLine(headline_default, border_x, headline_default->h - 1, border_x2, 0, SKIN.headline.border_col);
} else if (SKIN.headline.border == SKIN_HEADLINE_BORDER_TOP_BOTTOM) {
IMGHDR_DrawHLine(headline_default, border_x, 0, border_x2, 0, SKIN.headline.border_col);
IMGHDR_DrawHLine(headline_default, border_x, headline_default->h - 1, border_x2, 0, SKIN.headline.border_col);
}
}
ConvertImage(headline_default);
theme_cache_id = TCI_HEADLINE_FULLSCREEN;
IMGHDR *headline_fullscreen = GetIMGHDRFromThemeCache(theme_cache_id);
if (!headline_fullscreen) {
return theme_cache_id;
}
if (!IMGHDR_Clone(headline_fullscreen, headline_default)) {
return theme_cache_id;
}
Cs_SetColor(TPC_HEADER_FOREGROUND, SKIN.headline.text_col);
Cs_SetColor(TPC_EXTRA_HEADER_FOREGROUND, SKIN.headline.text_col);
Cs_SetColor(TPC_LIGHT_TEXT_FOREGROUND, SKIN.headline.text_col);
Cs_SetColor(TPC_POPUP_HEADER_FOREGROUND, SKIN.headline.text_col);
*crop_y += headline_fullscreen->h;
return 0;
}
static int ApplyBody(const IMGHDR *wallpaper, uint16_t *crop_y) {
int theme_cache_id = TCI_BODY_DEFAULT;
IMGHDR *body_default = PrepareBgImage(GetIMGHDRFromThemeCache(theme_cache_id), wallpaper, *crop_y,
SKIN.body.blur, SKIN.body.blur_radius,
SKIN.body.overlay, SKIN.body.overlay_col);
if (!body_default) {
return theme_cache_id;
}
ConvertImage(body_default);
theme_cache_id = TCI_BODY_TAB;
IMGHDR *body_tab = PrepareBgImage(GetIMGHDRFromThemeCache(theme_cache_id), wallpaper, *crop_y,
SKIN.body.blur, SKIN.body.blur_radius,
SKIN.body.overlay, SKIN.body.overlay_col);
if (!body_tab) {
return theme_cache_id;
}
if (SKIN.tabs.separator) {
const int separator_w = (int)SKIN.tabs.separator_width - 1;
const int separator_x = (ScreenW() - separator_w) / 2;
const int separator_x2 = separator_x + separator_w;
IMGHDR_DrawHLine(body_tab, separator_x, BODY_TAB_SEPARATOR_Y, separator_x2, 0, SKIN.tabs.separator_col);
}
ConvertImage(body_tab);
Cs_SetColor(TPC_FOREGROUND, SKIN.body.main_text_col);
Cs_SetColor(TPC_DISABLED_TEXT_FOREGROUND, SKIN.body.disabled_text_col);
Cs_SetColor(TPC_EDIT_HEADER_FOREGROUND, SKIN.body.edit_header_text_col);
Cs_SetColor(TPC_EDIT_FOREGROUND, SKIN.body.edit_text_col);
*crop_y += body_default->h;
return 0;
}
static int ApplyBottom(const IMGHDR *wallpaper, const uint16_t *crop_y) {
int theme_cache_id = TCI_BOTTOM_DEFAULT;
IMGHDR *bottom_default = PrepareBgImage(GetIMGHDRFromThemeCache(theme_cache_id), wallpaper, *crop_y,
SKIN.bottom.blur, SKIN.bottom.blur_radius,
SKIN.bottom.overlay, SKIN.bottom.overlay_col);
if (!bottom_default) {
return theme_cache_id;
}
if (SKIN.bottom.border) {
IMGHDR_DrawHLine(bottom_default, 0, 0, bottom_default->w - 1, 0, SKIN.bottom.border_col);
}
ConvertImage(bottom_default);
theme_cache_id = TCI_BOTTOM_FULLSCREEN;
if (!IMGHDR_Clone(GetIMGHDRFromThemeCache(theme_cache_id), bottom_default)) {
return theme_cache_id;
}
Cs_SetColor(TPC_BOTTOM_FOREGROUND, SKIN.bottom.text_col);
return 0;
}
static int ApplySelection() {
int theme_cache_id = 0;
for (int i = 0; i < 3; i++) {
theme_cache_id = TCI_SELECTION_1_LINE + i;
IMGHDR *selection = GetIMGHDRFromThemeCache(theme_cache_id);
if (!selection) {
return theme_cache_id;
}
if (!InjectImageSolid(selection, SKIN.selection.bg_col)) {
return theme_cache_id;
}
const int selection_clear_top_end = 1;
// const int selection_clear_bottom_start = selection->h - 1 - 1;
// const int selection_clear_bottom_end = selection->h - 1;
IMGHDR_TransparentV(selection, 0, selection_clear_top_end);
// IMGHDR_TransparentV(selection, selection_clear_bottom_start, selection_clear_bottom_end);
if (SKIN.selection.border) {
IMGHDR_DrawBorder(selection, 0, selection_clear_top_end, selection->w - 1, selection->h - 1, 0, SKIN.selection.border_col);
}
}
Cs_SetColor(TPC_SELECT_FOREGROUND, SKIN.selection.selected_text_col);
Cs_SetColor(TPC_POPUP_SELECT_FOREGROUD, SKIN.selection.selected_text_col);
Cs_SetColor(TPC_UNSELECT_FOREGOUND, SKIN.selection.unselected_text_col);
Cs_SetColor(TPC_WINDOW_FOREGROUND, SKIN.selection.unselected_text_col);
return 0;
}
static int ApplyTabs() {
int theme_cache_id = TCI_TAB_UNSELECTED;
IMGHDR *tab_unselected = GetIMGHDRFromThemeCache(theme_cache_id);
if (!tab_unselected) {
return theme_cache_id;
}
if (!InjectImageSolid(tab_unselected, (uint8_t [4]){0x00, 0x00, 0x00, 0x00})) {
return theme_cache_id;
}
ConvertImage(tab_unselected);
theme_cache_id = TCI_TAB_SELECTED;
IMGHDR *tab_selected = GetIMGHDRFromThemeCache(theme_cache_id);
if (!tab_selected) {
return theme_cache_id;
}
IMGHDR *tab_selected_mask = IMGHDR_CreateGlowMask(tab_selected->w, tab_selected->h, SKIN.tabs.selected_bg_col);
if (!tab_selected_mask) {
return theme_cache_id;
}
mfree(tab_selected->bitmap);
memcpy(tab_selected, tab_selected_mask, sizeof(IMGHDR));
mfree(tab_selected_mask);
return 0;
}
static int ApplyPopups(const IMGHDR* wallpaper) {
// Options
int theme_cache_id = TCI_POPUP_OPTIONS;
IMGHDR *status_bar = GetIMGHDRFromThemeCache(TCI_STATUS_BAR_STANDARD);
IMGHDR *headline = GetIMGHDRFromThemeCache(TCI_HEADLINE_DEFAULT);
if (!headline || !status_bar) {
return theme_cache_id;
}
int crop_y = status_bar->h + headline->h;
IMGHDR* popup_options = GetIMGHDRFromThemeCache(theme_cache_id);
popup_options->h += 1;
popup_options = PrepareBgImage(popup_options, wallpaper, crop_y,
SKIN.popup.blur, SKIN.popup.blur_radius,
SKIN.popup.overlay, SKIN.popup.overlay_col);
if (!popup_options) {
return theme_cache_id;
}
const int popup_options_clear_top_end = POPUP_OPTIONS_CLEAR_H;
IMGHDR_TransparentV(popup_options, 0, popup_options_clear_top_end);
if (SKIN.popup.border) {
IMGHDR_DrawBorder(popup_options,
0, popup_options_clear_top_end,
popup_options->w - 1, popup_options->h - 1,
0, SKIN.popup.border_col);
}
if (SKIN.popup.options.header_separator) {
const int separator_w = (int)SKIN.popup.options.header_separator_width - 1;
const int separator_x = (ScreenW() - separator_w) / 2;
const int separator_x2 = separator_x + separator_w;
IMGHDR_DrawHLine(popup_options, separator_x, POPUP_OPTIONS_SEPARATOR_Y, separator_x2, 0, SKIN.popup.border_col);
}
// Feedback
crop_y = POPUP_FEEDBACK_CROP_Y;
theme_cache_id = TCI_POPUP_FEEDBACK;
IMGHDR* popup_feedback = PrepareBgImage(GetIMGHDRFromThemeCache(theme_cache_id), wallpaper, crop_y,
SKIN.popup.blur, SKIN.popup.blur_radius,
SKIN.popup.overlay, SKIN.popup.overlay_col);
if (!popup_feedback) {
return theme_cache_id;
}
const int popup_feedback_clear_top_end = POPUP_FEEDBACK_CLEAR_H;
const int popup_feedback_clear_bottom_start = popup_feedback->h - 1 - POPUP_FEEDBACK_CLEAR_H;
const int popup_feedback_clear_left_end = POPUP_FEEDBACK_CLEAR_W;
const int popup_feedback_clear_right_start = popup_feedback->w - 1 - POPUP_FEEDBACK_CLEAR_W;
IMGHDR_TransparentV(popup_feedback, 0, popup_feedback_clear_top_end);
IMGHDR_TransparentV(popup_feedback, popup_feedback_clear_bottom_start, popup_feedback->h - 1);
IMGHDR_TransparentH(popup_feedback, 0, popup_feedback_clear_left_end);
IMGHDR_TransparentH(popup_feedback, popup_feedback_clear_right_start, popup_feedback->w - 1);
if (SKIN.popup.border) {
IMGHDR_DrawBorder(popup_feedback,
popup_feedback_clear_left_end, popup_feedback_clear_top_end,
popup_feedback_clear_right_start, popup_feedback_clear_bottom_start,
0, SKIN.popup.border_col
);
}
return 0;
}
static int ApplyScrollBar() {
Cs_SetColor(TPC_SCROLL_BAR, SKIN.scroll_bar.bg_col);
Cs_SetColor(TPC_SCROLL_BAR_SLIDER, SKIN.scroll_bar.slider_col);
return 0;
}
static int ApplyProgressBar() {
const int theme_cache_id = TCI_PROGRESS_BAR;
if (!InjectImageSolid(GetIMGHDRFromThemeCache(theme_cache_id), SKIN.progress_bar.fg_col)) {
return theme_cache_id;
}
Cs_SetColor(TPC_PROGRESS_BAR_BACKGROUND, SKIN.progress_bar.bg_col);
return 0;
}
static int ApplyCalendar() {
Cs_SetColor(TPC_CALENDAR_DAYBACKGROUND, SKIN.calendar.day_bg_col);
Cs_SetColor(TPC_CALENDAR_WEEKENDBACKGROUND, SKIN.calendar.weekend_bg_col);
Cs_SetColor(TPC_CALENDAR_EVENTBACKGROUND, SKIN.calendar.event_bg_col);
Cs_SetColor(TPC_CALENDAR_FOREGROUND, SKIN.calendar.fg_col);
return 0;
}
int Theme_Apply() {
IMGHDR *wallpaper = GetCanvasBufferPicPtr(0);
if (wallpaper) {
wallpaper->bpnum = IMGHDR_TYPE_RGB565;
if (wallpaper->w != ScreenW() && wallpaper->h != ScreenH()) {
MsgBoxError(0x11, (int)"Wrong wallpaper size");
return -1;
}
int error = 0;
uint16_t crop_y = 0;
error = ApplyGeneral();
if (error) {
return error;
}
error = ApplyStatusBar(wallpaper, &crop_y);
if (error) {
return error;
}
error = ApplyHeadline(wallpaper, &crop_y);
if (error) {
return error;
}
error = ApplyBody(wallpaper, &crop_y);
if (error) {
return error;
}
error = ApplyBottom(wallpaper, &crop_y);
if (error) {
return error;
}
error = ApplySelection();
if (error) {
return error;
}
error = ApplyTabs();
if (error) {
return error;
}
error = ApplyPopups(wallpaper);
if (error) {
return error;
}
error = ApplyScrollBar();
if (error) {
return error;
}
error = ApplyProgressBar();
if (error) {
return error;
}
error = ApplyCalendar();
if (error) {
return error;
}
Cs_Update();
return 0;
}
return -1;
}

3
elf/src/theme.h Normal file
View file

@ -0,0 +1,3 @@
#pragma once
int Theme_Apply();