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
This commit is contained in:
parent
114fb66cd3
commit
7b9af35847
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// Library version test program for the Fast Light Tool Kit (FLTK).
|
// 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
|
// 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
|
// the file "COPYING" which should have been included with this file. If this
|
||||||
@ -14,65 +14,129 @@
|
|||||||
// https://www.fltk.org/bugs.php
|
// https://www.fltk.org/bugs.php
|
||||||
//
|
//
|
||||||
|
|
||||||
|
// This program is work in progress and may not be "perfect".
|
||||||
|
|
||||||
#include <FL/Fl.H>
|
#include <FL/Fl.H>
|
||||||
|
#include <FL/platform.H>
|
||||||
#include <FL/Fl_Window.H>
|
#include <FL/Fl_Window.H>
|
||||||
|
#include <FL/Fl_Grid.H>
|
||||||
#include <FL/Fl_Box.H>
|
#include <FL/Fl_Box.H>
|
||||||
#include <FL/fl_ask.H>
|
#include <FL/fl_ask.H>
|
||||||
|
|
||||||
#include <stdio.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
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
|
||||||
|
// set box attributes and optionally set a background color (debug mode)
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
static char version[9][80];
|
||||||
|
|
||||||
|
// Optional: uncomment next line to disable wayland backend
|
||||||
|
// FL_EXPORT bool fl_disable_wayland = true;
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
int versions = 0;
|
int versions = 0;
|
||||||
|
fl_open_display();
|
||||||
|
const char *platform = get_platform();
|
||||||
|
printf("System/platform = %s\n", platform);
|
||||||
|
|
||||||
sprintf(version[versions++],"FL_VERSION = %6.4f",FL_VERSION);
|
// Version comparison results (Unicode check marks in comments are experimental)
|
||||||
sprintf(version[versions++],"Fl::version() = %6.4f %s",Fl::version(),
|
|
||||||
(FL_VERSION == Fl::version()) ? "" : "***");
|
|
||||||
|
|
||||||
#ifdef FL_API_VERSION
|
const char *YES = "OK"; // "🗹"; // "✓";
|
||||||
sprintf(version[versions++],"FL_API_VERSION = %6d",FL_API_VERSION);
|
const char *NO = "FAIL"; // "🗷"; // "❌";
|
||||||
sprintf(version[versions++],"Fl::api_version() = %6d %s",Fl::api_version(),
|
|
||||||
(FL_API_VERSION == Fl::api_version()) ? "" : "***");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef FL_ABI_VERSION
|
sprintf(version[versions++], "FL_VERSION = %6.4f", FL_VERSION);
|
||||||
sprintf(version[versions++],"FL_ABI_VERSION = %6d",FL_ABI_VERSION);
|
sprintf(version[versions++], "Fl::version() = %6.4f", Fl::version());
|
||||||
sprintf(version[versions++],"Fl::abi_version() = %6d %s",Fl::abi_version(),
|
sprintf(version[versions++], "%s", (FL_VERSION == Fl::version()) ? YES : NO);
|
||||||
(FL_ABI_VERSION == Fl::abi_version()) ? "" : "***");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for (int i=0; i<versions; i++) {
|
sprintf(version[versions++], "FL_API_VERSION = %6d", FL_API_VERSION);
|
||||||
printf("%s\n",version[i]);
|
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);
|
fflush(stdout);
|
||||||
|
|
||||||
#ifdef FL_ABI_VERSION
|
#ifdef FL_ABI_VERSION
|
||||||
if (FL_ABI_VERSION != Fl::abi_version()) {
|
if (FL_ABI_VERSION != Fl::abi_version()) {
|
||||||
printf("*** FLTK ABI version mismatch: headers = %d, lib = %d ***\n",
|
printf("*** FLTK ABI version mismatch: headers = %d, lib = %d ***\n",
|
||||||
FL_ABI_VERSION, Fl::abi_version());
|
FL_ABI_VERSION, Fl::abi_version());
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
fl_message("*** FLTK ABI version mismatch: headers = %d, lib = %d ***",
|
fl_message("*** FLTK ABI version mismatch: headers = %d, lib = %d ***",
|
||||||
FL_ABI_VERSION, Fl::abi_version());
|
FL_ABI_VERSION, Fl::abi_version());
|
||||||
// exit(1);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Fl_Window *window = new Fl_Window(670,300);
|
Fl_Window *window = new Fl_Window(ww, wh);
|
||||||
|
|
||||||
Fl_Box *box[8];
|
Fl_Grid *grid = new Fl_Grid(0, 0, ww, wh);
|
||||||
for (int i=0; i<4; i++) {
|
grid->layout(4, 3, 20, 5);
|
||||||
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_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<8; i++) {
|
for (int i = 0; i < versions; i++)
|
||||||
box[i]->labelfont(FL_COURIER);
|
set_attributes(box[i], FL_GREEN);
|
||||||
box[i]->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE);
|
|
||||||
}
|
|
||||||
|
|
||||||
window->end();
|
window->end();
|
||||||
|
window->resizable(grid);
|
||||||
|
window->size_range(ww, wh, mw, mh);
|
||||||
window->show(argc, argv);
|
window->show(argc, argv);
|
||||||
return Fl::run();
|
return Fl::run();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user