AutoHotkey Community

It is currently May 27th, 2012, 10:50 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: October 17th, 2006, 6:53 am 
Offline

Joined: January 20th, 2006, 4:48 am
Posts: 29
Location: Colorado, USA
I recently made this because I only found one working eample of a color selector. I bet the second one (on autohotkey.net) was better, yet it doesnt seem to exist on the server. Anyway here it is:

Features:
-Shows RGB addition by seperating each color.
-Allows two colors to be saved
-Easily switches between the two colors using radio buttons.
-Writes rgb values of both to an ini file (or modify it to do something else)
-Updates the color demos dynamically, not on release of mouse.
-Tested bug-free on WinXp Pro
-Fast rendering (not a generated bitmap demo, yet a custom colored 100% progress bar!)

Limitations:
-No HSV, HSL support (maybe future work?)
-Does not allow manual input of values yet or accept saved values. (very likely future work; easy to do)

Code:
; Language:       English
; Platform:       Win9x/NT/XP
; Author:         A.D.Stokes <stokes91@gmail.com>
; Alias:          1991
; Basic color picker without HSV\HSL\etc. conversion.


setformat, integer, Hex
random, random1, 0, 0xFF
random, random2, 0, 0xFF
random, random3, 0, 0xFF

Gui, Add, Button, x128 y283 w66 h23 , OK
Gui, Add, Button, x200 y283 w66 h23 , Cancel

Gui, Add, Slider, x6 y15 w256 h30 vRedS Range0-255, 0
Gui, Add, Text, x144 y50 w36 h15, &Red:
Gui, Add, Text, x183 y50 w27 h20 vRedU cRed,

Gui, Add, Slider, x6 y75 w256 h30 vGreenS Range0-255, 0
Gui, Add, Text, x144 y110 w36 h15, &Green:
Gui, Add, Text, x183 y110 w27 h20 vGreenU cGreen,

Gui, Add, Slider, x6 y135 w256 h30 vBlueS Range0-255, 0
Gui, Add, Text, x144 y170 w36 h15, Bl&ue:
Gui, Add, Text, x183 y170 w27 h20 vBlueU cBlue,

Gui, Add, Text, x195 y203 w50 h20, Red
Gui, Add, Progress, x169 y203 w20 h20 vRedT cRed, 100

Gui, Add, Text, x195 y223 w50 h20, Green
Gui, Add, Progress, x169 y223 w20 h20 vGreenT cGreen, 100

Gui, Add, Text, x195 y243 w50 h20, Blue
Gui, Add, Progress, x169 y243 w20 h20 vBlueT cBlue, 100

Gui, Add, Radio, x18 y254 w55 h20 +checked vColor1 gchangecolor, Color 1
Gui, Add, Radio, x78 y254 w55 h20 gchangecolor, Color 2
Gui, Add, Progress, x14 y210 w60 h40 vAllT cBlack, 100
Gui, Add, Progress, x74 y210 w60 h40 vAllV cBlack, 100
Gui, Show, x223 y232 w274 h311, Color Selector

setTimer, checkcolors, 100
Return

checkcolors:
gui,submit,nohide
if Color1 = 1
 selectedradio=T
else
 selectedradio=V
setformat, integer, H
stringmid, HexRedS, RedS, 3, 2
stringmid, HexGreenS, GreenS, 3, 2
stringmid, HexBlueS, BlueS, 3, 2
HexRedS=00%HexRedS%
HexGreenS=00%HexGreenS%
HexBlueS=00%HexBlueS%
stringright, HexRedS, HexRedS,2
stringright, HexGreenS, HexGreenS,2
stringright, HexBlueS, HexBlueS,2
Guicontrol, +c%HexRedS%0000, RedT
Guicontrol, +c00%HexGreenS%00, GreenT
Guicontrol, +c0000%HexBlueS%, BlueT
Guicontrol, +c%HexRedS%%HexGreenS%%HexBlueS%, All%selectedradio%
setformat, integer, D
RedS:=RedS+0
GreenS:=GreenS+0
BlueS:=BlueS+0
Guicontrol, , BlueU, %BlueS%
Guicontrol, , GreenU, %GreenS%
Guicontrol, , RedU, %RedS%

colorR%selectedradio%=%RedS%
colorG%selectedradio%=%GreenS%
colorB%selectedradio%=%BlueS%

return

changecolor:
gui,submit,nohide
if Color1 = 1
 selectedradio=T
else
 selectedradio=V
colorR:=colorR%selectedradio%
colorG:=colorG%selectedradio%
colorB:=colorB%selectedradio%
Guicontrol, , RedS, %ColorR%
Guicontrol, , GreenS, %ColorG%
Guicontrol, , BlueS, %ColorB%
return

