From ecc47d0cc3e1784e17ac94829202f2bdbd38a682 Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Sun, 22 Nov 2020 19:19:19 +0100 Subject: Refactor and simplify "arrow drawing" in widgets "Arrows" in widgets are those GUI elements mostly represented by triangles pointing in a particular direction as in scrollbars, choice widgets, some menus, valuators and Fl_Counter widgets. The code has been simplified and standardized such that all these GUI elements are drawn identically per FLTK scheme. Widget authors no longer need to write code to calculate arrow sizes and draw polygons etc. Different schemes can and do implement different drawing functions. Todo: see comments "FIXME_ARROW" in src/Fl_Menu_Button.cxx and src/Fl_Menu.cxx --- src/Fl_Spinner.cxx | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'src/Fl_Spinner.cxx') diff --git a/src/Fl_Spinner.cxx b/src/Fl_Spinner.cxx index 51657d87b..a298d189e 100644 --- a/src/Fl_Spinner.cxx +++ b/src/Fl_Spinner.cxx @@ -1,7 +1,7 @@ // // Spinner widget for the Fast Light Tool Kit (FLTK). // -// Copyright 1998-2017 by Bill Spitzak and others. +// Copyright 1998-2022 by Bill Spitzak and others. // // This library is free software. Distribution and use rights are outlined in // the file "COPYING" which should have been included with this file. If this @@ -21,6 +21,8 @@ #include #include +#include +#include /* This widget is a combination of the input widget and repeat buttons. @@ -91,9 +93,6 @@ void Fl_Spinner::update() { input_.value(s); } -#define FL_UP_ARROW_TX "@-42<" -#define FL_DOWN_ARROW_TX "@-42>" - /** Creates a new Fl_Spinner widget using the given position, size, and label string. @@ -104,9 +103,8 @@ void Fl_Spinner::update() { Fl_Spinner::Fl_Spinner(int X, int Y, int W, int H, const char *L) : Fl_Group(X, Y, W, H, L), input_(X, Y, W - H / 2 - 2, H), - up_button_(X + W - H / 2 - 2, Y, H / 2 + 2, H / 2, FL_UP_ARROW_TX), - down_button_(X + W - H / 2 - 2, Y + H - H / 2, - H / 2 + 2, H / 2, FL_DOWN_ARROW_TX) + up_button_(X + W - H / 2 - 2, Y, H / 2 + 2, H / 2), + down_button_(X + W - H / 2 - 2, Y + H - H / 2, H / 2 + 2, H / 2) { end(); @@ -129,6 +127,26 @@ Fl_Spinner::Fl_Spinner(int X, int Y, int W, int H, const char *L) down_button_.callback((Fl_Callback *)sb_cb, this); } +void Fl_Spinner::draw() { + + // draw the box and the input widget + + draw_box(); + ((Fl_Widget&)input_).draw(); + + // draw the buttons and the up and down arrows as their "labels" + + ((Fl_Widget&)up_button_).draw(); + Fl_Rect up(up_button_); + up.inset(up_button_.box()); + fl_draw_arrow(up, FL_ARROW_SINGLE, FL_ORIENT_UP, labelcolor()); + + ((Fl_Widget&)down_button_).draw(); + Fl_Rect down(down_button_); + down.inset(down_button_.box()); + fl_draw_arrow(down, FL_ARROW_SINGLE, FL_ORIENT_DOWN, labelcolor()); +} + int Fl_Spinner::handle(int event) { switch (event) { -- cgit v1.2.3