2024-06-16 19:22:40 -04:00
|
|
|
//
|
|
|
|
// Created by william on 6/8/24.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <SDL_ttf.h>
|
|
|
|
#include "main_window.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "char_map.h"
|
|
|
|
#include "gui.h"
|
2024-09-01 15:54:41 -04:00
|
|
|
#include "components/window_menu.h"
|
2024-06-16 19:22:40 -04:00
|
|
|
|
2024-07-25 21:22:00 -04:00
|
|
|
void main_window_init(NesMainWindow *window) {
|
2024-09-01 15:54:41 -04:00
|
|
|
window->window = window_create("NES Emulator", MAIN_WINDOW_WIDTH, MAIN_WINDOW_HEIGHT, MAIN_WINDOW_SCALE);
|
|
|
|
window->texture = window_create_texture(&window->window, SDL_TEXTUREACCESS_STREAMING);
|
|
|
|
|
|
|
|
MenuComponent *menu = menu_create(&window->window, gui_get_font());
|
|
|
|
|
|
|
|
MenuItemComponent *mi_file = menu_item_create("FILE", NULL);
|
|
|
|
menu_append(menu, mi_file);
|
|
|
|
MenuItemComponent *mi_file_open = menu_item_create("OPEN ROM...", NULL);
|
|
|
|
menu_item_append(mi_file, mi_file_open);
|
|
|
|
|
|
|
|
MenuItemComponent *mi_debug = menu_item_create("DEBUG", NULL);
|
|
|
|
menu_append(menu, mi_debug);
|
|
|
|
MenuItemComponent *mi_debug_nametable = menu_item_create("NAMETABLE", NULL);
|
|
|
|
menu_item_append(mi_debug, mi_debug_nametable);
|
|
|
|
MenuItemComponent *mi_debug_pattern = menu_item_create("PATTERN TABLE", NULL);
|
|
|
|
menu_item_append(mi_debug, mi_debug_pattern);
|
|
|
|
|
|
|
|
menu_build(menu);
|
|
|
|
window_add_component(&window->window, menu_as_component(menu));
|
2024-06-16 19:22:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void main_window_uninit(NesMainWindow *window) {
|
|
|
|
SDL_DestroyTexture(window->texture);
|
2024-09-01 15:54:41 -04:00
|
|
|
window_destroy(&window->window);
|
2024-06-16 19:22:40 -04:00
|
|
|
}
|
|
|
|
|
2024-07-25 21:22:00 -04:00
|
|
|
#if DEBUG
|
2024-09-01 15:54:41 -04:00
|
|
|
|
2024-06-16 19:22:40 -04:00
|
|
|
void main_window_render_delay(SDL_Renderer *renderer) {
|
|
|
|
Uint32 delay = gui_get_frame_delay();
|
|
|
|
|
|
|
|
char buffer[5];
|
|
|
|
buffer[0] = (char) ((delay / 10) + 48);
|
|
|
|
buffer[1] = (char) ((delay % 10) + 48);
|
|
|
|
buffer[2] = ' ';
|
|
|
|
buffer[3] = 'm';
|
|
|
|
buffer[4] = 's';
|
|
|
|
|
|
|
|
char_map_render(renderer, buffer);
|
|
|
|
}
|
2024-09-01 15:54:41 -04:00
|
|
|
|
2024-07-25 21:22:00 -04:00
|
|
|
#endif
|
2024-06-16 19:22:40 -04:00
|
|
|
|
2024-08-17 17:38:15 -04:00
|
|
|
void main_window_render(NesMainWindow *window, pixel *pixels) {
|
2024-08-20 20:43:42 -04:00
|
|
|
SDL_UpdateTexture(window->texture, NULL, pixels, 256 * sizeof(pixel));
|
2024-06-16 19:22:40 -04:00
|
|
|
|
2024-09-01 15:54:41 -04:00
|
|
|
window_render_texture(&window->window, window->texture);
|
|
|
|
window_render_components(&window->window);
|
|
|
|
|
|
|
|
window_present(&window->window);
|
|
|
|
}
|
|
|
|
|
|
|
|
void main_window_mouse_motion(NesMainWindow *window, int x, int y) {
|
|
|
|
window_mouse_motion(&window->window, x, y);
|
2024-06-16 19:22:40 -04:00
|
|
|
}
|
|
|
|
|
2024-09-01 15:54:41 -04:00
|
|
|
void main_window_mouse_click(NesMainWindow *window) {
|
|
|
|
window_mouse_click(&window->window);
|
2024-06-16 19:22:40 -04:00
|
|
|
}
|