mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2026-01-07 18:09:44 +00:00
wip
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@233 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
@@ -36,6 +36,10 @@ typedef void* MwLLPixmap;
|
|||||||
#define MwLLDispatch(x, y, z) \
|
#define MwLLDispatch(x, y, z) \
|
||||||
if(x->handler != NULL && x->handler->y != NULL) x->handler->y(x, z)
|
if(x->handler != NULL && x->handler->y != NULL) x->handler->y(x, z)
|
||||||
|
|
||||||
|
enum MwLLKey {
|
||||||
|
MwLLKeyBackSpace = (1 << 31) | 1
|
||||||
|
};
|
||||||
|
|
||||||
struct _MwLLHandler {
|
struct _MwLLHandler {
|
||||||
void (*draw)(MwLL handle, void* data);
|
void (*draw)(MwLL handle, void* data);
|
||||||
void (*up)(MwLL handle, void* data);
|
void (*up)(MwLL handle, void* data);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
/*!
|
/*!
|
||||||
* %file Mw/Widget/Text.h
|
* %file Mw/Widget/Text.h
|
||||||
* %brief Text widget
|
* %brief Text widget
|
||||||
* %prop MwNchecked
|
* %prop MwNtext
|
||||||
*/
|
*/
|
||||||
#ifndef __MW_WIDGET_TEXT_H__
|
#ifndef __MW_WIDGET_TEXT_H__
|
||||||
#define __MW_WIDGET_TEXT_H__
|
#define __MW_WIDGET_TEXT_H__
|
||||||
|
|||||||
@@ -182,9 +182,12 @@ void MwLLNextEvent(MwLL handle) {
|
|||||||
|
|
||||||
MwLLDispatch(handle, move, &p);
|
MwLLDispatch(handle, move, &p);
|
||||||
} else if(ev.type == KeyPress) {
|
} else if(ev.type == KeyPress) {
|
||||||
int n;
|
int n = -1;
|
||||||
KeySym sym = XLookupKeysym(&ev.xkey, 0);
|
KeySym sym = XLookupKeysym(&ev.xkey, 0);
|
||||||
char* str = XKeysymToString(sym);
|
char* str = XKeysymToString(sym);
|
||||||
|
|
||||||
|
if(strcmp(str, "space") == 0) str = " ";
|
||||||
|
|
||||||
/* 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 == NULL ? 0 : str[0];
|
char s = str == NULL ? 0 : str[0];
|
||||||
@@ -194,9 +197,11 @@ void MwLLNextEvent(MwLL handle) {
|
|||||||
} else {
|
} else {
|
||||||
n = s;
|
n = s;
|
||||||
}
|
}
|
||||||
|
} else if(strcmp(str, "BackSpace") == 0) {
|
||||||
MwLLDispatch(handle, key, &n);
|
n = MwLLKeyBackSpace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(n != -1) MwLLDispatch(handle, key, &n);
|
||||||
}
|
}
|
||||||
if(render) {
|
if(render) {
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ static void destroy(MwWidget handle) {
|
|||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
r.x = p.x - 5; \
|
r.x = p.x - 5; \
|
||||||
r.y = p.y - 5; \
|
r.y = p.y - th / 2 - 5; \
|
||||||
r.width = tw + 10; \
|
r.width = tw + 10; \
|
||||||
r.height = th + 10; \
|
r.height = th + 10; \
|
||||||
\
|
\
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ static int create(MwWidget handle) {
|
|||||||
static void draw(MwWidget handle) {
|
static void draw(MwWidget handle) {
|
||||||
MwRect r;
|
MwRect r;
|
||||||
MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground));
|
MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground));
|
||||||
|
MwLLColor text = MwParseColor(handle, MwGetText(handle, MwNforeground));
|
||||||
|
const char* str = MwGetText(handle, MwNtext);
|
||||||
|
|
||||||
r.x = 0;
|
r.x = 0;
|
||||||
r.y = 0;
|
r.y = 0;
|
||||||
@@ -20,12 +22,53 @@ static void draw(MwWidget handle) {
|
|||||||
|
|
||||||
MwDrawFrame(handle, &r, base, (handle->pressed || MwGetInteger(handle, MwNchecked)) ? 1 : 0);
|
MwDrawFrame(handle, &r, base, (handle->pressed || MwGetInteger(handle, MwNchecked)) ? 1 : 0);
|
||||||
MwDrawRect(handle, &r, base);
|
MwDrawRect(handle, &r, base);
|
||||||
|
if(str != NULL) {
|
||||||
|
int h = MwTextHeight(handle, "M");
|
||||||
|
MwPoint p;
|
||||||
|
|
||||||
|
p.x = (r.height - h) / 2;
|
||||||
|
p.y = r.height / 2;
|
||||||
|
|
||||||
|
/* limit so there isn't a crazy padding */
|
||||||
|
if(p.x > 4) p.x = 4;
|
||||||
|
|
||||||
|
MwDrawText(handle, &p, str, 0, MwALIGNMENT_BEGINNING, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
MwLLFreeColor(text);
|
||||||
MwLLFreeColor(base);
|
MwLLFreeColor(base);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void key(MwWidget handle, int code) {
|
static void key(MwWidget handle, int code) {
|
||||||
printf("%c\n", code);
|
const char* str = MwGetText(handle, MwNtext);
|
||||||
|
char* out;
|
||||||
|
char buf[2];
|
||||||
|
if(str == NULL) str = "";
|
||||||
|
|
||||||
|
if(code == MwLLKeyBackSpace) {
|
||||||
|
if(strlen(str) == 0) return;
|
||||||
|
out = malloc(strlen(str) + 1);
|
||||||
|
|
||||||
|
strcpy(out, str);
|
||||||
|
out[strlen(out) - 1] = 0;
|
||||||
|
|
||||||
|
MwSetText(handle, MwNtext, out);
|
||||||
|
|
||||||
|
free(out);
|
||||||
|
} else {
|
||||||
|
buf[0] = code;
|
||||||
|
buf[1] = 0;
|
||||||
|
|
||||||
|
out = malloc(strlen(str) + 1 + 1);
|
||||||
|
strcpy(out, str);
|
||||||
|
strcat(out, buf);
|
||||||
|
|
||||||
|
MwSetText(handle, MwNtext, out);
|
||||||
|
|
||||||
|
free(out);
|
||||||
|
}
|
||||||
|
|
||||||
|
MwForceRender(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
MwClassRec MwTextClassRec = {
|
MwClassRec MwTextClassRec = {
|
||||||
|
|||||||
Reference in New Issue
Block a user