mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2026-01-08 10:23:27 +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>
|
#include <Mw/Milsko.h>
|
||||||
|
|
||||||
|
MwWidget window, button, button2, button3, button4;
|
||||||
|
|
||||||
void handler(MwWidget handle, void* user_data, void* call_data){
|
void handler(MwWidget handle, void* user_data, void* call_data){
|
||||||
(void)handle;
|
(void)handle;
|
||||||
(void)user_data;
|
(void)user_data;
|
||||||
@@ -10,26 +12,59 @@ void handler(MwWidget handle, void* user_data, void* call_data){
|
|||||||
printf("hello world!\n");
|
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(){
|
int main(){
|
||||||
MwWidget window = MwVaCreateWidget(MwWindowClass, "main", NULL, 0, 0, 400, 400,
|
window = MwVaCreateWidget(MwWindowClass, "main", NULL, 0, 0, 400, 400,
|
||||||
MwNtitle, "hello world",
|
MwNtitle, "hello world",
|
||||||
NULL);
|
NULL);
|
||||||
MwWidget button = MwVaCreateWidget(MwButtonClass, "button", window, 50, 50, 300, 125,
|
button = MwVaCreateWidget(MwButtonClass, "button", window, 50, 50, 300, 125,
|
||||||
MwNtext, "lorem ipsum",
|
MwNtext, "lorem ipsum",
|
||||||
NULL);
|
NULL);
|
||||||
MwWidget button2 = MwVaCreateWidget(MwButtonClass, "button", window, 50, 225, 100, 125,
|
button2 = MwVaCreateWidget(MwButtonClass, "button", window, 50, 225, 100, 125,
|
||||||
MwNtext, "lorem ipsum",
|
MwNtext, "lorem ipsum",
|
||||||
MwNbackground, "#f66",
|
MwNbackground, "#f66",
|
||||||
NULL);
|
NULL);
|
||||||
MwWidget button3 = MwVaCreateWidget(MwButtonClass, "button", window, 150, 225, 100, 125,
|
button3 = MwVaCreateWidget(MwButtonClass, "button", window, 150, 225, 100, 125,
|
||||||
MwNtext, "lorem ipsum",
|
MwNtext, "lorem ipsum",
|
||||||
MwNbackground, "#6f6",
|
MwNbackground, "#6f6",
|
||||||
NULL);
|
NULL);
|
||||||
MwWidget button4 = MwVaCreateWidget(MwButtonClass, "button", window, 250, 225, 100, 125,
|
button4 = MwVaCreateWidget(MwButtonClass, "button", window, 250, 225, 100, 125,
|
||||||
MwNtext, "lorem ipsum",
|
MwNtext, "lorem ipsum",
|
||||||
MwNbackground, "#66f",
|
MwNbackground, "#66f",
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
|
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
|
||||||
MwAddUserHandler(button, MwNactivateHandler, handler, NULL);
|
MwAddUserHandler(button, MwNactivateHandler, handler, NULL);
|
||||||
MwAddUserHandler(button2, MwNactivateHandler, handler, NULL);
|
MwAddUserHandler(button2, MwNactivateHandler, handler, NULL);
|
||||||
MwAddUserHandler(button3, MwNactivateHandler, handler, NULL);
|
MwAddUserHandler(button3, MwNactivateHandler, handler, NULL);
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ struct _MwLLHandler {
|
|||||||
void (*draw)(MwLL handle);
|
void (*draw)(MwLL handle);
|
||||||
void (*up)(MwLL handle);
|
void (*up)(MwLL handle);
|
||||||
void (*down)(MwLL handle);
|
void (*down)(MwLL handle);
|
||||||
|
void (*resize)(MwLL handle);
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
@@ -13,5 +13,6 @@
|
|||||||
#define MwNforeground "Sforeground"
|
#define MwNforeground "Sforeground"
|
||||||
|
|
||||||
#define MwNactivateHandler "Cactivate"
|
#define MwNactivateHandler "Cactivate"
|
||||||
|
#define MwNresizeHandler "Cresize"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -20,6 +20,12 @@ static void lldownhandler(MwLL handle) {
|
|||||||
h->pressed = 1;
|
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 MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent, int x, int y, unsigned int width, unsigned int height) {
|
||||||
MwWidget h = malloc(sizeof(*h));
|
MwWidget h = malloc(sizeof(*h));
|
||||||
|
|
||||||
@@ -36,6 +42,7 @@ MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent,
|
|||||||
h->lowlevel->handler->draw = lldrawhandler;
|
h->lowlevel->handler->draw = lldrawhandler;
|
||||||
h->lowlevel->handler->up = lluphandler;
|
h->lowlevel->handler->up = lluphandler;
|
||||||
h->lowlevel->handler->down = lldownhandler;
|
h->lowlevel->handler->down = lldownhandler;
|
||||||
|
h->lowlevel->handler->resize = llresizehandler;
|
||||||
|
|
||||||
if(parent != NULL) arrput(parent->children, h);
|
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);
|
SetCapture(NULL);
|
||||||
MwLLDispatch(u->ll, up);
|
MwLLDispatch(u->ll, up);
|
||||||
InvalidateRect(hWnd, NULL, FALSE);
|
InvalidateRect(hWnd, NULL, FALSE);
|
||||||
|
} else if(msg == WM_SIZE) {
|
||||||
|
MwLLDispatch(u->ll, resize);
|
||||||
} else if(msg == WM_ERASEBKGND) {
|
} else if(msg == WM_ERASEBKGND) {
|
||||||
} else if(msg == WM_NCHITTEST) {
|
} else if(msg == WM_NCHITTEST) {
|
||||||
return HTCLIENT;
|
return HTCLIENT;
|
||||||
@@ -140,6 +142,7 @@ void MwLLGetXYWH(MwLL handle, int* x, int* y, unsigned int* w, unsigned int* h)
|
|||||||
RECT rc;
|
RECT rc;
|
||||||
|
|
||||||
GetClientRect(handle->hWnd, &rc);
|
GetClientRect(handle->hWnd, &rc);
|
||||||
|
MapWindowPoints(handle->hWnd, GetParent(handle->hWnd), (LPPOINT)&rc, 2);
|
||||||
|
|
||||||
*x = rc.left;
|
*x = rc.left;
|
||||||
*y = rc.top;
|
*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) {
|
void MwLLSetXY(MwLL handle, int x, int y) {
|
||||||
SetWindowPos(handle->hWnd, NULL, x, y, 0, 0, SWP_NOSIZE);
|
SetWindowPos(handle->hWnd, NULL, x, y, 0, 0, SWP_NOSIZE);
|
||||||
|
InvalidateRect(handle->hWnd, NULL, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MwLLSetWH(MwLL handle, int w, int h) {
|
void MwLLSetWH(MwLL handle, int w, int h) {
|
||||||
SetWindowPos(handle->hWnd, NULL, 0, 0, w, h, SWP_NOMOVE);
|
SetWindowPos(handle->hWnd, NULL, 0, 0, w, h, SWP_NOMOVE);
|
||||||
|
InvalidateRect(handle->hWnd, NULL, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MwLLSetTitle(MwLL handle, const char* title) {
|
void MwLLSetTitle(MwLL handle, const char* title) {
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ int MwLLPending(MwLL handle) {
|
|||||||
|
|
||||||
void MwLLNextEvent(MwLL handle) {
|
void MwLLNextEvent(MwLL handle) {
|
||||||
XEvent ev;
|
XEvent ev;
|
||||||
if(XCheckWindowEvent(handle->display, handle->window, mask, &ev)) {
|
while(XCheckWindowEvent(handle->display, handle->window, mask, &ev)) {
|
||||||
if(ev.type == Expose) {
|
if(ev.type == Expose) {
|
||||||
MwLLDispatch(handle, draw);
|
MwLLDispatch(handle, draw);
|
||||||
} else if(ev.type == ButtonPress) {
|
} else if(ev.type == ButtonPress) {
|
||||||
@@ -118,6 +118,8 @@ void MwLLNextEvent(MwLL handle) {
|
|||||||
MwLLDispatch(handle, up);
|
MwLLDispatch(handle, up);
|
||||||
MwLLDispatch(handle, draw);
|
MwLLDispatch(handle, draw);
|
||||||
}
|
}
|
||||||
|
} else if(ev.type == ConfigureNotify) {
|
||||||
|
MwLLDispatch(handle, resize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user