[BUG][FIX] ScaleMorph

Russell Swan swan at hayman.cs.umass.edu
Tue Oct 26 20:57:15 UTC 1999


There is a problem in ScaleMorph with loop indices. If start is a
positive number, the scale rectangle is drawn from 0 to (start-stop), but
the tick marks and labels don't appear until start. Stop will also run
past the end, and the labels beyond the end of the rectangle all get
overwritten on the right hand side. Also, major ticks start on the start
value, instead of multiples of majorTickLength. These can all be seen by
evaluating

sm _ ((ScaleMorph new initialize extent: 400 at 100) start: 23 stop: 99
minorTick: 1
minorTickLength: 3 majorTick: 10 majorTickLength: 10 caption:'Scale' 
tickPrintBlock: [:v | v printString]) openInWorld

I changed drawOn: and buildLabels and it works better now.

'From Squeak2.6 of 11 October 1999 [latest update: #1559] on 25 October
1999 at 6:45:20 pm'!

!ScaleMorph methodsFor: 'as yet unclassified' stamp: 'RCS 10/25/1999
18:42'!
drawOn: aCanvas
	| scale x1 y1 y2 x y3 even yy loopStart checkStart |
	super drawOn: aCanvas.
	scale _ (self innerBounds width-1) / (stop-start) asFloat.
	x1 _ self innerBounds left.
	y1 _ self innerBounds bottom - 1.
	y2 _ y1 - minorTickLength.
	loopStart _ ((start / minorTick ) ceiling) * minorTick.
	loopStart to: stop by: minorTick do:
		[:v | x _ x1 + (scale*(v - start)).
		aCanvas line: x at y1 to: x at y2 width: 1 color: Color black].
	x1 _ self innerBounds left.
	y2 _ y1 - majorTickLength.
	y3 _ y1 - (minorTickLength+majorTickLength//2).
	even _ true.

	"Make sure mjor ticks start drawing on a multiple of majorTick"
	loopStart _ ((start / majorTick ) ceiling) * majorTick.
	checkStart _ ((start / (majorTick/2.0) ) ceiling) * majorTick.
	"Check to see if semimajor tick should be drawn before majorTick"
	( checkStart = (loopStart * 2) ) ifFalse:
			[ loopStart _ checkStart/2.0.
				even _ false. ].
	loopStart to: stop by: majorTick/2.0 do:
		[:v | x _ x1 + (scale*(v - start)).
		yy _ even ifTrue: [y2] ifFalse: [y3].
		aCanvas line: x at y1 to: x at yy width: 1 color: Color black.
		even _ even not].
! !


'From Squeak2.6 of 11 October 1999 [latest update: #1559] on 25 October
1999 at 6:45:14 pm'!

!ScaleMorph methodsFor: 'as yet unclassified' stamp: 'RCS 10/25/1999
18:42'!
buildLabels
	| scale x1 y1 y2 x captionMorph tickMorph loopStart |
	self removeAllMorphs.
	caption ifNotNil:
		[captionMorph _ StringMorph contents: caption.
		captionMorph align: captionMorph bounds bottomCenter
				with: self bounds bottomCenter -
(0 at majorTickLength)
						- (0@(captionMorph height
+ 2)).
		self addMorph: captionMorph].
	tickPrintBlock ifNotNil:
		[scale _ (self innerBounds width-1) / (stop-start)
asFloat.
		x1 _ self innerBounds left.
		y1 _ self innerBounds bottom.
		y2 _ y1 - majorTickLength.
		"Start loop on multiple of majorTick"
		loopStart _ ((start / majorTick ) ceiling) * majorTick.
		loopStart to: stop by: majorTick do:
			[:v | x _ x1 + (scale*(v - start)).
			tickMorph _ StringMorph contents: (tickPrintBlock
value: v).
			tickMorph align: tickMorph bounds bottomCenter
						with: x at y2.
			tickMorph left < self left ifTrue:
				[tickMorph position: self left at tickMorph
top].
			tickMorph right > self right ifTrue:
				[tickMorph position: (self right-tickMorph
width)@tickMorph top].
			self addMorph: tickMorph]]
! !





More information about the Squeak-dev mailing list