From 9f26e372ba0dce0d721c0dc7b537d3cd2e0a9c6d Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Sat, 15 Dec 2018 16:47:00 +0100 Subject: [PATCH] prevent sliders to be displayed out of their range --- src/engine.c | 28 +++++++++++++++++++--------- src/engine.h | 2 +- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/engine.c b/src/engine.c index 50617ac2..962dd7d3 100644 --- a/src/engine.c +++ b/src/engine.c @@ -1958,10 +1958,16 @@ void Window_draw_slider(T_Scroller_button * button) button->Pos_Y, button->Length-24,11,MC_Black/*MC_Dark*/); - if (button->Nb_elements>button->Nb_visibles) - slider_position+= - ((button->Length-24-button->Cursor_length)*(button->Position)+(button->Nb_elements-button->Nb_visibles)/2)/(button->Nb_elements-button->Nb_visibles); - + if (button->Nb_elements > button->Nb_visibles) + { + int pos = ( (button->Length - 24 - button->Cursor_length) * button->Position + + (button->Nb_elements - button->Nb_visibles) / 2) + / (button->Nb_elements - button->Nb_visibles); + if ((pos + button->Cursor_length) > (button->Length - 24)) + pos = button->Length - 24 - button->Cursor_length; + slider_position += pos; + } + Window_rectangle(slider_position, button->Pos_Y, button->Cursor_length,11,MC_OnBlack/*MC_White*/); @@ -1978,11 +1984,15 @@ void Window_draw_slider(T_Scroller_button * button) slider_position, 11,button->Length-24,MC_Black/*MC_Dark*/); - if (button->Nb_elements>button->Nb_visibles) - slider_position+= - ((button->Length-24-button->Cursor_length)*(button->Position)+(button->Nb_elements-button->Nb_visibles)/2)/(button->Nb_elements-button->Nb_visibles); - // - //(button->Position*) / (button->Nb_elements-button->Nb_visibles)); + if (button->Nb_elements > button->Nb_visibles) + { + int pos = ( (button->Length - 24 - button->Cursor_length) * button->Position + + (button->Nb_elements - button->Nb_visibles) / 2) + / (button->Nb_elements - button->Nb_visibles); + if ((pos + button->Cursor_length) > (button->Length - 24)) + pos = button->Length - 24 - button->Cursor_length; + slider_position += pos; + } Window_rectangle(button->Pos_X, slider_position, diff --git a/src/engine.h b/src/engine.h index e7af5075..155aa5f0 100644 --- a/src/engine.h +++ b/src/engine.h @@ -70,7 +70,7 @@ T_Scroller_button * Window_set_scroller_button(word x_pos, word y_pos, word initial_position); T_Scroller_button * Window_set_horizontal_scroller_button(word x_pos, word y_pos, - word height, word nb_elements, word nb_elements_visible, + word width, word nb_elements, word nb_elements_visible, word initial_position); T_Special_button * Window_set_special_button(word x_pos, word y_pos,