#include "keraforge/graphics.h" #include #include struct kf_uiconfig kf_uiconfig = { .select = KF_INPUTBIND_NONE, .cancel = KF_INPUTBIND_NONE, .up = KF_INPUTBIND_NONE, .down = KF_INPUTBIND_NONE, .fmt = " %s ", .selectfmt = "> %s <", .fontsize = 20, .bg = BLACK, .fg = WHITE, .panelheight = 200, .xpadding = 8, .ypadding = 16, }; void kf_ui_init(void) { kf_uiconfig.select = kf_inputbind_select; kf_uiconfig.cancel = kf_inputbind_cancel; kf_uiconfig.up = kf_inputbind_ui_up; kf_uiconfig.down = kf_inputbind_ui_down; kf_uiconfig.fontsize = kf_window.fontsize; } int kf_ui_panel(char *title) { int y = GetScreenHeight() - kf_uiconfig.panelheight; DrawRectangle(0, y, GetScreenWidth(), kf_uiconfig.panelheight, kf_uiconfig.bg); if (title) { y += kf_uiconfig.ypadding; kf_drawtextshadowed(kf_uiconfig.fg, kf_uiconfig.xpadding, y, kf_uiconfig.fontsize, title); y += kf_uiconfig.fontsize; } return y; } int kf_ui_choice(char *title, char **choices, int nchoices, int *choice) { int y = kf_ui_panel(title); if (*choice >= nchoices) goto skip_text; for (int i = 0 ; i < nchoices ; i++) { char *c = choices[i]; kf_drawtextshadowed( kf_uiconfig.fg, kf_uiconfig.xpadding, y, kf_uiconfig.fontsize, (char *)TextFormat(i == *choice ? kf_uiconfig.selectfmt : kf_uiconfig.fmt, c) ); y += kf_uiconfig.fontsize; if (y >= GetScreenHeight()) break; } skip_text: if (kf_checkinputpress(kf_uiconfig.select) || kf_checkinputpress(kf_uiconfig.cancel)) return 1; else if (kf_checkinputpress(kf_uiconfig.down) && *choice < nchoices - 1) (*choice)++; else if (kf_checkinputpress(kf_uiconfig.up) && *choice > 0) (*choice)--; return 0; } int kf_ui_yesno(char *title, int *choice) { static char *yesno[] = { "yes", "no" }; return !kf_ui_choice(title, yesno, 2, choice); } int kf_ui_textinput(char *title, char *text);