 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Lego_Coder
Joined: 03 Dec 2005 Posts: 8
|
Posted: Sat Dec 03, 2005 2:06 am Post subject: Quick and dirty color picker |
|
|
Hi,
I'm only a few weeks old into this software and so far I've been loving it all the way!
I needed a color picker for a script and wrote this one. Not sure if it's of any interest, but here it goes:
UPDATED WITH SUGGESTIONS BELOW
Update 1 -Added Altsubmit to sliders
Update 2 -Added copy to clipboard function
| 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 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 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 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
gui, font,s10 c000000 w400,
Gui, Add, text, x124 y160 +right, Hex:
Gui, Add, Edit, x161 y155 w81 +right VColor_Value
Gui, Add, Button, x124 y196 w55 +center gGuiClose, 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
;===============================================================
;Gui Basics
GuiClose:
Msgbox,4,, Copy hex code to clipboard before exiting?
IfMsgBox, Yes
gosub Copy_Hex_To_Clipboard
ExitApp
;===============================================================
;Sliders
Change_Red_Slider:
GuiControlGet, Red_Slider
GuiControl, Text, Red_Value, %Red_Slider%
gosub Show_New_Color
Return
Change_Green_Slider:
GuiControlGet, Green_Slider
GuiControl, Text, Green_Value, %Green_Slider%
Gosub Show_New_Color
Return
Change_Blue_Slider:
GuiControlGet, Blue_Slider
GuiControl, Text, Blue_Value, %Blue_Slider%
Gosub Show_New_Color
Return
;===============================================================
;Value boxes
Change_Red_Value:
GuiControlGet, Red_Value
GuiControl, Text, Red_Slider, %Red_Value%
Gosub Show_New_Color
Return
Change_Green_Value:
GuiControlGet, Green_Value
GuiControl, Text, Green_Slider, %Green_Value%
Gosub Show_New_Color
Return
Change_Blue_Value:
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
|
Cheers
Last edited by Lego_Coder on Mon Dec 19, 2005 1:35 pm; edited 3 times in total |
|
| Back to top |
|
 |
Jesse
Joined: 01 Dec 2005 Posts: 37 Location: Los Angeles, CA
|
Posted: Sat Dec 03, 2005 2:18 am Post subject: |
|
|
Hey man nice work - only thing i didn't like was the colors didn't change as you moved the sliders. I did a little revision and came up with the following - not much added but check it out.
| Code: | ;Krappy Color Picker
;by Lego_coder / Miguel Agullo
settimer, checksliders, 25 ;function call for slider updates -jesse
;also removed slider calls below as it is done automatically now
;===============================================================
; 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 vRed_Value gChange_Red_Value,0
Gui, Add, UpDown, Range0-255 Wrap, 0
Gui, Add, Slider, x10 y50 w110 Range0-255 vRed_Slider , 0
gui, font,s14 w1000 C00CC00
Gui, Add, Text, x20 y90, G
gui, font,s10 c000000 w400
Gui, Add, Edit, x45 y90 w40 +right vGreen_Value gChange_Green_Value, 0
Gui, Add, UpDown, Range0-255 Wrap, 0
Gui, Add, Slider, x10 y120 w110 Range0-255 vGreen_Slider, 0
gui, font,s14 w1000 C0000FF
Gui, Add, Text, x20 y160, B
gui, font,s10 c000000 w400
Gui, Add, Edit, x45 y160 w40 +right vBlue_Value gChange_Blue_Value, 0
Gui, Add, UpDown, Range0-255 Wrap, 0
Gui, Add, Slider, x10 y190 w110 Range0-255 vBlue_Slider, 0
Gui, Add, ListView, x124 y20 h120 w120 ReadOnly 0x4000 +Background000000 VColor_Block
gui, font,s10 c000000 w400,
Gui, Add, Edit, x124 y155 w118 +right VColor_Value, 0
Gui, Add, Button, x124 y196 w118 +center gGuiClose, Ok
Gosub Show_New_Color
Gui, Show, x440 y329 h240 w260, Color Picker
Return
;===============================================================
;Gui Basics
checksliders: ;new funtion to constantly update sliders -jesse
GuiControlGet, Red_Slider
GuiControl, Text, Red_Value, %Red_Slider%
GuiControlGet, Green_Slider
GuiControl, Text, Green_Value, %Green_Slider%
GuiControlGet, Blue_Slider
GuiControl, Text, Blue_Value, %Blue_Slider%
Gosub Show_New_Color
return
GuiClose:
ExitApp
;===============================================================
;Sliders
GuiControlGet, Red_Slider
GuiControl, Text, Red_Value, %Red_Slider%
gosub Show_New_Color
GuiControlGet, Green_Slider
GuiControl, Text, Green_Value, %Green_Slider%
Gosub Show_New_Color
GuiControlGet, Blue_Slider
GuiControl, Text, Blue_Value, %Blue_Slider%
Gosub Show_New_Color
;===============================================================
;Value boxes
Change_Red_Value:
GuiControlGet, Red_Value
GuiControl, Text, Red_Slider, %Red_Value%
Gosub Show_New_Color
Return
Change_Green_Value:
GuiControlGet, Green_Value
GuiControl, Text, Green_Slider, %Green_Value%
Gosub Show_New_Color
Return
Change_Blue_Value:
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 |
_________________
 |
|
| Back to top |
|
 |
