mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2026-01-08 18:33:30 +00:00
number entry seems to work
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@254 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
@@ -102,8 +102,9 @@ struct _MwMenu {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct _MwEntry {
|
struct _MwEntry {
|
||||||
int cursor;
|
int cursor;
|
||||||
int right;
|
int right;
|
||||||
|
MwPoint mouse;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MwCursorDataHeight 16
|
#define MwCursorDataHeight 16
|
||||||
|
|||||||
@@ -209,6 +209,13 @@ void MwLLNextEvent(MwLL handle) {
|
|||||||
|
|
||||||
XLookupString(&ev.xkey, str, 512, &sym, NULL);
|
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 */
|
/* HACK: this is bad, you can guess why */
|
||||||
if(strlen(str) == 1) {
|
if(strlen(str) == 1) {
|
||||||
char s = str[0];
|
char s = str[0];
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ static int create(MwWidget handle) {
|
|||||||
MwEntry t = malloc(sizeof(*t));
|
MwEntry t = malloc(sizeof(*t));
|
||||||
|
|
||||||
t->cursor = 0;
|
t->cursor = 0;
|
||||||
|
t->right = 0;
|
||||||
handle->internal = t;
|
handle->internal = t;
|
||||||
|
|
||||||
MwSetDefault(handle);
|
MwSetDefault(handle);
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ static int create(MwWidget handle) {
|
|||||||
e = handle->internal;
|
e = handle->internal;
|
||||||
e->right = 32;
|
e->right = 32;
|
||||||
|
|
||||||
|
MwSetText(handle, MwNtext, "0");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18,7 +20,50 @@ static void destroy(MwWidget handle) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void draw(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);
|
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) {
|
static void key(MwWidget handle, int code) {
|
||||||
@@ -40,17 +85,54 @@ static void key(MwWidget handle, int code) {
|
|||||||
if(ok) MwEntryClass->key(handle, 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 = {
|
MwClassRec MwNumberEntryClassRec = {
|
||||||
create, /* create */
|
create, /* create */
|
||||||
destroy, /* destroy */
|
destroy, /* destroy */
|
||||||
draw, /* draw */
|
draw, /* draw */
|
||||||
NULL, /* click */
|
NULL, /* click */
|
||||||
NULL, /* parent_resize */
|
NULL, /* parent_resize */
|
||||||
NULL, /* prop_change */
|
NULL, /* prop_change */
|
||||||
NULL, /* mouse_move */
|
mouse_move, /* mouse_move */
|
||||||
MwForceRender, /* mouse_up */
|
mouse_up, /* mouse_up */
|
||||||
MwForceRender, /* mouse_down */
|
mouse_down, /* mouse_down */
|
||||||
key, /* key */
|
key, /* key */
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
|
|||||||
Reference in New Issue
Block a user