From 8f68beb719562e4e1fbbcd02498bb72b95738066 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 8 Apr 2023 21:50:30 +0300 Subject: [PATCH 38/38] 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 fdc81ab607..c2fe5a7096 100644 --- a/client/zoom.c +++ b/client/zoom.c @@ -24,10 +24,12 @@ float map_zoom = 1.0; bool zoom_enabled = FALSE; -static float zoom_steps[] = { +static float default_zoom_steps[] = { -1.0, 1.0, 2.0, -1.0 }; +static float *zoom_steps = default_zoom_steps; + static struct zoom_data { bool active; @@ -59,6 +61,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 **************************************************************************/ @@ -71,7 +87,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) { @@ -92,12 +108,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