Sign in to follow this  
Followers 0
Yashied

ColorChooser UDF

16 posts in this topic

#1 ·  Posted (edited)

LAST VERSION - 1.1

07-Dec-10

This library provides a dialog box to select a color in three color models - RGB (Red, Green, Blue), HSL (Hue, Saturation, Lightness), and HSB (Hue, Saturation, Brightness). This is not a program, this is a function that you can use in your scripts. This function is similar to the _ChooseColor() from Misc UDF library that is included in the AutoIt package. UDF is fully compatible with ColorPicker UDF (v1.5) and can be used as a custom function for a Color Chooser dialog box (see examples). Also there is a tool (pipette) to get the color from the screen. I recommend to first read description inside the library. Please play with this UDF and post any comments and suggestions.

ColorChooser.png

ColorChooser UDF Library v1.1

Previous downloads: 316

ColorChooser.au3

Example1

#Include <ColorChooser.au3>

Opt('MustDeclareVars', 1)

Global $hForm, $Msg, $Label, $Button, $Data, $Color = 0x50CA1B

$hForm = GUICreate('MyGUI', 170, 200)
$Label = GUICtrlCreateLabel('', 15, 15, 140, 140, $SS_SUNKEN)
GUICtrlSetBkColor(-1, $Color)
$Button = GUICtrlCreateButton('Select color...', 35, 166, 100, 23)
GUISetState()

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Button
            $Data = _ColorChooserDialog($Color, $hForm)
            If $Data > -1 Then
                GUICtrlSetBkColor($Label, $Data)
                $Color = $Data
            EndIf
    EndSwitch
WEnd

Example2 (required ColorPicker UDF)

#Include <ColorChooser.au3>
#Include <ColorPicker.au3>

Opt('MustDeclareVars', 1)

Global $hForm, $Msg, $Label, $Picker

$hForm = GUICreate('MyGUI', 170, 200)
$Label = GUICtrlCreateLabel('', 15, 15, 140, 140, $SS_SUNKEN)
GUICtrlSetBkColor(-1, 0x50CA1B)
$Picker = _GUIColorPicker_Create('', 55, 166, 60, 23, 0x50CA1B, BitOR($CP_FLAG_CHOOSERBUTTON, $CP_FLAG_MAGNIFICATION, $CP_FLAG_ARROWSTYLE), 0, -1, -1, 0, 'Simple Text', 'Custom...', '_ColorChooserDialog')
GUISetState()

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Picker
            GUICtrlSetBkColor($Label, _GUIColorPicker_GetColor($Picker))
    EndSwitch
WEnd
Edited by Yashied
1 person likes this

Share this post


Link to post
Share on other sites



This is quite nice. And useful.

Thanks


[Not using this account any more. Using "iShafayet" instead]

Share this post


Link to post
Share on other sites

The library has been updated.

v1.1

Changes

  • Added the following flags for more appearance changes and functionality of the dialog box.

    $CC_FLAG_SOLIDCOLOR

    $CC_FLAG_CAPTURECOLOR

    $CC_FLAG_USERCOLOR

    $CC_FLAG_DEFAULT

  • Added ability to save up to 20 color values, and use them in other programs that using this library (see $CC_FLAG_USERCOLOR).
  • Fixed several minor bugs.

Share this post


Link to post
Share on other sites

Yashid, I get the following errors when running example 1:

F:\AutoIt\Other People Projects and Examples\Yasheid\Color Choser UDF\ColorChooser.au3(1295,47) : ERROR: CP_WM_COMMAND(): undefined function.
        CP_WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
F:\AutoIt\Other People Projects and Examples\Yasheid\Color Choser UDF\ColorChooser.au3(1469,59) : ERROR: CP_WM_SETCURSOR(): undefined function.
        $Result = CP_WM_SETCURSOR($hWnd, $iMsg, $wParam, $lParam)

Share this post


Link to post
Share on other sites

Yashid, I get the following errors when running example 1...

With this code you also get an error, but the code is absolutely correct. Do not pay any attention to it.

If (IsDeclared('A')) And ($A = 1) Then
    MyFunc()
EndIf

:mellow:

Share this post


Link to post
Share on other sites

This requires really hard work. Thanks Yashied. I appreciate it...

Regards

Tip


[center]MsgBox_Tipped: Eye candy msgboxes/inputboxes/loginboxes. | CreateBlankBox: Semi-transparent layers with borders and rounded corners.[/center]

Share this post


Link to post
Share on other sites

when R = 250, G = 250, B = 250, return value of ColorChooser function is H = 160, S = 0, L = 240

why here H = 160, instead of H = 0 ?

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

when R = 250, G = 250, B = 250, return value of ColorChooser function is H = 160, S = 0, L = 240

why here H = 160, instead of H = 0 ?

When Saturation is 0 it really doesnt matter what the Hue is because its still going to be grey/black/white and its very common in this instance for the hue to be set to the center of the colour wheel which is 160 in this case.

EDIT: Freakn great UDF....the color picker tool is just gravy!

Edited by PAEz

Share this post


Link to post
Share on other sites

It's possible for _GUIColorPicker_GetColor() to return directly HSL or HSB not just RGB?


When the words fail... music speaks

Share this post


Link to post
Share on other sites

Andreik,

A quick search (you did do one before posting?) brought up this thread which looks as if it could be useful to you. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

I saw that post but I asked because the UI where you select the color let you see all this color spaces. Following the same logic I asked if wouldn't be good to have an option (second parameter as flag) to get the color in the desired format. :rolleyes:


When the words fail... music speaks

Share this post


Link to post
Share on other sites

for some reason the dialog is not returning a proper hexdecemel


All my projects live on github

Share this post


Link to post
Share on other sites

Nice tool, well done :thumbsup:

At least with AutoIt 3.3.12.0 a little patch is necessary:

; Search:
Global Const $CC_WM_SYSCOMMAND = 0x0112

; Insert below:
Global Const $ghGDIPDll = @SystemDir & '\GdiPlus.dll'

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0