more handler

git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@268 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-10-11 11:46:28 +00:00
parent 927f9577ca
commit a5dae3ffd9
5 changed files with 33 additions and 12 deletions

View File

@@ -52,6 +52,7 @@ struct _MwLLHandler {
void (*close)(MwLL handle, void* data);
void (*move)(MwLL handle, void* data);
void (*key)(MwLL handle, void* data);
void (*key_released)(MwLL handle, void* data);
};
#ifdef __cplusplus

View File

@@ -36,5 +36,6 @@
#define MwNmouseUpHandler "CmouseUpHandler"
#define MwNchangedHandler "CchangedHandler"
#define MwNkeyHandler "CkeyHandler"
#define MwNkeyReleasedHandler "CkeyReleasedHandler"
#endif

View File

@@ -81,13 +81,19 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
int n = wp;
MwLLDispatch(u->ll, key, &n);
} else if(msg == WM_KEYDOWN) {
} else if(msg == WM_KEYDOWN || msg == WM_KEYUP) {
int n = -1;
if(wp == VK_LEFT) n = MwLLKeyLeft;
if(wp == VK_RIGHT) n = MwLLKeyRight;
if(wp == VK_UP) n = MwLLKeyUp;
if(wp == VK_DOWN) n = MwLLKeyDown;
if(n != -1) MwLLDispatch(u->ll, key, &n);
if(n != -1) {
if(msg == WM_KEYDOWN) {
MwLLDispatch(u->ll, key, &n);
} else {
MwLLDispatch(u->ll, key_released, &n);
}
}
} else if(msg == WM_GETMINMAXINFO) {
if(u->min_set || u->max_set) {
LPARAM style = GetWindowLongPtr(hWnd, GWL_STYLE);

View File

@@ -200,7 +200,7 @@ void MwLLNextEvent(MwLL handle) {
p.y = ev.xmotion.y;
MwLLDispatch(handle, move, &p);
} else if(ev.type == KeyPress) {
} else if(ev.type == KeyPress || ev.type == KeyRelease) {
int n = -1;
char str[512];
KeySym sym;
@@ -237,7 +237,13 @@ void MwLLNextEvent(MwLL handle) {
n = MwLLKeyDown;
}
if(n != -1) MwLLDispatch(handle, key, &n);
if(n != -1) {
if(ev.type == KeyPress) {
MwLLDispatch(handle, key, &n);
} else {
MwLLDispatch(handle, key_released, &n);
}
}
}
if(render) {
int x, y;

View File

@@ -74,6 +74,12 @@ static void llkeyhandler(MwLL handle, void* data) {
MwDispatchUserHandler(h, MwNkeyHandler, data);
}
static void llkeyrelhandler(MwLL handle, void* data) {
MwWidget h = (MwWidget)handle->user;
MwDispatchUserHandler(h, MwNkeyReleasedHandler, data);
}
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));
@@ -93,14 +99,15 @@ MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent,
h->destroy_queue = NULL;
h->prop_event = 1;
h->lowlevel->user = h;
h->lowlevel->handler->draw = lldrawhandler;
h->lowlevel->handler->up = lluphandler;
h->lowlevel->handler->down = lldownhandler;
h->lowlevel->handler->resize = llresizehandler;
h->lowlevel->handler->close = llclosehandler;
h->lowlevel->handler->move = llmovehandler;
h->lowlevel->handler->key = llkeyhandler;
h->lowlevel->user = h;
h->lowlevel->handler->draw = lldrawhandler;
h->lowlevel->handler->up = lluphandler;
h->lowlevel->handler->down = lldownhandler;
h->lowlevel->handler->resize = llresizehandler;
h->lowlevel->handler->close = llclosehandler;
h->lowlevel->handler->move = llmovehandler;
h->lowlevel->handler->key = llkeyhandler;
h->lowlevel->handler->key_released = llkeyrelhandler;
if(parent != NULL) arrput(parent->children, h);