FLTK 1.4.5: Cairo Support Functions and Classes

FLTK 1.4.5

Loading...
Searching...
No Matches
Cairo Support Functions and Classes

## Classes
class | Fl_Cairo_State
| Contains all the necessary info on the current cairo context. More...
class | Fl_Cairo_Window
| This defines an FLTK window with Cairo support. More...

## Functions
static bool | Fl::cairo_autolink_context ()
| Gets the current autolink mode for Cairo support.
static void | Fl::cairo_autolink_context (bool alink)
| When FLTK_HAVE_CAIRO is defined and cairo_autolink_context() is true, any current window dc is linked to a current Cairo context.
static cairo_t * | Fl::cairo_cc ()
| Gets the current Cairo context linked with a fltk window.
static void | Fl::cairo_cc (cairo_t *c, bool own=false)
| Sets the current Cairo context to `c`.
static void | Fl::cairo_flush (cairo_t *c)
| Flush Cairo drawings on Cairo context `c`.
static cairo_t * | Fl::cairo_make_current (Fl_Window *w)
| Provides a Cairo context for window wi.

## Detailed Description

## Function Documentation

## ◆ cairo_autolink_context() [1/2]

bool Fl::cairo_autolink_context | ( |  | ) |
| inlinestatic

Gets the current autolink mode for Cairo support.

Return values

  false | if no Cairo context autolink is made for each window.
  true | if any fltk window is attached a Cairo context when it is current.

See also
  void cairo_autolink_context(bool alink)

Note
  Only available when configure has the –enable-cairo option

## ◆ cairo_autolink_context() [2/2]

void Fl::cairo_autolink_context | ( | bool | alink | ) |
| inlinestatic

When FLTK_HAVE_CAIRO is defined and cairo_autolink_context() is true, any current window dc is linked to a current Cairo context.

This is not the default, because it may not be necessary to add Cairo support to all fltk supported windows. When you wish to associate a Cairo context in this mode, you need to call explicitly in your draw() overridden method, Fl::cairo_make_current(Fl_Window*). This will create a Cairo context only for this Window. Still in custom Cairo application it is possible to handle completely this process automatically by setting `alink` to true. In this last case, you don't need anymore to call Fl::cairo_make_current(). You can use Fl::cairo_cc() to get the current Cairo context anytime.

Note
  Only available when configure has the –enable-cairo option

## ◆ cairo_cc()

void Fl::cairo_cc | ( | cairo_t * | c,
|  | bool | own = false )
| inlinestatic

Sets the current Cairo context to `c`.

Set `own` to true if you want fltk to handle this cc deletion.

Note
  Only available when configure has the –enable-Cairo option

## ◆ cairo_flush()

void Fl::cairo_flush | ( | cairo_t * | c | ) |
| inlinestatic

Flush Cairo drawings on Cairo context `c`.

This is required on Windows if you use the Cairo context provided by the "Cairo autolink" option. Call this when all your drawings on the Cairo context are finished. This is maybe not necessary on other platforms than Windows but it does no harm if you call it always.

You don't need to use this if you use an Fl_Cairo_Window which does this automatically after the draw callback returns.

Code example for "Cairo autolink" mode:

In the overridden draw() method of your subclass of Fl_Window or any widget:

cairo_t *cc = Fl::cairo_cc(); // get the "autolink" Cairo context
// ... your Cairo drawings are here ...
Fl::cairo_flush(cc); // flush Cairo drawings to the device
Fl::cairo_cc
static cairo_t * cairo_cc()
Gets the current Cairo context linked with a fltk window.
Definition Fl.H:1470
Fl::cairo_flush
static void cairo_flush(cairo_t *c)
Flush Cairo drawings on Cairo context c.
Definition Fl.H:1515

If you configure FLTK with `'--enable-cairo'` or CMake option `'FLTK_OPTION_CAIRO_WINDOW'` (i.e. without `'--enable-cairoext'` or CMake option `'FLTK_OPTION_CAIRO_EXT'`) or if you don't enable the `'autolink'` Cairo context you may do the equivalent to use Cairo drawings in an overridden draw() method of derived classes by using

// get the Cairo context for the \c window
cairo_t *cc = Fl::cairo_make_current(window);
// ... your Cairo drawings are here ...
Fl::cairo_flush(cc); // flush Cairo drawings to the device
Fl::cairo_make_current
static cairo_t * cairo_make_current(Fl_Window *w)
Provides a Cairo context for window wi.
Definition Fl_Cairo.cxx:100

See also
  Fl::cairo_autolink_context(bool)
  Fl::cairo_make_current(Fl_Window*);

## ◆ cairo_make_current()

cairo_t * Fl::cairo_make_current | ( | Fl_Window * | wi | ) |
| static

Provides a Cairo context for window wi.

This is needed in a draw() override if Fl::cairo_autolink_context() returns false, which is the default. The cairo_context() does not need to be freed as it is freed every time a new Cairo context is created. When the program terminates, a call to Fl::cairo_make_current(0) will destroy any residual context.

Note
  A new Cairo context is not always re-created when this method is used. In particular, if the current graphical context and the current window didn't change between two calls, the previous gc is internally kept, thus optimizing the drawing performances. Also, after this call, Fl::cairo_cc() is adequately updated with this Cairo context.
  Only available when configure has the –enable-cairo option

Returns
  The valid cairo_t *cairo context associated to this window.

Return values

  NULL | if wi is NULL or maybe with GL windows under Wayland