Code Challenge !!!

Bob Arning arning at
Fri Mar 24 12:13:03 UTC 2000

On Fri, 24 Mar 2000 09:27:51 +0100 (CET) Bert Freudenberg <bert at isgnw.CS.Uni-Magdeburg.De> wrote:
>What might be challenging (maybe it's easy) is making the World be able to
>have a gradient - PasteUpMorph actually is a subclass of GradientFillMorph
>but it's drawOn: method is only used in a Playfield, not for the World.

'From Squeak2.8alpha of 13 January 2000 [latest update: #1919] on 24 March 2000 at 7:11:39 am'!
"Change Set:		gradientWorld
Date:			24 March 2000
Author:			Bob Arning

Permit the world to be drawn with a gradient. Note that the world has a #color: method that sets the fillColor2 to be the same as color, thus eliminating the gradient. So, if you want to change the color and keep the gradient, calls to #color: should be followed by a call to #gradientFillColor:.

World color: Color green.
World gradientFillColor: Color lightGreen


!PasteUpMorph methodsFor: 'display' stamp: 'RAA 3/24/2000 07:04'!
pseudoDraw: aRectangle on: aCanvas

	| c style |
	c _ aCanvas copyClipRect: aRectangle.
	c fillColor: color.

	((color isKindOf: Color) and: [color ~= Color transparent and: [color ~= fillColor2]]) ifTrue: [
		style _ GradientFillStyle ramp: {0.0 -> color. 1.0 -> fillColor2}.
		style origin: self position.
		style direction: (gradientDirection == #vertical 
			ifTrue:[0 at self height] 
			ifFalse:[self width at 0]).
		aCanvas fillRectangle: aRectangle fillStyle: style.

	turtleTrailsForm ifNotNil: [c paintImage: turtleTrailsForm at: 0 at 0].
	^c! !

!PasteUpMorph methodsFor: 'misc' stamp: 'RAA 3/24/2000 07:01'!
drawInvalidAreasOn: aCanvas 
	"Redraw the damaged areas of the given canvas and clear the damage list. Return a collection of the areas that were redrawn."
	| rectList c i n mm morphs rects rectToFill remnants rect |

	rectList _ self damageRecorder invalidRectsFullBounds: ("0 at 0 extent:" self viewBox "extent").
	self damageRecorder reset.
	n _ self submorphs size.
	morphs _ OrderedCollection new: n*2.
	rects _ OrderedCollection new: n*2.
	rectList do: [:r |
			["Experimental top-down drawing --
			Traverses top to bottom, stopping if the entire area is filled.
			If only a single rectangle remains, then continue with the reduced rectangle."
			rectToFill _ r.
			i _ 1.
			[rectToFill == nil or: [i > n]] whileFalse:
				[mm _ submorphs at: i.
				((mm fullBounds intersects: r) and: [mm visible]) ifTrue:
					[morphs addLast: mm.  rects addLast: rectToFill.
					remnants _ mm areasRemainingToFill: rectToFill.
					remnants size = 1 ifTrue: [rectToFill _ remnants first].
					remnants size = 0 ifTrue: [rectToFill _ nil]].
				i _ i+1].

			"Now paint from bottom to top, but using the reduced rectangles."
			rectToFill ifNotNil:
				[c _ self pseudoDraw: rectToFill on: aCanvas].
			[morphs isEmpty] whileFalse:
				[(rect _ rects removeLast) == rectToFill ifFalse:
					[c _ aCanvas copyClipRect: (rectToFill _ rect)].
				morphs removeLast fullDrawOn: c].
			morphs reset.  rects reset]
		ifFalse: [c _ self pseudoDraw: r on: aCanvas.
				submorphs reverseDo: [:m | m fullDrawOn: c]]
	^ rectList! !

More information about the Squeak-dev mailing list