seems to work

git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@243 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-10-09 12:45:51 +00:00
parent 814e5ea011
commit 2cecb6c34a
5 changed files with 87 additions and 23 deletions

View File

@@ -360,7 +360,7 @@ void MwDrawTriangle(MwWidget handle, MwRect* rect, MwLLColor color, int invert,
}
void MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color) {
int i, x, y, sx, sy;
int i = 0, x, y, sx, sy;
MwRect r;
sx = point->x;
@@ -374,7 +374,7 @@ void MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, int
while(text[i] != 0) {
int out;
i += MwUTF8ToUTF32(text, &out);
i += MwUTF8ToUTF32(text + i, &out);
if(out >= 0x80) out = 0;

View File

@@ -75,14 +75,17 @@ int MwUTF8Length(const char* input) {
return len;
}
int MwUTF8Copy(const char* src, int srcskip, char* dst, int dstskip, int len){
int MwUTF8Copy(const char* src, int srcskip, char* dst, int dstskip, int len) {
int i;
int out;
int total = 0;
for(i = 0; i < srcskip; i++) src += MwUTF8ToUTF32(src, &out);
for(i = 0; i < dstskip; i++) dst += MwUTF8ToUTF32(dst, &out);
for(i = 0; i < len; i++){
int len = MwUTF8ToUTF32(src, &out);
for(i = 0; i < len; i++) {
int len;
if(src[0] == 0) break;
len = MwUTF8ToUTF32(src, &out);
memcpy(dst, src, len);
@@ -90,7 +93,7 @@ int MwUTF8Copy(const char* src, int srcskip, char* dst, int dstskip, int len){
dst += len;
total += len;
}
dst[total] = 0;
dst[0] = 0;
return total;
}

View File

@@ -13,7 +13,6 @@ static int create(MwWidget handle) {
MwSetDefault(handle);
MwSetText(handle, MwNtext, "こんにちは、世界 Hello, World");
MwLLSetCursor(handle->lowlevel, &MwCursorText, &MwCursorTextMask);
return 0;
@@ -53,14 +52,12 @@ static void draw(MwWidget handle) {
len = (r.width - p.x * 2) / w;
show = malloc(len + 1);
memset(show, 0, len + 1);
show = malloc(len * 4 + 1);
memset(show, 0, len * 4 + 1);
start = (t->cursor - 1) / len;
start *= len;
for(i = start; i < (int)strlen(str) && i < start + len; i++) {
show[i - start] = str[i];
}
MwUTF8Copy(str, start, show, 0, len);
MwDrawText(handle, &p, show, 0, MwALIGNMENT_BEGINNING, text);
@@ -88,18 +85,13 @@ static void key(MwWidget handle, int code) {
if(str == NULL) str = "";
if(code == MwLLKeyBackSpace) {
int i, incr = 0;
if(t->cursor == 0) return;
out = malloc(strlen(str) + 1);
t->cursor--;
for(i = 0; str[i] != 0; i++) {
if(i != t->cursor) {
out[incr++] = str[i];
}
}
out[incr++] = 0;
MwUTF8Copy(str, 0, out, 0, t->cursor);
MwUTF8Copy(str, t->cursor + 1, out, t->cursor, MwUTF8Length(str) - (t->cursor + 1));
MwSetText(handle, MwNtext, out);
@@ -108,11 +100,11 @@ static void key(MwWidget handle, int code) {
if(t->cursor == 0) return;
t->cursor--;
} else if(code == MwLLKeyRight) {
if(t->cursor == (int)strlen(str)) return;
if(t->cursor == MwUTF8Length(str)) return;
t->cursor++;
} else {
int incr = 0;
out = malloc(strlen(str) + 1 + 1);
out = malloc(strlen(str) + 1 + 1);
incr += MwUTF8Copy(str, 0, out, 0, t->cursor);
out[incr++] = code;
MwUTF8Copy(str, t->cursor, out, t->cursor + 1, MwUTF8Length(str) - t->cursor);