1#ifndef DesktopDisplay_H
2#define DesktopDisplay_H
10#include <vulkan/vulkan.h>
11#define GLFW_INCLUDE_NONE
12#include <GLFW/glfw3.h>
14#include <imgui/imgui.h>
15#include <imgui/imgui_impl_glfw.h>
16#include <imgui/imgui_impl_opengl3.h>
28#include <imgui/imgui_impl_win32.h>
32#include <imgui/imgui_impl_osx.h>
115 GLFWmousebuttonfun mouseButtonCallback,
116 GLFWscrollfun mouseScrollCallback,
129 for (
auto icon : logo)
131 stbi_image_free(icon.pixels);
143 bool isOpen(){
if (glfwWindow != NULL) {
return !glfwWindow ? false :
true; }
return false; }
144 bool closing(){
return glfwWindowShouldClose(glfwWindow); }
150 if (glfwWindow == NULL)
154 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
155 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
156 glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT,
true);
157 glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
158 glfwWindowHint(GLFW_COCOA_RETINA_FRAMEBUFFER, windowConfig.
COCOA_RETINA);
159 glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
162 int wxpos, wypos, wwidth, wheight;
163 glfwGetMonitorWorkarea(glfwGetPrimaryMonitor(), &wxpos, &wypos, &wwidth, &wheight);
166 GLFWwindow * temporaryWindow = glfwCreateWindow(1, 1,
"", NULL, NULL);
167 int fleft, ftop, fright, fbottom;
168 glfwGetWindowFrameSize(temporaryWindow, &fleft, &ftop, &fright, &fbottom);
169 glfwWindowShouldClose(temporaryWindow);
170 glfwDestroyWindow(temporaryWindow);
174 glm::ivec2 pos(wxpos, wypos+ftop);
176 glm::ivec2 pos(wxpos, wypos);
181 const GLFWvidmode * mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
199 main_scale = ImGui_ImplGlfw_GetContentScaleForMonitor(glfwGetPrimaryMonitor());
200 glfwWindow = glfwCreateWindow(
getResX()*main_scale,
getResY()*main_scale,title,NULL,NULL);
206 void close(){
if (glfwWindow != NULL) { glfwDestroyWindow(glfwWindow); glfwWindow = NULL; } }
208 void setAsFocus(){
if (glfwWindow != NULL) { glfwMakeContextCurrent(glfwWindow); } }
219 void mousePosition(
double & x,
double & y){
if (glfwWindow != NULL){ glfwGetCursorPos(glfwWindow,&x,&y); } }
223 if (glfwWindow != NULL)
225 glfwSetCursorPos(glfwWindow, x, y);
235 if (glfwWindowShouldClose(glfwWindow)){
close(); }
261 return std::find(ts.cbegin(), ts.cend(), action) != ts.cend();
274 for (
const auto & action : actions)
276 if (std::find(ts.cbegin(), ts.cend(), action) != ts.cend())
287 std::vector<EventType> e;
294 for (
auto evt : data.
events[code])
296 e.push_back(evt.type);
310 return data.
events[code][0];
316 std::map<int, std::vector<Event>>
events;
330 void setIcon(
const std::vector<std::vector<std::byte>> & icons)
332 glfwSetWindowIcon(glfwWindow, 0, NULL);
334 for (
auto icon : icons)
337 unsigned char * chData =
reinterpret_cast<unsigned char*
>(icon.data());
338 image.pixels = stbi_load_from_memory
347 logo.push_back(image);
350 glfwSetWindowIcon(glfwWindow,logo.size(),logo.data());
356 if (glfwWindow != NULL)
358 glfwGetFramebufferSize(glfwWindow, &s.x, &s.y);
366 if (glfwWindow != NULL)
368 glfwGetWindowSize(glfwWindow, &s.x, &s.y);
376 if (glfwWindow != NULL)
378 glfwGetWindowContentScale(glfwWindow, &s.x, &s.y);
386 if (glfwWindow != NULL)
388 glfwGetWindowFrameSize(glfwWindow, &s.x, &s.y, &s.z, &s.w);
396 if (glfwWindow != NULL)
398 glfwGetWindowPos(glfwWindow, &s.x, &s.y);
405 if (glfwWindow != NULL)
407 glfwSetWindowPos(glfwWindow, s.x, s.y);
414 if (glfwWindow != NULL)
422 IMGUI_CHECKVERSION();
423 ImGui::CreateContext();
424 ImGuiIO& io = ImGui::GetIO(); (void)io;
425 io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
427 ImGui::StyleColorsDark();
429 ImGuiStyle& style = ImGui::GetStyle();
430 style.ScaleAllSizes(main_scale);
431 style.FontScaleDpi = main_scale;
433 ImGui_ImplGlfw_InitForOpenGL(glfwWindow,
true);
434 ImGui_ImplOpenGL3_Init(
"#version " GLSL_VERSION
"");
441 std::vector<GLFWimage> logo;
443 GLFWwindow * glfwWindow;
451 void swap(){
if (glfwWindow != NULL) { glfwSwapBuffers(glfwWindow); } }
453 void handleEvents(){
if (glfwWindow != NULL){ glfwPollEvents(); } }
Definition desktopDisplay.h:70
void setMousePosition(double x, double y)
Definition desktopDisplay.h:221
glm::ivec4 windowFrameSize() const
Definition desktopDisplay.h:383
void setWindowPosition(glm::ivec2 s)
Definition desktopDisplay.h:403
void loop()
Definition desktopDisplay.h:231
void keyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
void setAsFocus()
Definition desktopDisplay.h:208
std::vector< Event > getEvents(int code)
Definition desktopDisplay.h:240
bool isOpen()
Definition desktopDisplay.h:143
std::vector< EventType > getEventTypes(int code)
Definition desktopDisplay.h:285
void mousePosition(double &x, double &y)
Definition desktopDisplay.h:219
~DesktopDisplay()
Definition desktopDisplay.h:127
glm::ivec2 windowSize() const
Definition desktopDisplay.h:363
void setResolution(glm::ivec2 wh)
Definition desktopDisplay.h:411
void setIcon(const std::vector< std::vector< std::byte > > &icons)
Definition desktopDisplay.h:330
int getKeyLastState(int key)
Definition desktopDisplay.h:229
bool keyHasAnyEvents(int key, std::vector< EventType > actions)
Definition desktopDisplay.h:265
bool keyHasEvent(int key, EventType action)
Definition desktopDisplay.h:252
GLFWwindow * getWindow() const
Definition desktopDisplay.h:141
bool closing()
Definition desktopDisplay.h:144
Event getEvent(int code)
Definition desktopDisplay.h:302
glm::vec2 contentScale() const
Definition desktopDisplay.h:373
void open()
Definition desktopDisplay.h:146
void close()
Definition desktopDisplay.h:206
glm::ivec2 windowPosition() const
Definition desktopDisplay.h:393
glm::ivec2 frameBufferSize() const
Definition desktopDisplay.h:353
void initImgui()
Definition desktopDisplay.h:420
unsigned getResY() const
Definition display.h:26
virtual void throttle()
Definition display.h:50
glm::ivec2 resolution
Definition display.h:44
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:74
bool CLIP_TO_WORK_AREA
Definition desktopDisplay.h:107
bool VULKAN
Definition desktopDisplay.h:102
bool CLIP_TO_MONITOR
Definition desktopDisplay.h:105
bool COCOA_RETINA
Definition desktopDisplay.h:103
Config(const Config &c)
Definition desktopDisplay.h:95
Config(bool vulkan, bool cocoa, bool clipMonitor, bool clipWorkArea)
Definition desktopDisplay.h:83
Config()
Definition desktopDisplay.h:75
Definition desktopDisplay.h:315
double scrollY
Definition desktopDisplay.h:318
void clear()
Definition desktopDisplay.h:321
std::map< int, std::vector< Event > > events
Definition desktopDisplay.h:316
double scrollX
Definition desktopDisplay.h:317
bool scrolled
Definition desktopDisplay.h:319