summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 563dffa)
raw | patch | inline | side by side (parent: 563dffa)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Wed, 22 Apr 2020 11:20:29 +0000 (15:20 +0400) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Wed, 22 Apr 2020 11:20:29 +0000 (15:20 +0400) |
src/gl/render.c | patch | blob | history | |
src/menu.c | patch | blob | history | |
src/soft/render.c | patch | blob | history |
diff --git a/src/gl/render.c b/src/gl/render.c
index c4da0dc3844e8644cb14ecdadf740ca49d989e9d..0dc1ac30144082ebe1a292f9bf0e419cfd42fe25 100644 (file)
--- a/src/gl/render.c
+++ b/src/gl/render.c
int type = 0;
menu_msg_t msg;
msg.type = GM_GETENTRY;
- assert(GM_send(m, i, &msg));
- type = msg.integer.i;
- switch (type) {
- case GM_BUTTON:
- case GM_SCROLLER:
- case GM_TEXTFIELD:
- case GM_TEXTFIELD_BUTTON:
- msg.type = GM_GETCAPTION;
- if (GM_send(m, i, &msg)) {
- x = Z_get_big_string_width("%.*s", msg.string.maxlen, msg.string.s);
- }
- break;
- case GM_SMALL_BUTTON:
- msg.type = GM_GETCAPTION;
- if (GM_send(m, i, &msg)) {
- x = Z_get_small_string_width("%.*s", msg.string.maxlen, msg.string.s);
- }
- break;
- default:
- assert(0);
- }
- switch (type) {
- case GM_BUTTON:
- msg.type = GM_GETSTR;
- if (GM_send(m, i, &msg)) {
- x += Z_get_big_string_width("%.*s", msg.string.maxlen, msg.string.s);
- }
- y = 16;
- break;
- case GM_SMALL_BUTTON:
- msg.type = GM_GETSTR;
- if (GM_send(m, i, &msg)) {
- x += Z_get_big_string_width("%.*s", msg.string.maxlen, msg.string.s);
- }
- y = 12;
- break;
- case GM_SCROLLER:
- x += (SCROLLER_MIDDLE + 2) * 8;
- y = 16;
- break;
- case GM_TEXTFIELD:
- case GM_TEXTFIELD_BUTTON:
- msg.type = GM_GETSTR;
- if (GM_send(m, i, &msg)) {
- x += (msg.string.maxlen + 2) * 8;
- } else {
- x += (TEXTFIELD_MIDDLE + 2) * 8;
- }
- y = 16;
- break;
- default:
- assert(0);
+ if (GM_send(m, i, &msg)) {
+ type = msg.integer.i;
+ switch (type) {
+ case GM_BUTTON:
+ case GM_SCROLLER:
+ case GM_TEXTFIELD:
+ case GM_TEXTFIELD_BUTTON:
+ msg.type = GM_GETCAPTION;
+ if (GM_send(m, i, &msg)) {
+ x = Z_get_big_string_width("%.*s", msg.string.maxlen, msg.string.s);
+ }
+ break;
+ case GM_SMALL_BUTTON:
+ msg.type = GM_GETCAPTION;
+ if (GM_send(m, i, &msg)) {
+ x = Z_get_small_string_width("%.*s", msg.string.maxlen, msg.string.s);
+ }
+ break;
+ default:
+ assert(0);
+ }
+ switch (type) {
+ case GM_BUTTON:
+ msg.type = GM_GETSTR;
+ if (GM_send(m, i, &msg)) {
+ x += Z_get_big_string_width("%.*s", msg.string.maxlen, msg.string.s);
+ }
+ y = 16;
+ break;
+ case GM_SMALL_BUTTON:
+ msg.type = GM_GETSTR;
+ if (GM_send(m, i, &msg)) {
+ x += Z_get_big_string_width("%.*s", msg.string.maxlen, msg.string.s);
+ }
+ y = 12;
+ break;
+ case GM_SCROLLER:
+ x += (SCROLLER_MIDDLE + 2) * 8;
+ y = 16;
+ break;
+ case GM_TEXTFIELD:
+ case GM_TEXTFIELD_BUTTON:
+ msg.type = GM_GETSTR;
+ if (GM_send(m, i, &msg)) {
+ x += (msg.string.maxlen + 2) * 8;
+ } else {
+ x += (TEXTFIELD_MIDDLE + 2) * 8;
+ }
+ y = 16;
+ break;
+ default:
+ assert(0);
+ }
}
*w = x;
*h = y;
diff --git a/src/menu.c b/src/menu.c
index 4205285ea1f5436574805f05ad61325c19694784..639fed9cfddeed963cc9862a5316f4d59c1ca989 100644 (file)
--- a/src/menu.c
+++ b/src/menu.c
static int main_menu_handler (menu_msg_t *msg, const menu_t *m, void *data, int i) {
static int cur;
enum { NEWGAME, OLDGAME, SAVEGAME, OPTIONS, EXIT, __NUM__ };
+ assert(i >= 0 && i < __NUM__);
static const simple_menu_t sm = {
GM_BIG, "Menu", NULL,
{
int GM_act (void) {
menu_msg_t msg;
int n, cur, type;
- const menu_t *m = GM_get ();
+ const menu_t *m = GM_get();
if (m == NULL) {
if (lastkey == KEY_ESCAPE || (state_for_anykey(g_st) && lastkey != KEY_UNKNOWN)) {
GM_push(&main_menu);
}
} else {
msg.type = GM_QUERY;
- assert(GM_send_this(m, &msg));
- cur = msg.integer.i;
- n = msg.integer.a;
- msg.type = GM_GETENTRY;
- assert(GM_send(m, cur, &msg));
- type = msg.integer.i;
- switch (lastkey) {
- case KEY_ESCAPE:
- if (type == GM_TEXTFIELD && input) {
- input = 0;
- Y_disable_text_input();
- msg.type = GM_CANCEL;
- GM_send(m, cur, &msg);
- } else {
- GM_pop();
- Z_sound(msnd4, 128);
- }
- break;
- case KEY_UP:
- case KEY_DOWN:
- msg.type = lastkey == KEY_UP ? GM_UP : GM_DOWN;
- if (GM_send(m, cur, &msg)) {
- Z_sound(msnd1, 128);
- }
- break;
- case KEY_LEFT:
- case KEY_RIGHT:
- if (type == GM_SCROLLER) {
- msg.integer.type = GM_GETINT;
- if (GM_send(m, cur, &msg)) {
- msg.integer.type = GM_SETINT;
- msg.integer.i += lastkey == KEY_LEFT ? -msg.integer.s : msg.integer.s;
- msg.integer.i = min(max(msg.integer.i, msg.integer.a), msg.integer.b);
- if (GM_send(m, cur, &msg)) {
- Z_sound(lastkey == KEY_LEFT ? msnd5 : msnd6, 255);
+ if (GM_send_this(m, &msg)) {
+ cur = msg.integer.i;
+ n = msg.integer.a;
+ msg.type = GM_GETENTRY;
+ if (GM_send(m, cur, &msg)) {
+ type = msg.integer.i;
+ switch (lastkey) {
+ case KEY_ESCAPE:
+ if (type == GM_TEXTFIELD && input) {
+ input = 0;
+ Y_disable_text_input();
+ msg.type = GM_CANCEL;
+ GM_send(m, cur, &msg);
+ } else {
+ GM_pop();
+ Z_sound(msnd4, 128);
}
- }
- } else if (type == GM_TEXTFIELD) {
- //if (input) {
- // icur += lastkey == KEY_LEFT ? -1 : +1;
- // icur = min(max(icur, 0), strnlen(ibuf, imax));
- //}
- }
- break;
- case KEY_BACKSPACE:
- if (type == GM_TEXTFIELD) {
- if (input && icur > 0) {
- // FIXIT buffers in strncpy must not overlap
- strncpy(&ibuf[icur - 1], &ibuf[icur], imax - icur);
- ibuf[imax - 1] = 0;
- icur -= 1;
- }
- }
- break;
- case KEY_RETURN:
- if (type == GM_TEXTFIELD) {
- if (input) {
- input = 0;
- Y_disable_text_input();
- msg.type = GM_END;
- msg.string.s = ibuf;
- msg.string.maxlen = imax;
- GM_send(m, cur, &msg);
- } else {
- msg.type = GM_GETSTR;
- if (GM_send(m, cur, &msg)) {
- imax = min(msg.string.maxlen, GM_MAX_INPUT);
- strncpy(ibuf, msg.string.s, imax);
- icur = strnlen(ibuf, imax);
+ break;
+ case KEY_UP:
+ case KEY_DOWN:
+ if (input == 0) {
+ msg.type = lastkey == KEY_UP ? GM_UP : GM_DOWN;
+ if (GM_send(m, cur, &msg)) {
+ Z_sound(msnd1, 128);
+ }
+ }
+ break;
+ case KEY_LEFT:
+ case KEY_RIGHT:
+ if (type == GM_SCROLLER) {
+ msg.integer.type = GM_GETINT;
+ if (GM_send(m, cur, &msg)) {
+ msg.integer.type = GM_SETINT;
+ msg.integer.i += lastkey == KEY_LEFT ? -msg.integer.s : msg.integer.s;
+ msg.integer.i = min(max(msg.integer.i, msg.integer.a), msg.integer.b);
+ if (GM_send(m, cur, &msg)) {
+ Z_sound(lastkey == KEY_LEFT ? msnd5 : msnd6, 255);
+ }
+ }
+ } else if (type == GM_TEXTFIELD) {
+ //if (input) {
+ // icur += lastkey == KEY_LEFT ? -1 : +1;
+ // icur = min(max(icur, 0), strnlen(ibuf, imax));
+ //}
+ }
+ break;
+ case KEY_BACKSPACE:
+ if (type == GM_TEXTFIELD) {
+ if (input && icur > 0) {
+ // FIXIT buffers in strncpy must not overlap
+ strncpy(&ibuf[icur - 1], &ibuf[icur], imax - icur);
+ ibuf[imax - 1] = 0;
+ icur -= 1;
+ }
+ }
+ break;
+ case KEY_RETURN:
+ if (type == GM_TEXTFIELD) {
+ if (input) {
+ input = 0;
+ Y_disable_text_input();
+ msg.type = GM_END;
+ msg.string.s = ibuf;
+ msg.string.maxlen = imax;
+ GM_send(m, cur, &msg);
+ } else {
+ msg.type = GM_GETSTR;
+ if (GM_send(m, cur, &msg)) {
+ imax = min(msg.string.maxlen, GM_MAX_INPUT);
+ strncpy(ibuf, msg.string.s, imax);
+ icur = strnlen(ibuf, imax);
+ } else {
+ memset(ibuf, 0, GM_MAX_INPUT);
+ imax = GM_MAX_INPUT;
+ icur = 0;
+ }
+ input = 1;
+ Y_enable_text_input();
+ msg.type = GM_BEGIN;
+ GM_send(m, cur, &msg);
+ }
+ Z_sound(msnd2, 128);
} else {
- memset(ibuf, 0, GM_MAX_INPUT);
- imax = GM_MAX_INPUT;
- icur = 0;
+ msg.type = GM_SELECT;
+ if (cur < 0) abort();
+ if (GM_send(m, cur, &msg)) {
+ Z_sound(msnd2, 128);
+ }
}
- input = 1;
- Y_enable_text_input();
- msg.type = GM_BEGIN;
- GM_send(m, cur, &msg);
- }
- Z_sound(msnd2, 128);
- } else {
- msg.type = GM_SELECT;
- if (GM_send(m, cur, &msg)) {
- Z_sound(msnd2, 128);
- }
+ break;
}
- break;
+ }
}
}
lastkey = KEY_UNKNOWN;
diff --git a/src/soft/render.c b/src/soft/render.c
index 25c387226367fae0404daf53cd2c05876549e5be..705de17f30725cecf1d45697c402b164ef706e6a 100644 (file)
--- a/src/soft/render.c
+++ b/src/soft/render.c
int type = 0;
menu_msg_t msg;
msg.type = GM_GETENTRY;
- assert(GM_send(m, i, &msg));
- type = msg.integer.i;
- switch (type) {
- case GM_BUTTON:
- case GM_SCROLLER:
- case GM_TEXTFIELD:
- case GM_TEXTFIELD_BUTTON:
- msg.type = GM_GETCAPTION;
- if (GM_send(m, i, &msg)) {
- x = Z_get_big_string_width("%.*s", msg.string.maxlen, msg.string.s);
- }
- break;
- case GM_SMALL_BUTTON:
- msg.type = GM_GETCAPTION;
- if (GM_send(m, i, &msg)) {
- x = Z_get_small_string_width("%.*s", msg.string.maxlen, msg.string.s);
- }
- break;
- default:
- assert(0);
- }
- switch (type) {
- case GM_BUTTON:
- msg.type = GM_GETSTR;
- if (GM_send(m, i, &msg)) {
- x += Z_get_big_string_width("%.*s", msg.string.maxlen, msg.string.s);
- }
- y = 16;
- break;
- case GM_SMALL_BUTTON:
- msg.type = GM_GETSTR;
- if (GM_send(m, i, &msg)) {
- x += Z_get_big_string_width("%.*s", msg.string.maxlen, msg.string.s);
- }
- y = 12;
- break;
- case GM_SCROLLER:
- x += (SCROLLER_MIDDLE + 2) * 8;
- y = 16;
- break;
- case GM_TEXTFIELD:
- case GM_TEXTFIELD_BUTTON:
- msg.type = GM_GETSTR;
- if (GM_send(m, i, &msg)) {
- x += (msg.string.maxlen + 2) * 8;
- } else {
- x += (TEXTFIELD_MIDDLE + 2) * 8;
- }
- y = 16;
- break;
- default:
- assert(0);
+ if (GM_send(m, i, &msg)) {
+ type = msg.integer.i;
+ switch (type) {
+ case GM_BUTTON:
+ case GM_SCROLLER:
+ case GM_TEXTFIELD:
+ case GM_TEXTFIELD_BUTTON:
+ msg.type = GM_GETCAPTION;
+ if (GM_send(m, i, &msg)) {
+ x = Z_get_big_string_width("%.*s", msg.string.maxlen, msg.string.s);
+ }
+ break;
+ case GM_SMALL_BUTTON:
+ msg.type = GM_GETCAPTION;
+ if (GM_send(m, i, &msg)) {
+ x = Z_get_small_string_width("%.*s", msg.string.maxlen, msg.string.s);
+ }
+ break;
+ default:
+ assert(0);
+ }
+ switch (type) {
+ case GM_BUTTON:
+ msg.type = GM_GETSTR;
+ if (GM_send(m, i, &msg)) {
+ x += Z_get_big_string_width("%.*s", msg.string.maxlen, msg.string.s);
+ }
+ y = 16;
+ break;
+ case GM_SMALL_BUTTON:
+ msg.type = GM_GETSTR;
+ if (GM_send(m, i, &msg)) {
+ x += Z_get_big_string_width("%.*s", msg.string.maxlen, msg.string.s);
+ }
+ y = 12;
+ break;
+ case GM_SCROLLER:
+ x += (SCROLLER_MIDDLE + 2) * 8;
+ y = 16;
+ break;
+ case GM_TEXTFIELD:
+ case GM_TEXTFIELD_BUTTON:
+ msg.type = GM_GETSTR;
+ if (GM_send(m, i, &msg)) {
+ x += (msg.string.maxlen + 2) * 8;
+ } else {
+ x += (TEXTFIELD_MIDDLE + 2) * 8;
+ }
+ y = 16;
+ break;
+ default:
+ assert(0);
+ }
}
*w = x;
*h = y;