Conquer Space 0.0.0
A space themed grand strategy game set in the near future, with realistic orbital mechanics, and an emphasis on economics and politics.
glfwwindow.h
Go to the documentation of this file.
1/* Conquer Space
2* Copyright (C) 2021 Conquer Space
3*
4* This program is free software: you can redistribute it and/or modify
5* it under the terms of the GNU General Public License as published by
6* the Free Software Foundation, either version 3 of the License, or
7* (at your option) any later version.
8*
9* This program is distributed in the hope that it will be useful,
10* but WITHOUT ANY WARRANTY; without even the implied warranty of
11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12* GNU General Public License for more details.
13*
14* You should have received a copy of the GNU General Public License
15* along with this program. If not, see <https://www.gnu.org/licenses/>.
16*/
17#pragma once
18
19#include <vector>
20
21#include "engine/application.h"
22#include "engine/window.h"
23
24namespace cqsp::engine {
26 public:
27 explicit GLWindow(Application* app) : app(app) {}
28
29 bool ButtonIsHeld(int btn) const { return m_keys_held[btn]; }
30 bool ButtonIsReleased(int btn) const { return m_keys_released[btn]; }
31 bool ButtonIsPressed(int btn) const { return m_keys_pressed[btn]; }
32 double GetMouseX() const { return m_mouse_x; }
33 double GetMouseY() const { return m_mouse_y; }
34
35 bool MouseButtonIsHeld(int btn) const { return m_mouse_keys_held[btn]; }
36 bool MouseButtonIsReleased(int btn) const { return m_mouse_keys_released[btn]; }
37 bool MouseButtonIsPressed(int btn) const { return m_mouse_keys_pressed[btn]; }
38
40
41 void KeyboardCallback(GLFWwindow* _w, int key, int scancode, int action, int mods);
42
43 void MousePositionCallback(GLFWwindow* _w, double xpos, double ypos) {
44 m_mouse_x = xpos;
45 m_mouse_y = ypos;
47 }
48
49 void MouseEnterCallback(GLFWwindow* _w, int entered) {
51 }
52
53 void MouseButtonCallback(GLFWwindow* _w, int button, int action, int mods);
54
55 void ScrollCallback(GLFWwindow* _w, double xoffset, double yoffset) {
56 m_scroll_amount = yoffset;
58 }
59
60 void CharacterCallback(GLFWwindow* window, unsigned int codepoint) {
61 // Callback
62 code_input.push_back(codepoint);
64 }
65
66 void DropCallback(GLFWwindow* _w, int count, const char** paths) {}
67
68 void FrameBufferSizeCallback(GLFWwindow* window, int width, int height);
69
70 void SetCallbacks();
71
72 void OnFrame();
73
74 void SetWindowSize(int width, int height) {
75 m_window_width = width;
76 m_window_height = height;
77 glfwSetWindowSize(window, width, height);
78 }
79
80 bool WindowSizeChanged() const { return window_size_changed; }
81
82 int GetScrollAmount() const { return m_scroll_amount; }
83 int GetWindowHeight() const { return m_window_height; }
84 int GetWindowWidth() const { return m_window_width; }
85
86 void InitWindow(int width, int height);
87
88 double MouseButtonLastReleased(int btn) const { return m_mouse_keys_last_pressed[btn]; }
89
90 bool MouseButtonDoubleClicked(int btn) const {
91 bool is_pressed_long_enough = (m_mouse_pressed_time[btn]) <= 0.5f;
92 return (MouseButtonIsPressed(btn) && is_pressed_long_enough);
93 }
94
95 void Destroy();
96
97 float GetTime() const;
98
99 void SetFullScreen(bool fullscreen) const;
100
101 bool ShouldExit() const;
102 bool ExitApplication();
103
104 void SetIcon(std::string_view path);
105
106 GLFWwindow* window;
107
109
110 private:
112 double m_mouse_x;
113 double m_mouse_y;
114
117
118 bool m_mouse_keys_held[GLFW_MOUSE_BUTTON_LAST] = {false};
119 bool m_mouse_keys_released[GLFW_MOUSE_BUTTON_LAST] = {false};
120 bool m_mouse_keys_pressed[GLFW_MOUSE_BUTTON_LAST] = {false};
121
122 double m_mouse_keys_last_pressed[GLFW_MOUSE_BUTTON_LAST] = {0.0};
123 double m_mouse_pressed_time[GLFW_MOUSE_BUTTON_LAST] = {0.0};
124
125 bool m_keys_held[GLFW_KEY_LAST] = {false};
126 bool m_keys_released[GLFW_KEY_LAST] = {false};
127 bool m_keys_pressed[GLFW_KEY_LAST] = {false};
128
130
132
133 public:
134 std::vector<int> keys_pressed_last;
135 std::vector<int> keys_released_last;
136 std::vector<unsigned int> code_input;
137
139};
140} // namespace cqsp::engine
Definition: application.h:47
Rml::Context * GetRmlUiContext()
Definition: application.h:162
Definition: glfwwindow.h:25
void InitWindow(int width, int height)
Definition: glfwwindow.cpp:163
double GetMouseY() const
Definition: glfwwindow.h:33
void Destroy()
Definition: glfwwindow.cpp:115
bool ButtonIsHeld(int btn) const
Definition: glfwwindow.h:29
std::vector< unsigned int > code_input
Definition: glfwwindow.h:136
GLFWwindow * window
Definition: glfwwindow.h:106
void SetIcon(std::string_view path)
Definition: glfwwindow.cpp:140
void SetFullScreen(bool fullscreen) const
Definition: glfwwindow.cpp:122
Application * app
Definition: glfwwindow.h:108
GLWindow(Application *app)
Definition: glfwwindow.h:27
int GetWindowWidth() const
Definition: glfwwindow.h:84
double m_mouse_pressed_time[GLFW_MOUSE_BUTTON_LAST]
Definition: glfwwindow.h:123
void FrameBufferSizeCallback(GLFWwindow *window, int width, int height)
Definition: glfwwindow.cpp:55
double m_scroll_amount
Definition: glfwwindow.h:129
void MouseButtonCallback(GLFWwindow *_w, int button, int action, int mods)
Definition: glfwwindow.cpp:40
bool MouseButtonIsReleased(int btn) const
Definition: glfwwindow.h:36
bool m_mouse_keys_pressed[GLFW_MOUSE_BUTTON_LAST]
Definition: glfwwindow.h:120
void MouseEnterCallback(GLFWwindow *_w, int entered)
Definition: glfwwindow.h:49
double m_mouse_y
Definition: glfwwindow.h:113
bool MouseButtonIsPressed(int btn) const
Definition: glfwwindow.h:37
float GetTime() const
Definition: glfwwindow.cpp:120
bool ButtonIsPressed(int btn) const
Definition: glfwwindow.h:31
void DropCallback(GLFWwindow *_w, int count, const char **paths)
Definition: glfwwindow.h:66
double MouseButtonLastReleased(int btn) const
Definition: glfwwindow.h:88
bool m_mouse_keys_held[GLFW_MOUSE_BUTTON_LAST]
Definition: glfwwindow.h:118
void CharacterCallback(GLFWwindow *window, unsigned int codepoint)
Definition: glfwwindow.h:60
bool m_mouse_keys_released[GLFW_MOUSE_BUTTON_LAST]
Definition: glfwwindow.h:119
double m_mouse_y_on_pressed
Definition: glfwwindow.h:116
void SetCallbacks()
Definition: glfwwindow.cpp:64
void SetWindowSize(int width, int height)
Definition: glfwwindow.h:74
bool window_size_changed
Definition: glfwwindow.h:111
bool ButtonIsReleased(int btn) const
Definition: glfwwindow.h:30
void OnFrame()
Any cleanups or clearing the window has to do each frame
Definition: glfwwindow.cpp:147
bool WindowSizeChanged() const
Definition: glfwwindow.h:80
bool ExitApplication()
Definition: glfwwindow.cpp:135
double m_mouse_x
Definition: glfwwindow.h:112
int GetScrollAmount() const
Definition: glfwwindow.h:82
void KeyboardCallback(GLFWwindow *_w, int key, int scancode, int action, int mods)
Definition: glfwwindow.cpp:26
int m_mods
Definition: glfwwindow.h:138
std::vector< int > keys_released_last
Definition: glfwwindow.h:135
bool m_keys_held[GLFW_KEY_LAST]
Definition: glfwwindow.h:125
int m_window_width
Definition: glfwwindow.h:131
void ScrollCallback(GLFWwindow *_w, double xoffset, double yoffset)
Definition: glfwwindow.h:55
void MousePositionCallback(GLFWwindow *_w, double xpos, double ypos)
Definition: glfwwindow.h:43
bool ShouldExit() const
Definition: glfwwindow.cpp:133
bool MouseButtonIsHeld(int btn) const
Definition: glfwwindow.h:35
double GetMouseX() const
Definition: glfwwindow.h:32
bool MouseButtonDoubleClicked(int btn) const
Definition: glfwwindow.h:90
bool m_keys_released[GLFW_KEY_LAST]
Definition: glfwwindow.h:126
std::vector< int > keys_pressed_last
Definition: glfwwindow.h:134
int GetWindowHeight() const
Definition: glfwwindow.h:83
bool m_keys_pressed[GLFW_KEY_LAST]
Definition: glfwwindow.h:127
bool MouseDragged() const
Definition: glfwwindow.h:39
double m_mouse_x_on_pressed
Definition: glfwwindow.h:115
double m_mouse_keys_last_pressed[GLFW_MOUSE_BUTTON_LAST]
Definition: glfwwindow.h:122
int m_window_height
Definition: glfwwindow.h:131
The window handles the initialization of the callbacks, and all the input and output....
Definition: window.h:25
bool ProcessCursorPosCallback(Rml::Context *context, double xpos, double ypos, int mods)
Definition: RmlUi_Platform_GLFW.cpp:111
bool ProcessCharCallback(Rml::Context *context, unsigned int codepoint)
Definition: RmlUi_Platform_GLFW.cpp:96
bool ProcessCursorEnterCallback(Rml::Context *context, int entered)
Definition: RmlUi_Platform_GLFW.cpp:103
bool ProcessScrollCallback(Rml::Context *context, double yoffset, int mods)
Definition: RmlUi_Platform_GLFW.cpp:134
Definition: application.cpp:54