mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2026-01-03 16:10:50 +00:00
text seems functional
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@235 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
@@ -37,7 +37,9 @@ typedef void* MwLLPixmap;
|
|||||||
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 {
|
enum MwLLKey {
|
||||||
MwLLKeyBackSpace = (1 << 31) | 1
|
MwLLKeyBackSpace = (1 << 31) | 1,
|
||||||
|
MwLLKeyLeft,
|
||||||
|
MwLLKeyRight
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _MwLLHandler {
|
struct _MwLLHandler {
|
||||||
|
|||||||
@@ -199,6 +199,10 @@ void MwLLNextEvent(MwLL handle) {
|
|||||||
}
|
}
|
||||||
} else if(strcmp(str, "BackSpace") == 0) {
|
} else if(strcmp(str, "BackSpace") == 0) {
|
||||||
n = MwLLKeyBackSpace;
|
n = MwLLKeyBackSpace;
|
||||||
|
} else if(strcmp(str, "Left") == 0) {
|
||||||
|
n = MwLLKeyLeft;
|
||||||
|
} else if(strcmp(str, "Right") == 0) {
|
||||||
|
n = MwLLKeyRight;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(n != -1) MwLLDispatch(handle, key, &n);
|
if(n != -1) MwLLDispatch(handle, key, &n);
|
||||||
|
|||||||
@@ -1,17 +1,30 @@
|
|||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
#include <Mw/Milsko.h>
|
#include <Mw/Milsko.h>
|
||||||
|
|
||||||
|
typedef struct text {
|
||||||
|
int cursor;
|
||||||
|
} text_t;
|
||||||
|
|
||||||
static int create(MwWidget handle) {
|
static int create(MwWidget handle) {
|
||||||
|
text_t* t = malloc(sizeof(*t));
|
||||||
|
|
||||||
|
t->cursor = 0;
|
||||||
|
handle->internal = t;
|
||||||
|
|
||||||
MwSetDefault(handle);
|
MwSetDefault(handle);
|
||||||
|
|
||||||
MwSetText(handle, MwNtext, "dkdqdnqwjkneqwewkeqkenkqwenneqweknqwenqwjkenqwkenqwkenkqwenkqwnejkqwenkwqnekqwneknqwkw");
|
|
||||||
MwLLSetCursor(handle->lowlevel, &MwCursorText, &MwCursorTextMask);
|
MwLLSetCursor(handle->lowlevel, &MwCursorText, &MwCursorTextMask);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void destroy(MwWidget handle) {
|
||||||
|
free(handle->internal);
|
||||||
|
}
|
||||||
|
|
||||||
static void draw(MwWidget handle) {
|
static void draw(MwWidget handle) {
|
||||||
MwRect r;
|
MwRect r;
|
||||||
|
text_t* t = handle->internal;
|
||||||
MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground));
|
MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground));
|
||||||
MwLLColor text = MwParseColor(handle, MwGetText(handle, MwNforeground));
|
MwLLColor text = MwParseColor(handle, MwGetText(handle, MwNforeground));
|
||||||
const char* str = MwGetText(handle, MwNtext);
|
const char* str = MwGetText(handle, MwNtext);
|
||||||
@@ -30,23 +43,36 @@ static void draw(MwWidget handle) {
|
|||||||
char* show;
|
char* show;
|
||||||
int len;
|
int len;
|
||||||
int i;
|
int i;
|
||||||
|
int start;
|
||||||
|
int textlen;
|
||||||
|
MwRect currc;
|
||||||
|
|
||||||
p.x = (r.height - h) / 2;
|
p.x = (r.width - (r.width / w * w)) / 2;
|
||||||
p.y = r.height / 2;
|
p.y = r.height / 2;
|
||||||
|
|
||||||
/* limit so there isn't a crazy padding */
|
|
||||||
if(p.x > 4) p.x = 4;
|
|
||||||
|
|
||||||
len = (r.width - p.x * 2) / w;
|
len = (r.width - p.x * 2) / w;
|
||||||
|
|
||||||
show = malloc(len + 1);
|
show = malloc(len + 1);
|
||||||
memset(show, 0, len + 1);
|
memset(show, 0, len + 1);
|
||||||
|
|
||||||
for(i = 0; i < len; i++) {
|
start = (t->cursor - 1) / len;
|
||||||
show[i] = str[i];
|
start *= len;
|
||||||
|
for(i = start; i < (int)strlen(str) && i < start + len; i++) {
|
||||||
|
show[i - start] = str[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
MwDrawText(handle, &p, show, 0, MwALIGNMENT_BEGINNING, text);
|
MwDrawText(handle, &p, show, 0, MwALIGNMENT_BEGINNING, text);
|
||||||
|
|
||||||
|
textlen = (t->cursor - 1) % len + 1;
|
||||||
|
for(i = 0; i < textlen; i++) show[i] = 'M';
|
||||||
|
show[i] = 0;
|
||||||
|
|
||||||
|
currc.x = p.x + MwTextWidth(handle, show);
|
||||||
|
currc.y = (r.height - h) / 2;
|
||||||
|
currc.width = 1;
|
||||||
|
currc.height = h;
|
||||||
|
MwDrawRect(handle, &currc, text);
|
||||||
|
|
||||||
free(show);
|
free(show);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,28 +81,43 @@ static void draw(MwWidget handle) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void key(MwWidget handle, int code) {
|
static void key(MwWidget handle, int code) {
|
||||||
|
text_t* t = handle->internal;
|
||||||
const char* str = MwGetText(handle, MwNtext);
|
const char* str = MwGetText(handle, MwNtext);
|
||||||
char* out;
|
char* out;
|
||||||
char buf[2];
|
|
||||||
if(str == NULL) str = "";
|
if(str == NULL) str = "";
|
||||||
|
|
||||||
if(code == MwLLKeyBackSpace) {
|
if(code == MwLLKeyBackSpace) {
|
||||||
if(strlen(str) == 0) return;
|
int i, incr = 0;
|
||||||
|
if(t->cursor == 0) return;
|
||||||
out = malloc(strlen(str) + 1);
|
out = malloc(strlen(str) + 1);
|
||||||
|
|
||||||
strcpy(out, str);
|
t->cursor--;
|
||||||
out[strlen(out) - 1] = 0;
|
|
||||||
|
for(i = 0; str[i] != 0; i++) {
|
||||||
|
if(i != t->cursor) {
|
||||||
|
out[incr++] = str[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out[incr++] = 0;
|
||||||
|
|
||||||
MwSetText(handle, MwNtext, out);
|
MwSetText(handle, MwNtext, out);
|
||||||
|
|
||||||
free(out);
|
free(out);
|
||||||
|
} else if(code == MwLLKeyLeft) {
|
||||||
|
if(t->cursor == 0) return;
|
||||||
|
t->cursor--;
|
||||||
|
} else if(code == MwLLKeyRight) {
|
||||||
|
if(t->cursor == (int)strlen(str)) return;
|
||||||
|
t->cursor++;
|
||||||
} else {
|
} else {
|
||||||
buf[0] = code;
|
int i, incr = 0;
|
||||||
buf[1] = 0;
|
|
||||||
|
|
||||||
out = malloc(strlen(str) + 1 + 1);
|
out = malloc(strlen(str) + 1 + 1);
|
||||||
strcpy(out, str);
|
for(i = 0; i < t->cursor; i++) out[incr++] = str[i];
|
||||||
strcat(out, buf);
|
out[incr++] = code;
|
||||||
|
for(i = t->cursor; i < (int)strlen(str); i++) out[incr++] = str[i];
|
||||||
|
out[incr++] = 0;
|
||||||
|
|
||||||
|
t->cursor++;
|
||||||
|
|
||||||
MwSetText(handle, MwNtext, out);
|
MwSetText(handle, MwNtext, out);
|
||||||
|
|
||||||
@@ -88,7 +129,7 @@ static void key(MwWidget handle, int code) {
|
|||||||
|
|
||||||
MwClassRec MwTextClassRec = {
|
MwClassRec MwTextClassRec = {
|
||||||
create, /* create */
|
create, /* create */
|
||||||
NULL, /* destroy */
|
destroy, /* destroy */
|
||||||
draw, /* draw */
|
draw, /* draw */
|
||||||
NULL, /* click */
|
NULL, /* click */
|
||||||
NULL, /* parent_resize */
|
NULL, /* parent_resize */
|
||||||
|
|||||||
Reference in New Issue
Block a user