diff options
| author | Albrecht Schlosser <albrechts.fltk@online.de> | 2024-11-17 18:12:45 +0100 |
|---|---|---|
| committer | Albrecht Schlosser <albrechts.fltk@online.de> | 2024-11-17 18:12:45 +0100 |
| commit | 7b9af35847e443147ffa0bd45564ae25862429b3 (patch) | |
| tree | 00fe6049407724323a435675a0a1d7f68313b131 | |
| parent | 114fb66cd38f10c14a076108eb8f77e75a107174 (diff) | |
Improve 'test/fltk-versions' demo program
- add code to get the platform and backend
- display platform and backend on screen
- improve and simplify layout (using Fl_Grid)
- add version check indicator
| -rw-r--r-- | test/fltk-versions.cxx | 126 |
1 files changed, 95 insertions, 31 deletions
diff --git a/test/fltk-versions.cxx b/test/fltk-versions.cxx index ed80c7b1f..bd16d75a7 100644 --- a/test/fltk-versions.cxx +++ b/test/fltk-versions.cxx @@ -1,7 +1,7 @@ // // Library version test program for the Fast Light Tool Kit (FLTK). // -// Copyright 1998-2017 by Bill Spitzak and others. +// Copyright 1998-2024 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 @@ -14,65 +14,129 @@ // https://www.fltk.org/bugs.php // +// This program is work in progress and may not be "perfect". + #include <FL/Fl.H> +#include <FL/platform.H> #include <FL/Fl_Window.H> +#include <FL/Fl_Grid.H> #include <FL/Fl_Box.H> #include <FL/fl_ask.H> - #include <stdio.h> -static char version[8][80] = { "","","","","","","","" }; +static const int ww = 640, mw = 750; // initial, max. window width +static const int wh = 200, mh = 300; // initial, max. window height -int main(int argc, char **argv) { +// Function to determine the platform (system and backend). +// Note: the display must have been opened before this is called. +// Returns a string describing the system/platform and backend. - int versions = 0; +static const char *get_platform() { +#if defined(_WIN32) + return "Windows"; +#elif defined(FLTK_USE_X11) || defined(FLTK_USE_WAYLAND) +# if defined(FLTK_USE_X11) + if (fl_x11_display()) + return "Unix/Linux (X11)"; +# endif +# if defined(FLTK_USE_WAYLAND) + if (fl_wl_display()) + return "Unix/Linux (Wayland)"; +# endif + return "X11 or Wayland (backend unknown or display not opened)"; +#elif defined(__APPLE__) + return "macOS (native)"; +#endif + return "platform unknown, unsupported, or display not opened"; +} - sprintf(version[versions++],"FL_VERSION = %6.4f",FL_VERSION); - sprintf(version[versions++],"Fl::version() = %6.4f %s",Fl::version(), - (FL_VERSION == Fl::version()) ? "" : "***"); +// set box attributes and optionally set a background color (debug mode) -#ifdef FL_API_VERSION - sprintf(version[versions++],"FL_API_VERSION = %6d",FL_API_VERSION); - sprintf(version[versions++],"Fl::api_version() = %6d %s",Fl::api_version(), - (FL_API_VERSION == Fl::api_version()) ? "" : "***"); +static void set_attributes(Fl_Widget *w, Fl_Color col) { + w->labelfont(FL_COURIER); + w->labelsize(16); + w->align(FL_ALIGN_CENTER | FL_ALIGN_INSIDE); +#if (0) // 1 = debug: set a background color for a box (widget) + w->box(FL_FLAT_BOX); + w->color(col); #endif +} -#ifdef FL_ABI_VERSION - sprintf(version[versions++],"FL_ABI_VERSION = %6d",FL_ABI_VERSION); - sprintf(version[versions++],"Fl::abi_version() = %6d %s",Fl::abi_version(), - (FL_ABI_VERSION == Fl::abi_version()) ? "" : "***"); -#endif +static char version[9][80]; - for (int i=0; i<versions; i++) { - printf("%s\n",version[i]); +// Optional: uncomment next line to disable wayland backend +// FL_EXPORT bool fl_disable_wayland = true; + +int main(int argc, char **argv) { + int versions = 0; + fl_open_display(); + const char *platform = get_platform(); + printf("System/platform = %s\n", platform); + + // Version comparison results (Unicode check marks in comments are experimental) + + const char *YES = "OK"; // "🗹"; // "✓"; + const char *NO = "FAIL"; // "🗷"; // "❌"; + + sprintf(version[versions++], "FL_VERSION = %6.4f", FL_VERSION); + sprintf(version[versions++], "Fl::version() = %6.4f", Fl::version()); + sprintf(version[versions++], "%s", (FL_VERSION == Fl::version()) ? YES : NO); + + sprintf(version[versions++], "FL_API_VERSION = %6d", FL_API_VERSION); + sprintf(version[versions++], "Fl::api_version() = %6d", Fl::api_version()); + sprintf(version[versions++], "%s", (FL_API_VERSION == Fl::api_version()) ? YES : NO); + + sprintf(version[versions++], "FL_ABI_VERSION = %6d", FL_ABI_VERSION); + sprintf(version[versions++], "Fl::abi_version() = %6d", Fl::abi_version()); + sprintf(version[versions++], "%s", (FL_ABI_VERSION == Fl::abi_version()) ? YES : NO); + + for (int i = 0; i < versions; i++) { + if (i % 3 == 1) // 2nd line followed by check mark or text + printf("%s ", version[i]); + else // 1st and 3rd line + printf("%s\n", version[i]); } fflush(stdout); #ifdef FL_ABI_VERSION if (FL_ABI_VERSION != Fl::abi_version()) { printf("*** FLTK ABI version mismatch: headers = %d, lib = %d ***\n", - FL_ABI_VERSION, Fl::abi_version()); + FL_ABI_VERSION, Fl::abi_version()); fflush(stdout); fl_message("*** FLTK ABI version mismatch: headers = %d, lib = %d ***", - FL_ABI_VERSION, Fl::abi_version()); - // exit(1); + FL_ABI_VERSION, Fl::abi_version()); } #endif - Fl_Window *window = new Fl_Window(670,300); + Fl_Window *window = new Fl_Window(ww, wh); - Fl_Box *box[8]; - for (int i=0; i<4; i++) { - box[2*i] = new Fl_Box( 10,40+40*i,320,30,version[2*i]); - box[2*i+1] = new Fl_Box(340,40+40*i,320,30,version[2*i+1]); - } + Fl_Grid *grid = new Fl_Grid(0, 0, ww, wh); + grid->layout(4, 3, 20, 5); - for (int i=0; i<8; i++) { - box[i]->labelfont(FL_COURIER); - box[i]->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE); + Fl_Box *title = new Fl_Box(0, 0, 0, 0, platform); + set_attributes(title, FL_YELLOW); + title->labelfont(FL_HELVETICA_BOLD); + grid->widget(title, 0, 0, 1, 3); + grid->row_height(0, 40); + title->labelsize(20); + + Fl_Box *box[versions]; + for (int i = 0; i < versions/3; i += 1) { + box[3 * i ] = new Fl_Box(0, 0, 270, 0, version[3 * i]); + box[3 * i + 1] = new Fl_Box(0, 0, 270, 0, version[3 * i + 1]); + box[3 * i + 2] = new Fl_Box(0, 0, 40, 0, version[3 * i + 2]); + grid->widget(box[3 * i], i + 1, 0); + grid->widget(box[3 * i + 1], i + 1, 1); + grid->widget(box[3 * i + 2], i + 1, 2); + grid->row_height(i + 1, 30); } + for (int i = 0; i < versions; i++) + set_attributes(box[i], FL_GREEN); + window->end(); + window->resizable(grid); + window->size_range(ww, wh, mw, mh); window->show(argc, argv); return Fl::run(); } |
