From 14f562ee0aa131176acd3630737ce7210e6a11eb Mon Sep 17 00:00:00 2001 From: trpeski Date: Mon, 12 Sep 2016 10:29:18 +0300 Subject: [PATCH 01/16] Create glfw3windowbackend.hpp --- src/ui/glfw3windowbackend.hpp | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/ui/glfw3windowbackend.hpp diff --git a/src/ui/glfw3windowbackend.hpp b/src/ui/glfw3windowbackend.hpp new file mode 100644 index 00000000..2ae75829 --- /dev/null +++ b/src/ui/glfw3windowbackend.hpp @@ -0,0 +1 @@ +#include From 4a4d11f17d7db540cd02809c3ea5d1a40867fe51 Mon Sep 17 00:00:00 2001 From: trpeski Date: Mon, 12 Sep 2016 11:17:54 +0300 Subject: [PATCH 02/16] Update glfw3windowbackend.hpp --- src/ui/glfw3windowbackend.hpp | 120 ++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/src/ui/glfw3windowbackend.hpp b/src/ui/glfw3windowbackend.hpp index 2ae75829..a54127e0 100644 --- a/src/ui/glfw3windowbackend.hpp +++ b/src/ui/glfw3windowbackend.hpp @@ -1 +1,121 @@ #include + +namespace fea{ + +void glfw3WindowBackend::open(VideoMode mode, const std::string& title, uint32_t style, const ContextSettings& settings) +{ + glfwInit(); + GLFWwindow * window = glfwCreateWindow(mode.mwidth, mode.mheight, title.c_str(), NULL, NULL); +} + + void glfw3WindowBackend::close() + { + glfwDestroyWindow(window); + } + + + bool glfw3WindowBackend::isOpen() const + { + return window != nullptr; + } + + const ContextSettings glfw3WindowBackend::getSettings() const + { + + // still looking on how to get and set context setings + + } + + Vec2I glfw3WindowBackend::getPosition() const + { + Vec2I s; + s.x = 0; + s.y = 0; + + if(isOpen()) + glfwGetWindowPos(window, &s.x , &s.y ); + + return s; + } + + void glfw3WindowBackend::setPosition(int32_t x, int32_t y) + { + if(isOpen()) + { + glfwSetWindowPos(window , x , y); + } + } + + Vec2I glfw3WindowBackend::getSize() const + { + Vec2I s; + s.x = 0; + s.y = 0; + + if(isOpen()) + glfwGetWindowSize(window, &s.x, &s.y); + + return s; + } + + void glfw3WindowBackend::setSize(int32_t w, int32_t h) + { + glfwSetWindowSize(window, w, h); + } + + void glfw3WindowBackend::setTitle(const std::string& title) + { + glfwSetWindowTitle(window, title.c_str()); + } + + void glfw3WindowBackend::setIcon(uint32_t width, uint32_t height, const uint8_t* pixels) + { + // still working on it + } + + void glfw3WindowBackend::setVisible(bool visible) + { + // still working on it + } + + void glfw3WindowBackend::setVSyncEnabled(bool enabled) + { + // still woriking on it + } + + void glfw3WindowBackend::setMouseCursorVisible(bool visible) + { + // still working on it + } + + void glfw3WindowBackend::setFramerateLimit(uint32_t limit) + { + //still woriking on it + } + + bool glfw3WindowBackend::setRenderingActive(bool active) const + { + // still working on it + } + + void glfw3WindowBackend::swapBuffers() + { + glfwSwapBuffers(window); + } + + void glfw3WindowBackend::lockCursor(bool lock) + { + if(isOpen()) + { + // still working on it + } + } + + glfw3WindowBackend::~SDL2WindowBackend() + { + close(); + } + + + +} From 4371296cde91ca2287d561003cc8b259f1014de7 Mon Sep 17 00:00:00 2001 From: trpeski Date: Mon, 12 Sep 2016 13:11:23 +0300 Subject: [PATCH 03/16] Add files via upload --- src/ui/glfw3windowbackend.h | 34 ++++++++++++++++++++++++++++++++++ src/ui/glfw3windowbackend.hpp | 17 +++++++++-------- 2 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 src/ui/glfw3windowbackend.h diff --git a/src/ui/glfw3windowbackend.h b/src/ui/glfw3windowbackend.h new file mode 100644 index 00000000..9c87df6a --- /dev/null +++ b/src/ui/glfw3windowbackend.h @@ -0,0 +1,34 @@ +#ifndef GLFW3WINDOWBACKEND_H_INCLUDED +#define GLFW3WINDOWBACKEND_H_INCLUDED + +namespace fea{ +class glfw3WindowBackend +{ +public: + void open(VideoMode mode, const std::string& title, uint32_t style, const ContextSettings& settings) const; + void close(); + bool isOpen(); + void getSettings(); + Vec2I getPosition(); + void setPosition(int32_t x, int32_t y); + vec2I getSize(); + void setSize(int32_t w, int32_t h); + void setTitle(const std::string& title); + void setIcon(uint32_t width, uint32_t height, const uint8_t* pixels); + void setVisible(bool visible); + void setVSyncEnabled(bool enabled); + void setMouseCursorVisible(bool visible); + void setFramerateLimit(uint32_t limit); + bool setRenderingActive(bool active); + void swapBuffers(); + void lockCursor(bool lock); + ~glfw3WindowBackend(); + + + +}; + +} + + +#endif // GLFW3WINDOWBACKEND_H_INCLUDED diff --git a/src/ui/glfw3windowbackend.hpp b/src/ui/glfw3windowbackend.hpp index a54127e0..dfd521b1 100644 --- a/src/ui/glfw3windowbackend.hpp +++ b/src/ui/glfw3windowbackend.hpp @@ -1,7 +1,8 @@ -#include +#include +#include "glfw3windowbackend.h" namespace fea{ - + void glfw3WindowBackend::open(VideoMode mode, const std::string& title, uint32_t style, const ContextSettings& settings) { glfwInit(); @@ -21,9 +22,9 @@ void glfw3WindowBackend::open(VideoMode mode, const std::string& title, uint32_t const ContextSettings glfw3WindowBackend::getSettings() const { - + // still looking on how to get and set context setings - + } Vec2I glfw3WindowBackend::getPosition() const @@ -33,7 +34,7 @@ void glfw3WindowBackend::open(VideoMode mode, const std::string& title, uint32_t s.y = 0; if(isOpen()) - glfwGetWindowPos(window, &s.x , &s.y ); + glfwGetWindowPos(window, &s.x , &s.y ); return s; } @@ -42,7 +43,7 @@ void glfw3WindowBackend::open(VideoMode mode, const std::string& title, uint32_t { if(isOpen()) { - glfwSetWindowPos(window , x , y); + glfwSetWindowPos(window , x , y); } } @@ -100,7 +101,7 @@ void glfw3WindowBackend::open(VideoMode mode, const std::string& title, uint32_t void glfw3WindowBackend::swapBuffers() { - glfwSwapBuffers(window); + glfwSwapBuffers(window); } void glfw3WindowBackend::lockCursor(bool lock) @@ -111,7 +112,7 @@ void glfw3WindowBackend::open(VideoMode mode, const std::string& title, uint32_t } } - glfw3WindowBackend::~SDL2WindowBackend() + glfw3WindowBackend::~glfw3WindowBackend() { close(); } From 46442f30e5a3ba7d7fbfb405008b961e9e83a62d Mon Sep 17 00:00:00 2001 From: trpeski Date: Mon, 12 Sep 2016 13:18:19 +0300 Subject: [PATCH 04/16] Update glfw3windowbackend.h --- src/ui/glfw3windowbackend.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/ui/glfw3windowbackend.h b/src/ui/glfw3windowbackend.h index 9c87df6a..1d7067a8 100644 --- a/src/ui/glfw3windowbackend.h +++ b/src/ui/glfw3windowbackend.h @@ -1,3 +1,12 @@ + // written by antonio trpeski // + + + + + + + + #ifndef GLFW3WINDOWBACKEND_H_INCLUDED #define GLFW3WINDOWBACKEND_H_INCLUDED From 7d1a7db5a70abedaa83917f07ba9f91aaa3adea1 Mon Sep 17 00:00:00 2001 From: trpeski Date: Mon, 12 Sep 2016 13:19:00 +0300 Subject: [PATCH 05/16] Update glfw3windowbackend.hpp --- src/ui/glfw3windowbackend.hpp | 250 ++++++++++++++++++---------------- 1 file changed, 129 insertions(+), 121 deletions(-) diff --git a/src/ui/glfw3windowbackend.hpp b/src/ui/glfw3windowbackend.hpp index dfd521b1..6a9514a6 100644 --- a/src/ui/glfw3windowbackend.hpp +++ b/src/ui/glfw3windowbackend.hpp @@ -1,122 +1,130 @@ + // written by antonio trpeski // + + + + + + + #include -#include "glfw3windowbackend.h" - -namespace fea{ - -void glfw3WindowBackend::open(VideoMode mode, const std::string& title, uint32_t style, const ContextSettings& settings) -{ - glfwInit(); - GLFWwindow * window = glfwCreateWindow(mode.mwidth, mode.mheight, title.c_str(), NULL, NULL); -} - - void glfw3WindowBackend::close() - { - glfwDestroyWindow(window); - } - - - bool glfw3WindowBackend::isOpen() const - { - return window != nullptr; - } - - const ContextSettings glfw3WindowBackend::getSettings() const - { - - // still looking on how to get and set context setings - - } - - Vec2I glfw3WindowBackend::getPosition() const - { - Vec2I s; - s.x = 0; - s.y = 0; - - if(isOpen()) - glfwGetWindowPos(window, &s.x , &s.y ); - - return s; - } - - void glfw3WindowBackend::setPosition(int32_t x, int32_t y) - { - if(isOpen()) - { - glfwSetWindowPos(window , x , y); - } - } - - Vec2I glfw3WindowBackend::getSize() const - { - Vec2I s; - s.x = 0; - s.y = 0; - - if(isOpen()) - glfwGetWindowSize(window, &s.x, &s.y); - - return s; - } - - void glfw3WindowBackend::setSize(int32_t w, int32_t h) - { - glfwSetWindowSize(window, w, h); - } - - void glfw3WindowBackend::setTitle(const std::string& title) - { - glfwSetWindowTitle(window, title.c_str()); - } - - void glfw3WindowBackend::setIcon(uint32_t width, uint32_t height, const uint8_t* pixels) - { - // still working on it - } - - void glfw3WindowBackend::setVisible(bool visible) - { - // still working on it - } - - void glfw3WindowBackend::setVSyncEnabled(bool enabled) - { - // still woriking on it - } - - void glfw3WindowBackend::setMouseCursorVisible(bool visible) - { - // still working on it - } - - void glfw3WindowBackend::setFramerateLimit(uint32_t limit) - { - //still woriking on it - } - - bool glfw3WindowBackend::setRenderingActive(bool active) const - { - // still working on it - } - - void glfw3WindowBackend::swapBuffers() - { - glfwSwapBuffers(window); - } - - void glfw3WindowBackend::lockCursor(bool lock) - { - if(isOpen()) - { - // still working on it - } - } - - glfw3WindowBackend::~glfw3WindowBackend() - { - close(); - } - - - -} +#include "glfw3windowbackend.h" + +namespace fea{ + +void glfw3WindowBackend::open(VideoMode mode, const std::string& title, uint32_t style, const ContextSettings& settings) +{ + glfwInit(); + GLFWwindow * window = glfwCreateWindow(mode.mwidth, mode.mheight, title.c_str(), NULL, NULL); +} + + void glfw3WindowBackend::close() + { + glfwDestroyWindow(window); + } + + + bool glfw3WindowBackend::isOpen() const + { + return window != nullptr; + } + + const ContextSettings glfw3WindowBackend::getSettings() const + { + + // still looking on how to get and set context setings + + } + + Vec2I glfw3WindowBackend::getPosition() const + { + Vec2I s; + s.x = 0; + s.y = 0; + + if(isOpen()) + glfwGetWindowPos(window, &s.x , &s.y ); + + return s; + } + + void glfw3WindowBackend::setPosition(int32_t x, int32_t y) + { + if(isOpen()) + { + glfwSetWindowPos(window , x , y); + } + } + + Vec2I glfw3WindowBackend::getSize() const + { + Vec2I s; + s.x = 0; + s.y = 0; + + if(isOpen()) + glfwGetWindowSize(window, &s.x, &s.y); + + return s; + } + + void glfw3WindowBackend::setSize(int32_t w, int32_t h) + { + glfwSetWindowSize(window, w, h); + } + + void glfw3WindowBackend::setTitle(const std::string& title) + { + glfwSetWindowTitle(window, title.c_str()); + } + + void glfw3WindowBackend::setIcon(uint32_t width, uint32_t height, const uint8_t* pixels) + { + // still working on it + } + + void glfw3WindowBackend::setVisible(bool visible) + { + // still working on it + } + + void glfw3WindowBackend::setVSyncEnabled(bool enabled) + { + // still woriking on it + } + + void glfw3WindowBackend::setMouseCursorVisible(bool visible) + { + // still working on it + } + + void glfw3WindowBackend::setFramerateLimit(uint32_t limit) + { + //still woriking on it + } + + bool glfw3WindowBackend::setRenderingActive(bool active) const + { + // still working on it + } + + void glfw3WindowBackend::swapBuffers() + { + glfwSwapBuffers(window); + } + + void glfw3WindowBackend::lockCursor(bool lock) + { + if(isOpen()) + { + // still working on it + } + } + + glfw3WindowBackend::~glfw3WindowBackend() + { + close(); + } + + + +} From 33f2ed5720583684febec05928a3bd16729ce923 Mon Sep 17 00:00:00 2001 From: trpeski Date: Tue, 13 Sep 2016 12:07:50 +0300 Subject: [PATCH 06/16] Update glfw3windowbackend.hpp --- src/ui/glfw3windowbackend.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/glfw3windowbackend.hpp b/src/ui/glfw3windowbackend.hpp index 6a9514a6..ab16fc76 100644 --- a/src/ui/glfw3windowbackend.hpp +++ b/src/ui/glfw3windowbackend.hpp @@ -14,7 +14,7 @@ namespace fea{ void glfw3WindowBackend::open(VideoMode mode, const std::string& title, uint32_t style, const ContextSettings& settings) { glfwInit(); - GLFWwindow * window = glfwCreateWindow(mode.mwidth, mode.mheight, title.c_str(), NULL, NULL); + window = glfwCreateWindow(mode.mwidth, mode.mheight, title.c_str(), NULL, NULL); } void glfw3WindowBackend::close() From faa303be80d5541d98b025f6720f0b3f4184cbe1 Mon Sep 17 00:00:00 2001 From: trpeski Date: Tue, 13 Sep 2016 12:08:57 +0300 Subject: [PATCH 07/16] Update glfw3windowbackend.h --- src/ui/glfw3windowbackend.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ui/glfw3windowbackend.h b/src/ui/glfw3windowbackend.h index 1d7067a8..296663a4 100644 --- a/src/ui/glfw3windowbackend.h +++ b/src/ui/glfw3windowbackend.h @@ -13,6 +13,8 @@ namespace fea{ class glfw3WindowBackend { +private: + GLFWwindow *window; public: void open(VideoMode mode, const std::string& title, uint32_t style, const ContextSettings& settings) const; void close(); From efeb5c035edd4427b296b3753560d51c7482a857 Mon Sep 17 00:00:00 2001 From: trpeski Date: Fri, 16 Sep 2016 12:55:31 +0300 Subject: [PATCH 08/16] Update glfw3windowbackend.hpp --- src/ui/glfw3windowbackend.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/glfw3windowbackend.hpp b/src/ui/glfw3windowbackend.hpp index ab16fc76..80e99f56 100644 --- a/src/ui/glfw3windowbackend.hpp +++ b/src/ui/glfw3windowbackend.hpp @@ -79,7 +79,7 @@ void glfw3WindowBackend::open(VideoMode mode, const std::string& title, uint32_t void glfw3WindowBackend::setIcon(uint32_t width, uint32_t height, const uint8_t* pixels) { - // still working on it + glfwSetWindowIcon(window, 0 ,images ) } void glfw3WindowBackend::setVisible(bool visible) From f5f7c065e3757d645b857495224b5df82d159ab0 Mon Sep 17 00:00:00 2001 From: trpeski Date: Fri, 16 Sep 2016 13:08:26 +0300 Subject: [PATCH 09/16] Update glfw3windowbackend.h --- src/ui/glfw3windowbackend.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ui/glfw3windowbackend.h b/src/ui/glfw3windowbackend.h index 296663a4..01748f97 100644 --- a/src/ui/glfw3windowbackend.h +++ b/src/ui/glfw3windowbackend.h @@ -15,6 +15,7 @@ class glfw3WindowBackend { private: GLFWwindow *window; + GLFWimage *images[2]; public: void open(VideoMode mode, const std::string& title, uint32_t style, const ContextSettings& settings) const; void close(); From fd37114e86094b5679876ca51789262b91ac342a Mon Sep 17 00:00:00 2001 From: trpeski Date: Fri, 16 Sep 2016 13:14:47 +0300 Subject: [PATCH 10/16] Update glfw3windowbackend.hpp --- src/ui/glfw3windowbackend.hpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ui/glfw3windowbackend.hpp b/src/ui/glfw3windowbackend.hpp index 80e99f56..3dae34f9 100644 --- a/src/ui/glfw3windowbackend.hpp +++ b/src/ui/glfw3windowbackend.hpp @@ -77,9 +77,12 @@ void glfw3WindowBackend::open(VideoMode mode, const std::string& title, uint32_t glfwSetWindowTitle(window, title.c_str()); } - void glfw3WindowBackend::setIcon(uint32_t width, uint32_t height, const uint8_t* pixels) + void glfw3WindowBackend::setIcon(const std::string &path_small , const std::string &path_big ) { - glfwSetWindowIcon(window, 0 ,images ) + images[0] = load_icon(path_big.c_str()); + images[1] = load_icon(path_small.c_str()); + + glfwSetWindowIcon(window, 2 ,images) } void glfw3WindowBackend::setVisible(bool visible) From 80e9b6bff795f3eff8608909b13ad6d5e255a0c1 Mon Sep 17 00:00:00 2001 From: Tobias Widlund Date: Sat, 17 Sep 2016 15:54:34 +0200 Subject: [PATCH 11/16] Made it compile with glfw3inputbackend --- CMakeLists.txt | 27 ++++ cmake/modules/FindGLFW.cmake | 83 +++++++++++ include/fea/ui/glfw3inputbackend.hpp | 34 +++++ .../fea/ui/glfw3windowbackend.hpp | 33 ++--- pkg-config/fea-glfw.pc.in | 12 ++ src/ui/glfw3inputbackend.cpp | 79 +++++++++++ src/ui/glfw3windowbackend.cpp | 123 ++++++++++++++++ src/ui/glfw3windowbackend.hpp | 133 ------------------ 8 files changed, 369 insertions(+), 155 deletions(-) create mode 100644 cmake/modules/FindGLFW.cmake create mode 100644 include/fea/ui/glfw3inputbackend.hpp rename src/ui/glfw3windowbackend.h => include/fea/ui/glfw3windowbackend.hpp (56%) create mode 100644 pkg-config/fea-glfw.pc.in create mode 100644 src/ui/glfw3inputbackend.cpp create mode 100644 src/ui/glfw3windowbackend.cpp delete mode 100644 src/ui/glfw3windowbackend.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 2880593f..4c2e90af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,7 @@ set(BUILD_UTIL TRUE CACHE BOOL "Selects if the util module should be built") set(BUILD_SFMLBACKENDS FALSE CACHE BOOL "Selects if the SFML backends should be built") set(BUILD_SDLBACKENDS FALSE CACHE BOOL "Selects if the SDL backends should be built") set(BUILD_SDL2BACKENDS FALSE CACHE BOOL "Selects if the SDL2 backends should be built") +set(BUILD_GLFWBACKENDS FALSE CACHE BOOL "Selects if the GLFW backends should be built") set(BUILD_JSON TRUE CACHE BOOL "Selects if the json (de)serialization functions should be built") @@ -487,6 +488,29 @@ if(BUILD_UI) ${ui_sdl2_backend_header_files}) target_link_libraries(${project_name}-sdl2 ${SDL2_LIBRARY} ${project_name}-ui) endif() + + if(${BUILD_GLFWBACKENDS}) + find_package(GLFW REQUIRED) + if(GLFW_FOUND) + include_directories(${GLFW_INCLUDE_DIR}) + endif(GLFW_FOUND) + + set(ui_glfw_backend_source_files + src/ui/glfw3windowbackend.cpp + #src/ui/contextsettings.cpp + src/ui/glfw3inputbackend.cpp) + + set(ui_glfw_backend_header_files + include/fea/ui/glfw3windowbackend.hpp + include/fea/ui/glfw3inputbackend.hpp) + + set(BUILT_TARGETS ${BUILT_TARGETS} ${project_name}-glfw) + + add_library(${project_name}-glfw ${SHARED_OR_STATIC} + ${ui_glfw_backend_source_files} + ${ui_glfw_backend_header_files}) + target_link_libraries(${project_name}-glfw ${GLFW_LIBRARY} ${project_name}-ui) + endif() endif() if(BUILD_UTIL) @@ -554,6 +578,9 @@ if(INSTALL_PKGCONFIG_FILES) if(BUILD_SDL2BACKENDS) set(PKGMODULE_SDL2 fea-sdl2) endif() + if(BUILD_GLFWBACKENDS) + set(PKGMODULE_SDL2 fea-glfw) + endif() if(BUILD_JSON) set(PKGREQ_JSONCPP jsoncpp) endif() diff --git a/cmake/modules/FindGLFW.cmake b/cmake/modules/FindGLFW.cmake new file mode 100644 index 00000000..a4574173 --- /dev/null +++ b/cmake/modules/FindGLFW.cmake @@ -0,0 +1,83 @@ +# + +# Try to find GLFW library and include path. +# Once done this will define +# +# GLFW_FOUND +# GLFW_INCLUDE_DIR +# GLFW_LIBRARY +# + +include(FindPackageHandleStandardArgs) + +if (WIN32) + find_path( GLFW_INCLUDE_DIR + NAMES + GLFW/glfw3.h + PATHS + ${PROJECT_SOURCE_DIR}/shared_external/glfw/include + ${PROJECT_SOURCE_DIR}/../shared_external/glfw/include + ${GLFW_LOCATION}/include + $ENV{GLFW_LOCATION}/include + $ENV{PROGRAMFILES}/GLFW/include + ${GLFW_LOCATION} + $ENV{GLFW_LOCATION} + DOC "The directory where GLFW/glfw3.h resides" ) + if(ARCH STREQUAL "x86") + find_library( GLFW_LIBRARY + NAMES + glfw3 + PATHS + ${GLFW_LOCATION}/lib + $ENV{GLFW_LOCATION}/lib + $ENV{PROGRAMFILES}/GLFW/lib + DOC "The GLFW library") + else() + find_library( GLFW_LIBRARY + NAMES + glfw3 + PATHS + ${GLFW_LOCATION}/lib + $ENV{GLFW_LOCATION}/lib + $ENV{PROGRAMFILES}/GLFW/lib + DOC "The GLFW library") + endif() +endif () + +if (${CMAKE_HOST_UNIX}) + find_path( GLFW_INCLUDE_DIR + NAMES + GLFW/glfw3.h + PATHS + ${GLFW_LOCATION}/include + $ENV{GLFW_LOCATION}/include + /usr/include + /usr/local/include + /sw/include + /opt/local/include + NO_DEFAULT_PATH + DOC "The directory where GLFW/glfw3.h resides" + ) + find_library( GLFW_LIBRARY + NAMES + glfw3 glfw + PATHS + ${GLFW_LOCATION}/lib + $ENV{GLFW_LOCATION}/lib + /usr/lib64 + /usr/lib + /usr/local/lib64 + /usr/local/lib + /sw/lib + /opt/local/lib + /usr/lib/x86_64-linux-gnu + NO_DEFAULT_PATH + DOC "The GLFW library") +endif () + +find_package_handle_standard_args(GLFW DEFAULT_MSG + GLFW_INCLUDE_DIR + GLFW_LIBRARY +) + +mark_as_advanced( GLFW_FOUND ) diff --git a/include/fea/ui/glfw3inputbackend.hpp b/include/fea/ui/glfw3inputbackend.hpp new file mode 100644 index 00000000..7e5e4e4b --- /dev/null +++ b/include/fea/ui/glfw3inputbackend.hpp @@ -0,0 +1,34 @@ +#pragma once +#include +#define NO_SDL_GLEXT +#include + +namespace fea +{ + class FEA_API GLFW3InputBackend : public InputBackend + { + public: + GLFW3InputBackend(); + + std::queue fetchEvents() override; + + bool isKeyPressed(Keyboard::Code code) override; + + bool isMouseButtonPressed(Mouse::Button b) override; + Vec2I getMouseGlobalPosition() override; //not supported + Vec2I getMouseWindowPosition() override; + void setMouseGlobalPosition(int32_t x, int32_t y) override; //not supported + void setMouseWindowPosition(int32_t x, int32_t y) override; //not supported + + bool isGamepadConnected(uint32_t id) override; //not supported + uint32_t getGamepadButtonCount(uint32_t id) override; //not supported + bool isGamepadButtonPressed(uint32_t id, uint32_t button) override; //not supported + bool gamepadHasAxis(uint32_t id, Gamepad::Axis axis) override; //not supported + float getGamepadAxisPosition(uint32_t id, Gamepad::Axis axis) override; //not supported + + void setGamepadThreshold(float threshold) override; //not supported + void setKeyRepeatEnabled(bool enabled) override; //not supported + private: + bool mKeyRepeat; + }; +} diff --git a/src/ui/glfw3windowbackend.h b/include/fea/ui/glfw3windowbackend.hpp similarity index 56% rename from src/ui/glfw3windowbackend.h rename to include/fea/ui/glfw3windowbackend.hpp index 01748f97..bb2c5bb7 100644 --- a/src/ui/glfw3windowbackend.h +++ b/include/fea/ui/glfw3windowbackend.hpp @@ -1,29 +1,21 @@ - // written by antonio trpeski // - - - - - - - - -#ifndef GLFW3WINDOWBACKEND_H_INCLUDED -#define GLFW3WINDOWBACKEND_H_INCLUDED +#pragma once +#include +#include namespace fea{ -class glfw3WindowBackend +class GLFW3WindowBackend : public WindowBackend { private: GLFWwindow *window; GLFWimage *images[2]; public: - void open(VideoMode mode, const std::string& title, uint32_t style, const ContextSettings& settings) const; + void open(VideoMode mode, const std::string& title, uint32_t style, const ContextSettings& settings) override; void close(); - bool isOpen(); - void getSettings(); - Vec2I getPosition(); + bool isOpen() const; + const ContextSettings getSettings() const override; //not supported + Vec2I getPosition() const; void setPosition(int32_t x, int32_t y); - vec2I getSize(); + Vec2I getSize() const; void setSize(int32_t w, int32_t h); void setTitle(const std::string& title); void setIcon(uint32_t width, uint32_t height, const uint8_t* pixels); @@ -31,16 +23,13 @@ class glfw3WindowBackend void setVSyncEnabled(bool enabled); void setMouseCursorVisible(bool visible); void setFramerateLimit(uint32_t limit); - bool setRenderingActive(bool active); + bool setRenderingActive(bool active) const override; void swapBuffers(); void lockCursor(bool lock); - ~glfw3WindowBackend(); + ~GLFW3WindowBackend(); }; } - - -#endif // GLFW3WINDOWBACKEND_H_INCLUDED diff --git a/pkg-config/fea-glfw.pc.in b/pkg-config/fea-glfw.pc.in new file mode 100644 index 00000000..8fd3b417 --- /dev/null +++ b/pkg-config/fea-glfw.pc.in @@ -0,0 +1,12 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=${prefix}/include + +Name: fea-glfw +Description: Feather Kit GLFW backends +Version: @fea_VERSION@ +URL: http://featherkit.therocode.net/ +Libs: -L${libdir} -lfea-glfw +Cflags: -I${includedir} +Requires.private: glfw diff --git a/src/ui/glfw3inputbackend.cpp b/src/ui/glfw3inputbackend.cpp new file mode 100644 index 00000000..638f4437 --- /dev/null +++ b/src/ui/glfw3inputbackend.cpp @@ -0,0 +1,79 @@ +#include + +namespace fea +{ + GLFW3InputBackend::GLFW3InputBackend(): + mKeyRepeat(true) + { + } + + std::queue GLFW3InputBackend::fetchEvents() + { + std::queue result; + return result; + } + + + bool GLFW3InputBackend::isKeyPressed(Keyboard::Code code) + { + return false; + } + + bool GLFW3InputBackend::isMouseButtonPressed(Mouse::Button b) + { + return false; + } + + Vec2I GLFW3InputBackend::getMouseGlobalPosition() + { + return {}; + } + + Vec2I GLFW3InputBackend::getMouseWindowPosition() + { + return {}; + } + + void GLFW3InputBackend::setMouseGlobalPosition(int32_t x, int32_t y) + { + } + + void GLFW3InputBackend::setMouseWindowPosition(int32_t x, int32_t y) + { + } + + bool GLFW3InputBackend::isGamepadConnected(uint32_t id) + { + return true; + } + + uint32_t GLFW3InputBackend::getGamepadButtonCount(uint32_t id) + { + return 0; + } + + bool GLFW3InputBackend::isGamepadButtonPressed(uint32_t id, uint32_t button) + { + return false; + } + + bool GLFW3InputBackend::gamepadHasAxis(uint32_t id, Gamepad::Axis axis) + { + return false; + } + + float GLFW3InputBackend::getGamepadAxisPosition(uint32_t id, Gamepad::Axis axis) + { + return 0.0f; + } + + void GLFW3InputBackend::setGamepadThreshold(float threshold) + { + (void) threshold; + } + + void GLFW3InputBackend::setKeyRepeatEnabled(bool enabled) + { + (void) enabled; + } +} diff --git a/src/ui/glfw3windowbackend.cpp b/src/ui/glfw3windowbackend.cpp new file mode 100644 index 00000000..78c30fb3 --- /dev/null +++ b/src/ui/glfw3windowbackend.cpp @@ -0,0 +1,123 @@ +#include +#include + +namespace fea{ + + void GLFW3WindowBackend::open(VideoMode mode, const std::string& title, uint32_t style, const ContextSettings& settings) + { + glfwInit(); + window = glfwCreateWindow(mode.mWidth, mode.mHeight, title.c_str(), NULL, NULL); + } + + void GLFW3WindowBackend::close() + { + glfwDestroyWindow(window); + } + + + bool GLFW3WindowBackend::isOpen() const + { + return window != nullptr; + } + + const ContextSettings GLFW3WindowBackend::getSettings() const + { + + // still looking on how to get and set context setings + + } + + Vec2I GLFW3WindowBackend::getPosition() const + { + Vec2I s; + s.x = 0; + s.y = 0; + + if(isOpen()) + glfwGetWindowPos(window, &s.x , &s.y ); + + return s; + } + + void GLFW3WindowBackend::setPosition(int32_t x, int32_t y) + { + if(isOpen()) + { + glfwSetWindowPos(window , x , y); + } + } + + Vec2I GLFW3WindowBackend::getSize() const + { + Vec2I s; + s.x = 0; + s.y = 0; + + if(isOpen()) + glfwGetWindowSize(window, &s.x, &s.y); + + return s; + } + + void GLFW3WindowBackend::setSize(int32_t w, int32_t h) + { + glfwSetWindowSize(window, w, h); + } + + void GLFW3WindowBackend::setTitle(const std::string& title) + { + glfwSetWindowTitle(window, title.c_str()); + } + + //void GLFW3WindowBackend::setIcon(const std::string &path_small , const std::string &path_big ) + void GLFW3WindowBackend::setIcon(uint32_t width, uint32_t height, const uint8_t* pixels) + { + //images[0] = load_icon(path_big.c_str()); + //images[1] = load_icon(path_small.c_str()); + + //glfwSetWindowIcon(window, 2 ,images) + } + + void GLFW3WindowBackend::setVisible(bool visible) + { + // still working on it + } + + void GLFW3WindowBackend::setVSyncEnabled(bool enabled) + { + // still woriking on it + } + + void GLFW3WindowBackend::setMouseCursorVisible(bool visible) + { + // still working on it + } + + void GLFW3WindowBackend::setFramerateLimit(uint32_t limit) + { + //still woriking on it + } + + bool GLFW3WindowBackend::setRenderingActive(bool active) const + { + // still working on it + } + + void GLFW3WindowBackend::swapBuffers() + { + glfwSwapBuffers(window); + } + + void GLFW3WindowBackend::lockCursor(bool lock) + { + if(isOpen()) + { + // still working on it + } + } + + GLFW3WindowBackend::~GLFW3WindowBackend() + { + close(); + } +} diff --git a/src/ui/glfw3windowbackend.hpp b/src/ui/glfw3windowbackend.hpp deleted file mode 100644 index 3dae34f9..00000000 --- a/src/ui/glfw3windowbackend.hpp +++ /dev/null @@ -1,133 +0,0 @@ - // written by antonio trpeski // - - - - - - - -#include -#include "glfw3windowbackend.h" - -namespace fea{ - -void glfw3WindowBackend::open(VideoMode mode, const std::string& title, uint32_t style, const ContextSettings& settings) -{ - glfwInit(); - window = glfwCreateWindow(mode.mwidth, mode.mheight, title.c_str(), NULL, NULL); -} - - void glfw3WindowBackend::close() - { - glfwDestroyWindow(window); - } - - - bool glfw3WindowBackend::isOpen() const - { - return window != nullptr; - } - - const ContextSettings glfw3WindowBackend::getSettings() const - { - - // still looking on how to get and set context setings - - } - - Vec2I glfw3WindowBackend::getPosition() const - { - Vec2I s; - s.x = 0; - s.y = 0; - - if(isOpen()) - glfwGetWindowPos(window, &s.x , &s.y ); - - return s; - } - - void glfw3WindowBackend::setPosition(int32_t x, int32_t y) - { - if(isOpen()) - { - glfwSetWindowPos(window , x , y); - } - } - - Vec2I glfw3WindowBackend::getSize() const - { - Vec2I s; - s.x = 0; - s.y = 0; - - if(isOpen()) - glfwGetWindowSize(window, &s.x, &s.y); - - return s; - } - - void glfw3WindowBackend::setSize(int32_t w, int32_t h) - { - glfwSetWindowSize(window, w, h); - } - - void glfw3WindowBackend::setTitle(const std::string& title) - { - glfwSetWindowTitle(window, title.c_str()); - } - - void glfw3WindowBackend::setIcon(const std::string &path_small , const std::string &path_big ) - { - images[0] = load_icon(path_big.c_str()); - images[1] = load_icon(path_small.c_str()); - - glfwSetWindowIcon(window, 2 ,images) - } - - void glfw3WindowBackend::setVisible(bool visible) - { - // still working on it - } - - void glfw3WindowBackend::setVSyncEnabled(bool enabled) - { - // still woriking on it - } - - void glfw3WindowBackend::setMouseCursorVisible(bool visible) - { - // still working on it - } - - void glfw3WindowBackend::setFramerateLimit(uint32_t limit) - { - //still woriking on it - } - - bool glfw3WindowBackend::setRenderingActive(bool active) const - { - // still working on it - } - - void glfw3WindowBackend::swapBuffers() - { - glfwSwapBuffers(window); - } - - void glfw3WindowBackend::lockCursor(bool lock) - { - if(isOpen()) - { - // still working on it - } - } - - glfw3WindowBackend::~glfw3WindowBackend() - { - close(); - } - - - -} From abb010e38e1aea9911cf5f0c0f8dd6875ef386c5 Mon Sep 17 00:00:00 2001 From: trpeski Date: Sat, 24 Sep 2016 11:58:03 +0300 Subject: [PATCH 12/16] Update glfw3inputbackend.cpp --- src/ui/glfw3inputbackend.cpp | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/ui/glfw3inputbackend.cpp b/src/ui/glfw3inputbackend.cpp index 638f4437..5afe170b 100644 --- a/src/ui/glfw3inputbackend.cpp +++ b/src/ui/glfw3inputbackend.cpp @@ -9,9 +9,33 @@ namespace fea std::queue GLFW3InputBackend::fetchEvents() { + std::queue result; - return result; - } + void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) + { +- +- ++ switch(action){ ++ case GLFW_PRESS: ++ switch(key) ++ { ++ case GLFW_KEY_E: ++ KeyEvent event; ++ Code code(4); ++ event = key_press(code,false,false,false,false); + result.push(event); ++ break; ++ } ++ break; ++ } ++ ++ + + } + + + + return result;} bool GLFW3InputBackend::isKeyPressed(Keyboard::Code code) From 4b007673d1484052725c2ba240fdff07bed96502 Mon Sep 17 00:00:00 2001 From: trpeski Date: Sat, 24 Sep 2016 11:59:40 +0300 Subject: [PATCH 13/16] Update glfw3inputbackend.cpp --- src/ui/glfw3inputbackend.cpp | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/ui/glfw3inputbackend.cpp b/src/ui/glfw3inputbackend.cpp index 5afe170b..50d8eb76 100644 --- a/src/ui/glfw3inputbackend.cpp +++ b/src/ui/glfw3inputbackend.cpp @@ -8,14 +8,14 @@ namespace fea } std::queue GLFW3InputBackend::fetchEvents() - { - - std::queue result; - void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) - { -- -- -+ switch(action){ + { + std::queue result; +- return result; ++ glfwSetKeyCallback(window, key_callback); ++ ++ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) ++ { ++ switch(action){ + case GLFW_PRESS: + switch(key) + { @@ -23,20 +23,15 @@ namespace fea + KeyEvent event; + Code code(4); + event = key_press(code,false,false,false,false); - result.push(event); + break; + } + break; + } + -+ - - } - - - - return result;} - ++ } ++ } ++ return event; + } bool GLFW3InputBackend::isKeyPressed(Keyboard::Code code) { From 27702897833c04222ee938e42dfb46a79d57d47f Mon Sep 17 00:00:00 2001 From: trpeski Date: Sat, 24 Sep 2016 12:01:11 +0300 Subject: [PATCH 14/16] Update glfw3windowbackend.cpp --- src/ui/glfw3windowbackend.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/ui/glfw3windowbackend.cpp b/src/ui/glfw3windowbackend.cpp index 78c30fb3..8e35eb4b 100644 --- a/src/ui/glfw3windowbackend.cpp +++ b/src/ui/glfw3windowbackend.cpp @@ -2,6 +2,18 @@ #include namespace fea{ + + int key_press(KeyBoard::Code pkey_code ,bool psystem,bool pcontrol,bool pshift,bool palt ) ++ { ++ KeyEvent Event; ++ Event.code =pKey_code; ++ Event.shift = pshift; ++ Event.control = pcontrol; ++ Event.alt = palt; ++ Event.system = psystem; ++ ++ return Event; ++ } void GLFW3WindowBackend::open(VideoMode mode, const std::string& title, uint32_t style, const ContextSettings& settings) { From a2d6b262cd6f0fd06cb9be122812858c58231bb8 Mon Sep 17 00:00:00 2001 From: trpeski Date: Mon, 3 Oct 2016 09:26:11 +0300 Subject: [PATCH 15/16] Update glfw3windowbackend.cpp --- src/ui/glfw3windowbackend.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/ui/glfw3windowbackend.cpp b/src/ui/glfw3windowbackend.cpp index 8e35eb4b..2c4a592e 100644 --- a/src/ui/glfw3windowbackend.cpp +++ b/src/ui/glfw3windowbackend.cpp @@ -4,16 +4,16 @@ namespace fea{ int key_press(KeyBoard::Code pkey_code ,bool psystem,bool pcontrol,bool pshift,bool palt ) -+ { -+ KeyEvent Event; -+ Event.code =pKey_code; -+ Event.shift = pshift; -+ Event.control = pcontrol; -+ Event.alt = palt; -+ Event.system = psystem; -+ -+ return Event; -+ } + { + KeyEvent Event; + Event.code =pKey_code; + Event.shift = pshift; + Event.control = pcontrol; + Event.alt = palt; + Event.system = psystem; + + return Event; + } void GLFW3WindowBackend::open(VideoMode mode, const std::string& title, uint32_t style, const ContextSettings& settings) { From 1739b666213693e2b47547b108a2c82b8307eadd Mon Sep 17 00:00:00 2001 From: trpeski Date: Tue, 4 Oct 2016 11:45:29 +0300 Subject: [PATCH 16/16] Update glfw3inputbackend.cpp --- src/ui/glfw3inputbackend.cpp | 54 ++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/src/ui/glfw3inputbackend.cpp b/src/ui/glfw3inputbackend.cpp index 50d8eb76..55de7b86 100644 --- a/src/ui/glfw3inputbackend.cpp +++ b/src/ui/glfw3inputbackend.cpp @@ -10,27 +10,39 @@ namespace fea std::queue GLFW3InputBackend::fetchEvents() { std::queue result; -- return result; -+ glfwSetKeyCallback(window, key_callback); -+ -+ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) -+ { -+ switch(action){ -+ case GLFW_PRESS: -+ switch(key) -+ { -+ case GLFW_KEY_E: -+ KeyEvent event; -+ Code code(4); -+ event = key_press(code,false,false,false,false); -+ break; -+ } -+ break; -+ } -+ -+ } -+ } -+ return event; + glfwSetKeyCallback(window, key_callback); + + void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) + { + switch(action){ + case GLFW_PRESS: + switch(key) + { + case GLFW_KEY_E: + KeyEvent event; + Code code(4); + event = key_press(code,false,false,false,false); + break; + + case GLFW_KEY_A: + KeyEvent event; + Code code(0); + event = key_press(code,false,false,false,false); + break; + + case GLFW_KEY_B: + KeyEvent event; + Code code(1); + event = key_press(code,false,false,false,false); + break; + + } + break; + } + + } + } + return event; } bool GLFW3InputBackend::isKeyPressed(Keyboard::Code code)