nesemu/gui/gui.c

69 lines
1.5 KiB
C
Raw Normal View History

2024-05-17 00:33:37 -04:00
//
// Created by william on 16/05/24.
//
#include <assert.h>
2024-05-17 00:33:37 -04:00
#include "log.h"
2024-05-17 13:16:21 -04:00
#include "gui.h"
#include "window.h"
2024-05-17 00:33:37 -04:00
2024-05-17 13:16:21 -04:00
typedef struct nes_gui {
NesWindow main_window;
NesWindow debug_pattern_window;
} NesGui;
2024-05-17 00:33:37 -04:00
NesGui gui;
void gui_init() {
2024-05-17 13:16:21 -04:00
gui.main_window = window_init(WINDOW_MAIN_WIDTH, WINDOW_MAIN_HEIGHT, WINDOW_MAIN_SCALING, "NES Emulator");
gui.debug_pattern_window = window_init(WINDOW_PATTERN_WIDTH, WINDOW_PATTERN_HEIGHT, WINDOW_PATTERN_SCALING,
"Pattern Table");
}
2024-05-17 00:33:37 -04:00
void gui_uninit() {
window_uninit(&gui.main_window);
window_uninit(&gui.debug_pattern_window);
2024-05-17 00:33:37 -04:00
}
int gui_input() {
SDL_Event event;
while (SDL_PollEvent(&event)) {
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE) {
return -1;
2024-05-17 00:33:37 -04:00
}
}
return 1;
}
void gui_render() {
window_render(&gui.main_window);
window_render(&gui.debug_pattern_window);
2024-05-17 00:33:37 -04:00
}
void gui_present() {
window_present(&gui.main_window);
window_present(&gui.debug_pattern_window);
2024-05-17 00:33:37 -04:00
}
2024-05-17 13:16:21 -04:00
void gui_delay() {
SDL_Delay(16);
}
Canvas *gui_get_canvas(char win_id) {
NesWindow *window;
switch (win_id) {
2024-05-17 13:16:21 -04:00
case WINDOW_ID_MAIN:
window = &gui.main_window;
break;
2024-05-17 13:16:21 -04:00
case WINDOW_ID_PATTERN:
window = &gui.debug_pattern_window;
break;
default:
log_error("Couldn't get canvas for window ID '%d' because it doesn't exists", win_id);
assert(false);
}
2024-05-17 00:33:37 -04:00
return &window->canvas;
2024-05-17 00:33:37 -04:00
}