shimanov
Joined: 25 Sep 2005 Posts: 610
|
Posted: Sat Dec 03, 2005 4:02 am Post subject: |
|
|
I keep switching between different color mixers. This is a useful AHk solution.
You can also use the "AltSubmit" option to enable synchronous updates. Just add it to the "Gui, Add, Slider" lines. |
|
| Back to top |
|
 |
Lego_Coder
Joined: 03 Dec 2005 Posts: 8
|
Posted: Sat Dec 03, 2005 12:35 pm Post subject: |
|
|
Many thanks for the feedback! I feel dumb about failing to notice ALtSubmit. Oh well, that's what learning is all about.
I've updated the script in my first post. |
|
| Back to top |
|
 |
Rich
Joined: 28 Nov 2005 Posts: 10 Location: Michigan, USA
|
Posted: Tue Dec 06, 2005 7:39 pm Post subject: |
|
|
Extra points: add some function to copy the current Hex code  |
|
| Back to top |
|
 |
Lego_Coder
Joined: 03 Dec 2005 Posts: 8
|
Posted: Thu Dec 08, 2005 4:46 pm Post subject: |
|
|
Hmm ... I'm not sure what you mean by that, Rich.
As I said earlier, the reason I wrote this is because I am using it in a larger, fairly complex script (in fact, meant to be released as a stand-alone app). Clearly, there has to be a way for the color picker to pass the info back to the main program.
But I was under the impression that once you have a value showing on an edit box in a custom-made GUI (as is the case), it is a trivial matter to access that piece of data. Which is why I did not include that functionality in the script above, leaving for users to access it in ways that make sense with their scripts.
That said, if there is a way to make the picker more useful, I'll be happy to oblige
... that said, I am in the middle of writing that other larger app; so while I'll be happy to refine this script in simple ways, writing a full-blown color picker is not my highest priority at the moment. |
|
| Back to top |
|
 |
Rich
Joined: 28 Nov 2005 Posts: 10 Location: Michigan, USA
|
Posted: Fri Dec 16, 2005 8:46 pm Post subject: |
|
|
It's a really nice script, its just that I don't like having to highlight the Hex code and then right-click>copy. It seems like too many steps... I would rather just hit a 'copy' button and have that code copied to my clipboard for me.
No biggie, it was just a suggestion to make it easier to use. |
|
| Back to top |
|
 |
Lego_Coder
Joined: 03 Dec 2005 Posts: 8
|
Posted: Mon Dec 19, 2005 11:09 am Post subject: |
|
|
Hi again, Rich
That is actually a very reasonable suggestion. I've updated the script above and now it features a "Copy" button and it also asks if you want to copy the hex code to the clipboard upon exit.
Thanks for that!
(I guess I think of Autohotkey as more of a programming language than a scripting language due to the way I use it, and as a result improvements like this just fly by me) |
|
| Back to top |
|
 |
Rich
Joined: 28 Nov 2005 Posts: 10 Location: Michigan, USA
|
Posted: Mon Dec 19, 2005 6:31 pm Post subject: |
|
|
Thanks Lego!  |
|
| Back to top |
|
 |
Terrapin
Joined: 15 Aug 2005 Posts: 107 Location: North Carolina
|
Posted: Thu Dec 22, 2005 9:24 am Post subject: |
|
|
Hi Lego, I wanted to let you know that I've been tinkering with your color picker, hoping to use it in a little helper for Winamp. Since Winamp looks so colorful, and has options to easily change the colors, I thought my relatively sad-looking GUI could use some spicing up.
I actually have not done much in the way of modifying your code. But what I did was write a short function which calls the Color Picker, and returns Color_Value back to the caller. Then just used an #include.
I appreciate having your code to use in my little app.
Bob _________________ When it comes to Binary, there are 10 types of people. Those who get it and those who don't.  |
|
| Back to top |
|
 |
quatermass
Joined: 14 Dec 2005 Posts: 167
|
Posted: Tue Jan 31, 2006 3:53 pm Post subject: |
|
|
Nice colour viewer!
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? _________________ Stuart Halliday |
|
| Back to top |
|
 |
Lego_Coder
Joined: 03 Dec 2005 Posts: 8
|
Posted: Thu Feb 23, 2006 11:37 pm Post subject: |
|
|
| 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 |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10667
|
Posted: Fri Feb 24, 2006 12:37 am Post subject: |
|
|
| If this is an improved version of the original script, it's generally better to edit your top post so that visitors know which version is "best". |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6723 Location: France (near Paris)
|
Posted: Fri Feb 24, 2006 10:33 am Post subject: |
|
|
... and remove the duplicate code, to reduce the size of the topic and avoid confusion.
Suggestion: add GuiEscape: before GuiClose:, to allow closing your color picker with the Escape key.
Actually, in both cases (Escape or Close X button), I would avoid to ask any question, as users usually use these ways to Cancel the dialog. A Cancel button wouldn't hurt, too. When it is missing, the user feels like he is required to change something. _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
Guest
|
Posted: Fri Feb 24, 2006 12:56 pm Post subject: |
|
|
I agree with you, Chris. But the thing is ... I'm not sure if the latest version posted is the "best". It does include new features, but at a price (let's just say that I'm less satisfied with it than with previous versions), which is why I wanted to have both version available. I was posting late last night and I guess it slipped my mind to mention it.
PhiLho, many thanks for the suggestions. I'll look into them.
(And if I come up with a satisfying new version, I'll do my best to try and clean up the mess I made in this thread) |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|