Quote:
One nice touch may be to allow the user to type in a hex number and see the colour appear when they press the Return key?
This version does that - with the following caveat: if the user presses the enter key while the focus is on a control other than the hex color code edit control, the script will initiate its closing sequence.
Also, the script now checks whether the hex color value is already in the clipboard. If it is, the script will not ask the user if it should copy the value to the clipboard.
Code:
;Krappy Color Picker
;by Lego_coder / Miguel Agullo
;===============================================================
; Gui
gui, font,s14 w1000 cFF0000, Verdana
Gui, Add, Text, x20 y20, R
gui, font,s10 c000000 w400
Gui, Add, Edit, x45 y20 w40 +right limit3 number vRed_Value gChange_Red_Value,0
Gui, Add, UpDown, Range0-255 Wrap, 0
Gui, Add, Slider, x10 y50 w110 Range0-255 vRed_Slider gChange_Red_Slider ALtSubmit, 0
gui, font,s14 w1000 C00CC00
Gui, Add, Text, x20 y90, G
gui, font,s10 c000000 w400
Gui, Add, Edit, x45 y90 w40 +right limit3 number vGreen_Value gChange_Green_Value, 0
Gui, Add, UpDown, Range0-255 Wrap, 0
Gui, Add, Slider, x10 y120 w110 Range0-255 vGreen_Slider gChange_Green_Slider ALtSubmit, 0
gui, font,s14 w1000 C0000FF
Gui, Add, Text, x20 y160, B
gui, font,s10 c000000 w400
Gui, Add, Edit, x45 y160 w40 +right limit3 number vBlue_Value gChange_Blue_Value, 0
Gui, Add, UpDown, Range0-255 Wrap, 0
Gui, Add, Slider, x10 y190 w110 Range0-255 vBlue_Slider gChange_Blue_Slider ALtSubmit, 0
Gui, Add, ListView, x124 y20 h120 w120 ReadOnly 0x4000 +Background000000 VColor_Block lv0x800000
gui, font,s10 c000000 w400,
Gui, Add, text, x124 y160 +right, Hex:
Gui, Add, Edit, x161 y155 w81 h25 +right limit6 VColor_Value
Gui, Add, Button, x124 y196 w55 +center gGuiClose default, Ok
Gui, Add, Button, x190 y196 w55 +center gCopy_Hex_To_Clipboard, Copy
Gosub Show_New_Color
Gui, Show, x440 y329 h240 w260, Color Picker
Return
;===============================================================
;Closes gui or updates color from hex color edit box
GuiClose:
ControlGetFocus, Check_Control, Color Picker
if ErrorLevel = 0
ifequal,Check_Control,Edit4
{
gosub Change_Hex_Color_Code
return
}
else
GuiControlGet, Color_Value
ifnotequal,Clipboard,%Color_Value%
{
Gui +OwnDialogs
Msgbox,3,, Copy hex code to clipboard before exiting?
IfMsgBox, Yes
gosub Copy_Hex_To_Clipboard
else IfMsgBox, Cancel
Return
}
ExitApp
;===============================================================
;Sliders
Change_Red_Slider:
ifequal, Update_Hex_Flag
{
GuiControlGet, Red_Slider
GuiControl, Text, Red_Value, %Red_Slider%
gosub Show_New_Color
}
Return
Change_Green_Slider:
ifequal, Update_Hex_Flag
{
GuiControlGet, Green_Slider
GuiControl, Text, Green_Value, %Green_Slider%
Gosub Show_New_Color
}
Return
Change_Blue_Slider:
ifequal, Update_Hex_Flag
{
GuiControlGet, Blue_Slider
GuiControl, Text, Blue_Value, %Blue_Slider%
Gosub Show_New_Color
}
Return
;===============================================================
;Value boxes
Change_Red_Value:
ifequal, Update_Hex_Flag
{
GuiControlGet, Red_Value
GuiControl, Text, Red_Slider, %Red_Value%
Gosub Show_New_Color
}
Return
Change_Green_Value:
ifequal, Update_Hex_Flag
{
GuiControlGet, Green_Value
GuiControl, Text, Green_Slider, %Green_Value%
Gosub Show_New_Color
}
Return
Change_Blue_Value:
ifequal, Update_Hex_Flag
{
GuiControlGet, Blue_Value
GuiControl, Text, Blue_Slider, %Blue_Value%
Gosub Show_New_Color
}
Return
;===============================================================
;Update new color
Show_New_Color:
Gui submit, nohide
SetFormat, integer, hex
Red_Value += 0
Green_Value += 0
Blue_Value += 0
SetFormat, integer, d
Stringright,Red_Value,Red_Value,StrLen(Red_Value)-2
If (StrLen(Red_Value)=1)
Red_Value=0%Red_Value%
Stringright,Green_Value,Green_Value,StrLen(Green_Value)-2
If (StrLen(Green_Value)=1)
Green_Value=0%Green_Value%
Stringright,Blue_Value,Blue_Value,StrLen(Blue_Value)-2
If (StrLen(Blue_Value)=1)
Blue_Value=0%Blue_Value%
New_Color_Value=%Red_Value%%Green_Value%%Blue_Value%
GuiControl, Text, Color_Value, %New_Color_Value%
GuiControl, +Background%New_Color_Value%, Color_Block
Return
;===============================================================
;Copy hex color code to clipboard
Copy_Hex_To_Clipboard:
clipboard =
GuiControlGet, Color_Value
clipboard = %Color_Value%
Return
;===============================================================
;Changes hex color via direct (editcontrol) input
Change_Hex_Color_Code:
GuiControlGet, Color_Value
GuiControl, +Background%Color_Value%, Color_Block
sleep 50
PixelGetColor, New_Color_Value, 150, 100,RGB
StringTrimLeft, New_Color_Value, New_Color_Value, 2
GuiControl,, Color_Value,%New_Color_Value%
StringMid, Red_Value, New_Color_Value, 0, 2
StringMid, Green_Value, New_Color_Value, 3, 2
StringMid, Blue_Value, New_Color_Value, 5, 2
Red_Value=0x%Red_Value%
Green_Value=0x%Green_Value%
Blue_Value=0x%Blue_Value%
SetFormat, integer, d
Red_Value += 0
Green_Value += 0
Blue_Value += 0
SetFormat, integer, hex
Update_Hex_Flag=1
GuiControl, Text, Red_Slider, %Red_Value%
GuiControl, Text, Red_Value, %Red_Value%
GuiControl, Text, Green_Slider, %Green_Value%
GuiControl, Text, Green_Value, %Green_Value%
GuiControl, Text, Blue_Slider, %Blue_Value%
GuiControl, Text, Blue_Value, %Blue_Value%
Update_Hex_Flag=
return
Cheers