optimize: undraw selection
authorca
Wed, 15 Nov 2000 11:35:31 +0100
changeset 1427 85b9b5da0b8d
parent 1426 fcf2ecbdde67
child 1428 8243829fd6d3
optimize: undraw selection
UIObjectView.st
UIPainterView.st
--- a/UIObjectView.st	Mon Nov 13 12:14:23 2000 +0100
+++ b/UIObjectView.st	Wed Nov 15 11:35:31 2000 +0100
@@ -942,26 +942,6 @@
 
 !UIObjectView methodsFor:'private handles'!
 
-handleAffectedViews:aViewOrSeqOfViews
-    "update affected views
-    "
-    |c|
-
-    self forEach:aViewOrSeqOfViews do:[:v|
-	v shown ifTrue:[
-	    v fill:v viewBackground.
-	    v borderWidth ~~ 0 ifTrue:[
-		c := v borderColor.
-		v borderColor:(Color colorId:1).
-		v borderColor:c.
-	    ].
-	    v exposeX:0 y:0 width:(v width) height:(v height)
-	]
-    ]
-
-    "Modified: / 16.9.1998 / 01:40:30 / cg"
-!
-
 handlesOf:aComponent do:aTwoArgAction
     "perform action on each handle of a component
     "
@@ -972,88 +952,10 @@
     ext := 6@6.
 
     self class handlesOf:aComponent do:[:pnt :wht |
-	aTwoArgAction value:(pnt + dlt extent:ext) value:wht
+        aTwoArgAction value:(pnt + dlt extent:ext) value:wht
     ]
 !
 
-showUnselected:aComponent
-    "show object unselected
-    "
-    self showUnselected:aComponent addAffectedViewsTo:nil
-!
-
-showUnselected:aComponent addAffectedViewsTo:aSet
-    "show object unselected. If the set, an IdentitySet, is not nil, the
-     affected subviews are added into the set, otherwise an expose event
-     to each affected component is raised.
-    "
-    |wasClipped r v|
-
-    selectionHiddenLevel ~~ 0 ifTrue:[^ self].
-
-"/    "/ new: simply create a little view ontop,
-"/    "/ and move it over the handles. This will generate
-"/    "/ the required expose events automatically.
-"/    "/ mhmh - does not work correctly with inverted frame (exposes destroy it)
-"/
-"/    v := SimpleView in:self.
-"/    self handlesOf:aComponent do:[:rec :wht | 
-"/        r isNil 
-"/            ifTrue:[r := rec]
-"/            ifFalse:[r := r merge:rec].
-"/    ].
-"/
-"/    "/ if the area is small, make one big rectangle-expose
-"/    r area < 10000 ifTrue:[
-"/        v origin:r origin extent:r extent.
-"/        v map.
-"/        v unmap.
-"/    ] ifFalse:[
-"/        self handlesOf:aComponent do:[:rec :wht | 
-"/            v origin:rec origin extent:rec extent.
-"/            v map.
-"/            v unmap.
-"/        ].
-"/    ].
-"/    v destroy.
-"/    ^ self.
-
-    (wasClipped := clipChildren) ifTrue:[
-	self clippedByChildren:(clipChildren := false). 
-    ].
-
-    self handlesOf:aComponent do:[:rec :wht| self clearRectangle:rec ].
-
-    wasClipped ifTrue:[
-	self clippedByChildren:(clipChildren := true). 
-    ].
-
-    "/ must redraw all components which are affected b the handles
-    r := (aComponent originRelativeTo:self) - (3@3) extent:(aComponent extent + (6@6)).
-
-    subViews do:[:anotherComponent |
-	|absOrg absFrame|
-
-	anotherComponent ~~ inputView ifTrue:[
-	    absOrg := anotherComponent originRelativeTo:self.
-	    absFrame := absOrg extent:(anotherComponent extent).
-	    (absFrame intersects:r) ifTrue:[
-		anotherComponent withAllSubViewsDo:[:v |
-		    v shown ifTrue:[
-			aSet notNil ifTrue:[
-			    aSet add:v
-			] ifFalse:[
-			    self handleAffectedViews:v
-			]
-		    ]
-		]
-	    ]
-	]
-    ].
-
-    "Modified: / 24.8.1998 / 12:19:38 / cg"
-!
-
 whichHandleOf:aComponent isHitBy:aPoint
     "returns kind of handle or nil
     "
@@ -1258,19 +1160,9 @@
 !UIObjectView methodsFor:'selections'!
 
 hideSelection
-    "hide the selection - undraw hilights - whatever that is"
-
-    |aSet|
-
-    self selectionDo:[:object|
-	aSet isNil ifTrue:[
-	    aSet := IdentitySet new
-	].
-	self showUnselected:object addAffectedViewsTo:aSet.
-    ].
-    self handleAffectedViews:aSet.
-
-
+    "hide the selection - undraw hilights - whatever that is
+    "
+    self showUnselected:selection.
 !
 
 moveableSelection
@@ -1413,6 +1305,85 @@
 
 !UIObjectView methodsFor:'selections basic'!
 
