make it work on retina screens
This commit is contained in:
@@ -25,7 +25,7 @@ public:
|
||||
|
||||
void setup();
|
||||
void loadSettings();
|
||||
void resize(uint32_t width, uint32_t height);
|
||||
void resize(uint32_t width, uint32_t height, uint32_t fb_width, uint32_t fb_height);
|
||||
|
||||
/* callback */
|
||||
bool render();
|
||||
|
||||
@@ -53,9 +53,13 @@ private:
|
||||
double pixel_y() const;
|
||||
|
||||
public:
|
||||
// logical dimensions
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
|
||||
// physical (framebuffer) dimensions
|
||||
uint32_t fb_width;
|
||||
uint32_t fb_height;
|
||||
|
||||
private:
|
||||
double x, y; // pixel values of the map center in the current scale
|
||||
|
||||
@@ -33,14 +33,13 @@ public:
|
||||
exit(1);
|
||||
}
|
||||
|
||||
glfwSetWindowUserPointer(window, this);
|
||||
glfwMakeContextCurrent(window);
|
||||
|
||||
settings.load();
|
||||
map.setup();
|
||||
|
||||
int width, height;
|
||||
glfwGetWindowSize(window, &width, &height);
|
||||
map.resize(width, height);
|
||||
resize(window, 0, 0);
|
||||
|
||||
glfwSwapInterval(1);
|
||||
|
||||
@@ -49,11 +48,10 @@ public:
|
||||
glfwSetCursorPosCallback(window, mousemove);
|
||||
glfwSetMouseButtonCallback(window, mouseclick);
|
||||
glfwSetWindowSizeCallback(window, resize);
|
||||
glfwSetFramebufferSizeCallback(window, resize);
|
||||
glfwSetScrollCallback(window, scroll);
|
||||
glfwSetCharCallback(window, character);
|
||||
glfwSetKeyCallback(window, key);
|
||||
|
||||
glfwSetWindowUserPointer(window, this);
|
||||
}
|
||||
|
||||
static void character(GLFWwindow *window, unsigned int codepoint) {
|
||||
@@ -105,9 +103,15 @@ public:
|
||||
view->map.scaleBy(scale, view->last_x, view->last_y);
|
||||
}
|
||||
|
||||
static void resize(GLFWwindow *window, int width, int height) {
|
||||
static void resize(GLFWwindow *window, int, int) {
|
||||
MapView *view = (MapView *)glfwGetWindowUserPointer(window);
|
||||
view->map.resize(width, height);
|
||||
|
||||
int width, height;
|
||||
glfwGetWindowSize(window, &width, &height);
|
||||
int fb_width, fb_height;
|
||||
glfwGetFramebufferSize(window, &fb_width, &fb_height);
|
||||
|
||||
view->map.resize(width, height, fb_width, fb_height);
|
||||
}
|
||||
|
||||
static void mouseclick(GLFWwindow *window, int button, int action, int modifiers) {
|
||||
|
||||
@@ -32,9 +32,11 @@ void Map::loadSettings() {
|
||||
update();
|
||||
}
|
||||
|
||||
void Map::resize(uint32_t width, uint32_t height) {
|
||||
void Map::resize(uint32_t width, uint32_t height, uint32_t fb_width, uint32_t fb_height) {
|
||||
transform.width = width;
|
||||
transform.height = height;
|
||||
transform.fb_width = fb_width;
|
||||
transform.fb_height = fb_height;
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
@@ -154,7 +154,7 @@ void Painter::render(const Tile::Ptr& tile) {
|
||||
tile->lineVertex.bind();
|
||||
glVertexAttribPointer(outlineShader->a_pos, 2, GL_SHORT, GL_FALSE, 0, BUFFER_OFFSET(0));
|
||||
glUniform4f(outlineShader->u_color, 0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glUniform2f(outlineShader->u_world, transform.width, transform.height);
|
||||
glUniform2f(outlineShader->u_world, transform.fb_width, transform.fb_height);
|
||||
glLineWidth(2.0f);
|
||||
glDrawArrays(GL_LINE_STRIP, 0, tile->lineVertex.length());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user