nesemu/gui/gui.c

59 lines
1.3 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 "gui.h"
#include "log.h"
NesGui gui;
void gui_init() {
gui.main_window = window_init(MAIN_WINDOW_WIDTH, MAIN_WINDOW_HEIGHT, "NES Emulator");
gui.debug_pattern_window = window_init(DEBUG_PATTERN_WIDTH, DEBUG_PATTERN_HEIGHT, "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
}
Canvas *gui_get_canvas(char win_id) {
NesWindow *window;
switch (win_id) {
case GUI_WINDOW_MAIN:
window = &gui.main_window;
break;
case GUI_WINDOW_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
}