mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2025-12-31 06:30:52 +00:00
map window points
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@58 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
#include <Mw/Milsko.h>
|
||||
|
||||
MwWidget window, button, button2, button3, button4;
|
||||
|
||||
void handler(MwWidget handle, void* user_data, void* call_data){
|
||||
(void)handle;
|
||||
(void)user_data;
|
||||
@@ -10,26 +12,59 @@ void handler(MwWidget handle, void* user_data, void* call_data){
|
||||
printf("hello world!\n");
|
||||
}
|
||||
|
||||
void resize(MwWidget handle, void* user_data, void* call_data){
|
||||
unsigned int w, h;
|
||||
w = MwGetInteger(handle, MwNwidth);
|
||||
h = MwGetInteger(handle, MwNheight);
|
||||
|
||||
(void)user_data;
|
||||
(void)call_data;
|
||||
|
||||
MwVaApply(button,
|
||||
MwNwidth, w - 50 * 2,
|
||||
MwNheight, h - 125 - 50 * 3,
|
||||
NULL);
|
||||
|
||||
MwVaApply(button2,
|
||||
MwNx, 50 + (w - 50 * 2) / 3 * 0,
|
||||
MwNy, h - 50 - 125,
|
||||
MwNwidth, (w - 50 * 2) / 3,
|
||||
NULL);
|
||||
|
||||
MwVaApply(button3,
|
||||
MwNx, 50 + (w - 50 * 2) / 3 * 1,
|
||||
MwNy, h - 50 - 125,
|
||||
MwNwidth, (w - 50 * 2) / 3,
|
||||
NULL);
|
||||
|
||||
MwVaApply(button4,
|
||||
MwNx, 50 + (w - 50 * 2) / 3 * 2,
|
||||
MwNy, h - 50 - 125,
|
||||
MwNwidth, (w - 50 * 2) / 3,
|
||||
NULL);
|
||||
}
|
||||
|
||||
int main(){
|
||||
MwWidget window = MwVaCreateWidget(MwWindowClass, "main", NULL, 0, 0, 400, 400,
|
||||
window = MwVaCreateWidget(MwWindowClass, "main", NULL, 0, 0, 400, 400,
|
||||
MwNtitle, "hello world",
|
||||
NULL);
|
||||
MwWidget button = MwVaCreateWidget(MwButtonClass, "button", window, 50, 50, 300, 125,
|
||||
button = MwVaCreateWidget(MwButtonClass, "button", window, 50, 50, 300, 125,
|
||||
MwNtext, "lorem ipsum",
|
||||
NULL);
|
||||
MwWidget button2 = MwVaCreateWidget(MwButtonClass, "button", window, 50, 225, 100, 125,
|
||||
button2 = MwVaCreateWidget(MwButtonClass, "button", window, 50, 225, 100, 125,
|
||||
MwNtext, "lorem ipsum",
|
||||
MwNbackground, "#f66",
|
||||
NULL);
|
||||
MwWidget button3 = MwVaCreateWidget(MwButtonClass, "button", window, 150, 225, 100, 125,
|
||||
button3 = MwVaCreateWidget(MwButtonClass, "button", window, 150, 225, 100, 125,
|
||||
MwNtext, "lorem ipsum",
|
||||
MwNbackground, "#6f6",
|
||||
NULL);
|
||||
MwWidget button4 = MwVaCreateWidget(MwButtonClass, "button", window, 250, 225, 100, 125,
|
||||
button4 = MwVaCreateWidget(MwButtonClass, "button", window, 250, 225, 100, 125,
|
||||
MwNtext, "lorem ipsum",
|
||||
MwNbackground, "#66f",
|
||||
NULL);
|
||||
|
||||
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
|
||||
MwAddUserHandler(button, MwNactivateHandler, handler, NULL);
|
||||
MwAddUserHandler(button2, MwNactivateHandler, handler, NULL);
|
||||
MwAddUserHandler(button3, MwNactivateHandler, handler, NULL);
|
||||
|
||||
@@ -30,6 +30,7 @@ struct _MwLLHandler {
|
||||
void (*draw)(MwLL handle);
|
||||
void (*up)(MwLL handle);
|
||||
void (*down)(MwLL handle);
|
||||
void (*resize)(MwLL handle);
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -13,5 +13,6 @@
|
||||
#define MwNforeground "Sforeground"
|
||||
|
||||
#define MwNactivateHandler "Cactivate"
|
||||
#define MwNresizeHandler "Cresize"
|
||||
|
||||
#endif
|
||||
|
||||
15
src/core.c
15
src/core.c
@@ -20,6 +20,12 @@ static void lldownhandler(MwLL handle) {
|
||||
h->pressed = 1;
|
||||
}
|
||||
|
||||
static void llresizehandler(MwLL handle) {
|
||||
MwWidget h = (MwWidget)handle->user;
|
||||
|
||||
MwDispatchUserHandler(h, MwNresizeHandler, NULL);
|
||||
}
|
||||
|
||||
MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent, int x, int y, unsigned int width, unsigned int height) {
|
||||
MwWidget h = malloc(sizeof(*h));
|
||||
|
||||
@@ -32,10 +38,11 @@ MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent,
|
||||
h->widget_class = widget_class;
|
||||
h->pressed = 0;
|
||||
|
||||
h->lowlevel->user = h;
|
||||
h->lowlevel->handler->draw = lldrawhandler;
|
||||
h->lowlevel->handler->up = lluphandler;
|
||||
h->lowlevel->handler->down = lldownhandler;
|
||||
h->lowlevel->user = h;
|
||||
h->lowlevel->handler->draw = lldrawhandler;
|
||||
h->lowlevel->handler->up = lluphandler;
|
||||
h->lowlevel->handler->down = lldownhandler;
|
||||
h->lowlevel->handler->resize = llresizehandler;
|
||||
|
||||
if(parent != NULL) arrput(parent->children, h);
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
|
||||
SetCapture(NULL);
|
||||
MwLLDispatch(u->ll, up);
|
||||
InvalidateRect(hWnd, NULL, FALSE);
|
||||
} else if(msg == WM_SIZE) {
|
||||
MwLLDispatch(u->ll, resize);
|
||||
} else if(msg == WM_ERASEBKGND) {
|
||||
} else if(msg == WM_NCHITTEST) {
|
||||
return HTCLIENT;
|
||||
@@ -140,6 +142,7 @@ void MwLLGetXYWH(MwLL handle, int* x, int* y, unsigned int* w, unsigned int* h)
|
||||
RECT rc;
|
||||
|
||||
GetClientRect(handle->hWnd, &rc);
|
||||
MapWindowPoints(handle->hWnd, GetParent(handle->hWnd), (LPPOINT)&rc, 2);
|
||||
|
||||
*x = rc.left;
|
||||
*y = rc.top;
|
||||
@@ -149,10 +152,12 @@ void MwLLGetXYWH(MwLL handle, int* x, int* y, unsigned int* w, unsigned int* h)
|
||||
|
||||
void MwLLSetXY(MwLL handle, int x, int y) {
|
||||
SetWindowPos(handle->hWnd, NULL, x, y, 0, 0, SWP_NOSIZE);
|
||||
InvalidateRect(handle->hWnd, NULL, FALSE);
|
||||
}
|
||||
|
||||
void MwLLSetWH(MwLL handle, int w, int h) {
|
||||
SetWindowPos(handle->hWnd, NULL, 0, 0, w, h, SWP_NOMOVE);
|
||||
InvalidateRect(handle->hWnd, NULL, FALSE);
|
||||
}
|
||||
|
||||
void MwLLSetTitle(MwLL handle, const char* title) {
|
||||
|
||||
@@ -105,7 +105,7 @@ int MwLLPending(MwLL handle) {
|
||||
|
||||
void MwLLNextEvent(MwLL handle) {
|
||||
XEvent ev;
|
||||
if(XCheckWindowEvent(handle->display, handle->window, mask, &ev)) {
|
||||
while(XCheckWindowEvent(handle->display, handle->window, mask, &ev)) {
|
||||
if(ev.type == Expose) {
|
||||
MwLLDispatch(handle, draw);
|
||||
} else if(ev.type == ButtonPress) {
|
||||
@@ -118,6 +118,8 @@ void MwLLNextEvent(MwLL handle) {
|
||||
MwLLDispatch(handle, up);
|
||||
MwLLDispatch(handle, draw);
|
||||
}
|
||||
} else if(ev.type == ConfigureNotify) {
|
||||
MwLLDispatch(handle, resize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user