From bd76fa6041fd887665260ccf113d709356b01632 Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Thu, 23 Oct 2025 00:40:09 +0000 Subject: [PATCH] switchable theme git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@470 b9cfdab3-6d41-4d17-bbe4-086880011989 --- include/Mw/StringDefs.h | 1 + milsko.xml | 1 + src/core.c | 18 ++++++++++++++++++ src/default.c | 4 ---- src/draw.c | 39 ++++++++++++++++++++++----------------- 5 files changed, 42 insertions(+), 21 deletions(-) diff --git a/include/Mw/StringDefs.h b/include/Mw/StringDefs.h index 7b9d459..269cd5f 100644 --- a/include/Mw/StringDefs.h +++ b/include/Mw/StringDefs.h @@ -24,6 +24,7 @@ #define MwNhasHeading "IhasHeading" #define MwnhasBorder "IhasBorder" #define MwNinverted "Iinverted" +#define MwNmodernLook "ImodernLook" #define MwNtitle "Stitle" #define MwNtext "Stext" diff --git a/milsko.xml b/milsko.xml index 598c035..937033e 100644 --- a/milsko.xml +++ b/milsko.xml @@ -60,6 +60,7 @@ + diff --git a/src/core.c b/src/core.c index 3a7fdd9..b348c0c 100644 --- a/src/core.c +++ b/src/core.c @@ -420,11 +420,29 @@ static void inherit_text(MwWidget handle, const char* key, const char* default_v MwSetText(handle, key, default_value); } +static void inherit_integer(MwWidget handle, const char* key, int default_value) { + int n; + MwWidget h = handle; + while(h != NULL) { + if((n = MwGetInteger(h, key)) != -1) { + MwSetInteger(handle, key, n); + return; + } + h = h->parent; + } + MwSetInteger(handle, key, default_value); +} + void MwSetDefault(MwWidget handle) { MwLLSetCursor(handle->lowlevel, &MwCursorDefault, &MwCursorDefaultMask); inherit_text(handle, MwNbackground, MwDefaultBackground); inherit_text(handle, MwNforeground, MwDefaultForeground); +#ifdef MW_CLASSIC_THEME + inherit_integer(handle, MwNmodernLook, 0); +#else + inherit_integer(handle, MwNmodernLook, 1); +#endif } void MwHideCursor(MwWidget handle) { diff --git a/src/default.c b/src/default.c index 127cf98..13163cd 100644 --- a/src/default.c +++ b/src/default.c @@ -1,10 +1,6 @@ /* $Id$ */ #include -#ifdef MW_CLASSIC_THEME const int MwDefaultBorderWidth = 2; -#else -const int MwDefaultBorderWidth = 1; -#endif const char* MwDefaultBackground = "#ddd"; const char* MwDefaultForeground = "#000"; diff --git a/src/draw.c b/src/draw.c index 7b7713b..7ae1339 100644 --- a/src/draw.c +++ b/src/draw.c @@ -11,11 +11,14 @@ #include "../external/stb_ds.h" -#ifdef MW_CLASSIC_THEME -#define ColorDiff 128 -#else -#define ColorDiff 48 -#endif +static int get_color_diff(MwWidget handle){ + if(MwGetInteger(handle, MwNmodernLook)){ + return 48; + }else{ + return 128; + } +} + static int hex(const char* txt, int len) { int i; int r = 0; @@ -96,12 +99,11 @@ void MwDrawRectFading(MwWidget handle, MwRect* rect, MwLLColor color) { int y; int x; double darken = 0.; + int ColorDiff = get_color_diff(handle); double darkenStep = (ColorDiff / 2.) / rect->height; - -#define SIZE (rect->width * rect->height * 4) - unsigned char* data = malloc(SIZE); - memset(data, 0, SIZE); -#undef SIZE + unsigned long sz = rect->width * rect->height * 4; + unsigned char* data = malloc(sz); + memset(data, 0, sz); for(y = 0; y < rect->height; y++) { MwLLColor col = MwLightenColor(handle, color, -darken, -darken, -darken); @@ -122,21 +124,23 @@ void MwDrawRectFading(MwWidget handle, MwRect* rect, MwLLColor color) { } void MwDrawFrame(MwWidget handle, MwRect* rect, MwLLColor color, int invert) { - MwDrawFrameEx(handle, rect, color, invert, MwDefaultBorderWidth); + MwDrawFrameEx(handle, rect, color, invert, MwGetInteger(handle, MwNmodernLook) ? 1 : MwDefaultBorderWidth); } + void MwDrawWidgetBack(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int border) { if(border) { MwDrawFrame(handle, rect, color, invert); } -#ifdef MW_CLASSIC_THEME - MwDrawRect(handle, rect, color); -#else - MwDrawRectFading(handle, rect, color); -#endif + if(MwGetInteger(handle, MwNmodernLook)){ + MwDrawRectFading(handle, rect, color); + }else{ + MwDrawRect(handle, rect, color); + } } void MwDrawFrameEx(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int border) { MwPoint p[6]; + int ColorDiff = get_color_diff(handle); MwLLColor darker = MwLightenColor(handle, color, -ColorDiff, -ColorDiff, -ColorDiff); MwLLColor lighter = MwLightenColor(handle, color, ColorDiff, ColorDiff, ColorDiff); @@ -191,7 +195,8 @@ void MwDrawFrameEx(MwWidget handle, MwRect* rect, MwLLColor color, int invert, i void MwDrawTriangle(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int direction) { MwPoint p1[4], p2[4], p3[4], p4[3]; - const int border = MwDefaultBorderWidth; + const int border = MwGetInteger(handle, MwNmodernLook) ? 1 : MwDefaultBorderWidth; + int ColorDiff = get_color_diff(handle); MwLLColor darker = MwLightenColor(handle, color, -ColorDiff, -ColorDiff, -ColorDiff); MwLLColor lighter = MwLightenColor(handle, color, ColorDiff, ColorDiff, ColorDiff);