From b2bf457df54a675fc9669a60cc4f2bcc1f600a21 Mon Sep 17 00:00:00 2001 From: Nishi Date: Wed, 13 May 2026 15:02:49 +0900 Subject: [PATCH] update --- external/ppr | 2 +- src/gui.c | 124 +++++------------------------------------- src/gui_menu.c | 30 ++++++++++ src/gui_preferences.c | 23 ++++++++ src/gui_version.c | 89 ++++++++++++++++++++++++++++++ src/midas.h | 10 +++- 6 files changed, 167 insertions(+), 111 deletions(-) create mode 100644 src/gui_menu.c create mode 100644 src/gui_preferences.c create mode 100644 src/gui_version.c diff --git a/external/ppr b/external/ppr index f921861..1baa367 160000 --- a/external/ppr +++ b/external/ppr @@ -1 +1 @@ -Subproject commit f9218619766942366adc6443869aafd8350fb79e +Subproject commit 1baa36725d2a75333f1ed0d2b355dfc0398a07be diff --git a/src/gui.c b/src/gui.c index 8868613..53e325a 100644 --- a/src/gui.c +++ b/src/gui.c @@ -1,45 +1,8 @@ -#define _MILSKO #define LOAD_ICONS #include -MwWidget window, menu = NULL, fileview = NULL, editor = NULL, console = NULL; - -static MwMenu m_about_midas; - -static void image_draw_inject(MwWidget handle) { - char version[128]; - MwPoint p, p2; - MwLLColor c = MwParseColor(handle, "#fff"); - MwLLColor cd = MwParseColor(handle, "#222"); - MwFLFont f = MwFLBuildFont(0); - - handle->bgcolor = MwParseColor(handle, "#888"); - - sprintf(version, "Version %s\n\n\xc2\xa9 Pyrite development team", VERSION); - - p.x = MwGetInteger(handle, MwNwidth) - 16; - p.y = MwGetInteger(handle, MwNheight) - 16 - MwTextHeight(handle, f, version) / 2; - p2 = p; - - p.x += 1; - p.y += 1; - MwDrawText(handle, f, &p, version, MwALIGNMENT_END, cd); - p = p2; - - MwDrawText(handle, f, &p, version, MwALIGNMENT_END, c); - - MwLLFreeColor(handle->bgcolor); - handle->bgcolor = NULL; - - MwLLFreeColor(cd); - MwLLFreeColor(c); -} - -static void menu_handler(MwWidget handle, void* user, void* client) { - if(client == m_about_midas) { - gui_version(); - } -} +static MwWidget loop; +MwWidget window, menu = NULL, fileview = NULL, editor = NULL, console = NULL; static void MWAPI resize(MwWidget handle, void* user, void* client) { int ww = MwGetInteger(window, MwNwidth); @@ -48,18 +11,9 @@ static void MWAPI resize(MwWidget handle, void* user, void* client) { int padding = 5; if(menu == NULL) { - MwMenu m; - menu = MwCreateWidget(MwMenuClass, "menu", window, 0, 0, 0, 0); - m = MwMenuAdd(menu, NULL, "File"); - m = MwMenuAdd(menu, NULL, "Edit"); - m = MwMenuAdd(menu, NULL, "Project"); - - m = MwMenuAdd(menu, NULL, "?Help"); - m_about_midas = MwMenuAdd(menu, m, "About Midas"); - - MwAddUserHandler(menu, MwNmenuHandler, menu_handler, NULL); + gui_menu_init(); } ww -= padding * 2; @@ -106,6 +60,7 @@ static void MWAPI resize(MwWidget handle, void* user, void* client) { console = MwCreateWidget(MwListBoxClass, "console", window, x, y, w, h); MwListBoxSet(console, -1, 0, "Midas " VERSION " console"); + MwListBoxSet(console, -1, 0, "Milsko version " MwVERSION); } else { MwVaApply(console, MwNx, x, @@ -116,6 +71,10 @@ static void MWAPI resize(MwWidget handle, void* user, void* client) { } } +static void window_close(MwWidget handle, void* user, void* client) { + MwDestroyWidget(loop); +} + static void tick(MwWidget handle, void* user, void* client) { dir_tick(); } @@ -126,7 +85,9 @@ void gui_init(void) { MwLibraryInit(); - window = MwVaCreateWidget(MwWindowClass, "window", NULL, MwDEFAULT, MwDEFAULT, 640, 480, + loop = MwCreateWidget(NULL, "loop", NULL, 0, 0, 0, 0); + + window = MwVaCreateWidget(MwWindowClass, "window", loop, MwDEFAULT, MwDEFAULT, 640, 480, MwNtitle, "Midas", NULL); @@ -161,68 +122,13 @@ void gui_init(void) { resize(window, NULL, NULL); MwAddUserHandler(window, MwNresizeHandler, resize, NULL); - MwAddUserHandler(window, MwNtickHandler, tick, NULL); + MwAddUserHandler(window, MwNcloseHandler, window_close, NULL); + + MwAddUserHandler(loop, MwNtickHandler, tick, NULL); MwTimeSleep(50); } -static void version_ok_activate(MwWidget handle, void* user, void* client) { - int i; - MwWidget* children = MwGetChildren(user); - - for(i = 0; children[i] != NULL; i++) { - if(MwGetClass(children[i]) == MwImageClass) { - MwLLPixmap px = MwGetVoid(children[i], MwNpixmap); - - MwVaApply(children[i], - MwNpixmap, NULL, - NULL); - MwLLDestroyPixmap(px); - - break; - } - } - - MwDestroyWidget(user); -} - -void gui_version(void) { - MwWidget version, image, ok; - MwRect rc; - int x = MwGetInteger(window, MwNx); - int y = MwGetInteger(window, MwNy); - int ww = MwGetInteger(window, MwNwidth); - int wh = MwGetInteger(window, MwNheight); - int bsh = 48; - int bh = bsh / 2; - int w = 640; - int h = 426 + bh; - MwLLPixmap px = MwLoadIcon(window, icon_midas); - MwSizeHints sh; - - sh.min_width = sh.max_width = w; - sh.min_height = sh.max_height = h; - - MwGetScreenSize(window, &rc); - - version = MwVaCreateWidget(MwWindowClass, "window", NULL, x + (ww - w) / 2, y + (wh - h) / 2, w, h, - MwNtitle, "Version information", - MwNsizeHints, &sh, - NULL); - - image = MwVaCreateWidget(MwImageClass, "image", version, 0, 0, w, h - bsh, - MwNpixmap, px, - NULL); - image->draw_inject = image_draw_inject; - - ok = MwVaCreateWidget(MwButtonClass, "btn", version, w - bh * 4 - (bsh - bh) / 2, h - bsh + (bsh - bh) / 2, bh * 4, bh, - MwNtext, "OK", - NULL); - MwAddUserHandler(ok, MwNactivateHandler, version_ok_activate, version); - - MwReparent(version, window); -} - void gui_loop(void) { - MwLoop(window); + MwLoop(loop); } diff --git a/src/gui_menu.c b/src/gui_menu.c new file mode 100644 index 0000000..a4909e7 --- /dev/null +++ b/src/gui_menu.c @@ -0,0 +1,30 @@ +#include + +static MwMenu m_exit, m_preferences, m_about_midas; + +static void menu_handler(MwWidget handle, void* user, void* client) { + if(client == m_exit) { + MwDispatchUserHandler(window, MwNcloseHandler, NULL); + } else if(client == m_preferences) { + gui_preferences(); + } else if(client == m_about_midas) { + gui_version(); + } +} + +void gui_menu_init(void) { + MwMenu m; + + m = MwMenuAdd(menu, NULL, "File"); + m_exit = MwMenuAdd(menu, m, "Exit"); + + m = MwMenuAdd(menu, NULL, "Edit"); + m_preferences = MwMenuAdd(menu, m, "Preferences"); + + m = MwMenuAdd(menu, NULL, "Project"); + + m = MwMenuAdd(menu, NULL, "?Help"); + m_about_midas = MwMenuAdd(menu, m, "About Midas"); + + MwAddUserHandler(menu, MwNmenuHandler, menu_handler, NULL); +} diff --git a/src/gui_preferences.c b/src/gui_preferences.c new file mode 100644 index 0000000..5872023 --- /dev/null +++ b/src/gui_preferences.c @@ -0,0 +1,23 @@ +#include + +static void pref_close(MwWidget handle, void* user, void* client) { + MwDestroyWidget(user); +} + +void gui_preferences(void) { + MwWidget pref; + int x = MwGetInteger(window, MwNx); + int y = MwGetInteger(window, MwNy); + int ww = MwGetInteger(window, MwNwidth); + int wh = MwGetInteger(window, MwNheight); + int w = 640; + int h = 480; + + pref = MwVaCreateWidget(MwWindowClass, "window", NULL, x + (ww - w) / 2, y + (wh - h) / 2, w, h, + MwNtitle, "Preferences", + NULL); + + MwAddUserHandler(pref, MwNcloseHandler, pref_close, pref); + + MwReparent(pref, window); +} diff --git a/src/gui_version.c b/src/gui_version.c new file mode 100644 index 0000000..8b155b4 --- /dev/null +++ b/src/gui_version.c @@ -0,0 +1,89 @@ +#define _MILSKO +#include + +static void image_draw_inject(MwWidget handle) { + char version[128]; + MwPoint p, p2; + MwLLColor c = MwParseColor(handle, "#fff"); + MwLLColor cd = MwParseColor(handle, "#222"); + MwFLFont f = MwFLBuildFont(0); + + handle->bgcolor = MwParseColor(handle, "#888"); + + sprintf(version, "Version %s\n\n\xc2\xa9 Pyrite development team", VERSION); + + p.x = MwGetInteger(handle, MwNwidth) - 16; + p.y = MwGetInteger(handle, MwNheight) - 16 - MwTextHeight(handle, f, version) / 2; + p2 = p; + + p.x += 1; + p.y += 1; + MwDrawText(handle, f, &p, version, MwALIGNMENT_END, cd); + p = p2; + + MwDrawText(handle, f, &p, version, MwALIGNMENT_END, c); + + MwLLFreeColor(handle->bgcolor); + handle->bgcolor = NULL; + + MwLLFreeColor(cd); + MwLLFreeColor(c); +} + +static void version_close(MwWidget handle, void* user, void* client) { + int i; + MwWidget* children = MwGetChildren(user); + + for(i = 0; children[i] != NULL; i++) { + if(MwGetClass(children[i]) == MwImageClass) { + MwLLPixmap px = MwGetVoid(children[i], MwNpixmap); + + MwVaApply(children[i], + MwNpixmap, NULL, + NULL); + MwLLDestroyPixmap(px); + + break; + } + } + + MwDestroyWidget(user); +} + +void gui_version(void) { + MwWidget version, image, ok; + MwRect rc; + int x = MwGetInteger(window, MwNx); + int y = MwGetInteger(window, MwNy); + int ww = MwGetInteger(window, MwNwidth); + int wh = MwGetInteger(window, MwNheight); + int bsh = 48; + int bh = bsh / 2; + int w = 640; + int h = 426 + bh; + MwLLPixmap px = MwLoadIcon(window, icon_midas); + MwSizeHints sh; + + sh.min_width = sh.max_width = w; + sh.min_height = sh.max_height = h; + + MwGetScreenSize(window, &rc); + + version = MwVaCreateWidget(MwWindowClass, "window", NULL, x + (ww - w) / 2, y + (wh - h) / 2, w, h, + MwNtitle, "Version information", + MwNsizeHints, &sh, + NULL); + + image = MwVaCreateWidget(MwImageClass, "image", version, 0, 0, w, h - bsh, + MwNpixmap, px, + NULL); + image->draw_inject = image_draw_inject; + + ok = MwVaCreateWidget(MwButtonClass, "btn", version, w - bh * 4 - (bsh - bh) / 2, h - bsh + (bsh - bh) / 2, bh * 4, bh, + MwNtext, "OK", + NULL); + MwAddUserHandler(ok, MwNactivateHandler, version_close, version); + MwAddUserHandler(version, MwNcloseHandler, version_close, version); + + MwReparent(version, window); +} diff --git a/src/midas.h b/src/midas.h index 94045f0..dfaa0d0 100644 --- a/src/midas.h +++ b/src/midas.h @@ -43,9 +43,17 @@ ICONS; #undef ICON void gui_init(void); -void gui_version(void); void gui_loop(void); +/* gui_menu.c */ +void gui_menu_init(void); + +/* gui_version.c */ +void gui_version(void); + +/* gui_preferences.c */ +void gui_preferences(void); + /* dir.c */ void dir_init(void); void dir_scan(const char* dir);