When can you draw things in FL?

There are only certain places you can execute drawing code in Fl. Calling these functions at other places will result in undefined behavior!

Drawing using X
#include <FL/x.H>

On X systems you can draw using any Xlib calls. Xlib requires a bunch of silly extra arguments, and FL gives you values for all of these in static variables declared in <FL/x.H>:

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

unsigned long fl_xpixel(uchar i);

unsigned long fl_xpixel(uchar r, uchar g, uchar b);

Drawing using OpenGL
#include <FL/gl_draw.H>

It may be possible to use OpenGL to draw normal objects (also see Fl_Gl_Window). This lets you use Gourand shading and other useful functions to make cool looking widgets. It's apparent the designers and implementors of the glX extension did not consider this possibility, but it works with some limitations: you must choose a default visual with Fl::gl_visual(), you cannot use double buffered gl contexts, and you cannot use Fl_Double_Window (or Fl_Overlay_Window).

void gl_start();
void gl_finish();

Portable drawing functions
#include <FL/fl_draw.H>

The plan is to reproduce the following functions on machines that do not use X:

Colors

void fl_color(uchar);

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

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

Clipping

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

void fl_pop_clip();

extern struct Fl_Clip {short x,y,r,b;} fl_current_clip;
extern int fl_clipped;

Fixed-size drawing code

These functions are used to draw almost all the FL objects. They draw on exact pixel boundaries and are as fast as possible. Do not call these between fl_push_matrix() and fl_pop_matrix(), or after fl_rotate(), fl_scale(), or fl_translate(), as the results are undefined.

FL considers integer positions to be at the corners of pixels, and a 1-pixel thick line fills in the pixel below and to the right of the mathematical line.

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

void fl_line(int x,int y,int x1,int y1,...);

void fl_loop(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,...);

void fl_xyline(int x,int y,int x1(,y1,x2...));

void fl_yxline(int x,int y,int y1(,x2,y3...));

Scalable drawing code

These functions let you draw arbitrary shapes with simple transformations. The exact pixels filled in is less defined than for the above calls, so that FL can take advantage of drawing hardware. X unfortunately rounds 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.

void fl_push_matrix();
void fl_pop_matrix();

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

void fl_begin_line();

void fl_begin_loop();

void fl_begin_polygon();

void fl_vertex(float x,float y);
void fl_vertex(const float* p);

void fl_arc(float x,float y,float w,float h,int start,int end);
void fl_arc(float x,float y,float r,int start,int end);
void fl_circle(float x,float y,float w,float h);
void fl_circle(float x,float y,float r);

void fl_end();

float fl_transform_x(float x,float y);
float fl_transform_y(float x,float y);
void fl_transformed_vertex(float x,float y);

Fonts

void fl_font(uchar fontid, int size);

int fl_height();

int fl_descent();

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

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, uchar align, uchar c);

const char* fl_shortcut_label(const char*);

const char* Fl::get_font(uchar fontid);

uchar Fl::set_font(uchar fontid, const char*);

uchar Fl::set_font(uchar fontid, uchar from);

uchar Fl::set_font(const char*);

void Fl::font_enumerate(void (*cb)(const char*, const int*, int));

Bitmaps, Pixmaps and Images

To draw images, you can either do it directly from data in your memory, or you can create an "Fl_Pixmap" or similar object from the data. 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 FL will cache transated forms of the image (on X it uses a server pixmap) and thus redrawing it is much faster.

There currently is no fl_draw_bitmap() function. Probably it will be added.

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

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

int fl_draw_pixmap(char** data, int x, int y, uchar bg=FL_GRAY);

int fl_pixmap_size(char** data, int &w, int &h);

void fl_draw(Fl_Bitmap* b,int x,int y,int w,int h);
void fl_draw(Fl_Pixmap* b,int x,int y,int w,int h);
void fl_draw(Fl_Image* b,int x,int y,int w,int h);

Cursor

void fl_cursor(uchar, uchar bg=FL_WHITE, uchar fg=FL_BLACK);

Selection rectangle

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

(back to contents)