nesemu/gui/components/window.h

91 lines
2.3 KiB
C

//
// Created by william on 17/05/24.
//
#ifndef NES_EMULATOR_WINDOW_H
#define NES_EMULATOR_WINDOW_H
#include <SDL.h>
#include "linked_list.h"
#include "component.h"
typedef struct window_sdl_context {
SDL_Renderer *renderer;
SDL_Window *window;
} WindowSdlContext;
typedef struct window {
int width;
int height;
int scale;
WindowSdlContext sdl_context;
LinkedList components;
} Window;
/**
* Creates a window.
* @param title The title of the window
* @param width The width in pixels
* @param height The height in pixels
* @param scale The scale of pixels of this window (number of real pixels per drawn pixel)
* @return The created window
*/
Window window_create(char *title, int width, int height, int scale);
/**
* Creates a background_texture for a window. (same width/height)
* @param window A reference to the window
* @param access The SDL background_texture access type
* @return An SDL background_texture for the window
*/
SDL_Texture *window_create_texture(Window *window, int access);
/**
* Adds a component to a window.
* @param window A reference to the window
* @param component A reference to the component to add
*/
void window_add_component(Window *window, Component *component);
/**
* Renders the components of a window (but not the window itself)
* @param window The window to render components
*/
void window_render_components(Window *window);
/**
* Renders a background_texture in the window.
* @param window A reference to the window
* @param texture The background_texture to render
*/
void window_render_texture(Window *window, SDL_Texture *texture);
/**
* Presents a window.
* @param window A reference to the window
*/
void window_present(Window *window);
/**
* Destroys a window.
* Free the ressources of the window and its components.
* @param window The window to destroy
*/
void window_destroy(Window *window);
/**
* Handles mouse motion events in the window.
* @param window A reference to the window
* @param x The x position of the mouse
* @param y The y position of the mouse
*/
void window_mouse_motion(Window *window, int x, int y);
/**
* Handles mouse click events in the window.
* @param window A reference to the window
*/
void window_mouse_click(Window *window);
#endif //NES_EMULATOR_WINDOW_H