[Cairo] Remove part of the dependency of FL/Fl.H on config.h.

To use Fl_Cairo_Window one ddi not only need to configure with --enable-cairo,
but also needed to #include <config.h> before #include <FL/Fl.H>.

This commit removes the smaller part of the dependency of the public header
file FL/Fl.H on config.h. This needs a better solution in FLTK 1.4.0.

The user still needs to define FLTK_HAVE_CAIRO _before_ #include <FL/Fl.H>.

Note: This is not compatible with fluid, since fluid _always_ includes
FL/Fl.H as the first statement in generated header files.

See also the discussion in fltk.general:

https://groups.google.com/d/msg/fltkgeneral/_C1OJhMLQl0/pHUFtz9SCwAJ



git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@11167 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Albrecht Schlosser 2016-02-13 17:35:36 +00:00
parent 1e2118d20f
commit 0462cae6d1
3 changed files with 44 additions and 29 deletions

View File

@ -3,7 +3,7 @@
//
// Main header file for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2010 by Bill Spitzak and others.
// Copyright 1998-2016 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@ -1261,19 +1261,19 @@ int main() {
static int use_high_res_GL() { return use_high_res_GL_; }
#ifdef FLTK_HAVE_CAIRO
/** \defgroup group_cairo Cairo support functions and classes
/** \defgroup group_cairo Cairo Support Functions and Classes
@{
*/
public:
// Cairo support API
static cairo_t * cairo_make_current(Fl_Window* w);
/** when FLTK_HAVE_CAIRO is defined and cairo_autolink_context() is true,
any current window dc is linked to a current context.
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
Fl::cairo_make_current(Fl_Window*). This will create a cairo context
but only for this Window.
Still in custom cairo application it is possible to handle
completely this process automatically by setting \p alink to true.

View File

@ -29,15 +29,7 @@
# include <FL/Fl_Export.H>
# if defined(USE_X11) // X11
# include <cairo-xlib.h>
# elif defined(WIN32)
# include <cairo-win32.h>
# elif defined(__APPLE_QUARTZ__)
# include <cairo-quartz.h>
# else
# error Cairo is not supported on that platform.
# endif
# include <cairo.h>
/**
\addtogroup group_cairo
@ -58,7 +50,14 @@ public:
// access attributes
cairo_t* cc() const {return cc_;} ///< Gets the current cairo context
bool autolink() const {return autolink_;} ///< Gets the autolink option. See Fl::cairo_autolink_context(bool)
/** Sets the current cairo context, \p own indicates cc deletion is handle externally by user */
/** Sets the current cairo context.
\p own == \e true (the default) indicates that the cairo context \p c
will be deleted by FLTK internally when another cc is set later.
\p own == \e false indicates cc deletion is handled externally
by the user program.
*/
void cc(cairo_t* c, bool own=true) {
if (cc_ && own_cc_) cairo_destroy(cc_);
cc_=c;
@ -74,7 +73,8 @@ public:
private:
cairo_t * cc_; // contains the unique autoupdated cairo context
bool own_cc_; // indicates whether we must delete the cc, useful for internal cleanup
bool autolink_; // true by default, permits to prevent the automatic cairo mapping on fltk windows for custom cairo implementations
bool autolink_; // false by default, prevents the automatic cairo mapping on fltk windows
// for custom cairo implementations.
void* window_, *gc_; // for keeping track internally of last win+gc treated
};

View File

@ -3,7 +3,7 @@
//
// Main header file for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2010 by Bill Spitzak and others.
// Copyright 1998-2016 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@ -26,8 +26,21 @@
#include <Carbon/Carbon.h>
#endif
// Cairo is currently supported for the following platforms:
// Win32, Apple Quartz, X11
# if defined(USE_X11) // X11
# include <cairo-xlib.h>
# elif defined(WIN32)
# include <cairo-win32.h>
# elif defined(__APPLE_QUARTZ__)
# include <cairo-quartz.h>
# else
# error Cairo is not supported on this platform.
# endif
// static Fl module initialization :
Fl_Cairo_State Fl::cairo_state_; ///< contains all necesary info for current cairo context mapping
Fl_Cairo_State Fl::cairo_state_; ///< contains all necessary info for current cairo context mapping
// Fl cairo features implementation
@ -39,7 +52,7 @@ void Fl_Cairo_State::autolink(bool b) {
autolink_ = b;
#else
Fl::fatal("In Fl::autolink(bool) : Cairo autolink() feature is only "
"available with the enable-cairoext configure option, now quitting.");
"available with the enable-cairoext configure option, now quitting.");
#endif
}
@ -54,7 +67,7 @@ void Fl_Cairo_State::autolink(bool b) {
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_gc() is adequately updated with this
Also, after this call, Fl::cairo_cc() is adequately updated with this
cairo context.
\note Only available when configure has the --enable-cairo option
\return the valid cairo_t* cairo context associated to this window.
@ -83,7 +96,8 @@ cairo_t * Fl::cairo_make_current(Fl_Window* wi) {
/*
Creates transparently a cairo_surface_t object.
gc is an HDC context in WIN32, a CGContext* in Quartz, a display on X11
gc is an HDC context in WIN32, a CGContext* in Quartz, and
a display on X11 (not used on this platform)
*/
static cairo_surface_t * cairo_create_surface(void * gc, int W, int H) {
@ -99,8 +113,9 @@ static cairo_surface_t * cairo_create_surface(void * gc, int W, int H) {
}
/**
Creates a cairo context from a \a gc only, get its window size or offscreen size if fl_window is null.
\note Only available when configure has the --enable-cairo option
Creates a cairo context from a \a gc only, gets its window size or
offscreen size if fl_window is null.
\note Only available when configure has the --enable-cairo option
*/
cairo_t * Fl::cairo_make_current(void *gc) {
int W=0,H=0;
@ -127,7 +142,7 @@ cairo_t * Fl::cairo_make_current(void *gc) {
#elif defined(WIN32)
// we don't need any W,H for WIN32
#else
# error Cairo is not supported under this platform.
# error Cairo is not supported on this platform.
#endif
if (!gc) {
Fl::cairo_cc(0);