AutoHotkey Community

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

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: December 16th, 2010, 4:12 pm 
Offline

Joined: February 22nd, 2009, 7:24 pm
Posts: 21
Location: Dallas TX
So this is something I whipped up while looking for a cool looking color picker on the forums for a project I'm working on.
Image
http://www.autohotkey.net/~jamixzol/colorpicker4ahk.jpg
It uses PixelGetColor on a splash GUI to use as a color picker. It's not super practical, but it catches the eye. A great deal of this script is from another color picker, which I cannot seem to locate the post now... :oops:
So if you recognize the tooltip box please post it here so I can link the post.

Everything else is in the source:
Code:
/*
Flashy and impractical color picker
Build (0.1)
Released (12.16.10)
Framework
(
Written in AHK_L (Version v1.0.48.05.L61)
www.autohotkey.net/~Lexikos/AutoHotkey_L
©2003-2009 Chris Mallett, portions ©AutoIt Team and various AHK community members
)
Platforms tested (XP_32+64)
Language (English native + os dependent)
Author (The Naked General _ jamixzol@gmail.com)


DEPENDENCIES:
the colorpicker4ahk.jpg located at www.autohotkey.net/~jamixzol/colorpicker4ahk.jpg
It is written in AHK_L COM compliant syntax

TEST ENVIRONMENT:
Built and tested in Windows XP X64 sp3. Written in AHL_L_10.48.05.L61 with SciTE4AHK

*/


; This uses the image as a pallet
Gui, -Caption +ToolWindow +LastFound +AlwaysOnTop
GUI, add, pic, , colorpicker4ahk.jpg ;assumed to be in the directory with the script
Gui, Show
Gui, Color, 000000
;WinSet, TransColor, FFFFFF (This didn't work lawls)

;This is the color frame initialization
Gui, 2:-Caption +ToolWindow +LastFound +AlwaysOnTop
Gui, 2:Font, s12 cBlack ;Set font size & color
Gui, 2:Add, Text, x5 y5 w75 center vupdatetxt, FFFFFF

;Initialize this if you call it from somewhere else
showpad=1

Loop
{
CoordMode, Mouse, Screen
MouseGetPos X, Y
PixelGetColor Color, X, Y, RGB
ColorD := Color ;build an int based variable
StringRight, color, color, 6 ;removes 0x prefix
SetFormat, IntegerFast, d
ColorD += 0  ; Sets Var (which previously contained 11) to be 0xb.
ColorD .= ""  ; Necessary due to the "fast" mode.

Gui, 2:Color, %color%
CoordMode, Pixel
mx := X - 90
my := Y - 40
Gui, 2:-Caption +ToolWindow +LastFound +AlwaysOnTop +Border

Gui, 2:Show, NoActivate x%mX% y%mY% w85 h30
if (ColorD < 3158064)
{
Gui, 2:Font, cWhite  ; If desired, use a line like this to set a new default font for the window.
GuiControl, 2:Font, updatetxt
}
if (ColorD >= 3158064)
{
Gui, 2:Font, cBlack
GuiControl, 2:Font, updatetxt  ; Put the above font into effect for a control.
}
guicontrol,2: , updatetxt, %color% ;Update the text
Sleep 50
}Until showpad=0 ;WARNING AHK_L SYNTAX

~lButton:: ; Set the shortcut to be used to catch the color under mouse.
SetTimer, killgui, 500
;messagebox BONK
If (showpad=1)
MsgBox The color you picked is 0x%color% ;final color chosen
;Clipboard = %color% ;or stick it to the clipboard
showpad=0 ;break the loop
Return

esc::
Pause
Return ;just in case of emergency

;tell your GUIs to step up off
killgui:
gui, hide
gui, 2:hide
If (showpad=0) ;waiting for the bonk
{
ExitApp ;^ or just hide them
    SetTimer, killgui, Off ;stop killing stuff
}
Else
SetTimer, killgui, 500 ;kill away

Return


As always suggestions, comments, criticism or kudos are very welcome. :D

_________________
"lol, i made this thing, but it didn't work... so I read the forums and now it does!"


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2010, 2:21 am 
Offline
User avatar

Joined: September 5th, 2009, 2:06 pm
Posts: 1713
Location: Somewhere near you
Built for AHK_L?
Error Message wrote:
}Until showpad=0 ;WARNING AHK_L SYNTAX ==> This line does not contain a recognized action.

