mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2026-01-11 11:53:29 +00:00
better api for mouse
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@269 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
@@ -163,23 +163,33 @@ void MwLLNextEvent(MwLL handle) {
|
||||
if(ev.type == Expose) {
|
||||
render = 1;
|
||||
} else if(ev.type == ButtonPress) {
|
||||
MwLLMouse p;
|
||||
p.point.x = ev.xbutton.x;
|
||||
p.point.y = ev.xbutton.y;
|
||||
if(ev.xbutton.button == Button1) {
|
||||
MwPoint p;
|
||||
p.x = ev.xbutton.x;
|
||||
p.y = ev.xbutton.y;
|
||||
|
||||
MwLLDispatch(handle, down, &p);
|
||||
|
||||
XSetInputFocus(handle->display, handle->window, RevertToNone, CurrentTime);
|
||||
p.button = MwLLMouseLeft;
|
||||
} else if(ev.xbutton.button == Button2) {
|
||||
p.button = MwLLMouseMiddle;
|
||||
} else if(ev.xbutton.button == Button3) {
|
||||
p.button = MwLLMouseRight;
|
||||
}
|
||||
|
||||
MwLLDispatch(handle, down, &p);
|
||||
|
||||
XSetInputFocus(handle->display, handle->window, RevertToNone, CurrentTime);
|
||||
} else if(ev.type == ButtonRelease) {
|
||||
MwLLMouse p;
|
||||
p.point.x = ev.xbutton.x;
|
||||
p.point.y = ev.xbutton.y;
|
||||
if(ev.xbutton.button == Button1) {
|
||||
MwPoint p;
|
||||
p.x = ev.xbutton.x;
|
||||
p.y = ev.xbutton.y;
|
||||
|
||||
MwLLDispatch(handle, up, &p);
|
||||
p.button = MwLLMouseLeft;
|
||||
} else if(ev.xbutton.button == Button2) {
|
||||
p.button = MwLLMouseMiddle;
|
||||
} else if(ev.xbutton.button == Button3) {
|
||||
p.button = MwLLMouseRight;
|
||||
}
|
||||
|
||||
MwLLDispatch(handle, up, &p);
|
||||
} else if(ev.type == ConfigureNotify) {
|
||||
MwLLDispatch(handle, resize, NULL);
|
||||
|
||||
|
||||
34
src/core.c
34
src/core.c
@@ -12,28 +12,26 @@ static void lldrawhandler(MwLL handle, void* data) {
|
||||
}
|
||||
|
||||
static void lluphandler(MwLL handle, void* data) {
|
||||
MwWidget h = (MwWidget)handle->user;
|
||||
MwPoint* p = data;
|
||||
MwWidget h = (MwWidget)handle->user;
|
||||
MwLLMouse* p = data;
|
||||
|
||||
(void)data;
|
||||
if(p->button == MwLLMouseLeft) h->pressed = 0;
|
||||
h->mouse_point.x = p->point.x;
|
||||
h->mouse_point.y = p->point.y;
|
||||
|
||||
h->pressed = 0;
|
||||
h->mouse_point.x = p->x;
|
||||
h->mouse_point.y = p->y;
|
||||
|
||||
MwDispatch(h, click);
|
||||
MwDispatch(h, mouse_up);
|
||||
if(p->button == MwLLMouseLeft) MwDispatch(h, click);
|
||||
MwDispatch3(h, mouse_up, data);
|
||||
MwDispatchUserHandler(h, MwNmouseUpHandler, data);
|
||||
}
|
||||
|
||||
static void lldownhandler(MwLL handle, void* data) {
|
||||
MwWidget h = (MwWidget)handle->user;
|
||||
MwPoint* p = data;
|
||||
h->pressed = 1;
|
||||
h->mouse_point.x = p->x;
|
||||
h->mouse_point.y = p->y;
|
||||
MwWidget h = (MwWidget)handle->user;
|
||||
MwLLMouse* p = data;
|
||||
if(p->button == MwLLMouseLeft) h->pressed = 1;
|
||||
h->mouse_point.x = p->point.x;
|
||||
h->mouse_point.y = p->point.y;
|
||||
|
||||
MwDispatch(h, mouse_down);
|
||||
MwDispatch3(h, mouse_down, data);
|
||||
MwDispatchUserHandler(h, MwNmouseDownHandler, data);
|
||||
}
|
||||
|
||||
@@ -384,3 +382,9 @@ void MwGetBeforeStep(MwWidget handle, jmp_buf* jmpbuf) {
|
||||
void MwForceRender(MwWidget handle) {
|
||||
MwLLForceRender(handle->lowlevel);
|
||||
}
|
||||
|
||||
void MwForceRender2(MwWidget handle, void* ptr) {
|
||||
(void)ptr;
|
||||
|
||||
MwForceRender(handle);
|
||||
}
|
||||
|
||||
@@ -66,16 +66,16 @@ static void prop_change(MwWidget handle, const char* key) {
|
||||
}
|
||||
|
||||
MwClassRec MwButtonClassRec = {
|
||||
create, /* create */
|
||||
NULL, /* destroy */
|
||||
draw, /* draw */
|
||||
click, /* click */
|
||||
NULL, /* parent_resize */
|
||||
prop_change, /* prop_change */
|
||||
NULL, /* mouse_move */
|
||||
MwForceRender, /* mouse_up */
|
||||
MwForceRender, /* mouse_down */
|
||||
NULL, /* key */
|
||||
create, /* create */
|
||||
NULL, /* destroy */
|
||||
draw, /* draw */
|
||||
click, /* click */
|
||||
NULL, /* parent_resize */
|
||||
prop_change, /* prop_change */
|
||||
NULL, /* mouse_move */
|
||||
MwForceRender2, /* mouse_up */
|
||||
MwForceRender2, /* mouse_down */
|
||||
NULL, /* key */
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
|
||||
@@ -38,16 +38,16 @@ static void prop_change(MwWidget handle, const char* key) {
|
||||
}
|
||||
|
||||
MwClassRec MwCheckBoxClassRec = {
|
||||
create, /* create */
|
||||
NULL, /* destroy */
|
||||
draw, /* draw */
|
||||
click, /* click */
|
||||
NULL, /* parent_resize */
|
||||
prop_change, /* prop_change */
|
||||
NULL, /* mouse_move */
|
||||
MwForceRender, /* mouse_up */
|
||||
MwForceRender, /* mouse_down */
|
||||
NULL, /* key */
|
||||
create, /* create */
|
||||
NULL, /* destroy */
|
||||
draw, /* draw */
|
||||
click, /* click */
|
||||
NULL, /* parent_resize */
|
||||
prop_change, /* prop_change */
|
||||
NULL, /* mouse_move */
|
||||
MwForceRender2, /* mouse_up */
|
||||
MwForceRender2, /* mouse_down */
|
||||
NULL, /* key */
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
|
||||
@@ -118,16 +118,16 @@ static void key(MwWidget handle, int code) {
|
||||
}
|
||||
|
||||
MwClassRec MwEntryClassRec = {
|
||||
create, /* create */
|
||||
destroy, /* destroy */
|
||||
draw, /* draw */
|
||||
NULL, /* click */
|
||||
NULL, /* parent_resize */
|
||||
NULL, /* prop_change */
|
||||
NULL, /* mouse_move */
|
||||
MwForceRender, /* mouse_up */
|
||||
MwForceRender, /* mouse_down */
|
||||
key, /* key */
|
||||
create, /* create */
|
||||
destroy, /* destroy */
|
||||
draw, /* draw */
|
||||
NULL, /* click */
|
||||
NULL, /* parent_resize */
|
||||
NULL, /* prop_change */
|
||||
NULL, /* mouse_move */
|
||||
MwForceRender2, /* mouse_up */
|
||||
MwForceRender2, /* mouse_down */
|
||||
key, /* key */
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
|
||||
@@ -122,8 +122,11 @@ static void parent_resize(MwWidget handle) {
|
||||
set_xywh(handle);
|
||||
}
|
||||
|
||||
static void mouse_down(MwWidget handle) {
|
||||
static void mouse_down(MwWidget handle, void* ptr) {
|
||||
MENU_LOOP_DECL;
|
||||
|
||||
if(((MwLLMouse*)ptr)->button != MwLLMouseLeft) return;
|
||||
|
||||
BEGIN_MENU_LOOP;
|
||||
if(in_area) {
|
||||
if(m->sub[i]->wsub == NULL && arrlen(m->sub[i]->sub) > 0) {
|
||||
@@ -151,8 +154,11 @@ static void mouse_down(MwWidget handle) {
|
||||
MwForceRender(handle);
|
||||
}
|
||||
|
||||
static void mouse_up(MwWidget handle) {
|
||||
static void mouse_up(MwWidget handle, void* ptr) {
|
||||
MENU_LOOP_DECL;
|
||||
|
||||
if(((MwLLMouse*)ptr)->button != MwLLMouseLeft) return;
|
||||
|
||||
BEGIN_MENU_LOOP;
|
||||
if(in_area && m->sub[i]->wsub != NULL) {
|
||||
m->sub[i]->keep = 1;
|
||||
|
||||
@@ -95,12 +95,14 @@ static void mouse_move(MwWidget handle) {
|
||||
}
|
||||
}
|
||||
|
||||
static void mouse_up(MwWidget handle) {
|
||||
static void mouse_up(MwWidget handle, void* ptr) {
|
||||
MwEntry e = handle->internal;
|
||||
int w = MwGetInteger(handle, MwNwidth);
|
||||
int h = MwGetInteger(handle, MwNheight);
|
||||
const char* str = MwGetText(handle, MwNtext);
|
||||
|
||||
if(((MwLLMouse*)ptr)->button != MwLLMouseLeft) return;
|
||||
|
||||
if(e->mouse.x >= (w - e->right)) {
|
||||
char s[512];
|
||||
if(e->mouse.y >= (h / 2)) {
|
||||
@@ -114,9 +116,11 @@ static void mouse_up(MwWidget handle) {
|
||||
MwForceRender(handle);
|
||||
}
|
||||
|
||||
static void mouse_down(MwWidget handle) {
|
||||
static void mouse_down(MwWidget handle, void* ptr) {
|
||||
MwEntry e = handle->internal;
|
||||
|
||||
if(((MwLLMouse*)ptr)->button != MwLLMouseLeft) return;
|
||||
|
||||
e->mouse = handle->mouse_point;
|
||||
|
||||
MwForceRender(handle);
|
||||
|
||||
@@ -156,12 +156,14 @@ static void mouse_move(MwWidget handle) {
|
||||
}
|
||||
}
|
||||
|
||||
static void mouse_down(MwWidget handle) {
|
||||
static void mouse_down(MwWidget handle, void* ptr) {
|
||||
int ww = MwGetInteger(handle, MwNwidth);
|
||||
int wh = MwGetInteger(handle, MwNheight);
|
||||
int or = MwGetInteger(handle, MwNorientation);
|
||||
scrollbar_t* scr = handle->internal;
|
||||
|
||||
if(((MwLLMouse*)ptr)->button != MwLLMouseLeft) return;
|
||||
|
||||
scr->point = handle->mouse_point;
|
||||
scr->drag = 0;
|
||||
if(or == MwVERTICAL) {
|
||||
@@ -186,16 +188,16 @@ static void prop_change(MwWidget handle, const char* key) {
|
||||
}
|
||||
|
||||
MwClassRec MwScrollBarClassRec = {
|
||||
create, /* create */
|
||||
destroy, /* destroy */
|
||||
draw, /* draw */
|
||||
NULL, /* click */
|
||||
NULL, /* parent_resize */
|
||||
prop_change, /* prop_change */
|
||||
mouse_move, /* mouse_move */
|
||||
MwForceRender, /* mouse_up */
|
||||
mouse_down, /* mouse_down */
|
||||
NULL, /* key */
|
||||
create, /* create */
|
||||
destroy, /* destroy */
|
||||
draw, /* draw */
|
||||
NULL, /* click */
|
||||
NULL, /* parent_resize */
|
||||
prop_change, /* prop_change */
|
||||
mouse_move, /* mouse_move */
|
||||
MwForceRender2, /* mouse_up */
|
||||
mouse_down, /* mouse_down */
|
||||
NULL, /* key */
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
|
||||
@@ -147,16 +147,16 @@ static void click(MwWidget handle) {
|
||||
}
|
||||
|
||||
MwClassRec MwSubMenuClassRec = {
|
||||
create, /* create */
|
||||
destroy, /* destroy */
|
||||
draw, /* draw */
|
||||
click, /* click */
|
||||
NULL, /* parent_resize */
|
||||
NULL, /* prop_change */
|
||||
NULL, /* mouse_move */
|
||||
MwForceRender, /* mouse_up */
|
||||
MwForceRender, /* mouse_down */
|
||||
NULL, /* key */
|
||||
create, /* create */
|
||||
destroy, /* destroy */
|
||||
draw, /* draw */
|
||||
click, /* click */
|
||||
NULL, /* parent_resize */
|
||||
NULL, /* prop_change */
|
||||
NULL, /* mouse_move */
|
||||
MwForceRender2, /* mouse_up */
|
||||
MwForceRender2, /* mouse_down */
|
||||
NULL, /* key */
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
|
||||
Reference in New Issue
Block a user