ButtonOk:
iniwrite, %colorRV%, colorpick.ini, Color2, Red
iniwrite, %colorGV%, colorpick.ini, Color2, Green
iniwrite, %colorBV%, colorpick.ini, Color2, Blue
iniwrite, %colorRT%, colorpick.ini, Color1, Red
iniwrite, %colorGT%, colorpick.ini, Color1, Green
iniwrite, %colorBT%, colorpick.ini, Color1, Blue
exitapp
return

ButtonCancel:
exitapp
return

GuiClose:
ExitApp


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 19th, 2006, 3:28 am 
Offline

Joined: January 20th, 2006, 4:48 am
Posts: 29
Location: Colorado, USA
Update 2 Features:
-Accepts, stores, and saves values! (New)
-Shows RGB addition by seperating each color.
-Allows two colors to be saved
-Easily switches between the two colors using radio buttons.
-Writes rgb values of both to an ini file (or modify it to do something else)
-Updates the color demos dynamically, not on release of mouse.
-Tested bug-free on WinXp Pro
-Fast rendering (not a generated bitmap demo, yet a custom colored 100% progress bar!)

Limitations:
-No HSV, HSL support (maybe future work? ...anyone know how?)

Code:

; Language:       English
; Platform:       Win9x/NT/XP
; Author:         A.D.Stokes <stokes91@gmail.com>
; Alias:          1991
; Basic color picker without HSV\HSL\etc. conversion.
if colorpickincluded<>1
{
colorpickincluded=0
}
opencolorbox:
Gui,3:destroy
iniread, Set1R, colorpick.ini, color1, Red
iniread, Set1G, colorpick.ini, color1, Green
iniread, Set1B, colorpick.ini, color1, Blue
iniread, Set2R, colorpick.ini, color2, Red
iniread, Set2G, colorpick.ini, color2, Green
iniread, Set2B, colorpick.ini, color2, Blue
color1all=%Set1R%%Set1G%%Set1B%
color2all=%Set2R%%Set2G%%Set2B%

Gui, 3:Add, Button, x128 y283 w66 h23 , OK
Gui, 3:Add, Button, x200 y283 w66 h23 , Cancel

Gui, 3:Add, Slider, x6 y15 w256 h30 vRedS Range0-255,0x%Set1R%
Gui, 3:Add, Text, x144 y50 w36 h15, &Red:
Gui, 3:Add, Text, x183 y50 w27 h20 vRedU cRed,

Gui, 3:Add, Slider, x6 y75 w256 h30 vGreenS Range0-255,0x%Set1G%
Gui, 3:Add, Text, x144 y110 w36 h15, &Green:
Gui, 3:Add, Text, x183 y110 w27 h20 vGreenU cGreen,

Gui, 3:Add, Slider, x6 y135 w256 h30 vBlueS Range0-255,0x%Set1B%
Gui, 3:Add, Text, x144 y170 w36 h15, Bl&ue:
Gui, 3:Add, Text, x183 y170 w27 h20 vBlueU cBlue,

Gui, 3:Add, Text, x195 y203 w50 h20, Red
Gui, 3:Add, Progress, x169 y203 w20 h20 vRedT cRed, 100

Gui, 3:Add, Text, x195 y223 w50 h20, Green
Gui, 3:Add, Progress, x169 y223 w20 h20 vGreenT cGreen, 100

Gui, 3:Add, Text, x195 y243 w50 h20, Blue
Gui, 3:Add, Progress, x169 y243 w20 h20 vBlueT cBlue, 100

Gui, 3:Add, Radio, x18 y254 w55 h20 vColor1 +checked gchangecolor, Color 1
Gui, 3:Add, Radio, x78 y254 w55 h20 gchangecolor, Color 2
Gui, 3:Add, Progress, x14 y210 w60 h40 vAllT c%color1all%, 100
Gui, 3:Add, Progress, x74 y210 w60 h40 vAllV c%color2all%, 100
Gui, 3:Show, x223 y232 w274 h311, Color Selector

setTimer, checkcolors, 100

Return

checkcolors:
gui, 3:submit,nohide
if Color1 = 1
 selectedradio=T
else
 selectedradio=V
setformat, integer, D
RedS:=RedS+0
GreenS:=GreenS+0
BlueS:=BlueS+0
HexRedS:=toHex(RedS,2)
HexGreenS:=toHex(GreenS,2)
HexBlueS:=toHex(BlueS,2)
Guicontrol, 3:+c%HexRedS%0000, RedT
Guicontrol, 3:+c00%HexGreenS%00, GreenT
Guicontrol, 3:+c0000%HexBlueS%, BlueT
Guicontrol, 3:+c%HexRedS%%HexGreenS%%HexBlueS%, All%selectedradio%

