nesemu/gui/main_window.c

65 lines
2.1 KiB
C
Raw Normal View History

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"
#include "actions.h"
2024-06-16 19:22:40 -04:00
void main_window_menu_process_action(int action_type) {
process_action(action_type);
}
MainWindow *main_window_create(int* window_id) {
MainWindow *window = malloc(sizeof(MainWindow));
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(), &main_window_menu_process_action);
2024-09-01 15:54:41 -04:00
// MenuItemComponent *mi_file = menu_item_create("FILE", ACTION_TYPE_OPEN_);
// menu_append(menu, mi_file);
// MenuItemComponent *mi_file_open = menu_item_create("OPEN ROM...", NULL);
// menu_item_append(mi_file, mi_file_open);
2024-09-01 15:54:41 -04:00
MenuItemComponent *mi_debug = menu_item_create("DEBUG", -1);
2024-09-01 15:54:41 -04:00
menu_append(menu, mi_debug);
MenuItemComponent *mi_debug_nametable = menu_item_create("NAMETABLE", ACTION_TYPE_OPEN_WINDOW_NAMETABLE);
2024-09-01 15:54:41 -04:00
menu_item_append(mi_debug, mi_debug_nametable);
MenuItemComponent *mi_debug_pattern = menu_item_create("PATTERN TABLE", ACTION_TYPE_OPEN_WINDOW_PATTERN_TABLE);
2024-09-01 15:54:41 -04:00
menu_item_append(mi_debug, mi_debug_pattern);
menu_build(menu);
window_add_component(&window->window, menu_as_component(menu));
*window_id = window->window.id;
return window;
2024-06-16 19:22:40 -04:00
}
void main_window_destroy(MainWindow *window) {
2024-06-16 19:22:40 -04:00
SDL_DestroyTexture(window->texture);
2024-09-01 15:54:41 -04:00
window_destroy(&window->window);
2024-06-16 19:22:40 -04:00
free(window);
2024-06-16 19:22:40 -04:00
}
2024-09-01 15:54:41 -04:00
void main_window_render(MainWindow *window, pixel *pixels) {
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(MainWindow *window, int x, int y) {
2024-09-01 15:54:41 -04:00
window_mouse_motion(&window->window, x, y);
2024-06-16 19:22:40 -04:00
}
void main_window_mouse_click(MainWindow *window) {
2024-09-01 15:54:41 -04:00
window_mouse_click(&window->window);
2024-06-16 19:22:40 -04:00
}