From c6b81aff022ebe9d12faa46e1b78004cac9106cc Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Sat, 11 Oct 2025 08:37:24 +0000 Subject: [PATCH] add messagebox git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@261 b9cfdab3-6d41-4d17-bbe4-086880011989 --- doc/index.html | 150 +++++++++++++++++++++++++++++++++++++ include/Mw/Constants.h | 40 ++++++++++ include/Mw/MessageBox.h | 8 ++ resource/icon/info.png | Bin 434 -> 434 bytes resource/icon/news.png | Bin 542 -> 542 bytes resource/icon/note.png | Bin 594 -> 594 bytes resource/icon/question.png | Bin 529 -> 529 bytes resource/icon/warning.png | Bin 498 -> 498 bytes src/messagebox.c | 38 ++++++++-- 9 files changed, 228 insertions(+), 8 deletions(-) diff --git a/doc/index.html b/doc/index.html index 964835d..6b62679 100644 --- a/doc/index.html +++ b/doc/index.html @@ -41,6 +41,30 @@
#define MwMB_ICONNEWS 0x5
+
+ #define MwMB_BUTTONMASK 0xf0 +
+
+ #define MwMB_BUTTONOK 0x10 +
+
+ #define MwMB_BUTTONCANCEL 0x20 +
+
+ #define MwMB_BUTTONYES 0x40 +
+
+ #define MwMB_BUTTONNO 0x80 +
+
+ MwMB_BUTTONOKCANCEL +
+
+ MwMB_BUTTONYESNO +
+
+ MwMB_BUTTONYESNOCANCEL +
Mw/Core.h
@@ -248,6 +272,12 @@
Mw/MessageBox.h
+
+ MwMessageBox +
+
+ MwMessageBoxGetChild +
Mw/Milsko.h
@@ -498,6 +528,62 @@
+
#define MwMB_BUTTONMASK 0xf0
+
+
+ Button mask. +
+
+
+
#define MwMB_BUTTONOK 0x10
+
+
+ OK button. +
+
+
+
#define MwMB_BUTTONCANCEL 0x20
+
+
+ Cancel button. +
+
+
+
#define MwMB_BUTTONYES 0x40
+
+
+ Yes button. +
+
+
+
#define MwMB_BUTTONNO 0x80
+
+
+ No button. +
+
+
+
#define MwMB_BUTTONOKCANCEL (MwMB_BUTTONCANCEL | MwMB_BUTTONOK)
+
+
+ Ok and Cancel button. +
+
+
+
#define MwMB_BUTTONYESNO (MwMB_BUTTONYES | MwMB_BUTTONNO)
+
+
+ Yes and No button. +
+
+
+
#define MwMB_BUTTONYESNOCANCEL (MwMB_BUTTONYES | MwMB_BUTTONNO | MwMB_BUTTONCANCEL)
+
+
+ Yes, No and Cancel button. +
+
+

Mw/Core.h

@@ -1941,6 +2027,70 @@

+
MWDECL MwWidget MwMessageBox (
+	MwWidget handle,
+	const char* text,
+	const char* title,
+	unsigned int flag
+);
+
+
+ Creates a message box. +
+
+ Parameter handle +
+
+ Widget. +
+
+ Parameter text +
+
+ Text. +
+
+ Parameter title +
+
+ Title text. +
+
+ Parameter flag +
+
+ Flag. +
+
+ Returns +
+
+ Widget. +
+
+
+
MWDECL MwWidget MwMessageBoxGetChild (
+	MwWidget handle,
+	int child
+);
+
+
+ Gets a child of the message box. +
+
+ Parameter handle +
+
+ Widget. +
+
+ Parameter child +
+
+ Child. +
+
+

Mw/Milsko.h

