From 1a250234ea1ea774c461c96173c83e7be19b572b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Sun, 26 Nov 2017 22:12:41 +0100 Subject: [PATCH] Add revert button to gamma ramp test --- tests/gamma.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/tests/gamma.c b/tests/gamma.c index 500d41c4..c692cf9a 100644 --- a/tests/gamma.c +++ b/tests/gamma.c @@ -38,6 +38,7 @@ #define NK_INCLUDE_DEFAULT_ALLOCATOR #define NK_INCLUDE_VERTEX_BUFFER_OUTPUT #define NK_INCLUDE_STANDARD_VARARGS +#define NK_BUTTON_TRIGGER_ON_RELEASE #include #define NK_GLFW_GL2_IMPLEMENTATION @@ -85,6 +86,7 @@ int main(int argc, char** argv) { GLFWmonitor* monitor = NULL; GLFWwindow* window; + GLFWgammaramp orig_ramp; struct nk_context* nk; struct nk_font_atlas* atlas; float gamma_value = 1.f; @@ -103,6 +105,18 @@ int main(int argc, char** argv) exit(EXIT_FAILURE); } + { + const GLFWgammaramp* ramp = glfwGetGammaRamp(monitor); + const size_t array_size = ramp->size * sizeof(short); + orig_ramp.size = ramp->size; + orig_ramp.red = malloc(array_size); + orig_ramp.green = malloc(array_size); + orig_ramp.blue = malloc(array_size); + memcpy(orig_ramp.red, ramp->red, array_size); + memcpy(orig_ramp.green, ramp->green, array_size); + memcpy(orig_ramp.blue, ramp->blue, array_size); + } + glfwMakeContextCurrent(window); gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); glfwSwapInterval(1); @@ -125,13 +139,17 @@ int main(int argc, char** argv) nk_glfw3_new_frame(); if (nk_begin(nk, "", area, 0)) { - const GLFWgammaramp* ramp = glfwGetGammaRamp(monitor); + const GLFWgammaramp* ramp; nk_window_set_bounds(nk, area); - nk_layout_row_dynamic(nk, 30, 2); + nk_layout_row_dynamic(nk, 30, 3); if (nk_slider_float(nk, 0.1f, &gamma_value, 5.f, 0.1f)) glfwSetGamma(monitor, gamma_value); nk_labelf(nk, NK_TEXT_LEFT, "%0.1f", gamma_value); + if (nk_button_label(nk, "Revert")) + glfwSetGammaRamp(monitor, &orig_ramp); + + ramp = glfwGetGammaRamp(monitor); nk_layout_row_dynamic(nk, height - 60.f, 3); chart_ramp_array(nk, nk_rgb(255, 0, 0), ramp->size, ramp->red); @@ -146,6 +164,10 @@ int main(int argc, char** argv) glfwWaitEventsTimeout(1.0); } + free(orig_ramp.red); + free(orig_ramp.green); + free(orig_ramp.blue); + nk_glfw3_shutdown(); glfwTerminate(); exit(EXIT_SUCCESS);