AutoHotkey Community

It is currently May 27th, 2012, 5:18 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: December 3rd, 2005, 2:06 am 
Offline

Joined: December 3rd, 2005, 1:57 am
Posts: 8
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 December 19th, 2005, 1:35 pm, edited 3 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 3rd, 2005, 2:18 am 
Offline

Joined: December 1st, 2005, 7:04 pm
Posts: 37
Location: Los Angeles, CA
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   

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 3rd, 2005, 4:02 am 
Offline

Joined: September 25th, 2005, 4:31 pm
Posts: 610
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 3rd, 2005, 12:35 pm 
Offline

Joined: December 3rd, 2005, 1:57 am
Posts: 8
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 6th, 2005, 7:39 pm 
Offline

Joined: November 28th, 2005, 4:34 pm
Posts: 10
Location: Michigan, USA
Extra points: add some function to copy the current Hex code 8)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 8th, 2005, 4:46 pm 
Offline

Joined: December 3rd, 2005, 1:57 am
Posts: 8
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 8)

... 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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 16th, 2005, 8:46 pm 
Offline

Joined: November 28th, 2005, 4:34 pm
Posts: 10
Location: Michigan, USA
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 19th, 2005, 11:09 am 
Offline

Joined: December 3rd, 2005, 1:57 am
Posts: 8
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)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 19th, 2005, 6:31 pm 
Offline

Joined: November 28th, 2005, 4:34 pm
Posts: 10
Location: Michigan, USA
Thanks Lego! :D


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 22nd, 2005, 9:24 am 
Offline

Joined: August 15th, 2005, 7:15 am
Posts: 107
Location: North Carolina
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. :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 31st, 2006, 3:53 pm 
Offline

Joined: December 14th, 2005, 3:08 pm
Posts: 219
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 23rd, 2006, 11:37 pm 
Offline

Joined: December 3rd, 2005, 1:57 am
Posts: 8
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 24th, 2006, 12:37 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
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".


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 24th, 2006, 10:33 am 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
... 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.

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 24th, 2006, 12:56 pm 
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)


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Exabot [Bot], Google Feedfetcher and 12 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group