- [NEW] Pasada la textura de font a png
- [FIX] debugger inicialitzat al començar - [WIP] Noves classes de UI
This commit is contained in:
1 parent
1dddc11722
commit
6c205fb014
7 files changed
+255
-1
No files matched your search
@@ -0,0 +1,50 @@
|
||||
#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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user