diff --git a/include/Mw/TypeDefs.h b/include/Mw/TypeDefs.h index e9cf0f0..1e35d1b 100644 --- a/include/Mw/TypeDefs.h +++ b/include/Mw/TypeDefs.h @@ -102,8 +102,9 @@ struct _MwMenu { }; struct _MwEntry { - int cursor; - int right; + int cursor; + int right; + MwPoint mouse; }; #define MwCursorDataHeight 16 diff --git a/src/backend/x11.c b/src/backend/x11.c index 7e7e664..08aff70 100644 --- a/src/backend/x11.c +++ b/src/backend/x11.c @@ -209,6 +209,13 @@ void MwLLNextEvent(MwLL handle) { XLookupString(&ev.xkey, str, 512, &sym, NULL); + /* wtf is wrong with xlib? */ + if(strlen(str) == 0) { + char* s = XKeysymToString(sym); + + strcpy(str, s); + } + /* HACK: this is bad, you can guess why */ if(strlen(str) == 1) { char s = str[0]; diff --git a/src/widget/entry.c b/src/widget/entry.c index 1cbb2da..d0b6a20 100644 --- a/src/widget/entry.c +++ b/src/widget/entry.c @@ -5,6 +5,7 @@ static int create(MwWidget handle) { MwEntry t = malloc(sizeof(*t)); t->cursor = 0; + t->right = 0; handle->internal = t; MwSetDefault(handle); diff --git a/src/widget/numberentry.c b/src/widget/numberentry.c index 3662c4e..c0d08f9 100644 --- a/src/widget/numberentry.c +++ b/src/widget/numberentry.c @@ -10,6 +10,8 @@ static int create(MwWidget handle) { e = handle->internal; e->right = 32; + MwSetText(handle, MwNtext, "0"); + return 0; } @@ -18,7 +20,50 @@ static void destroy(MwWidget handle) { } static void draw(MwWidget handle) { + int w = MwGetInteger(handle, MwNwidth); + int h = MwGetInteger(handle, MwNheight); + MwEntry e = handle->internal; + MwRect r; + int pr; + MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground)); + MwEntryClass->draw(handle); + + pr = (handle->pressed && e->mouse.x >= (w - e->right) && e->mouse.y < (h / 2)) ? 1 : 0; + r.x = w - e->right; + r.y = 0; + r.width = e->right; + r.height = h / 2; + MwDrawFrame(handle, &r, base, pr); + MwDrawRect(handle, &r, base); + + if(r.width > r.height) { + r.width = r.height; + } else { + r.height = r.width; + } + r.x = r.x + (e->right - r.width) / 2; + r.y = r.y + (h / 2 - r.height) / 2; + MwDrawTriangle(handle, &r, base, pr, MwNORTH); + + pr = (handle->pressed && e->mouse.x >= (w - e->right) && e->mouse.y >= (h / 2)) ? 1 : 0; + r.x = w - e->right; + r.y = h / 2; + r.width = e->right; + r.height = h / 2; + MwDrawFrame(handle, &r, base, pr); + MwDrawRect(handle, &r, base); + + if(r.width > r.height) { + r.width = r.height; + } else { + r.height = r.width; + } + r.x = r.x + (e->right - r.width) / 2; + r.y = r.y + (h / 2 - r.height) / 2; + MwDrawTriangle(handle, &r, base, pr, MwSOUTH); + + MwLLFreeColor(base); } static void key(MwWidget handle, int code) { @@ -40,17 +85,54 @@ static void key(MwWidget handle, int code) { if(ok) MwEntryClass->key(handle, code); } +static void mouse_move(MwWidget handle) { + MwEntry e = handle->internal; + int w = MwGetInteger(handle, MwNwidth); + if(handle->mouse_point.x >= (w - e->right)) { + MwLLSetCursor(handle->lowlevel, &MwCursorDefault, &MwCursorDefaultMask); + } else { + MwLLSetCursor(handle->lowlevel, &MwCursorText, &MwCursorTextMask); + } +} + +static void mouse_up(MwWidget handle) { + MwEntry e = handle->internal; + int w = MwGetInteger(handle, MwNwidth); + int h = MwGetInteger(handle, MwNheight); + const char* str = MwGetText(handle, MwNtext); + + if(e->mouse.x >= (w - e->right)) { + char s[512]; + if(e->mouse.y >= (h / 2)) { + sprintf(s, "%g", atof(str) - 1); + } else { + sprintf(s, "%g", atof(str) + 1); + } + MwSetText(handle, MwNtext, s); + } + + MwForceRender(handle); +} + +static void mouse_down(MwWidget handle) { + MwEntry e = handle->internal; + + e->mouse = handle->mouse_point; + + MwForceRender(handle); +} + MwClassRec MwNumberEntryClassRec = { - 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 */ + mouse_move, /* mouse_move */ + mouse_up, /* mouse_up */ + mouse_down, /* mouse_down */ + key, /* key */ NULL, NULL, NULL,