From 758ae46138be7d4352fb51a073615f970bb5731b Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Fri, 17 Oct 2025 00:16:02 +0000 Subject: [PATCH] c89-ification git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@387 b9cfdab3-6d41-4d17-bbe4-086880011989 --- examples/color_picker.c | 40 +++++++++++++++++++++++++++------------- include/Mw/Directory.h | 6 ++++++ include/Mw/MachDep.h | 4 +++- src/directory.c | 13 +++++++++++++ src/filechooser.c | 9 ++++++++- src/widget/entry.c | 6 +++++- src/widget/numberentry.c | 24 ++++++++++++++---------- src/widget/scrollbar.c | 8 ++++---- 8 files changed, 80 insertions(+), 30 deletions(-) diff --git a/examples/color_picker.c b/examples/color_picker.c index 92e7da6..a6b8837 100644 --- a/examples/color_picker.c +++ b/examples/color_picker.c @@ -69,8 +69,9 @@ typedef struct { } color_wheel; void color_wheel_wheel_image_update(color_wheel* wheel) { - for(int y = 0; y < PICKER_SIZE; y++) { - for(int x = 0; x < PICKER_SIZE; x++) { + int y, x; + for(y = 0; y < PICKER_SIZE; y++) { + for(x = 0; x < PICKER_SIZE; x++) { int i = ((y * PICKER_SIZE) + x) * 4; int _x = x - (PICKER_SIZE / 2); int _y = y - (PICKER_SIZE / 2); @@ -89,14 +90,16 @@ void color_wheel_wheel_image_update(color_wheel* wheel) { float angle = atan2(yd, xd) - M_PI; float hue = (angle * 180.) / M_PI; + hsv hsv_v; + rgb color; + if(hue < 0.0) { hue += 360; } - rgb color = hsv2rgb((hsv){ - .h = hue / 360., - .s = (dist / 179.61), - .v = wheel->value, - }); + hsv_v.h = hue / 360.; + hsv_v.s = (dist / 179.61); + hsv_v.v = wheel->value; + color = hsv2rgb(hsv_v); wheel->color_wheel_image_data[i] = color.r * 255; wheel->color_wheel_image_data[i + 1] = color.g * 255; @@ -116,17 +119,25 @@ void color_wheel_wheel_image_update(color_wheel* wheel) { static void color_wheel_click(MwWidget handle, void* user, void* call) { color_wheel* wheel = (color_wheel*)user; MwLLMouse* mouse = (MwLLMouse*)call; + char* hexColor; + int i, r, g, b, a; + + (void)handle; + (void)user; + (void)call; color_wheel_wheel_image_update(wheel); - int i = ((mouse->point.y * PICKER_SIZE) + mouse->point.x) * 4; + i = ((mouse->point.y * PICKER_SIZE) + mouse->point.x) * 4; - int r = wheel->color_wheel_image_data[i]; - int g = wheel->color_wheel_image_data[i + 1]; - int b = wheel->color_wheel_image_data[i + 2]; - int a = wheel->color_wheel_image_data[i + 3]; + r = wheel->color_wheel_image_data[i]; + g = wheel->color_wheel_image_data[i + 1]; + b = wheel->color_wheel_image_data[i + 2]; + a = wheel->color_wheel_image_data[i + 3]; - char* hexColor = malloc(8); + (void)a; + + hexColor = malloc(8); snprintf(hexColor, 8, "#%02X%02X%02X", r, g, b); MwSetText(wheel->color_display, MwNbackground, hexColor); MwSetText(wheel->color_display_text, MwNbackground, hexColor); @@ -139,6 +150,9 @@ static void color_wheel_on_change_value(MwWidget handle, void* user, void* call) int value = MwGetInteger(handle, MwNvalue); int diff = MwGetInteger(handle, MwNchangedBy); + (void)diff; + (void)call; + wheel->value = 1.0 - ((double)value / 1024.); color_wheel_wheel_image_update(wheel); diff --git a/include/Mw/Directory.h b/include/Mw/Directory.h index 6072522..d724e9a 100644 --- a/include/Mw/Directory.h +++ b/include/Mw/Directory.h @@ -39,6 +39,12 @@ MWDECL MwDirectoryEntry* MwDirectoryRead(void* handle); */ MWDECL void MwDirectoryFreeEntry(MwDirectoryEntry* entry); +/*! + * %brief Gets a current directory + * %param Directory + */ +MWDECL char* MwDirectoryCurrent(void); + #ifdef __cplusplus } #endif diff --git a/include/Mw/MachDep.h b/include/Mw/MachDep.h index ce0b999..a74d398 100644 --- a/include/Mw/MachDep.h +++ b/include/Mw/MachDep.h @@ -16,7 +16,9 @@ #include #include #include -#ifndef _WIN32 +#ifdef _WIN32 +#include +#else #include #include #include diff --git a/src/directory.c b/src/directory.c index 747d3db..0b29522 100644 --- a/src/directory.c +++ b/src/directory.c @@ -103,3 +103,16 @@ void MwDirectoryFreeEntry(MwDirectoryEntry* entry) { free(entry->name); free(entry); } + +char* MwDirectoryCurrent(void) { +#ifdef _WIN32 + int len = GetCurrentDirectory(0, NULL); + char* out = malloc(len); + + GetCurrentDirectory(len, out); + + return out; +#else + return getcwd(NULL, 0); +#endif +} diff --git a/src/filechooser.c b/src/filechooser.c index 868676a..6527055 100644 --- a/src/filechooser.c +++ b/src/filechooser.c @@ -237,6 +237,10 @@ static void resize(MwWidget handle, void* user, void* call) { static void scan(MwWidget handle, const char* path) { filechooser_t* fc = handle->opaque; + MwVaApply(fc->addr, + MwNtext, path, + NULL); + MwListBoxReset(fc->files); MwListBoxInsert(fc->files, -1, NULL, "Name", "Date modified", "Size", NULL); MwListBoxSetWidth(fc->files, 0, -128 - 64); @@ -251,6 +255,7 @@ MwWidget MwFileChooser(MwWidget handle, const char* title) { int wh = MwGetInteger(handle, MwNheight); int w, h; filechooser_t* fc = malloc(sizeof(*fc)); + char* path; memset(fc, 0, sizeof(*fc)); @@ -275,7 +280,9 @@ MwWidget MwFileChooser(MwWidget handle, const char* title) { layout(window); MwAddUserHandler(window, MwNresizeHandler, resize, NULL); - scan(window, "."); + path = MwDirectoryCurrent(); + scan(window, path); + free(path); MwLLDetach(window->lowlevel, &p); MwLLMakePopup(window->lowlevel, handle->lowlevel); diff --git a/src/widget/entry.c b/src/widget/entry.c index 565da7f..79ebfaf 100644 --- a/src/widget/entry.c +++ b/src/widget/entry.c @@ -117,13 +117,17 @@ static void key(MwWidget handle, int code) { MwForceRender(handle); } +static void prop_change(MwWidget handle, const char* prop) { + if(strcmp(prop, MwNtext) == 0) MwForceRender(handle); +} + MwClassRec MwEntryClassRec = { create, /* create */ destroy, /* destroy */ draw, /* draw */ NULL, /* click */ NULL, /* parent_resize */ - NULL, /* prop_change */ + prop_change, /* prop_change */ NULL, /* mouse_move */ MwForceRender2, /* mouse_up */ MwForceRender2, /* mouse_down */ diff --git a/src/widget/numberentry.c b/src/widget/numberentry.c index 4158b47..98c2b19 100644 --- a/src/widget/numberentry.c +++ b/src/widget/numberentry.c @@ -126,17 +126,21 @@ static void mouse_down(MwWidget handle, void* ptr) { MwForceRender(handle); } +static void prop_change(MwWidget handle, const char* prop) { + if(strcmp(prop, MwNtext) == 0) MwForceRender(handle); +} + MwClassRec MwNumberEntryClassRec = { - create, /* create */ - destroy, /* destroy */ - draw, /* draw */ - NULL, /* click */ - NULL, /* parent_resize */ - NULL, /* prop_change */ - mouse_move, /* mouse_move */ - mouse_up, /* mouse_up */ - mouse_down, /* mouse_down */ - key, /* key */ + create, /* create */ + destroy, /* destroy */ + draw, /* draw */ + NULL, /* click */ + NULL, /* parent_resize */ + prop_change, /* prop_change */ + mouse_move, /* mouse_move */ + mouse_up, /* mouse_up */ + mouse_down, /* mouse_down */ + key, /* key */ NULL, NULL, NULL, diff --git a/src/widget/scrollbar.c b/src/widget/scrollbar.c index 6b23460..fa4a037 100644 --- a/src/widget/scrollbar.c +++ b/src/widget/scrollbar.c @@ -132,7 +132,7 @@ static void draw(MwWidget handle) { } static void mouse_move(MwWidget handle) { - int or = MwGetInteger(handle, MwNorientation); + int or = MwGetInteger(handle, MwNorientation); scrollbar_t* scr = handle->internal; if(!handle->pressed) return; @@ -160,9 +160,9 @@ static void mouse_move(MwWidget handle) { } static void mouse_down(MwWidget handle, void* ptr) { - int ww = MwGetInteger(handle, MwNwidth); - int wh = MwGetInteger(handle, MwNheight); - int or = MwGetInteger(handle, MwNorientation); + int ww = MwGetInteger(handle, MwNwidth); + int wh = MwGetInteger(handle, MwNheight); + int or = MwGetInteger(handle, MwNorientation); scrollbar_t* scr = handle->internal; MwLLMouse* m = ptr;