#842: Enables command line color arguments on macOS

This commit is contained in:
Matthias Melcher 2023-12-16 21:59:39 +01:00
parent 638e762d3e
commit 469d3ef3d5
4 changed files with 34 additions and 2 deletions

View File

@ -142,7 +142,7 @@ public:
// --- global colors
/* the default implementation of parse_color() may be enough */
virtual int parse_color(const char *p, uchar &r, uchar &g, uchar &b);
virtual void get_system_colors() {}
virtual void get_system_colors();
/* the default implementation of get_system_scheme() may be enough */
virtual const char *get_system_scheme();

View File

@ -23,6 +23,7 @@
#include "Fl_Screen_Driver.H"
#include <FL/Fl_Image.H>
#include <FL/Fl.H>
#include <FL/platform.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Input.H>
@ -32,6 +33,12 @@
#include <FL/Fl_Tooltip.H>
#include <string.h> // for memchr
// these are set by Fl::args() and override any system colors: from Fl_get_system_colors.cxx
extern const char *fl_fg;
extern const char *fl_bg;
extern const char *fl_bg2;
// end of extern additions workaround
char Fl_Screen_Driver::bg_set = 0;
char Fl_Screen_Driver::bg2_set = 0;
char Fl_Screen_Driver::fg_set = 0;
@ -181,6 +188,29 @@ int Fl_Screen_Driver::screen_num(int x, int y, int w, int h)
return best_screen;
}
static void getsyscolor(const char* arg, void (*func)(uchar,uchar,uchar))
{
if (arg && *arg) {
uchar r,g,b;
if (!fl_parse_color(arg, r,g,b))
Fl::error("Unknown color: %s", arg);
else
func(r,g,b);
}
}
static void set_selection_color(uchar r, uchar g, uchar b)
{
Fl::set_color(FL_SELECTION_COLOR,r,g,b);
}
void Fl_Screen_Driver::get_system_colors()
{
if (!bg2_set) getsyscolor(fl_bg2, Fl::background2);
if (!fg_set) getsyscolor(fl_fg, Fl::foreground);
if (!bg_set) getsyscolor(fl_bg, Fl::background);
getsyscolor(0, set_selection_color);
}
const char *Fl_Screen_Driver::get_system_scheme()
{

View File

@ -210,6 +210,8 @@ void Fl_Cocoa_Screen_Driver::get_system_colors()
{
open_display();
Fl_Screen_Driver::get_system_colors();
if (!bg2_set) Fl::background2(0xff, 0xff, 0xff);
if (!fg_set) Fl::foreground(0, 0, 0);
if (!bg_set) Fl::background(0xd8, 0xd8, 0xd8);

View File

@ -26,6 +26,6 @@ int main(int argc, char **argv) {
box->labelsize(36);
box->labeltype(FL_SHADOW_LABEL);
window->end();
window->show();//argc, argv);
window->show(argc, argv);
return Fl::run();
}