FLTK Dark Theme

765 views
Skip to first unread message

Robin Rowe

unread,
Apr 1, 2020, 11:01:01 AM4/1/20
to fltkg...@googlegroups.com
How do I give my FLTK app a dark theme like Nuke?

https://beforesandafters.com/wp-content/uploads/2020/01/Nuke-8-pic-2.png

The FLTK scheme() choices are "none" or "base", "plastic", "gtk+" and
"gleam". Any efforts to improve upon this? Links?

Robin
--
Robin Rowe
CinePaint Project Manager
Beverly Hills, California
imdb.me/robinrowe

Manolo

unread,
Apr 1, 2020, 11:45:38 AM4/1/20
to fltk.general
There's no preset dark theme, yet. But if you put that

  Fl::get_system_colors();
  Fl::background(0, 0, 0);
  Fl::foreground(250, 250, 250);

before any widget is created, you'll get somewhat closer to your goal.

Greg Ercolano

unread,
Apr 1, 2020, 12:43:52 PM4/1/20
to fltkg...@googlegroups.com
On 2020-04-01 08:00, Robin Rowe wrote:
How do I give my FLTK app a dark theme like Nuke?

https://beforesandafters.com/wp-content/uploads/2020/01/Nuke-8-pic-2.png

The FLTK scheme() choices are "none" or "base", "plastic", "gtk+" and 
"gleam". Any efforts to improve upon this? Links?


I rolled my own colormap and load it based on what the user chooses from a menu.

I use the gtk+ scheme with a bunch of different color maps for the user to choose from,
one being a "dark" theme. An ascii config file in the app's install directory defines the
different color maps so the user can actually change or make new ones.

Here's a screenshot comparing my 'black' vs 'tan' color map options which the user
can change in the Edit -> Preferences:



    I've attached the ascii file defining the color maps which you can try for yourself
    as a means of getting started. Loading this file is just a matter of taking the cmap and rgb
    values and setting them with Fl::set_color(c,r,g,b);
    Certain colors I have configured specially for my app, so be sure to do some research before
    just using it wholesale. It did take some time to choose the colormap carefully and adjust widgets
    in some cases to get everything to look right for my case.


irush-themes

Greg Ercolano

unread,
Apr 1, 2020, 1:16:22 PM4/1/20
to fltkg...@googlegroups.com
On 2020-04-01 09:43, Greg Ercolano wrote:
> I rolled my own colormap and load it based on what the user chooses from a menu.
> [..]
>     I've attached the ascii file defining the color maps which you can try for yourself
>     as a means of getting started. Loading this file is just a matter of taking the cmap and rgb
>     values and setting them with Fl::set_color(c,r,g,b);
>

I might as well post this too; it's the default application colors I set
in the code before loading the text config files, so that if for some reason
the config files go missing, there's at least a consistent 'default'.

These are basically the colors WinXP used to provide, which I always kinda
liked, as they were very similar to the colors used by SGI + rapidapp + Motif.

Note at the end of the code, a call to Fl::reload_scheme() is needed
to re-apply the changes to the current FLTK scheme.

--- snip

// CHANGE THE GRAYSCALE RAMP TO A 'WINXP' STYLE TAN RAMP
void TanColormap_FLTKSUBS(void)
{
// WIN XP 24 COLOR GRAY SCALE (32-56)
int c = 32;
Fl::set_color(Fl_Color(c),0 ,0 ,0 ); c++;
Fl::set_color(Fl_Color(c),114,100,46 ); c++;
Fl::set_color(Fl_Color(c),120,107,56 ); c++;
Fl::set_color(Fl_Color(c),127,114,65 ); c++;
Fl::set_color(Fl_Color(c),133,121,75 ); c++;
Fl::set_color(Fl_Color(c),140,128,84 ); c++;
Fl::set_color(Fl_Color(c),146,135,94 ); c++;
Fl::set_color(Fl_Color(c),152,142,103 ); c++;
Fl::set_color(Fl_Color(c),159,149,113 ); c++;
Fl::set_color(Fl_Color(c),165,156,122 ); c++;
Fl::set_color(Fl_Color(c),172,163,132 ); c++;
Fl::set_color(Fl_Color(c),178,170,141 ); c++;
Fl::set_color(Fl_Color(c),185,178,151 ); c++;
Fl::set_color(Fl_Color(c),191,185,160 ); c++;
Fl::set_color(Fl_Color(c),197,192,170 ); c++;
Fl::set_color(Fl_Color(c),204,199,179 ); c++;
Fl::set_color(Fl_Color(c),210,206,189 ); c++;
Fl::set_color(Fl_Color(c),217,213,198 ); c++;
Fl::set_color(Fl_Color(c),223,220,208 ); c++;
Fl::set_color(Fl_Color(c),229,227,217 ); c++;
Fl::set_color(Fl_Color(c),236,234,227 ); c++;
Fl::set_color(Fl_Color(c),242,241,236 ); c++;
Fl::set_color(Fl_Color(c),249,248,246 ); c++;
Fl::set_color(Fl_Color(c),255,255,255 ); c++;
Fl::reload_scheme(); // if plastic/gtk+/etc, update with new colors
}


--- snip

And here's the function that loads the theme file I posted earlier,
just for reference. (This code uses my own string and list library,
because at the time the code was written, STL was still unstable and/or
unavailable on the SGI compilers. But it should be easy to figure out what's
being done here, and retool it for stl or whatever)

