From de6f468b5121df32566bbaa3b250d35eae8e1178 Mon Sep 17 00:00:00 2001
From: Albrecht Schlosser
All programs must include the file <FL/Fl.H>. +
All programs must include the file
Listing 1 - "hello.cxx" -
-#include <FL/Fl.H> -#include <FL/Fl_Window.H> -#include <FL/Fl_Box.H> ++\endcodeListing 1 - "hello.cxx" +\code +#include
+#include +#include int main(int argc, char **argv) { - Fl_Window *window = new Fl_Window(300,180); - Fl_Box *box = new Fl_Box(20,40,260,100,"Hello, World!"); - box->box(FL_UP_BOX); - box->labelsize(36); - box->labelfont(FL_BOLD+FL_ITALIC); - box->labeltype(FL_SHADOW_LABEL); - window->end(); - window->show(argc, argv); - return Fl::run(); + Fl_Window *window = new Fl_Window(300,180); + Fl_Box *box = new Fl_Box(20,40,260,100,"Hello, World!"); + box->box(FL_UP_BOX); + box->labelsize(36); + box->labelfont(FL_BOLD+FL_ITALIC); + box->labeltype(FL_SHADOW_LABEL); + window->end(); + window->show(argc, argv); + return Fl::run(); } -
After including the required header files, the program then creates a window. All following widgets will automatically be children of this window.
--Fl_Window *window = new Fl_Window(300,180); -+\code +Fl_Window *window = new Fl_Window(300,180); +\endcode -
Then we create a box with the "Hello, World!" string in it. FLTK automatically adds +
Then we create a box with the "Hello, World!" string in it. FLTK automatically adds the new box to window, the current grouping widget.
--Fl_Box *box = new Fl_Box(20,40,260,100,"Hello, World!"); -+\code +Fl_Box *box = new Fl_Box(20,40,260,100,"Hello, World!"); +\endcode
Next, we set the type of box and the size, font, and style of the label:
--box->box(FL_UP_BOX); -box->labelsize(36); -box->labelfont(FL_BOLD+FL_ITALIC); -box->labeltype(FL_SHADOW_LABEL); -+\code +box->box(FL_UP_BOX); +box->labelsize(36); +box->labelfont(FL_BOLD+FL_ITALIC); +box->labeltype(FL_SHADOW_LABEL); +\endcode
We tell FLTK that we will not add any more widgets to window.
--window->end(); -+\code +window->end(); +\endcode
Finally, we show the window and enter the FLTK event loop:
--window->show(argc, argv); -return Fl::run(); -+\code +window->show(argc, argv); +return Fl::run(); +\endcode
The resulting program will display the window in Figure 2-1. -You can quit the program by closing the window or pressing the +You can quit the program by closing the window or pressing the ESCape key.
-
-Figure 2-1: The Hello, World! Window
The widgets are created using the C++ new operator. For most widgets the arguments to the constructor are:
-+\code Fl_Widget(x, y, width, height, label) -+\endcode
The x and y parameters determine where the widget or window is placed on the screen. In FLTK the top left @@ -107,8 +105,8 @@ copy of it - it just uses the pointer.
Widgets are commonly ordered into functional groups, which in turn may be grouped again, creating a hierarchy of widgets. FLTK makes it easy to fill groups by automatically adding all widgets -that are created between a myGroup->begin() and -myGroup->end(). In this example, myGroup +that are created between a myGroup->begin() and +myGroup->end(). In this example, myGroup would be the current group.
Newly created groups and their derived widgets implicitly call @@ -122,19 +120,19 @@ hierarchies. New widgets can now be added manually using
box->box(FL_UP_BOX) sets the type of box the +
box->box(FL_UP_BOX) sets the type of box the Fl_Box draws, changing it from the default of FL_NO_BOX, which means that no box is drawn. In our -"Hello, World!" example we use FL_UP_BOX, +"Hello, World!" example we use FL_UP_BOX, which means that a raised button border will be drawn around the widget. You can learn more about boxtypes in Chapter 3.
You could examine the boxtype in by doing -box->box(). FLTK uses method name overloading to make +box->box(). FLTK uses method name overloading to make short names for get/set methods. A "set" method is always of -the form "void name(type)", and a "get" method is always -of the form "type name() const".
+the form "void name(type)", and a "get" method is always +of the form "type name() const".All widgets support labels. In the case of window widgets, +the label is used for the label in the title bar. Our example +program calls the labelfont(), labelsize, +and labeltype() methods.
+All widgets support labels. In the case of window widgets, the label is used for the label in the title bar. Our example program calls the @@ -203,17 +206,16 @@ write, or when an error condition occurs on a file. They are most often used to monitor network connections (sockets) for data-driven displays.
-FLTK applications must periodically check -(Fl::check()) or wait (Fl::wait()) for events -or use the Fl::run() +
FLTK applications must periodically check (Fl::check()) +or wait (Fl::wait()) for events or use the Fl::run() method to enter a standard event processing loop. Calling -Fl::run() is equivalent to the following code:
+Fl::run() is equivalent to the following code: -+\code while (Fl::wait()); -+\endcode -
Fl::run() does not return until all of the windows +
Fl::run() does not return until all of the windows under FLTK control are closed by the user or your program.
+\code CC -I/usr/local/include ... gcc -I/usr/local/include ... -+\endcode
The fltk-config script included with FLTK can be used to get the options that are required by your compiler:
-+\code CC `fltk-config --cxxflags` ... -+\endcode
Similarly, when linking your application you will need to tell the compiler to use the FLTK library:
--CC ... -L/usr/local/lib -lfltk -lXext -lX11 -lm +\code +CC ... -L/usr/local/lib -lfltk -lXext -lX11 -lm gcc ... -L/usr/local/lib -lfltk -lXext -lX11 -lm -+\endcode
Aside from the "fltk" library, there is also a "fltk_forms"
library for the XForms compatibility classes, "fltk_gl" for the
OpenGL and GLUT classes, and "fltk_images" for the image file
-classes, Fl_Help_Dialog
-widget, and system icon support.
-
-
| Note:
- The libraries are named "fltk.lib", "fltkgl.lib", "fltkforms.lib", +classes, Fl_Help_Dialog widget, and system icon support. + +\note + The libraries are named "fltk.lib", "fltkgl.lib", "fltkforms.lib", and "fltkimages.lib", respectively under Windows. - |
-
As before, the fltk-config script included with FLTK can be used to get the options that are required by your linker:
-+\code CC ... `fltk-config --ldflags` -+\endcode
The forms, GL, and images libraries are included with the "--use-foo" options, as follows: -
+\code CC ... `fltk-config --use-forms --ldflags` CC ... `fltk-config --use-gl --ldflags` CC ... `fltk-config --use-images --ldflags` CC ... `fltk-config --use-forms --use-gl --use-images --ldflags` -+\endcode
Finally, you can use the fltk-config script to compile a single source file as a FLTK program: -
+\code fltk-config --compile filename.cpp fltk-config --use-forms --compile filename.cpp fltk-config --use-gl --compile filename.cpp fltk-config --use-images --compile filename.cpp fltk-config --use-forms --use-gl --use-images --compile filename.cpp -+\endcode
Any of these will create an executable named filename. @@ -294,11 +289,10 @@ fltk-config --use-forms --use-gl --use-images --compile filename.cpp
In Visual C++ you will need to tell the compiler where to find the FLTK header files. This can be done by selecting -"Settings" from the "Project" menu and then -changing the "Preprocessor" settings under the -"C/C++" tab. You will also need to add the FLTK and -WinSock (WSOCK32.LIB) libraries to the "Link" -settings.
+"Settings" from the "Project" menu and then changing the +"Preprocessor" settings under the "C/C++" tab. You will also +need to add the FLTK and WinSock2 (WS2_32.LIB) libraries to +the "Link" settings.You can build your Microsoft Windows applications as Console or WIN32 applications. If you want to use the standard C main() @@ -306,7 +300,7 @@ function as the entry point, FLTK includes a WinMain() function that will call your main() function for you.
Note: The Visual C++ 5.0 optimizer is known to cause problems with -many programs. We only recommend using the "Favor Small Code" +many programs. We only recommend using the "Favor Small Code" optimization setting. The Visual C++ 6.0 optimizer seems to be much better and can be used with the "optimized for speed" setting.
@@ -325,7 +319,7 @@ better and can be used with the "optimized for speed" setting.The proper way to include FLTK header files is:
--#include <FL/Fl_xyz.H> -- -
| Note:
+\code
+#include Case is significant on many operating systems, +\note + Case is significant on many operating systems, and the C standard uses the forward slash (/) to separate directories. Do not use any of the following - include lines: - -- #include <FL\Fl_xyz.H> - #include <fl/fl_xyz.h> - #include <Fl/fl_xyz.h> -+ include lines: - |
-