2008-09-25 22:26:33 +04:00
|
|
|
//
|
|
|
|
// "$Id$"
|
|
|
|
//
|
|
|
|
// Main header file for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2016-02-13 21:02:17 +03:00
|
|
|
// Copyright 1998-2016 by Bill Spitzak and others.
|
2008-09-25 22:26:33 +04:00
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
// 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
|
|
|
|
// file is missing or damaged, see the license at:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/COPYING.php
|
2008-09-25 22:26:33 +04:00
|
|
|
//
|
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/str.php
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2011-01-06 13:24:58 +03:00
|
|
|
#ifdef FLTK_HAVE_CAIRO
|
2008-09-25 22:26:33 +04:00
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/x.H>
|
|
|
|
#include <FL/Fl_Window.H>
|
2011-01-06 13:24:58 +03:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#include <Carbon/Carbon.h>
|
|
|
|
#endif
|
2008-09-25 22:26:33 +04:00
|
|
|
|
2016-02-13 21:02:17 +03:00
|
|
|
// 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__) // PORTME: Cairo Support
|
|
|
|
# include <cairo-quartz.h>
|
|
|
|
#elif defined(FL_PORTING)
|
|
|
|
# pragma message "FL_PORTING: is the Cairo library available on this platform?"
|
|
|
|
#else
|
|
|
|
# error Cairo is not supported on this platform.
|
|
|
|
#endif
|
|
|
|
|
2008-09-25 22:26:33 +04:00
|
|
|
// static Fl module initialization :
|
2016-02-13 21:02:17 +03:00
|
|
|
Fl_Cairo_State Fl::cairo_state_; ///< contains all necessary info for current cairo context mapping
|
Cairo increment 2: Finer cairo granularity, less deps, new fltk_cairo lib
+ added new USE_CAIRO config preprocessor def.
to differentiate from HAVE_CAIRO so that we can use the cairo lib
without forcing the full fltk lib to be linked against it.
In that case, cairo autolink context functionality which needs fltk lib
instrumentation is disabled.
+ added new --enable-cairoext, which correspond to previous --enable-cairo.
now, --enable-cairo only adds HAVE_CAIRO def. and keeps fltk lib
from referencing cairo.
In both cases (--enable-cairo & --enable-cairoext), a new fltk_cairo lib is
created. This lib, similarly to local versions of png,jpeg and zlib,
is not generated if cairo is not enabled.
+ added cairo to fltk-config : now new --use-cairo flag is available
+ modified all unix like makefiles to now generate minimum cairo deps and also
new libfltk_cairo lib.
+ added new cairo subdir to permit conditional fltk_cairo lib generation.
+ vc2005 project minimum update to compile without be broken, but still needs
to create a similar fltk_cairo independent lib. For now, it works as before
with a dedicated cairo env. similar to --enable-cairoext context in unix.
+ regression tested ok with cairo disabled on win32, mac osx, mingw.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6462 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2008-10-19 05:42:35 +04:00
|
|
|
|
|
|
|
|
2008-09-25 22:26:33 +04:00
|
|
|
// Fl cairo features implementation
|
|
|
|
|
Cairo increment 2: Finer cairo granularity, less deps, new fltk_cairo lib
+ added new USE_CAIRO config preprocessor def.
to differentiate from HAVE_CAIRO so that we can use the cairo lib
without forcing the full fltk lib to be linked against it.
In that case, cairo autolink context functionality which needs fltk lib
instrumentation is disabled.
+ added new --enable-cairoext, which correspond to previous --enable-cairo.
now, --enable-cairo only adds HAVE_CAIRO def. and keeps fltk lib
from referencing cairo.
In both cases (--enable-cairo & --enable-cairoext), a new fltk_cairo lib is
created. This lib, similarly to local versions of png,jpeg and zlib,
is not generated if cairo is not enabled.
+ added cairo to fltk-config : now new --use-cairo flag is available
+ modified all unix like makefiles to now generate minimum cairo deps and also
new libfltk_cairo lib.
+ added new cairo subdir to permit conditional fltk_cairo lib generation.
+ vc2005 project minimum update to compile without be broken, but still needs
to create a similar fltk_cairo independent lib. For now, it works as before
with a dedicated cairo env. similar to --enable-cairoext context in unix.
+ regression tested ok with cairo disabled on win32, mac osx, mingw.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6462 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2008-10-19 05:42:35 +04:00
|
|
|
// Fl_Cairo_State class impl
|
|
|
|
|
|
|
|
void Fl_Cairo_State::autolink(bool b) {
|
2011-01-06 13:24:58 +03:00
|
|
|
#ifdef FLTK_USE_CAIRO
|
Cairo increment 2: Finer cairo granularity, less deps, new fltk_cairo lib
+ added new USE_CAIRO config preprocessor def.
to differentiate from HAVE_CAIRO so that we can use the cairo lib
without forcing the full fltk lib to be linked against it.
In that case, cairo autolink context functionality which needs fltk lib
instrumentation is disabled.
+ added new --enable-cairoext, which correspond to previous --enable-cairo.
now, --enable-cairo only adds HAVE_CAIRO def. and keeps fltk lib
from referencing cairo.
In both cases (--enable-cairo & --enable-cairoext), a new fltk_cairo lib is
created. This lib, similarly to local versions of png,jpeg and zlib,
is not generated if cairo is not enabled.
+ added cairo to fltk-config : now new --use-cairo flag is available
+ modified all unix like makefiles to now generate minimum cairo deps and also
new libfltk_cairo lib.
+ added new cairo subdir to permit conditional fltk_cairo lib generation.
+ vc2005 project minimum update to compile without be broken, but still needs
to create a similar fltk_cairo independent lib. For now, it works as before
with a dedicated cairo env. similar to --enable-cairoext context in unix.
+ regression tested ok with cairo disabled on win32, mac osx, mingw.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6462 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2008-10-19 05:42:35 +04:00
|
|
|
autolink_ = b;
|
|
|
|
#else
|
|
|
|
Fl::fatal("In Fl::autolink(bool) : Cairo autolink() feature is only "
|
2016-02-13 21:02:17 +03:00
|
|
|
"available with the enable-cairoext configure option, now quitting.");
|
Cairo increment 2: Finer cairo granularity, less deps, new fltk_cairo lib
+ added new USE_CAIRO config preprocessor def.
to differentiate from HAVE_CAIRO so that we can use the cairo lib
without forcing the full fltk lib to be linked against it.
In that case, cairo autolink context functionality which needs fltk lib
instrumentation is disabled.
+ added new --enable-cairoext, which correspond to previous --enable-cairo.
now, --enable-cairo only adds HAVE_CAIRO def. and keeps fltk lib
from referencing cairo.
In both cases (--enable-cairo & --enable-cairoext), a new fltk_cairo lib is
created. This lib, similarly to local versions of png,jpeg and zlib,
is not generated if cairo is not enabled.
+ added cairo to fltk-config : now new --use-cairo flag is available
+ modified all unix like makefiles to now generate minimum cairo deps and also
new libfltk_cairo lib.
+ added new cairo subdir to permit conditional fltk_cairo lib generation.
+ vc2005 project minimum update to compile without be broken, but still needs
to create a similar fltk_cairo independent lib. For now, it works as before
with a dedicated cairo env. similar to --enable-cairoext context in unix.
+ regression tested ok with cairo disabled on win32, mac osx, mingw.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6462 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2008-10-19 05:42:35 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-09-25 22:26:33 +04:00
|
|
|
/**
|
2008-10-01 19:28:41 +04:00
|
|
|
Provides a corresponding cairo context for window \a wi.
|
2016-02-13 21:02:17 +03:00
|
|
|
This is needed in a draw() override if Fl::cairo_autolink_context()
|
2008-09-25 22:26:33 +04:00
|
|
|
returns false, which is the default.
|
2016-02-13 21:02:17 +03:00
|
|
|
The cairo_context() does not need to be freed as it is freed every time
|
2008-09-25 22:26:33 +04:00
|
|
|
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
|
2016-02-13 21:02:17 +03:00
|
|
|
is used. In particular, if the current graphical context and the current
|
2008-09-25 22:26:33 +04:00
|
|
|
window didn't change between two calls, the previous gc is internally kept,
|
|
|
|
thus optimizing the drawing performances.
|
2016-02-13 21:02:17 +03:00
|
|
|
Also, after this call, Fl::cairo_cc() is adequately updated with this
|
2008-09-25 22:26:33 +04:00
|
|
|
cairo context.
|
|
|
|
\note Only available when configure has the --enable-cairo option
|
|
|
|
\return the valid cairo_t* cairo context associated to this window.
|
|
|
|
*/
|
|
|
|
cairo_t * Fl::cairo_make_current(Fl_Window* wi) {
|
|
|
|
if (!wi) return NULL; // Precondition
|
|
|
|
|
|
|
|
if (fl_gc==0) { // means remove current cc
|
|
|
|
Fl::cairo_cc(0); // destroy any previous cc
|
|
|
|
cairo_state_.window(0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// don't re-create a context if it's the same gc/window couple
|
|
|
|
if (fl_gc==Fl::cairo_state_.gc() && fl_xid(wi) == (Window) Fl::cairo_state_.window())
|
|
|
|
return Fl::cairo_cc();
|
|
|
|
|
|
|
|
cairo_state_.window(wi);
|
|
|
|
|
|
|
|
#if defined(USE_X11)
|
|
|
|
return Fl::cairo_make_current(0, wi->w(), wi->h());
|
|
|
|
#else
|
|
|
|
return Fl::cairo_make_current(fl_gc, wi->w(), wi->h());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Creates transparently a cairo_surface_t object.
|
2016-02-13 21:02:17 +03:00
|
|
|
gc is an HDC context in WIN32, a CGContext* in Quartz, and
|
|
|
|
a display on X11 (not used on this platform)
|
2008-09-25 22:26:33 +04:00
|
|
|
*/
|
2013-12-11 10:16:57 +04:00
|
|
|
|
2008-09-25 22:26:33 +04:00
|
|
|
static cairo_surface_t * cairo_create_surface(void * gc, int W, int H) {
|
2008-10-14 03:10:43 +04:00
|
|
|
# if defined(USE_X11)
|
2008-09-25 22:26:33 +04:00
|
|
|
return cairo_xlib_surface_create(fl_display, fl_window, fl_visual->visual, W, H);
|
|
|
|
# elif defined(WIN32)
|
|
|
|
return cairo_win32_surface_create((HDC) gc);
|
|
|
|
# elif defined(__APPLE_QUARTZ__)
|
|
|
|
return cairo_quartz_surface_create_for_cg_context((CGContext*) gc, W, H);
|
|
|
|
# else
|
|
|
|
# error Cairo is not supported under this platform.
|
|
|
|
# endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-02-13 21:02:17 +03:00
|
|
|
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
|
2008-09-25 22:26:33 +04:00
|
|
|
*/
|
|
|
|
cairo_t * Fl::cairo_make_current(void *gc) {
|
|
|
|
int W=0,H=0;
|
|
|
|
#if defined(USE_X11)
|
|
|
|
//FIXME X11 get W,H
|
|
|
|
// gc will be the window handle here
|
|
|
|
# warning FIXME get W,H for cairo_make_current(void*)
|
|
|
|
#elif defined(__APPLE_QUARTZ__)
|
|
|
|
if (fl_window) {
|
2012-02-21 16:27:31 +04:00
|
|
|
W = Fl_Window::current()->w();
|
|
|
|
H = Fl_Window::current()->h();
|
2016-09-26 15:08:37 +03:00
|
|
|
}
|
2008-09-25 22:26:33 +04:00
|
|
|
else {
|
|
|
|
W = CGBitmapContextGetHeight(fl_gc);
|
|
|
|
H = CGBitmapContextGetHeight(fl_gc);
|
|
|
|
}
|
|
|
|
#elif defined(WIN32)
|
|
|
|
// we don't need any W,H for WIN32
|
|
|
|
#else
|
2016-02-13 21:02:17 +03:00
|
|
|
# error Cairo is not supported on this platform.
|
2008-09-25 22:26:33 +04:00
|
|
|
#endif
|
|
|
|
if (!gc) {
|
|
|
|
Fl::cairo_cc(0);
|
|
|
|
cairo_state_.gc(0); // keep track for next time
|
|
|
|
return 0;
|
|
|
|
}
|
2013-12-11 10:16:57 +04:00
|
|
|
if (gc==Fl::cairo_state_.gc() &&
|
|
|
|
fl_window== (Window) Fl::cairo_state_.window() &&
|
2013-12-11 10:33:14 +04:00
|
|
|
cairo_state_.cc()!=0)
|
2008-09-25 22:26:33 +04:00
|
|
|
return Fl::cairo_cc();
|
|
|
|
cairo_state_.gc(fl_gc); // keep track for next time
|
|
|
|
cairo_surface_t * s = cairo_create_surface(gc, W, H);
|
|
|
|
cairo_t * c = cairo_create(s);
|
|
|
|
cairo_surface_destroy(s);
|
2013-12-11 10:16:57 +04:00
|
|
|
cairo_state_.cc(c);
|
2008-09-25 22:26:33 +04:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Creates a cairo context from a \a gc and its size
|
|
|
|
\note Only available when configure has the --enable-cairo option
|
|
|
|
*/
|
|
|
|
cairo_t * Fl::cairo_make_current(void *gc, int W, int H) {
|
2013-12-11 10:16:57 +04:00
|
|
|
if (gc==Fl::cairo_state_.gc() &&
|
|
|
|
fl_window== (Window) Fl::cairo_state_.window() &&
|
|
|
|
cairo_state_.cc()!=0) // no need to create a cc, just return that one
|
|
|
|
return cairo_state_.cc();
|
|
|
|
|
|
|
|
// we need to (re-)create a fresh cc ...
|
|
|
|
cairo_state_.gc(gc); // keep track for next time
|
|
|
|
cairo_surface_t * s = cairo_create_surface(gc, W, H);
|
2008-09-25 22:26:33 +04:00
|
|
|
cairo_t * c = cairo_create(s);
|
2013-12-11 10:16:57 +04:00
|
|
|
cairo_state_.cc(c); // and purge any previously owned context
|
2008-09-25 22:26:33 +04:00
|
|
|
cairo_surface_destroy(s);
|
|
|
|
return c;
|
|
|
|
}
|
Cairo increment 2: Finer cairo granularity, less deps, new fltk_cairo lib
+ added new USE_CAIRO config preprocessor def.
to differentiate from HAVE_CAIRO so that we can use the cairo lib
without forcing the full fltk lib to be linked against it.
In that case, cairo autolink context functionality which needs fltk lib
instrumentation is disabled.
+ added new --enable-cairoext, which correspond to previous --enable-cairo.
now, --enable-cairo only adds HAVE_CAIRO def. and keeps fltk lib
from referencing cairo.
In both cases (--enable-cairo & --enable-cairoext), a new fltk_cairo lib is
created. This lib, similarly to local versions of png,jpeg and zlib,
is not generated if cairo is not enabled.
+ added cairo to fltk-config : now new --use-cairo flag is available
+ modified all unix like makefiles to now generate minimum cairo deps and also
new libfltk_cairo lib.
+ added new cairo subdir to permit conditional fltk_cairo lib generation.
+ vc2005 project minimum update to compile without be broken, but still needs
to create a similar fltk_cairo independent lib. For now, it works as before
with a dedicated cairo env. similar to --enable-cairoext context in unix.
+ regression tested ok with cairo disabled on win32, mac osx, mingw.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6462 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2008-10-19 05:42:35 +04:00
|
|
|
#else
|
|
|
|
// just don't leave the libfltk_cairo lib empty to avoid warnings
|
|
|
|
#include <FL/Fl_Export.H>
|
|
|
|
FL_EXPORT int fltk_cairo_dummy() { return 1;}
|
2011-01-06 13:24:58 +03:00
|
|
|
#endif // FLTK_HAVE_CAIRO
|
2008-09-25 22:26:33 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// End of "$Id$" .
|
|
|
|
//
|