diff --git a/include/Mw/Constants.h b/include/Mw/Constants.h index e7c6734..ab0a0f9 100644 --- a/include/Mw/Constants.h +++ b/include/Mw/Constants.h @@ -68,4 +68,44 @@ enum MwALIGNMENT { */ #define MwMB_ICONNEWS 0x5 +/*! + * %brief Button mask + */ +#define MwMB_BUTTONMASK 0xf0 + +/*! + * %brief OK button + */ +#define MwMB_BUTTONOK 0x10 + +/*! + * %brief Cancel button + */ +#define MwMB_BUTTONCANCEL 0x20 + +/*! + * %brief Yes button + */ +#define MwMB_BUTTONYES 0x40 + +/*! + * %brief No button + */ +#define MwMB_BUTTONNO 0x80 + +/*! + * %brief Ok and Cancel button + */ +#define MwMB_BUTTONOKCANCEL (MwMB_BUTTONCANCEL | MwMB_BUTTONOK) + +/*! + * %brief Yes and No button + */ +#define MwMB_BUTTONYESNO (MwMB_BUTTONYES | MwMB_BUTTONNO) + +/*! + * %brief Yes, No and Cancel button + */ +#define MwMB_BUTTONYESNOCANCEL (MwMB_BUTTONYES | MwMB_BUTTONNO | MwMB_BUTTONCANCEL) + #endif diff --git a/include/Mw/MessageBox.h b/include/Mw/MessageBox.h index 2342e46..7e2a543 100644 --- a/include/Mw/MessageBox.h +++ b/include/Mw/MessageBox.h @@ -14,6 +14,7 @@ extern "C" { #endif /*! + * %brief Creates a message box * %param handle Widget * %param text Text * %param title Title text @@ -22,6 +23,13 @@ extern "C" { */ MWDECL MwWidget MwMessageBox(MwWidget handle, const char* text, const char* title, unsigned int flag); +/*! + * %brief Gets a child of the message box + * %param handle Widget + * %param child Child + */ +MWDECL MwWidget MwMessageBoxGetChild(MwWidget handle, int child); + #ifdef __cplusplus } #endif diff --git a/resource/icon/info.png b/resource/icon/info.png index b6f543fbce7f64b15cc9d6d8cd75894a34c27a99..65f85c7e96d552d8e7b464b828ae79208b01c9f2 100644 GIT binary patch delta 48 zcmdnQyoq^2H#>)_;G4R8&o@qDW|XzCGB&p|G}AUPure@My!lfJ0}yz+`njxgN@xNA Dkh~AB delta 48 zcmdnQyoq^2H#@r?_s=amvo}s+W|TFzGBL9bP0l+XkK Dle`bX delta 48 zcmbQoGLL1#M0R#P?w?zBW^bI4$tY`XWnyM!XsB&qU}a#?J~zFH0SG)@{an^LB{Ts5 DfaDI@ diff --git a/resource/icon/note.png b/resource/icon/note.png index 0bcb4b23576d49d7ac2d5a3c9d3ad7a23597d18d..f41d709403d67766efcc591267646da109aaa20c 100644 GIT binary patch delta 48 zcmcb_a*1WabaoC^!8djHo^PBtol(}p%Glh>&|KTVz{gTe~DWM4f Du3Qjf delta 48 zcmcb_a*1Wabar+bP0l+XkK DjaCnu delta 48 zcmbQpGLdD%M0R#Pp7aYkCpONAVU#tuGBL90SG)@{an^LB{Ts5 DY9tP* diff --git a/resource/icon/warning.png b/resource/icon/warning.png index 08ba558bdafd382d78de6609d6d97aa34fe02f18..f6b92afcaf148cf949449a5f6ac8eede1e8b5b50 100644 GIT binary patch delta 48 zcmeyw{E2zOM0O5U!8djHo^PCC%P4DMWo&L`Xs&HwU}a#ydgSK;1|aZs^>bP0l+XkK Dthf+6 delta 48 zcmeyw{E2zOM0R#Pp7aYkCpONoWt26yGBL90SG)@{an^LB{Ts5 DiG~kJ diff --git a/src/messagebox.c b/src/messagebox.c index 50710e0..478067d 100644 --- a/src/messagebox.c +++ b/src/messagebox.c @@ -1,18 +1,31 @@ /* $Id$ */ #include -void msgbox_ok_handler(MwWidget handle, void* user, void* call) { - MwWidget win = user; +#include "external/stb_ds.h" - MwDestroyWidget(win); +typedef struct msgbox { + int key; + MwWidget value; +} msgbox_t; + +static void spawn_button(MwWidget handle, int x, int y, int id, const char* text) { + msgbox_t* mb = handle->opaque; + MwWidget widget = MwVaCreateWidget(MwButtonClass, text, handle, x, y, 80, 24, + MwNtext, text, + NULL); + + hmput(mb, id, widget); + + handle->opaque = mb; } MwWidget MwMessageBox(MwWidget handle, const char* text, const char* title, unsigned int flag) { - MwWidget window, ok; + MwWidget window; MwPoint p; int w, h; int left = 8; int th; + int x = 0; p.x = 0; p.y = 0; @@ -20,11 +33,14 @@ MwWidget MwMessageBox(MwWidget handle, const char* text, const char* title, unsi window = MwVaCreateWidget(MwWindowClass, "messagebox", handle, 0, 0, (w = 512), (h = 32 * 4), MwNtitle, title, NULL); - ok = MwVaCreateWidget(MwButtonClass, "ok", window, w - 8 - 80, h - 8 - 24, 80, 24, - MwNtext, "OK", - NULL); - MwAddUserHandler(ok, MwNactivateHandler, msgbox_ok_handler, window); + window->opaque = NULL; + + if(flag & MwMB_BUTTONOK) spawn_button(window, w - (x += 8 + 80), h - 8 - 24, MwMB_BUTTONOK, "OK"); + if(flag & MwMB_BUTTONCANCEL) spawn_button(window, w - (x += 8 + 80), h - 8 - 24, MwMB_BUTTONCANCEL, "Cancel"); + + if(flag & MwMB_BUTTONNO) spawn_button(window, w - (x += 8 + 80), h - 8 - 24, MwMB_BUTTONNO, "No"); + if(flag & MwMB_BUTTONYES) spawn_button(window, w - (x += 8 + 80), h - 8 - 24, MwMB_BUTTONYES, "Yes"); if((flag & MwMB_ICONMASK) != 0) { MwWidget icon; @@ -75,3 +91,9 @@ MwWidget MwMessageBox(MwWidget handle, const char* text, const char* title, unsi return window; } + +MwWidget MwMessageBoxGetChild(MwWidget handle, int child) { + msgbox_t* mb = handle->opaque; + + return hmget(mb, child); +}