home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
European Smalltalk User Group 2004 September
/
esugcd.iso
/
Books-Tutorial-Lectures
/
Books
/
FreeBooks
/
GuzdialBookDrafts
/
clock-ui1.cs
< prev
next >
Wrap
Text File
|
2003-03-31
|
3KB
|
84 lines
'From Squeak 2.2 of Sept 23, 1998 on 9 October 1998 at 2:53:44 pm'!
Object subclass: #Clock
instanceVariableNames: 'time timer displayFormat position '
classVariableNames: ''
poolDictionaries: ''
category: 'ClockWorks'!
!Clock methodsFor: 'time management'!
addMinute
time _ time addTime: (Time fromSeconds: 60)
!
subtractHour
time _ time subtractTime: (Time fromSeconds: 60*60)
!
nextSecond
time _ time addTime: (Time fromSeconds: 1).
self timeDisplay.
!
addHour
time _ time addTime: (Time fromSeconds: 60*60)
!
subtractMinute
time _ time subtractTime: (Time fromSeconds: 60)
! !
!Clock methodsFor: 'interface-accessing'!
position: aPoint
position := aPoint.
!
position
^ position! !
!Clock methodsFor: 'window'!
catchEvents
| hourPlus hourMinus minutePlus minuteMinus click |
"Define the regions where we care about mouse clicks"
hourPlus _ (position x) @ ((position y)+100) extent: 100@50.
hourMinus _ ((position x)+100) @ ((position y)+100) extent: 100@50.
minutePlus _ (position x) @ ((position y)+150) extent: 100@50.
minuteMinus _ ((position x)+100) @ ((position y)+150) extent: 100@50.
"Enter into an event loop"
[Sensor yellowButtonPressed] whileFalse: "Yellow button press ends the clock"
["Give other processes a chance, and give user a chance to pick up."
(Delay forMilliseconds: 500) wait.
"self timeDisplay."
(Sensor redButtonPressed) ifTrue: "Red button press could go to a button"
[click _ Sensor mousePoint.
(hourPlus containsPoint: click) ifTrue: [self addHour].
(hourMinus containsPoint: click) ifTrue: [self subtractHour].
(minutePlus containsPoint: click) ifTrue: [self addMinute].
(minuteMinus containsPoint: click) ifTrue: [self subtractMinute].]].
!
openWindow
| pen |
"Open the blank frame"
(Form extent: 200@200) fillWhite displayAt: position.
"Draw the Buttons"
pen := Pen new.
pen up. pen goto: (position x) @ ((position y)+100). pen down.
pen north. pen turn: 90.
pen go: 200.
pen up. pen goto: (position x) @ ((position y)+150). pen down.
pen go: 200.
pen up. pen goto: ((position x)+100) @ ((position y)+100). pen down.
pen turn: 90.
pen go: 100.
'Hours +' displayAt: ((position x)+25) @ ((position y)+125).
'Hours -' displayAt: ((position x)+125) @ ((position y)+125).
'Minutes +' displayAt: ((position x)+25) @ ((position y)+175).
'Minutes -' displayAt: ((position x)+125) @ ((position y)+175).! !
!Clock methodsFor: 'timedisplay'!
timeDisplay
' ' displayAt: position + (50@50). "Erase whatever time was there before"
self display displayAt: position + (50 @ 50).! !