2024-05-17 00:33:37 -04:00
|
|
|
//
|
|
|
|
// Created by william on 16/05/24.
|
|
|
|
//
|
|
|
|
|
2024-05-17 11:40:02 -04:00
|
|
|
#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;
|
|
|
|
|
2024-05-17 11:40:02 -04:00
|
|
|
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 11:40:02 -04:00
|
|
|
}
|
2024-05-17 00:33:37 -04:00
|
|
|
|
2024-05-17 11:40:02 -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)) {
|
2024-05-17 11:40:02 -04:00
|
|
|
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() {
|
2024-05-17 11:40:02 -04:00
|
|
|
window_render(&gui.main_window);
|
|
|
|
window_render(&gui.debug_pattern_window);
|
2024-05-17 00:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void gui_present() {
|
2024-05-17 11:40:02 -04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2024-05-17 11:40:02 -04:00
|
|
|
Canvas *gui_get_canvas(char win_id) {
|
|
|
|
NesWindow *window;
|
|
|
|
|
|
|
|
switch (win_id) {
|
2024-05-17 13:16:21 -04:00
|
|
|
case WINDOW_ID_MAIN:
|
2024-05-17 11:40:02 -04:00
|
|
|
window = &gui.main_window;
|
|
|
|
break;
|
2024-05-17 13:16:21 -04:00
|
|
|
case WINDOW_ID_PATTERN:
|
2024-05-17 11:40:02 -04:00
|
|
|
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
|
|
|
|
2024-05-17 11:40:02 -04:00
|
|
|
return &window->canvas;
|
2024-05-17 00:33:37 -04:00
|
|
|
}
|