diff --git a/doc/index.html b/doc/index.html index 4910a84..c6e9805 100644 --- a/doc/index.html +++ b/doc/index.html @@ -134,6 +134,9 @@
MwFontData[]
+
+ MwBoldFontData[] +
Mw/Frame.h
@@ -155,6 +158,9 @@
MwMenuClass
+
+ MwMenuAdd +
Mw/Milsko.h
@@ -1064,6 +1070,7 @@ MwWidget handle, MwPoint* point, const char* text, + int bold, MwLLColor color );
@@ -1088,6 +1095,12 @@
Text.
+
+ Parameter bold +
+
+ Bold. +
Parameter color
@@ -1215,6 +1228,13 @@

+
MWDECL MwFont MwBoldFontData[];
+
+
+ Default bold font data. +
+
+

Mw/Frame.h

@@ -1276,6 +1296,41 @@

+
MWDECL void* MwMenuAdd (
+	MwWidget handle,
+	void* menu,
+	const char* name
+);
+
+
+ Adds a menu. +
+
+ Parameter handle +
+
+ Widget. +
+
+ Parameter menu +
+
+ Menu. +
+
+ Parameter name +
+
+ Menu name. +
+
+ Returns +
+
+ Menu. +
+
+

Mw/Milsko.h

diff --git a/include/Mw/LowLevel.h b/include/Mw/LowLevel.h index c11ba1e..6320dd1 100644 --- a/include/Mw/LowLevel.h +++ b/include/Mw/LowLevel.h @@ -30,15 +30,15 @@ typedef void* MwLLPixmap; #endif #include -#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 diff --git a/include/Mw/TypeDefs.h b/include/Mw/TypeDefs.h index c44dad0..5be2552 100644 --- a/include/Mw/TypeDefs.h +++ b/include/Mw/TypeDefs.h @@ -72,6 +72,7 @@ struct _MwWidget { MwClass widget_class; int pressed; + MwPoint pressed_point; int close; jmp_buf before_step; diff --git a/src/core.c b/src/core.c index fe289d0..e3ca99e 100644 --- a/src/core.c +++ b/src/core.c @@ -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; } diff --git a/src/gdi.c b/src/gdi.c index c9f323a..419ba14 100644 --- a/src/gdi.c +++ b/src/gdi.c @@ -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); diff --git a/src/menu.c b/src/menu.c index b8fa664..aa554be 100644 --- a/src/menu.c +++ b/src/menu.c @@ -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; diff --git a/src/x11.c b/src/x11.c index 83746c9..c39e0c3 100644 --- a/src/x11.c +++ b/src/x11.c @@ -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); } }