From 7b9af35847e443147ffa0bd45564ae25862429b3 Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Sun, 17 Nov 2024 18:12:45 +0100 Subject: 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 --- test/fltk-versions.cxx | 126 +++++++++++++++++++++++++++++++++++++------------ 1 file 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 +#include #include +#include #include #include - #include -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; ilayout(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(); } -- cgit v1.2.3