switchable theme

git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@470 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-10-23 00:40:09 +00:00
parent 71685aebd6
commit bd76fa6041
5 changed files with 42 additions and 21 deletions

View File

@@ -24,6 +24,7 @@
#define MwNhasHeading "IhasHeading"
#define MwnhasBorder "IhasBorder"
#define MwNinverted "Iinverted"
#define MwNmodernLook "ImodernLook"
#define MwNtitle "Stitle"
#define MwNtext "Stext"

View File

@@ -60,6 +60,7 @@
<integer name="hasHeading" />
<integer name="hasBorder" />
<integer name="inverted" />
<integer name="modernLook" />
<string name="title" />
<string name="text" />

View File

@@ -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) {

View File

@@ -1,10 +1,6 @@
/* $Id$ */
#include <Mw/Milsko.h>
#ifdef MW_CLASSIC_THEME
const int MwDefaultBorderWidth = 2;
#else
const int MwDefaultBorderWidth = 1;
#endif
const char* MwDefaultBackground = "#ddd";
const char* MwDefaultForeground = "#000";

View File

@@ -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);