'From etoys2.1 of 26 July 2007 [latest update: #1638] on 14 September 2007 at 1:46:41 pm'! "Change Set: ColoPickerSize-tak Date: 14 September 2007 Author: Takashi Yamamiya Color picker's buttons become larger." ScriptingSystem formDictionary at: #'PickerX' put: ( (GIFReadWriter on: (Base64MimeConverter mimeDecodeToBytes: 'R0lGODlhDwAPAJEAAAAAAP///////wAAACH5BAUUAAIALAAAAAAPAA8AAAIclI+py42QoAL0 UBnrbbe6/XWc5mUYGKXOyrZGAQA7' readStream) readStream) nextImage). ScriptingSystem formDictionary at: #'PickerPlus' put: ( (GIFReadWriter on: (Base64MimeConverter mimeDecodeToBytes: 'R0lGODlhDwAPAJEAAAAAAP///////wAAACH5BAUUAAIALAAAAAAPAA8AAAIblI+py+CMHIBH UmOX3Dty7n2ZMkJl81znxTIFADs=' readStream) readStream) nextImage). ScriptingSystem formDictionary at: #'PickerHand' put: ( (GIFReadWriter on: (Base64MimeConverter mimeDecodeToBytes: 'R0lGODlhDwAPAJEAAAAAAP///////wAAACH5BAUUAAIALAAAAAAPAA8AAAIglI+pu+APmoh0 qoqTs/nkblQXEjFlyFikNK4mlMZyUgAAOw==' readStream) readStream) nextImage). ! SketchMorph subclass: #ColorPickerMorph instanceVariableNames: 'selectedColor sourceHand deleteOnMouseUp updateContinuously target selector argument originalColor theSelectorDisplayMorph command isModal clickedTranslucency noChart ' classVariableNames: 'ColorChart DragBox FeedbackBox OpenFullBox RevertBox TransparentBox TransText DeleteBox ' poolDictionaries: '' category: 'Morphic-Widgets'! !Color class methodsFor: 'color from user' stamp: 'tak 9/12/2007 13:51'! colorPaletteCaptionHeight ^ 20! ! !Color class methodsFor: 'color from user' stamp: 'tak 9/13/2007 10:04'! colorPaletteForDepth: depth extent: chartExtent "Display a palette of colors sorted horizontally by hue and vertically by lightness. Useful for eyeballing the color gamut of the display, or for choosing a color interactively." "Note: It is slow to build this palette, so it should be cached for quick access." "(Color colorPaletteForDepth: 16 extent: 190@60) display" | basicHue x y c startHue palette vSteps transCaption hSteps captionHeight | palette _ Form extent: chartExtent depth: depth. transCaption _ "(DisplayText text: 'no color' asText textStyle: (TextConstants at: #ComicPlain)) form storeString" (Form extent: 34@9 depth: 1 fromArray: #(0 0 256 0 256 0 3808663859 2147483648 2491688266 2147483648 2491688266 0 2491688266 0 2466486578 0 0 0) offset: 0@0). captionHeight := self colorPaletteCaptionHeight. palette fillWhite: (0@0 extent: palette width@captionHeight). palette fillBlack: (0@captionHeight extent: palette width@1). transCaption displayOn: palette at: palette boundingBox topCenter - ((transCaption width // 2)@0). startHue _ 338.0. vSteps _ palette height - captionHeight // 2. hSteps _ palette width - self colorPaletteGrayWidth. x _ 0. startHue to: startHue + 360.0 by: 360.0/hSteps do: [:h | basicHue _ Color h: h asFloat s: 1.0 v: 1.0. y _ captionHeight+1. 0 to: vSteps do: [:n | c _ basicHue mixed: (n asFloat / vSteps asFloat) with: Color white. palette fill: (x@y extent: 1@1) fillColor: c. y _ y + 1]. 1 to: vSteps do: [:n | c _ Color black mixed: (n asFloat / vSteps asFloat) with: basicHue. palette fill: (x@y extent: 1@1) fillColor: c. y _ y + 1]. x _ x + 1]. y _ captionHeight + 1. 1 to: vSteps * 2 do: [:n | c _ Color black mixed: (n asFloat / (vSteps*2) asFloat) with: Color white. palette fill: (x@y extent: self colorPaletteGrayWidth @1) fillColor: c. y _ y + 1]. ^ palette ! ! !Color class methodsFor: 'color from user' stamp: 'tak 9/13/2007 10:01'! colorPaletteGrayWidth ^ 20! ! !ColorPickerMorph methodsFor: 'accessing' stamp: 'tak 9/12/2007 20:14'! originalColor: colorOrSymbol "Set the receiver's original color. It is at this point that a command is launched to represent the action of the picker, in support of Undo." originalColor := (colorOrSymbol isColor) ifTrue: [colorOrSymbol] ifFalse: [Color lightGreen]. originalForm fill: (RevertBox insetBy: 2) fillColor: originalColor. selectedColor := originalColor. self updateAlpha: originalColor alpha. self locationIndicator center: self topLeft + (self positionOfColor: originalColor)! ! !ColorPickerMorph methodsFor: 'event handling' stamp: 'tak 9/14/2007 13:28'! mouseDown: evt "The mouse went down in the picker; process it." | localPt | localPt _ evt cursorPoint - self topLeft. self deleteAllBalloons. clickedTranslucency _ TransparentBox containsPoint: localPt. self inhibitDragging ifFalse: [ (DragBox containsPoint: localPt) ifTrue: [^ evt hand grabMorph: self]. ]. (RevertBox containsPoint: localPt) ifTrue: [^ self updateColor: originalColor feedbackColor: originalColor]. self inhibitDragging ifFalse: [self comeToFront]. sourceHand _ evt hand. self startStepping. ! ! !ColorPickerMorph methodsFor: 'geometry' stamp: 'tak 9/14/2007 11:37'! slopeBox ^ TransparentBox insetBy: 20@0! ! !ColorPickerMorph methodsFor: 'initialization' stamp: 'tak 9/14/2007 11:32'! buildChartForm | chartForm | chartForm _ ColorChart deepCopy asFormOfDepth: Display depth. chartForm border: (self slopeBox insetBy: 0@2) width: 1 fillColor: Color lightGray. chartForm border: (TransparentBox insetBy: 4@2) width: 1. Display depth = 32 ifTrue: ["Set opaque bits for 32-bit display" chartForm fill: chartForm boundingBox rule: Form under fillColor: (Color r: 0.0 g: 0.0 b: 0.0 alpha: 1.0)]. chartForm borderWidth: 1. self form: chartForm. selectedColor ifNotNil: [self updateAlpha: selectedColor alpha]. self updateSelectorDisplay. ! ! !ColorPickerMorph methodsFor: 'initialization' stamp: 'tak 9/14/2007 13:30'! initializeModal: beModal "Initialize the receiver. If beModal is true, it will be a modal color picker, else not" isModal _ beModal. self removeAllMorphs. self addMorph: (IconicButton new borderWidth: 0; labelGraphic: (ScriptingSystem formAtKey: #PickerX); color: Color transparent; actionSelector: #deleteBoxHit; target: self; useSquareCorners; bounds: (DeleteBox translateBy: self topLeft); setCenteredBalloonText: 'dismiss color picker' translated). self addMorph: (IconicButton new borderWidth: 0; labelGraphic: (ScriptingSystem formAtKey: #PickerHand); color: Color transparent; bounds: (DragBox translateBy: self topLeft); lock: true; setCenteredBalloonText: 'move this color-picker to another position, and keep it on the screen until dismissed with the X button ' translated). self addMorph: ((Morph newBounds: (RevertBox translateBy: self topLeft)) color: Color transparent; setCenteredBalloonText: 'restore original color' translated). self addMorph: ((Morph newBounds: (FeedbackBox translateBy: self topLeft)) color: Color transparent; setCenteredBalloonText: 'shows selected color' translated). self addMorph: ((Morph newBounds: (TransparentBox translateBy: self topLeft)) color: Color transparent; setCenteredBalloonText: 'adjust translucency' translated). self addMorph: (IconicButton new borderWidth: 0; labelGraphic: (ScriptingSystem formAtKey: #PickerPlus); color: Color transparent; actionSelector: #openPropertySheet; target: self; useSquareCorners; bounds: (OpenFullBox translateBy: self topLeft); setCenteredBalloonText: 'open a full property sheet' translated; yourself). self buildChartForm. selectedColor ifNil: [selectedColor _ Color white]. sourceHand _ nil. deleteOnMouseUp _ false. updateContinuously _ true. ! ! !ColorPickerMorph methodsFor: 'private' stamp: 'tak 9/14/2007 10:55'! pickColorAt: aGlobalPoint | alpha selfRelativePoint pickedColor c | clickedTranslucency ifNil: [clickedTranslucency _ false]. selfRelativePoint _ (self globalPointToLocal: aGlobalPoint) - self topLeft. (FeedbackBox containsPoint: selfRelativePoint) ifTrue: [^ self]. (RevertBox containsPoint: selfRelativePoint) ifTrue: [^ self updateColor: originalColor feedbackColor: originalColor]. "check for transparent color and update using appropriate feedback color " (TransparentBox containsPoint: selfRelativePoint) ifTrue: [clickedTranslucency ifFalse: [^ self]. "Can't wander into translucency control" alpha _ (selfRelativePoint x - self slopeBox left) asFloat / self slopeBox width min: 1.0 max: 0.0. "(alpha roundTo: 0.01) printString , ' ' displayAt: 0@0." " -- debug" self updateColor: (selectedColor alpha: alpha) feedbackColor: (selectedColor alpha: alpha). ^ self]. "pick up color, either inside or outside this world" clickedTranslucency ifTrue: [^ self]. "Can't wander out of translucency control" self locationIndicator visible: false. self refreshWorld. pickedColor _ Display colorAt: aGlobalPoint. c _ self getColorFromKedamaWorldIfPossible: aGlobalPoint. c ifNotNil: [pickedColor _ c]. self locationIndicator visible: true. self refreshWorld. self updateColor: ( (selectedColor isColor and: [selectedColor isTranslucentColor]) ifTrue: [pickedColor alpha: selectedColor alpha] ifFalse: [pickedColor] ) feedbackColor: pickedColor! ! !ColorPickerMorph methodsFor: 'private' stamp: 'tak 9/13/2007 10:10'! positionOfColor: aColor "Compute the position of the given color in the color chart form" | rgbRect x y h s v | rgbRect _ (0@0 extent: originalForm boundingBox extent) insetBy: (1@ Color colorPaletteCaptionHeight corner: Color colorPaletteGrayWidth + 1 @1). h _ aColor hue. s _ aColor saturation. v _ aColor brightness. h = 0.0 ifTrue:["gray" ^(rgbRect right + (Color colorPaletteGrayWidth // 2)) @ (rgbRect height * (1.0 - v) + rgbRect top)]. x _ (h + 22 \\ 360 / 360.0 * rgbRect width) rounded. y _ 0.5. s < 1.0 ifTrue:[y _ y - (1.0 - s * 0.5)]. v < 1.0 ifTrue:[y _ y + (1.0 - v * 0.5)]. y _ (y * rgbRect height) rounded. ^x@y + (1 @ Color colorPaletteCaptionHeight)! ! !ColorPickerMorph methodsFor: 'private' stamp: 'tak 9/14/2007 13:08'! updateAlpha: alpha | sliderRect alphaPos | sliderRect := self slopeBox insetBy: 1@3. alphaPos := sliderRect left + (alpha*sliderRect width) rounded. originalForm fill: (sliderRect withRight: alphaPos) fillColor: Color lightGray. originalForm fillWhite: (sliderRect withLeft: alphaPos). originalForm fill: (self slopeBox topRight + (0 @ 3) corner: TransparentBox bottomRight + (-5@-3)) fillColor: (alpha < 1.0 ifTrue: [Color white] ifFalse: [Color lightGray]). TransText displayOn: originalForm at: (TransText boundingBox align: TransText boundingBox center with: TransparentBox center) topLeft rule: Form paint. ! ! !ColorPickerMorph methodsFor: 'private' stamp: 'tak 9/12/2007 20:12'! updateColor: aColor feedbackColor: feedbackColor "Set my selected color to the given color if it is different. Give user feedback. Inform the target of the change if the target and selector are not nil." selectedColor = aColor ifTrue: [^ self]. "do nothing if color doesn't change" self updateAlpha: aColor alpha. originalForm fill: (FeedbackBox insetBy: 2) fillColor: feedbackColor. self form: originalForm. selectedColor _ aColor. updateContinuously ifTrue: [self updateTargetColor]. self locationIndicator center: self topLeft + (self positionOfColor: feedbackColor).! ! !ColorPickerMorph class methodsFor: 'class initialization' stamp: 'tak 9/12/2007 19:32'! buttonSize ^ 20 @ Color colorPaletteCaptionHeight! ! !ColorPickerMorph class methodsFor: 'class initialization' stamp: 'tak 9/14/2007 11:26'! initialize "Initialize the class-variables that hold the color chart and various rectangles defining the different areas of the picker, and get the wording for 'transprent' installed in TransText, in the current language." | captionHeight buttonSize | captionHeight := Color colorPaletteCaptionHeight. buttonSize := self buttonSize. ColorChart _ Color colorPaletteForDepth: 16 extent: 240@200. DeleteBox _ 0@0 extent: buttonSize. DragBox _ buttonSize x @0 extent: buttonSize. OpenFullBox _ ((ColorChart width - (buttonSize x * 3)) @ 1) extent: buttonSize - 1. RevertBox _ ((ColorChart width - (buttonSize x * 2)) ) @ 1 extent: buttonSize - 1. FeedbackBox _ ((ColorChart width - (buttonSize x * 1))) @ 1 extent: buttonSize - 1. TransparentBox _ (buttonSize x * 2) @ 1 corner: (ColorChart width - (buttonSize x * 3) @ captionHeight). ColorChart fillWhite: TransparentBox. self localeChanged. " ColorPickerMorph initialize. "! ! ColorPickerMorph initialize! SketchMorph subclass: #ColorPickerMorph instanceVariableNames: 'selectedColor sourceHand deleteOnMouseUp updateContinuously target selector argument originalColor theSelectorDisplayMorph command isModal clickedTranslucency noChart' classVariableNames: 'ColorChart DeleteBox DragBox FeedbackBox OpenFullBox RevertBox TransparentBox TransText' poolDictionaries: '' category: 'Morphic-Widgets'! !ColorPickerMorph reorganize! ('accessing' argument argument: deleteOnMouseUp deleteOnMouseUp: locationIndicator originalColor: selectedColor selector selector: sourceHand sourceHand: target target: updateContinuously updateContinuously:) ('drawing' drawOn:) ('e-toy support' isCandidateForAutomaticViewing openPropertySheet) ('event handling' deleteBoxHit handlesMouseDown: inhibitDragging mouseDown: mouseUp:) ('geometry' containsPoint: slopeBox) ('halos and balloon help' isLikelyRecipientForMouseOverHalos) ('initialization' buildChartForm choseModalityFromPreference initialize initializeForJustCursor initializeForPropertiesPanel initializeModal: updateSelectorDisplay) ('menu' addCustomMenuItems:hand: pickUpColorFor: toggleDeleteOnMouseUp toggleUpdateContinuously) ('other' addToWorld:near: bestPositionNear:inWorld: indicateColorUnderMouse putUpFor:near: trackColorUnderMouse) ('stepping and presenter' step) ('submorphs-add/remove' delete) ('testing' stepTime) ('private' anchorAndRunModeless: argumentsWith: deleteAllBalloons modalBalloonHelpAtPoint: pickColorAt: positionOfColor: trackColorAt: updateAlpha: updateColor:feedbackColor: updateTargetColor updateTargetColorWith:) ('copying' veryDeepFixupWith: veryDeepInner:) ('kedama' getColorFromKedamaWorldIfPossible:) !