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-10-03 19:24:03 -04:00
|
|
|
#include "actions.h"
|
2024-06-16 19:22:40 -04:00
|
|
|
|
2024-10-03 19:24:03 -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);
|
|
|
|
|
2024-10-03 19:24:03 -04:00
|
|
|
MenuComponent *menu = menu_create(&window->window, gui_get_font(), &main_window_menu_process_action);
|
2024-09-01 15:54:41 -04:00
|
|
|
|
2024-10-03 19:24:03 -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
|
|
|
|
2024-10-03 19:24:03 -04:00
|
|
|
MenuItemComponent *mi_debug = menu_item_create("DEBUG", -1);
|
2024-09-01 15:54:41 -04:00
|
|
|
menu_append(menu, mi_debug);
|
2024-10-03 19:24:03 -04:00
|
|
|
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);
|
2024-10-03 19:24:03 -04:00
|
|
|
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));
|
2024-10-03 19:24:03 -04:00
|
|
|
|
|
|
|
*window_id = window->window.id;
|
|
|
|
return window;
|
2024-06-16 19:22:40 -04:00
|
|
|
}
|
|
|
|
|
2024-10-03 19:24:03 -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
|
|
|
|
2024-10-03 19:24:03 -04:00
|
|
|
free(window);
|
2024-06-16 19:22:40 -04:00
|
|
|
}
|
2024-09-01 15:54:41 -04:00
|
|
|
|
2024-10-03 19:24:03 -04:00
|
|
|
void main_window_render(MainWindow *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);
|
|
|
|
}
|
|
|
|
|
2024-10-03 19:24:03 -04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2024-10-03 19:24:03 -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
|
|
|
}
|