// // Created by william on 6/8/24. // #include #include "main_window.h" #include "log.h" #include "char_map.h" #include "gui.h" #include "components/window_menu.h" #include "actions.h" 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)); 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); // 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); MenuItemComponent *mi_debug = menu_item_create("DEBUG", -1); menu_append(menu, mi_debug); MenuItemComponent *mi_debug_nametable = menu_item_create("NAMETABLE", ACTION_TYPE_OPEN_WINDOW_NAMETABLE); menu_item_append(mi_debug, mi_debug_nametable); MenuItemComponent *mi_debug_pattern = menu_item_create("PATTERN TABLE", ACTION_TYPE_OPEN_WINDOW_PATTERN_TABLE); 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; } void main_window_destroy(MainWindow *window) { SDL_DestroyTexture(window->texture); window_destroy(&window->window); free(window); } void main_window_render(MainWindow *window, pixel *pixels) { SDL_UpdateTexture(window->texture, NULL, pixels, 256 * sizeof(pixel)); 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) { window_mouse_motion(&window->window, x, y); } void main_window_mouse_click(MainWindow *window) { window_mouse_click(&window->window); }