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-2025 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 {
25class GLWindow : public Window {
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 bool MouseMoved() const { return m_mouse_moved; }
41
42 void KeyboardCallback(GLFWwindow* _w, int key, int scancode, int action, int mods);
43
44 void MousePositionCallback(GLFWwindow* _w, double xpos, double ypos);
45
46 void MouseEnterCallback(GLFWwindow* _w, int entered);
47
48 void MouseButtonCallback(GLFWwindow* _w, int button, int action, int mods);
49
50 void ScrollCallback(GLFWwindow* _w, double xoffset, double yoffset);
51
52 void CharacterCallback(GLFWwindow* window, unsigned int codepoint);
53
54 void DropCallback(GLFWwindow* _w, int count, const char** paths) {}
55
56 void FrameBufferSizeCallback(GLFWwindow* window, int width, int height);
57
58 void SetCallbacks();
59
60 void OnFrame();
61
62 void SetWindowSize(int width, int height) {
63 m_window_width = width;
64 m_window_height = height;
65 glfwSetWindowSize(window, width, height);
66 }
67
68 bool WindowSizeChanged() const { return window_size_changed; }
69
70 int GetScrollAmount() const { return m_scroll_amount; }
71 int GetWindowHeight() const { return m_window_height; }
72 int GetWindowWidth() const { return m_window_width; }
73
74 bool InitWindow(int width, int height);
75
76 double MouseButtonLastReleased(int btn) const { return m_mouse_keys_last_pressed[btn]; }
77
78 bool MouseButtonDoubleClicked(int btn) const;
79
80 void Destroy();
81
82 float GetTime() const;
83
84 void SetFullScreen(bool fullscreen) const;
85
86 bool ShouldExit() const;
87 bool ExitApplication();
88
89 void SetIcon(std::string_view path);
90
91 bool RmlUiCapturedKeyboardInput() const override { return rmlui_keyboard_processed; }
92
93 bool RmlUiCapturedMouseInput() const override { return rmlui_mouse_processed; }
94
95 bool RmlUiCapturedTextInput() const override { return rmlui_text_processed; }
96
97 GLFWwindow* window;
98
100
101 private:
104 double m_mouse_x;
105 double m_mouse_y;
106
111
114
115 bool m_mouse_keys_held[GLFW_MOUSE_BUTTON_LAST] = {false};
116 bool m_mouse_keys_released[GLFW_MOUSE_BUTTON_LAST] = {false};
117 bool m_mouse_keys_pressed[GLFW_MOUSE_BUTTON_LAST] = {false};
118
119 double m_mouse_keys_last_pressed[GLFW_MOUSE_BUTTON_LAST] = {0.0};
120 double m_mouse_pressed_time[GLFW_MOUSE_BUTTON_LAST] = {0.0};
121
122 bool m_keys_held[GLFW_KEY_LAST] = {false};
123 bool m_keys_released[GLFW_KEY_LAST] = {false};
124 bool m_keys_pressed[GLFW_KEY_LAST] = {false};
125
127
129
133
134 public:
135 std::vector<int> keys_pressed_last;
136 std::vector<int> keys_released_last;
137 std::vector<unsigned int> code_input;
138
140};
141} // namespace cqsp::engine
Definition: application.h:61
Definition: glfwwindow.h:25
double GetMouseY() const
Definition: glfwwindow.h:33
void Destroy()
Definition: glfwwindow.cpp:161
bool MouseMoved() const
Definition: glfwwindow.h:40
bool ButtonIsHeld(int btn) const
Definition: glfwwindow.h:29
std::vector< unsigned int > code_input
Definition: glfwwindow.h:137
GLFWwindow * window
Definition: glfwwindow.h:97
void SetIcon(std::string_view path)
Definition: glfwwindow.cpp:186
bool rmlui_keyboard_processed
Definition: glfwwindow.h:130
bool rmlui_text_processed
Definition: glfwwindow.h:132
void SetFullScreen(bool fullscreen) const
Definition: glfwwindow.cpp:168
Application * app
Definition: glfwwindow.h:99
GLWindow(Application *app)
Definition: glfwwindow.h:27
int GetWindowWidth() const
Definition: glfwwindow.h:72
bool RmlUiCapturedKeyboardInput() const override
Definition: glfwwindow.h:91
double m_mouse_pressed_time[GLFW_MOUSE_BUTTON_LAST]
Definition: glfwwindow.h:120
bool InitWindow(int width, int height)
Definition: glfwwindow.cpp:209
bool RmlUiCapturedMouseInput() const override
Definition: glfwwindow.h:93
bool rmlui_mouse_processed
Definition: glfwwindow.h:131
void FrameBufferSizeCallback(GLFWwindow *window, int width, int height)
Definition: glfwwindow.cpp:73
double m_scroll_amount
Definition: glfwwindow.h:126
void MouseButtonCallback(GLFWwindow *_w, int button, int action, int mods)
Definition: glfwwindow.cpp:54
bool MouseButtonIsReleased(int btn) const
Definition: glfwwindow.h:36
bool m_mouse_keys_pressed[GLFW_MOUSE_BUTTON_LAST]
Definition: glfwwindow.h:117
void MouseEnterCallback(GLFWwindow *_w, int entered)
Definition: glfwwindow.cpp:100
double m_mouse_y
Definition: glfwwindow.h:105
bool MouseButtonIsPressed(int btn) const
Definition: glfwwindow.h:37
float GetTime() const
Definition: glfwwindow.cpp:166
bool ButtonIsPressed(int btn) const
Definition: glfwwindow.h:31
void DropCallback(GLFWwindow *_w, int count, const char **paths)
Definition: glfwwindow.h:54
bool RmlUiCapturedTextInput() const override
Definition: glfwwindow.h:95
double MouseButtonLastReleased(int btn) const
Definition: glfwwindow.h:76
bool m_mouse_keys_held[GLFW_MOUSE_BUTTON_LAST]
Definition: glfwwindow.h:115
void CharacterCallback(GLFWwindow *window, unsigned int codepoint)
Definition: glfwwindow.cpp:104
bool m_mouse_keys_released[GLFW_MOUSE_BUTTON_LAST]
Definition: glfwwindow.h:116
double m_mouse_y_on_pressed
Definition: glfwwindow.h:108
void SetCallbacks()
Definition: glfwwindow.cpp:110
void SetWindowSize(int width, int height)
Definition: glfwwindow.h:62
bool window_size_changed
Definition: glfwwindow.h:102
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:193
bool WindowSizeChanged() const
Definition: glfwwindow.h:68
bool ExitApplication()
Definition: glfwwindow.cpp:181
double m_mouse_x
Definition: glfwwindow.h:104
int GetScrollAmount() const
Definition: glfwwindow.h:70
void KeyboardCallback(GLFWwindow *_w, int key, int scancode, int action, int mods)
Definition: glfwwindow.cpp:28
int m_mods
Definition: glfwwindow.h:139
double m_mouse_y_last_clicked
Definition: glfwwindow.h:113
std::vector< int > keys_released_last
Definition: glfwwindow.h:136
int m_mouse_button_last_pressed
Definition: glfwwindow.h:109
bool m_keys_held[GLFW_KEY_LAST]
Definition: glfwwindow.h:122
int m_mouse_button_current_pressed
Definition: glfwwindow.h:110
int m_window_width
Definition: glfwwindow.h:128
void ScrollCallback(GLFWwindow *_w, double xoffset, double yoffset)
Definition: glfwwindow.cpp:95
bool m_mouse_moved
Definition: glfwwindow.h:103
void MousePositionCallback(GLFWwindow *_w, double xpos, double ypos)
Definition: glfwwindow.cpp:88
bool ShouldExit() const
Definition: glfwwindow.cpp:179
double m_mouse_x_last_clicked
Definition: glfwwindow.h:112
bool MouseButtonIsHeld(int btn) const
Definition: glfwwindow.h:35
double GetMouseX() const
Definition: glfwwindow.h:32
bool MouseButtonDoubleClicked(int btn) const
Definition: glfwwindow.cpp:42
bool m_keys_released[GLFW_KEY_LAST]
Definition: glfwwindow.h:123
std::vector< int > keys_pressed_last
Definition: glfwwindow.h:135
int GetWindowHeight() const
Definition: glfwwindow.h:71
bool m_keys_pressed[GLFW_KEY_LAST]
Definition: glfwwindow.h:124
bool MouseDragged() const
Definition: glfwwindow.h:39
double m_mouse_x_on_pressed
Definition: glfwwindow.h:107
double m_mouse_keys_last_pressed[GLFW_MOUSE_BUTTON_LAST]
Definition: glfwwindow.h:119
int m_window_height
Definition: glfwwindow.h:128
The window handles the initialization of the callbacks, and all the input and output....
Definition: window.h:24
Definition: application.cpp:56