'From Squeak3.7gamma of ''17 July 2004'' [latest update: #5976] on 13 September 2004 at 10:00:47 am'! "Change Set: ColorSelectorBiggerJMM Date: 13 September 2004 Author: johnmci@smalltalkconsulting.com As reported at ESUG2004 the choice for color in the color picker morphic, or the paint tool morphic was lousy. First it was 16 bit resolution, then it was limited to a couple of hundred colors. I changed the size to 360*180 + grey scale which gives 64980 colors along with changing the color spectum form from to 32 bits versus 16. I also fixed some lingering bugs in the morphic painting tool when it enforces selection boundaries for the color selection widget. Please note for perfect color a better tool would be required, one that would allow you to access millions of colors... "! !PaintBoxColorPicker commentStamp: 'JMM 9/13/2004 07:37' prior: 0! A pop-up, 32-bit color palette used as part of a PaintBoxMorph. ! !ColorPickerMorph methodsFor: 'menu' stamp: 'JMM 9/13/2004 09:41'! pickUpColorFor: aMorph "Show the eyedropper cursor, and modally track the mouse through a mouse-down and mouse-up cycle" | aHand localPt delay | aHand _ aMorph ifNil: [self activeHand] ifNotNil: [aMorph activeHand]. aHand ifNil: [aHand _ self currentHand]. self addToWorld: aHand world near: (aMorph ifNil: [aHand world]) fullBounds. self owner ifNil: [^ self]. aHand showTemporaryCursor: (ScriptingSystem formAtKey: #Eyedropper) hotSpotOffset: 6 negated @ 4 negated. "<<<< the form was changed a bit??" self updateContinuously: false. delay _ Delay forMilliseconds: 50. [Sensor anyButtonPressed] whileFalse: [self trackColorUnderMouse. delay wait]. self deleteAllBalloons. localPt _ Sensor cursorPoint - self topLeft. self inhibitDragging ifFalse: [ (DragBox containsPoint: localPt) ifTrue: ["Click or drag the drag-dot means to anchor as a modeless picker" ^ self anchorAndRunModeless: aHand]. ]. (clickedTranslucency _ TransparentBox containsPoint: localPt) ifTrue: [selectedColor _ originalColor]. self updateContinuously: true. [Sensor anyButtonPressed] whileTrue: [self updateTargetColorWith: self indicateColorUnderMouse]. aHand newMouseFocus: nil; showTemporaryCursor: nil; flushEvents. self delete. ! ! !ColorPickerMorph class methodsFor: 'class initialization' stamp: 'JMM 9/13/2004 09:26'! initialize "ColorPickerMorph initialize" ColorChart _ Color colorPaletteForDepth: 32 extent: (360+10)@(180+10). DragBox _ (11@0) extent: 9@8. RevertBox _ (ColorChart width - 20)@1 extent: 9@8. FeedbackBox _ (ColorChart width - 10)@1 extent: 9@8. TransparentBox _ DragBox topRight corner: RevertBox bottomLeft. ColorChart fillBlack: ((DragBox left - 1)@0 extent: 1@9). ColorChart fillBlack: ((TransparentBox left)@0 extent: 1@9). ColorChart fillBlack: ((FeedbackBox left - 1)@0 extent: 1@9). ColorChart fillBlack: ((RevertBox left - 1)@0 extent: 1@9). (Form dotOfSize: 5) displayOn: ColorChart at: DragBox center + (0@1). TransText _ (Form extent: 63@8 depth: 1 "Where there's a will there's a way..." fromArray: #(4194306 1024 4194306 1024 15628058 2476592640 4887714 2485462016 1883804850 2486772764 4756618 2485462016 4748474 1939416064 0 0) offset: 0@0). TransText _ ColorForm mappingWhiteToTransparentFrom: TransText ! ! !PaintBoxColorPicker methodsFor: 'event handling' stamp: 'JMM 9/13/2004 09:08'! selectColor: evt "Update the receiver from the given event. Constrain locOfCurrent's center to lie within the color selection area. If it is partially in the transparent area, snap it entirely into it vertically." | r | locOfCurrent := evt cursorPoint - self topLeft. r := Rectangle center: locOfCurrent extent: 9 @ 9. locOfCurrent := locOfCurrent + (r amountToTranslateWithin: (8 @ 11 corner: (self image width-6) @ (self image height-6))). locOfCurrent x > (self image width-(12+7)) ifTrue: [locOfCurrent := (self image width - 12) @ locOfCurrent y]. "snap into grayscale" currentColor := locOfCurrent y < 19 ifTrue: [locOfCurrent := locOfCurrent x @ 11. "snap into transparent" Color transparent] ifFalse: [image colorAt: locOfCurrent]. (owner isKindOf: PaintBoxMorph) ifTrue: [owner takeColorEvt: evt from: self]. self changed! ! !PaintBoxMorph methodsFor: 'actions' stamp: 'JMM 9/13/2004 09:47'! eyedropper: aButton action: aSelector cursor: aCursor evt: evt "Take total control and pick up a color!!!!" | pt feedbackColor delay | delay _ Delay forMilliseconds: 10. aButton state: #on. tool ifNotNil: [tool state: #off]. currentCursor := aCursor. evt hand showTemporaryCursor: currentCursor hotSpotOffset: 6 negated @ 4 negated. "<<<< the form was changed a bit??" feedbackColor := Display colorAt: Sensor cursorPoint. colorMemory align: colorMemory bounds topRight with: colorMemoryThin bounds topRight. self addMorphFront: colorMemory. "Full color picker" [Sensor anyButtonPressed] whileFalse: [pt := Sensor cursorPoint. "deal with the fact that 32 bit displays may have garbage in the alpha bits" feedbackColor := Display depth = 32 ifTrue: [Color colorFromPixelValue: ((Display pixelValueAt: pt) bitOr: 4278190080) depth: 32] ifFalse: [Display colorAt: pt]. "the hand needs to be drawn" evt hand position: pt. currentColor ~= feedbackColor ifTrue: [ currentColor _ feedbackColor. self showColor ]. self world displayWorldSafely. delay wait]. "Now wait for the button to be released." [Sensor anyButtonPressed] whileTrue: [ pt := Sensor cursorPoint. "the hand needs to be drawn" evt hand position: pt. self world displayWorldSafely. delay wait]. evt hand showTemporaryCursor: nil hotSpotOffset: 0 @ 0. self currentColor: feedbackColor evt: evt. colorMemory delete. tool ifNotNil: [tool state: #on. currentCursor := tool arguments third]. aButton state: #off ! ! !PaintBoxMorph methodsFor: 'recent colors' stamp: 'JMM 9/13/2004 09:26'! fixUpColorPicker | chart picker | chart _ ColorChart ifNil:[Cursor wait showWhile:[ColorChart _ (Color colorPaletteForDepth: 32 extent: (360+10)@(180+10))]]. chart getCanvas frameRectangle: chart boundingBox color: Color black. picker _ Form extent: (chart extent + (14@12)) depth: 32. picker fillWhite. "top" false ifTrue: [picker copy: (0@0 extent: picker width@6) from: (colorMemory image width - picker width)@0 in: colorMemory image rule: Form over. "bottom" picker copy: (0@ (picker height-6) extent: picker width@6) from: (colorMemory image width - picker width)@(colorMemory image height - 7) in: colorMemory image rule: Form over. "left" picker copy: (0@6 corner: 8@(picker height - 6)) from: (colorMemory image boundingBox topLeft + (0@6)) in: colorMemory image rule: Form over. "right" picker copy: (picker width-6@6 corner: picker width@(picker height - 6)) from: (colorMemory image boundingBox topRight - (6@-6)) in: colorMemory image rule: Form over.]. chart displayOn: picker at: 8@6. picker getCanvas frameRectangle: picker boundingBox color: Color black. colorMemory image: picker. ! ! !PaintBoxMorph class methodsFor: 'as yet unclassified' stamp: 'JMM 9/13/2004 09:26'! initializeColorChart "PaintBoxMorph initializeColorChart" ColorChart _ (Color colorPaletteForDepth: 32 extent: (360+10)@(180+10))! ! ColorPickerMorph initialize! "Postscript: Ensure we re-init the color picker and the paint box" ColorPickerMorph initialize. PaintBoxMorph initializeColorChart.!