SelectColor Question?

Hi,
in the SelectColor example in the LR, the last parameter of line 4 seems to have no purpose - as the words “Select a Color” do not show anywhere???

Could someone please explain, why that is needed ?

Dim c as Color Dim b as Boolean c=CMY(.35,.9,.6) //choose the default color shown in color picker b=SelectColor(c,"Select a Color") Rectangle1.FillColor=c

[quote=104563:@Richard Summers]Hi,
in the SelectColor example in the LR, the last parameter of line 4 seems to have no purpose - as the words “Select a Color” do not show anywhere???

Could someone please explain, why that is needed ?

Dim c as Color Dim b as Boolean c=CMY(.35,.9,.6) //choose the default color shown in color picker b=SelectColor(c,"Select a Color") Rectangle1.FillColor=c[/quote]
The text is shown only on Linux-built apps - Windows and OS X ignore it.

Ah - just noticed that was stated in the LR. :frowning: Sorry!

Just one other question - when a user selects a colour in the Color Picker, which colour space gets returned - Hex, RGB, CMY ???
Or does it change dependant on how the user has their default OS X ColorPicker set up?

I need to save the colour which they choose, but do not know if the same colour space will always be returned (RGB, Hex etc.)

Thanks.

[quote=104566:@Richard Summers]Ah - thanks.

Just one other question - when a user selects a colour in the Color Picker, which colour space gets returned - Hex, RGB, CMY ???
Or does it change dependant on how the user has their default OS X ColorPicker set up?

I need to save the colour which they choose, but do not know if the same colour space will always be returned (RGB, Hex etc.)
[/quote]
You always get back a Color (the Xojo datatype). You can save that.

I know my code below will be wrong, but this is the best I can come up with.
I want to take c (the colour chosen by the ColorPicker), and then display its Hex value in a text field.

[code]Dim c as Color
Dim b as Boolean
c=RGB(99,0,0)
b=SelectColor(c,"")

Dim StrippedColorPickerValue As String = str(Mid(c, 3, 6)) // convert to a string and remove the “&c”
HexValue.text = StrippedColourPickerValue[/code]

Gulp
How wrong was that???

You can simply use Color’s properties. Try something like this:

dim c as color = &c630000

call selectColor(c, "")
dim v as variant = c
RgbValue.text = mid(v.stringValue, 5)

Thank you both - I will look at both of those solutions :slight_smile:

Would I then be correct in presuming that my hybrid code from both of you (below), would separate c into it’s separate components (both RGB and Hex)?

[code]dim c as color = RGB(99,0,0)
call selectColor(c, “”)

RedRGBValue.text = Str(c.red)
GreenRGBValue.text = Str(c.green)
BlueRGBValue.text = Str(c.blue)

dim v as variant = c

RedHexValue.text = str(Mid(v, 3, 2))
GreenHexValue.text = str(Mid(v, 5, 2))
BlueHexValue.text = str(Mid(v, 7, 2))[/code]

I wouldn’t rely on the magic of Variants to do this conversion for you. If you want to show the hex values, use something like this:

RedHexValue.text = Right("0"+Hex(c.red),2)

Like this:

[code]dim c as color = RGB(99,0,0)
call selectColor(c, “”)

RedRGBValue.text = Str(c.red)
GreenRGBValue.text = Str(c.green)
BlueRGBValue.text = Str(c.blue)

RedHexValue.text = Right(“0”+Hex(c.red),2)
GreenHexValue.text = Right(“0”+Hex(c.green),2)
BlueHexValue.text = Right(“0”+Hex(c.blue),2)[/code]

Just so I have understood Greg’s recommendation - this line:

GreenHexValue.text = Right("0"+Hex(c.green),2)

Will prefix a 0 to the c.green value, then copy those 2 characters (in a right to left direction), then set the result to the HexGreenValue.text?

Is that correct?
If so, there is a possibility that a 0 could be prefixed to a value such as 4B, when would then be invalid??
The default colour will be changed by the user.

Or have I mis-understood what Greg’s line of code does?

Ah - just realised that only the last 2 characters will be displayed in the text field - therefore an unneeded 0 at the beginning will be ignored.

The Right directive takes the rightmost characters from a string whereas your question assumes the Left directive which takes the leftmost characters.

So the answer to your question is no, the result will be the last two characters of the string.

Simon - I just noticed that and had already posted my realisation (just above your post) :slight_smile:
Thanks Simon, Gavin, Massimo and Greg :slight_smile: