home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BURKS 2
/
BURKS_AUG97.ISO
/
BURKS
/
LANGUAGE
/
SMALTALK
/
TEXTBOOK
/
AP05.ST
(
.txt
)
< prev
next >
Wrap
Text File
|
1997-04-22
|
20KB
|
642 lines
'Smalltalk Textbook Appendix 05'!
EngiVariable subclass: #EngiColorModel
instanceVariableNames: ''
classVariableNames: 'MenuOfColorConstants MenuOfYellowButton RecentSelectedColor '
poolDictionaries: ''
category: 'Engi-Color'!
EngiColorModel comment:
'
Engi 0.01 (10 January 1994)
Copyright (C) 1994 by Atsushi Aoki
'!
!EngiColorModel methodsFor: 'initialize-release'!
initialize
self setValue: (ColorValue
hue: 0
saturation: 0
brightness: 1).
^self! !
!EngiColorModel methodsFor: 'accessing'!
brightness
^self value brightness!
brightness: brightnessValue
| brightness |
brightness := 0 max: (brightnessValue min: 1).
self setValue: (ColorValue
hue: self hue
saturation: self saturation
brightness: brightness).
brightness = 0
ifTrue:
[self changed: #hue.
self changed: #saturation].
self changed: #brightness.
self changed: #color!
hue
^self value hue!
hue: hueValue
| hue |
hue := 0 max: (hueValue min: 1).
self setValue: (ColorValue
hue: hue
saturation: self saturation
brightness: self brightness).
self changed: #hue.
self changed: #sturation.
self changed: #color!
hue: hueValue saturation: saturationValue brightness: brightnessValue
| hue saturation brightness |
hue := 0 max: (hueValue min: 1).
saturation := 0 max: (saturationValue min: 1).
brightness := 0 max: (brightnessValue min: 1).
self setValue: (ColorValue
hue: hue
saturation: saturation
brightness: brightness).
self changed: #hue.
self changed: #saturation.
self changed: #brightness.
self changed: #color!
saturation
^self value saturation!
saturation: saturationValue
| saturation |
saturation := 0 max: (saturationValue min: 1).
self setValue: (ColorValue
hue: self hue
saturation: saturation
brightness: self brightness).
saturation = 0 ifTrue: [self changed: #hue].
self changed: #saturation.
self changed: #color!
value: colorValue
colorValue isNil ifFalse: [self
hue: colorValue hue
saturation: colorValue saturation
brightness: colorValue brightness]! !
!EngiColorModel methodsFor: 'viewing'!
open
| colorView edgeDecorator topWindow |
colorView := EngiColorView on: self.
edgeDecorator := LookPreferences edgeDecorator on: colorView.
edgeDecorator noMenuBar.
edgeDecorator noVerticalScrollBar.
edgeDecorator noHorizontalScrollBar.
topWindow := EngiTopView
model: nil
label: 'Color'
minimumSize: 300 @ 100.
topWindow add: edgeDecorator in: (0 @ 0 corner: 1 @ 1).
topWindow open! !
!EngiColorModel methodsFor: 'adaptor'!
yellowButtonMenu
"EngiColorModel flushMenus."
| collection aMenu |
MenuOfYellowButton isNil
ifTrue:
[collection := OrderedCollection new.
collection add: 'copy' -> #copyColor.
collection add: 'print' -> #printColor.
aMenu := EngiMenuMaker fromCollection: collection.
MenuOfYellowButton := aMenu].
^MenuOfYellowButton! !
!EngiColorModel methodsFor: 'menu messages'!
copyColor
ParagraphEditor currentSelection: self printString asText!
printColor
Transcript cr; show: self printString! !
!EngiColorModel methodsFor: 'printing'!
printOn: aStream
aStream nextPutAll: '(ColorValue hue: '.
aStream nextPutAll: self hue asFloat printString.
aStream nextPutAll: ' saturation: '.
aStream nextPutAll: self saturation asFloat printString.
aStream nextPutAll: ' brightness: '.
aStream nextPutAll: self brightness asFloat printString.
aStream nextPutAll: ')'! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
EngiColorModel class
instanceVariableNames: ''!
!EngiColorModel class methodsFor: 'class initialization'!
flushMenus
"EngiColorModel flushMenus."
MenuOfColorConstants := nil.
MenuOfYellowButton := nil! !
!EngiColorModel class methodsFor: 'instance creation'!
new
^super new initialize! !
!EngiColorModel class methodsFor: 'view creation'!
open
"EngiColorModel open."
| colorModel |
colorModel := EngiColorModel new.
colorModel open.
^colorModel!
openOn: colorValue
"EngiColorModel openOn: ColorValue cyan."
| colorModel |
colorModel := EngiColorModel new.
colorModel value: colorValue.
colorModel open.
^colorModel! !
!EngiColorModel class methodsFor: 'utilities'!
select
"EngiColorModel select."
^self select: RecentSelectedColor!
select: defaultColorValue
"EngiColorModel select: ColorValue cyan."
| colorModel colorView edgeDecorator topView aBoolean |
colorModel := self new.
colorModel value: defaultColorValue.
colorView := EngiColorView on: colorModel.
edgeDecorator := LookPreferences edgeDecorator on: colorView.
edgeDecorator noMenuBar.
edgeDecorator noVerticalScrollBar.
edgeDecorator noHorizontalScrollBar.
topView := EngiTopView new.
topView minimumSize: 300 @ 140.
topView add: edgeDecorator in: (topView frameFraction: (0 @ 0 corner: 1 @ 1)).
aBoolean := topView popUp.
aBoolean
ifTrue:
[RecentSelectedColor := colorModel value.
^RecentSelectedColor]
ifFalse: [^nil]!
selectFromColorConstants
"EngiColorModel selectFromColorConstants."
| colorNames anIndex |
colorNames := ColorValue constantNames asSortedCollection asArray.
colorNames isEmpty ifTrue: [^nil].
MenuOfColorConstants isNil ifTrue: [MenuOfColorConstants := PopUpMenu labelList: (Array with: colorNames)].
anIndex := MenuOfColorConstants startUp.
anIndex > 0 ifTrue: [^ColorValue perform: (colorNames at: anIndex)].
^nil! !
!EngiColorModel class methodsFor: 'examples'!
example1
"EngiColorModel example1."
^EngiColorModel openOn: ColorValue green!
example2
"EngiColorModel example2."
| colorModel windowCreation |
colorModel := EngiColorModel new.
windowCreation :=
[| colorView edgeDecorator topWindow |
colorView := EngiColorView on: colorModel.
edgeDecorator := LookPreferences edgeDecorator on: colorView.
edgeDecorator noMenuBar.
edgeDecorator noVerticalScrollBar.
edgeDecorator noHorizontalScrollBar.
topWindow := EngiTopView
model: nil
label: 'Color'
minimumSize: 300 @ 100.
topWindow add: edgeDecorator in: (0 @ 0 corner: 1 @ 1).
topWindow].
3 timesRepeat: [windowCreation value open].
colorModel inspect.
^colorModel!
example3
"EngiColorModel example3."
^EngiColorModel select: ColorValue green! !
View subclass: #EngiColorView
instanceVariableNames: 'colorFrame hueFrame saturationFrame brightnessFrame hueImage saturationImage brightnessImage '
classVariableNames: ''
poolDictionaries: ''
category: 'Engi-Color'!
EngiColorView comment:
'
Engi 0.01 (10 January 1994)
Copyright (C) 1994 by Atsushi Aoki
'!
!EngiColorView methodsFor: 'controller accessing'!
defaultControllerClass
^EngiColorController! !
!EngiColorView methodsFor: 'bounds accessing'!
bounds: newBounds
super bounds: newBounds.
self computeFrames! !
!EngiColorView methodsFor: 'controlling'!
brightnessActivity
| aSensor graphicsContext saveCursor oldPoint newPoint insetFrame brightness colorValue |
aSensor := self controller sensor.
graphicsContext := self graphicsContext.
saveCursor := Cursor currentCursor.
oldPoint := nil.
[aSensor redButtonPressed and: [brightnessFrame containsPoint: (newPoint := aSensor cursorPoint)]]
whileTrue:
[Cursor currentCursor = Cursor crossHair ifFalse: [Cursor crossHair show].
newPoint = oldPoint
ifFalse:
[insetFrame := brightnessFrame insetBy: 1.
brightness := newPoint x - insetFrame origin x / insetFrame width.
brightness := 0 max: (brightness min: 1).
self displayBrightnessFrameOn: graphicsContext.
self displayBrightnessValue: brightness on: graphicsContext.
colorValue := ColorValue
hue: self model hue
saturation: self model saturation
brightness: brightness.
self displayColorValue: colorValue on: graphicsContext].
oldPoint := newPoint].
Cursor currentCursor = saveCursor ifFalse: [saveCursor show].
(brightnessFrame containsPoint: aSensor cursorPoint)
ifTrue: [brightness isNil ifFalse: [self model brightness: brightness]]
ifFalse:
[self displayBrightnessFrameOn: graphicsContext.
self displayBrightnessValueOn: graphicsContext.
self displayColorFrameOn: graphicsContext.
self displayColorValueOn: graphicsContext]!
colorActivity
|