Last updated at 10:51 pm UTC on 25 July 2013
The ColorPickerMorph is instantiated and used in the method Morph changeColor:
sourceHand: self activeHand;
originalColor: self color;
putUpFor: self near: self fullBoundsInWorld
It brings up a rectangluar area from which the user can choose a color. Afterwards the target morph is set to this color.
''Creating your own colorpicker morph
The method #changeColor of Morph is a hook for adding your own colorpicker.
So instead of (a) above put something minimal in that method like:
target: self) openInWorld
With target self the morph to be recolored is meant.
A working example:
"Change the color of the receiver -- triggered, e.g. from a menu"
| m |
m _ Morph new.
m color: Color transparent.
m layoutPolicy: TableLayout new.
m hResizing: #shrinkwrap.
m vResizing: #shrinkwrap.
m addMorphBack: (ColorSelectorMorph newWithColor: *2308* red forTarget: self).
m addMorphBack: (ColorSelectorMorph newWithColor: Color green forTarget: self).
m addMorphBack: (ColorSelectorMorph newWithColor: Color blue forTarget: self).
m addMorphBack: (ColorSelectorMorph newWithColor: Color yellow forTarget: self).
m addMorphBack: (ColorSelectorMorph newWithColor: Color white forTarget: self).
m addMorphBack: (ColorSelectorMorph newWithColor: Color black forTarget: self).
m addMorphBack: (ColorSelectorMorph newWithColor: Color brown forTarget: self).
m addMorphBack: (ColorSelectorMorph newWithColor: Color orange forTarget: self).
m addMorphBack: (ColorSelectorMorph newWithColor: Color magenta forTarget: self).
The class ColorSelectorMorph is a custom made class like the one below (select the code and choose 'file-in')
'From Squeak3.3alpha of 30 January 2002 [latest update: #4798] on 14 March 2002 at 1:46:38 pm'!
EllipseMorph subclass: #ColorSelectorMorph
instanceVariableNames: 'target '
module: #(Squeak Morphic Core Basic)!
!ColorSelectorMorph methodsFor: 'accessing' stamp: 'HJH 3/14/2002 13:03'!
target _ aMorph! !
!ColorSelectorMorph methodsFor: 'event handling' stamp: 'HJH 3/14/2002 13:11'!
See How to add a mouse-up action in your own subclass of Morph
!ColorSelectorMorph methodsFor: 'event handling' stamp: 'HJH 3/14/2002 13:18'!
target color: self color.
self owner delete.
"– – – – – – – – – – – – – – – – – – "!
!ColorSelectorMorph class methodsFor: 'as yet unclassified' stamp: 'HJH 3/14/2002 13:26'!
newWithColor: aColor forTarget: aMorph
| c |
c _ super new.
c color: aColor.
c extent: 50 @ 50.
c target: aMorph.
To activate the your own color picker morph make sure that the preference "propertySheetFromHalo" is unchecked.
Recommendations for other ways of implementing your own color picker morph see below.
From: Scott Wallace
Subject: Re: [Q] Larger color picker with fewer colors
Date: Wed, 13 Mar 2002 11:46:25 -0800
From the Squeakland mailing list...
At 8:32 AM +0100 3/13/02, Hannes Hirzel wrote:
>How do I change the current color picker for assigning colors to morphs?
>For an image I'm configuring I would like to have a fairly large color
>picker with just a dozen colors (12 EllipseMorphs of different colors to
>And I would also like that the third and fourth color chooser (which are
>grayed out) do not show up.
>How do I do that? (preferably with a preference setting)
First of all, be aware that when you click on the "recolor" handle,
you can get a simple color-picker rather than the huge "property
sheet" – this is under control of a preference,
"propertySheetFromHalo". For your application, you'll almost surely
want to set this preference to false.
But you still want to create a custom color-picker that has a small
number of oversize swatches. For this, you, or someone, will need to
write a little code.
I think Color class method #colorPaletteForDepth:extent: is probably
the first place to look, because that's where the existing color
picker is constructed.
A reasonable way to start would be to define your own
ColorPickerMorph subclass, and in it write the code that defines your
custom picker's appearance; you can try to adapt the code in
from scratch. (If you only want a dozen colors, you probably also
- colorPaletteForDepth:extent:, or perhaps just write your own code
don't want the clutter and the complexity of the "translucency" are.)
Next, perhaps a good place to thread your new picker into your user's
experience is to modify method Morph.changeColor, such that instead
of launching a ColorPickerMorph, it instead launches a
Or, alternatively, modify Blue button method #doRecolor:with:.
If you were to bring this topic up in a message to the Squeak
Developers List, I imagine that several people there would quickly
offer advice, encouragement, and probably also actual code for
creating your custom color picker.
PS: If you have "propertySheetFromHalo" set to false, you can still
get the big property sheet, on those occasions when you want it, by
holding down the shift key as you click on the "recolor" handle.
And conversely, if propertySheetFromHalo is true, you can still get
the simple picker by holding down the shift key as you click on the