Initialization and Argument Parser


Enumerations

enum  {
  RGB_COLOR, INDEXED_COLOR, SINGLE_BUFFER, DOUBLE_BUFFER,
  ACCUM_BUFFER, ALPHA_BUFFER, DEPTH_BUFFER, STENCIL_BUFFER,
  RGB24_COLOR, MULTISAMPLE, STEREO
}

Functions

int fltk::arg (int, char **, int &)
void fltk::args (int, char **)
int fltk::args (int, char **, int &, int(*)(int, char **, int &)=0)
void fltk::display (const char *)
bool enable_tablet_events ()
bool glVisual (int)
void fltk::own_colormap ()
void fltk::Window::show (int, char **)
float fltk::version ()
bool fltk::visual (int)
int XParseGeometry (const char *, int *, int *, unsigned int *, unsigned int *)

Variables

const char *const fltk::help

Detailed Description

Warning: most of these functions will not work (and may crash) after Window::show() has been called the first time. Calling Window::show() will call any necessary setup that you have not called yourself.

The args() argument parser is entirely optional. It was written to make demo programs easy to write, although some minor work was done to make it usable by more complex programs. But there is no requirement that you call it or even acknoledge it's existence, if you prefer to use your own code to parse switches.


Function Documentation

float version  ) 
 

Returns the version number of fltk. This can be compared to the value of the FL_VERSION macro to see if the shared library of fltk your program linked with is up to date.

The FLTK version number is stored in a number of compile-time constants:

  • FL_MAJOR_VERSION - The major release number, currently 2.
  • FL_MINOR_VERSION - The minor release number, currently 0.
  • FL_PATCH_VERSION - The patch release number, currently 1.
  • FL_VERSION - A combined floating-point version number of the form M.mmpp where M is the major number, mm is the minor number, and pp is the patch number, currently 2.0001.

void display const char *  d  ) 
 

Startup method to set what X display to use. This uses setenv() to change the $DISPLAY environment variable, so it will affect programs that are exec'd by this one.

This does some "uglification" required by X. If there is no colon in the string it appends ":0.0" to it. Thus a plain machine name may be used.

On non-X systems this sets the environment variable anyway, even though it probably will not affect the display used. It appears that putenv is missing on some versions of Windows so I commented it all out there, sigh.

int arg int  argc,
char **  argv,
int &  i
 

Consume a single switch from argv, starting at word i. Returns the number of words eaten (1 or 2, or 0 if it is not recognized) and adds the same value to i. You can use this function if you prefer to control the incrementing through the arguments yourself. The arguments recognized are listed under args().

int args int  argc,
char **  argv,
int &  i,
int(*)(int, char **, int &)  cb = 0
 

Consume all switches from argv.

To use the switch parser, call fltk::args(argc,argv) near the start of your program. This does not open the display, instead switches that need the display open are stashed into static variables. Then you must display your first window by calling window->show(argc,argv), which will do anything stored in the static variables.

callback lets you define your own switches. It is called with the same argc and argv, and with i the index of each word. The callback should return zero if the switch is unrecognized, and not change i. It should return non-zero if the switch is recognized, and add at least 1 to i (it can add more to consume words after the switch). This function is called before any other tests, so you can override any FLTK switch (this is why fltk can use very short switches instead of the long ones all other toolkits force you to use).

On return i is set to the index of the first non-switch. This is either:

  • The first word that does not start with '-'.
  • The word "-" (used by many programs to name stdin as a file)
  • The first word after "--" (GNU standard end-of-switches switch)
  • The first unrecognized switch (return value is 0).
  • argc

The return value is i unless an unrecognized switch is found, in which case it is zero. If your program takes no arguments other than switches you should produce an error if the return value is less than argc.

All switches may be abbreviated one letter and case is ignored:

  • -iconic Window::iconize() will be done to the window.
  • -geometry WxH Window is resized to this width & height
  • -geometry +X+Y Initial window position
  • -geometry WxH+X+Y Window is resized and positioned.
  • -display host or -display host:n.n The X display to use (ignored under WIN32).
  • -name string will set the Window::label()
  • -bg color XParseColor is used to lookup the passed color and then fltk::background() is done. Under WIN32 only color names of the form "#xxxxxx" are understood.
  • -background color is the same as -bg color

void args int  argc,
char **  argv
 

The second form of fltk::args() is useful if your program does not have command line switches of its own. It parses all the switches, and if any are not recognized it calls fltk::fatal(fltk::help).

bool visual int  flags  ) 
 

X-specific crap to allow you to force the "visual" used by fltk to one you like, rather than the "default visual" which in many cases has less capabilities than your machine really has! For instance fltk::visual(fltk::RGB_COLOR) will get you a full color display instead of an 8-bit colormap, if possible.

You must call this before you show() any windows. The integer argument is an 'or' of the following:

  • fltk::INDEX indicates that a colormapped visual is ok. This call will normally fail if a TrueColor visual cannot be found.
  • fltk::RGB this value is zero and may be passed to indicate that fltk::INDEX is not wanted.
  • fltk::RGB8 indicates that the TrueColor visual must have at least 8 bits of red, green, and blue (Windows calls this "millions of colors").
  • fltk::DOUBLE indicates that hardware accelerated double buffering is wanted. This will make fltk::DoubleBufferWindow work better.

This returns true if the system has the capabilities by default or FLTK suceeded in turing them on. Your program will still work even if this returns false (it just won't look as good).

On non-X systems this just returns true or false indicating if the system supports the passed values.

void own_colormap  ) 
 

Makes FLTK use its own X colormap. This may make FLTK display better and will reduce conflicts with other programs that want lots of colors. However the colors may flash as you move the cursor between windows. This function is a no-op on non-X systems or if the visual is not colormapped (which means it probably does nothing on any modern system).

Use fltk::setvisual() to set the visual first.

void show int  argc,
char **  argv
[inherited]
 

This must be called after fltk::args(argc,argv) to show the "main" window, this indicates which window should be affected by any -geometry switch. In addition if fltk::args() has not been called yet this does so, this is a useful shortcut for the main window in a small program.


Variable Documentation

const char *const help
 

This is a portion of the string printed by fltk::args() detects an invalid argument on the command-line. You can add this to your own error or help message to show the fltk switches. It's value is (no newline at start or the end):

 -d[isplay] host:n.n
 -g[eometry] WxH+X+Y
 -n[ame] windowname
 -i[conic]
 -bg color


Sun May 8 21:48:57 2005. FLTK ©2004 Bill Spitzak and others. See Main Page for details.