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 behavior!

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


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

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_pop_clip();

int fl_not_clipped(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);


Colors

void fl_color(Fl_Color);

Fl_Color fl_color();

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


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

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

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

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

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

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

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_yxline(x, y, y1);
void fl_yxline(x, y, y1, x2);
void fl_yxline(x, y, y1, x2, y3);

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


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();

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_begin_line();
void fl_end_line();

void fl_begin_loop();
void fl_end_loop();

void fl_begin_polygon();
void fl_end_polygon();

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

void fl_vertex(x, y);

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

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

void fl_circle(x, y, r);


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

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

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

int fl_height();

int fl_descent();

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

const char* fl_shortcut_label(ulong);


Fonts

void fl_font(int face, int size);

int fl_font();
int fl_size();

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

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

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

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

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

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


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


Overlay rectangle

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

(back to contents)