OpenColorPicker ( [red][,green][,blue][,title$] )

Parameters

red (optional) - starting red component, 0 to 255; 255 (default)

green (optional) - starting green component, 0 to 255; 255 (default)

blue (optional) - starting blue component, 0 to 255; 255 (default)

title$ (optional) - the picker's title, such as what is being coloured; "" shows "Colour" (default)

Description

Opens the colour picker without waiting, so your program can show each colour as it is chosen.

OpenColorPicker returns 1 at once and your loop carries on: it gets an event each time the colour changes, and one when the user closes the picker. A 3D preview, a light or a material can follow the picker while the user drags, which RequestColor cannot do because it waits. It returns 0, and opens nothing, while a picker is already open.

$2007 (colour changed): EventData is the new colour as $RRGGBB. Take it apart with (EventData() Shr 16) And 255 for red, (EventData() Shr 8) And 255 for green and EventData() And 255 for blue, or read RequestedRed, RequestedGreen and RequestedBlue. Changes your loop has not reached yet are merged, so a slow frame only ever sees the latest colour.

$2008 (picker closed): EventData is 1 for OK and 0 for Cancel. Cancel first sends a $2007 with the starting colour, so a program that just applies each change ends where it started. Use $2008 when the pick should become one undoable step, or to tidy up. Afterwards RequestedRed, RequestedGreen and RequestedBlue hold the chosen colour after OK, and the starting colour after Cancel.

While the picker is open your windows ignore the mouse and keyboard, as with a requester, and the begin and end-modal events ($2004 and $2005) arrive as it opens and closes. Your program keeps drawing, so canvases and 3D views stay live. CloseColorPicker closes it from your program.

The picker is the one RequestColor shows: on Windows a colour square and hue slider drawn in the GUI theme, with Hex, Red, Green and Blue fields and basic and recent colours; on macOS the system colour panel; on the web the browser's colour picker.

Local window=CreateWindow("Colour", 100, 100, 320, 160)
Local swatch=CreatePanel(20, 20, 120, 80, window, 1)
Local choose=CreateButton("Choose...", 160, 20, 120, 28, window)
Local red=200, green=80, blue=80
SetPanelColor swatch, red, green, blue
Repeat
    Select WaitEvent()
    Case $401
        If EventSource()=choose Then OpenColorPicker red, green, blue, "Swatch colour"
    Case $2007
        red=(EventData() Shr 16) And 255
        green=(EventData() Shr 8) And 255
        blue=EventData() And 255
        SetPanelColor swatch, red, green, blue
    Case $803
        End
    End Select
Forever

The Modern controls sample (10_Modern_Control_Showcase.bb) colours its 3D preview this way.

See also: CloseColorPicker, RequestColor, RequestedRed, EventData, SetPanelColor.

Index