[ENH] Antialiased Watch

Bert Freudenberg bert at isgnw.CS.Uni-Magdeburg.De
Thu May 18 09:30:19 UTC 2000


Hi Folks.

WatchMorph must be the most important 2.8 addition, at least measured in
number of updates ;-)

This one makes WatchMorph a subclass of EllipseMorph, and adds
antialiasing. Try a radial gradient from solid to transparent ...

-- Bert
-------------- next part --------------
'From Squeak2.8alpha of 18 January 2000 [latest update: #2158] on 18 May 2000 at 11:23:28 am'!
"Change Set:		WatchTweak-bf
Date:			17 May 2000
Author:			Bert Freudenberg

Makes WatchMorph a subclass of EllipseMorph, and adds antialiasing. Try a radial gradient from solid to transparent ..."!

EllipseMorph subclass: #WatchMorph
	instanceVariableNames: 'fontName cColor handsColor romanNumerals antialias '
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Morphic-Demo'!

!WatchMorph commentStamp: 'bf 5/17/2000 18:36' prior: 0!
This class is a representation of a watch.
The labels' font is changeble. Labels' font size increase or decrease when resizing me.

WatchMorph new openInWorld
(WatchMorph fontName: 'ComicPlain') openInWorld		" transparent "
(WatchMorph fontName: 'ComicBold' bgColor: Color white centerColor: Color black) openInWorld

Structure:
	fontName		String -- the labels' font name
	cColor			Color -- center color
	handsColor		Color
	romanNumerals	Boolean
	antialias		Boolean!

!WatchMorph methodsFor: 'initialization' stamp: 'bf 5/17/2000 18:47'!
initialize  "Establish all default parameters..."
	super initialize.
	self color: Color green.
	self handsColor: Color red.
	self centerColor: Color gray.
	romanNumerals _ false.
	antialias _ false.
	fontName _ 'NewYork'.
	self extent: 130 at 130.
	self start.! !

!WatchMorph methodsFor: 'accessing' stamp: 'bf 5/18/2000 11:06'!
antialias: aBoolean
	antialias _ aBoolean! !

!WatchMorph methodsFor: 'drawing' stamp: 'bf 5/18/2000 10:45'!
drawOn: aCanvas
	| pHour pMin pSec time |
	time _ Time now.
	pHour _ self radius: 0.6 hourAngle: time hours + (time minutes/60.0).
	pMin _ self radius: 0.72 hourAngle: (time minutes / 5.0).
	pSec _ self radius: 0.8 hourAngle: (time seconds / 5.0).

	antialias ifTrue: [
		aCanvas asBalloonCanvas
			aaLevel: 4;
			drawOval: (bounds insetBy: borderWidth // 2 + 1) color: self fillStyle
				borderWidth: borderWidth borderColor: borderColor;
			drawOval: (bounds insetBy: self extent*0.35) color: cColor
				borderWidth: 0 borderColor: Color black;
			drawPolygon: {self center. pHour}
				color: Color transparent borderWidth: 3 borderColor: handsColor;
			drawPolygon: {self center. pMin}
				color: Color transparent borderWidth: 2 borderColor: handsColor;
			drawPolygon: {self center. pSec}
				color: Color transparent borderWidth: 1 borderColor: handsColor]
		ifFalse: [
			super drawOn: aCanvas.
			aCanvas
				fillOval: (bounds insetBy: self extent*0.35) color: cColor;
				line: self center to: pHour width: 3 color: handsColor;
				line: self center to: pMin width: 2 color: handsColor;
				line: self center to: pSec width: 1 color: handsColor.]
! !

!WatchMorph methodsFor: 'menus' stamp: 'bf 5/18/2000 10:54'!
addCustomMenuItems: aCustomMenu hand: aHandMorph
	"Add morph-specific items to the given menu which was invoked by the given hand."

	super addCustomMenuItems: aCustomMenu hand: aHandMorph.
	aCustomMenu add: 'change font...' action: #changeFont.
	romanNumerals
		ifTrue: [aCustomMenu add: 'use latin numerals' action: #toggleRoman]
		ifFalse: [aCustomMenu add: 'use roman numerals' action: #toggleRoman].
	aCustomMenu add: 'toggle antialiasing' action: #toggleAntialias.
	aCustomMenu add: 'change hands color...' action: #changeHandsColor.
	aCustomMenu add: 'change center color...' action: #changeCenterColor! !

!WatchMorph methodsFor: 'menus' stamp: 'bf 5/17/2000 18:46'!
toggleAntialias

	antialias _ antialias not.
! !

"Postscript:
Initialize new inst var antialias"
WatchMorph allInstancesDo: [:m | m antialias: true]
!



More information about the Squeak-dev mailing list