simplifying clipping algorithm: done once in make_current() instead of repeated at each fl_restore_clip() call

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7037 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Manolo Gouy 2010-02-02 17:13:55 +00:00
parent c7b67bc252
commit 5ec87ac848
2 changed files with 40 additions and 46 deletions

View File

@ -114,7 +114,6 @@ char fl_key_vector[32]; // used by Fl::get_key()
bool fl_show_iconic; // true if called from iconize() - shows the next created window in collapsed state bool fl_show_iconic; // true if called from iconize() - shows the next created window in collapsed state
int fl_disable_transient_for; // secret method of removing TRANSIENT_FOR int fl_disable_transient_for; // secret method of removing TRANSIENT_FOR
//const Fl_Window* fl_modal_for; // parent of modal() window //const Fl_Window* fl_modal_for; // parent of modal() window
Fl_Region fl_window_region = 0;
Window fl_window; Window fl_window;
Fl_Window *Fl_Window::current_; Fl_Window *Fl_Window::current_;
//EventRef fl_os_event; // last (mouse) event //EventRef fl_os_event; // last (mouse) event
@ -2246,11 +2245,8 @@ void Fl_Window::make_current()
[[(NSWindow*)i->xid contentView] lockFocus]; [[(NSWindow*)i->xid contentView] lockFocus];
i->gc = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; i->gc = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
fl_gc = i->gc; fl_gc = i->gc;
if ( fl_window_region ) XDestroyRegion(fl_window_region); Fl_Region fl_window_region = XRectangleRegion(0,0,w(),h());
if (this->window()) { if ( ! this->window() ) {
fl_window_region = XRectangleRegion(0,0,w(),h());
} else {
fl_window_region = XRectangleRegion(0, 0, w(), h());
for ( Fl_X *cx = i->xidChildren; cx; cx = cx->xidNext ) { // clip-out all sub-windows for ( Fl_X *cx = i->xidChildren; cx; cx = cx->xidNext ) { // clip-out all sub-windows
Fl_Window *cw = cx->w; Fl_Window *cw = cx->w;
Fl_Region from = fl_window_region; Fl_Region from = fl_window_region;
@ -2263,7 +2259,18 @@ void Fl_Window::make_current()
// and escapes even clipping!!! // and escapes even clipping!!!
// it gets activated when needed (e.g., draw text) // it gets activated when needed (e.g., draw text)
CGContextSetShouldAntialias(fl_gc, false); CGContextSetShouldAntialias(fl_gc, false);
// this is the native view context with origin at bottom left CGFloat hgt = [[(NSWindow*)fl_window contentView] frame].size.height;
CGContextTranslateCTM(fl_gc, 0.5, hgt-0.5f);
CGContextScaleCTM(fl_gc, 1.0f, -1.0f); // now 0,0 is top-left point of the window
win = this;
while(win && win->window()) { // translate to subwindow origin if this is a subwindow context
CGContextTranslateCTM(fl_gc, win->x(), win->y());
win = win->window();
}
//apply window's clip
CGContextClipToRects(fl_gc, fl_window_region->rects, fl_window_region->count );
XDestroyRegion(fl_window_region);
// this is the context with origin at top left of (sub)window clipped out of its subwindows if any
CGContextSaveGState(fl_gc); CGContextSaveGState(fl_gc);
#if defined(USE_CAIRO) #if defined(USE_CAIRO)
if (Fl::cairo_autolink_context()) Fl::cairo_make_current(this); // capture gc changes automatically to update the cairo context adequately if (Fl::cairo_autolink_context()) Fl::cairo_make_current(this); // capture gc changes automatically to update the cairo context adequately
@ -2286,24 +2293,14 @@ extern void fl_quartz_restore_line_style_();
// current Quartz context // current Quartz context
void Fl_X::q_fill_context() { void Fl_X::q_fill_context() {
if (!fl_gc) return; if (!fl_gc) return;
int hgt = 0; if ( ! fl_window) { // a bitmap context
if (fl_window) { size_t hgt = CGBitmapContextGetHeight(fl_gc);
hgt = [[(NSWindow*)Fl_X::i(Fl_Window::current_)->xid contentView] frame].size.height; CGContextTranslateCTM(fl_gc, 0.5, hgt-0.5f);
} else { CGContextScaleCTM(fl_gc, 1.0f, -1.0f); // now 0,0 is top-left point of the context
hgt = CGBitmapContextGetHeight(fl_gc); }
}
CGContextTranslateCTM(fl_gc, 0.5, hgt-0.5f);
CGContextScaleCTM(fl_gc, 1.0f, -1.0f); // now 0,0 is top-left point of the context
fl_font(fl_fontsize); fl_font(fl_fontsize);
fl_color(fl_color_); fl_color(fl_color_);
fl_quartz_restore_line_style_(); fl_quartz_restore_line_style_();
if (fl_window) { // translate to subwindow origin if this is a subwindow context
Fl_Window *w = Fl_Window::current_;
while(w && w->window()) {
CGContextTranslateCTM(fl_gc, w->x(), w->y());
w = w->window();
}
}
} }
// The only way to reset clipping to its original state is to pop the current graphics // The only way to reset clipping to its original state is to pop the current graphics

View File

@ -564,7 +564,6 @@ Fl_Region XRectangleRegion(int x, int y, int w, int h) {
// warning: the Quartz implementation currently uses Quickdraw calls to achieve // warning: the Quartz implementation currently uses Quickdraw calls to achieve
// clipping. A future version should instead use 'CGContectClipToRect' // clipping. A future version should instead use 'CGContectClipToRect'
// and friends. // and friends.
extern Fl_Region fl_window_region;
#endif #endif
/** Undoes any clobbering of clip done by your program */ /** Undoes any clobbering of clip done by your program */
@ -577,19 +576,17 @@ void fl_restore_clip() {
#elif defined(WIN32) #elif defined(WIN32)
SelectClipRgn(fl_gc, r); //if r is NULL, clip is automatically cleared SelectClipRgn(fl_gc, r); //if r is NULL, clip is automatically cleared
#elif defined(__APPLE_QUARTZ__) #elif defined(__APPLE_QUARTZ__)
if ( fl_window ) // clipping for a true window if ( fl_window ) { // clipping for a true window
{
#ifdef __APPLE_COCOA__ #ifdef __APPLE_COCOA__
Fl_X::q_clear_clipping(); Fl_X::q_clear_clipping();
Fl_X::q_fill_context();//flip coords and translate if subwindow Fl_X::q_fill_context();//flip coords if bitmap context
//apply window's clip //apply program clip
CGContextClipToRects(fl_gc, fl_window_region->rects, fl_window_region->count ); if(r) {
//apply additional program clip CGContextClipToRects(fl_gc, r->rects, r->count);
if(r) { }
CGContextClipToRects(fl_gc, r->rects, r->count);
}
#else #else
GrafPtr port = GetWindowPort( fl_window ); extern Fl_Region fl_window_region;
GrafPtr port = GetWindowPort( fl_window );
if ( port ) { if ( port ) {
RgnHandle portClip = NewRgn(); RgnHandle portClip = NewRgn();
CopyRgn( fl_window_region, portClip ); // changed CopyRgn( fl_window_region, portClip ); // changed
@ -603,20 +600,20 @@ void fl_restore_clip() {
} }
#endif #endif
} else if (fl_gc) { // clipping for an offscreen drawing world (CGBitmap) } else if (fl_gc) { // clipping for an offscreen drawing world (CGBitmap)
Rect portRect; Fl_X::q_clear_clipping();
portRect.top = 0; if (r) {
portRect.left = 0;
portRect.bottom = CGBitmapContextGetHeight(fl_gc);
portRect.right = CGBitmapContextGetWidth(fl_gc);
Fl_X::q_clear_clipping();
if (r) {
#ifdef __APPLE_COCOA__ #ifdef __APPLE_COCOA__
CGContextClipToRects(fl_gc, r->rects, r->count); CGContextClipToRects(fl_gc, r->rects, r->count);
#else #else
ClipCGContextToRegion(fl_gc, &portRect, r); Rect portRect;
portRect.top = 0;
portRect.left = 0;
portRect.bottom = CGBitmapContextGetHeight(fl_gc);
portRect.right = CGBitmapContextGetWidth(fl_gc);
ClipCGContextToRegion(fl_gc, &portRect, r);
#endif #endif
} }
Fl_X::q_fill_context(); Fl_X::q_fill_context();
} }
#else #else
# error unsupported platform # error unsupported platform