summaryrefslogtreecommitdiff
path: root/fluid/fluid.cxx
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2023-01-01 21:53:07 +0100
committerAlbrecht Schlosser <albrechts.fltk@online.de>2023-01-12 19:21:09 +0100
commitbafd3fd3d792b530d39d3af06e087dc63d2a25a2 (patch)
tree42f4d533490191a92a13863d07378820b04a7b9c /fluid/fluid.cxx
parent79832b679f2d195eb3b0f30ca920a857cc133b2b (diff)
Add Fl_Scheme_Choice widget and use it in test programs
This widget offers the selection of all known FLTK schemes as a simple widget based on Fl_Choice. Some test and demo programs use Fl_Scheme_Choice to enable the developer or user to switch schemes quickly for comparison. Todo: - add features to add new schemes during runtime (partially done) - update status when the scheme is changed by Fl::scheme("...")
Diffstat (limited to 'fluid/fluid.cxx')
-rw-r--r--fluid/fluid.cxx94
1 files changed, 70 insertions, 24 deletions
diff --git a/fluid/fluid.cxx b/fluid/fluid.cxx
index 62c3e9636..47266b63f 100644
--- a/fluid/fluid.cxx
+++ b/fluid/fluid.cxx
@@ -1475,34 +1475,80 @@ Fl_Menu_Item Main_Menu[] = {
/**
Change the app's and hence preview the design's scheme.
- The scheme setting is stored inthe app preferences.
+
+ The scheme setting is stored in the app preferences
+ - in key \p 'scheme_name' since 1.4.0
+ - in key \p 'scheme' (index: 0 - 4) in 1.3.x
+
+ This callback is triggered by changing the scheme in the
+ Fl_Scheme_Choice widget (\p Edit/GUI Settings).
+
+ \see init_scheme() for choice values and backwards compatibility
*/
-void scheme_cb(Fl_Choice *, void *) {
+void scheme_cb(Fl_Scheme_Choice *choice, void *) {
if (batch_mode)
return;
- switch (scheme_choice->value()) {
- case 0 : // Default
- Fl::scheme(NULL);
- break;
- case 1 : // None
- Fl::scheme("none");
- break;
- case 2 : // Plastic
- Fl::scheme("plastic");
- break;
- case 3 : // GTK+
- Fl::scheme("gtk+");
- break;
- case 4 : // Gleam
- Fl::scheme("gleam");
- break;
- case 5 : // Oxy
- Fl::scheme("oxy");
- break;
- }
-
- fluid_prefs.set("scheme", scheme_choice->value());
+ // set the new scheme only if the scheme was changed
+ const char *new_scheme = choice->text(choice->value());
+
+ if (Fl::is_scheme(new_scheme))
+ return;
+
+ Fl::scheme(new_scheme);
+ fluid_prefs.set("scheme_name", new_scheme);
+
+ // Backwards compatibility: store 1.3 scheme index (1-4).
+ // We assume that index 0-3 (base, plastic, gtk+, gleam) are in the
+ // same order as in 1.3.x (index 1-4), higher values are ignored
+
+ int scheme_index = scheme_choice->value();
+ if (scheme_index <= 3) // max. index for 1.3.x (Gleam)
+ fluid_prefs.set("scheme", scheme_index + 1); // compensate for different indexing
+}
+
+/**
+ Read Fluid's scheme preferences and set the app's scheme.
+
+ Since FLTK 1.4.0 the scheme \b name is stored as a character string
+ with key "scheme_name" in the preference database.
+
+ In FLTK 1.3.x the scheme preference was stored as an integer index
+ with key "scheme" in the database. The known schemes were hardcoded in
+ Fluid's sources (here for reference):
+
+ | Index | 1.3 Scheme Name | Choice | 1.4 Scheme Name |
+ |-------|-----------------|-------|-----------------|
+ | 0 | Default (same as None) | n/a | n/a |
+ | 1 | None (same as Default) | 0 | base |
+ | 2 | Plastic | 1 | plastic |
+ | 3 | GTK+ | 2 | gtk+ |
+ | 4 | Gleam | 3 | gleam |
+ | n/a | n/a | 4 | oxy |
+
+ The new Fluid tries to keep backwards compatibility and reads both
+ keys (\p scheme and \p scheme_name). If the latter is defined, it is used.
+ If not the old \p scheme (index) is used - but we need to subtract one to
+ get the new Fl_Scheme_Choice index (column "Choice" above).
+*/
+void init_scheme() {
+ int scheme_index = 0; // scheme index for backwards compatibility (1.3.x)
+ char *scheme_name; // scheme name since 1.4.0
+ fluid_prefs.get("scheme_name", scheme_name, "XXX"); // XXX means: not set => fallback 1.3.x
+ if (!strcmp(scheme_name, "XXX")) {
+ fluid_prefs.get("scheme", scheme_index, 0);
+ if (scheme_index > 0) {
+ scheme_index--;
+ scheme_choice->value(scheme_index); // set the choice value
+ }
+ if (scheme_index < 0)
+ scheme_index = 0;
+ else if (scheme_index > scheme_choice->size() - 1)
+ scheme_index = 0;
+ scheme_name = const_cast<char *>(scheme_choice->text(scheme_index));
+ fluid_prefs.set("scheme_name", scheme_name);
+ }
+ Fl::scheme(scheme_name);
}
/**