--- snip
// LOAD A COLORMAP THEME FROM A FILE
// Returns a list of all possible theme names, and if a theme name is specified,
// that colormap theme is loaded into FLTK's colormap.
// Returns 0 on success, -1 on error (errmsg has reason).
//
// THEME FILE FORMAT
// Blank lines and lines that start with '#' are ignored.
// Comments may be added at the end of lines if they start with '#'.
//
// New themes are defined with 'theme "Some Name"'. Names can contain spaces
// but not double quotes.
//
// In each theme, an optional 'fltkscheme "Name"' can appear to define
// a particular FLTK scehme be used when this theme is loaded.
//
// The special command 'fltkscheme "Default"' will load whatever configuration
// the app may have previously saved with SaveColormap_FLTKSUBS().
// The special command 'fltkscheme "none"' will use the FLTK default 'empty'
// theme, same as Fl::scheme("");
//
// One or more "cmap" commands can be specified to redefine particular
// FLTK colormap entries. You do not have to redefine all 255 colormap entries;
// any you don't define will remain unchanged.
//
// A single file can define more than one theme, simply by having multiple
// 'theme' entries. Braces are used to enclose all the fltkscheme/cmap entries
// for each theme.
//
// The general format is:
//
// theme "Theme Name" # defines a new theme named "Theme Name"
// {
// fltkscheme "Name" # [optional] defines the FLTK scheme to use for this theme.
// # possible FLTK scheme names are "", "plastic", "gtk+", etc.
//
// cmap <color#> <R> <G> <B> # [optional] defines a new R/G/B value for an FLTK colormap entr
// # <color#>: is an FLTK colormap # (0-255)
// # <R> <G> <B>: 8 bit colormap values (0-255)
// }
//
// An actual example being:
//
// theme "Dark Grey"
// {
// cmap 1 180 0 0
// cmap 2 0 180 0
// [..]
// cmap 255 120 120 120
// }
//
// NOTE: Assumes app has already called SaveColormap_FLTKSUBS() at app startup.
//
int LoadThemes_FLTKSUBS(const String& filename, // file to load
const String& load_themename, // theme name to load..
// ..can be "" to just get the themenames[]
List<String>& themenames, // returned names of all themes
String& errmsg) // error message if return -1
{
int debug = (getenv("IRUSH_DEBUG") && getenv("IRUSH_DEBUG")[0] == '1') ? 1 : 0;

if ( debug )
{
fprintf(stderr, "DEBUG: LoadThemes_FLTKSUBS(): filename='%s', load_themename='%s'\n",
filename.Chars(), load_themename.Chars());
}

MyFile file;
if ( file.Open(filename, "r") < 0 )
{
errmsg = file.errmsg;
return(-1);
}

int line = 0;
String s;
int set_color = 0;
while ( s.FgetsNoCRLF(file.GetFp(), 4096) )
{
++line;
s.StripWhite();

if ( s[0] == '#' || s[0] == '\0' ) continue;

String key;
s >> key;

// LOAD A THEME
if ( key == "theme" )
{
String themename;
if ( s.ParseQuotedAtCurPos('"', themename) < 0 )
{
ERRMSG << filename << ": (Line " << line << "): '"
<< s << "': expected '" << key << " \"name\"";
return(-1);
}

themenames.Append(themename);
int loadit = ( themename == load_themename );

if ( debug )
{
fprintf(stderr, "GOT THEME: '%s' -- Match '%s'? %s\n",
themename.Chars(), load_themename.Chars(), (loadit?"Yes":"No"));
}

while ( s.FgetsNoCRLF(file.GetFp(), 4096) )
{
++line;
s.StripWhite();

if ( s[0] == '#' || s[0] == '\0' ) continue;

// HANDLE BRACES
if ( s[0] == '{' ) continue; // skip opening
if ( s[0] == '}' ) break; // break on close

s >> key;
if ( key == "cmap" )
{
int ci,r,g,b;
s >> ci;
s >> r;
s >> g;
s >> b;
if ( s.Fail() )
{
ERRMSG << "'" << s << "': expected <c> <r> <g> <b>";
return(-1);
}

if ( ! loadit ) continue;

Fl::set_color(Fl_Color(ci), (uchar)r, (uchar)g, (uchar)b);
set_color = 1;
continue;
}

if ( key == "fltkscheme" )
{
String scheme;
if ( s.ParseQuotedAtCurPos('"', scheme) < 0 )
{
ERRMSG << filename << ": (Line " << line << "): '"
<< s << "': expected '" << key << " \"schemename\"";
return(-1);
}

if ( ! loadit ) continue;

if ( scheme == "Default" )
{
Fl::scheme("gtk+");
Fl::reload_scheme();
}
else
{
Fl::scheme(scheme);
Fl::reload_scheme();
}
continue;
}

ERRMSG << filename << ": (Line " << line << "): '" << s << "': unknown command";
return(-1);
}
continue;
}

// ERROR
ERRMSG << filename << ": (Line " << line << "): '" << s << "': unknown command";
return(-1);
}

// DEFAULT THEME AND NONE DEFINED? USE A DEFAULT WE LIKE
if ( load_themename == "Default" && set_color == 0 )
{
Fl::scheme("gtk+"); // we like gtk+ as a "default"
RestoreColormap_FLTKSUBS(); // fltk default map
Fl::reload_scheme();
}

if ( set_color )
{
// SaveColormap_FLTKSUBS(); // update defaults
if ( Fl::scheme() == 0 || ( Fl::scheme() && strcmp(Fl::scheme(), "none") != 0 ) )
{ Fl::reload_scheme(); } // reload scheme
}

file.Close();
return(0);
}

--- snip
Reply all
Reply to author
Forward
0 new messages