1#ifndef DesktopDisplay_H
2#define DesktopDisplay_H
10#include <vulkan/vulkan.h>
11#define GLFW_INCLUDE_NONE
12#include <GLFW/glfw3.h>
106 GLFWmousebuttonfun mouseButtonCallback,
107 GLFWscrollfun mouseScrollCallback,
120 for (
auto icon : logo)
122 stbi_image_free(icon.pixels);
134 bool isOpen(){
if (glfwWindow != NULL) {
return !glfwWindow ? false :
true; }
return false; }
135 bool closing(){
return glfwWindowShouldClose(glfwWindow); }
141 if (glfwWindow == NULL)
145 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
146 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
147 glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT,
true);
148 glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
149 glfwWindowHint(GLFW_COCOA_RETINA_FRAMEBUFFER, windowConfig.
COCOA_RETINA);
150 glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
153 int wxpos, wypos, wwidth, wheight;
154 glfwGetMonitorWorkarea(glfwGetPrimaryMonitor(), &wxpos, &wypos, &wwidth, &wheight);
157 GLFWwindow * temporaryWindow = glfwCreateWindow(1, 1,
"", NULL, NULL);
158 int fleft, ftop, fright, fbottom;
159 glfwGetWindowFrameSize(temporaryWindow, &fleft, &ftop, &fright, &fbottom);
160 glfwWindowShouldClose(temporaryWindow);
161 glfwDestroyWindow(temporaryWindow);
165 glm::ivec2 pos(wxpos, wypos+ftop);
167 glm::ivec2 pos(wxpos, wypos);
172 const GLFWvidmode * mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
190 glfwWindow = glfwCreateWindow(
getResX(),
getResY(),title,NULL,NULL);
196 void close(){
if (glfwWindow != NULL) { glfwDestroyWindow(glfwWindow); glfwWindow = NULL; } }
198 void setAsFocus(){
if (glfwWindow != NULL) { glfwMakeContextCurrent(glfwWindow); } }
209 void mousePosition(
double & x,
double & y){
if (glfwWindow != NULL){ glfwGetCursorPos(glfwWindow,&x,&y); } }
213 if (glfwWindow != NULL)
215 glfwSetCursorPos(glfwWindow, x, y);
225 if (glfwWindowShouldClose(glfwWindow)){
close(); }
251 return std::find(ts.cbegin(), ts.cend(), action) != ts.cend();
264 for (
const auto & action : actions)
266 if (std::find(ts.cbegin(), ts.cend(), action) != ts.cend())
277 std::vector<EventType> e;
284 for (
auto evt : data.
events[code])
286 e.push_back(evt.type);
300 return data.
events[code][0];
306 std::map<int, std::vector<Event>>
events;
320 void setIcon(
const std::vector<std::vector<std::byte>> & icons)
322 glfwSetWindowIcon(glfwWindow, 0, NULL);
324 for (
auto icon : icons)
327 unsigned char * chData =
reinterpret_cast<unsigned char*
>(icon.data());
328 image.pixels = stbi_load_from_memory
337 logo.push_back(image);
340 glfwSetWindowIcon(glfwWindow,logo.size(),logo.data());
346 if (glfwWindow != NULL)
348 glfwGetFramebufferSize(glfwWindow, &s.x, &s.y);
356 if (glfwWindow != NULL)
358 glfwGetWindowSize(glfwWindow, &s.x, &s.y);
366 if (glfwWindow != NULL)
368 glfwGetWindowContentScale(glfwWindow, &s.x, &s.y);
376 if (glfwWindow != NULL)
378 glfwGetWindowFrameSize(glfwWindow, &s.x, &s.y, &s.z, &s.w);
386 if (glfwWindow != NULL)
388 glfwGetWindowPos(glfwWindow, &s.x, &s.y);
395 if (glfwWindow != NULL)
397 glfwSetWindowPos(glfwWindow, s.x, s.y);
405 std::vector<GLFWimage> logo;
407 GLFWwindow * glfwWindow;
413 void swap(){
if (glfwWindow != NULL) { glfwSwapBuffers(glfwWindow); } }
415 void handleEvents(){
if (glfwWindow != NULL){ glfwPollEvents(); } }
Definition desktopDisplay.h:61
void setMousePosition(double x, double y)
Definition desktopDisplay.h:211
glm::ivec4 windowFrameSize() const
Definition desktopDisplay.h:373
void setWindowPosition(glm::ivec2 s)
Definition desktopDisplay.h:393
void loop()
Definition desktopDisplay.h:221
void keyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
void setAsFocus()
Definition desktopDisplay.h:198
std::vector< Event > getEvents(int code)
Definition desktopDisplay.h:230
bool isOpen()
Definition desktopDisplay.h:134
std::vector< EventType > getEventTypes(int code)
Definition desktopDisplay.h:275
void mousePosition(double &x, double &y)
Definition desktopDisplay.h:209
~DesktopDisplay()
Definition desktopDisplay.h:118
glm::ivec2 windowSize() const
Definition desktopDisplay.h:353
void setIcon(const std::vector< std::vector< std::byte > > &icons)
Definition desktopDisplay.h:320
int getKeyLastState(int key)
Definition desktopDisplay.h:219
bool keyHasAnyEvents(int key, std::vector< EventType > actions)
Definition desktopDisplay.h:255
bool keyHasEvent(int key, EventType action)
Definition desktopDisplay.h:242
GLFWwindow * getWindow() const
Definition desktopDisplay.h:132
bool closing()
Definition desktopDisplay.h:135
Event getEvent(int code)
Definition desktopDisplay.h:292
glm::vec2 contentScale() const
Definition desktopDisplay.h:363
void open()
Definition desktopDisplay.h:137
void close()
Definition desktopDisplay.h:196
glm::ivec2 windowPosition() const
Definition desktopDisplay.h:383
glm::ivec2 frameBufferSize() const
Definition desktopDisplay.h:343
unsigned getResY() const
Definition display.h:26
virtual void throttle()
Definition display.h:49
glm::ivec2 resolution
Definition display.h:43
unsigned getResX() const
Definition display.h:25
A drawable graphic.
Definition id.h:10
void defaultScrollCallback(GLFWwindow *window, double x, double y)
Definition desktopDisplay.cpp:61
EventType
Definition event.h:9
void parseAction(GLFWwindow *window, int code, int action)
Definition desktopDisplay.cpp:8
void defaultMouseButtonCallback(GLFWwindow *window, int button, int action, int mods)
Definition desktopDisplay.cpp:50
void defaultKeyEventCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
Definition desktopDisplay.cpp:32
Definition desktopDisplay.h:65
bool CLIP_TO_WORK_AREA
Definition desktopDisplay.h:98
bool VULKAN
Definition desktopDisplay.h:93
bool CLIP_TO_MONITOR
Definition desktopDisplay.h:96
bool COCOA_RETINA
Definition desktopDisplay.h:94
Config(const Config &c)
Definition desktopDisplay.h:86
Config(bool vulkan, bool cocoa, bool clipMonitor, bool clipWorkArea)
Definition desktopDisplay.h:74
Config()
Definition desktopDisplay.h:66
Definition desktopDisplay.h:305
double scrollY
Definition desktopDisplay.h:308
void clear()
Definition desktopDisplay.h:311
std::map< int, std::vector< Event > > events
Definition desktopDisplay.h:306
double scrollX
Definition desktopDisplay.h:307
bool scrolled
Definition desktopDisplay.h:309