menu kinda works

git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@108 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-10-01 16:47:48 +00:00
parent aa92f0c31e
commit 4dc4093119
7 changed files with 120 additions and 25 deletions

View File

@@ -134,6 +134,9 @@
<dd>
<a href="#Mw_Font_h__MwFontData__">MwFontData[]</a>
</dd>
<dd>
<a href="#Mw_Font_h__MwBoldFontData__">MwBoldFontData[]</a>
</dd>
<dt>
<a href="#Mw_Frame_h">Mw/Frame.h</a>
</dt>
@@ -155,6 +158,9 @@
<dd>
<a href="#Mw_Menu_h__MwMenuClass">MwMenuClass</a>
</dd>
<dd>
<a href="#Mw_Menu_h__MwMenuAdd">MwMenuAdd</a>
</dd>
<dt>
<a href="#Mw_Milsko_h">Mw/Milsko.h</a>
</dt>
@@ -1064,6 +1070,7 @@
MwWidget handle,
MwPoint* point,
const char* text,
int bold,
MwLLColor color
);</code></pre>
<dl>
@@ -1088,6 +1095,12 @@
<dd>
Text.
</dd>
<dt>
Parameter <code>bold</code>
</dt>
<dd>
Bold.
</dd>
<dt>
Parameter <code>color</code>
</dt>
@@ -1215,6 +1228,13 @@
</dd>
</dl>
<hr>
<pre id="Mw_Font_h__MwBoldFontData__"><code>MWDECL MwFont MwBoldFontData[];</code></pre>
<dl>
<dd>
Default bold font data.
</dd>
</dl>
<hr>
<h2 align="center" id="Mw_Frame_h">Mw/Frame.h</h2>
<dl>
<dt>
@@ -1276,6 +1296,41 @@
</dd>
</dl>
<hr>
<pre id="Mw_Menu_h__MwMenuAdd"><code>MWDECL void* MwMenuAdd (
MwWidget handle,
void* menu,
const char* name
);</code></pre>
<dl>
<dd>
Adds a menu.
</dd>
<dt>
Parameter <code>handle</code>
</dt>
<dd>
Widget.
</dd>
<dt>
Parameter <code>menu</code>
</dt>
<dd>
Menu.
</dd>
<dt>
Parameter <code>name</code>
</dt>
<dd>
Menu name.
</dd>
<dt>
Returns
</dt>
<dd>
Menu.
</dd>
</dl>
<hr>
<h2 align="center" id="Mw_Milsko_h">Mw/Milsko.h</h2>
<dl>
<dt>

View File

@@ -30,15 +30,15 @@ typedef void* MwLLPixmap;
#endif
#include <Mw/TypeDefs.h>
#define MwLLDispatch(x, y) \
if(x->handler != NULL && x->handler->y != NULL) x->handler->y(x)
#define MwLLDispatch(x, y, z) \
if(x->handler != NULL && x->handler->y != NULL) x->handler->y(x, z)
struct _MwLLHandler {
void (*draw)(MwLL handle);
void (*up)(MwLL handle);
void (*down)(MwLL handle);
void (*resize)(MwLL handle);
void (*close)(MwLL handle);
void (*draw)(MwLL handle, void* data);
void (*up)(MwLL handle, void* data);
void (*down)(MwLL handle, void* data);
void (*resize)(MwLL handle, void* data);
void (*close)(MwLL handle, void* data);
};
#ifdef __cplusplus

View File

