restructure project for dynamic linking
This commit is contained in:
94
modules/gui/window/sdl2Window.cpp
Executable file
94
modules/gui/window/sdl2Window.cpp
Executable file
@@ -0,0 +1,94 @@
|
||||
#include "sdl2Window.h"
|
||||
|
||||
|
||||
|
||||
WindowSDL2::WindowSDL2() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
WindowSDL2::~WindowSDL2() {
|
||||
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
void WindowSDL2::init( std::string title, int x, int y) : title(title), x(x), y(y) {
|
||||
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
|
||||
{
|
||||
printf("Error: %s\n", SDL_GetError());
|
||||
error = true;
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
|
||||
window = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, x, y, window_flags);
|
||||
if (window == nullptr)
|
||||
{
|
||||
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
|
||||
error = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// int test = SDL_SetWindowOpacity(this->window, 0.1f);
|
||||
// float t;
|
||||
// SDL_GetWindowOpacity(this->window, &t);
|
||||
// std::cout << test << " " << t << std::endl;
|
||||
}
|
||||
|
||||
void WindowSDL2::shutdown() {
|
||||
~WindowSDL2();
|
||||
}
|
||||
|
||||
void WindowSDL2::getSize() {
|
||||
|
||||
SDL_GetWindowSize(window, &x, &y);
|
||||
}
|
||||
|
||||
const Event* WindowSDL2::createEvent() {
|
||||
switch(event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
return new KeyEvent(event.key.keysym.sym, event.key.keysym.scancode,
|
||||
event.key.keysym.mod, event.key.repeat, true);
|
||||
|
||||
case SDL_KEYUP:
|
||||
return new KeyEvent(event.key.keysym.sym, event.key.keysym.scancode,
|
||||
event.key.keysym.mod, event.key.repeat, false);
|
||||
|
||||
case SDL_TEXTINPUT:
|
||||
return new KeyTypedEvent(event.text.windowID, event.text.text);
|
||||
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
|
||||
switch(event.button.button) {
|
||||
case SDL_BUTTON_LEFT: return new MouseButtonEvent(0, (event.type == SDL_MOUSEBUTTONDOWN));
|
||||
case SDL_BUTTON_RIGHT: return new MouseButtonEvent(1, (event.type == SDL_MOUSEBUTTONDOWN));
|
||||
case SDL_BUTTON_MIDDLE: return new MouseButtonEvent(2, (event.type == SDL_MOUSEBUTTONDOWN));
|
||||
case SDL_BUTTON_X1: return new MouseButtonEvent(3, (event.type == SDL_MOUSEBUTTONDOWN));
|
||||
case SDL_BUTTON_X2: return new MouseButtonEvent(4, (event.type == SDL_MOUSEBUTTONDOWN));
|
||||
}
|
||||
|
||||
|
||||
case SDL_MOUSEMOTION:
|
||||
return new MouseMovedEvent(event.motion.x, event.motion.y, event.motion.xrel, event.motion.yrel);
|
||||
|
||||
case SDL_MOUSEWHEEL:
|
||||
return new MouseScrolledEvent(event.wheel.x, event.wheel.y);
|
||||
|
||||
case SDL_WINDOWEVENT:
|
||||
return new WindowEvent(event.window.windowID, event.window.event);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
const Event* WindowSDL2::pollEvents() {
|
||||
|
||||
while (SDL_PollEvent(&event)) {
|
||||
|
||||
return createEvent();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
Reference in New Issue
Block a user