#include <FL/x.H>
Despite the name, this header file will define the appropriate interface for your environment. The pages that follow describe the functionality that is provided for each operating system.
WARNING: The interfaces provided by this header file may change radically in new FLTK releases. Use them only when an existing generic FLTK interface is not sufficient.
|
fl_xevent
variable.FL_SHORTCUT
.
shown()
.
NULL
if not found. This function uses a cache so it is slightly faster than iterating through the windows yourself.
add_handler()
functions all return 0, this function will return false.
extern Display *fl_display; extern Window fl_window; extern GC fl_gc; extern int fl_screen; extern XVisualInfo *fl_visual; extern Colormap fl_colormap;
You must use them to produce Xlib calls. Don't attempt to change them. A typical X drawing call is written like this:
XDrawSomething(fl_display, fl_window, fl_gc, ...);
Other information such as the position or size of the X window can be found by looking at Fl_Window::current(), which returns a pointer to the Fl_Window being drawn.
unsigned long fl_xpixel(Fl_Color i)
unsigned long fl_xpixel(uchar r, uchar g, uchar b)
fl_parse_color()
can only convert names in hexadecimal encoding, for example #ff8083
.
fl_gc
, which is not set until fl_draw() is called. If FLTK was compiled with Xft support, fl_xfont
will usually be 0 and fl_xftfont
will contain a pointer to the XftFont
structure instead.
fl_xftfont
points to the xft font selected by the most recent fl_font(). Otherwise it will be 0. fl_xftfont
should be cast to XftFont*
.
putenv("DISPLAY=...")
so that child programs will display on the same screen if called with exec()
. This must be done before the display is opened. This call is provided under MacOS and WIN32 but it has no effect.
NULL
before the display is opened.
fl_display
is non-zero. You should call this if you wish to do X calls and there is a chance that your code will be called before the first show()
of a window.
fl_open_display()
to the default screen. You can change it by setting this to a different value immediately afterwards. It can also be set by changing the last number in the Fl::display() string to "host:0.#".
fl_open_display()
to the default visual and colormap. You can change them before calling show()
on the first window. Typical code for changing the default visual is: Fl::args(argc, argv); // do this first so $DISPLAY is set fl_open_display(); fl_visual = find_a_good_visual(fl_display, fl_screen); if (!fl_visual) Fl::abort("No good visual"); fl_colormap = make_a_colormap(fl_display, fl_visual->visual, fl_visual->depth); // it is now ok to show() windows: window->show(argc, argv);
draw()
method that uses Xlib (and/or OpenGL) calls only.FLTK can also manage XID's provided by other libraries or programs, and call those libraries when the window needs to be redrawn.
To do this, you need to make a subclass of Fl_Window and override some of these virtual functions:
virtual void Fl_Window::show()
shown()
this must cause it to be raised, this can usually be done by calling Fl_Window::show(). If not shown()
your implementation must call either Fl_X::set_xid() or Fl_X::make_xid().void MyWindow::show() { if (shown()) {Fl_Window::show(); return;} // you must do this! fl_open_display(); // necessary if this is first window // we only calculate the necessary visual colormap once: static XVisualInfo *visual; static Colormap colormap; if (!visual) { visual = figure_out_visual(); colormap = XCreateColormap(fl_display, RootWindow(fl_display,fl_screen), vis->visual, AllocNone); } Fl_X::make_xid(this, visual, colormap); }
fl_window
and fl_gc
and then calling the draw()
method. For your own windows you might just want to put all the drawing code in here.damage()
calls done so far is in Fl_X::i(this)->region
. If NULL
then you should redraw the entire window. The undocumented function fl_clip_region(XRegion)
will initialize the FLTK clip stack with a region or NULL
for no clipping. You must set region to NULL
afterwards as fl_clip_region()
will own and delete it when done.damage() & FL_DAMAGE_EXPOSE
then only X expose events have happened. This may be useful if you have an undamaged image (such as a backing buffer) around.void MyWindow::flush() { fl_clip_region(Fl_X::i(this)->region); Fl_X::i(this)->region = 0; if (damage() != 2) {... draw things into backing store ...} ... copy backing store to window ... }
xid()
. If you override this, you must also override the destructor as shown: void MyWindow::hide() { if (mypixmap) { XFreePixmap(fl_display,mypixmap); mypixmap = 0; } Fl_Window::hide(); // you must call this }
hide()
you must override the destructor as well (otherwise only the base class hide()
is called): MyWindow::~MyWindow() { hide(); }
void Fl_Window::icon(const void *)
Pixmap
to a char*
when calling this method. To set a monochrome icon using a bitmap compiled with your application use: #include "icon.xbm" fl_open_display(); // needed if display has not been previously opened Pixmap p = XCreateBitmapFromData(fl_display, DefaultRootWindow(fl_display), icon_bits, icon_width, icon_height); window->icon((const void*)p);
#include <X11/xpm.h> #include "icon.xpm" fl_open_display(); // needed if display has not been previously opened Pixmap p, mask; XpmCreatePixmapFromData(fl_display, DefaultRootWindow(fl_display), icon_xpm, &p, &mask, NULL); window->icon((const void *)p);
NOTE: You must call Fl_Window::show(int argc, char** argv) for the icon to be used. The Fl_Window::show() method does not bind the icon to the window.
|
background
- The default background color for widgets (color).dndTextOps
- The default setting for drag and drop text operations (boolean).foreground
- The default foreground (label) color for widgets (color).scheme
- The default scheme to use (string).selectBackground
- The default selection color for menus, etc. (color).Text.background
- The default background color for text fields (color).tooltips
- The default setting for tooltips (boolean).visibleFocus
- The default setting for visible keyboard focus on non-text widgets (boolean).fltk.background
). If no match is found, a global search is done (e.g. *background
).
You can probably combine FLTK with other libraries that make their own WIN32 window classes. The easiest way is to call Fl::wait(), as it will call DispatchMessage()
for all messages to the other windows. If necessary you can let the other library take over as long as it calls DispatchMessage()
, but you will have to arrange for the function Fl::flush() to be called regularly so that widgets are updated, timeouts are handled, and the idle functions are called.
extern MSG fl_msg
GetMessage()
, which is called by Fl::wait(). This may not be the most recent message sent to an FLTK window, because silly WIN32 calls the handle procedures directly for some events (sigh).
DefWindowProc()
.
shown()
.
NULL
if not found. This function uses a cache so it is slightly faster than iterating through the windows yourself.
extern HINSTANCE fl_display; extern HWND fl_window; extern HDC fl_gc; COLORREF fl_RGB(); HPEN fl_pen(); HBRUSH fl_brush();
These global variables are set before Fl_Widget::draw() is called, or by Fl_Window::make_current(). You can refer to them when needed to produce GDI calls, but don't attempt to change them. The functions return GDI objects for the current color set by fl_color() and are created as needed and cached. A typical GDI drawing call is written like this:
DrawSomething(fl_gc, ..., fl_brush());
It may also be useful to refer to Fl_Window::current() to get the window's size or position.
void Fl_Window::icon(const void *)
HICON
handle to a char*
when calling this method. To set the icon using an icon resource compiled with your application use: window->icon((const void *)LoadIcon(fl_display, MAKEINTRESOURCE(IDI_ICON)));
LoadImage()
and related functions to load specific resolutions or create the icon from bitmap data.NOTE: You must call Fl_Window::show(int argc, char** argv) for the icon to be used. The Fl_Window::show() method does not bind the icon to the window.
|
To always get a console window you simply create a console application (the "/SUBSYSTEM:CONSOLE" option for the linker). For a GUI-only application create a WIN32 application (the "/SUBSYSTEM:WINDOWS" option for the linker).
FLTK includes a WinMain()
function that calls the ANSI standard main()
entry point for you. This function creates a console window when you use the debug version of the library.
WIN32 applications without a console cannot write to stdout
or stderr
, even if they are run from a console window. Any output is silently thrown away. Additionally, WIN32 applications are run in the background by the console, although you can use "start /wait program" to run them in the foreground.
Fl::wait()
does not return until it is activated again, even though many events are delivered to the program. This can cause idle background processes to stop unexpectedly. This also happens while the user is dragging or resizing windows or otherwise holding the mouse down. We were forced to remove most of the efficiency FLTK uses for redrawing in order to get windows to update while being moved. This is a design error in WIN32 and probably impossible to get around.Fl_Gl_Window::can_do_overlay()
returns true until the first time it attempts to draw an overlay, and then correctly returns whether or not there is overlay hardware.SetCapture
(used by Fl::grab()
) doesn't work, and the main window title bar turns gray while menus are popped up.gcc 3.4.4
and -Os
exposes an optimisation bug in gcc. The symptom is that when drawing filled circles only the perimeter is drawn. This can for instance be seen in the symbols demo. Other optimisation options such as -O2 and -O3 seem to work OK. More details can be found in STR#1656Control, Option, and Command Modifier Keys
FL_CTRL
, the 'option' key to FL_ALT
and the 'Apple' key to FL_META
. Furthermore, FL_COMMAND
designates the 'Apple' key on Mac OS X and the 'control' key on other platforms. Keyboard events return the key name in Fl::event_key() and the keystroke translation in Fl::event_text(). For example, typing Option-Y on a Mac US keyboard will set FL_ALT
in Fl::event_state(), set Fl::event_key() to 'y' and return the Yen symbol in Fl::event_text().
FL_CLOSE
event to all open windows. If all windows close, the application will terminate.
fl_open_callback
show()
of a window.
NULL
if the window has not been shown. This reference is a pointer to an instance of the subclass FLWindow of Cocoa's NSWindow class.
NULL
if not found. FLTK windows that are children of top-level windows share the Window
of the top-level window.
cb
will be called with a single Unix-style file name and path. If multiple files were dropped, fl_open_callback()
will be called multiple times.
cb
to the "About myprog" item of the system application menu. cb
will be called with NULL first argument and user_data
second argument.
fl_gc
is the appropriate Quartz 2D drawing environment. Include FL/x.H to declare the fl_gc
variable.OS X double-buffers all windows automatically. On OS X, Fl_Window and Fl_Double_Window are handled internally in the same way.
Caution: When using UNIX commands to copy or move executables, OS X will NOT copy any resource forks! For copying and moving use CpMac and MvMac respectively. For creating a tar archive, all executables need to be stripped from their Resource Fork before packing, e.g. "DeRez fluid > fluid.r". After unpacking the Resource Fork needs to be reattached, e.g. "Rez fluid.r -o fluid". |
It is advisable to use the Finder for moving and copying and Mac archiving tools like Sit for distribution as they will handle the Resource Fork correctly.
[Prev] Forms Compatibility | [Index] | Migrating Code from FLTK 1.0 to 1.1 [Next] |