@@ -72,6 +72,7 @@ struct _MwWidget {
MwClass widget_class;
int pressed;
MwPoint pressed_point;
int close;
jmp_buf before_step;

View File

@@ -3,36 +3,49 @@
#include "stb_ds.h"
static void lldrawhandler(MwLL handle) {
static void lldrawhandler(MwLL handle, void* data) {
MwWidget h = (MwWidget)handle->user;
(void)data;
MwDispatch(h, draw);
}
static void lluphandler(MwLL handle) {
static void lluphandler(MwLL handle, void* data) {
MwWidget h = (MwWidget)handle->user;
(void)data;
h->pressed = 0;
MwDispatch(h, click);
}
static void lldownhandler(MwLL handle) {
MwWidget h = (MwWidget)handle->user;
h->pressed = 1;
static void lldownhandler(MwLL handle, void* data) {
MwWidget h = (MwWidget)handle->user;
MwPoint* p = data;
h->pressed = 1;
h->pressed_point.x = p->x;
h->pressed_point.y = p->y;
}
static void llresizehandler(MwLL handle) {
static void llresizehandler(MwLL handle, void* data) {
MwWidget h = (MwWidget)handle->user;
int i;
(void)data;
MwDispatchUserHandler(h, MwNresizeHandler, NULL);
for(i = 0; i < arrlen(h->children); i++) {
MwDispatch(h->children[i], parent_resize);
}
}
static void llclosehandler(MwLL handle) {
static void llclosehandler(MwLL handle, void* data) {
MwWidget h = (MwWidget)handle->user;
(void)data;
h->close = 1;
}

View File

@@ -27,7 +27,7 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
ReleaseDC(hWnd, dc);
u->ll->hDC = hbdc;
MwLLDispatch(u->ll, draw);
MwLLDispatch(u->ll, draw, NULL);
dc = BeginPaint(hWnd, &ps);
StretchBlt(dc, 0, 0, rc.right - rc.left, rc.bottom - rc.top, hbdc, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SRCCOPY);
@@ -37,25 +37,33 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
DeleteObject(hbmp);
} else {
u->ll->hDC = BeginPaint(hWnd, &ps);
MwLLDispatch(u->ll, draw);
MwLLDispatch(u->ll, draw, NULL);
EndPaint(hWnd, &ps);
}
} else if(msg == WM_LBUTTONDOWN) {
MwPoint p;
p.x = LOWORD(lp);
p.y = HIWORD(lp);
SetCapture(hWnd);
MwLLDispatch(u->ll, down);
MwLLDispatch(u->ll, down, &p);
InvalidateRect(hWnd, NULL, FALSE);
} else if(msg == WM_LBUTTONUP) {
MwPoint p;
p.x = LOWORD(lp);
p.y = HIWORD(lp);
SetCapture(NULL);
MwLLDispatch(u->ll, up);
MwLLDispatch(u->ll, up, &p);
InvalidateRect(hWnd, NULL, FALSE);
} else if(msg == WM_SIZE) {
MwLLDispatch(u->ll, resize);
MwLLDispatch(u->ll, resize, NULL);
} else if(msg == WM_ERASEBKGND) {
return 1;
} else if(msg == WM_NCHITTEST) {
return HTCLIENT;
} else if(msg == WM_DESTROY) {
MwLLDispatch(u->ll, close);
MwLLDispatch(u->ll, close, NULL);
PostQuitMessage(0);
} else if(msg == WM_CLOSE) {
DestroyWindow(hWnd);

View File

@@ -82,9 +82,19 @@ static void draw(MwWidget handle) {
MwDrawRect(handle, &r, base);
for(i = 0; i < arrlen(m->sub); i++) {
int tw = MwTextWidth(handle, m->sub[i]->name);
int th = MwTextHeight(handle, m->sub[i]->name);
p.x += tw / 2;
r.x = p.x - tw / 2 - 5;
r.y = p.y - th / 2 - 5;
r.width = tw + 10;
r.height = th + 10;
if(handle->pressed && r.x <= handle->pressed_point.x && r.y <= handle->pressed_point.y && handle->pressed_point.x <= (int)(r.x + r.width) && handle->pressed_point.y <= (int)(r.y + r.height)) {
MwDrawFrame(handle, &r, base, 0);
}
MwDrawText(handle, &p, m->sub[i]->name, 1, text);
p.x += tw / 2 + 20;

View File

@@ -145,16 +145,24 @@ void MwLLNextEvent(MwLL handle) {
render = 1;
} else if(ev.type == ButtonPress) {
if(ev.xbutton.button == Button1) {
MwLLDispatch(handle, down);
MwPoint p;
p.x = ev.xbutton.x;
p.y = ev.xbutton.y;
MwLLDispatch(handle, down, &p);
render = 1;
}
} else if(ev.type == ButtonRelease) {
if(ev.xbutton.button == Button1) {
MwLLDispatch(handle, up);
MwPoint p;
p.x = ev.xbutton.x;
p.y = ev.xbutton.y;
MwLLDispatch(handle, up, &p);
render = 1;
}
} else if(ev.type == ConfigureNotify) {
MwLLDispatch(handle, resize);
MwLLDispatch(handle, resize, NULL);
if(handle->width != (unsigned int)ev.xconfigure.width || handle->height != (unsigned int)ev.xconfigure.height) {
destroy_pixmap(handle);
@@ -165,7 +173,7 @@ void MwLLNextEvent(MwLL handle) {
handle->height = ev.xconfigure.height;
} else if(ev.type == ClientMessage) {
if(ev.xclient.data.l[0] == (long)handle->wm_delete) {
MwLLDispatch(handle, close);
MwLLDispatch(handle, close, NULL);
}
}
if(render) {
@@ -174,7 +182,7 @@ void MwLLNextEvent(MwLL handle) {
MwLLGetXYWH(handle, &x, &y, &w, &h);
MwLLDispatch(handle, draw);
MwLLDispatch(handle, draw, NULL);
if(handle->copy_buffer) XCopyArea(handle->display, handle->pixmap, handle->window, handle->gc, 0, 0, w, h, 0, 0);
}
}