From 15e0c797bdc5d11e4aa9f429a431e9d8a76b2cbd Mon Sep 17 00:00:00 2001 From: Brad Grantham Date: Tue, 6 Dec 2016 18:58:34 -0800 Subject: [PATCH] resize to fit window --- interface.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/interface.cpp b/interface.cpp index 7cdba6b..4e492a3 100644 --- a/interface.cpp +++ b/interface.cpp @@ -1524,11 +1524,9 @@ void initialize_widgets(bool run_fast, bool add_floppies, bool floppy0_inserted, for(auto b : controls) controls_centered.push_back(new centering(b)); - widget *screen = new apple2screen(); - widget *padding = new spacer(10, 0); widget *buttonpanel = new centering(new widgetbox(widgetbox::VERTICAL, controls_centered)); - vector panels_centered = {new centering(screen), padding, new centering(buttonpanel)}; + vector panels_centered = {new spacer(10, 0), new centering(screen), new spacer(10, 0), new centering(buttonpanel), new spacer(10, 0)}; ui = new centering(new widgetbox(widgetbox::HORIZONTAL, panels_centered)); } @@ -1543,7 +1541,7 @@ void show_floppy_activity(int number, bool activity) floppy1_icon->change_state(elapsed.count(), 1, activity); } -const float widget_scale = 4; +float widget_scale = 4; float to_screen_transform[9]; void make_to_screen_transform() @@ -1624,13 +1622,25 @@ static void key(GLFWwindow *window, int key, int scancode, int action, int mods) } } -static void resize(GLFWwindow *window, int x, int y) +static void resize_based_on_framebuffer(GLFWwindow *window) { glfwGetFramebufferSize(window, &gWindowWidth, &gWindowHeight); + float cw, ch; + tie(cw, ch) = ui->get_min_dimensions(); + if(float(gWindowHeight) / gWindowWidth < ch / cw) { + widget_scale = gWindowHeight / ch; + } else { + widget_scale = gWindowWidth / cw; + } glViewport(0, 0, gWindowWidth, gWindowHeight); make_to_screen_transform(); } +static void resize(GLFWwindow *window, int x, int y) +{ + resize_based_on_framebuffer(window); +} + widget *widget_clicked = NULL; static void button(GLFWwindow *window, int b, int action, int mods) @@ -1762,6 +1772,7 @@ void start(bool run_fast, bool add_floppies, bool floppy0_inserted, bool floppy1 make_to_screen_transform(); initialize_gl(); initialize_widgets(run_fast, add_floppies, floppy0_inserted, floppy1_inserted); + resize_based_on_framebuffer(my_window); CheckOpenGL(__FILE__, __LINE__); glfwSetKeyCallback(my_window, key);