69 lines
1.5 KiB
C
69 lines
1.5 KiB
C
//
|
|
// Created by william on 16/05/24.
|
|
//
|
|
|
|
#include <assert.h>
|
|
#include "log.h"
|
|
#include "gui.h"
|
|
#include "window.h"
|
|
|
|
typedef struct nes_gui {
|
|
NesWindow main_window;
|
|
NesWindow debug_pattern_window;
|
|
} NesGui;
|
|
NesGui gui;
|
|
|
|
void gui_init() {
|
|
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");
|
|
}
|
|
|
|
void gui_uninit() {
|
|
window_uninit(&gui.main_window);
|
|
window_uninit(&gui.debug_pattern_window);
|
|
}
|
|
|
|
int gui_input() {
|
|
SDL_Event event;
|
|
|
|
while (SDL_PollEvent(&event)) {
|
|
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE) {
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
return 1;
|
|
}
|
|
|
|
void gui_render() {
|
|
window_render(&gui.main_window);
|
|
window_render(&gui.debug_pattern_window);
|
|
}
|
|
|
|
void gui_present() {
|
|
window_present(&gui.main_window);
|
|
window_present(&gui.debug_pattern_window);
|
|
}
|
|
|
|
void gui_delay() {
|
|
SDL_Delay(16);
|
|
}
|
|
|
|
Canvas *gui_get_canvas(char win_id) {
|
|
NesWindow *window;
|
|
|
|
switch (win_id) {
|
|
case WINDOW_ID_MAIN:
|
|
window = &gui.main_window;
|
|
break;
|
|
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);
|
|
}
|
|
|
|
return &window->canvas;
|
|
} |