Files
atari2600/source/ui/window.cpp
T
Raimon @ quifisraimon 6c205fb014 - [NEW] Pasada la textura de font a png
- [FIX] debugger inicialitzat al començar
- [WIP] Noves classes de UI
2026-09-24 14:01:45 +02:00

50 lines
1.3 KiB
C++

#include "window.h"
namespace ui
{
Window::Window(const char *title, int width, int height)
{
this->win = SDL_CreateWindow(title, width, height, 0);
this->context = new Context(this->win);
windows.push_back({SDL_GetWindowID(this->win), this});
float x, y;
SDL_GetMouseState(&x, &y);
input.mouse.x = int(x);
input.mouse.y = int(y);
}
Window::~Window()
{
for (size_t i=0; i<windows.size(); ++i) { if (windows[i].second==this) std::swap(windows[i], windows.back()); windows.pop_back(); break; }
delete this->context;
SDL_DestroyWindow(this->win);
}
bool Window::HandleEvents(SDL_Event *e)
{
switch (e->type) {
case SDL_EVENT_MOUSE_MOTION:
input.mouse.x = e->motion.x;
input.mouse.y = e->motion.y;
// ...
default: break;
}
}
/* MÈTODES ESTATICS */
/* ================ */
std::vector<std::pair<uint32_t, Window*>> Window::windows;
void Window::DistributeEvent(SDL_Event *e)
{
uint32_t id = SDL_GetWindowID(SDL_GetWindowFromEvent(e));
for (auto window : Window::windows) if (window.first == id) window.second->HandleEvents(e);
}
}