From d74976944c982027746d2a99a3e5a15e034b4b99 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 8 Apr 2023 21:47:25 +0300 Subject: [PATCH 42/42] Zoom: Add support for gui-specific zoom steps See osdn #47813 Signed-off-by: Marko Lindqvist --- client/zoom.c | 30 ++++++++++++++++++++++++------ client/zoom.h | 3 ++- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/client/zoom.c b/client/zoom.c index 0e79443aa4..c94d0a320b 100644 --- a/client/zoom.c +++ b/client/zoom.c @@ -24,7 +24,7 @@ float map_zoom = 1.0; bool zoom_enabled = FALSE; -static float zoom_steps[] = { +static float default_zoom_steps[] = { #ifdef EXP_ZOOM_LEVELS -1.0, 0.13, 0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 2.0, 2.5, 3.0, 4.0, -1.0 #else @@ -32,6 +32,8 @@ static float zoom_steps[] = { #endif /* EXP_ZOOM_LEVELS */ }; +static float *zoom_steps = default_zoom_steps; + static struct zoom_data { bool active; @@ -63,6 +65,20 @@ void zoom_1_0(void) map_canvas_resized(mapview.width, mapview.height); } +/**********************************************************************//** + Set list of zoom steps that the system uses. + The list is not copied - caller is expected to maintain it. + First and last value must be -1.0 +**************************************************************************/ +void zoom_set_steps(float *steps) +{ + if (steps == NULL) { + zoom_steps = default_zoom_steps; + } else { + zoom_steps = steps; + } +} + /**********************************************************************//** Zoom level one step up **************************************************************************/ @@ -75,7 +91,7 @@ void zoom_step_up(void) for (i = 1 ; zoom_steps[i] < map_zoom * 1.05 && zoom_steps[i] > 0.0 ; i++ ) { - /* empty */ + /* Empty */ } if (zoom_steps[i] > 0.0) { @@ -96,12 +112,14 @@ void zoom_step_down(void) /* Even if above previous step, close enough is considered to be in * previous step so that change is not miniscule */ - for (i = ARRAY_SIZE(zoom_steps) - 2 ; - zoom_steps[i] * 1.05 > map_zoom && zoom_steps[i] > 0.0 ; - i-- ) { - /* empty */ + for (i = 1; + zoom_steps[i] < map_zoom * 1.05 && zoom_steps[i] > 0.0 ; + i++) { } + /* Get back, and below */ + i = MAX(i - 2, 1); + if (zoom_steps[i] > 0.0) { if (zoom_steps[i] > 0.99 && zoom_steps[i] < 1.01) { zoom_1_0(); diff --git a/client/zoom.h b/client/zoom.h index 5815554775..d5b8f77078 100644 --- a/client/zoom.h +++ b/client/zoom.h @@ -1,4 +1,4 @@ -/********************************************************************** +/*********************************************************************** Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -19,6 +19,7 @@ extern "C" { void zoom_set(float new_zoom); void zoom_1_0(void); +void zoom_set_steps(float *steps); #define zoom_get_level() map_zoom #define zoom_is_enabled() zoom_enabled -- 2.39.2