diff --git a/documentation/Fl_Widget.html b/documentation/Fl_Widget.html index 5509a8f85..933e1ef7e 100644 --- a/documentation/Fl_Widget.html +++ b/documentation/Fl_Widget.html @@ -53,11 +53,11 @@ after these.
  • argument
  • box
  • callback -
  • changed -Microsoft Windows developers please note: case *is* significant +Microsoft Windows developers please note: case *is* significant under other operating systems, and the C standard uses the forward slash (/) to separate directories. The following #include directives are *not* recommended for portability reasons: @@ -71,9 +71,8 @@ header files. This can be done by selecting "Settings" from the

    You can build your Microsoft Windows applications as Console or WIN32 applications. If you want to use the standard C main() -function as the entry point, enter the name mainCRTStartup in -the "Entry-point symbol" field in the "Output" settings under the -"Link" tab. +function as the entry point, FLTK includes a WinMain() function +that will call your main() function for you.

    Note: The Visual C++ optimizer is known to cause problems with many programs. We only recommend using the "Favor Small Code" @@ -155,7 +154,7 @@ The boxtype value is the style of the box that is drawn around the widget. Usually this is FL_NO_BOX, which means that no box is drawn. In our "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 +widget. You can learn more about boxtypes in Chapter 3.

    The x and y parameters determine where the widget @@ -170,7 +169,7 @@ governed by the underlying window system or hardware.

    Labels

    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 +is used for the label in the title bar. Our example program calls the labelfont, labelsize, and labeltype methods. @@ -185,7 +184,7 @@ directly.

    The labeltype method sets the type of label. FLTK supports normal, embossed, shadowed, symbol, and image labels. -

    A complete list of all label options can be found in +

    A complete list of all label options can be found in Chapter 3.

    Showing the Window

    diff --git a/documentation/common.html b/documentation/common.html index 2f75ea98b..18911c86b 100644 --- a/documentation/common.html +++ b/documentation/common.html @@ -1,7 +1,7 @@ -

    3 - Common Widgets and Attributes

    +

    3 - Common Widgets and Attributes

    This chapter describes many of the widgets that are provided with FLTK and covers how to query and set the standard attributes. @@ -119,7 +119,7 @@ window->size(width, height); Changing the size or position of a widget will cause a redraw of that widget and its children. -

    Colors

    +

    Colors

    FLTK manages a virtual color palette of "standard" colors. The standard colors are: @@ -148,7 +148,7 @@ Similarly, the label color can be set using the labelcolor() method: button->labelcolor(FL_WHITE); -

    Box Types

    +

    Box Types

    The type Fl_Boxtype stored and returned in Fl_Widget::box() is an enumeration defined in @@ -204,9 +204,9 @@ The last 4 arguments to Fl::set_boxtype() are the offsets for the bounding box that should be subtracted when drawing the label inside the box. -

    Labels and Label Types

    +

    Labels and Label Types

    -The label(), align, labelfont(), labelsize(), +The label(), align, labelfont(), labelsize(), and labeltype() methods control the labeling of widgets.

    label()

    diff --git a/documentation/drawing.html b/documentation/drawing.html index 2e78a7086..2d195d3de 100644 --- a/documentation/drawing.html +++ b/documentation/drawing.html @@ -1,9 +1,11 @@ -

    Chapter XXX - Drawing Things in FLTK

    +

    5 - Drawing Things in FLTK

    -

    When can you draw things in FLTK?

    +This chapter covers the drawing functions that are provided with FLTK. + +

    When Can You Draw Things in FLTK?

    There are only certain places you can execute drawing code in FLTK. Calling these functions at other places will result in undefined @@ -11,1285 +13,669 @@ behavior!
      -
    • The most common is inside the virtual method Fl_Widget::draw(). To write code here, -you must subclass one of the existing Fl_Widget classes and implement -your own version of draw(). +
    • The most common is inside the virtual method Fl_Widget::draw(). To write code + here, you must subclass one of the existing Fl_Widget + classes and implement your own version of draw(). -

      +

    • You can also write boxtypes and labeltypes. These are small procedures + that can be called by existing Fl_Widget + draw() methods. These "types" are identified by an + 8-bit index that is stored in the widget's box(), + labeltype(), and possibly other properties. -
    • You can also write boxtypes and labeltypes. These are small procedures that can be -called by existing Fl_Widget draw() methods. These "types" are -identified by an 8-bit index that is stored in the widget's box(), -labeltype(), and possibly other properties. - -

      - -

    • You can call Fl_Window::make_current() to do -incremental update of a widget (use Fl_Widget::window() to find the -window). Under X this only works for the base Fl_Window class, not -for double buffered, overlay, or OpenGL windows! +
    • You can call Fl_Window::make_current() + to do incremental update of a widget. Use Fl_Widget::window() to + find the window. Under X this only works for the base + Fl_Window class, not for double buffered, overlay, or + OpenGL windows!
    -

    FLTK Drawing functions
    #include <FL/fl_draw.H>

    +

    FLTK Drawing Functions

    + +To use the drawing functions you must first include the +<FL/fl_draw.H> header file. FLTK provides the following types +of drawing functions: -

    Clipping

    +

    Clipping

    -

    You can limit all your drawing to a rectangular region by calling -fl_clip, and put the drawings back by using fl_pop_clip. This -rectangle is measured in pixels (it is unaffected by the current -transformation matrix). +You can limit all your drawing to a rectangular region by calling +fl_clip, and put the drawings back by using +fl_pop_clip. This rectangle is measured in pixels (it is +unaffected by the current transformation matrix).

    In addition, the system may provide clipping when updating windows, this clip region may be more complex than a simple rectangle. -

    void fl_clip(int x, int y, int w, int h);

      +

      void fl_clip(int x, int y, int w, int h)

      -Intesect the current clip region with a rectangle and push this new +Intersect the current clip region with a rectangle and push this new region onto the stack. -

    void fl_pop_clip();

      +

      void fl_pop_clip()

      -Restore the previous clip region. You must call fl_pop_clip() once -for every time you call fl_clip(). If you return to FLTK with the -clip stack not empty unpredictable results occur. +Restore the previous clip region. You must call +fl_pop_clip() once for every time you call +fl_clip(). If you return to FLTK with the clip stack not +empty unpredictable results occur. -

    int fl_not_clipped(int x, int y, int w, int h);

      +

      int fl_not_clipped(int x, int y, int w, int h)

      Returns true if any of the rectangle intersects the current clip region. If this returns false you don't have to draw the object. -On X this returns 2 if the rectangle is partially clipped, and 1 if -it is entirely inside the clip region. +Under X this returns 2 if the rectangle is partially clipped, and 1 +if it is entirely inside the clip region. -

    int fl_clip_box(int x, int y, int w, int h,
    -    int& X, int& Y, int& W, int& H);

      +

      int fl_clip_box(int x, int y, int w, int h, int &X, int &Y, int &W, int &H)

      -Intersect the rectangle x,y,w,h with the current clip region and -returns the bounding box of the result in X,Y,W,H. Returns non-zero -if the resulting rectangle is different than the original. This can -be used to limit the necessary drawing to a rectangle. W and H are set to -zero if the rectangle is completely outside the region. +Intersect the rectangle x,y,w,h with the current clip region +and returns the bounding box of the result in X,Y,W,H. +Returns non-zero if the resulting rectangle is different than the +original. This can be used to limit the necessary drawing to a +rectangle. W and H are set to zero if the rectangle +is completely outside the region. -

    Colors

    +

    Colors

    -

    void fl_color(Fl_Color);

      +

      void fl_color(Fl_Color)

      -

      Set the color for all subsequent drawing operations. Fl_Color is -an enumeration type, all values are in the range 0-255. This is -not the X pixel, it is an internal table! The table provides -several general colors, a 24-entry gray ramp, and a 5x8x5 color cube. -All of these are named with poorly-documented symbols in <FL/Enumerations.H>. +Set the color for all subsequent drawing operations. Fl_Color +is an enumeration type, and all values are in the range 0-255. This is +not the X or WIN32 pixel, it is an index into an internal +table! The table provides several general colors, a 24-entry gray +ramp, and a 5x8x5 color cube. All of these are named with +poorly-documented symbols in <FL/Enumerations.H>. -

      Under X, a color cell will be allocated out of fl_colormap each -time you request an fl_color the first time. If the colormap fills up -then a least-squares algorithim is used to find the closest color. +

      For colormapped displays, a color cell will be allocated out of +fl_colormap the first time you use a color. If the colormap +fills up then a least-squares algorithm is used to find the closest +color. -

    Fl_Color fl_color();

      +

      Fl_Color fl_color()

      -Returns the last fl_color() that was set. This can be used for state +Returns the last fl_color() that was set. This can be used for state save/restore. -

    void Fl::set_color(Fl_Color, uchar r, uchar g, uchar b); -
    void Fl::get_color(Fl_Color, uchar &, uchar &, uchar &);

      +

      void fl_color(uchar r, uchar g, uchar b)

      -Set or get an entry in the fl_color index table. You can set it to -any 8-bit rgb color. On X, if the index has been requested before, -the pixel is free'd. No pixel is allocated until fl_color(i) is used -again, and there is no guarantee that the same pixel will be used next -time. +Set the color for all subsequent drawing operations. The closest +possible match to the RGB color is used. The RGB color is used +directly on TrueColor displays. For colormap visuals the nearest index +in the gray ramp or color cube is used. -

    void fl_color(uchar r, uchar g, uchar -b);

      +

      Fast Shapes

      -

      Set the color for all subsequent drawing operations. The closest -possible match to the rgb color is used. Under X this works -perfectly for TrueColor visuals. For colormap visuals the nearest index -in the gray ramp or color cube is figured out, and fl_color(i) is done -with that, this can result in two approximations of the color and is -very inaccurate! - -


    Fast Shapes

    - -These are used to draw almost all the FLTK widgets. They draw on -exact pixel boundaries and are as fast as possible, and their behavior -will be duplicated exactly on any platform FLTK is ported to. It is +These are used to draw almost all the FLTK widgets. They draw on exact +pixel boundaries and are as fast as possible, and their behavior will +be duplicated exactly on any platform FLTK is ported to. It is undefined whether these are affected by the transformation matrix, so you should only call these +href="#complex_shapes">transformation matrix, so you should only call these while it is the identity. -

    All arguments are integers. - -

    void fl_rectf(x, y, w, h);

      +

      void fl_rectf(int x, int y, int w, int h)

      Color a rectangle that exactly fills the given bounding box. -

    void fl_rectf(x, y, w, h, uchar r, uchar g, uchar b);

      +

      void fl_rectf(int x, int y, int w, int h, uchar r, uchar g, uchar b)

      -Color a rectangle with "exactly" the passed r,g,b color. On screens -with less than 24 bits of color this is done by drawing a +Color a rectangle with "exactly" the passed r,g,b color. On +screens with less than 24 bits of color this is done by drawing a solid-colored block using fl_draw_image() so that dithering -is produced. If you have 24 bit color, this fills the rectangle with a -single pixel value and is about 1 zillion times faster. +href="#fl_draw_image">fl_draw_image() so that dithering is +produced. -

    void fl_rect(x, y, w, h);

      +

      void fl_rect(int x, int y, int w, int h)

      Draw a 1-pixel border inside this bounding box. -

    void fl_line(x, y, x1, y1); -
    void fl_line(x, y, x1, y1, x2, y2);

      +

      void fl_line(int x, int y, int x1, int y1)
      +void fl_line(int x, int y, int x1, int y1, int x2, int y2)

      Draw one or two 1-pixel thick lines between the given points. -

    void fl_loop(x, y, x1, y1, x2, y2); -
    void fl_loop(x, y, x1, y1, x2, y2, x3, y3); -

      +

      void fl_loop(int x, int y, int x1, int y1, int x2, int y2)
      +void fl_loop(int x, int y, int x1, int y1, int x2, int y2, int x3, int y3)

      Outline a 3 or 4-sided polygon with 1-pixel thick lines. -

    void fl_polygon(x, y, x1, y1, x2, y2); -
    void fl_polygon(x, y, x1, y1, x2, y2, x3, y3); -

      +

      void fl_polygon(int x, int y, int x1, int y1, int x2, int y2)
      +void fl_polygon(int x, int y, int x1, int y1, int x2, int y2, int x3, int y3)

      Fill a 3 or 4-sided polygon. The polygon must be convex. -

    void fl_xyline(x, y, x1, y1); -
    void fl_xyline(x, y, x1, y1, x2); -
    void fl_xyline(x, y, x1, y1, x2, y3); -

      +

      void fl_xyline(int x, int y, int x1, int y1)
      +void fl_xyline(int x, int y, int x1, int y1, int x2)
      +void fl_xyline(int x, int y, int x1, int y1, int x2, int y3)

      Draw 1-pixel wide horizontal and vertical lines. A horizontal line is drawn first, then a vertical, then a horizontal. -

    void fl_yxline(x, y, y1); -
    void fl_yxline(x, y, y1, x2); -
    void fl_yxline(x, y, y1, x2, y3); -

      +

      void fl_yxline(int x, int y, int y1)
      +void fl_yxline(int x, int y, int y1, int x2)
      +void fl_yxline(int x, int y, int y1, int x2, int y3)

      Draw 1-pixel wide vertical and horizontal lines. A vertical line is drawn first, then a horizontal, then a vertical. -

    -void fl_arc(x, y, w, h, double a1, double a2);
    -void fl_pie(x, y, w, h, double a1, double a2);
    -void fl_chord(x, y, w, h, double a1, double a2);

      +

      void fl_arc(int x, int y, int w, int h, double a1, double a2)
      +void fl_pie(int x, int y, int w, int h, double a1, double a2)
      +void fl_chord(int x, int y, int w, int h, double a1, double a2)

      High-speed ellipse sections. These functions match the rather limited -circle drawing code provided by X and MSWindows. The advantage over using fl_arc is that they are faster because they often use -the hardware, and they draw much nicer small circles, since the small -sizes are often hard-coded bitmaps. +circle drawing code provided by X and MSWindows. The advantage over +using fl_arc is that they are faster +because they often use the hardware, and they draw much nicer small +circles, since the small sizes are often hard-coded bitmaps.

      If a complete circle is drawn it will fit inside the passed bounding box. The two angles are measured in degrees counterclockwise -from 3'oclock and are the starting and ending angle of the arc, a2 -must be greater or equal to a1. +from 3'oclock and are the starting and ending angle of the arc, a2 +must be greater or equal to a1. -

      fl_arc draws a 1-pixel thick line (notice this has a different -number of arguments than the fl_arc described +

      fl_arc() draws a 1-pixel thick line (notice this has a different +number of arguments than the fl_arc() described below. -

      fl_pie draws a filled-in pie slice. This slice may extend outside -the line drawn by fl_arc, to avoid this use w-1 and h-1. +

      fl_pie() draws a filled-in pie slice. This slice may extend outside +the line drawn by fl_arc, to avoid this use w - 1 and +h - 1. -

      fl_chord is not yet implemented. +

      fl_chord() is not yet implemented. -


    Complex Shapes

    +

    Complex Shapes

    These functions let you draw arbitrary shapes with 2-D linear -transformations. The functionality matches PostScript. The exact -pixels filled in is less defined than for the above calls, so that FLTK -can take advantage of drawing hardware. (Both Xlib and MSWindows round -all the transformed verticies to integers before drawing the line -segments. This severely limits the accuracy of these functions for -complex graphics. Try using OpenGL instead) +transformations. The functionality matches that found in Adobe® +PostScriptTM. The exact pixels filled in is less defined +than for the above calls, so that FLTK can take advantage of drawing +hardware. The transformed vertices are rounded to integers before +drawing the line segments. This severely limits the accuracy of these +functions for complex graphics. Use OpenGL when greater accuracy +and/or performance is required. -

    All arguments are float. - -

    void fl_push_matrix(); -
    void fl_pop_matrix();

      +

      void fl_push_matrix()
      +void fl_pop_matrix()

      Save and restore the current transformation. The maximum depth of the stack is 4. -

    void fl_scale(x, y); -
    void fl_scale(x); -
    void fl_translate(x, y); -
    void fl_rotate(d); -
    void fl_mult_matrix(a, b, c, d, x, y);

      +

      void fl_scale(float x, float y)
      +void fl_scale(float x)
      +void fl_translate(float x, float y)
      +void fl_rotate(float d)
      +void fl_mult_matrix(float a, float b, float c, float d, float x, float y)

      -Concat another transformation to the current one. The rotation angle -is in degrees (not radians) counter-clockwise. +Concatenate another transformation onto the current one. The rotation angle +is in degrees (not radians) and is counter-clockwise. -

    void fl_begin_line(); -
    void fl_end_line();

      +

      void fl_begin_line()
      +void fl_end_line()

      Start and end drawing 1-pixel thick lines. -

    void fl_begin_loop(); -
    void fl_end_loop();

      +

      void fl_begin_loop()
      +void fl_end_loop()

      Start and end drawing a closed sequence of 1-pixel thick lines. -

    void fl_begin_polygon(); -
    void fl_end_polygon();

      +

      void fl_begin_polygon()
      +void fl_end_polygon()

      Start and end drawing a convex filled polygon. -

    void fl_begin_complex_polygon(); -
    void fl_gap(); -
    void fl_end_complex_polygon();

      +

      void fl_begin_complex_polygon()
      +void fl_gap()
      +void fl_end_complex_polygon()

      Start and end drawing a complex filled polygon. This polygon may be concave, may have holes in it, or may be several disconnected pieces. -Call fl_gap() to seperate loops of the path (it is unnecessary but -harmless to call fl_gap() before the first vertex, after the last one, -or several times in a row). For portability, you should only draw -polygons that appear the same whether "even/odd" or "non-zero" -"winding rules" are used to fill them. This mostly means that holes -should be drawn in the opposite direction of the outside. +Call fl_gap() to seperate loops of the path (it is unnecessary +but harmless to call fl_gap() before the first vertex, after +the last one, or several times in a row). For portability, you should +only draw polygons that appear the same whether "even/odd" or +"non-zero" winding rules are used to fill them. This mostly means that +holes should be drawn in the opposite direction of the outside. -

      fl_gap() should only be called between -fl_begin/end_complex_polygon(). To outline the polygon, use -fl_begin_loop() and replace each fl_gap() with -fl_end_loop();fl_begin_loop(). +

      fl_gap() should only be called between +fl_begin_complex_polygon() and +fl_end_complex_polygon(). To outline the polygon, use +fl_begin_loop() and replace each fl_gap() with +fl_end_loop();fl_begin_loop(). -

    void fl_vertex(x, y);

      +

      void fl_vertex(float x, float y)

      Add a single vertex to the current path. -

    void fl_curve(int x,int y,int x1,int y1,int x2,int -y2,int x3,int y3);

      +

      void fl_curve(float x, float y, float x1, float y1, float x2, float y2, float x3, float y3)

      Add a series of points on a Bezier curve to the path. The curve ends -(and two of the points) are at x,y and x3,y3. +(and two of the points) are at x,y and x3,y3. -

    void fl_arc(x, y, r, start, end);

      +

      void fl_arc(float x, float y, float r, float start, float end)

      Add a series of points to the current path on the arc of a circle (you can get elliptical paths by using scale and rotate before calling -this). x,y are the center of the circle, and r is it's -radius. fl_arc() takes start and end angles that are -measured in degrees counter-clockwise from 3 o'clock. If end -is less than start then it draws clockwise. +this). x,y are the center of the circle, and r is +its radius. fl_arc() takes start and end +angles that are measured in degrees counter-clockwise from 3 o'clock. +If end is less than start then it draws the arc in a +clockwise direction. -

    void fl_circle(x, y, r);

      +

      void fl_circle(float x, float y, float r)

      -fl_circle() is equivalent to fl_arc(...,0,360) but may be faster. It -must be the only thing in the path: if you want a circle as -part of a complex polygon you must use fl_arc(). Under Xlib and -MSWindows this draws incorrectly if the transformation is both rotated -and non-square scaled. +fl_circle() is equivalent to fl_arc(...,0,360) but +may be faster. It must be the only thing in the path: if you +want a circle as part of a complex polygon you must use +fl_arc(). This draws incorrectly if the transformation is +both rotated and non-square scaled. -

    Text

    +

    Text

    -All text is drawn in the current font. It is +All text is drawn in the current font. It is undefined whether this location or the characters are modified by the current transformation. -

    void fl_draw(const char*, float x, float y); -
    void fl_draw(const char*, int n, float x, float y);

      +

      void fl_draw(const char *, float x, float y)
      +void fl_draw(const char *, int n, float x, float y)

      -Draw a null terminated string or an array of n characters +Draw a nul-terminated string or an array of n characters starting at the given location. -

    void fl_draw(const char*, int x,int y,int w,int h, Fl_Align);

      +

      void fl_draw(const char *, int x, int y, int w, int h, Fl_Align)

      Fancy string drawing function which is used to draw all the labels. The string is formatted and aligned inside the passed box. Handles '\t' and '\n', expands all other control characters to ^X, and aligns inside or against the edges of the box. See Fl_Widget::align() for values for -align. The value FL_ALIGN_INSIDE is ignored, this always -prints inside the box. +href="#Fl_Widget.align">Fl_Widget::align() for values for +align. The value FL_ALIGN_INSIDE is ignored, as this +function always prints inside the box. -

    void fl_measure(const char*, int& w, int& h);

      +

      void fl_measure(const char *, int &w, int &h)

      Measure how wide and tall the string will be when printed by the -fl_draw(...align) function. If the incoming w is non-zero it will -wrap to that width. +fl_draw(...align) function. If the incoming w is +non-zero it will wrap to that width. -

    int fl_height();

      +

      int fl_height()

      Recommended minimum line spacing for the current font. You can also -just use the value of size passed to fl_font(). +just use the value of size passed to +fl_font(). -

    int fl_descent();

      +

      int fl_descent()

      -Recommended distance above the bottom of a fl_height() tall box to -draw the text at so it looks centered vertically in that box. +Recommended distance above the bottom of a fl_height() tall +box to draw the text at so it looks centered vertically in that box. -

    float fl_width(const char*); -
    float fl_width(const char*, int n); -
    float fl_width(uchar);

      +

      float fl_width(const char*)
      +float fl_width(const char*, int n)
      +float fl_width(uchar)

      -Return the width of a null-terminated string, a sequence of n -characters, and a single character. +Return the width of a nul-terminated string, a sequence of n +characters, or a single character. -

    const char* fl_shortcut_label(ulong);

      +

      const char *fl_shortcut_label(ulong)

      Unparse a shortcut value as used by Fl_Button or Fl_Menu_Item into a human-readable string like -"Alt+N". This only works if the shortcut is a character key or a -numbered Function key. If the shortcut is zero an empty string is -returned. The return value points at a static buffer that is +href="#Fl_Button.shortcut">Fl_Button or Fl_Menu_Item into a human-readable +string like "Alt+N". This only works if the shortcut is a character +key or a numbered function key. If the shortcut is zero an empty +string is returned. The return value points at a static buffer that is overwritten with each call. -

    Fonts

    +

    Fonts

    -

    void fl_font(int face, int size);

      +

      void fl_font(int face, int size)

      Set the current font, which is then used by the routines described above. You may call this outside a draw context if necessary to call -fl_width(), but on X this will open the display. +fl_width(), but on X this will open the display. -

      The font is identified by a face and a size. The -size of the font is measured in pixels (ie. it is not -"resolution [in]dependent"). Lines should be spaced size +

      The font is identified by a face and a size. The +size of the font is measured in pixels (i.e. it is not +"resolution [in]dependent"). Lines should be spaced size pixels apart (or more). -

      The face is an index into an internal table. Initially only -the first 16 faces are filled in. There are symbolic names for them: -FL_HELVETICA, FL_TIMES, FL_COURIER, and modifier values FL_BOLD and -FL_ITALIC which can be added to these, and FL_SYMBOL and -FL_ZAPF_DINGBATS. Faces greater than 255 cannot be used in Fl_Widget -labels, since it stores the index as a byte. +

      The face is an index into an internal table. Initially +only the first 16 faces are filled in. There are symbolic names for +them: FL_HELVETICA, FL_TIMES, FL_COURIER, +and modifier values FL_BOLD and FL_ITALIC which can +be added to these, and FL_SYMBOL and +FL_ZAPF_DINGBATS. Faces greater than 255 cannot be used in +Fl_Widget labels, since it stores the index as a byte. -

    int fl_font();
    -int fl_size();

      +

      int fl_font()
      +int fl_size()

      -Returns the face and size set by the most recent fl_font(a,b). This -can be used to save/restore the font. +Returns the face and size set by the most recent call to +fl_font(a,b). This can be used to save/restore the font. -

    const char* Fl::get_font(int face);

      +

      Cursor

      -Get the string for this face. This string is different for each face. -Under X this value is passed to XListFonts to get all the sizes of -this face. - -

    const char* Fl::get_font_name(int face, int* attributes=0);

      - -Get a human-readable string describing the family of this face. This -is useful if you are presenting a choice to the user. There is no -guarantee that each face has a different name. The return value -points to a static buffer that is overwritten each call. - -

      The integer pointed to by attributes (if the pointer is not -zero) is set to zero, FL_BOLD(1) or -FL_ITALIC(2) or FL_BOLD|FL_ITALIC (maybe -more attributes will be defined in the future). To locate a "family" -of fonts, search forward and back for a set with non-zero attributes, -these faces along with the face with a zero attribute before them -constitute a family. - -

    int get_font_sizes(int face, int*& sizep);

      - -Return an array of sizes in sizep. The return value is the -length of this array. The sizes are sorted from smallest to largest -and indicate what sizes can be given to fl_font() that will be matched -exactly (fl_font() will pick the closest size for other sizes). A -zero in the first location of the array indicates a scalable font, -where any size works, although the array may list sizes that work -"better" than others. Warning: the returned array points at a static -buffer that is overwritten each call. Under X this will open the -display. - -

    int Fl::set_font(int face, const char*);

      - -Change a face. The string pointer is simply stored, the string is not -copied, so the string must be in static memory. - -

    int Fl::set_font(int face, int from);

      - -Copy one face to another. - -

    int Fl::set_fonts(const char* = 0);

      - -FLTK will open the display, and add every font on the server to the -face table. It will attempt to put "families" of faces together, so -that the normal one is first, followed by bold, italic, and bold -italic. - -

      The optional argument is a string to describe the set of fonts to -add. Passing NULL will select only fonts that have the ISO8859-1 -character set (and are thus usable by normal text). Passing "-*" will -select all fonts with any encoding as long as they have normal X font -names with dashes in them. Passing "*" will list every font that -exists (on X this may produce some strange output). Other values may -be useful but are system dependent. On MSWindows NULL selects fonts -with ISO8859-1 encoding and non-NULL selects all fonts. - -

      Return value is how many faces are in the table after this is done. - -


    Bitmaps, Pixmaps and Images

    - -Click here for information on drawing images - -

    Cursor

    - -

    void fl_cursor(Fl_Cursor, Fl_Color=FL_WHITE, Fl_Color=FL_BLACK);

      +

      void fl_cursor(Fl_Cursor, Fl_Color = FL_WHITE, Fl_Color = FL_BLACK)

      Change the cursor. Depending on the system this may affect the cursor everywhere, or only when it is pointing at the window that is current when you call this. For portability you should change the cursor back -to the default in response to FL_LEAVE events. +to the default in response to FL_LEAVE events. -

      The type Fl_Cursor is an enumeration defined in <Enumerations.H>. The +

      The type Fl_Cursor is an enumeration defined in <Enumerations.H>. The double-headed arrows are bitmaps provided by FLTK on X, the others are provided by system-defined cursors. Under X you can get any XC_cursor -value by passing Fl_Cursor((XC_foo/2)+1). +value by passing Fl_Cursor((XC_foo/2)+1). -

        -
      • FL_CURSOR_DEFAULT (0) usually an arrow -
      • FL_CURSOR_ARROW -
      • FL_CURSOR_CROSS - crosshair -
      • FL_CURSOR_WAIT - watch or hourglass -
      • FL_CURSOR_INSERT - I-beam -
      • FL_CURSOR_HAND - hand (uparrow on MSWindows) -
      • FL_CURSOR_HELP - question mark -
      • FL_CURSOR_MOVE - 4-pointed arrow -
      • FL_CURSOR_NS - up/down arrow -
      • FL_CURSOR_WE - left/right arrow -
      • FL_CURSOR_NWSE - diagonal arrow -
      • FL_CURSOR_NESW - diagonal arrow -
      • FL_CURSOR_NONE - invisible +

        The following standard cursors are available: + +

          +
        • FL_CURSOR_DEFAULT - the default cursor, usually an arrow +
        • FL_CURSOR_ARROW - an arrow pointer +
        • FL_CURSOR_CROSS - crosshair +
        • FL_CURSOR_WAIT - watch or hourglass +
        • FL_CURSOR_INSERT - I-beam +
        • FL_CURSOR_HAND - hand (uparrow on MSWindows) +
        • FL_CURSOR_HELP - question mark +
        • FL_CURSOR_MOVE - 4-pointed arrow +
        • FL_CURSOR_NS - up/down arrow +
        • FL_CURSOR_WE - left/right arrow +
        • FL_CURSOR_NWSE - diagonal arrow +
        • FL_CURSOR_NESW - diagonal arrow +
        • FL_CURSOR_NONE - invisible
        -

      Overlay rectangle

      +

      Overlays

      -

    void fl_overlay_rect(int x, int y, int w, int h);
    -void fl_overlay_clear();

      +

      void fl_overlay_rect(int x, int y, int w, int h)
      +void fl_overlay_clear()

      -

      Big kludge to draw interactive selection rectangles without using -the overlay. FLTK will xor a single rectangle outline over a window. -Calling this will erase any previous rectangle (by xor'ing it), and -then draw the new one. Calling fl_overlay_clear() will erase the -rectangle without drawing a new one. Using this is tricky. You -should make a widget with both a handle() and draw() method. draw() -should call fl_overlay_clear() before doing anything else. Your -handle() method should call window()->make_current() and then -fl_overlay_rect() after FL_DRAG events, and should call -fl_overlay_clear() after a FL_RELEASE event. +These functions allow you to draw interactive selection rectangles +without using the overlay hardware. FLTK will XOR a single rectangle +outline over a window. Calling this will erase any previous rectangle +(by XOR'ing it), and then draw the new one. Calling +fl_overlay_clear() will erase the rectangle without drawing a +new one. -

    (back to contents) - - -Drawing Images in FLTK -

    Drawing Images in FLTK

    +

    Using this is tricky. You should make a widget with both a +handle() and draw() method. draw() should +call fl_overlay_clear() before doing anything else. Your +handle() method should call window()->make_current() +and then fl_overlay_rect() after FL_DRAG events, and +should call fl_overlay_clear() after a FL_RELEASE +event. -To draw images, you can either do it directly from data in your -memory, or you can create Fl_Bitmap or Fl_Image or Fl_Pixmap -objects. The advantage of drawing directly is that it is more -intuitive, and it is faster if the image data changes more often than -it is redrawn. The advantage of using the object is that FLTK will -cache translated forms of the image (on X it uses a server pixmap) and -thus redrawing it is much faster. +

    Images

    - -


    Direct Image Drawing
    -#include <FL/fl_draw.H>

    +To draw images, you can either do it directly from data in your memory, +or you can create
    Fl_Bitmap, Fl_Image, or Fl_Pixmap objects. The advantage of +drawing directly is that it is more intuitive, and it is faster if the +image data changes more often than it is redrawn. The advantage of +using the object is that FLTK will cache translated forms of the image +(on X it uses a server pixmap) and thus redrawing is much +faster. -

    It is undefined whether the location or drawing of the image is +

    Direct Image Drawing

    + +It is undefined whether the location or drawing of the image is affected by the current transformation, so you should only call these when it is the identity. -

    All untyped arguments are integers. - -

    -void fl_draw_bitmap(const uchar*, X, Y, W, H, LD = 0);

      +

      void fl_draw_bitmap(const uchar *, int X, int Y, int W, int H, int LD = 0)

      This function is planned but not yet implemented (it may be impossible under X without allocating a pixmap). - -

    -void fl_draw_image(const uchar*, X, Y, W, H, D = 3, LD = 0);
    -void fl_draw_image_mono(const uchar*, X, Y, W, H, D = 1, LD = 0); -

    -typedef void (*fl_draw_image_cb)(void*, x, y, w, uchar*);
    -void fl_draw_image(fl_draw_image_cb, void*, X, Y, W, H, D = 3);
    -void fl_draw_image_mono(fl_draw_image_cb, void*, X, Y, W, H, D = 1); -

    -int fl_draw_pixmap(char** data, X, Y, Fl_Color=FL_GRAY);

    -int fl_measure_pixmap(char** data, int &w, int -&h);

      - -An XPM image contains the dimensions in it's data. This function +An XPM image contains the dimensions in its data. This function finds and returns the width and height. The return value is non-zero if it parsed the dimensions ok, and zero if there is any problem. -
    +

    class Fl_Bitmap

    - -


    class Fl_Bitmap -
    #include <FL/Fl_Bitmap.H>

    - -This object encapsulates the width, height, and bits of an Xbitmap -(XBM), and allows you to make an Fl_Widget use a bitmap as a label, or -to just draw the bitmap directly. Under X it will create an +This object encapsulates the width, height, and bits of an X bitmap +(XBM), and allows you to make an Fl_Widget use a bitmap as a +label, or to just draw the bitmap directly. Under X it will create an offscreen pixmap the first time it is drawn, and copy this each -subsequent time it is drawn. +subsequent time it is drawn. -

    Fl_Bitmap(const char *bits, int W, int H); -
    Fl_Bitmap(const uchar *bits, int W, int H);

    +

    Fl_Bitmap(const char *bits, int W, int H)
    +Fl_Bitmap(const uchar *bits, int W, int H)

    -Construct from an Xbitmap. The bits pointer is simply copied to the -object, so it must point at persistent storage. I provide two -constructors because various X implementations disagree about the type -of bitmap data. To use an XBM file, -#include "foo.xbm", and then do "new -Fl_Bitmap(foo_bits,foo_width,foo_height)" +Construct using an X bitmap. The bits pointer is simply copied to the +object, so it must point at persistent storage. The two constructors +are provided because various X implementations disagree about the type +of bitmap data. To use an XBM file use: -

    ~Fl_Bitmap()

    +
      +#include "foo.xbm"
      +...
      +Fl_Bitmap bitmap = new Fl_Bitmap(foo_bits, foo_width, foo_height);
      +
    + +

    ~Fl_Bitmap()

    The destructor will destroy any X pixmap created. It does not do anything to the bits data. -

    void draw(int x, int y, int w, int h, int ox=0, int oy=0);

    +

    void draw(int x, int y, int w, int h, int ox = 0, int oy = 0)

    -x,y,w,h indicates a destination rectangle. ox,oy,w,h is -a source rectangle. This source rectangle from the bitmap is drawn in -the destination. 1 bits are drawn with the current color, 0 bits are -unchanged. The source rectangle may extend outside the bitmap (i.e. ox -and oy may be negative and w and h may be bigger than the bitmap) and -this area is left unchanged. +x,y,w,h indicates a destination rectangle. ox,oy,w,h +is a source rectangle. This source rectangle from the bitmap is drawn +in the destination. 1 bits are drawn with the current color, 0 bits +are unchanged. The source rectangle may extend outside the bitmap +(i.e. ox and oy may be negative and w and +h may be bigger than the bitmap) and this area is left +unchanged. -

    void draw(int x, int y);

    +

    void draw(int x, int y)

    -Draws the bitmap with the upper-left corner at x,y. This is -the same as doing draw(x,y,this->w,this->h,0,0). +Draws the bitmap with the upper-left corner at x,y. This is +the same as doing draw(x,y,this->w,this->h,0,0). -

    void label(Fl_Widget *);

    +

    void label(Fl_Widget *)

    -Change the label() and the labeltype() of the widget to draw the -bitmap. 1 bits will be drawn with the labelcolor(), zero bits will be -unchanged. You can use the same bitmap for many widgets. +Change the label() and the labeltype() of the widget +to draw the bitmap. 1 bits will be drawn with the +labelcolor(), zero bits will be unchanged. You can use the +same bitmap for many widgets. -
    -


    class Fl_Pixmap -
    #include <FL/Fl_Pixmap.H>

    + +

    class Fl_Pixmap

    This object encapsulates the data from an XPM image, and allows you to -make an Fl_Widget use a pixmap as a label, or to just draw the pixmap -directly. Under X it will create an offscreen pixmap the first -time it is drawn, and copy this each subsequent time it is drawn. +make an Fl_Widget use a pixmap as a label, or to just draw the +pixmap directly. Under X it will create an offscreen pixmap the +first time it is drawn, and copy this each subsequent time it is +drawn.

    The current implementation converts the pixmap to 8 bit color data -and uses fl_draw_image() to draw +and uses fl_draw_image() to draw it. Thus you will get dithered colors on an 8 bit screen. -

    Fl_Pixmap(char * const * data);

    +

    Fl_Pixmap(char *const* data)

    -Construct from XPM data. The data pointer is simply copied to the -object, so it must point at persistent storage. To use an XPM file, -#include "foo.xpm", and then do "new -Fl_Pixmap(foo)" +Construct using XPM data. The data pointer is simply copied to the +object, so it must point at persistent storage. To use an XPM file do: -

    ~Fl_Pixmap()

    - -The destructor will destroy any X pixmap created. It does not do -anything to the data. - -

    void draw(int x, int y, int w, int h, int ox=0, int oy=0);

    - -x,y,w,h indicates a destination rectangle. ox,oy,w,h is -a source rectangle. This source rectangle is copied to the -destination. The source rectangle may extend outside the pixmap -(i.e. ox and oy may be negative and w and h may be bigger than the -pixmap) and this area is left unchanged. - -

    void draw(int x, int y);

    - -Draws the image with the upper-left corner at x,y. This is -the same as doing draw(x,y,this->w,this->h,0,0). - -

    void label(Fl_Widget *);

    - -Change the label() and the labeltype() of the widget to draw the -pixmap. You can use the same pixmap for many widgets. - - -


    class Fl_Image -
    #include <FL/Fl_Image.H>

    - -This object encapsulates a full-color RGB image, and allows you to -make an Fl_Widget use a Image as a label, or to just draw the Image -directly. Under X it will create an offscreen pixmap the first -time it is drawn, and copy this each subsequent time it is drawn. - -

    See fl_draw_image() for what -happens. On 8 bit screens dithering is used. - -

    Fl_Image(char uchar *data, int W, int H, int D=3, int LD=0);

    - -Construct from a pointer to RGB data. W and H are the size of the -image in pixels. D is the delta between pixels (it may be more than 3 -to skip alpha or other data, or negative to flip the image -left/right). LD is the delta between lines (it may be more than D*W -to crop images, or negative to flip the image vertically). The data -pointer is simply copied to the object, so it must point at persistent -storage. - -

    ~Fl_Image()

    - -The destructor will destroy any X pixmap created. It does not do -anything to the data. - -

    void draw(int x, int y, int w, int h, int ox=0, int oy=0);

    - -x,y,w,h indicates a destination rectangle. ox,oy,w,h is -a source rectangle. This source rectangle is copied to the -destination. The source rectangle may extend outside the image -(i.e. ox and oy may be negative and w and h may be bigger than the -image) and this area is left unchanged. - -

    void draw(int x, int y);

    - -Draws the image with the upper-left corner at x,y. This is -the same as doing draw(x,y,this->w,this->h,0,0). - -

    void label(Fl_Widget *);

    - -Change the label() and the labeltype() of the widget to draw the -Image. You can use the same Image for many widgets. - -

    (back to contents) -FLTK enhancements to the XPM format -

    FLTK enhancements to the XPM format

    - -

    I made some additions to XPM that may be good, or intensely -disliked by X purists. I do not know if the changes are compatable -with current XPM. - -

    The change was to make a "compressed colormap" that avoids -XParseColor(), and gives the actual color values (which is really what -everybody wants!). Only colormaps of this form, and ones where the -colors are named as "#rrggbb", will be portable to non-X platforms. - -

    A compressed colormap is indicated by the number of colors being -negative. The colormap is then given as an array of 4*numcolors -characters. Each color is described by 4 characters: the index -character, and the red, green, and blue value (for 2-character indexes -each color needs 5 characters). - -

    XPM files support a single transparent index. I require this index -to be ' ' (space). To indicate that ' ' is transparent, it should be -first in the color table. To make ' ' not be transparent, put it -somewhere other than first in the table. - -

    To make the XPM files easily parseable, but still portable to most -C compilers, I suggest the following format: - -

    -/* XPM */
    -static char * name[] = {
    -/* width height ncolors chars_per_pixel */
    -"64 64 -4 1 ",
    -/* colormap */
    -"\
    - \x50\x50\x80\
    -.\xff\xff\x00\
    -r\xff\x00\x00\
    -b\x00\x00\x00",
    -/* pixels */
    -"        bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb        ",
    -"        bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb        ",
    -"        bb............................................bb        ",
    +
      +#include <FL/Fl_Pixmap.H>
      +#include "foo.xpm"
       ...
      -
      +Fl_Pixmap pixmap = new Fl_Pixmap(foo); +
    -

    All lines starting with "/*" are optional. Parsers should handle -'\' at the end of the line and \xNN and \NNN characters. This -requires the C compiler to parse \xNN characters. - - +

    ~Fl_Pixmap()

    -

    Chapter XXX - Drawing Things in FLTK

    +The destructor will destroy any X pixmap created. It does not do +anything to the data. -

    When can you draw things in FLTK?

    +

    void draw(int x, int y, int w, int h, int ox = 0, int oy = 0)

    -There are only certain places you can execute drawing code in FLTK. -Calling these functions at other places will result in undefined -behavior! +x,y,w,h indicates a destination rectangle. ox,oy,w,h +is a source rectangle. This source rectangle is copied to the +destination. The source rectangle may extend outside the pixmap (i.e. +ox and oy may be negative and w and +h may be bigger than the pixmap) and this area is left +unchanged. -
      +

      void draw(int x, int y)

      -
    • The most common is inside the virtual method Fl_Widget::draw(). To write code here, -you must subclass one of the existing Fl_Widget classes and implement -your own version of draw(). +Draws the image with the upper-left corner at x,y. This is +the same as doing draw(x,y,this->w,this->h,0,0). -

      +

      void label(Fl_Widget *)

      -
    • You can also write boxtypes and labeltypes. These are small procedures that can be -called by existing Fl_Widget draw() methods. These "types" are -identified by an 8-bit index that is stored in the widget's box(), -labeltype(), and possibly other properties. +Change the label() and the labeltype() of the widget +to draw the pixmap. You can use the same pixmap for many widgets. -

      -

    • You can call Fl_Window::make_current() to do -incremental update of a widget (use Fl_Widget::window() to find the -window). Under X this only works for the base Fl_Window class, not -for double buffered, overlay, or OpenGL windows! +

      class Fl_Image

      -
    +This object encapsulates a full-color RGB image, and allows you to make +an Fl_Widget use an image as a label, or to just draw the +image directly. Under X it will create an offscreen pixmap the +first time it is drawn, and copy this each subsequent time it is +drawn. -

    FLTK Drawing functions
    #include <FL/fl_draw.H>

    +

    Fl_Image(char uchar *data, int W, int H, int D = 3, int LD = 0)

    - +Construct using a pointer to RGB data. W and H are +the size of the image in pixels. D is the delta between +pixels (it may be more than 3 to skip alpha or other data, or negative +to flip the image left/right). LD is the delta between lines +(it may be more than D * W to crop images, or negative to flip +the image vertically). The data pointer is simply copied to the +object, so it must point at persistent storage. -

    Clipping

    +

    ~Fl_Image()

    -

    You can limit all your drawing to a rectangular region by calling -fl_clip, and put the drawings back by using fl_pop_clip. This -rectangle is measured in pixels (it is unaffected by the current -transformation matrix). +The destructor will destroy any X pixmap created. It does not do +anything to the data. -

    In addition, the system may provide clipping when updating windows, -this clip region may be more complex than a simple rectangle. +

    void draw(int x, int y, int w, int h, int ox = 0, int oy = 0)

    -

    void fl_clip(int x, int y, int w, int h);

      +x,y,w,h indicates a destination rectangle. ox,oy,w,h +is a source rectangle. This source rectangle is copied to the +destination. The source rectangle may extend outside the image (i.e. +ox and oy may be negative and w and +h may be bigger than the image) and this area is left +unchanged. -Intesect the current clip region with a rectangle and push this new -region onto the stack. +

      void draw(int x, int y)

      -

    void fl_pop_clip();

      +Draws the image with the upper-left corner at x,y. This is +the same as doing draw(x,y,this->w,this->h,0,0). -Restore the previous clip region. You must call fl_pop_clip() once -for every time you call fl_clip(). If you return to FLTK with the -clip stack not empty unpredictable results occur. +

      void label(Fl_Widget *)

      -

    int fl_not_clipped(int x, int y, int w, int h);

      +Change the label() and the labeltype() of the widget +to draw the image. You can use the same image for many widgets. -Returns true if any of the rectangle intersects the current clip -region. If this returns false you don't have to draw the object. -On X this returns 2 if the rectangle is partially clipped, and 1 if -it is entirely inside the clip region. - -

    int fl_clip_box(int x, int y, int w, int h,
    -    int& X, int& Y, int& W, int& H);

      - -Intersect the rectangle x,y,w,h with the current clip region and -returns the bounding box of the result in X,Y,W,H. Returns non-zero -if the resulting rectangle is different than the original. This can -be used to limit the necessary drawing to a rectangle. W and H are set to -zero if the rectangle is completely outside the region. - -

    Colors

    - -

    void fl_color(Fl_Color);

      - -

      Set the color for all subsequent drawing operations. Fl_Color is -an enumeration type, all values are in the range 0-255. This is -not the X pixel, it is an internal table! The table provides -several general colors, a 24-entry gray ramp, and a 5x8x5 color cube. -All of these are named with poorly-documented symbols in <FL/Enumerations.H>. - -

      Under X, a color cell will be allocated out of fl_colormap each -time you request an fl_color the first time. If the colormap fills up -then a least-squares algorithim is used to find the closest color. - -

    Fl_Color fl_color();

      - -Returns the last fl_color() that was set. This can be used for state -save/restore. - -

    void Fl::set_color(Fl_Color, uchar r, uchar g, uchar b); -
    void Fl::get_color(Fl_Color, uchar &, uchar &, uchar &);

      - -Set or get an entry in the fl_color index table. You can set it to -any 8-bit rgb color. On X, if the index has been requested before, -the pixel is free'd. No pixel is allocated until fl_color(i) is used -again, and there is no guarantee that the same pixel will be used next -time. - -

    void fl_color(uchar r, uchar g, uchar -b);

      - -

      Set the color for all subsequent drawing operations. The closest -possible match to the rgb color is used. Under X this works -perfectly for TrueColor visuals. For colormap visuals the nearest index -in the gray ramp or color cube is figured out, and fl_color(i) is done -with that, this can result in two approximations of the color and is -very inaccurate! - -


    Fast Shapes

    - -These are used to draw almost all the FLTK widgets. They draw on -exact pixel boundaries and are as fast as possible, and their behavior -will be duplicated exactly on any platform FLTK is ported to. It is -undefined whether these are affected by the transformation matrix, so you should only call these -while it is the identity. - -

    All arguments are integers. - -

    void fl_rectf(x, y, w, h);

      - -Color a rectangle that exactly fills the given bounding box. - -

    void fl_rectf(x, y, w, h, uchar r, uchar g, uchar b);

      - -Color a rectangle with "exactly" the passed r,g,b color. On screens -with less than 24 bits of color this is done by drawing a -solid-colored block using fl_draw_image() so that dithering -is produced. If you have 24 bit color, this fills the rectangle with a -single pixel value and is about 1 zillion times faster. - -

    void fl_rect(x, y, w, h);

      - -Draw a 1-pixel border inside this bounding box. - -

    void fl_line(x, y, x1, y1); -
    void fl_line(x, y, x1, y1, x2, y2);

      - -Draw one or two 1-pixel thick lines between the given points. - -

    void fl_loop(x, y, x1, y1, x2, y2); -
    void fl_loop(x, y, x1, y1, x2, y2, x3, y3); -

      - -Outline a 3 or 4-sided polygon with 1-pixel thick lines. - -

    void fl_polygon(x, y, x1, y1, x2, y2); -
    void fl_polygon(x, y, x1, y1, x2, y2, x3, y3); -

      - -Fill a 3 or 4-sided polygon. The polygon must be convex. - -

    void fl_xyline(x, y, x1, y1); -
    void fl_xyline(x, y, x1, y1, x2); -
    void fl_xyline(x, y, x1, y1, x2, y3); -

      - -Draw 1-pixel wide horizontal and vertical lines. A horizontal line is -drawn first, then a vertical, then a horizontal. - -

    void fl_yxline(x, y, y1); -
    void fl_yxline(x, y, y1, x2); -
    void fl_yxline(x, y, y1, x2, y3); -

      - -Draw 1-pixel wide vertical and horizontal lines. A vertical line is -drawn first, then a horizontal, then a vertical. - -

    -void fl_arc(x, y, w, h, double a1, double a2);
    -void fl_pie(x, y, w, h, double a1, double a2);
    -void fl_chord(x, y, w, h, double a1, double a2);

      - -High-speed ellipse sections. These functions match the rather limited -circle drawing code provided by X and MSWindows. The advantage over using fl_arc is that they are faster because they often use -the hardware, and they draw much nicer small circles, since the small -sizes are often hard-coded bitmaps. - -

      If a complete circle is drawn it will fit inside the passed -bounding box. The two angles are measured in degrees counterclockwise -from 3'oclock and are the starting and ending angle of the arc, a2 -must be greater or equal to a1. - -

      fl_arc draws a 1-pixel thick line (notice this has a different -number of arguments than the fl_arc described -below. - -

      fl_pie draws a filled-in pie slice. This slice may extend outside -the line drawn by fl_arc, to avoid this use w-1 and h-1. - -

      fl_chord is not yet implemented. - -


    Complex Shapes

    - -These functions let you draw arbitrary shapes with 2-D linear -transformations. The functionality matches PostScript. The exact -pixels filled in is less defined than for the above calls, so that FLTK -can take advantage of drawing hardware. (Both Xlib and MSWindows round -all the transformed verticies to integers before drawing the line -segments. This severely limits the accuracy of these functions for -complex graphics. Try using OpenGL instead) - -

    All arguments are float. - -

    void fl_push_matrix(); -
    void fl_pop_matrix();

      - -Save and restore the current transformation. The maximum depth of the -stack is 4. - -

    void fl_scale(x, y); -
    void fl_scale(x); -
    void fl_translate(x, y); -
    void fl_rotate(d); -
    void fl_mult_matrix(a, b, c, d, x, y);

      - -Concat another transformation to the current one. The rotation angle -is in degrees (not radians) counter-clockwise. - -

    void fl_begin_line(); -
    void fl_end_line();

      - -Start and end drawing 1-pixel thick lines. - -

    void fl_begin_loop(); -
    void fl_end_loop();

      - -Start and end drawing a closed sequence of 1-pixel thick lines. - -

    void fl_begin_polygon(); -
    void fl_end_polygon();

      - -Start and end drawing a convex filled polygon. - -

    void fl_begin_complex_polygon(); -
    void fl_gap(); -
    void fl_end_complex_polygon();

      - -Start and end drawing a complex filled polygon. This polygon may be -concave, may have holes in it, or may be several disconnected pieces. -Call fl_gap() to seperate loops of the path (it is unnecessary but -harmless to call fl_gap() before the first vertex, after the last one, -or several times in a row). For portability, you should only draw -polygons that appear the same whether "even/odd" or "non-zero" -"winding rules" are used to fill them. This mostly means that holes -should be drawn in the opposite direction of the outside. - -

      fl_gap() should only be called between -fl_begin/end_complex_polygon(). To outline the polygon, use -fl_begin_loop() and replace each fl_gap() with -fl_end_loop();fl_begin_loop(). - -

    void fl_vertex(x, y);

      - -Add a single vertex to the current path. - -

    void fl_curve(int x,int y,int x1,int y1,int x2,int -y2,int x3,int y3);

      - -Add a series of points on a Bezier curve to the path. The curve ends -(and two of the points) are at x,y and x3,y3. - -

    void fl_arc(x, y, r, start, end);

      - -Add a series of points to the current path on the arc of a circle (you -can get elliptical paths by using scale and rotate before calling -this). x,y are the center of the circle, and r is it's -radius. fl_arc() takes start and end angles that are -measured in degrees counter-clockwise from 3 o'clock. If end -is less than start then it draws clockwise. - -

    void fl_circle(x, y, r);

      - -fl_circle() is equivalent to fl_arc(...,0,360) but may be faster. It -must be the only thing in the path: if you want a circle as -part of a complex polygon you must use fl_arc(). Under Xlib and -MSWindows this draws incorrectly if the transformation is both rotated -and non-square scaled. - -

    Text

    - -All text is drawn in the current font. It is -undefined whether this location or the characters are modified by the -current transformation. - -

    void fl_draw(const char*, float x, float y); -
    void fl_draw(const char*, int n, float x, float y);

      - -Draw a null terminated string or an array of n characters in the -current font, starting at the given location. - -

    void fl_draw(const char*, int x,int y,int w,int h, Fl_Align);

      - -Fancy string drawing function which is used to draw all the labels. -The string is formatted and aligned inside the passed box. Handles -'\t' and '\n', expands all other control characters to ^X, and aligns -inside or against the edges of the box. See Fl_Widget::align() for values for -align. The value FL_ALIGN_INSIDE is ignored, this always -prints inside the box. - -

    void fl_measure(const char*, int& w, int& h);

      - -Measure how wide and tall the string will be when printed by the -fl_draw(...align) function. If the incoming w is non-zero it will -wrap to that width. - -

    int fl_height();

      - -Recommended minimum line spacing for the current font. You can also -just use the value of size passed to fl_font(). - -

    int fl_descent();

      - -Recommended distance above the bottom of a fl_height() tall box to -draw the text at so it looks centered vertically in that box. - -

    float fl_width(const char*); -
    float fl_width(const char*, int n); -
    float fl_width(uchar);

      - -Return the width of a null-terminated string, a sequence of n -characters, and a single character. - -

    const char* fl_shortcut_label(ulong);

      - -Unparse a shortcut value as used by Fl_Button or Fl_Menu_Item into a human-readable string like -"Alt+N". This only works if the shortcut is a character key or a -numbered Function key. If the shortcut is zero an empty string is -returned. The return value points at a static buffer that is -overwritten with each call. - -

    Fonts

    - -

    void fl_font(int face, int size);

      - -Set the current font, which is then used by the routines described -above. You may call this outside a draw context if necessary to call -fl_width(), but on X this will open the display. - -

      The font is identified by a face and a size. The -size of the font is measured in pixels (ie. it is not -"resolution [in]dependent"). Lines should be spaced size -pixels apart (or more). - -

      The face is an index into an internal table. Initially only -the first 16 faces are filled in. There are symbolic names for them: -FL_HELVETICA, FL_TIMES, FL_COURIER, and modifier values FL_BOLD and -FL_ITALIC which can be added to these, and FL_SYMBOL and -FL_ZAPF_DINGBATS. Faces greater than 255 cannot be used in Fl_Widget -labels, since it stores the index as a byte. - -

    int fl_font();
    -int fl_size();

      - -Returns the face and size set by the most recent fl_font(a,b). This -can be used to save/restore the font. - -

    const char* Fl::get_font(int face);

      - -Get the string for this face. This string is different for each face. -Under X this value is passed to XListFonts to get all the sizes of -this face. - -

    const char* Fl::get_font_name(int face, int* attributes=0);

      - -Get a human-readable string describing the family of this face. This -is useful if you are presenting a choice to the user. There is no -guarantee that each face has a different name. The return value -points to a static buffer that is overwritten each call. - -

      The integer pointed to by attributes (if the pointer is not -zero) is set to zero, FL_BOLD(1) or -FL_ITALIC(2) or FL_BOLD|FL_ITALIC (maybe -more attributes will be defined in the future). To locate a "family" -of fonts, search forward and back for a set with non-zero attributes, -these faces along with the face with a zero attribute before them -constitute a family. - -

    int get_font_sizes(int face, int*& sizep);

      - -Return an array of sizes in sizep. The return value is the -length of this array. The sizes are sorted from smallest to largest -and indicate what sizes can be given to fl_font() that will be matched -exactly (fl_font() will pick the closest size for other sizes). A -zero in the first location of the array indicates a scalable font, -where any size works, although the array may list sizes that work -"better" than others. Warning: the returned array points at a static -buffer that is overwritten each call. Under X this will open the -display. - -

    int Fl::set_font(int face, const char*);

      - -Change a face. The string pointer is simply stored, the string is not -copied, so the string must be in static memory. - -

    int Fl::set_font(int face, int from);

      - -Copy one face to another. - -

    int Fl::set_fonts(const char* = 0);

      - -FLTK will open the display, and add every font on the server to the -face table. It will attempt to put "families" of faces together, so -that the normal one is first, followed by bold, italic, and bold -italic. - -

      The optional argument is a string to describe the set of fonts to -add. Passing NULL will select only fonts that have the ISO8859-1 -character set (and are thus usable by normal text). Passing "-*" will -select all fonts with any encoding as long as they have normal X font -names with dashes in them. Passing "*" will list every font that -exists (on X this may produce some strange output). Other values may -be useful but are system dependent. On MSWindows NULL selects fonts -with ISO8859-1 encoding and non-NULL selects all fonts. - -

      Return value is how many faces are in the table after this is done. - -


    Bitmaps, Pixmaps and Images

    - -Click here for information on drawing images - -

    Cursor

    - -

    void fl_cursor(Fl_Cursor, Fl_Color=FL_WHITE, Fl_Color=FL_BLACK);

      - -Change the cursor. Depending on the system this may affect the cursor -everywhere, or only when it is pointing at the window that is current -when you call this. For portability you should change the cursor back -to the default in response to FL_LEAVE events. - -

      The type Fl_Cursor is an enumeration defined in <Enumerations.H>. The -double-headed arrows are bitmaps provided by FLTK on X, the others are -provided by system-defined cursors. Under X you can get any XC_cursor -value by passing Fl_Cursor((XC_foo/2)+1). - -

        -
      • FL_CURSOR_DEFAULT (0) usually an arrow -
      • FL_CURSOR_ARROW -
      • FL_CURSOR_CROSS - crosshair -
      • FL_CURSOR_WAIT - watch or hourglass -
      • FL_CURSOR_INSERT - I-beam -
      • FL_CURSOR_HAND - hand (uparrow on MSWindows) -
      • FL_CURSOR_HELP - question mark -
      • FL_CURSOR_MOVE - 4-pointed arrow -
      • FL_CURSOR_NS - up/down arrow -
      • FL_CURSOR_WE - left/right arrow -
      • FL_CURSOR_NWSE - diagonal arrow -
      • FL_CURSOR_NESW - diagonal arrow -
      • FL_CURSOR_NONE - invisible -
      - -

    Overlay rectangle

    - -

    void fl_overlay_rect(int x, int y, int w, int h);
    -void fl_overlay_clear();

      - -

      Big kludge to draw interactive selection rectangles without using -the overlay. FLTK will xor a single rectangle outline over a window. -Calling this will erase any previous rectangle (by xor'ing it), and -then draw the new one. Calling fl_overlay_clear() will erase the -rectangle without drawing a new one. Using this is tricky. You -should make a widget with both a handle() and draw() method. draw() -should call fl_overlay_clear() before doing anything else. Your -handle() method should call window()->make_current() and then -fl_overlay_rect() after FL_DRAG events, and should call -fl_overlay_clear() after a FL_RELEASE event. - -

    (back to contents) diff --git a/documentation/editor.html b/documentation/editor.html index 60dca040c..5c31a16e7 100644 --- a/documentation/editor.html +++ b/documentation/editor.html @@ -1,7 +1,7 @@ -

    4 - Designing a Simple Text Editor

    +

    4 - Designing a Simple Text Editor

    This chapter takes you through the design of a simple FLTK-based text editor. @@ -295,7 +295,7 @@ We call the load_file() function to actually load the file.

    paste_cb()

    This callback function will send a FL_PASTE message to the input -widget using the Fl::paste() method: +widget using the Fl::paste() method:
       void paste_cb(void) {
      @@ -514,7 +514,7 @@ void load_file(char *newfile) {
       
    When loading the file we use the -input->replace() method to "replace" the text at the end of +input->replace() method to "replace" the text at the end of the buffer. The pos variable keeps track of the end of the buffer. diff --git a/documentation/enumerations.html b/documentation/enumerations.html index 355437a73..8d303bcc8 100644 --- a/documentation/enumerations.html +++ b/documentation/enumerations.html @@ -1,328 +1,373 @@ -

    C - FLTK Enumerations.H

    +

    C - FLTK Enumerations.H

    -Here are the values of all the public-visible enumerations used by fltk: +This appendix lists the enumerations provided in the +<FL/Enumerations.H> header file, organized by section. -
    -#include <FL/Enumerations.H>
    +

    Version Numbers

    -// -// The FLTK version number; this is changed slightly from the beta versions -// because the old "const double" definition would not allow for conditional -// compilation... -// -// FL_VERSION is a double that describes the major and minor version numbers. -// Version 1.1 is actually stored as 1.01 to allow for more than 9 minor -// releases. -// -// The FL_MAJOR_VERSION, FL_MINOR_VERSION, and FL_PATCH_VERSION constants -// give the integral values for the major, minor, and patch releases -// respectively. -// +The FLTK version number is stored in a number of compile-time constants: -#define FL_MAJOR_VERSION 1 -#define FL_MINOR_VERSION 0 -#define FL_PATCH_VERSION 0 -#define FL_VERSION ((double)FL_MAJOR_VERSION + \ - (double)FL_MINOR_VERSION * 0.01) +
      -typedef unsigned char uchar; -typedef unsigned long ulong; -typedef unsigned int u32; // you must fix if not 32 bits on your machine! +
    • FL_MAJOR_VERSION - The major release number, currently + 1. -enum Fl_Event { // events - FL_NO_EVENT = 0, - FL_PUSH = 1, - FL_RELEASE = 2, - FL_ENTER = 3, - FL_LEAVE = 4, - FL_DRAG = 5, - FL_FOCUS = 6, - FL_UNFOCUS = 7, - FL_KEYBOARD = 8, - FL_CLOSE = 9, - FL_MOVE = 10, - FL_SHORTCUT = 11, - FL_DEACTIVATE = 13, - FL_ACTIVATE = 14, - FL_HIDE = 15, - FL_SHOW = 16, - FL_PASTE = 17, - FL_SELECTIONCLEAR = 18 -}; +
    • FL_MINOR_VERSION - The minor release number, currently + 0. -enum Fl_When { // Fl_Widget::when(): - FL_WHEN_NEVER = 0, - FL_WHEN_CHANGED = 1, - FL_WHEN_RELEASE = 4, - FL_WHEN_RELEASE_ALWAYS= 6, - FL_WHEN_ENTER_KEY = 8, - FL_WHEN_ENTER_KEY_ALWAYS=10, - FL_WHEN_NOT_CHANGED = 2 // modifier bit to disable changed() test -}; +
    • FL_PATCH_VERSION - The patch release number, currently + 0. -// Fl::event_key() and Fl::get_key(n) (use ascii letters for all other keys): -#define FL_Button 0xfee8 // use Fl_Button+n for mouse button n -#define FL_BackSpace 0xff08 -#define FL_Tab 0xff09 -#define FL_Enter 0xff0d -#define FL_Pause 0xff13 -#define FL_Scroll_Lock 0xff14 -#define FL_Escape 0xff1b -#define FL_Home 0xff50 -#define FL_Left 0xff51 -#define FL_Up 0xff52 -#define FL_Right 0xff53 -#define FL_Down 0xff54 -#define FL_Page_Up 0xff55 -#define FL_Page_Down 0xff56 -#define FL_End 0xff57 -#define FL_Print 0xff61 -#define FL_Insert 0xff63 -#define FL_Menu 0xff67 // the "menu/apps" key on XFree86 -#define FL_Num_Lock 0xff7f -#define FL_KP 0xff80 // use FL_KP+'x' for 'x' on numeric keypad -#define FL_KP_Enter 0xff8d // same as Fl_KP+'\r' -#define FL_KP_Last 0xffbd // use to range-check keypad -#define FL_F 0xffbd // use FL_F+n for function key n -#define FL_F_Last 0xffe0 // use to range-check function keys -#define FL_Shift_L 0xffe1 -#define FL_Shift_R 0xffe2 -#define FL_Control_L 0xffe3 -#define FL_Control_R 0xffe4 -#define FL_Caps_Lock 0xffe5 -#define FL_Meta_L 0xffe7 // the left MSWindows key on XFree86 -#define FL_Meta_R 0xffe8 // the right MSWindows key on XFree86 -#define FL_Alt_L 0xffe9 -#define FL_Alt_R 0xffea -#define FL_Delete 0xffff +
    • FL_VERSION - A combined floating-point version + number for the major and minor release numbers, currently 1.0. -// Fl::event_state(): -#define FL_SHIFT 0x00010000 -#define FL_CAPS_LOCK 0x00020000 -#define FL_CTRL 0x00040000 -#define FL_ALT 0x00080000 -#define FL_NUM_LOCK 0x00100000 // most X servers do this? -#define FL_META 0x00400000 // correct for XFree86 -#define FL_SCROLL_LOCK 0x00800000 // correct for XFree86 -#define FL_BUTTON1 0x01000000 -#define FL_BUTTON2 0x02000000 -#define FL_BUTTON3 0x04000000 +
    -enum Fl_Boxtype { // boxtypes (if you change these you must fix fl_boxtype.C): - FL_NO_BOX = 0, FL_FLAT_BOX, +

    Events

    - FL_UP_BOX, FL_DOWN_BOX, - FL_UP_FRAME, FL_DOWN_FRAME, - FL_THIN_UP_BOX, FL_THIN_DOWN_BOX, - FL_THIN_UP_FRAME, FL_THIN_DOWN_FRAME, - FL_ENGRAVED_BOX, FL_EMBOSSED_BOX, - FL_ENGRAVED_FRAME, FL_EMBOSSED_FRAME, - FL_BORDER_BOX, _FL_SHADOW_BOX, - FL_BORDER_FRAME, _FL_SHADOW_FRAME, - _FL_ROUNDED_BOX, _FL_RSHADOW_BOX, - _FL_ROUNDED_FRAME, _FL_RFLAT_BOX, - _FL_ROUND_UP_BOX, _FL_ROUND_DOWN_BOX, - _FL_DIAMOND_UP_BOX, _FL_DIAMOND_DOWN_BOX, - _FL_OVAL_BOX, _FL_OSHADOW_BOX, - _FL_OVAL_FRAME, _FL_OFLAT_BOX -}; -extern Fl_Boxtype define_FL_ROUND_UP_BOX(); -#define FL_ROUND_UP_BOX define_FL_ROUND_UP_BOX() -#define FL_ROUND_DOWN_BOX (Fl_Boxtype)(define_FL_ROUND_UP_BOX()+1) -extern Fl_Boxtype define_FL_SHADOW_BOX(); -#define FL_SHADOW_BOX define_FL_SHADOW_BOX() -#define FL_SHADOW_FRAME (Fl_Boxtype)(define_FL_SHADOW_BOX()+2) -extern Fl_Boxtype define_FL_ROUNDED_BOX(); -#define FL_ROUNDED_BOX define_FL_ROUNDED_BOX() -#define FL_ROUNDED_FRAME (Fl_Boxtype)(define_FL_ROUNDED_BOX()+2) -extern Fl_Boxtype define_FL_RFLAT_BOX(); -#define FL_RFLAT_BOX define_FL_RFLAT_BOX() -extern Fl_Boxtype define_FL_RSHADOW_BOX(); -#define FL_RSHADOW_BOX define_FL_RSHADOW_BOX() -extern Fl_Boxtype define_FL_DIAMOND_BOX(); -#define FL_DIAMOND_UP_BOX define_FL_DIAMOND_BOX() -#define FL_DIAMOND_DOWN_BOX (Fl_Boxtype)(define_FL_DIAMOND_BOX()+1) -extern Fl_Boxtype define_FL_OVAL_BOX(); -#define FL_OVAL_BOX define_FL_OVAL_BOX() -#define FL_OSHADOW_BOX (Fl_Boxtype)(define_FL_OVAL_BOX()+1) -#define FL_OVAL_FRAME (Fl_Boxtype)(define_FL_OVAL_BOX()+2) -#define FL_OFLAT_BOX (Fl_Boxtype)(define_FL_OVAL_BOX()+3) +Events are identified by an Fl_Event enumeration value. The +following events are currently defined: -// conversions of box types to other boxtypes: -inline Fl_Boxtype down(Fl_Boxtype b) {return (Fl_Boxtype)(b|1);} -inline Fl_Boxtype frame(Fl_Boxtype b) {return (Fl_Boxtype)(b|2);} +
      -// back-compatability box types: -#define FL_FRAME FL_ENGRAVED_FRAME -#define FL_FRAME_BOX FL_ENGRAVED_BOX -#define FL_CIRCLE_BOX FL_ROUND_DOWN_BOX -#define FL_DIAMOND_BOX FL_DIAMOND_DOWN_BOX +
    • FL_NO_EVENT - No event occurred. -enum Fl_Labeltype { // labeltypes: - FL_NORMAL_LABEL = 0, - FL_NO_LABEL, - _FL_SYMBOL_LABEL, - _FL_SHADOW_LABEL, - _FL_ENGRAVED_LABEL, - _FL_EMBOSSED_LABEL, - _FL_BITMAP_LABEL, - _FL_PIXMAP_LABEL, - _FL_IMAGE_LABEL, - _FL_MULTI_LABEL, - FL_FREE_LABELTYPE -}; -extern Fl_Labeltype define_FL_SYMBOL_LABEL(); -#define FL_SYMBOL_LABEL define_FL_SYMBOL_LABEL() -extern Fl_Labeltype define_FL_SHADOW_LABEL(); -#define FL_SHADOW_LABEL define_FL_SHADOW_LABEL() -extern Fl_Labeltype define_FL_ENGRAVED_LABEL(); -#define FL_ENGRAVED_LABEL define_FL_ENGRAVED_LABEL() -extern Fl_Labeltype define_FL_EMBOSSED_LABEL(); -#define FL_EMBOSSED_LABEL define_FL_EMBOSSED_LABEL() +
    • FL_PUSH - A mouse button was pushed. -enum Fl_Align { // align() values - FL_ALIGN_CENTER = 0, - FL_ALIGN_TOP = 1, - FL_ALIGN_BOTTOM = 2, - FL_ALIGN_LEFT = 4, - FL_ALIGN_RIGHT = 8, - FL_ALIGN_INSIDE = 16, - FL_ALIGN_CLIP = 64, - FL_ALIGN_WRAP = 128, - FL_ALIGN_TOP_LEFT = FL_ALIGN_TOP | FL_ALIGN_LEFT, - FL_ALIGN_TOP_RIGHT = FL_ALIGN_TOP | FL_ALIGN_RIGHT, - FL_ALIGN_BOTTOM_LEFT = FL_ALIGN_BOTTOM | FL_ALIGN_LEFT, - FL_ALIGN_BOTTOM_RIGHT = FL_ALIGN_BOTTOM | FL_ALIGN_RIGHT, - FL_ALIGN_LEFT_TOP = FL_ALIGN_TOP_LEFT, - FL_ALIGN_RIGHT_TOP = FL_ALIGN_TOP_RIGHT, - FL_ALIGN_LEFT_BOTTOM = FL_ALIGN_BOTTOM_LEFT, - FL_ALIGN_RIGHT_BOTTOM = FL_ALIGN_BOTTOM_RIGHT, - FL_ALIGN_NOWRAP = 0 // for back compatability -}; +
    • FL_RELEASE - A mouse button was released. -enum Fl_Font { // standard fonts - FL_HELVETICA = 0, - FL_HELVETICA_BOLD, - FL_HELVETICA_ITALIC, - FL_HELVETICA_BOLD_ITALIC, - FL_COURIER, - FL_COURIER_BOLD, - FL_COURIER_ITALIC, - FL_COURIER_BOLD_ITALIC, - FL_TIMES, - FL_TIMES_BOLD, - FL_TIMES_ITALIC, - FL_TIMES_BOLD_ITALIC, - FL_SYMBOL, - FL_SCREEN, - FL_SCREEN_BOLD, - FL_ZAPF_DINGBATS, +
    • FL_ENTER - The mouse pointer entered a widget. - FL_FREE_FONT = 16, // first one to allocate - FL_BOLD = 1, // add this to helvetica, courier, or times - FL_ITALIC = 2 // add this to helvetica, courier, or times -}; +
    • FL_LEAVE - The mouse pointer left a widget. -#define FL_NORMAL_SIZE 14 // default size of all labels & text +
    • FL_DRAG - The mouse pointer was moved with a button + pressed. -enum Fl_Color { // standard colors - FL_BLACK = 0, - FL_RED = 1, - FL_GREEN = 2, - FL_YELLOW = 3, - FL_BLUE = 4, - FL_MAGENTA = 5, - FL_CYAN = 6, - FL_WHITE = 7, - FL_INACTIVE_COLOR = 8, - FL_SELECTION_COLOR = 15, +
    • FL_FOCUS - A widget should receive keyboard focus. - FL_FREE_COLOR = 16, - FL_NUM_FREE_COLOR = 16, +
    • FL_UNFOCUS - A widget loses keyboard focus. - FL_GRAY_RAMP = 32, +
    • FL_KEYBOARD - A key was pressed. - // boxtypes limit themselves to these colors so whole ramp is not allocated: - FL_GRAY0 = 32, // 'A' - FL_DARK3 = 39, // 'H' - FL_DARK2 = 45, // 'N' - FL_DARK1 = 47, // 'P' - FL_GRAY = 49, // 'R' default color - FL_LIGHT1 = 50, // 'S' - FL_LIGHT2 = 52, // 'U' - FL_LIGHT3 = 54, // 'W' +
    • FL_CLOSE - A window was closed. - FL_COLOR_CUBE = 56 -}; +
    • FL_MOVE - The mouse pointer was moved with no buttons + pressed. -inline Fl_Color inactive(Fl_Color c) {return (Fl_Color)(c|8);} -Fl_Color contrast(Fl_Color fg, Fl_Color bg); -#define FL_NUM_GRAY 24 -inline Fl_Color fl_gray_ramp(int i) {return (Fl_Color)(i+FL_GRAY_RAMP);} -#define FL_NUM_RED 5 -#define FL_NUM_GREEN 8 -#define FL_NUM_BLUE 5 -inline Fl_Color fl_color_cube(int r, int g, int b) { - return (Fl_Color)((b*FL_NUM_RED + r) * FL_NUM_GREEN + g + FL_COLOR_CUBE);} +
    • FL_SHORTCUT - The user pressed a shortcut key. -enum Fl_Cursor { // standard cursors - FL_CURSOR_DEFAULT = 0, - FL_CURSOR_ARROW = 35, - FL_CURSOR_CROSS = 66, - FL_CURSOR_WAIT = 76, - FL_CURSOR_INSERT = 77, - FL_CURSOR_HAND = 31, - FL_CURSOR_HELP = 47, - FL_CURSOR_MOVE = 27, - // fltk provides bitmaps for these: - FL_CURSOR_NS = 78, - FL_CURSOR_WE = 79, - FL_CURSOR_NWSE = 80, - FL_CURSOR_NESW = 81, - FL_CURSOR_NONE = 255, - // for back compatability (non MSWindows ones): - FL_CURSOR_N = 70, - FL_CURSOR_NE = 69, - FL_CURSOR_E = 49, - FL_CURSOR_SE = 8, - FL_CURSOR_S = 9, - FL_CURSOR_SW = 7, - FL_CURSOR_W = 36, - FL_CURSOR_NW = 68 - //FL_CURSOR_NS = 22, - //FL_CURSOR_WE = 55, -}; +
    • FL_DEACTIVATE - The widget has been deactivated. -enum { // values for "when" passed to Fl::add_fd() - FL_READ = 1, - FL_WRITE = 4, - FL_EXCEPT = 8 -}; +
    • FL_ACTIVATE - The widget has been activated. -enum Fl_Mode { // visual types and Fl_Gl_Window::mode() (values match Glut) - FL_RGB = 0, - FL_INDEX = 1, - FL_SINGLE = 0, - FL_DOUBLE = 2, - FL_ACCUM = 4, - FL_ALPHA = 8, - FL_DEPTH = 16, - FL_STENCIL = 32, - FL_RGB8 = 64, - FL_MULTISAMPLE= 128 -}; +
    • FL_HIDE - The widget has been hidden. -// damage masks +
    • FL_SHOW - The widget has been shown. + +
    • FL_PASTE - The widget should paste the contents of the + clipboard. + +
    • FL_SELECTIONCLEAR - The widget should clear any selections + made for the clipboard. + +
    + +

    Callback "When" Conditions

    + +The following constants determine when a callback is performed: + +
      + +
    • FL_WHEN_NEVER - Never call the callback. + +
    • FL_WHEN_CHANGED - Do the callback only when the + widget value changes. + +
    • FL_WHEN_NOT_CHANGED - Do the callback whenever the + user interacts with the widget. + +
    • FL_WHEN_RELEASE - Do the callback when the button or + key is released and the value changes. + +
    • FL_WHEN_ENTER_KEY - Do the callback when the user presses + the ENTER key and the value changes. + +
    • FL_WHEN_RELEASE_ALWAYS - Do the callback when the button + or key is released, even if the value doesn't change. + +
    • FL_WHEN_ENTER_KEY_ALWAYS - Do the callback when the user + presses the ENTER key, even if the value doesn't change. + +
    + +

    Fl::event_key() Values

    + +The following constants define the non-ASCII keys on the keyboard for +FL_KEYBOARD and FL_SHORTCUT events: + +
      + +
    • FL_Button - A mouse button; use Fl_Button + + n for mouse button n. + +
    • FL_BackSpace - The backspace key. + +
    • FL_Tab - The tab key. + +
    • FL_Enter - The enter key. + +
    • FL_Pause - The pause key. + +
    • FL_Scroll_Lock - The scroll lock key. + +
    • FL_Escape - The escape key. + +
    • FL_Home - The home key. + +
    • FL_Left - The left arrow key. + +
    • FL_Up - The up arrow key. + +
    • FL_Right - The right arrow key. + +
    • FL_Down - The down arrow key. + +
    • FL_Page_Up - The page-up key. + +
    • FL_Page_Down - The page-down key. + +
    • FL_End - The end key. + +
    • FL_Print - The print (or print-screen) key. + +
    • FL_Insert - The insert key. + +
    • FL_Menu - The menu key. + +
    • FL_Num_Lock - The num lock key. + +
    • FL_KP - One of the keypad numbers; use FL_KP + + n for number n. + +
    • FL_KP_Enter - The enter key on the keypad. + +
    • FL_F - One of the function keys; use FL_F + + n for function key n. + +
    • FL_Shift_L - The lefthand shift key. + +
    • FL_Shift_R - The righthand shift key. + +
    • FL_Control_L - The lefthand control key. + +
    • FL_Control_R - The righthand control key. + +
    • FL_Caps_Lock - The caps lock key. + +
    • FL_Meta_L - The left meta/Windows key. + +
    • FL_Meta_R - The right meta/Windows key. + +
    • FL_Alt_L - The left alt key. + +
    • FL_Alt_R - The right alt key. + +
    • FL_Delete - The delete key. + +
    + +

    Fl::event_state() Values

    + +The following constants define bits in the Fl::event_state() +value: + +
      + +
    • FL_SHIFT - One of the shift keys is down. + +
    • FL_CAPS_LOCK - The caps lock is on. + +
    • FL_CTRL - One of the ctrl keys is down. + +
    • FL_ALT - One of the alt keys is down. + +
    • FL_NUM_LOCK - The num lock is on. + +
    • FL_META - One of the meta/Windows keys is down. + +
    • FL_SCROLL_LOCK - The scroll lock is on. + +
    • FL_BUTTON1 - Mouse button 1 is pushed. + +
    • FL_BUTTON2 - Mouse button 2 is pushed. + +
    • FL_BUTTON3 - Mouse button 3 is pushed. + +
    + +

    Alignment Values

    + +The following constants define bits that can be used with Fl_Widget::align() to control the +positioning of the label: + +
      + +
    • FL_ALIGN_CENTER - The label is centered. + +
    • FL_ALIGN_TOP - The label is top-aligned. + +
    • FL_ALIGN_BOTTOM - The label is bottom-aligned. + +
    • FL_ALIGN_LEFT - The label is left-aligned. + +
    • FL_ALIGN_RIGHT - The label is right-aligned. + +
    • FL_ALIGN_INSIDE - The label is put inside the widget. + +
    • FL_ALIGN_CLIP - The label is clipped to the widget. + +
    • FL_ALIGN_WRAP - The label text is wrapped as needed. + +
    + +

    Fonts

    + +The following constants define the standard FLTK fonts: + + + +
  • FL_HELVETICA - Helvetica (or Arial) normal. + +
  • FL_HELVETICA_BOLD - Helvetica (or Arial) bold. + +
  • FL_HELVETICA_ITALIC - Helvetica (or Arial) oblique. + +
  • FL_HELVETICA_BOLD_ITALIC - Helvetica (or Arial) bold-oblique. + +
  • FL_COURIER - Courier normal. + +
  • FL_COURIER_BOLD - Courier bold. + +
  • FL_COURIER_ITALIC - Courier italic. + +
  • FL_COURIER_BOLD_ITALIC - Courier bold-italic. + +
  • FL_TIMES - Times roman. + +
  • FL_TIMES_BOLD - Times bold. + +
  • FL_TIMES_ITALIC - Times italic. + +
  • FL_TIMES_BOLD_ITALIC - Times bold-italic. + +
  • FL_SYMBOL - Standard symbol font. + +
  • FL_SCREEN - Default monospaced screen font. + +
  • FL_SCREEN_BOLD - Default monospaced bold screen font. + +
  • FL_ZAPF_DINGBATS - Zapf-dingbats font. + + + +

    Colors

    + +The following color constants can be used to access the colors in the FLTK +standard color palette: + +
      + +
    • FL_BLACK + +
    • FL_RED + +
    • FL_GREEN + +
    • FL_YELLOW + +
    • FL_BLUE + +
    • FL_MAGENTA + +
    • FL_CYAN + +
    • FL_WHITE + +
    • FL_GRAY0 + +
    • FL_DARK3 + +
    • FL_DARK2 + +
    • FL_DARK1 + +
    • FL_GRAY + +
    • FL_LIGHT1 + +
    • FL_LIGHT2 + +
    • FL_LIGHT3 + +
    + +

    Cursors

    + +The following constants define the mouse cursors that are available in +FLTK: + +
      +
    • FL_CURSOR_DEFAULT - the default cursor, usually an arrow +
    • FL_CURSOR_ARROW - an arrow pointer +
    • FL_CURSOR_CROSS - crosshair +
    • FL_CURSOR_WAIT - watch or hourglass +
    • FL_CURSOR_INSERT - I-beam +
    • FL_CURSOR_HAND - hand (uparrow on MSWindows) +
    • FL_CURSOR_HELP - question mark +
    • FL_CURSOR_MOVE - 4-pointed arrow +
    • FL_CURSOR_NS - up/down arrow +
    • FL_CURSOR_WE - left/right arrow +
    • FL_CURSOR_NWSE - diagonal arrow +
    • FL_CURSOR_NESW - diagonal arrow +
    • FL_CURSOR_NONE - invisible +
    + +

    FD "When" Conditions

    + +
      + +
    • FL_READ - Call the callback when there is data to be + read. + +
    • FL_WRITE - Call the callback when data can be written + without blocking. + +
    • FL_EXCEPT - Call the callback if an exception occurs on + the file. + +
    + +

    Damage Masks

    + +The following damage mask bits are used by the standard FLTK widgets: + +
      + +
    • FL_DAMAGE_CHILD - A child needs to be redrawn. + +
    • FL_DAMAGE_EXPOSE - The window was exposed. + +
    • FL_DAMAGE_SCROLL - The Fl_Scroll widget was + scrolled. + +
    • FL_DAMAGE_OVERLAY - The overlay planes need to be redrawn. + +
    • FL_DAMAGE_ALL - Everything needs to be redrawn. + +
    -enum Fl_Damage { - FL_DAMAGE_CHILD = 0x01, - FL_DAMAGE_EXPOSE = 0x02, - FL_DAMAGE_SCROLL = 0x04, - FL_DAMAGE_OVERLAY = 0x08, - FL_DAMAGE_ALL = 0x80 -}; -
  • diff --git a/documentation/events.html b/documentation/events.html index b4b5f1513..c4bc8c052 100644 --- a/documentation/events.html +++ b/documentation/events.html @@ -1,499 +1,225 @@ -

    4 - Handling Events

    +

    6 - Handling Events

    This chapter discusses the FLTK event model and how to handle events in your program or widget.

    The FLTK Event Model

    +Events are identified the small integer argument passed to the Fl_Widget::handle() virtual method. Other +information about the most recent event is stored in static locations +and acquired by calling the Fl::event_*() methods. This static +information remains valid until the next event is read from window +system (i.e. it is ok to look at it outside of the handle() method). +

    Mouse Events

    -

    FL_PUSH

    - -

    FL_RELEASE

    - -

    FL_DRAG

    - -

    FL_MOVE

    - -

    Keyboard Events

    - -

    FL_KEYBOARD

    - -

    FL_SHORTCUT

    - -

    Widget Events

    - -

    FL_ACTIVATE

    - -

    FL_DEACTIVATE

    - -

    FL_HIDE

    - -

    FL_SHOW

    - -

    FL_FOCUS

    - -

    FL_UNFOCUS

    - -

    FL_ENTER

    - -

    FL_LEAVE

    - -

    FL_PASTE

    - -

    FL_SELECTIONCLEAR

    - - - -Events in Fltk - -

    Events in Fltk

    - -

    Events are identified the small integer argument passed to the Fl_Widget::handle() virtual method. -Other information about the most recent event is stored in static -locations and aquired by calling Fl::event_*(). This static -information remains valid until the next event is read from the X -server (that is, it is ok to look at it outside the handle() method). - -

    FL_PUSH (1)

      +

      FL_PUSH

      A mouse button has gone down with the mouse pointing at this widget. You can find out what button by calling Fl::event_button(). You find out the mouse -position by calling Fl::event_x() and -Fl::event_y(). +href="#event_button">Fl::event_button(). You find out the +mouse position by calling Fl::event_x() +and Fl::event_y().

      A widget indicates that it "wants" the mouse click by returning -non-zero from it's handle() method. -It will then become the Fl::pushed() widget and -will get FL_DRAG and the matching FL_RELEASE events. If handle() -returns zero then fltk will try sending the FL_PUSH to another widget. +non-zero from its handle() method. It +will then become the Fl::pushed() widget +and will get FL_DRAG and the matching FL_RELEASE +events. If handle() returns zero then FLTK will try sending +the FL_PUSH to another widget. -

    FL_DRAG (5)

      +

      FL_DRAG

      -The mouse has moved with the button held down. +The mouse has moved with a button held down. -

    FL_RELEASE (2)

    FL_ENTER (3)

      - -The mouse has been moved to point at this widget. This can be used -for highlighting feedback. If a widget wants to highlight or -otherwise track the mouse, it indicates this by returning -non-zero from it's handle() method. -It then becomes the Fl::belowmouse() widget -and will receive FL_MOVE and FL_EXIT events. - -

    FL_MOVE (10)

      +

      FL_MOVE

      The mouse has moved without any mouse buttons held down. This event -is sent (sort of) to the belowmouse() widget. +is sent to the belowmouse() widget. -

    FL_LEAVE (4)

      +

      Focus Events

      + +

      FL_ENTER

      + +The mouse has been moved to point at this widget. This can be used for +highlighting feedback. If a widget wants to highlight or otherwise +track the mouse, it indicates this by returning non-zero from its handle() method. It then becomes the Fl::belowmouse() widget and will +receive FL_MOVE and FL_LEAVE events. + +

      FL_LEAVE

      The mouse has moved out of the widget. -

    FL_FOCUS (6)

      +

      FL_FOCUS

      This indicates an attempt to give a widget the keyboard focus.

      If a widget wants the focus, it should change itself to display the -fact that it has the focus, and return non-zero from it's handle() method. It then becomes the Fl::focus() widget and gets FL_KEYBOARD and FL_UNFOCUS -events. +fact that it has the focus, and return non-zero from its handle() method. It then becomes the Fl::focus() widget and gets FL_KEYBOARD +and FL_UNFOCUS events.

      The focus will change either because the window manager changed which window gets the focus, or because the user tried to navigate using tab, arrows, or other keys. You can check Fl::event_key() to figure out why it moved. For -navigation it will be the key pressed, for instructions from the +href="#event_key">Fl::event_key() to figure out why it moved. For +navigation it will be the key pressed and for instructions from the window manager it will be zero. -

    FL_UNFOCUS (7)

      +

      FL_UNFOCUS

      -Sent to the old Fl::focus() when something else -gets the focus. +Sent to the previous Fl::focus() when +another widget gets the focus. -

    FL_KEYBOARD (8)

      +

      Keyboard Events

      + +

      FL_KEYBOARD

      A key press. The key pressed can be found in Fl::event_key(), or, more usefully, the text that -the key should insert can be found with Fl::event_text() and it's length is in Fl::event_length(). If you use the key -handle() should return 1. If you return zero then fltk assummes you -ignored the key. It will then attempt to send it to a parent widget. -If none of them want it, it will change the event into a FL_SHORTCUT -event. +href="#event_key">Fl::event_key(). The text that the key +should insert can be found with Fl::event_text() and its length is in +Fl::event_length(). If you use +the key handle() should return 1. If you return zero then +FLTK assummes you ignored the key. It will then attempt to send it to +a parent widget. If none of them want it, it will change the event into +a FL_SHORTCUT event. -

    FL_SHORTCUT (11)

      +

      FL_SHORTCUT

      -If the Fl::focus() is zero or ignores an -FL_KEYBOARD event then fltk tries sending this event to every widget -it can, until one of them returns non-zero. FL_SHORTCUT is first sent -to the belowmouse widget, then it's parents and siblings, and -eventually to every widget in the window, trying to find an object -that returns non-zero. Fltk tries real hard to not let any keystrokes -be ignored! - -

      If the Fl::event_text() is a lower or -upper-case letter, and nothing wants the shortcut +If the Fl::focus() is zero or ignores an +FL_KEYBOARD event then FLTK tries sending this event to every +widget it can, until one of them returns non-zero. +FL_SHORTCUT is first sent to the belowmouse() widget, +then its parents and siblings, and eventually to every widget in the +window, trying to find an object that returns non-zero. FLTK tries +really hard to not to ignore any keystrokes!

      You can also make "global" shortcuts by using Fl::add_handler(). A global shortcut will work -no matter what windows are displayed or which one has the focus. +href="#add_handler">Fl::add_handler(). A global shortcut +will work no matter what windows are displayed or which one has the +focus. -

    FL_DEACTIVATE (13)

      +

      Widget Events

      + +

      FL_DEACTIVATE

      This widget is no longer active, due to deactivate() being called on it or one -of it's parents. active() may still be true after this, the widget is -only active if active() is true on it and all it's parents. +href="#Fl_Widget.deactivate">deactivate() being called on +it or one of its parents. active() may still be true after this, the +widget is only active if active() is true on it and all its parents +(use active_r() to check this). -

    FL_ACTIVATE (14)

      +

      FL_ACTIVATE

      This widget is now active, due to active() being called on it or one -of it's parents. +href="#Fl_Widget.activate">activate() being called on it +or one of its parents. -

    FL_HIDE (15)

      +

      FL_HIDE

      This widget is no longer visible, due to hide() being called, or a parent group -or window having hide() be called, or due to a parent window being -iconized. visible() may still be true after this, the widget is -visible only if visible() is true for it and all it's parents. +href="#Fl_Widget.hide>hide() being called on it or one of its +parents, or due to a parent window being minimized. visible() +may still be true after this, but the widget is visible only if +visible() is true for it and all its parents (use +visible_r() to check this). -

    FL_SHOW (16)

      +

      FL_SHOW

      This widget is visible again, due to show() being called on it or one of -it's parents, or due to a parent window being deiconized. Child -Fl_Windows respond to this by actually creating the X window if not -done already, so if you subclass a window, be sure to pass FL_SHOW to -the base class handle() method! +href="#Fl_Widget.show">show() being called on it or one of +its parents, or due to a parent window being restored. Child +Fl_Windows respond to this by actually creating the window if not +done already, so if you subclass a window, be sure to pass FL_SHOW to +the base class handle() method! - -

    FL_PASTE (17)

    FL_SELECTIONCLEAR (18)

      +

      FL_SELECTIONCLEAR

      -The Fl::selection_owner() will get this +The Fl::selection_owner() will get this event before the selection is moved to another widget. This indicates that some other widget or program has claimed the selection. -
    +

    Fl::event_*() methods

    - -

    Fl::event_*() methods

    - -Fltk keeps the information about the most recent event in static +FLTK keeps the information about the most recent event in static storage. This information is good until the next event is processed. -Thus it is valid inside handle() and callback() methods. +Thus it is valid inside handle() and callback() methods.

    These are all trivial inline functions and thus very fast and -small. The data is stored in static locations and remains valid until -the next X event is handled. - - -

    int Fl::event_button();

    int Fl::event_x() -
    int Fl::event_y()

    int Fl::event_x_root() -
    int Fl::event_y_root()

    void Fl::get_mouse(int &,int &)

    ulong Fl::event_state(); -
    unsigned int Fl::event_state(int);

    int Fl::event_key(); -
    int Fl::event_key(int); -
    int Fl::get_key(int);

    Fl_Widget *Fl::focus() const; -
    void Fl::focus(Fl_Widget *);

    int Fl_Widget::take_focus();

    Fl_Widget *Fl::belowmouse() const; -
    void Fl::belowmouse(Fl_Widget *);

    Fl_Widget *Fl::pushed() const; -
    void Fl::pushed(Fl_Widget *);

    void Fl::add_handler(int (*f)(int));

    -

    Some versions of Make will accept rules like this to allow all .fl +Some versions of make will accept rules like this to allow all .fl files found to be compiled: -

    -.SUFFIXES : .fl .C .H
    -.fl.H :
    +
      +.SUFFIXES: .fl .cxx .h
      +.fl.h .fl.cxx:
       	fluid -c $<
      -.fl.C :
      -	fluid -c $<
      -
      +
    -

    Some versions of Make (gnumake) may prefer this syntax: - -

    -%.H: %.fl
    -        fluid -c $<
    -
    -%.C: %.fl
    -        fluid -c $<
    -
    - -

    The Widget Browser

    -

    + + + + + +
    -

    The main window shows a menu bar and a scrolling browser of all the +The main window shows a menu bar and a scrolling browser of all the defined widgets. The name of the .fl file being edited is shown in the window title.

    The widgets are stored in a hierarchy. You can open and close a level by clicking the "triangle" at the left of a widget. This -widget is the parent, and all the widgets listed below it are it's +widget is the parent, and all the widgets listed below it are its children. There can be zero children.

    The top level of the hierarchy is functions. Each of these -will produce a single C++ public function in the output .C file. -Calling the function will create all of it's child windows. +will produce a single C++ public function in the output .cxx file. +Calling the function will create all of its child windows.

    The second level of the hierarchy is windows. Each of these produces an instance of class Fl_Window. @@ -277,7 +247,12 @@ provide the well-known file-card tab interface. as "main_panel" in the example), or if unnamed as their type and label (such as "Button "the green""). -

    You select widgets by clicking on their names, which +

    + +You select widgets by clicking on their names, which highlights them (you can also select widgets from any displayed window). You can select many widgets by dragging the mouse across them, or by using shift+click to toggle them on and off. To select no @@ -289,74 +264,73 @@ this. widgets you have picked) by typing the F1 key. This will bring up a control panel or window from which you can change the widget. -

    Menu Items

    The menu bar at the top is duplicated as a pop-up menu on any displayed window. The shortcuts for all the menu items work in any window. The menu items are: -

    File/Open... (Alt+Shift+O)

      +

      File/Open... (Alt+Shift+O)

      Discard the current editing session and read in a different .fl file. You are asked for confirmation if you have changed the current data. -

      fluid can also read .fd files produced by the Forms and XForms -"fdesign" programs. It is best to read them with Merge. Fluid does not +

      FLUID can also read .fd files produced by the Forms and XForms +"fdesign" programs. It is best to read them with Merge. FLUID does not understand everything in a .fd file, and will print a warning message on the controlling terminal for all data it does not understand. You will probably need to edit the resulting setup to fix these errors. -Be careful not to save the file without changing the name, as fluid -will write over the .fd file with it's own format, which fdesign +Be careful not to save the file without changing the name, as FLUID +will write over the .fd file with its own format, which fdesign cannot read! -

    File/Save (Alt+s)

      +

      File/Save (Alt+s)

      Write the current data to the .fl file. If the file is unnamed -(because fluid was started with no name) then ask for a file name. +(because FLUID was started with no name) then ask for a file name. -

    File/Save As...(Alt+Shift+S)

      +

      File/Save As...(Alt+Shift+S)

      Ask for a new name to save the file as, and save it. -

    File/Merge... (Alt+i)

      +

      File/Merge... (Alt+i)

      Insert the contents of another .fl file, without changing the name of the current .fl file. All the functions (even if they have the same names as the current ones) are added, you will have to use cut/paste to put the widgets where you want. -

    File/Write code (Alt+Shift+C)

      +

      File/Write code (Alt+Shift+C)

      -"Compiles" the data into a .C and .H file. These are exactly the same -as the files you get when you run fluid with the -c switch. +"Compiles" the data into a .cxx and .h file. These are exactly the same +as the files you get when you run FLUID with the -c switch.

      The output file names are the same as the .fl file, with the -leading directory and trailing ".fl" stripped, and ".H" or ".C" +leading directory and trailing ".fl" stripped, and ".h" or ".cxx" appended. Currently there is no way to override this. -

    File/Quit (Alt+q)

      +

      File/Quit (Alt+q)

      -Exit fluid. You are asked for confirmation if you have changed the +Exit FLUID. You are asked for confirmation if you have changed the current data. -

    Edit/Undo (Alt+z)

      +

      Edit/Undo (Alt+z)

      Don't you wish... This isn't implemented yet. You should do save often so that any mistakes you make don't irretrivably destroy your data. -

    Edit/Cut (Alt+x)

      +

      Edit/Cut (Alt+x)

      Delete the selected widgets and all their children. These are saved to a "clipboard" file (/usr/tmp/cut_buffer.fl) and can be pasted back -into this fluid or any other one. +into this FLUID or any other one. -

    Edit/Copy (Alt+c)

      +

      Edit/Copy (Alt+c)

      Copy the selected widgets and all their children to the "clipboard" file. -

    Edit/Paste (Alt+c)

      +

      Edit/Paste (Alt+c)

      Paste in the widgets in the clipboard file. @@ -372,7 +346,7 @@ doing a paste.

      Cut/paste is the only way to change the parent of a widget. -

    Edit/Select All (Alt+a)

      +

      Edit/Select All (Alt+a)

      Select all widgets in the same group as the current selection. @@ -380,20 +354,20 @@ Select all widgets in the same group as the current selection. that group's parent. Repeatedly typing Alt+a will select larger and larger groups of widgets until everything is selected. -

    Edit/Open... (F1 or double click)

      +

      Edit/Open... (F1 or double click)

      If the current widget is a window and it is not displayed, display it. Otherwise open a control panel for the most recent (and possibly all) selected widgets. -

    Edit/Sort

      +

      Edit/Sort

      All the selected widgets are sorted into left to right, top to bottom -order. You need to do this to make navigation keys in fltk work +order. You need to do this to make navigation keys in FLTK work correctly. You may then fine-tune the sorting with "Earlier" and "Later". This does not affect the positions of windows or functions. -

    Edit/Earlier (F2)

      +

      Edit/Earlier (F2)

      All the selected widgets are moved one earlier in order amoung the children of their parent (if possible). This will affect navigation @@ -401,35 +375,35 @@ order, and if the widgets overlap it will affect how they draw, as the later widget is drawn on top of the earlier one. You can also use this to reorder functions and windows within functions. -

    Edit/Later (F3)

      +

      Edit/Later (F3)

      All the selected widgets are moved one later in order amoung the children of their parent (if possible). -

    Edit/Group (F7)

      +

      Edit/Group (F7)

      Create a new Fl_Group and make all the currently selected widgets be children of it. -

    Edit/Ungroup (F8)

      +

      Edit/Ungroup (F8)

      If all the children of a group are selected, delete that group and -make them all be children of it's parent. +make them all be children of its parent. -

    Edit/Overlays on/off (Alt+o)

      +

      Edit/Overlays on/off (Alt+o)

      Toggle the display of the red overlays off, without changing the selection. This makes it easier to see box borders and how the layout looks. The overlays will be forced back on if you change the selection. -

    Edit/Preferences (Alt+p)

      +

      Edit/Preferences (Alt+p)

      Currently the only preferences are for the "alignment grid" that all widgets snap to when you move them and resize them, and for the "snap" -which is how far a widget has to be dragged from it's original +which is how far a widget has to be dragged from its original position to actually change. -

    New/code/Function

      +

      New/code/Function

      Create a new C function. You will be asked for a name for the function. This name should be a legal C++ function template, without @@ -441,17 +415,17 @@ as returning an Fl_Window*. The unnamed window will be returned from it (more than one unnamed window is useless). If the function contains only named windows it will be declared as returning void. -

      It is possible to make the .C output be a self-contained program +

      It is possible to make the .cxx output be a self-contained program that can be compiled and executed. This is done by deleting the function name, in which case "main(argc,argv)" is used. The function will call show() on all the windows it creates and then call Fl::run(). This can be used to test resize behavior or other parts of the user interface. I'm not sure if it is possible to create really -useful programs using just Fluid. +useful programs using just FLUID.

      You can change the function name by double clicking the function. -

    New/Window

      +

      New/Window

      Create a new Fl_Window. It is added to the currently selected function, or to the function containing the currently selected item. @@ -461,7 +435,7 @@ to whatever size you require.

      You also get the window's control panel, which is almost exactly the same as any other Fl_Widget, and is described in the next chapter. -

    New/...

      +

      New/...

      All other items on the New menu are subclasses of Fl_Widget. Creating them will add them to the currently selected group or window, or the @@ -472,29 +446,28 @@ possible.

      When you create the widget you will get the widget's control panel, described in the next chapter. -

    Help/About fluid

      +

      Help/About FLUID

      -Pops up a panel showing the version of fluid. +Pops up a panel showing the version of FLUID. -

    Help/Manual

      +

      Help/Manual

      -Not yet implemented. Use netscape to read these pages instead. +Not yet implemented. Use a HTML or PDF file viewer to read these pages +instead. -
    - -

    The Widget Panel

    + + + + + +
    + When you double-click a widget or a set of widgets you will get the -"widget attribute panel": +"widget attribute panel". -

    - -

    When you change attributes -using this panel, the changes are reflected immediately in the window. -It is useful to hit the "no overlay" button (or type Alt+o) to -hide the red overlay so you can see the widgets more accurately, -especially when setting the box type. +

    When you change attributes using this panel, the changes are +reflected immediately in the window. It is useful to hit the "no +overlay" button (or type Alt+o) to hide the red overlay so you can see +the widgets more accurately, especially when setting the box type.

    If you have several widgets selected, they may have different values for the fields. In this case the value for one of the @@ -502,12 +475,17 @@ widgets is shown. But if you change this value, all the selected widgets are changed to the new value.

    Hitting "OK" makes the changes permanent. Selecting a different -widget also makes the changes permanent. Fluid checks for simple +widget also makes the changes permanent. FLUID checks for simple syntax errors in any code (such as mismatched parenthesis) before saving any text. -

    "Revert" or "Cancel" put everything back to when you last brought -up the panel or hit OK. However in the current version of Fluid, +

    + +"Revert" or "Cancel" put everything back to when you last brought +up the panel or hit OK. However in the current version of FLUID, changes to "visible" attributes (such as the color, label, box) are not undone by revert or cancel. Changes to code like the callbacks is undone, however. @@ -515,55 +493,55 @@ is undone, however.

    Widget Attributes

    -

    Name (text field)

      +

      Name (text field)

      Name of a global C variable to declare, and to store a pointer to this widget into. This variable will be of type "<class>*". If the name is blank then no variable is created.

      You can name several widgets with "name[0]", "name[1]", "name[2]", -etc. This will cause Fluid to declare an array of pointers. The +etc. This will cause FLUID to declare an array of pointers. The array is big enough that the highest number found can be stored. All widgets that in the array must be the same type. -

    Type (upper-right pulldown menu)

      +

      Type (upper-right pulldown menu)

      Some classes have subtypes that modify their appearance or behavior. You pick the subtype off of this menu. -

    Box (pulldown menu)

      +

      Box (pulldown menu)

      The boxtype to draw as a background for the widget.

      Many widgets will work, and draw faster, with a "frame" instead of a "box". A frame does not draw the colored interior, leaving whatever -was already there visible. Be careful, as fluid may draw this ok but +was already there visible. Be careful, as FLUID may draw this ok but the real program leave unwanted stuff inside the widget.

      If a window is filled with child widgets, you can speed up -redrawing by changing the window's box type to "NO_BOX". Fluid will +redrawing by changing the window's box type to "NO_BOX". FLUID will display a checkerboard for any areas that are not colored in by boxes (notice that this checkerboard is not drawn by the resulting program, instead random garbage is left there). -

    Color

      +

      Color

      The color to draw the box with. -

    Color2

      +

      Color2

      -

      Some widgets will use this color for certain parts. Fluid does not +

      Some widgets will use this color for certain parts. FLUID does not always show the result of this: this is the color buttons draw in when pushed down, and the color of input fields when they have the focus. -

    Label

      +

      Label

      String to print next to or inside the button.

      You can put newlines into the string to make multiple lines, the easiest way is by typing ctrl+j. -

    Label style (pull down menu)

    Label alignement (buttons)

      +

      Label alignement (buttons)

      Where to draw the label. The arrows put it on that side of the widget, you can combine the to put it in the corner. The "box" button puts the label inside the widget, rather than outside. -

    Label font

      +

      Label font

      Font to draw the label in. Ignored by symbols, bitmaps, and pixmaps. Your program can change the actual font used by these "slots", in case you want some font other than the 16 provided. -

    Label size

      +

      Label size

      Point size for the font to draw the label in. Ignored by symbols, bitmaps, and pixmaps. To see the result without dismissing the panel, type the new number and then Tab. -

    Label color

      +

      Label color

      Color to draw the label. Ignored by pixmaps (bitmaps, however, do use this color as the foreground color). -

    Text font, size, color

      +

      Text font, size, color

      Some widgets display text, such as input fields, pull-down menus, browsers. You can change this here. -

    Visible

      +

      Visible

      If you turn this off the widget is hidden initially. Don't change this for windows or for the immediate children of a Tabs group. -

    Active

      +

      Active

      If you turn this off the widget is deactivated initially. Currently -no fltk widgets display the fact that they are inactive (like by graying +no FLTK widgets display the fact that they are inactive (like by graying out), but this may change in the future. -

    Resizable

      +

      Resizable

      If a window is resizable or has an immediate child that is resizable, then the user will be able to resize it. In addition all the size @@ -627,41 +605,41 @@ other children.

      You can get more complex behavior by making invisible boxes the resizable widget, or by using hierarchies of groups. Unfortunatley -the only way to test it is to compile the program. Resizing the fluid +the only way to test it is to compile the program. Resizing the FLUID window is not the same as what will happen in the user program. -

    Hotspot

      +

      Hotspot

      Each window may have exactly one hotspot (turning this on will turn off any others). This will cause it to be positioned with that widget -centered on the mouse. This position is determined when the fluid +centered on the mouse. This position is determined when the FLUID function is called, so you should call it immediately before showing the window. If you want the window to hide and then reappear at a new position, you should have your program set the hotspot itself just before show(). -

    subclass

      +

      subclass

      This is how you put your own subclasses of Fl_Widget in. Whatever identifier you type in here will be the class that is instantiated. -

      In addition, no #include header file is put in the .H file. You +

      In addition, no #include header file is put in the .h file. You must provide a #include line as the first of the "extra code" which declares your subclass.

      The class had better be similar to the class you are spoofing. It does not have to be a subclass. It is sometimes useful to change this -to another fltk class: currently the only way to get a double-buffered +to another FLTK class: currently the only way to get a double-buffered window is to change this field for the window to "Fl_Double_Window" -and to add "#include <FL/Fl_Double_Window.H>" to the extra code. +and to add "#include <FL/Fl_Double_Window.h>" to the extra code. -

    Extra code

      +

      Extra code

      These four fields let you type in literal lines of code to dump into -the .H or .C files. +the .h or .cxx files. -

      If the text starts with a '#' or the word "extern" then fluid -thinks this is an "include" line, and it is written to the .H file. +

      If the text starts with a '#' or the word "extern" then FLUID +thinks this is an "include" line, and it is written to the .h file. If the same include line occurs several times then only one copy is written. @@ -671,37 +649,37 @@ pointed to by the local variable 'w'. You can also access any arguments passed to the function here, and any named widgets that are before this one. -

      Fluid will check for matching parenthesis, braces, and quotes, but +

      FLUID will check for matching parenthesis, braces, and quotes, but does not do much other error checking. Be careful here, as it may be hard to figure out what widget is producing an error in the compiler. If you need more than 4 lines you probably should call a function in -your own .C code. +your own .cxx code. -

    Callback

      +

      Callback

      This can either be the name of a function, or a small snippet of -code. Fluid thinks that if there is any punctuation then it is code. +code. FLUID thinks that if there is any punctuation then it is code.

      A name names a function in your own code. It must be declared as "void <name>(<class>*,void*)". -

      A code snippet is inserted into a static function in the .C output +

      A code snippet is inserted into a static function in the .cxx output file. The function prototype is "void f(<class>* o, void* v)", so you can refer to -the widget as 'o' and the user_data as 'v'. Fluid will check for +the widget as 'o' and the user_data as 'v'. FLUID will check for matching parenthesis, braces, and quotes, but does not do much other error checking. Be careful here, as it may be hard to figure out what widget is producing an error in the compiler.

      If the callback is blank then no callback is set. -

    user_data

      +

      user_data

      This is a value for the user_data() of the widget. If blank the default value of zero is used. This can be any piece of C code that can be put "(void*)(<here>)". -

    User data type

      +

      User data type

      The "void*" in the callback function prototypes is replaced with this. You may want to use "long" for old XForms code. Be warned that @@ -709,7 +687,7 @@ anything other than "void*" is not guaranteed to work by the C++ spec! However on most architectures other pointer types are ok, and long is usually ok. -

    When

      +

      When

      When to do the callback. Can be "never", "changed", "release". The value of "enter key" is only useful for text input fields. The "no @@ -720,8 +698,6 @@ if the data is not changed. are not in the menu. You should use the extra code fields to put these values in. -
    -

    Selecting & Moving Widgets

    @@ -754,7 +730,7 @@ hierarchy. Hit the right arrow enough and you will select every widget in the window. Up/down widgets move to the previous/next widgets that overlap horizontally. If the navigation does not seem to work you probably need to "Sort" the widgets. This is important if -you have input fields, as fltk uses the same rules when using arrow keys +you have input fields, as FLTK uses the same rules when using arrow keys to move between input fields.

    To "open" a widget, double click it. To open several widgets @@ -764,7 +740,7 @@ select them and then type F1 or pick "Edit/Open" off the pop-up menu. the selection, so you can see the widget borders.

    You can resize the window by using the window manager border -controls. Fltk will attempt to round the window size to the nearest +controls. FLTK will attempt to round the window size to the nearest multiple of the grid size and makes it big enough to contain all the widgets (it does this using illegal X methods, so it is possible it will barf with some window managers!). Notice that the actual window @@ -775,21 +751,19 @@ child widgets may be different. almost identical to the panel for any other Fl_Widget. There are three extra items: -

    Border

      +

      Border

      This button turns the window manager border on or off. On most window managers you will have to close the window and reopen it to see the effect. -

    xclass

      +

      xclass

      The string typed into here is passed to the X window manager as the class. This can change the icon or window decorations. On most (all?) window managers you will have to close the window and reopen it to see the effect. -
    -

    Image Labels

    @@ -799,8 +773,8 @@ already been chosen, you can change the image used by picking "Image..." again. The name of the image will appear in the "label" field, but you can't edit it. -

    The contents of the image file are written to the .C file, -so if you wish to distribute the C code, you only need to copy the .C +

    The contents of the image file are written to the .cxx file, +so if you wish to distribute the C code, you only need to copy the .cxx file, not the images. If many widgets share the same image then only one copy is written. @@ -810,9 +784,9 @@ to the location the .fl file is (not necessarily the current directory). I recommend you either put the images in the same directory as the .fl file, or use absolute path names. -

    Notes for all image types

      +

      Notes for all image types

      -

      Fluid runs using the default visual of your X server. This may be +

      FLUID runs using the default visual of your X server. This may be 8 bits, which will give you dithered images. You may get better results in your actual program by adding the code "Fl::visual(FL_RGB)" to your code right before the first window is displayed. @@ -822,12 +796,12 @@ source X pixmap. Thus once you have put an image on a widget, it is nearly free to put the same image on many other widgets.

      If you are using a painting program to edit an image: the only way -to convince Fluid to read the image file again is to remove the image +to convince FLUID to read the image file again is to remove the image from all widgets that are using it (including ones in closed windows), -which will cause it to free it's internal copy, and then set the image -again. You may find it easier to exit Fluid and run it again. +which will cause it to free its internal copy, and then set the image +again. You may find it easier to exit FLUID and run it again. -

      Don't rely on how fltk crops images that are outside the widget, as +

      Don't rely on how FLTK crops images that are outside the widget, as this may change in future versions! The cropping of inside labels will probably be unchanged. @@ -838,57 +812,55 @@ and you want the image inside it, you must change the button's boxtype to FL_UP_FRAME (or another frame), otherwise when it is pushed it will erase the image. -

    XBM (X bitmap files)

      +

      XBM (X bitmap files)

      -

      Fluid will read X bitmap files. These files have C source code to +

      FLUID will read X bitmap files. These files have C source code to define a bitmap. Sometimes they are stored with the ".h" or ".bm" extension rather than the standard ".xbm". -

      Fluid will output code to construct an Fl_Bitmap widget and use it +

      FLUID will output code to construct an Fl_Bitmap widget and use it to label the widget. The '1' bits in the bitmap are drawn using the -label color of the widget. You can change the color in Fluid. The +label color of the widget. You can change the color in FLUID. The '0' bits are transparent.

      The program "bitmap" on the X distribution does an ok job of editing bitmaps. -

    XPM (X pixmap files)

    GIF files

      +

      GIF files

      -

      Fluid will also read GIF image files. These files are often used +

      FLUID will also read GIF image files. These files are often used on html documents to make icons. This lets you use nice icons that you steal off the net in your user interface. -

      Fluid converts these into (modified) xpm -format and uses an Fl_Pixmap widget to label the widget. Transparency -is handled the same as for xpm files. Notice that the conversion -removes the compression, so the code may be much bigger than the .gif -file. Only the first image of an animated gif file is used. +

      FLUID converts these into (modified) XPM format and uses an +Fl_Pixmap widget to label the widget. Transparency is handled the same +as for xpm files. Notice that the conversion removes the compression, +so the code may be much bigger than the .gif file. Only the first +image of an animated gif file is used.

      Behavior and performance with large .gif files is not guaranteed! -

    - -

    (back to contents) + + diff --git a/documentation/forms.html b/documentation/forms.html index 1d6614581..c1c69cf0e 100644 --- a/documentation/forms.html +++ b/documentation/forms.html @@ -3,182 +3,193 @@

    E - Forms Compatibility

    -Fluid (the Fast Light User Interface Designer) -can read the .fd files put out by all versions of Forms and XForms -fdesign. However, it will mangle them a bit, but it prints a warning -message about anything it does not understand. Fluid cannot write -fdesign files, so you should save to a new name so you don't write -over the old one. +This appendix describes the Forms compatibility included with FLTK. + +

    Importing Forms Layout Files

    + +FLUID can read the .fd files put out by all +versions of Forms and XForms fdesign. However, it will mangle them a +bit, but it prints a warning message about anything it does not +understand. FLUID cannot write fdesign files, so you should save to a +new name so you don't write over the old one.

    You will need to edit your main code considerably to get it to link -with the output from fluid. If you are not interested in this you may -have more immediate luck with the forms compatability header, +with the output from FLUID. If you are not interested in this you may +have more immediate luck with the forms compatibility header, <FL/forms.H>. -

    You should be able to compile existing Forms or XForms source code -by changing the -I switch to your compiler so that the forms.h file -supplied with FLTK is included. Take a look at forms.h to see how it -works, but the basic trick is lots of inline functions. -Most of the XForms demo programs work without changes. +

    Using the Compatibility Header File

    + +You should be able to compile existing Forms or XForms source code +by changing the include directory switch to your compiler so that the +forms.h file supplied with FLTK is included. Take a look at +forms.h to see how it works, but the basic trick is lots of +inline functions. Most of the XForms demo programs work without +changes. + +

    You will also have to compile your Forms or XForms program using a +C++ compiler. The FLTK library does not provide C bindings or header +files.

    Although FLTK was designed to be compatable with the GL Forms library (version 0.3 or so), XForms has bloated severely and it's interface is -X specific. Therefore, XForms compatability is no longer a goal of -FLTK. Compatability was limited to things that were free, or that -would add code that would not be linked in if the feature is unused. -I did not add anything that would make the FLTK widgets bigger, or that -used X types as arguments. +X-specific. Therefore, XForms compatibility is no longer a goal of +FLTK. Compatibility was limited to things that were free, or that +would add code that would not be linked in if the feature is unused, +or that was not X-specific.

    To use any new features of FLTK, you should rewrite your code to not -use the inline functions and instead use "pure" FLTK. This -will make it a lot cleaner and make it easier to figure out how to -call the FLTK functions. Unfortunately this conversion is harder than I -expeceted and even our inhouse code still uses forms.H a lot. +use the inline functions and instead use "pure" FLTK. This will make +it a lot cleaner and make it easier to figure out how to call the FLTK +functions. Unfortunately this conversion is harder than expected and +even Digital Domain's inhouse code still uses forms.H a lot.

    Problems you will encounter

    -
      - -

    • Many parts of XForms use X-specific structures like XEvent in -their interface. I did not emulate these! Unfortunately these +

      Many parts of XForms use X-specific structures like XEvent +in their interface. I did not emulate these! Unfortunately these features (such as the "canvas" widget) are needed by most large programs. You will need to rewrite these to use FLTK subclasses. -

    • Fl_Free widgets emulate the old -Forms "free" widget. It may be useful for porting programs that -change the handle() function on widgets, but you will still need to -rewrite things. +

      Fl_Free widgets emulate the +old Forms "free" widget. It may be useful for porting programs +that change the handle() function on widgets, but you will +still need to rewrite things. -

    • Fl_Timer widgets are provided to -emulate the XForms timer. These work, but are quite inefficient -and inaccurate compared to using Fl::add_timeout(). +

      Fl_Timer widgets are provided to +emulate the XForms timer. These work, but are quite inefficient and +inaccurate compared to using Fl::add_timeout(). -

    • All instance variables are hidden. +

      All instance variables are hidden. If you directly refer to the x, y, w, h, label, or other fields of your Forms widgets you will have to add empty parenthesis after each reference. The easiest way to do this is to globally replace "->x" -with "->x()", etc. Replace "boxtype" with box(). +with "->x()", etc. Replace "boxtype" with "box()". -

    • const char* arguments to most FLTK methods are simply stored, while -Forms would strdup() the passed string. This is most noticable with the -label of widgets. Your program must always pass static data such as a -string constant or malloc'd buffer to label(). If you are using -labels to display program output you may want to try the Fl_Output widget. +

      const char * arguments to most FLTK methods are simply +stored, while Forms would strdup() the passed string. This is +most noticable with the label of widgets. Your program must always +pass static data such as a string constant or malloc'd buffer to +label(). If you are using labels to display program output +you may want to try the Fl_Output widget. -

    • The default fonts and sizes are matched to the older GL version of +

      The default fonts and sizes are matched to the older GL version of Forms, so all labels will draw somewhat larger than an XForms program does. -

    • fdesign outputs a setting of a "fdui" instance variable to the main -window. I did not emulate this because I wanted all instance -variables to be hidden. You can store the same information in the -user_data() field of a window. To do this, -search through the fdesign output for all occurances -of "->fdui" and edit to use "->user_data()" instead. This will -require casts and is not trivial. +

      fdesign outputs a setting of a "fdui" instance variable to the main +window. I did not emulate this because I wanted all instance variables +to be hidden. You can store the same information in the +user_data() field of a window. To do this, search through +the fdesign output for all occurances of "->fdui" and edit to use +"->user_data()" instead. This will require casts and is not trivial. -

    • The prototype for the functions passed to fl_add_timeout() and -fl_set_idle_callback() callback are different. +

      The prototype for the functions passed to fl_add_timeout() +and fl_set_idle_callback() callback are different. -

    • All the following XForms calls are missing:

      +

      All the following XForms calls are missing:

      -

    • FL_VERSION, FL_REVISION, fl_library_version() -
    • FL_RETURN_DBLCLICK (use Fl::event_clicks()) -
    • fl_add_signal_callback() -
    • fl_set_form_atactivate() & fl_set_form_atdeactivate() -
    • fl_set_form_property() -
    • fl_set_app_mainform(), fl_get_app_mainform() -
    • fl_set_form_minsize(), fl_set_form_maxsize() -
    • fl_set_form_event_cmask(), fl_get_form_event_cmask() -
    • fl_set_form_dblbuffer(), fl_set_object_dblbuffer() (use an -Fl_Double_Window instead) -
    • fl_adjust_form_size() -
    • fl_register_raw_callback() -
    • fl_set_object_bw(), fl_set_border_width() -
    • fl_set_object_resize(), fl_set_object_gravity() -
    • fl_set_object_shortcutkey() -
    • fl_set_object_automatic() -
    • fl_get_object_bbox() (maybe FLTK should do this) -
    • fl_set_object_prehandler(), fl_set_object_posthandler() -
    • fl_enumerate_fonts() -
    • Most drawing functions -
    • fl_set_coordunit() (FLTK uses pixels all the time) -
    • fl_ringbell() -
    • fl_gettime() -
    • fl_win*() (all these functions) -
    • fl_initialize(argc,argv,x,y,z) ignores last 3 arguments -
    • fl_read_bitmapfile(), fl_read_pixmapfile() -
    • fl_addto_browser_chars() -
    • FL_MENU_BUTTON just draws normally -
    • fl_set_bitmapbutton_file(), fl_set_pixmapbutton_file() -
    • FL_CANVAS objects -
    • FL_DIGITAL_CLOCK (comes out analog) -
    • fl_create_bitmap_cursor(), fl_set_cursor_color() -
    • fl_set_dial_angles() -
    • fl_show_oneliner() -
    • fl_set_choice_shortcut(a,b,c) -
    • command log -
    • Only some of file selector is emulated -
    • FL_DATE_INPUT -
    • fl_pup*() (all these functions) -
    • textbox object (should be easy but I had no sample programs) -
    • xyplot object +
        +
      • FL_REVISION, fl_library_version() +
      • FL_RETURN_DBLCLICK (use Fl::event_clicks()) +
      • fl_add_signal_callback() +
      • fl_set_form_atactivate() & fl_set_form_atdeactivate() +
      • fl_set_form_property() +
      • fl_set_app_mainform(), fl_get_app_mainform() +
      • fl_set_form_minsize(), fl_set_form_maxsize() +
      • fl_set_form_event_cmask(), fl_get_form_event_cmask() +
      • fl_set_form_dblbuffer(), fl_set_object_dblbuffer() (use an + Fl_Double_Window instead) +
      • fl_adjust_form_size() +
      • fl_register_raw_callback() +
      • fl_set_object_bw(), fl_set_border_width() +
      • fl_set_object_resize(), fl_set_object_gravity() +
      • fl_set_object_shortcutkey() +
      • fl_set_object_automatic() +
      • fl_get_object_bbox() (maybe FLTK should do this) +
      • fl_set_object_prehandler(), fl_set_object_posthandler() +
      • fl_enumerate_fonts() +
      • Most drawing functions +
      • fl_set_coordunit() (FLTK uses pixels all the time) +
      • fl_ringbell() +
      • fl_gettime() +
      • fl_win*() (all these functions) +
      • fl_initialize(argc,argv,x,y,z) ignores last 3 arguments +
      • fl_read_bitmapfile(), fl_read_pixmapfile() +
      • fl_addto_browser_chars() +
      • FL_MENU_BUTTON just draws normally +
      • fl_set_bitmapbutton_file(), fl_set_pixmapbutton_file() +
      • FL_CANVAS objects +
      • FL_DIGITAL_CLOCK (comes out analog) +
      • fl_create_bitmap_cursor(), fl_set_cursor_color() +
      • fl_set_dial_angles() +
      • fl_show_oneliner() +
      • fl_set_choice_shortcut(a,b,c) +
      • command log +
      • Only some of file selector is emulated +
      • FL_DATE_INPUT +
      • fl_pup*() (all these functions) +
      • textbox object (should be easy but I had no sample programs) +
      • xyplot object
      -

      Additional notes for porting old Forms programs

      +

      Additional Notes

      -

      These notes were written for porting programs written with the -older GL version of Forms. Most of these problems are the same ones +These notes were written for porting programs written with the older +IRISGL version of Forms. Most of these problems are the same ones encountered when going from old Forms to XForms: -

      Does not go into background

      +

      Does Not Run In Background

      -The GL library always forked when you created the first window, unless +The IRISGL library always forked when you created the first window, unless "foreground()" was called. FLTK acts like "foreground()" is called all the time. If you really want the fork behavior do "if (fork()) exit(0)" right at the start of your program. -

      You cannot use GL windows or fl_queue

      +

      You Cannot Use IRISGL windows or fl_queue

      -

      If a Forms (not XForms) program if you wanted your own window for -displaying things you would create a GL window and draw in it, +If a Forms (not XForms) program if you wanted your own window for +displaying things you would create a IRISGL window and draw in it, periodically calling Forms to check if the user hit buttons on the -panels. If the user did things to the GL window, you would find this -out by having the value FL_EVENT returned from the call to Forms. +panels. If the user did things to the IRISGL window, you would find +this out by having the value FL_EVENT returned from the call to Forms.

      None of this works with FLTK. Nor will it compile, the necessary calls are not in the interface.

      You have to make a subclass of Fl_Gl_Window and write a draw() method and -handle() method. This may require anywhere from a trivial to a major -rewrite. See the example program shape.C for -how this is structured. +href="#Fl_Gl_Window">Fl_Gl_Window and write a draw() +method and handle() method. This may require anywhere from a trivial +to a major rewrite.

      If you draw into the overlay planes you will have to also write a -draw_overlay() routine and call redraw_overlay() on the gl window. +draw_overlay() method and call redraw_overlay() on the +OpenGL window. -

      One easy way to hack your program so it works is to make the draw() -and handle() methods on your window set some static variables, storing -what event happened. Then in the main loop of your program, call -Fl::wait() and then check these variables, acting on them as -though they are events read from fl_queue. +

      One easy way to hack your program so it works is to make the +draw() and handle() methods on your window set some +static variables, storing what event happened. Then in the main loop +of your program, call Fl::wait() and then check these +variables, acting on them as though they are events read from +fl_queue. -

      You must use OpenGL to draw everything

      +

      You Must Use OpenGL to Draw Everything

      -

      The file <FL/gl.h> defines replacements for a lot of gl calls, -translating them to OpenGL. There are much better translators -available that you might want to investigate. +

      The file <FL/gl.h> defines replacements for a lot of +IRISGL calls, translating them to OpenGL. There are much better +translators available that you might want to investigate. -

      You cannot make Forms subclasses

      +

      You Cannot Make Forms Subclasses

      -Programs that call fl_make_object or directly setting the handle -routine will not compile. You have to rewrite them to use a subclass -of Fl_Widget. It is important to note that the handle() method is not -exactly the same as the handle() function of Forms. Where a Forms -handle() returned non-zero, your handle() must call do_callback(). -And your handle() must return non-zero if it "understood" the event. +Programs that call fl_make_object or directly setting the +handle routine will not compile. You have to rewrite them to use a +subclass of Fl_Widget. It is important to note that the +handle() method is not exactly the same as the +handle() function of Forms. Where a Forms handle() +returned non-zero, your handle() must call +do_callback(). And your handle() must return non-zero +if it "understood" the event.

      An attempt has been made to emulate the "free" widget. This appears to work quite well. It may be quicker to modify your subclass @@ -187,34 +198,64 @@ into a "free" widget, since the "handle" functions match.

      If your subclass draws into the overlay you are in trouble and will have to rewrite things a lot. -

      You cannot use <device.h>

      +

      You Cannot Use <device.h>

      If you have written your own "free" widgets you will probably get a lot of errors about "getvaluator". You should substitute: - -
      Forms FLTK -
      MOUSE_X Fl::event_x_root() -
      MOUSE_Y Fl::event_y_root() -
      LEFTSHIFTKEY,RIGHTSHIFTKEY Fl::event_shift() -
      CAPSLOCKKEY Fl::event_capslock() -
      LEFTCTRLKEY,RIGHTCTRLKEY Fl::event_ctrl() -
      LEFTALTKEY,RIGHTALTKEY Fl::event_alt() -
      MOUSE1,RIGHTMOUSE Fl::event_state()&(1<<10) -
      MOUSE2,MIDDLEMOUSE Fl::event_state()&(1<<9) -
      MOUSE3,LEFTMOUSE Fl::event_state()&(1<<8) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      FormsFLTK
      MOUSE_XFl::event_x_root()
      MOUSE_YFl::event_y_root()
      LEFTSHIFTKEY,RIGHTSHIFTKEYFl::event_shift()
      CAPSLOCKKEYFl::event_capslock()
      LEFTCTRLKEY,RIGHTCTRLKEYFl::event_ctrl()
      LEFTALTKEY,RIGHTALTKEYFl::event_alt()
      MOUSE1,RIGHTMOUSEFl::event_state()&FL_BUTTON3
      MOUSE2,MIDDLEMOUSEFl::event_state()&FL_BUTTON2
      MOUSE3,LEFTMOUSEFl::event_state()&FL_BUTTON1
      -

      Anything else in getvaluator and you are on your own... +Anything else in getvaluator and you are on your own... -

      Font numbers are different

      +

      Font Numbers Are Different

      The "style" numbers have been changed because I wanted to insert bold-italic versions of the normal fonts. If you use Times, Courier, or Bookman to display any text you will get a different font out of -FLTK. If you are really desperate to fix this use the following code:
        +FLTK. If you are really desperate to fix this use the following code: -
        +
           fl_font_name(3,"*courier-medium-r-no*");
           fl_font_name(4,"*courier-bold-r-no*");
           fl_font_name(5,"*courier-medium-o-no*");
          diff --git a/documentation/functions.html b/documentation/functions.html
          index 6dfe9a0cf..8d1ddbf1c 100644
          --- a/documentation/functions.html
          +++ b/documentation/functions.html
          @@ -3,620 +3,837 @@
           
           

          B - Function Reference

          -When we created the window and box widgets - and widgets inside the window. - Here a single -Fl_Box is created. The arguments to the -constructor are a value for the box() -property (most constructors do not have this), values for x(), y(), w(), h() to define the position -and size of the box, and a value for label() to define the text printed in the -box. +This appendix describes all of the fl_ functions and +Fl:: methods. For a description of the FLTK widgets, see Appendix A. -

          All the widgets have several attributes and there is a method for -setting and getting the current value of each of them. -box->labelsize(36) sets the labelsize() to 36. You could get -the value with box->labelsize(). Often you have to set -many properties, so you will be relieved to know that almost all of -these methods are trivial inline functions. +

          Functions

          -

          labelfont() is -set to a symbolic value which is compiled into a constant integer, 3 -in this case. All properties that cannot be described by a single -small number use a 1-byte index into a table. This makes the widget -smaller, allows the actual definition of the property to be deferred -until first use, and you can redefine existing entries to make global -style changes. +

          int fl_color_chooser(const char*, double &r, double &g, double &b)
          +int fl_color_chooser(const char *, uchar &r, uchar &g, uchar &b)

          -

          labeltype(FL_SHADOW_LABEL) -also stores a 1-byte symbolic value, in this case indicating a -procedure to draw drop shadows under the letters should be called to -draw the label. +The double version takes RGB values in the range 0.0 to 1.0. The +uchar version takes RGB values in the range 0 to 255. -

          The constructor for widgets adds them as children of the "current -group" (usually a window). window->end() stops adding -them to this window. For more control over the construction of -objects, you can end() the window immediately, and then add the -objects with window->add(box). You can -also do window->begin() -to switch what window new objects are added to. +

          -

          window->show() finally -puts the window on the screen. It is not until this point that the X -server is opened. FLTK provides some optional and rather -simple command-line parsing if you call show(argv,argc). If you don't want this, just -call show() with no arguments, and the unused argument code is not -linked into your program, making it smaller! +

          fl_color_chooser() pops up a window to let the user pick an +arbitrary RGB color. They can pick the hue and saturation in the "hue +box" on the left (hold down CTRL to just change the saturation), and +the brighness using the vertical slider. Or they can type the 8-bit +numbers into the RGB Fl_Value_Input fields, or drag the +mouse across them to adjust them. The pull-down menu lets the user set +the input fields to show RGB, HSV, or 8-bit RGB (0 to 255). -

          Fl::run() makes FLTK -enter a loop to update the screen and respond to events. By -default when the user closes the last window FLTK exits by calling exit(0). run() does not -actually return, it is declared to return an int so you can end your -main() function with "return Fl::run()" and outwit the stupid compiler -made by a certain very large software company. +

          This returns non-zero if the user picks ok, and updates the RGB +values. If the user picks cancel or closes the window this returns +zero and leaves RGB unchanged. -

          The following command compiles this program, assuming the FLTK -library has been put in /usr/local/lib and the header files in -/usr/local/include/FL: +

          If you use the color chooser on an 8-bit screen, it will allocate +all the available colors, leaving you no space to exactly represent +the color the user picks! You can however use fl_rectf() to fill a region with a +simulated color using dithering. +

          int fl_show_colormap(int oldcol)

          +fl_show_colormap() pops up a panel of the 256 colors you +can access with fl_color() and lets the +user pick one of them. It returns the new color index, or the old one +if the user types ESC or clicks outside the window. +
          +

          void fl_message(const char *, ...)

          +Displays a printf-style message in a pop-up box with an "OK" +button, waits for the user to hit the button. The message will wrap +to fit the window, or may be many lines by putting \n characters into +it. The enter key is a shortcut for the OK button. +
          +

          void fl_alert(const char *, ...)

          +Same as fl_message() except for the "!" symbol. +
          +

          int fl_ask(const char *, ...)

          +Displays a printf-style message in a pop-up box with an "Yes" and "No" +button and waits for the user to hit a button. The return value is 1 +if the user hits Yes, 0 if they pick No. The enter key is a shortcut +for Yes and ESC is a shortcut for No. +
          +

          int fl_choice(const char *q, const char *b0, const char *b1, const char *b2, ...)

          +Shows the message with three buttons below it marked with the strings +b0, b1, and b2. Returns 0, 1, or 2 +depending on which button is hit. ESC is a shortcut for button 0 and +the enter key is a shortcut for button 1. Notice the "misordered" +position of the buttons. You can hide buttons by passing NULL +as their labels. +
          +

          const char *fl_input(const char *label, const char *deflt = 0, ...)

          +Pops up a window displaying a string, lets the user edit it, and return +the new value. The cancel button returns NULL. The +returned pointer is only valid until the next time fl_input() +is called. Due to back-compatability, the arguments to any printf +commands in the label are after the default value. +
          +

          const char *fl_password(const char *label, const char *deflt = 0, ...)

          +Same as fl_input() except an Fl_Secret_Input field is used. - -

          The first thing your program should do is construct one or more -trees of Fl_Widgets. The base widget of each of these is -an Fl_Window widget. The constructors for widgets -automatically add them as children of the most recent created window -widget (use window->end() to stop this). Constructing the widgets -does not require the display to be open and does not open it, -unless you purposely open it to get information such as the width of a -font. - -

          Fl_Windows are displayed on the screen with -Fl_Window::show(). For the first window you may also use -Fl_Window::show(argc,argv) and FLTK will automatically -parse some startup arguments such as -display. - -

          Then the program repeatedly calls Fl::wait(). Each -time "something happens" Fl::wait() returns, usually after -a block of X events have been read and processed. It is often useful -for a program to check global state after each event, and FLTK makes -this easy by leaving the main loop under your control. - -

          Each widget has a single "callback". This is a function that -is called when something happens (such as the user pressing a button). -FLTK avoids all the complexities of signals/slots by having only a -single callback. Instead a when() method on the object selects when -the callback is done (ie. when a slider is moved or when the mouse is -released). - -

          The callback is passed a pointer to the widget and a void* user_data -field. This is redundant, as the user_data can be determined from the -widget, but was done for XForms compatability and to make the same -callbacks useful for menu items. Typically you want to turn the -callback into a method on some C++ object. A simple way is to use the -user_data as a pointer to the object. A more common but harder to -understand way is to store the object in the parent widget's -user_data field, since usually all the controls on a window are for the -same object, this lets you use the user_data for an abitrary method -argument. - -

          To display graphic data, you must subclass either -Fl_Window or Fl_Widget and define the virtual -draw() method. This can use functions defined in -<FL/fl_draw.H>, or can use system-specific calls such as Xlib. If -the data being displayed changes, your main program calls the -redraw() method on your widget, and FLTK will call -draw() while waiting for the next event. Subclassing -Fl_Window or Fl_Widget is so easy that I felt -it unnecessary to provide the "canvas" widget that most toolkits have. - -

          If your program needs to monitor another device (such as stdin) you -can provide a callback routine for when it becomes ready, by using -Fl::add_fd(i). If your program needs something to happen -at regular intervals you can define a timeout callback with Fl::add_timeout(time). - -

          Building a large hierarchy is made much easier with fluid -(the Fast Light User Interface Designer). This is a program that lets -you interactively design the widget layout and set all the properties -visually. It outputs C++ source code that you compile and link with -your program. All you have to write is the main loop and any -callbacks. - - - - - - -This chapter demonstrates the basics of FLTK programming with examples. - -

          Compiling a FLTK Program

          - -

          Include Files

          - -

          Library Files

          - -

          A "Hello, World" Program

          - -

          Creating the Window

          - -

          The Main Loop

          - - - -FLTK example: ask.C -

          ask.C

          - -

          - -

          -#include <stdio.h>
          -#include <string.h>
          -#include <FL/Fl.H>
          -#include <FL/Fl_Window.H>
          -#include <FL/Fl_Input.H>
          -#include <FL/Fl_Button.H>
          -#include <FL/Fl_Return_Button.H>
          -
          -int get_string(char*buffer, const char *from) {
          -  Fl_Window window(320,75);
          -  window.set_modal();
          -  Fl_Input input(60, 40, 250, 25,"Input:");
          -  input.value(buffer);
          -  Fl_Button cancel(60, 10,80, 25,"cancel");
          -  Fl_Return_Button ok(150, 10,80, 25,"OK");
          -  window.end();
          -  window.show();
          -  for (;;) {
          -    Fl::wait();
          -    Fl_Widget *o;
          -    while (o = Fl::readqueue()) {
          -      if (o == &ok) {
          -	strcpy(buffer, input.value());
          -	return 1;
          -      } else if (o == &cancel || o == &window) {
          -	return 0;
          -      }
          -    }
          -  }
          -}
          -
          -int main(int argc, char **argv) {
          -  char buffer[128];
          -  if (get_string(buffer, argv[1])) {
          -    puts(buffer);
          -    return 0;
          -  } else {
          -    return 1; // exit with error
          -  }
          -}
          -
          - -

          Widgets don't need to have callback() set. The default callback puts a -pointer to the widget on a "queue" from which it can later be read -with Fl::readqueue(). This was -done for Forms compatibility but it is useful for modal windows. In this example the -"get_string" function puts up a modal window and loops until one of -the buttons is pushed. - -Fl::wait() does exactly one cycle of -what Fl::run() does repeatedly: it updates the screen and then waits -for and responds to an event (or several events if they are all ready -at the same time). It then returns, allowing the user program to -check any state information it wants to after each group of events. -One thing the user program can check is Fl::readqueue() which returns each -object without a callback that was triggered. It returns null when -the queue is empty. It is possible for more than one object to be on -the queue (or the same object several times) so if your program wants -to read the queue it should always read it until empty and ignore -unrecognized widgets (don't look at them as they may have been -deleted). - -

          modal() on a window prevents any -interaction with other program windows below it, and prevents the user -from raising a program window above it (well, it tries, but X is -broken). It won't make any difference in this program because there -is only one window, but this allows the "get_string" function to be -used as subroutine by a larger program and have the expected behavior. - -

          This program also demonstrates that FLTK widgets may be constructed -as C++ automatic objects (local variables). You have to be careful -about destruction, however. -Always make sure all automatic children are destructed before the -container (by declaring the children after the container), -since the destructor for a container will attempt to delete all -remaining children, and you don't want to delete automatic objects. - -

          [Next example] -
          [back to contents] -FLTK example: button.C -

          button.C

          - -

          - -

          -#include <stdlib.h>
          -#include <stdio.h>
          -#include <FL/Fl.H>
          -#include <FL/Fl_Window.H>
          -#include <FL/Fl_Button.H>
          -
          -void beepcb(Fl_Widget *, void *) {
          -  printf("\007"); fflush(stdout);
          -}
          -
          -void exitcb(Fl_Widget *, void *) {
          -  exit(0);
          -}
          -
          -int main(int argc, char ** argv) {
          -  Fl_Window *window = new Fl_Window(320,65);
          -  window->begin();
          -  Fl_Button *b1 = new Fl_Button(20, 20, 80, 25, "Beep");
          -  b1->callback(beepcb,0);
          -  Fl_Button *b2 = new Fl_Button(120,20, 80, 25, "no op");
          -  Fl_Button *b3 = new Fl_Button(220,20, 80, 25, "Exit");
          -  b3->callback(exitcb,0);
          -  window->end();
          -  window->show(argc,argv);
          -  return Fl::run();
          -}
          -
          - -

          In this example we make some button widgets and make them do -something through callbacks. - -

          All widgets have a single callback() function. It is called in -response to an event on that widget, exactly which event depends on -the type of widget. The function takes two arguments: a pointer to -the widget (you will usually need to cast this to the correct -subclass) and a void* pointer to a piece of arbitrary user_data. - -

          You don't have to give all the widgets a callback, as the "no op" b2 -widget demonstrates. What these do is described in the next program. - -

          [Next example] -
          [back to contents] -FLTK methods - -

          #include <FL/Fl.H>

          - -

          You will have to include at least this header file in your main -code so that you can call the methods described here. - -

          Initialization

          - -

          You can construct all your widgets (and menus and boxtypes and -images and other FLTK types) without "initializing". The -constructors do not require a connection to the X display. This makes -it a lot easier, especially if your program has a mode where it does -not use a gui, and guarantees that code you don't use is not linked -in. - -

          FLTK is usually "initialized" when you show() the first window. At -this time the X display is opened and everything is set up so the -calls described in the rest of this document work. A few other calls -can open the X display, amoung them are fl_width() to measure the -size of a font. Be careful that the following calls are done before -the display is opened, if not you will get lots of strange X errors. - -

          Most of these "initialization" calls are to get around stupid X -things. I have tried to make these as simple to call as possible and -they have no effect on systems which aren't as badly designed as X. -But you should call them to make your program as portable as possible. - - -

        int Fl::visual(int)

        int Fl::gl_visual(int)

        void Fl::own_colormap();

          +

          The idle callback can call any FLTK functions. However if you call +something that calls Fl::wait() (such as a message pop-up) you +should first remove the idle callback so that it does not recurse. -Makes FLTK use it's 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 drag the cursor between -windows. +

          static void Fl::add_timeout(float t, void (*cb)(void *),void *v=0)

          -

          This does nothing if the current visual is not colormapped or on -MSWindows (even though it probably should if your display is in 8-bit -mode). +Add a one-shot timeout callback. The timeout will happen as soon as +possible after t seconds after the last time wait() +was called. The optional void * argument is passed to the +callback. -

        void Fl::get_system_colors();

          +

          This code will print "TICK" each second on stdout, no matter what +else the user or program does: -Read the user preference colors from the system and use them to call -Fl::foreground(), Fl::background(), and Fl::background2(). This is -done by Fl_Window::show(argc,argv) before applying the -fg and -bg -switches. +

            +void callback(void *) {
            +  printf("TICK\n");
            +  Fl::add_timeout(1.0,callback);
            +}
             
            -

            Currently this only works on MSWindows. In future versions on X it -may read the KDE or Gnome setup, but for now it does nothing. +main() { + Fl::add_timeout(1.0,callback); + Fl::run(); +} +

          -

        void Fl::background(uchar, uchar, uchar);

          +

          static int Fl::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. + +

          static int Fl::args(int argc, char **argv, int &i, int (*callback)(int, char**,int &)=0)
          +void Fl::args(int argc, char **argv)

          + +FLTK provides an entirely optional command-line switch parser. +You don't have to call it if you don't like them! Everything it can do +can be done with other calls to FLTK. + +

          To use the switch parser, call Fl::args(...) 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. + +

          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 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 to two letters and case is ignored: + +

            + +
          • -display host:n.n The X display to use (ignored + under WIN32). + +
          • -geometry WxH+X+Y The window position and size + will be modified according the the standard X geometry string. + +
          • -name string Fl_Window::xclass(string) will be + done to the window, possibly changing its icon. + +
          • -title string Fl_Window::label(string) will be + done to the window, changing both its title and the icontitle. + +
          • -iconic Fl_Window::iconize() will be done to + the window. + +
          • -bg color XParseColor is used to lookup the + passed color and then Fl::background() is done. Under WIN32 + only color names of the form "#xxxxxx" are understood. + +
          • -bg2 color XParseColor is used to lookup the + passed color and then Fl::background2() is done. + +
          • -fg color XParseColor is used to lookup the + passed color and then Fl::foreground() is done. + +
          + +The second form of Fl::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 Fl::abort(Fl::help). + +

          static void Fl::background(uchar, uchar, uchar)

          Changes fl_color(FL_GRAY) to the given color, and changes the gray ramp from 32 to 56 to black to white. These are the colors used as backgrounds by almost all widgets and used to draw the edges of all the boxtypes. -

        void Fl::foreground(uchar, uchar, uchar);

          - -Changes fl_color(FL_BLACK). Also changes -FL_INACTIVE_COLOR and FL_SELECTION_COLOR to -be a ramp between this and FL_WHITE. - -

        void Fl::background2(uchar, uchar, uchar);

          +

          static void Fl::background2(uchar, uchar, uchar)

          Changes fl_color(FL_WHITE) and the same colors as -Fl::foreground(). This color is used as a background by Fl_Input and -other text widgets. +Fl::foreground(). This color is used as a background by +Fl_Input and other text widgets. -

        int Fl::args(int argc, char** argv, int -&i, int (*callback)(int,char**,int&)=0)

        int Fl::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. - -

        void Fl::args(int argc, char** argv)

          - -This method is useful if your program does not have command line -switches of it's own. It parses all the switches, and if any are not -recognized it calls Fl::abort(Fl::help). - -

        const char* const Fl::help;

          - -A string descibing the switches understood by Fl::arg(), useful for -printing as an error message. - - -

        int Fl_Window::show(int argc, char** argv)

        - -

        Running

        - -After FLTK is "initialized" by calling show() on some window, you get -FLTK to wait for and respond to events by calling the following -methods: - -
        -

      int Fl::run()

      int Fl::wait()

        - -Calls the idle function if any, then calls any pending timeout -functions, then calls Fl::flush(). If there are -any windows displayed it then waits some time for events (zero if -there is an idle(), the shortest timeout if there are any timeouts, or -forever) and calls the handle() function on those events, and then -returns non-zero. - -

        Your program can check it's global state and update things after -each call to Fl::wait(), which can be very useful in complex programs. - -

        If there are no windows (this is checked after the idle and -timeouts are called) then Fl::wait() returns zero without waiting for -any events. Your program can either exit at this point, or call -show() on some window so the UI can continue to operate. - -

      float Fl::wait(float time)

        - -Wait only a certain amount of time for anything to happen. This does -the same as wait() except if the given time (in seconds) passes it -returns. The return value is how much time remains. If the return -value is zero or negative then the entire time period elapsed. - -

        If you do several wait(time) calls in a row, the subsequent ones -are measured from when the first one is called, even if you do -time-consuming calculations after they return. This allows you to -accurately make something happen at regular intervals. This code will -accurately call A() once per second (as long as it takes less than a -second to execute): - -

          -for (;;) {
          -  for (float time = 1.0; time > 0; ) time = Fl::wait(time);
          -  A();
          -}
          -
        - -

      int Fl::check()

        - -This does the same thing as Fl::wait(0), except because it does not +This does the same thing as Fl::wait(0), except because it does not have to return the elapsed time value it can be implemented faster on certain systems. Use this to interrupt a big calculation: -
          +
             while (!calculation_done()) {
               calculate();
               Fl::check();
               if (user_hit_abort_button()) break;
             }
            -
          +
        -

        This returns non-zero if any windows are displayed, and 0 if no +This returns non-zero if any windows are displayed, and 0 if no windows are displayed. -

      int Fl::ready();

      void Fl::add_timeout(float t,void (*cb)(void*),void* v=0); -
      void Fl::remove_timeout(void (*cb)(void*), void* = 0);

        +

        static void Fl::redraw()

        -Add or remove a one-shot timeout callback. The timeout will happen as -soon as possible after t seconds after the last time wait() was -called. The optional void* argument is passed to the callback. It is -harmless to remove a timeout callback that no longer exists. +Redraws all widgets. -

        This code will print "TICK" each second on stdout, no matter what -else the user or program does: +

        static void Fl::release()

        -
          -void callback(void *) {
          -  printf("TICK\n");
          -  Fl::add_timeout(1.0,callback);
          -}
          -main() {...
          -  Fl::add_timeout(1.0,callback);
          -  Fl::run();
          -}
          -
        +Turn off the grab() behavior. - -

      void Fl::set_idle(void (*cb)());

        +

        static void Fl::remove_idle(void (*cb)(void *), void *= 0)

        -If the idle callback is set it will be called by Fl::wait() and -Fl::wait() will return immediately. This can be used for background -processing. This will absorb all your machine's time! There is -only one idle callback, changing it will replace the old one. To turn -off the idle processing use Fl::set_idle(0). +Removes the specified idle callback. -

        Only Fl::wait(void) calls the idle callback. Fl::wait(time), -Fl::check(), and Fl::ready() ignore it. This is so that these -functions may be called by the idle callback itself without having to -worry about recursion. +

        static void Fl::remove_timeout(void (*cb)(void *), void *= 0)

        -

        The idle callback can call any FLTK functions. However if you call -something that calls Fl::wait() (such as a message pop-up) you should -first set the idle callback to zero so it does not recurse. +Removes a timeout callback. It is harmless to remove a timeout callback +that no longer exists. - -

      void Fl::flush()

        +

        static Fl::run()

        -Causes all the windows that need it to be redrawn and graphics forced -out through the pipes. This is what wait() does before looking for -events. +Runs FLTK until there are no windows displayed, and then returns a zero. +Fl::run() is exactly equivalent to: -

      int Fl::damage()

      Fl_Widget *Fl::readqueue();

      -

      Listening to other file descriptors (Unix only)

      +

      static Fl_Widget *Fl::selection_owner() const
      +static void Fl::selection_owner(Fl_Widget *)

      -

      -void Fl::add_fd(int fd, void (*cb)(int, void*), void* = 0);
      -void Fl::add_fd(int fd, int when, void (*cb)(int, void*), void* = 0);
      -void Fl::remove_fd(int);

        +The single-argument selection_owner(x) call can be used to +move the selection to another widget or to set the owner to +NULL, without changing the actual text of the selection. +FL_SELECTIONCLEAR is sent to the previous selection owner, if +any. -Add file descriptor fd to listen to. When the fd becomes ready -for reading the callback is done. The callback is passed the fd and -the arbitrary void* argument. Fl::wait() will return immediately -after calling the callback. +

        Copying the buffer every time the selection is changed is +obviously wasteful, especially for large selections. An interface will +probably be added in a future version to allow the selection to be made +by a callback function. The current interface will be emulated on top +of this. -

        The second version takes a when bitfield, with the bits -FL_READ, FL_WRITE, and FL_EXCEPT defined, to indicate when the -callback should be done. This probably only works on Unix. +

        static void Fl::set_boxtype(Fl_Boxtype, Fl_Box_Draw_F *, uchar, uchar, uchar, uchar)
        +static void Fl::set_boxtype(Fl_Boxtype, Fl_Boxtype from)

        -

        There can only be one callback of each type for a file descriptor. -Fl::remove_fd() gets rid of all the callbacks for a given file -descriptor. +The first form sets the function to call to draw a specific boxtype. + +

        The second form copies the from boxtype. + +

        static void Fl::set_color(Fl_Color, uchar r, uchar g, uchar b)

        + +Sets an entry in the fl_color index table. You can set +it to any 8-bit RGB color. The color is not allocated until +fl_color(i) is used. + +

        static int Fl::set_font(int face, const char *)
        +static int Fl::set_font(int face, int from)

        + +The first form changes a face. The string pointer is simply stored, +the string is not copied, so the string must be in static memory. + +

        The second form copies one face to another. + +

        int Fl::set_fonts(const char * = 0)

        + +FLTK will open the display, and add every font on the server to the +face table. It will attempt to put "families" of faces together, so +that the normal one is first, followed by bold, italic, and bold +italic. + +

        The optional argument is a string to describe the set of fonts to +add. Passing NULL will select only fonts that have the ISO8859-1 +character set (and are thus usable by normal text). Passing "-*" will +select all fonts with any encoding as long as they have normal X font +names with dashes in them. Passing "*" will list every font that +exists (on X this may produce some strange output). Other values may +be useful but are system dependent. With WIN32 NULL selects fonts +with ISO8859-1 encoding and non-NULL selects all fonts. + +

        The return value is how many faces are in the table after this is done. + +

        static void Fl::set_labeltype(Fl_Labeltype, Fl_Label_Draw_F *, Fl_Label_Measure_F *)
        +static void Fl:set_labeltype(Fl_Labeltype, Fl_Labeltype from)

        + +The first form sets the functions to call to draw and measure a +specific labeltype. + +

        The second form copies the from labeltype. + +

        int Fl::test_shortcut(ulong) const

        + +Test the current event, which must be an FL_KEYBOARD or +FL_SHORTCUT, against a shortcut value (described in Fl_Button). Returns non-zero +if there is a match. Not to be confused with +Fl_Widget::test_shortcut(). + +

        static int Fl::visual(int)

        + +Selects a visual so that your graphics are drawn correctly. This +does nothing if the default visual satisfies the capabilities, or if +no visual satisfies the capabilities, or on systems that don't have +such brain-dead notions. + +

        Only the following combinations do anything useful: + +

          + +
        • Fl::visual(FL_RGB) + +
          Full/true color (if there are several depths FLTK chooses + the largest). Do this if you use + fl_draw_image for much better (non-dithered) + output. +
            + +
        • Fl::visual(FL_RGB8) + +
          Full color with at least 24 bits of color. FL_RGB will always + pick this if available, but if not it will happily return a + less-than-24 bit deep visual. This call fails if 24 bits are not + available. +
            + +
        • Fl::visual(FL_DOUBLE|FL_INDEX) + +
          Hardware double buffering. Call this if you are going to use + Fl_Double_Window. +
            + +
        • Fl::visual(FL_DOUBLE|FL_RGB) +
        • Fl::visual(FL_DOUBLE|FL_RGB8) + +
          Hardware double buffering and full color. +
           
        -

        Exiting

        +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). -When all windows are closed Fl::wait() and Fl::run() return zero. If -your main() routine then returns the program exits. You can also call -exit(0) at any time in your program. You do not need to do any -cleanup code for FLTK. In particular you do not have to destroy -any widgets you have created. FLTK also does not sneak any atexit -functions in on you either. You will need to do -#include <stdlib.h> to call exit(). +

        static int Fl::w()

        -

        To stop a window from closing, or conversely to make the closing of -a particular window exit the program you must change the callback() -function. Here is a typical use: +Returns the width of the screen in pixels. -

          -static void main_window_cb(Fl_Widget*, void*) {
          -  if (document_changed()) {
          -    if (!fl_ask("Exit without saving changes?")) return;
          -    // window will not go away as hide() has not been called...
          -  }
          -  exit(0);
          +

          static int wait()
          +static double wait(double time)

          + +Calls the idle function if any, then calls any pending timeout +functions, then calls Fl::flush(). If there are +any windows displayed it then waits some time for events (zero if +there is an idle(), the shortest timeout if there are any timeouts, or +forever) and calls the handle() function on those events, and then +returns non-zero. + +

          Your program can check its global state and update things after +each call to Fl::wait(), which can be very useful in complex programs. + +

          If there are no windows (this is checked after the idle and +timeouts are called) then Fl::wait() returns zero without waiting for +any events. Your program can either exit at this point, or call +show() on some window so the GUI can continue to operate. + +The second form of Fl::wait() waits only a certain amount of +time for anything to happen. This does the same as wait() +except if the given time (in seconds) passes it returns. The return +value is how much time remains. If the return value is zero or +negative then the entire time period elapsed. + +

          If you do several wait(time) calls in a row, the subsequent ones +are measured from when the first one is called, even if you do +time-consuming calculations after they return. This allows you to +accurately make something happen at regular intervals. This code will +accurately call A() once per second (as long as it takes less than a +second to execute): + +

            +for (;;) {
            +  for (float time = 1.0; time > 0; ) time = Fl::wait(time);
            +  A();
             }
            +
          -...somewhere in main(): - main_window->callback(window_cb); -
        - - -

      void (*Fl::warning)(const char*,...); -
      void (*Fl::error)(const char*,...); -
      void (*Fl::fatal)(const char*,...);

        +

        static void (*Fl::warning)(const char *, ...)
        +static void (*Fl::error)(const char *, ...)
        +static void (*Fl::fatal)(const char *, ...)

        FLTK will call these to print messages when unexpected conditions -occur. By default they fprintf to stderr, and Fl::error and Fl::fatal -call exit(1). You can override the behavior by setting the function -pointers to your own routines. +occur. By default they fprintf to stderr, and +Fl::error and Fl::fatal call exit(1). You +can override the behavior by setting the function pointers to your own +routines. -

        Supposedly Fl::warning means that there was a recoverable problem, -the display may be messed up but the user can probably keep working -(all X protocol errors call this). Fl::error means there is a +

        Fl::warning means that there was a recoverable problem, the +display may be messed up but the user can probably keep working (all X +protocol errors call this). Fl::error means there is a recoverable error, but the display is so messed up it is unlikely the -user can continue (very little calls this now). Fl::fatal must not -return, as FLTK is in an unusable state (however your version may be -able to use longjmp or an exception to continue, as long as it does -not call FLTK again). - -

      (back to contents) -FLTK example: hello.C -

      hello.C

      - - -

      [Next example] -
      [back to contents] +user can continue (very little calls this now). Fl::fatal +must not return, as FLTK is in an unusable state, however your version +may be able to use longjmp or an exception to continue, as +long as it does not call FLTK again. diff --git a/documentation/glut.html b/documentation/glut.html index 3cbfdb50e..643f66dc2 100644 --- a/documentation/glut.html +++ b/documentation/glut.html @@ -3,143 +3,192 @@

      D - GLUT Compatibility

      -You should be able to compile existing Glut source code by -including <FL/glut.H> instead of <GL/glut.h>. This can be done by -editing the source, by changing the -I switches to the compiler, or by -providing a symbolic link from GL/glut.h to FL/glut.H. +This appendix describes the GLUT compatibility header file supplied with +FLTK. -

      All files calling glut procedures must be compiled with C++. You may +

      Using the GLUT Compatibility Header File

      + +You should be able to compile existing GLUT source code by including +<FL/glut.H> instead of <GL/glut.h>. This can +be done by editing the source, by changing the -I switches to +the compiler, or by providing a symbolic link from GL/glut.h +to FL/glut.H. + +

      All files calling GLUT procedures must be compiled with C++. You may have to alter them slightly to get them to compile without warnings, and you may have to rename them to get make to use the C++ compiler. -I was unable to get some calls to glu to compile without adding some -casts, apparently due to errors in the glu header files. -

      You must link with -lFl. If you call any glut drawing functions -that fltk does not emulate (glutExtensionsSupported(), glutWire*(), -glutSolid*(), and glutStroke*()), you will also have to link with --lglut, after -lFl. +

      You must link with the FLTK library. If you call any GLUT drawing +functions that FLTK does not emulate +(glutExtensionsSupported(), glutWire*(), +glutSolid*(), and glutStroke*()), you will also have +to link with the GLUT library (after the FLTK library!) -

      Most of glut.H is inline functions. You should take a look at it -(and maybe at glut.C in the fltk source) if you are having trouble -porting your Glut program. +

      Most of FL/glut.H is inline functions. You should take a +look at it (and maybe at test/glut.cxx in the FLTK source) if +you are having trouble porting your GLUT program.

      This has been tested with most of the demo programs that come with -the Glut 3.3 distribution. +the GLUT 3.3 distribution.

      Known Problems

      +The following functions and/or arguments to functions are missing, +and you will have to replace them or comment them out for your code to +compile: +

      int Fl_Gl_Window::can_do_overlay();

      void Fl_Gl_Window::redraw_overlay();

      virtual void Fl_Gl_Window::draw_overlay();


      - -

      Using OpenGL in normal Fltk windows

      - -

      You can put OpenGL code into an Fl_Widget::draw() method or into the code -for a boxtype or other places, with some care. +You can put OpenGL code into an Fl_Widget::draw() method or into the code for +a boxtype or other places with some care.

      Most important, before you show any windows (including those -that don't have OpenGL drawing) you must initialize fltk/X so that it +that don't have OpenGL drawing) you must initialize FLTK so that it knows it is going to use OpenGL. You may use any of the symbols -described for Fl_Gl_Window::mode() to describe how -you intend to use OpenGL: +described for Fl_Gl_Window::mode() to describe +how you intend to use OpenGL: -

        Fl::gl_visual(FL_RGB);

      +
        +Fl::gl_visual(FL_RGB);
        +
      -

      You can then put OpenGL drawing code anywhere you can draw normally +You can then put OpenGL drawing code anywhere you can draw normally by surrounding it with: -

        gl_start();
        -... put your OpenGL code here ...
        -gl_finish();

      +
        +gl_start();
        +... put your OpenGL code here ...
        +gl_finish();
        +
      -

      gl_start() and gl_finish() set up a GL context with an orthographic -projection so that 0,0 is the lower-left corner of the window and each -pixel is one unit. The current clipping is reproduced with OpenGL -scissor commands. These also synchronize the OpenGL graphics stream -with the drawing done by other X or fltk functions. +gl_start() and gl_finish() set up an OpenGL context with +an orthographic projection so that 0,0 is the lower-left corner of the +window and each pixel is one unit. The current clipping is reproduced +with OpenGL glScissor() commands. These also synchronize the +OpenGL graphics stream with the drawing done by other X, WIN32, or FLTK +functions.

      The same context is reused each time. If your code changes the -projection transformation or anything else you should use glPush/glPop -to put the state back before calling gl_finish(). +projection transformation or anything else you should use +glPushMatrix() and glPopMatrix() functions to put the +state back before calling gl_finish(). -

      You may want to use Fl_Window::current()->h() to get -the drawable height so you can flip the coordinate system. +

      You may want to use Fl_Window::current()->h() to get +the drawable height so you can flip the Y coordinates. -

      Unfortunately there are a bunch of limitations you must adhere to for -maximum portability:

        +

        Unfortunately, there are a bunch of limitations you must adhere to for +maximum portability: -

      • You must choose a default visual with Fl::gl_visual(). +
          -
        • You cannot pass FL_DOUBLE to Fl::gl_visual(). +
        • You must choose a default visual with Fl::gl_visual(). -
        • You cannot use Fl_Double_Window (or Fl_Overlay_Window). +
        • You cannot pass FL_DOUBLE to Fl::gl_visual(). + +
        • You cannot use Fl_Double_Window or + Fl_Overlay_Window.
        -

        Do not call gl_start()/gl_finish() when drawing an -Fl_Gl_Window! +Do not call gl_start() or gl_finish() when drawing +into an Fl_Gl_Window! -


      - -

      OpenGL drawing functions -
      #include <FL/gl_draw.H>

      +

      OpenGL drawing functions

      -Fltk provides some useful gl drawing functions. They can be freely -mixed with any OpenGL calls, and are defined by including <FL/gl.H> -(which you should include instead of the OpenGL header <GL/gl.h>). +FLTK provides some useful OpenGL drawing functions. They can be freely +mixed with any OpenGL calls, and are defined by including +<FL/gl.H> (which you should include instead of the OpenGL +header <GL/gl.h>). -

      void gl_color(Fl_Color);

        +

        void gl_color(Fl_Color)

        -Set the current color to a fltk color index. For color-index modes -it will use fl_xpixel(c), which is only right if this window uses the -default X colormap. +Set the current color to a FLTK color index. For color-index modes +it will use fl_xpixel(c), which is only right if this window +uses the default colormap! -

      void gl_rect(int x,int y,int w,int h); -
      void gl_rectf(int x,int y,int w,int h);

        +

        void gl_rect(int x, int y, int w, int h)
        +void gl_rectf(int x, int y, int w, int h)

        -Outline or fill a rectangle with the current color. If ortho() has -been called, then the rectangle will exactly fill the pixel rectangle -passed. +Outline or fill a rectangle with the current color. If +ortho() has been called, then the rectangle will exactly fill +the pixel rectangle passed. -

      void gl_font(Fl_Font fontid, int size);

      int gl_height(); -
      int gl_descent(); -
      float gl_width(const char *); -
      float gl_width(const char *, int n); -
      float gl_width(uchar);

        +

        int gl_height()
        +int gl_descent()
        +float gl_width(const char *)
        +float gl_width(const char *, int n)
        +float gl_width(uchar)

        -Return information about the current GL font. +Return information about the current OpenGL font. -

      void gl_draw(const char *); -
      void gl_draw(const char *, int n);

        +

        void gl_draw(const char *)
        +void gl_draw(const char *, int n)

        -Draw a null-terminated string or an array of n characters in -the current GL font at the current glRasterPos. +Draw a nul-terminated string or an array of n characters in +the current OpenGL font at the current glRasterPos. -

      void gl_draw(const char *, int x, int y); -
      void gl_draw(const char *, int n, int x, int y);

        +

        void gl_draw(const char *, int x, int y)
        +void gl_draw(const char *, int n, int x, int y)
        +void gl_draw(const char *, float x, float y)
        +void gl_draw(const char *, int n, float x, float y)

        -Draw a null-terminated string or an array of n characters in -the current GL font at the given position. +Draw a nul-terminated string or an array of n characters in +the current OpenGL font at the given position. -

      void gl_draw(const char *, int x, int y, int w, int h, Fl_Align);

        +

        void gl_draw(const char *, int x, int y, int w, int h, Fl_Align)

        Draw a string formatted into a box, with newlines and tabs expanded, other control characters changed to ^X, and aligned with the edges or -center. Exactly the same output as fl_draw(). +center. Exactly the same output as fl_draw(). -
      -

      (back to contents) -Fltk example: shape.C -

      shape.C

      +

      Using OpenGL Optimizer with FLTK

      -

      Of course GL is no fun unless you can draw your own graphics. This -is done with a subclass that you create: +OpenGL Optimizer is +a scene graph toolkit for OpenGL available from Silicon Graphics for +IRIX and Microsoft Windows. Versions are in the works for Solaris and +HP-UX. It allows you to view large scenes without writing a lot of +OpenGL code. -

      +

      OptimizerWindow Class Definition

      -
      -#include <FL/Fl.H>
      -#include <FL/Fl_Window.H>
      -#include <FL/Fl_Hor_Slider.H>
      -#include <FL/math.h>
      -#include <FL/gl.h>
      -#include <FL/Fl_Gl_Window.H>
      +To use OpenGL Optimizer with FLTK you'll need to create a subclass of
      +Fl_Gl_Widget that includes several state variables:
      +
      +
        +class OptimizerWindow : public Fl_Gl_Window {
        +  csContext *context_; // Initialized to 0 and set by draw()...
        +  csDrawAction *draw_action_; // Draw action...
        +  csGroup *scene_; // Scene to draw...
        +  csCamara *camera_; // Viewport for scene...
         
        -class shape_window : public Fl_Gl_Window {
           void draw();
        +
         public:
        -  int sides;
        -  shape_window(int x,int y,int w,int h,const char *l=0);
        +  OptimizerWindow(int X, int Y, int W, int H, const char *L)
        +    : Fl_Gl_Window(X, Y, W, H, L) {
        +      context_ = (csContext *)0;
        +      draw_action_ = (csDrawAction *)0;
        +      scene_ = (csGroup *)0;
        +      camera_ = (csCamera *)0;
        +    }
        +
        +  void scene(csGroup *g) { scene_ = g; redraw(); }
        +
        +  void camera(csCamera *c) {
        +    camera_ = c;
        +    if (context_) {
        +      draw_action_->setCamera(camera_);
        +      camera_->draw(draw_action_);
        +      redraw();
        +    }
        +  }
         };
        +
       
      -shape_window::shape_window(int x,int y,int w,int h,const char *l) :
      -Fl_Gl_Window(x,y,w,h,l) {
      -  sides = 3;
      -}
      +

      The camera() Method

      + +The camera() method sets the camera (projection and viewpoint) +to use when drawing the scene. The scene is redrawn after this call. + +

      The draw() Method

      + +The draw() method performs the needed initialization +and does the actual drawing: + +
        +void OptimizerWindow::draw() {
        +  if (!context_) {
        +    // This is the first time we've been asked to draw; create the
        +    // Optimizer context for the scene...
        +
        +    context_ = new csContext(fl_display, fl_visual);
        +    context_->ref();
        +    context_->makeCurrent(fl_display, fl_window);
        +
        +    ... perform other context setup as desired ...    
        +
        +    // Then create the draw action to handle drawing things...
        +
        +    draw_action_ = new csDrawAction;
        +    if (camera_) {
        +      draw_action_->setCamera(camera_);
        +      camera_->draw(draw_action_);
        +    }
        +  }
         
        -void shape_window::draw() {
        -  // the valid() property may be used to avoid reinitializing your
        -  // GL transformation for each redraw:
           if (!valid()) {
        -    valid(1);
        -    glLoadIdentity();
        -    glViewport(0,0,w(),h());
        +    // Update the viewport for this context...
        +    context_->setViewport(0, 0, w(), h());
           }
        -  // draw an amazing graphic:
        -  glClear(GL_COLOR_BUFFER_BIT);
        -  glColor3f(.5,.6,.7);
        -  glBegin(GL_POLYGON);
        -  for (int i=0; i<sides; i++) {
        -    double ang = i*2*M_PI/sides;
        -    glVertex3f(cos(ang),sin(ang),0);
        -  }
        -  glEnd();
        +
        +  // Clear the window...
        +
        +  context_->clear(csContext::COLOR_CLEAR | csContext::DEPTH_CLEAR,
        +                  0.0f,		// Red
        +		  0.0f,		// Green
        +		  0.0f,		// Blue
        +		  1.0f);	// Alpha
        +
        +  // Then draw the scene (if any)...
        +
        +  if (scene_)
        +    draw_action_->apply(scene_);
         }
        +
      -// when you change the data, as in this callback, you must call redraw(): -void sides_cb(Fl_Widget *o, void *p) { - shape_window *sw = (shape_window *)p; - sw->sides = int(((Fl_Slider *)o)->value()); - sw->redraw(); -} +

      The scene() Method

      -int main(int argc, char **argv) { +The scene() method sets the scene to be drawn. The scene is +a collection of 3D objects in a csGroup. The scene is redrawn +after this call. - Fl_Window window(300, 330); - - shape_window sw(10, 10, 280, 280); - window.resizable(&sw); - - Fl_Hor_Slider slider(50, 295, window.w()-60, 30, "Sides:"); - slider.align(FL_ALIGN_LEFT); - slider.callback(sides_cb,&sw); - slider.value(sw.sides); - slider.step(1); - slider.bounds(3,40); - - window.show(argc,argv); - - return Fl::run(); -} -
      - -

      To do your own drawing, you must subclass Fl_Gl_Window. The virtual method draw() is called when the window should -update. You can only draw into the window inside a draw() method. -You call the method redraw() on the -window to indicate that draw() needs to be called. It won't actually -be called until Fl::wait() is called. - -

      The window may be made a child of another window, as it is here. -This is done by add()ing it to a parent before you show() it. If -you don't want to make a child window, be sure to end() the previous -window! The Fl_Gl_Window constructor automatically does end() so -you don't accidentally add children to it. - -

      The files <FL/math.h> and <FL/gl.h> are wrappers for the -normal header files. You should use them to port to MSWindows because -the MicroSoft header files have errors or ommisions in them. - -

      [back to contents] + + diff --git a/documentation/osissues.html b/documentation/osissues.html index f9cd36991..3e651511e 100644 --- a/documentation/osissues.html +++ b/documentation/osissues.html @@ -1,184 +1,171 @@ -

      F - Operating System Specific Issues

      F - Operating System Issues - - -Fltk X-specific interface -

      Fltk X-specific interface

      +This appendix describes the X and WIN32 specific interfaces in FLTK. -#include <FL/x.H> +

      X-Specific Interface

      -

      On Unix/X you can include this file to access fltk's X-specific -functions. Be warned that some of the structures and calls in it are -subject to change in future version of fltk. Try to avoid doing this -so your code is portable. +

        +#include <FL/x.H>
        +
      -


      +On X you can include this file to access FLTK's X-specific functions. +Be warned that some of the structures and calls in it are subject to +change in future version of FLTK. Try to avoid doing this so your code +is portable. -

      Handling other X events

      +

      Handling Other X Events

      - -

      void Fl::add_handler(int (*f)(int));

        +

        void Fl::add_handler(int (*f)(int))

        -Install a function to parse unrecognized events. If fltk cannot figure +Installs a function to parse unrecognized events. If FLTK cannot figure out what to do with an event, it calls each of these functions (most recent first) until one of them returns non-zero. If none of them -returns non zero then the event is ignored. +returns non-zero then the event is ignored. -

        Fltk calls this for any X events it does not recognize, or X events -with a window id that fltk does not recognize. You can look at the X -event with the fl_xevent. +

        FLTK calls this for any X events it does not recognize, or X events +with a window id that FLTK does not recognize. You can look at the X +event with the fl_xevent variable.

        The argument is zero for unrecognized X events. These handlers are also called for global shortcuts and some other events that the widget they were passed to did not handle. In this case the argument is -non-zero (for instance FL_SHORTCUT). +non-zero (for example FL_SHORTCUT). - -

      extern XEvent* fl_xvent;

      extern ulong fl_event_time;

        +

        extern ulong fl_event_time

        This is the time stamp from the most recent X event that reported it (not all do). Many X calls (like cut and paste) need this value. -

      Window fl_xid(const Fl_Window*);

      Fl_Window* fl_find(ulong xid);

        +

        Fl_Window *fl_find(ulong xid)

        -

        Return the Fl_Window that corresponds to the given xid, or -null if not found. This uses a cache so it is slightly faster than -iterating through the windows yourself. +Returns the Fl_Window that corresponds to the given XID, or +NULL if not found. This uses a cache so it is slightly faster +than iterating through the windows yourself. -

      int fl_handle(const XEvent&);

        +

        int fl_handle(const XEvent &)

        -This call allows you to supply the X events to fltk, which may allow -fltk to cooperate with another toolkit or library. The return value -is true if fltk understood the event (if the window does not belong to -fltk and the add_handler() functions all ignore it this returns +This call allows you to supply the X events to FLTK, which may allow +FLTK to cooperate with another toolkit or library. The return value +is true if FLTK understood the event (if the window does not belong to +FLTK and the add_handler() functions all ignore it this returns false).

        Besides feeding events your code should call Fl::flush() periodically so that fltk redraws -it's windows. +href="#flush">Fl::flush() periodically so that FLTK +redraws its windows.

        This function will call the callback functions. It will not return until they complete. In particular if a callback pops up a modal -window (by calling fl_ask(), for +window (by calling fl_ask(), for instance) it will not return until the modal function returns. -

      -


      +

      Drawing using Xlib

      - -

      Drawing using Xlib

      +The following global variables are set before +Fl_Widget::draw() is called, or by
      Fl_Window::make_current(): -

      -extern Display* fl_display;
      -extern Window fl_window;
      -extern GC fl_gc;
      -extern int fl_screen;
      -extern XVisualInfo* fl_visual;
      -extern Colormap fl_colormap;

        +
          +extern Display *fl_display;
          +extern Window fl_window;
          +extern GC fl_gc;
          +extern int fl_screen;
          +extern XVisualInfo *fl_visual;
          +extern Colormap fl_colormap;
          +
        -These global variables are set before Fl_Widget::draw() is called, or -by Fl_Window::make_current() 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, ...);

        +
          +XDrawSomething(fl_display, fl_window, fl_gc, ...);
          +
        -

        Other information such as the position or size of the X window can be +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. +href="#Fl_Window.make_current">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);

        - -Return the X pixel number used to draw the given rgb color. This is -the X pixel that fl_color(r,g,b) would use. - -

      extern XFontStruct* fl_xfont;

      +

      Changing the Display, Screen, or X Visual

      -


      +FLTK uses only a single display, screen, X visual, and X colormap. This +greatly simplifies its internal structure and makes it much smaller and +faster. You can change which it uses by setting global variables +before the first Fl_Window::show() is called. You may +also want to call Fl::visual(), which is a +portable interface to get a full color and/or double buffered visual. - -

      Changing the display, screen, or X visual

      - -

      Fltk uses only a single display, screen, X visual, and X colormap. -This greatly simplifies it's internal structure and makes it much -smaller and faster. You can change which it uses by setting global -variables before the first Fl_Window::show() is called. -You may also want to call Fl::visual(int), which is a portable interface -to get a full color and/or double buffered visual. - -

      int Fl::display(const char *)

        +

        int Fl::display(const char *)

        Set which X display to use. This actually does -setenv("DISPLAY", x) 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 on MSWindows, but -it just sets the environment variable and has no other effect. +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 WIN32 but +it has no effect. -

      extern Display* fl_display;

        +

        extern Display *fl_display

        The open X display. This is needed as an argument to most Xlib calls. -Don't attempt to change it! This is zero before the display is opened. +Don't attempt to change it! This is NULL before the display is opened. -

      void fl_open_display();

        +

        void fl_open_display()

        -Open the display. Does nothing if it is already open. This will make -sure fl_display is non-zero. You should call this if you +Opens the display. Does nothing if it is already open. This will make +sure 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. +before the first show() of a window. -

        This may call Fl::abort() if there is an error opening the display. +

        This may call Fl::abort() if there is an error opening the display. -

      void fl_close_display();

        +

        void fl_close_display()

        This closes the X connection. You do not need to call this to exit, and in fact it is faster to not do so! It may be useful to call this if you want your program to continue without the X connection. -You cannot open the display again, and probably cannot call any fltk +You cannot open the display again, and probably cannot call any FLTK functions. -

      extern int fl_screen;

        +

        extern int fl_screen

        -Which screen to use. This is set by 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: host:0,#. +Which screen number to use. This is set by 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,#". -

      extern XVisualInfo* fl_visual;
      -extern Colormap fl_colormap;

        +

        extern XVisualInfo *fl_visual
        +extern Colormap fl_colormap

        -

        The visual and colormap that fltk will use for all windows. These -are set by 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: +The visual and colormap that FLTK will use for all windows. These +are set by 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);
            @@ -186,50 +173,32 @@ 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);
            -
          +
        -
      +

      Using a Subclass of Fl_Window for Special X Stuff

      -


      - -

      Using a subclass of Fl_Window for special X stuff

      +FLTK can manage an X window on a different screen, visual and/or +colormap, you just can't use FLTK's drawing routines to draw into it. +But you can write your own draw() method that uses Xlib +(and/or OpenGL) calls only. -Fltk can manage an X window on a different screen, visual and/or -colormap, you just can't use fltk's drawing routines to draw into it. -But you can write your own draw() method that uses Xlib calls only. - -

      Fltk can also manage xid's provided by other libraries or programs, +

      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 +href="#Fl_Window">Fl_Window and override some of these virtual functions: -

      virtual void Fl_Window::show()

        +

        virtual void Fl_Window::show()

        -

        If the window is already 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(): +If the window is already 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(). -

        Fl_X* Fl_X::set_xid(Fl_Window*, Window xid);

          +

          An example: -Allocate a hidden structure called an Fl_X, put the xid into it, and -set a pointer to it from the Fl_Window. This causes -Fl_Window::shown() to return true. - -

        void Fl_X::make_xid(Fl_Window*, XVisualInfo* = -fl_visual, Colormap = fl_colormap);

          - -This static method does the most onerous parts of creating an X window, -including setting the label, resize limitations, etc. It then does -set_xid with this new window and maps the window. - -
        - -

        Example: - -

        +
           void MyWindow::show() {
             if (shown()) {Fl_Window::show(); return;}  // you must do this!
             fl_open_display();	// necessary if this is first window
          @@ -243,47 +212,60 @@ void MyWindow::show() {
             }
             Fl_X::make_xid(this, visual, colormap);
           }
          -
          +
      -

      virtual void Fl_Window::flush()

        +

        Fl_X *Fl_X::set_xid(Fl_Window *, Window xid)

        -This virtual function is called by Fl::flush() to update the window. -For fltk's own windows it does this by setting the global variables -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. +Allocate a hidden structure called an Fl_X, put the XID into it, and +set a pointer to it from the Fl_Window. This causes +Fl_Window::shown() to return true. -

        The X region that is a combination of all 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 fl clip stack -with a region or null for no clipping. You must set region to null -afterwards as fl_clip_region() now owns it and will delete it when -done. +

        void Fl_X::make_xid(Fl_Window *, XVisualInfo *= fl_visual, Colormap = fl_colormap)

        -

        If damage()==2 then only X expose events have -happened. This may be useful if you have an undamaged image (such as -a backing buffer) around. +This static method does the most onerous parts of creating an X window, +including setting the label, resize limitations, etc. It then does +Fl_X::set_xid() with this new window and maps the window. + +

        virtual void Fl_Window::flush()

        + +This virtual function is called by Fl::flush() to update the +window. For FLTK's own windows it does this by setting the global +variables 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. + +

        The X region that is a combination of all 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() now owns it and +will delete it when done. + +

        If 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.

        Here is a sample where an undamaged image is kept somewhere: -

        +
           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 ...
           }
          -
          +
      -

      virtual void Fl_Window::hide()

        +

        virtual void Fl_Window::hide()

        -Destroy the window server copy of the window. Usually you will -destroy contexts, pixmaps, or other resources used by the window, and -then call Fl_Window::hide() to get rid of the main window identified -by xid(). If you override this, you must also override the destructor -as shown: +Destroy the window server copy of the window. Usually you will destroy +contexts, pixmaps, or other resources used by the window, and then call +Fl_Window::hide() to get rid of the main window identified by +xid(). If you override this, you must also override the +destructor as shown: -
        +
           void MyWindow::hide() {
             if (mypixmap) {
               XFreePixmap(fl_display,mypixmap);
          @@ -291,165 +273,183 @@ void MyWindow::hide() {
             }
             Fl_Window::hide(); // you must call this
           }
          -
          +
      -

      virtual void Fl_Window::~Fl_Window()

        +

        virtual void Fl_Window::~Fl_Window()

        -Because of the way C++ works, if you override hide() you must -override the destructor as well (otherwise only the base class hide() +Because of the way C++ works, if you override hide() you must +override the destructor as well (otherwise only the base class hide() is called): -
        +
           MyWindow::~MyWindow() {
             hide();
           }
          -
          +
      - +

      Setting the Icon of a Window

      -

      (back to contents) -Fltk MSWindows-specific interface -

      #include <FL/x.H>
      -Fltk MSWindows-specific interface

      +FLTK currently supports setting a window's icon *before* it is shown using +the Fl_Window::icon() method. -The <FL/x.H> header file defines the interface to fltk's -MSWindows-specific functions. Be warned that some of the structures -and calls in it are subject to change in future version of fltk. Try +

      void Fl_Window::icon(char *)

      + +Sets the icon for the window to the passed pointer. You will need to +cast the icon Pixmap to a char * when calling this +method. To set the icon using a bitmap compiled with your application +use: + +
        +#include "icon.xbm"
        +
        +Pixmap p = XCreatePixmapFromBitmapData(fl_display,
        +               DefaultRootWindow(fl_display), icon_bits,
        +	       icon_width, icon_height,
        +	       BlackPixel(fl_display, DefaultScreen(fl_display)),
        +	       WhitePixel(fl_display, DefaultScreen(fl_display)),
        +	       DefaultDepth(fl_display, DefaultScreen(fl_display)))
        +
        +window->icon((char *)p);
        +
      + +

      WIN32-Specific Interface

      + +
        +#include <FL/x.H>
        +
      + +The <FL/x.H> header file defines the interface to FLTK's +WIN32-specific functions. Be warned that some of the structures +and calls in it are subject to change in future version of FLTK. Try to avoid doing this so your code is portable. -


      +

      Handling Other WIN32 Messages

      -

      Handling other MSWindows messages

      +By default a single WNDCLASSEX called "FLTK" is created. All +Fl_Windows are of this class unless you use +Fl_Window::xclass(). The window class is created the first +time Fl_Window::show() is called. -

      A single WNDCLASSEX called "FLTK" is created. All -Fl_Windows are of this class. This window class is created the first -time Fl_Window::show() is called. - -

      You can probably combine fltk with other libraries that make their -own MSWindows window classes. The easiest way is to call Fl::wait(), it -will call DispatchMessage for all messages to the other windows. If +

      You can probably combine FLTK with other libraries that make their +own WIN32 window classes. The easiest way is to call Fl::wait(), 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 regularily (otherwise widgets will not -update), and timeouts and the idle function will not work. +DispatchMessage()), but you will have to arrange for the function +Fl::flush() to be called regularily so that widgets are updated, +timeouts are handled, and the idle functions are called. - -

      extern MSG fl_msg;

        +

        extern MSG fl_msg

        -The most recent message read by GetMessage (which is called by -Fl::wait(). This may not be the most recent -message sent to an fltk window, because silly MSWindows calls the +The most recent message read by 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). - -

      void Fl::add_handler(int (*f)(int));

        +

        void Fl::add_handler(int (*f)(int))

        -Install a function to parse unrecognized messages sent to fltk -windows. If fltk cannot figure out what to do with a message, it +Install a function to parse unrecognized messages sent to FLTK +windows. If FLTK cannot figure out what to do with a message, it calls each of these functions (most recent first) until one of them returns non-zero. The argument passed to the fuctions is zero. If -all the handlers return zero then fltk calls DefWindowProc(...). +all the handlers return zero then FLTK calls DefWindowProc(). -

      HWND fl_xid(const Fl_Window*);

        +

        HWND fl_xid(const Fl_Window *)

        -Returns the window handle for a Fl_Window, or zero if not shown(). +Returns the window handle for a Fl_Window, or zero if not +shown(). -

      Fl_Window* fl_find(HWND xid)

        +

        Fl_Window *fl_find(HWND xid)

        -

        Return the Fl_Window that corresponds to the given window handle, -or null if not found. This uses a cache so it is slightly faster than -iterating through the windows yourself. +Return the Fl_Window that corresponds to the given window +handle, or NULL if not found. This uses a cache so it is +slightly faster than iterating through the windows yourself. -

      +

      Drawing Things Using the WIN32 GDI

      -


      - - -

      Drawing things using the MSWindows GDI

      - -

      When the virtual function Fl_Widget::draw() is called, fltk has +When the virtual function Fl_Widget::draw() is called, FLTK has stashed in some global variables all the silly extra arguments you need to make a proper GDI call. These are: -

      -extern HINSTANCE fl_display;
      -extern HWND fl_window;
      -extern HDC fl_gc;
      -COLORREF fl_RGB();
      -HPEN fl_pen();
      -HBRUSH fl_brush();

      -


      -

      How to not get a MSDOS console window

      +

      Setting the Icon of a Window

      -MSWindows has a really stupid mode switch stored in the executables that -controls whether or not to make a console window (hint to Mr Gates: -why not leave it hidden until the program prints something?). +FLTK currently supports setting a window's icon *before* it is shown using +the Fl_Window::icon() method. -

      To not produce a "console" window when you run your program add the -following secret incantation to the Micro$oft linker: +

      void Fl_Window::icon(char *)

      -

              /SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup
      +Sets the icon for the window to the passed pointer. You will need to +cast the HICON handle to a char * when calling this +method. To set the icon using an icon resource compiled with your +application use: -

      Unfortunately this seems to completely disable stdin/stdout, even -if you run the program from a console. So don't do this until you -have debugged your program! +

        +window->icon((char *)LoadIcon(fl_display, MAKEINTRESOURCE(IDI_ICON)));
        +
      -


      -

      Other hints

      +

      How to Not Get a MSDOS Console Window

      -

      I use capital C as the extension for c++ source code, for instace -for Fluid output. Unfortunately there is no way to convince VC++ to -use this except to tell it to compile *everything* using C++ by -putting the switch "/TP" in the options. This makes it impossible to -combine old C code and fltk code. +WIN32 has a really stupid mode switch stored in the executables that +controls whether or not to make a console window. -


      -

      Known bugs

      +

      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). -

      If program is deactivated, 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. I was 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 MSWindows and probably -impossible to get around. +

      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. -

      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. +

      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. + +

      Known Bugs

      + +If a program is deactivated, 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. I was 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.

      Cut text contains ^J rather than ^M^J to break lines. This is a feature, not a bug. -

      I can't seem to get SetCapture (used by Fl::grab()) to work, and I -can't find a way to stop the main window title from turning gray while -menus are popped up. - -

      glpuzzle program does not animate unless you resize it first. Unknown why. - -

      Fl_Window::fullscreen() not implemented (should take over the screen -without a title bar). Currently does maximize instead. - -

      Import .bmp files into fluid. Wonko has the specs. - -

      Can't set icon of windows. - - +

      SetCapture (used by Fl::grab()) doesn't work, and +the main window title bar turns gray while menus are popped up. +

      FLUID does not support BMP files yet. + + diff --git a/documentation/preface.html b/documentation/preface.html index 5be3d0f99..61e06de5f 100644 --- a/documentation/preface.html +++ b/documentation/preface.html @@ -1,7 +1,7 @@ - + FLTK 1.0 Programming Manual @@ -23,15 +23,18 @@ This manual is organized into the following chapters and appendices:

    • Chapter 2 - FLTK Basics
    • Chapter 3 - Common Widgets and Attributes
    • Chapter 4 - Designing a Simple Text Editor -
    • Chapter 5 - Extending and Adding Widgets -
    • Chapter 6 - Programming With FLUID -
    • Chapter 7 - Using OpenGL +
    • Chapter 5 - Drawing Things in FLTK +
    • Chapter 6 - Handling Events +
    • Chapter 7 - Extending and Adding Widgets +
    • Chapter 8 - Programming With FLUID +
    • Chapter 9 - Using OpenGL
    • Appendix A - Widget Reference
    • Appendix B - Function Reference
    • Appendix C - Enumeration Reference
    • Appendix D - GLUT Compatibility
    • Appendix E - Forms Compatibility -
    • Appendix F - Software License +
    • Appendix F - Operating System Issues +
    • Appendix G - Software License

      Conventions

      @@ -63,7 +66,7 @@ The following abbreviations are used in this manual:

      Copyrights and Trademarks

      -FLTK is Copyright 1998 by Bill Spitzak and others. Use and distribution of FLTK is +FLTK is Copyright 1998-1999 by Bill Spitzak and others. Use and distribution of FLTK is governed by the GNU Library General Public License, located in Appendix D. diff --git a/documentation/subclassing.html b/documentation/subclassing.html index 414cca67b..7ed03ed7a 100644 --- a/documentation/subclassing.html +++ b/documentation/subclassing.html @@ -1,427 +1,338 @@ -

      5 - Adding and Extending Widgets

      +

      7 - Adding and Extending Widgets

      -This chapter describes how to add your own widgets or extend existing widgets in FLTK. +This chapter describes how to add your own widgets or extend existing +widgets in FLTK.

      Subclassing

      -

      Adding Syntax Highlighting to the Fl_Input Widget

      +New widgets are created by subclassing an existing FLTK widget, +typically Fl_Widget for controls and Fl_Group for +containers. -

      Drawing Functions

      +

      A control widget typically interacts with the user to receive and/or +display a value of some sort. -

      Lines, Rectangles, and Curves, Oh, My!

      +

      A container widget holds a list of child widgets and handles moving, +sizing, showing, or hiding them as needed. Fl_Group is the +main container widget class in FLTK, and all of the other containers +(Fl_Pack, Fl_Scroll, Fl_Tabs, Fl_Tile, +and Fl_Window) are subclasses of it. -

      Colors

      +

      You can also subclass other existing widgets to provide a different look +or user-interface. For example, the button widgets are all subclasses of +Fl_Button since they all interact with the user via a mouse button +click. The only difference is the code that draws the face of the button. -

      Fonts

      +

      Making a Subclass of Fl_Widget

      -

      Images

      +Your subclasses can directly descend from Fl_Widget or any +subclass of Fl_Widget. Fl_Widget has only four +virtual methods, and overriding some or all of these may be necessary. -

      Writing a Table Widget

      +

      The Constructor

      -

      Methods

      +The constructor should access the following arguments: -

      Cut and Paste Support

      +
        +MyClass(int x, int y, int w, int h, const char *label = 0);
        +
      - - -Cut & paste -

      Cut & paste

      - -Fltk provides routines to cut and paste ASCII text (in the future this -may be UTF-8) between applications. It may be possible to cut/paste -non-ascii data under X by using Fl::add_handler(). - -

      void Fl::paste(Fl_Widget *receiver)

        - -

        Set things up so the receiver widget will be called with an FL_PASTE event some time in the future. -The reciever should be prepared to be called directly by this, -or for it to happen later, or possibly not at all. This -allows the window system to take as long as necessary to retrieve the -paste buffer (or even to screw up completely) without complex and -error-prone synchronization code in fltk. - -

      void Fl::selection(Fl_Widget *owner, const char *stuff, int len); -

        - -

        Change the current selection. The block of text is copied to an -internal buffer by Fltk (be careful if doing this in response to an -FL_PASTE as this may be the same buffer returned by -event_text()). The selection_owner is set to the passed owner -(possibly sending FL_SELECTIONCLEAR to the previous owner). - -

      const char* Fl::selection(); -
      int Fl::selection_length();

        - -You can look at the buffer containing the current selection. Contents -of this buffer are undefined if this program does not own the X -selection. - -

      Fl_Widget *Fl::selection_owner() const; -
      void Fl::selection_owner(Fl_Widget *);

        - -

        The single-argument selection_owner(x) call can be used to move the -selection to another widget or to set the owner to NULL, without -changing the actual text of the selection. FL_SELECTIONCLEAR is sent -to the old selection owner, if any. - -

      - -

      Copying the buffer every time the selection is changed is -obviously wasteful, especially for large selections. I expect an -interface will be added in a future version to allow the selection to -be made by a callback function. The current interface will be -emulated on top of this. - -Making a subclass of Fl_Widget -

      Making a subclass of Fl_Widget

      - -

      Your subclasses can directly descend from Fl_Widget or any -subclass of Fl_Widget. Fl_Widget has only four virtual methods, and -overriding some or all of these may be necessary. - -

      Parts of this document: - -

      - - -

      Constructing your Fl_Widget

      - -I recommend your constructor be of this form: - -

      -    Class(int x, int y, int w, int h, const char* label = 0);
      -
      - -

      This will allow the class name to be typed into fluid and it will produce the correct call. +This will allow the class to be used in Fluid without +problems.

      The constructor must call the constructor for the base class and -pass the same arguments. Fl_Widget's protected constructor sets x(), -y(), w(), h(), and label() to the passed values and initializes the -other instance variables to: +pass the same arguments: -

      -    type(0);
      -    box(FL_NO_BOX);
      -    color(FL_GRAY);
      -    selection_color(FL_GRAY);
      -    labeltype(FL_NORMAL_LABEL);
      -    labelstyle(FL_NORMAL_STYLE);
      -    labelsize(FL_NORMAL_SIZE);
      -    labelcolor(FL_BLACK);
      -    align(FL_ALIGN_CENTER);
      -    callback(default_callback,0);
      -    flags(ACTIVE|VISIBLE);
      -
      +
        +MyClass::MyClass(int x, int y, int w, int h, const char *label)
        +: Fl_Widget(x, y, w, h, label) {
        +// do initialization stuff...
        +}
        +
      - -

      Protected methods of Fl_Widget

      +Fl_Widget's protected constructor sets x(), +y(), w(), h(), and label() to the +passed values and initializes the other instance variables to: -

      These methods are provided for subclasses to use. +

        +type(0);
        +box(FL_NO_BOX);
        +color(FL_GRAY);
        +selection_color(FL_GRAY);
        +labeltype(FL_NORMAL_LABEL);
        +labelstyle(FL_NORMAL_STYLE);
        +labelsize(FL_NORMAL_SIZE);
        +labelcolor(FL_BLACK);
        +align(FL_ALIGN_CENTER);
        +callback(default_callback,0);
        +flags(ACTIVE|VISIBLE);
        +
      -

      uchar Fl_Widget::type() const; -
      void Fl_Widget::type(uchar); -

      void Fl_Widget::set_flag(SHORTCUT_LABEL);

      int Fl_Widget::test_shortcut() const;
      -static int Fl_Widget::test_shortcut(const char *);

      void Fl_Widget::x(short); -
      void Fl_Widget::y(short); -
      void Fl_Widget::w(short); -
      void Fl_Widget::h(short);

      void Fl_Widget::damage(uchar mask);

      void Fl_Widget::damage(uchar mask,int x,int y,int w,int -h);

      void Fl_Widget::clear_damage(uchar value = 0);

      uchar Fl_Widget::damage()

      void Fl_Widget::set_visible(); -
      void Fl_Widget::clear_visible();

      void Fl_Widget::draw_box() const ;

      void Fl_Widget::draw_box(Fl_Boxtype b,ulong c) const -;

      void Fl_Widget::draw_label() const ;

      void Fl_Widget::draw_label(int x,int y,int w,int h) const -;

      void Fl_Widget::draw_label(int x,int y,int w,int -h,Fl_Align align) const ;

        +

        void Fl_Widget::set_flag(SHORTCUT_LABEL)

        -Draw the label anywhere. It acts as though FL_ALIGN_INSIDE has been -forced on, the label will appear inside the passed bounding box. This -is designed for parent groups to draw labels with. +If your constructor calls this it modifies draw_label() so +that '&' characters cause an underscore to be printed under the next +letter. -
      - -

      virtual int Fl_Widget::handle()

      +

      void Fl_Widget::set_visible()
      +void Fl_Widget::clear_visible()

      -The virtual method int Fl_Widget::handle(int -event) is called to handle each event passed to the widget. -It can:
        +Fast inline versions of Fl_Widget::hide() and +Fl_Widget::show(). These do not send the FL_HIDE and +FL_SHOW events to the widget. -
      • Change the state of the widget. +

        int Fl_Widget::test_shortcut() const
        +static int Fl_Widget::test_shortcut(const char *s)

        -
      • Call Fl_Widget::redraw() if the widget -needs to be redisplayed. +The first version tests Fl_Widget::label() against the current +event (which should be a FL_SHORTCUT event). If the label +contains a '&' character and the character after it matches the key +press, this returns true. This returns false if the +SHORTCUT_LABEL flag is off, if the label is NULL or +does not have a '&' character in it, or if the keypress does not match +the character. -
      • Call Fl_Widget::damage(n) if the widget needs -a partial-update (assumming you provide support for this in your -Fl_Widget::draw() method). +

        The second version lets you do this test against an arbitrary string. -

      • Call Fl_Widget::do_callback() if a -callback should be generated. +

        uchar Fl_Widget::type() const
        +void Fl_Widget::type(uchar t)

        -
      • Call Fl_Widget::handle() on child widgets. +The property Fl_Widget::type() can return an arbitrary 8-bit +identifier, and can be set with the protected method type(uchar t). +This value had to be provided for Forms compatibility, but you can use +it for any purpose you want. Try to keep the value less than 100 to +not interfere with reserved values. +

        FLTK does not use RTTI (Run Time Typing Infomation), to enhance +portability. But this may change in the near future if RTTI becomes +standard everywhere. + +

        If you don't have RTTI you can use the clumsy FLTK mechanisim, by +having type() have a unique value. These unique values must +be greater than the symbol FL_RESERVED_TYPE (which is 100). +Look through the header files for FL_RESERVED_TYPE to find an +unused number. If you make a subclass of Fl_Group you must +use FL_GROUP + n, and if you make a subclass of +Fl_Window you must use FL_WINDOW + n (in both cases +n is in the range 1 to 7). + +

        Handling Events

        + +The virtual method int Fl_Widget::handle(int event) is called +to handle each event passed to the widget. It can: + +
          +
        • Change the state of the widget. + +
        • Call Fl_Widget::redraw() + if the widget needs to be redisplayed. + +
        • Call Fl_Widget::damage(n) if + the widget needs a partial-update (assumming you provide + support for this in your Fl_Widget::draw() method). + +
        • Call Fl_Widget::do_callback() + if a callback should be generated. + +
        • Call Fl_Widget::handle() on child widgets.
        -

        Events are identified the small integer argument. Other -information about the most recent event is stored in static locations -and aquired by calling Fl::event_*(). -This other information remains valid until another event is read from -the X server. +Events are identified by the integer argument. Other information about +the most recent event is stored in static locations and aquired by +calling the Fl::event_*() functions. +This information remains valid until another event is handled. -

        Here is a sample Fl_Widget::handle(), for a widget that acts as a +

        Here is a sample handle() method for a widget that acts as a pushbutton and also accepts the keystroke 'x' to cause the callback: -