Change how active option is rendered
This commit is contained in:
parent
4aae6927e3
commit
00066f225b
32
ui.c
32
ui.c
|
@ -136,57 +136,53 @@ int uiRun(UIContext *ui, bool running) {
|
||||||
if (windowGuiBegin(&ui->win, "Shrooms VB")) {
|
if (windowGuiBegin(&ui->win, "Shrooms VB")) {
|
||||||
windowMenubarBegin(&ui->win, MENU_ITEMS);
|
windowMenubarBegin(&ui->win, MENU_ITEMS);
|
||||||
|
|
||||||
if (nk_menu_begin_label(ctx, "File", NK_TEXT_ALIGN_CENTERED, nk_vec2(windowScaleX(&ui->win, 100), windowGetScreenHeight(&ui->win)))) {
|
if (windowMenuBegin(&ui->win, "File", 100)) {
|
||||||
nk_layout_row_dynamic(ctx, windowGetMenuHeight(&ui->win), 1);
|
if (windowMenuItemLabel(&ui->win, "Open ROM")) {
|
||||||
if (nk_menu_item_label(ctx, "Open ROM", NK_TEXT_ALIGN_LEFT)) {
|
|
||||||
char *file = tinyfd_openFileDialog("Pick a ROM", NULL, 1, ROM_EXTENSIONS, "Virtual Boy ROM files", false);
|
char *file = tinyfd_openFileDialog("Pick a ROM", NULL, 1, ROM_EXTENSIONS, "Virtual Boy ROM files", false);
|
||||||
if (file) {
|
if (file) {
|
||||||
uiLoadGame(ui, file);
|
uiLoadGame(ui, file);
|
||||||
status = status_running;
|
status = status_running;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (nk_menu_item_label(ctx, "Quit", NK_TEXT_ALIGN_LEFT)) {
|
if (windowMenuItemLabel(&ui->win, "Quit")) {
|
||||||
SDL_Event QuitEvent;
|
SDL_Event QuitEvent;
|
||||||
QuitEvent.type = SDL_QUIT;
|
QuitEvent.type = SDL_QUIT;
|
||||||
QuitEvent.quit.timestamp = SDL_GetTicks();
|
QuitEvent.quit.timestamp = SDL_GetTicks();
|
||||||
SDL_PushEvent(&QuitEvent);
|
SDL_PushEvent(&QuitEvent);
|
||||||
}
|
}
|
||||||
nk_menu_end(ctx);
|
windowMenuEnd(&ui->win);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nk_menu_begin_label(ctx, "Emulation", NK_TEXT_ALIGN_CENTERED, nk_vec2(windowScaleX(&ui->win, 100), windowGetScreenHeight(&ui->win)))) {
|
if (windowMenuBegin(&ui->win, "Emulation", 100)) {
|
||||||
const char *label = status == status_paused ? "Resume" : "Pause";
|
const char *label = status == status_paused ? "Resume" : "Pause";
|
||||||
nk_layout_row_dynamic(ctx, windowGetMenuHeight(&ui->win), 1);
|
if (windowMenuItemLabel(&ui->win, label)) {
|
||||||
if (nk_menu_item_label(ctx, label, NK_TEXT_ALIGN_LEFT)) {
|
|
||||||
if (status == status_paused)
|
if (status == status_paused)
|
||||||
status = status_running;
|
status = status_running;
|
||||||
else
|
else
|
||||||
status = status_paused;
|
status = status_paused;
|
||||||
}
|
}
|
||||||
if (nk_menu_item_label(ctx, "Reset", NK_TEXT_ALIGN_LEFT)) {
|
if (windowMenuItemLabel(&ui->win, "Reset")) {
|
||||||
emuReset(&ui->emu);
|
emuReset(&ui->emu);
|
||||||
status = emuIsGameLoaded(&ui->emu) ? status_running : status_paused;
|
status = emuIsGameLoaded(&ui->emu) ? status_running : status_paused;
|
||||||
}
|
}
|
||||||
nk_menu_end(ctx);
|
windowMenuEnd(&ui->win);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nk_menu_begin_label(ctx, "Video", NK_TEXT_ALIGN_CENTERED, nk_vec2(windowScaleX(&ui->win, 100), windowGetScreenHeight(&ui->win)))) {
|
if (windowMenuBegin(&ui->win, "Video", 100)) {
|
||||||
float multiplier = windowGetScreenSizeMultiplier(&ui->win);
|
float multiplier = windowGetScreenSizeMultiplier(&ui->win);
|
||||||
|
if (windowMenuItemLabelChecked(&ui->win, "x1", multiplier == 1.0f)) {
|
||||||
nk_layout_row_dynamic(ctx, windowGetMenuHeight(&ui->win), 1);
|
|
||||||
if (nk_menu_item_label(ctx, multiplier == 1.0f ? "x1 *" : "x1", NK_TEXT_ALIGN_LEFT)) {
|
|
||||||
windowSetScreenSizeMultiplier(&ui->win, 1.0f);
|
windowSetScreenSizeMultiplier(&ui->win, 1.0f);
|
||||||
}
|
}
|
||||||
if (nk_menu_item_label(ctx, multiplier == 2.0f ? "x2 *" : "x2", NK_TEXT_ALIGN_LEFT)) {
|
if (windowMenuItemLabelChecked(&ui->win, "x2", multiplier == 2.0f)) {
|
||||||
windowSetScreenSizeMultiplier(&ui->win, 2.0f);
|
windowSetScreenSizeMultiplier(&ui->win, 2.0f);
|
||||||
}
|
}
|
||||||
if (nk_menu_item_label(ctx, multiplier == 3.0f ? "x3 *" : "x3", NK_TEXT_ALIGN_LEFT)) {
|
if (windowMenuItemLabelChecked(&ui->win, "x3", multiplier == 3.0f)) {
|
||||||
windowSetScreenSizeMultiplier(&ui->win, 3.0f);
|
windowSetScreenSizeMultiplier(&ui->win, 3.0f);
|
||||||
}
|
}
|
||||||
if (nk_menu_item_label(ctx, multiplier == 4.0f ? "x4 *" : "x4", NK_TEXT_ALIGN_LEFT)) {
|
if (windowMenuItemLabelChecked(&ui->win, "x4", multiplier == 4.0f)) {
|
||||||
windowSetScreenSizeMultiplier(&ui->win, 4.0f);
|
windowSetScreenSizeMultiplier(&ui->win, 4.0f);
|
||||||
}
|
}
|
||||||
nk_menu_end(ctx);
|
windowMenuEnd(&ui->win);
|
||||||
}
|
}
|
||||||
|
|
||||||
windowMenubarEnd(&ui->win);
|
windowMenubarEnd(&ui->win);
|
||||||
|
|
32
window.c
32
window.c
|
@ -1,5 +1,6 @@
|
||||||
#include "assets.h"
|
#include "assets.h"
|
||||||
#include "nuklear.h"
|
#include "nuklear.h"
|
||||||
|
#include <string.h>
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
|
||||||
#define MENU_HEIGHT 20
|
#define MENU_HEIGHT 20
|
||||||
|
@ -257,3 +258,34 @@ void windowMenubarBegin(WindowContext *win, const char **items) {
|
||||||
void windowMenubarEnd(WindowContext *win) {
|
void windowMenubarEnd(WindowContext *win) {
|
||||||
nk_menubar_end(win->nk);
|
nk_menubar_end(win->nk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool windowMenuBegin(WindowContext *win, const char *label, int width) {
|
||||||
|
if (!nk_menu_begin_label(win->nk, label, NK_TEXT_ALIGN_CENTERED, nk_vec2(windowScaleX(win, width), windowGetScreenHeight(win)))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
nk_layout_row_dynamic(win->nk, windowGetMenuHeight(win), 1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void windowMenuEnd(WindowContext *win) {
|
||||||
|
nk_menu_end(win->nk);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool windowMenuItemLabel(WindowContext *win, const char *label) {
|
||||||
|
return nk_menu_item_label(win->nk, label, NK_TEXT_ALIGN_LEFT);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool windowMenuItemLabelChecked(WindowContext *win, const char *label, bool checked) {
|
||||||
|
char buffer[80];
|
||||||
|
bool result;
|
||||||
|
if (!checked) {
|
||||||
|
return windowMenuItemLabel(win, label);
|
||||||
|
}
|
||||||
|
strcpy(buffer, " * ");
|
||||||
|
strncpy(buffer + 5, label, 74);
|
||||||
|
buffer[79] = '\0';
|
||||||
|
nk_style_push_vec2(win->nk, &win->nk->style.contextual_button.padding, nk_vec2(4 * win->screenScaleX, 4 * win->screenScaleY));
|
||||||
|
result = nk_menu_item_label(win->nk, buffer, NK_TEXT_ALIGN_LEFT);
|
||||||
|
nk_style_pop_vec2(win->nk);
|
||||||
|
return result;
|
||||||
|
}
|
4
window.h
4
window.h
|
@ -33,5 +33,9 @@ bool windowGuiBegin(WindowContext *win, const char *title);
|
||||||
void windowGuiEnd(WindowContext *win);
|
void windowGuiEnd(WindowContext *win);
|
||||||
void windowMenubarBegin(WindowContext *win, const char **items);
|
void windowMenubarBegin(WindowContext *win, const char **items);
|
||||||
void windowMenubarEnd(WindowContext *win);
|
void windowMenubarEnd(WindowContext *win);
|
||||||
|
bool windowMenuBegin(WindowContext *win, const char *label, int width);
|
||||||
|
void windowMenuEnd(WindowContext *win);
|
||||||
|
bool windowMenuItemLabel(WindowContext *win, const char *label);
|
||||||
|
bool windowMenuItemLabelChecked(WindowContext *win, const char *label, bool checked);
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Reference in New Issue