mirror of
https://github.com/kichikuou/xsystem35-sdl2.git
synced 2026-09-22 22:48:08 +03:00
Implement text input
This commit is contained in:
@@ -15773,7 +15773,9 @@ else
|
||||
fi
|
||||
|
||||
SRC_MENU=
|
||||
if test "x$have_gtk" = xyes ; then
|
||||
if test "x$is_emscripten" = xyes; then
|
||||
SRC_MENU="menu_emscripten.c"
|
||||
elif test "x$have_gtk" = xyes ; then
|
||||
SRC_MENU="menu.c menu_callback.c menu_gui.c s39init.c"
|
||||
else
|
||||
SRC_MENU="menu_null.c"
|
||||
|
||||
+3
-1
@@ -164,7 +164,9 @@ dnl fi
|
||||
|
||||
AM_CONDITIONAL(HAVE_GTK, test "x$have_gtk" = xyes)
|
||||
SRC_MENU=
|
||||
if test "x$have_gtk" = xyes ; then
|
||||
if test "x$is_emscripten" = xyes; then
|
||||
SRC_MENU="menu_emscripten.c"
|
||||
elif test "x$have_gtk" = xyes ; then
|
||||
SRC_MENU="menu.c menu_callback.c menu_gui.c s39init.c"
|
||||
else
|
||||
SRC_MENU="menu_null.c"
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* menu_emscripten.c menu implementation for Emscripten
|
||||
*
|
||||
* Copyright (C) 2017 <KichikuouChrome@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <emscripten.h>
|
||||
|
||||
#include "portab.h"
|
||||
#include "menu.h"
|
||||
|
||||
void menu_open(void) {
|
||||
return;
|
||||
}
|
||||
|
||||
void menu_quitmenu_open(void) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean menu_inputstring(INPUTSTRING_PARAM *p) {
|
||||
static char buf[256];
|
||||
int ok = EM_ASM_({
|
||||
var r = xsystem35.shell.inputString(UTF8ToString($0), UTF8ToString($1), $2);
|
||||
if (r) {
|
||||
stringToUTF8(r, $3, $4);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}, p->title, p->oldstring, p->max, buf, sizeof buf);
|
||||
if (ok)
|
||||
p->newstring = buf;
|
||||
else
|
||||
p->newstring = p->oldstring;
|
||||
return ok ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
boolean menu_inputstring2(INPUTSTRING_PARAM *p) {
|
||||
p->newstring = p->oldstring;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
boolean menu_inputnumber(INPUTNUM_PARAM *p) {
|
||||
p->value = p->def;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void menu_msgbox_open(char *msg) {
|
||||
return;
|
||||
}
|
||||
|
||||
void menu_init(void) {
|
||||
return;
|
||||
}
|
||||
|
||||
void menu_widget_reinit(boolean reset_colortmap) {
|
||||
return;
|
||||
}
|
||||
|
||||
void menu_gtkmainiteration() {
|
||||
return;
|
||||
}
|
||||
+48
-2
@@ -67,9 +67,55 @@ BYTE *sjis2utf(BYTE *src) {
|
||||
return dst;
|
||||
}
|
||||
|
||||
static int unicode_to_sjis(int u) {
|
||||
for (int b1 = 0x80; b1 <= 0xff; b1++) {
|
||||
if (b1 >= 0xa0 && b1 <= 0xdf)
|
||||
continue;
|
||||
for (int b2 = 0x40; b2 <= 0xff; b2++) {
|
||||
if (u == s2u[b1 - 0x80][b2 - 0x40])
|
||||
return b1 << 8 | b2;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
BYTE *utf2sjis(BYTE *src) {
|
||||
printf("%s not implemented\n", __func__);
|
||||
return strdup(src);
|
||||
BYTE* dst = malloc(strlen(src) + 1);
|
||||
BYTE* dstp = dst;
|
||||
|
||||
while (*src) {
|
||||
if (*src <= 0x7f) {
|
||||
*dstp++ = *src++;
|
||||
continue;
|
||||
}
|
||||
|
||||
int u;
|
||||
if (*src <= 0xdf) {
|
||||
u = (src[0] & 0x1f) << 6 | (src[1] & 0x3f);
|
||||
src += 2;
|
||||
} else if (*src <= 0xef) {
|
||||
u = (src[0] & 0xf) << 12 | (src[1] & 0x3f) << 6 | (src[2] & 0x3f);
|
||||
src += 3;
|
||||
} else {
|
||||
*dstp++ = '?';
|
||||
do src++; while ((*src & 0xc0) == 0x80);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (u > 0xff60 && u <= 0xff9f) {
|
||||
*dstp++ = u - 0xff60 + 0xa0;
|
||||
} else {
|
||||
int c = unicode_to_sjis(u);
|
||||
if (c) {
|
||||
*dstp++ = c >> 8;
|
||||
*dstp++ = c & 0xff;
|
||||
} else {
|
||||
*dstp++ = '?';
|
||||
}
|
||||
}
|
||||
}
|
||||
*dstp = '\0';
|
||||
return dst;
|
||||
}
|
||||
|
||||
/* src 内に半角カナもしくはASCII文字があるかどうか */
|
||||
|
||||
Reference in New Issue
Block a user