restructure project for dynamic linking
This commit is contained in:
87
modules/gui/window/glfwWindow.cpp
Executable file
87
modules/gui/window/glfwWindow.cpp
Executable file
@@ -0,0 +1,87 @@
|
||||
#include "glfwWindow.h"
|
||||
|
||||
|
||||
|
||||
WindowGLFW::WindowGLFW() {
|
||||
|
||||
}
|
||||
|
||||
WindowGLFW::~WindowGLFW() {
|
||||
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
void WindowGLFW::init( std::string title, int x, int y) : title(title), x(x), y(y) {
|
||||
|
||||
if(!glfwInit()) {
|
||||
std::cout << "glfwInit failed!\n";
|
||||
error = true;
|
||||
return;
|
||||
}
|
||||
|
||||
window = glfwCreateWindow(x, y, title.c_str(), NULL, NULL);
|
||||
if(!window) {
|
||||
glfwTerminate();
|
||||
std::cout << "glfwCreateWindow failed!";
|
||||
error = true;
|
||||
return;
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
}
|
||||
|
||||
void WindowGLFW::shutdown() {
|
||||
~WindowGLFW();
|
||||
}
|
||||
|
||||
void WindowGLFW::getSize() {
|
||||
|
||||
SDL_GetWindowSize(window, &x, &y);
|
||||
}
|
||||
|
||||
const Event* WindowGLFW::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* WindowGLFW::pollEvents() {
|
||||
|
||||
while (SDL_PollEvent(&event)) {
|
||||
|
||||
return createEvent();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
Reference in New Issue
Block a user