Guicontrol, 3:, BlueU, %BlueS%
Guicontrol, 3:, GreenU, %GreenS%
Guicontrol, 3:, RedU, %RedS%

Set%color1%R=%HexRedS%
Set%color1%G=%HexGreenS%
Set%color1%B=%HexBlueS%

return

changecolor:
gui, 3:submit,nohide
colorR:=Set%color1%R
colorG:=Set%color1%G
colorB:=Set%color1%B
Guicontrol, 3:, RedS, 0x%ColorR%
Guicontrol, 3:, GreenS, 0x%ColorG%
Guicontrol, 3:, BlueS, 0x%ColorB%
return

3ButtonOk:
if colorpickincluded=1
{
 color1out=%Set1R%%Set1G%%Set1B%
 color2out=%Set2R%%Set2G%%Set2B%

}
iniwrite, %Set1R%, colorpick.ini, Color1, Red
iniwrite, %Set1G%, colorpick.ini, Color1, Green
iniwrite, %Set1B%, colorpick.ini, Color1, Blue
iniwrite, %Set2R%, colorpick.ini, Color2, Red
iniwrite, %Set2G%, colorpick.ini, Color2, Green
iniwrite, %Set2B%, colorpick.ini, Color2, Blue
gui,3: cancel
gosub,update%colorpickincluded%
return

3ButtonCancel:
gui,3: cancel
if colorpickincluded=1
{
 color1out=NULL
 color2out=NULL
}
gosub,update%colorpickincluded%
return

3GuiClose:
gosub,update%colorpickincluded%
return

update0:
exitapp
return

toHex(input,padding=0)
{
 setformat,integer,H
 input:=input+0
 if padding>=1
 {
  stringtrimleft, input, input, 2
  stringlen, length, input
  toadd:=padding-length
  if toadd>=1
  {
   loop, %toadd%
   {
    input=0%input%
   }
  }
 }
 return %input%
}


This update now allows for easier compatibility with more gui windows, and also SAVES the info.


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

Joined: August 24th, 2005, 5:29 pm
Posts: 549
Location: Berlin / Germany
Nice peace of code, works fine. I'd suggest to use checkcolors: as a shared gLabel for the sliders and add the AltSubmit option to have direct response on slider moving without any timer.

THX, :D

_________________
nick :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 19th, 2006, 10:11 pm 
Offline

Joined: January 20th, 2006, 4:48 am
Posts: 29
Location: Colorado, USA
Good idea nick,
I added altsubmit, and the following appears to work fine:

Note: another bug has been fixed. When the user doesn't have a colorpick.ini, the sliders defaulted to 14.
Code:
; Language: English
; Platform: Win9x/NT/XP
; Author: A.D.Stokes <stokes91@gmail.com>
; Alias: 1991
; Basic color picker without HSV\HSL\etc. conversion.
if colorpickincluded<>1
{
colorpickincluded=0
}
opencolorbox:
Gui,3:destroy
iniread, Set1R, colorpick.ini, color1, Red,0
iniread, Set1G, colorpick.ini, color1, Green,0
iniread, Set1B, colorpick.ini, color1, Blue,0
iniread, Set2R, colorpick.ini, color2, Red,0
iniread, Set2G, colorpick.ini, color2, Green,0
iniread, Set2B, colorpick.ini, color2, Blue,0
color1all=%Set1R%%Set1G%%Set1B%
color2all=%Set2R%%Set2G%%Set2B%

Gui, 3:Add, Button, x128 y283 w66 h23 , OK
Gui, 3:Add, Button, x200 y283 w66 h23 , Cancel

Gui, 3:Add, Slider, x6 y15 w256 h30 vRedS Range0-255 gcheckcolors +altsubmit,0x%Set1R%
Gui, 3:Add, Text, x144 y50 w36 h15, &Red:
Gui, 3:Add, Text, x183 y50 w27 h20 vRedU cRed,

Gui, 3:Add, Slider, x6 y75 w256 h30 vGreenS Range0-255 gcheckcolors +altsubmit,0x%Set1G%
Gui, 3:Add, Text, x144 y110 w36 h15, &Green:
Gui, 3:Add, Text, x183 y110 w27 h20 vGreenU cGreen,

Gui, 3:Add, Slider, x6 y135 w256 h30 vBlueS Range0-255 gcheckcolors +altsubmit,0x%Set1B%
Gui, 3:Add, Text, x144 y170 w36 h15, Bl&ue:
Gui, 3:Add, Text, x183 y170 w27 h20 vBlueU cBlue,