+recursiveRepair:theDamages startIn:aView
+    "repair all views and contained views, which intersects the damage.
+     !!!! all damages repaired are removed from the list of damages !!!!
+    "
+    |color isRepaired relOrg damage
+     bwWidth    "{ Class:SmallInteger }"
+     x          "{ Class:SmallInteger }"
+     y          "{ Class:SmallInteger }"
+     w          "{ Class:SmallInteger }"
+     h          "{ Class:SmallInteger }"
+     relOrgX    "{ Class:SmallInteger }"
+     relOrgY    "{ Class:SmallInteger }"
+     width      "{ Class:SmallInteger }"
+     height     "{ Class:SmallInteger }"
+     size       "{ Class:SmallInteger }"
+    |
+    aView isInputOnly ifTrue:[^ self].
+
+    (aView shown and:[theDamages notEmpty]) ifFalse:[ ^ theDamages ].
+
+    aView subViews notNil ifTrue:[
+        aView subViews reverseDo:[:v| self recursiveRepair:theDamages startIn:v ].
+        theDamages isEmpty ifTrue:[ ^ self ].
+    ].
+
+    relOrg  := aView originRelativeTo:self.
+    bwWidth := aView borderWidth.
+    size    := theDamages size.
+
+    "/ compute relative origin starting from border left@top
+    relOrgX := relOrg x - bwWidth.
+    relOrgY := relOrg y - bwWidth.
+    width   := aView width  + bwWidth + bwWidth.
+    height  := aView height + bwWidth + bwWidth.
+
+    size to:1 by:-1 do:[:anIndex|
+        damage := theDamages at:anIndex.
+
+        "/ compute the rectangle into the view
+        y := damage top  - relOrgY.
+        x := damage left - relOrgX.
+        w := damage width.
+        h := damage height.
+
+        isRepaired := true.
+
+        x     < 0      ifTrue:[ w := w + x. x := 0. isRepaired := false ].
+        y     < 0      ifTrue:[ h := h + y. y := 0. isRepaired := false ].
+        x + w > width  ifTrue:[ w := width  - x.    isRepaired := false ].
+        y + h > height ifTrue:[ h := height - y.    isRepaired := false ].
+
+        (w > 0 and:[h > 0]) ifTrue:[
+            bwWidth ~~ 0 ifTrue:[
+                color isNil ifTrue:[
+                    "/ must force redraw of border
+                    color := aView borderColor.
+                    aView borderColor:(Color colorId:1).
+                    aView borderColor:color.
+                ].
+                w := w - bwWidth.
+                h := h - bwWidth.
+
+                (x := x - bwWidth) < 0 ifTrue:[w := w + x. x := 0].
+                (y := y - bwWidth) < 0 ifTrue:[h := h + y. y := 0].
+
+                (w > 0 and:[h > 0])  ifFalse:[w := 0].
+            ].
+
+            w > 0 ifTrue:[
+"/                    aView clearRectangleX:x y:y width:w height:h.
+                aView exposeX:x y:y width:w height:h
+            ].
+        ] ifFalse:[
+            isRepaired := false
+        ].
+        isRepaired ifTrue:[ theDamages removeIndex:anIndex ].
+    ].
+!
+
 selection
     "returns the current selection
     "
@@ -1437,6 +1408,36 @@
     ] ifFalse:[
 	selection := sel
     ]
+!
+
+showUnselected:something
+    "show a component ot list of components unselected
+    "
+    |damages oldClipped|
+
+    (selectionHiddenLevel ~~ 0 or:[something isNil]) ifTrue:[
+        ^ self
+    ].
+    damages := OrderedCollection new.
+
+    (oldClipped := clipChildren) ifTrue:[
+        self clippedByChildren:(clipChildren := false)
+    ].
+
+    self forEach:something do:[:v|
+        self handlesOf:v do:[:rec :wht|
+            self clearRectangle:rec.
+            damages add:rec
+        ]
+    ].
+
+    subViews notNil ifTrue:[
+        self clippedByChildren:(clipChildren := true).
+        subViews reverseDo:[:v| self recursiveRepair:damages startIn:v ].
+    ].
+    oldClipped ~~ clipChildren ifTrue:[
+        self clippedByChildren:(clipChildren := oldClipped).
+    ].
 ! !
 
 !UIObjectView methodsFor:'testing'!
--- a/UIPainterView.st	Mon Nov 13 12:14:23 2000 +0100
+++ b/UIPainterView.st	Wed Nov 15 11:35:31 2000 +0100
@@ -1756,26 +1756,22 @@
 updateSelectionFromModel:aSelOrNil
     "update selection from a new selection
     "
-    |aSet|
+    |list|
 
     selectionHiddenLevel == 0 ifTrue:[
         aSelOrNil size ~~ 0 ifTrue:[
+            list := OrderedCollection new.
+
             self selectionDo:[:el|
-                (aSelOrNil includes:el) ifFalse:[
-                    aSet isNil ifTrue:[
-                        aSet := IdentitySet new
-                    ].
-                    self showUnselected:el addAffectedViewsTo:aSet.
-                ] 
+                (aSelOrNil includes:el) ifFalse:[list add:el]
             ].
-            self handleAffectedViews:aSet.
+            self showUnselected:list.
         ] ifFalse:[
             self hideSelection.
         ]
     ].
     self setSelection:aSelOrNil withRedraw:false.
     self showSelection
-
 ! !
 
 !UIPainterView methodsFor:'specification'!
@@ -2177,22 +2173,26 @@
 spec
     "return the value of the instance variable 'spec' (automatically generated)"
 
-    ^ spec!
+    ^ spec
+!
 
 spec:something
     "set the value of the instance variable 'spec' (automatically generated)"
 
-    spec := something.!
+    spec := something.
+!
 
 view
     "return the value of the instance variable 'view' (automatically generated)"
 
-    ^ view!
+    ^ view
+!
 
 view:something
     "set the value of the instance variable 'view' (automatically generated)"
 
-    view := something.! !
+    view := something.
+! !
 
 !UIPainterView::ViewProperty methodsFor:'initialization'!