summaryrefslogtreecommitdiff
path: root/src/Fl_Spinner.cxx
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2020-11-22 19:19:19 +0100
committerAlbrecht Schlosser <albrechts.fltk@online.de>2022-11-22 19:32:54 +0100
commitecc47d0cc3e1784e17ac94829202f2bdbd38a682 (patch)
tree2519c9b11a598ed4ad1faf9d07c205da5c4903c7 /src/Fl_Spinner.cxx
parent4daec2a9408c674f8d62f8770ec8c035c25f2294 (diff)
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
Diffstat (limited to 'src/Fl_Spinner.cxx')
-rw-r--r--src/Fl_Spinner.cxx32
1 files changed, 25 insertions, 7 deletions
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 <stdlib.h>
#include <FL/Fl_Spinner.H>
+#include <FL/Fl_Rect.H>
+#include <FL/fl_draw.H>
/*
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) {