Browse Source

Add gWindowRatio and set window size on each step

pull/1639/head
Andrew Belt 7 years ago
parent
commit
fdc66b367b
2 changed files with 19 additions and 9 deletions
  1. +6
    -0
      include/gui.hpp
  2. +13
    -9
      src/gui.cpp

+ 6
- 0
include/gui.hpp View File

@@ -17,8 +17,14 @@ namespace rack {
extern GLFWwindow *gWindow;
extern NVGcontext *gVg;
extern NVGcontext *gFramebufferVg;
/** The default font to use for GUI elements */
extern std::shared_ptr<Font> gGuiFont;
/** The scaling ratio */
extern float gPixelRatio;
/* The ratio between the framebuffer size and the window size reported by the OS.
This is not equal to gPixelRatio in general.
*/
extern float gWindowRatio;
extern bool gAllowCursorLock;
extern int gGuiFrame;
extern Vec gMousePos;


+ 13
- 9
src/gui.cpp View File

@@ -33,7 +33,8 @@ GLFWwindow *gWindow = NULL;
NVGcontext *gVg = NULL;
NVGcontext *gFramebufferVg = NULL;
std::shared_ptr<Font> gGuiFont;
float gPixelRatio = 0.0;
float gPixelRatio = 1.0;
float gWindowRatio = 1.0;
bool gAllowCursorLock = true;
int gGuiFrame;
Vec gMousePos;
@@ -42,7 +43,6 @@ std::string lastWindowTitle;


void windowSizeCallback(GLFWwindow* window, int width, int height) {
gScene->box.size = Vec(width, height);
}

void mouseButtonCallback(GLFWwindow *window, int button, int action, int mods) {
@@ -145,7 +145,7 @@ void mouseButtonStickyCallback(GLFWwindow *window, int button, int action, int m
}

void cursorPosCallback(GLFWwindow* window, double xpos, double ypos) {
Vec mousePos = Vec(xpos, ypos).round();
Vec mousePos = Vec(xpos, ypos).div(gPixelRatio / gWindowRatio).round();
Vec mouseRel = mousePos.minus(gMousePos);

#ifdef ARCH_MAC
@@ -411,11 +411,6 @@ void guiDestroy() {

void guiRun() {
assert(gWindow);
{
int width, height;
glfwGetWindowSize(gWindow, &width, &height);
windowSizeCallback(gWindow, width, height);
}
gGuiFrame = 0;
while(!glfwWindowShouldClose(gWindow)) {
double startTime = glfwGetTime();
@@ -444,7 +439,7 @@ void guiRun() {
lastWindowTitle = windowTitle;
}

// Get framebuffer size
// Get desired scaling
float pixelRatio;
glfwGetWindowContentScale(gWindow, &pixelRatio, NULL);
pixelRatio = roundf(pixelRatio);
@@ -454,6 +449,15 @@ void guiRun() {
gPixelRatio = pixelRatio;
}

// Get framebuffer/window ratio
int width, height;
glfwGetFramebufferSize(gWindow, &width, &height);
int windowWidth, windowHeight;
glfwGetWindowSize(gWindow, &windowWidth, &windowHeight);
gWindowRatio = (float)width / windowWidth;

gScene->box.size = Vec(width, height).div(gPixelRatio / gWindowRatio);

// Step scene
gScene->step();



Loading…
Cancel
Save