sdl2dll
Loading...
Searching...
No Matches
sdl_window.h
1/*
2 * Clases para manejar ventanas en SDL2
3 * SDL_CreateWindow
4 * SDL_DestroyWindow
5 * SDL_GetWindowSize
6 */
7#ifndef _SDL_WINDOW
8#define _SDL_WINDOW
9
10#define EXPORT __declspec(dllexport)
11
12#include <SDL.h>
13#include <string>
14
15namespace sdl {
16
21class Window {
22protected:
23 SDL_Window* window = nullptr;
25public:
29 EXPORT Window() : window(NULL) {}
38 EXPORT Window(const std::string &titulo, int w, int h, SDL_WindowFlags flags) {
39 window = SDL_CreateWindow(titulo.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
40 w, h, flags);
41 }
46 EXPORT ~Window() {
47 SDL_DestroyWindow(window);
48 }
54 EXPORT SDL_Window* Get() const { return window; }
60 EXPORT operator SDL_Window*() { return window; }
67 EXPORT void GetSize(int *w, int *h) {
68 SDL_GetWindowSize(window, w, h);
69 }
76 EXPORT void SetSize(int w, int h) {
77 SDL_SetWindowSize(window, w, h);
78 }
83 EXPORT void Center() {
84 SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
85 }
86};
87
88} // namespace
89
90#endif // _SDL_WINDOW
Clase que encapsula una ventana SDL2.
Definition sdl_window.h:21
EXPORT Window(const std::string &titulo, int w, int h, SDL_WindowFlags flags)
Constructor principal. Crea una ventana centrada con el título, dimensiones y banderas especificadas.
Definition sdl_window.h:38
SDL_Window * window
Definition sdl_window.h:23
EXPORT SDL_Window * Get() const
Devuelve el manipulador de la ventana.
Definition sdl_window.h:54
EXPORT ~Window()
Destructor.
Definition sdl_window.h:46
EXPORT void SetSize(int w, int h)
Asigna el tamaño de la ventana.
Definition sdl_window.h:76
EXPORT Window()
Constructor por defecto.
Definition sdl_window.h:29
EXPORT void GetSize(int *w, int *h)
Obtiene el tamaño de la ventana.
Definition sdl_window.h:67
EXPORT void Center()
Centra la ventana.
Definition sdl_window.h:83
Espacio con nombre para el wrapper de SDL2.
Definition sdl_music.h:14