From 77e652cddccb5571e59bd18d6930d833485ef98b Mon Sep 17 00:00:00 2001 From: Nishi Date: Sat, 12 Sep 2026 06:34:35 +0900 Subject: [PATCH 1/2] improve checkbox --- src/abstract/directory.c | 12 ++++++------ src/core.c | 8 ++++---- src/draw.c | 6 +++--- src/string.c | 6 ++---- src/widget/checkbox.c | 40 ++++++++++++++++++++++++++++++++++++---- 5 files changed, 51 insertions(+), 21 deletions(-) diff --git a/src/abstract/directory.c b/src/abstract/directory.c index ddf10e1..3fbc235 100644 --- a/src/abstract/directory.c +++ b/src/abstract/directory.c @@ -19,8 +19,8 @@ typedef struct dir { void* MwDirectoryOpen(const char* path) { dir_t* dir = malloc(sizeof(*dir)); - char * p; - if(!dir) { + char* p; + if(!dir) { printf("Out Of Memory\n"); return NULL; } @@ -70,15 +70,15 @@ MwDirectoryEntry* MwDirectoryRead(void* handle) { dir_t* dir = handle; MwDirectoryEntry* entry = malloc(sizeof(*entry)); #ifdef _WIN32 - ULARGE_INTEGER* l; + ULARGE_INTEGER* l; #elif defined(CLASSIC_MAC_OS) #else - struct dirent* d; + struct dirent* d; struct stat s; char* p; #endif - - if(!entry) { + + if(!entry) { printf("Out Of Memory\n"); return NULL; } diff --git a/src/core.c b/src/core.c index c27b1a6..3180922 100644 --- a/src/core.c +++ b/src/core.c @@ -1090,14 +1090,14 @@ int MwLibraryInit(void) { int i; #ifdef _WIN32 - /* + /* There's no Windows configuration that Milsko supports that doesn't have winmm. However, uhh, Visual Studio 2022. For some fucking reason. Thanks for coming to my TED Talk. */ - MwLL_winmmLib = LoadLibrary("winmm.dll"); - MwLL_PFN_timeGetTime = (void *)GetProcAddress(MwLL_winmmLib, "timeGetTime"); - MwLL_PFN_timeBeginPeriod = (void *)GetProcAddress(MwLL_winmmLib, "timeBeginPeriod"); + MwLL_winmmLib = LoadLibrary("winmm.dll"); + MwLL_PFN_timeGetTime = (void*)GetProcAddress(MwLL_winmmLib, "timeGetTime"); + MwLL_PFN_timeBeginPeriod = (void*)GetProcAddress(MwLL_winmmLib, "timeBeginPeriod"); MwLL_PFN_timeBeginPeriod(10); #endif diff --git a/src/draw.c b/src/draw.c index 2314c02..c6de78f 100644 --- a/src/draw.c +++ b/src/draw.c @@ -124,7 +124,7 @@ void MwDrawRectFading(MwWidget handle, MwRect* rect, MwLLColor color) { int ColorDiff = get_color_diff(handle); double darkenStep = (ColorDiff / 2.) / rect->height; unsigned long sz = 1 * rect->height * 4; - unsigned char* data = malloc(sz*2); + unsigned char* data = malloc(sz * 2); MwRect r = *rect; if(!data) { return; @@ -952,8 +952,8 @@ MwLLPixmap MwLoadXPM(MwWidget handle, char** data) { } } - rgb = malloc(row * col * 4); - comp = malloc(cpp + 1); + rgb = malloc(row * col * 4); + comp = malloc(cpp + 1); if(!rgb || !comp) { printf("Null malloc! Out of memory?"); return NULL; diff --git a/src/string.c b/src/string.c index c894b9a..579c57e 100644 --- a/src/string.c +++ b/src/string.c @@ -2,7 +2,7 @@ char* MwStringDuplicate(const char* str) { int sz = strlen(str) + 1; - char* r = malloc(sz); + char* r = malloc(sz); if(!r) { printf("Out Of Memory\n"); return NULL; @@ -19,7 +19,7 @@ char* MwStringDuplicate(const char* str) { char* MwStringConcat(const char* str1, const char* str2) { int sz = strlen(str1) + strlen(str2) + 1; - char* r = malloc(sz); + char* r = malloc(sz); if(!r) { printf("Out Of Memory\n"); return NULL; @@ -64,8 +64,6 @@ void MwStringTime(char* out, time_t t) { struct tm* tm = localtime(&t); const char* months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; - - if(tm == NULL) { #if defined(_MSC_VER) && (_MSC_VER >= 1400) sprintf_s(out, 255, "localtime error"); diff --git a/src/widget/checkbox.c b/src/widget/checkbox.c index f196954..8e65dc0 100644 --- a/src/widget/checkbox.c +++ b/src/widget/checkbox.c @@ -10,8 +10,10 @@ static int wcreate(MwWidget handle) { static void draw(MwWidget handle) { MwRect r; - MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground)); - MwLLPixmap bgpx = MwGetVoid(handle, MwNbackgroundPixmap); + MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground)); + MwLLColor base2 = MwParseColor(handle, MwGetText(handle, MwNsubBackground)); + MwLLColor text2 = MwParseColor(handle, MwGetText(handle, MwNsubForeground)); + MwLLPixmap bgpx = MwGetVoid(handle, MwNbackgroundPixmap); r.x = 0; r.y = 0; @@ -27,12 +29,42 @@ static void draw(MwWidget handle) { r.x = (MwGetInteger(handle, MwNwidth) - r.width) / 2; r.y = (MwGetInteger(handle, MwNheight) - r.height) / 2; - MwDrawWidgetBack(handle, &r, base, (handle->pressed || MwGetInteger(handle, MwNchecked)) ? 1 : 0, MwDEFAULT); + MwDrawFrame(handle, &r, base, 1); + MwDrawRect(handle, &r, base2); if(bgpx != NULL) MwLLDrawPixmap(handle->lowlevel, &r, bgpx); if(handle->pressed || MwGetInteger(handle, MwNchecked)) { - /* TODO: write check mark */ + MwPoint p[6]; + int gap_w = r.width / 4 / 3; + int gap_h = r.height / 4 / 3; + + r.x += gap_w; + r.y += gap_h; + r.width -= gap_w * 2; + r.height -= gap_h * 2; + + p[0].x = r.x; + p[0].y = r.y + r.height * 2 / 3; + + p[1].x = r.x + r.width / 3; + p[1].y = r.y + r.height; + + p[2].x = r.x + r.width; + p[2].y = r.y + r.height / 3; + + p[3] = p[2]; + p[3].y -= r.height / 3; + + p[4] = p[1]; + p[4].y -= r.height / 3; + + p[5] = p[0]; + p[5].y -= r.height / 3; + + MwLLPolygon(handle->lowlevel, p, 6, text2); } + MwLLFreeColor(text2); + MwLLFreeColor(base2); MwLLFreeColor(base); } From eb1db3a5e97aa1c115a2a3e22bde341c261774c5 Mon Sep 17 00:00:00 2001 From: Nishi Date: Sat, 12 Sep 2026 06:45:45 +0900 Subject: [PATCH 2/2] fix MwDirectoryOpen --- src/abstract/directory.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/abstract/directory.c b/src/abstract/directory.c index 3fbc235..977f2f5 100644 --- a/src/abstract/directory.c +++ b/src/abstract/directory.c @@ -25,13 +25,15 @@ void* MwDirectoryOpen(const char* path) { return NULL; } #ifdef _WIN32 - p = MwStringDuplicate(path); + p = malloc(strlen(path) + 2 + 1); + + strcpy(p, path); if(strchr(path, '/') != NULL) { - MwStringConcat(p, "/"); + strcat(p, "/"); } else { - MwStringConcat(p, "\\"); + strcat(p, "\\"); } - MwStringConcat(p, "*"); + strcat(p, "*"); if((dir->hFind = FindFirstFile(p, &dir->ffd)) == INVALID_HANDLE_VALUE) { free(p); free(dir);