bug-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fix: NSView, view clipping


From: Georg Fleischmann
Subject: Fix: NSView, view clipping
Date: Fri, 31 Aug 2001 01:44:13 +0200

Hi,

here are a bunch of patches related to a small problem with the view clipping  
in NSView.
The fix promises to solve the following problems:
- sporadically blank areas in panels, especially inside of a Matrix
- problems with drawing when NSTextViews are mixed with PS-Operators

Every lockFocus of a view sets the view clipping rectangle to the bounds of  
the view, but doesn't restore the view clipping area afterwards. This isn't a  
problem as long as only views are drawn. However, if subviews (eg. NSTextView)  
are drawn before PS-Operators, this may result in wrong clipping.

The easiest way to solve the problem was to reset the clipping area after an  
unlockFocus by just adding DPSinitviewclip(ctxt) at the end of  
unlockFocusWithFlush:. This seems to work.

I decided to use the DPSsave and DPSrestore functions to restore the  
viewclipping area instead. I think this is what should happen. Unfortunately  
they were not defined, and so my little fix grew through 9 files :-(
The following patches need a complete recompile (make clean) of xgps and gui.  
Also some applications using DPS methods need a recompile.

I'm sorry, it's quite a bunch of many little changes. If someone has a better  
idea, I'm not angry at all.

Georg


2001-08-31  Georg Fleischmann

        * gui/Source/NSView.m
        [NSView lockFocusInRect:]: DPSsave(ctxt) added
        [NSView unlockFocusWithFlush:]: DPSrestore(ctxt) added

        * gui/Headers/gnustep/gui/DPSOperators.h
        DPSrestore() and DPSsave(): new

        * gui/Headers/gnustep/gui/GSMethodTable.h
        DPSrestore and DPSsave added

        * gui/Headers/gnustep/gui/NSGraphicsContext.h
        -DPSrestore and -DPSsave added

        * gui/Source/NSGraphicsContext.m
        [NSGraphicContext _inittializeMethodTable]:
        DPSrestore and DPSsave added
        [NSGraphicsContext DPSrestore]: new
        [NSGraphicsContext DPSsave]: new

        * xgps/Headers/gnustep/xgps/XGContext.h
        VM_STACKSIZE, vcstack and vmstackTop added

        * xgps/Source/XGContext.m
        [XGContext DPSrestore]: new
        [XGContext DPSsave]: new

        * xgps/Headers/gnustep/xgps/XGGState.h
        declaration of setClipMask added

        * xgps/Source/XGGState.m
        private declaration of setClipMask removed



--- gui/Source/NSView.m.orig    Wed Aug 29 22:06:39 2001
+++ gui/Source/NSView.m Thu Aug 30 23:56:42 2001
@@ -1328,6 +1328,7 @@
       return;
     }

+  DPSsave(ctxt);
   [ctxt lockFocusView: self inRect: rect];
   wrect = [self convertRect: rect toView: nil];
   NSDebugLLog(@"NSView", @"Displaying rect address@hidden window %p",
@@ -1416,6 +1417,7 @@
     }
   [window_t->_rectsBeingDrawn removeLastObject];
   [ctxt unlockFocusView: self needsFlush: YES ];
+  DPSrestore(ctxt);
 }

 - (void) lockFocus



--- gui/Headers/gnustep/gui/DPSOperators.h.orig Fri Apr 21 00:17:41 2000
+++ gui/Headers/gnustep/gui/DPSOperators.h      Thu Aug 30 18:00:23 2001
@@ -668,6 +668,17 @@
 __attribute__((unused));

 /* ----------------------------------------------------------------------- */
+/* System ops */
+/* ----------------------------------------------------------------------- */
+static inline void
+DPSrestore(GSCTXT *ctxt)
+__attribute__((unused));
+
+static inline void
+DPSsave(GSCTXT *ctxt)
+__attribute__((unused));
+
+/* ----------------------------------------------------------------------- */
 /* Window system ops */
 /* ----------------------------------------------------------------------- */
 static inline void
@@ -2177,6 +2188,23 @@
 {
   (ctxt->methods->DPScurrentalpha_)
     (ctxt, @selector(DPScurrentalpha:), a);
+}
+
+/* ----------------------------------------------------------------------- */
+/* System ops */
+/* ----------------------------------------------------------------------- */
+static inline void
+DPSrestore(GSCTXT *ctxt)
+{
+  (ctxt->methods->DPSrestore)
+    (ctxt, @selector(DPSrestore));
+}
+
+static inline void
+DPSsave(GSCTXT *ctxt)
+{
+  (ctxt->methods->DPSsave)
+    (ctxt, @selector(DPSsave));
 }

 /* ----------------------------------------------------------------------- */



--- gui/Headers/gnustep/gui/GSMethodTable.h.orig        Sat May  5 04:30:46 2001
+++ gui/Headers/gnustep/gui/GSMethodTable.h     Thu Aug 30 18:51:44 2001
@@ -369,6 +369,14 @@
   void (*DPSviewclippath)
        (NSGraphicsContext*, SEL);
 /* ----------------------------------------------------------------------- */
+/* System ops */
+/* ----------------------------------------------------------------------- */
+  void (*DPSrestore)
+       (NSGraphicsContext*, SEL);
+  void (*DPSsave)
+       (NSGraphicsContext*, SEL);
+
+/* ----------------------------------------------------------------------- */
 /* Window system ops */
 /* ----------------------------------------------------------------------- */
   void (*DPScurrentdrawingfunction_)