Gui, 3:Add, Text, x195 y203 w50 h20, Red
Gui, 3:Add, Progress, x169 y203 w20 h20 vRedT cRed, 100

Gui, 3:Add, Text, x195 y223 w50 h20, Green
Gui, 3:Add, Progress, x169 y223 w20 h20 vGreenT cGreen, 100

Gui, 3:Add, Text, x195 y243 w50 h20, Blue
Gui, 3:Add, Progress, x169 y243 w20 h20 vBlueT cBlue, 100

Gui, 3:Add, Radio, x18 y254 w55 h20 vColor1 +checked gchangecolor, Color 1
Gui, 3:Add, Radio, x78 y254 w55 h20 gchangecolor, Color 2
Gui, 3:Add, Progress, x14 y210 w60 h40 vAllT c%color1all%, 100
Gui, 3:Add, Progress, x74 y210 w60 h40 vAllV c%color2all%, 100
Gui, 3:Show, x223 y232 w274 h311, Color Selector


Return

checkcolors:
gui, 3:submit,nohide
if Color1 = 1
selectedradio=T
else
selectedradio=V
setformat, integer, D
RedS:=RedS+0
GreenS:=GreenS+0
BlueS:=BlueS+0
HexRedS:=toHex(RedS,2)
HexGreenS:=toHex(GreenS,2)
HexBlueS:=toHex(BlueS,2)
Guicontrol, 3:+c%HexRedS%0000, RedT
Guicontrol, 3:+c00%HexGreenS%00, GreenT
Guicontrol, 3:+c0000%HexBlueS%, BlueT
Guicontrol, 3:+c%HexRedS%%HexGreenS%%HexBlueS%, All%selectedradio%

Guicontrol, 3:, BlueU, %BlueS%
Guicontrol, 3:, GreenU, %GreenS%
Guicontrol, 3:, RedU, %RedS%

Set%color1%R=%HexRedS%
Set%color1%G=%HexGreenS%
Set%color1%B=%HexBlueS%

return

changecolor:
gui, 3:submit,nohide
colorR:=Set%color1%R
colorG:=Set%color1%G
colorB:=Set%color1%B
Guicontrol, 3:, RedS, 0x%ColorR%
Guicontrol, 3:, GreenS, 0x%ColorG%
Guicontrol, 3:, BlueS, 0x%ColorB%
return

3ButtonOk:
if colorpickincluded=1
{
color1out=%Set1R%%Set1G%%Set1B%
color2out=%Set2R%%Set2G%%Set2B%

}
iniwrite, %Set1R%, colorpick.ini, Color1, Red
iniwrite, %Set1G%, colorpick.ini, Color1, Green
iniwrite, %Set1B%, colorpick.ini, Color1, Blue
iniwrite, %Set2R%, colorpick.ini, Color2, Red
iniwrite, %Set2G%, colorpick.ini, Color2, Green
iniwrite, %Set2B%, colorpick.ini, Color2, Blue
gui,3: cancel
gosub,update%colorpickincluded%
return

3ButtonCancel:
gui,3: cancel
if colorpickincluded=1
{
color1out=NULL
color2out=NULL
}
gosub,update%colorpickincluded%
return

3GuiClose:
gosub,update%colorpickincluded%
return

update0:
exitapp
return

toHex(input,padding=0)
{
setformat,integer,H
input:=input+0
if padding>=1
{
stringtrimleft, input, input, 2
stringlen, length, input
toadd:=padding-length
if toadd>=1
{
loop, %toadd%
{
input=0%input%
}
}
}
return %input%
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 19th, 2006, 11:22 pm 
Offline

Joined: September 3rd, 2006, 5:34 am
Posts: 601
Location: Iowa, U.S.
I must say I do like it. But what you should do is not just add to the ini file what color you just added, but every color you have done, in case you wish to see what the RGB value was.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 1st, 2007, 1:50 pm 
nice, but a msgbox missed :D



Code:
ButtonOk:
iniwrite, %colorRV%, colorpick.ini, Color2, Red
iniwrite, %colorGV%, colorpick.ini, Color2, Green
iniwrite, %colorBV%, colorpick.ini, Color2, Blue
iniwrite, %colorRT%, colorpick.ini, Color1, Red
iniwrite, %colorGT%, colorpick.ini, Color1, Green
iniwrite, %colorBT%, colorpick.ini, Color1, Blue



msgbox, Color1:c%Set1R%%Set1G%%Set1B%`nColor2:c%Set2R%%Set2G%%Set2B%
exitapp
return


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 44 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