_________________
Image
The quick onyx goblin jumps over the lazy dwarf


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2010, 5:29 am 
Offline

Joined: February 22nd, 2009, 7:24 pm
Posts: 21
Location: Dallas TX
tomoe_uehara wrote:
Built for AHK_L?
Error Message wrote:
}Until showpad=0 ;WARNING AHK_L SYNTAX ==> This line does not contain a recognized action.


Yes, you would have to change the way it breaks that loop to use it in vanilla AHK

_________________
"lol, i made this thing, but it didn't work... so I read the forums and now it does!"


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2010, 10:50 am 
Offline
User avatar

Joined: September 5th, 2009, 2:06 pm
Posts: 1713
Location: Somewhere near you
Since I don't have AHK_L installed, I just commented it out and it works fine :wink:

_________________
Image
The quick onyx goblin jumps over the lazy dwarf


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 18th, 2010, 12:50 am 
Offline
User avatar

Joined: April 4th, 2009, 8:19 pm
Posts: 1143
Location: Croatia
Hello General,

here is my unfinished color picker. Hold F1 to show HSB wheel, release it to select color.
Requires Gdip.ahk by Tic. Uses radial menu concepts - practical.
Code:
;===Auto-execute========================================================================
OnExit, ExitSub
FileFullPath := A_ScriptDir "\HSB wheel.jpg"
IfNotExist, %FileFullPath%
{
   URLDownloadToFile, http://oi53.tinypic.com/2gtombt.jpg, %FileFullPath%
   MsgBox,,, Download complete,1
}
ColorPicker("Init", FileFullPath)
return


;===Hotkeys=============================================================================
F1::MsgBox,,, % ColorPicker("Pick"), 1
Esc::ExitApp


;===Subroutines=========================================================================
ExitSub:
ColorPicker("OnExit")
ExitApp


;===Functions===========================================================================
#Include Gdip.ahk            ; by Tic

ColorPicker(cmd, param1="", param2="") {   ; by Learning one. Not finished!
   static  pToken, pBitmap, Width, Height, GuiNum
   if cmd = Init
   {
      IfNotExist, %param1%
      {
         MsgBox, 64, File not found, %param1% not found.`n`nApplication will exit.
         ExitApp
      }
      pToken := Gdip_Startup()
      if pToken =
      {
         MsgBox, 64, GDI+ error, GDI+ failed to start. Please ensure you have GDI+ on your system.`n`nApplication will exit.
         ExitApp
      }
      pBitmap := Gdip_CreateBitmapFromFile(param1)
      param2 := (param2) ? param2 : 99
      GuiNum := (GuiNum) ? GuiNum : param2
      Gui %GuiNum%: -Caption +E0x80000 +LastFound +ToolWindow +AlwaysOnTop +OwnDialogs
      Gui %GuiNum%: Show, hide
      hwnd1 := WinExist()
      Width := Gdip_GetImageWidth(pBitmap), Height := Gdip_GetImageHeight(pBitmap)
      hbm := CreateDIBSection(Width, Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
      G := Gdip_GraphicsFromHDC(hdc), Gdip_SetSmoothingMode(G, 4), Gdip_SetInterpolationMode(G, 7)
      Gdip_DrawImage(G, pBitmap, 0, 0, Width, Height)
      UpdateLayeredWindow(hwnd1, hdc, (A_ScreenWidth-Width)/2, (A_ScreenHeight-Height)/2, Width, Height)
      SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc), Gdip_DeleteGraphics(G)
      Return hwnd1
   }
   else if (cmd = "Pick" or cmd = "select")
   {
      CoordMode, mouse, screen
      MouseGetPos, x1,y1
      Hotkey := RegExReplace(A_ThisHotkey,"^(\w* & |\W*)")
      GuiX := x1 - Width/2, GuiY := y1 - Height/2
      Gui %GuiNum%:Show, x%GuiX% y%GuiY% NA
      KeyWait, %Hotkey%
      MouseGetPos, x2,y2
      SelectedColor := Gdip_GetPixel(pBitmap, x2-GuiX, y2-GuiY)
      Gui %GuiNum%:Hide
      SetFormat, Integer, hex
      return SelectedColor
   }
   else if cmd = OnExit
   Gdip_DisposeImage(pBitmap), Gdip_Shutdown(pToken)
}


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: Stigg and 10 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