--- gui/Headers/gnustep/gui/NSGraphicsContext.h.orig    Sun Aug  5 04:30:37 2001
+++ gui/Headers/gnustep/gui/NSGraphicsContext.h Thu Aug 30 18:34:07 2001
@@ -366,6 +366,13 @@
 - (void) DPSsetbbox: (float)llx : (float)lly : (float)urx : (float)ury ;
 - (void) DPSviewclip;
 - (void) DPSviewclippath;
+
+/* ----------------------------------------------------------------------- */
+/* System system ops */
+/* ----------------------------------------------------------------------- */
+- (void) DPSrestore ;
+- (void) DPSsave ;
+
 /* ----------------------------------------------------------------------- */
 /* Window system ops */
 /* ----------------------------------------------------------------------- */



--- gui/Source/NSGraphicsContext.m.orig Sun Aug  5 04:30:37 2001
+++ gui/Source/NSGraphicsContext.m      Thu Aug 30 18:12:14 2001
@@ -731,6 +731,13 @@
   methodTable.DPSviewclippath =
     GET_IMP(@selector(DPSviewclippath));
 /* ----------------------------------------------------------------------- */
+/* System system ops */
+/* ----------------------------------------------------------------------- */
+  methodTable.DPSrestore =
+    GET_IMP(@selector(DPSrestore));
+  methodTable.DPSsave =
+    GET_IMP(@selector(DPSsave));
+/* ----------------------------------------------------------------------- */
 /* Window system ops */
 /* ----------------------------------------------------------------------- */
   methodTable.DPScurrentdrawingfunction_ =
@@ -1794,6 +1801,20 @@
 }

 - (void) DPSviewclippath
+{
+  [self subclassResponsibility: _cmd];
+}
+
+/* ----------------------------------------------------------------------- */
+/* System ops */
+/* ----------------------------------------------------------------------- */
+
+- (void) DPSrestore
+{
+  [self subclassResponsibility: _cmd];
+}
+
+- (void) DPSsave
 {
   [self subclassResponsibility: _cmd];
 }



--- xgps/Headers/gnustep/xgps/XGContext.h.orig  Sat Jan 20 18:35:07 2001
+++ xgps/Headers/gnustep/xgps/XGContext.h       Thu Aug 30 23:25:51 2001
@@ -58,6 +58,8 @@
   XGDM_PORTABLE
 } XGDrawMechanism;

+#define VM_STACKSIZE   10      // stack size for virtual memory (vm) states
+
 @interface XGContext : NSGraphicsContext
 {
 @public
@@ -69,6 +71,8 @@

   void                 *context;
   Region                viewclip;
+  XRectangle           vcstack[VM_STACKSIZE];  // vm stack for viewclip
+  int                  vmstackTop;     // vm stack top
   Window               grabWindow;
   XGDrawMechanism      drawMechanism;
   struct XGGeneric     generic;        /* Defined in XGGeneric.h       */



--- xgps/Source/XGContext.m.orig        Tue May 22 04:31:42 2001
+++ xgps/Source/XGContext.m     Fri Aug 31 00:07:20 2001
@@ -1607,6 +1607,54 @@
 }

 /* ----------------------------------------------------------------------- */
+/* System ops */
+/* ----------------------------------------------------------------------- */
+
+- (void)DPSrestore
+{
+  XRectangle   r;
+
+  if (vmstackTop-1 >= VM_STACKSIZE)
+    {
+       vmstackTop--;
+       return;
+    }
+  if (vmstackTop <= 0)
+    {
+      NSLog(@"DPSrestore: unbalanced save/restore");
+      return;
+    }
+  // pop topmost rectangle from stack
+  r = vcstack[--vmstackTop];
+  if (r.width)
+    {
+      XSubtractRegion(viewclip, viewclip, viewclip);
+      XUnionRectWithRegion(&r, viewclip, viewclip);
+      [gstate setClipMask];
+    }
+  else
+    [self DPSinitviewclip];
+}
+
+- (void)DPSsave
+{
+  XRectangle   r;
+
+  if (vmstackTop >= VM_STACKSIZE)
+    {
+      NSLog(@"DPSsave: stack limit exceeded !");
+      vmstackTop++;
+      return;
+    }
+  // add viewclip rectangle to stack
+  if (viewclip)
+    XClipBox(viewclip, &r);
+  else
+    r.width = r.height = 0;
+  vcstack[vmstackTop++] = r;
+}
+
+/* ----------------------------------------------------------------------- */
 /* Window system ops */
 /* ----------------------------------------------------------------------- */




--- xgps/Headers/gnustep/xgps/XGGState.h.orig   Tue May 22 04:31:42 2001
+++ xgps/Headers/gnustep/xgps/XGGState.h        Thu Aug 30 23:29:31 2001
@@ -65,6 +65,7 @@
 - (void) setDrawable: (Drawable)theDrawable;
 - (void) setGraphicContext: (GC)xGraphicContext;
 - (void) setGCValues: (XGCValues)values withMask: (int)mask;
+- (void) setClipMask;
 - (void) setColor: (xr_device_color_t)acolor;
 - (void) setOffset: (NSPoint)theOffset;




--- xgps/Source/XGGState.m.orig Thu Aug 30 00:57:59 2001
+++ xgps/Source/XGGState.m      Thu Aug 30 23:29:48 2001
@@ -81,7 +81,6 @@

 @interface XGGState (Private)
 - (void) _paintPath: (ctxt_object_t) drawType;
-- (void) setClipMask;
 - (void) createGraphicContext;
 - (void) copyGraphicContext;
 @end



reply via email to

[Prev in Thread] Current Thread [Next in Thread]