[Tool] Show Me That Color (display selected text colors in a GUI)

Post your working scripts, libraries and tools
User avatar
SpeedMaster
Posts: 353
Joined: 12 Nov 2016, 16:09

[Tool] Show Me That Color (display selected text colors in a GUI)

30 Aug 2019, 22:01

:arrow: This script should be run normally or via command "Run" ( a text value must first be selected ! )
You can add a keyboard shortcut in your main script. (for ex. f9::run, Show_Me_That_Color.ahk)
When launched, the script copies any selected text to the clipboard and searches in the clipboard for hex colors and R,G,B colors to display them in a GUI.
see also new extra features by rommmeck :geek:
Up to 150 colors can be shown. 8-)
All suggestions for improving the script are welcome. ;)

script name: Show_Me_That_Color.ahk

New version by rommmcek v1.58

Code: Select all

; =====================================================================================================================
; Name:				Show me that color
; Description:		Use clipboard to display selected hex color or R,G,B text value
; Topic:           	https://www.autohotkey.com/boards/viewtopic.php?f=6&t=67586
; Sript version:	(v1.57.5 - didn't follow exactly) by rommmcek slightly modified by Speedmaster (v1.58)
; AHK Version:		1.1.24.03 (A32/U32/U64)
; Tested on:		Win 7 (x64)
; Author:			SpeedMaster
; How to use:	  	This script should be run normally or via command (for ex. f9::run, Show_Me_That_Color.ahk) 
;					in your main script. Then do one of the folowing:
;					1. Select text color values following by the F2. (copies any selected text)
;                   2. Set range with #LButton and draging the mouse following by the F2. (gets colors in the marked range)
;
;					The script copies any selected text to the variable
;                   or gets colors in the marked range (on raster spots - evry 25 pixels by default)
;                   and displays the hexadecimal colors or R,G,B colors in a GUI
;					Right click a square to copy it's value to clipboard.
;                   Shortcuts:
;                               F2    - Copy colors
;                               F3    - Open a stored color chart
;                               F4    - Change the color of the range frame
;                               F5    - Set new raster value when range is set (default: 25 pixel)
;                               F6    - Save color chart displayed via Gui
;                               Esc   - Exit or Hide GUI/Frame (set ExitOnGuiclose to true or false in settings section)
;                               +F2   - Show or Hide GUI.
;                               +F4   - Show Frame again (after it was hidden)
;                               ^Esc  - Exit application
;                               Ctrl  - When Mouse is over color: Open Color dialog
;                               Wheel - When Color dialog is opend and Edit control is focused: Increment/Decrease value
;                               Ctrl  - When Color dialog is opend: Reset Color
;                               Enter - When Color dialog is opend (or "OK" Button): Copy (current) color to Clipboard
;                               Esc   - When Color dialog is opend (or "Cancel" Button): Exit Color dialog
;=======================================================================================================================
#NoEnv  
version:=1.58

#singleinstance force
SetBatchLines, -1

CoordMode, Mouse, Screen
CoordMode, Pixel, Screen


WM_MOUSEMOVE := 0x200
OnMessage(WM_MOUSEMOVE, "OnMouseMove")

;----------------------settings----------------------------
raster:= 25
cols:=5
rows:=30
capital_font:=false         ; if true force GUI to display all captured values with capital font.
ExitOnGuiclose:= !A_Args.1   ; if true exit application  (false = hide GUI)
;----------------------------------------------------------
SoundBeep, 400
SoundBeep, 800

if ExitOnGuiclose
    gosub, copyClr
Return

BuildGui:
gui, add, text, w10 h10 x0 y0 +border ginputbox,
gui, font, s8

Grid(ctr:="listview", clln:="color", type:=0, gpx:=10, gpy:=10, cols:=cols, rows:=rows, cllw:=50+10, cllh:=40, wsp:=55+10, hsp:=60, opt:="  -Hdr -E0x200", fill:="")

Grid(ctr:="edit", clln:="t", type:=0, gpx:=10, gpy:=51, cols:=cols, rows:=rows, cllw:=50+10, cllh:=15, wsp:=55+10, hsp:=60, opt:=" +Multi -E0x200 -0x200000 -Wrap -WantReturn +ReadOnly 0x201 ", fill:="")

loop, % cols*rows
{
	guicontrol, % "+backgroundffffff" , color%a_index%
	GuiControl, MoveDraw, color%a_index% 
	color%a_index%:=""	
	t%a_index%:=""
	drawchar("t" a_index, "")
}
Return

copyClr:
lastfound:=0
clipboard:=""
sleep, 100
send, ^c
ClipWait, 0.2, 1


Clip=%Clipboard% ; Convert clipboard to plain text

ShowClr:
lastfound:=0
Gui, Destroy
sleep, 100
gosub, BuildGui
colors:=[]
pos := 0 
m := ""
while (pos := RegExMatch(clip, "[[:xdigit:]]{6}|\b\d{1,3}\s?,\s?\d{1,3}\s?,\s?\d{1,3}\b(?CCheckRGB)", m, (instr(m,",")) ? pos + StrLen(m) : pos+1))
{
   if (instr(m,","))
	colors.push(hextorgb(rgbtohex(m),"parse"))
   else
	colors.push(m)
	guicontrol, % "+background" (instr(colors[a_index],",") ? rgbToHex(colors[a_index]) : colors[a_index]),  color%a_index%  
	GuiControl, MoveDraw, color%a_index%  
	t%a_index%:=colors[a_index]

	if capital_font
		StringUpper, t%a_index%, t%a_index%
		
	drawchar("t" a_index, t%a_index%)

	if (lastfound<(cols*rows))
	lastfound++   
}



gui, +resize

if (lastfound) && (lastfound<=(cols*rows)) 
	lfpos:=getcontrol("t" lastfound, "yh")+5
else if (lastfound) && (lastfound>cols*rows)
	lfpos:=getcontrol("t" cols*rows, "yh")+5
else 
	lfpos:=getcontrol("t" cols*5, "yh")+5

if NewCols {
    Gosub apply
    return
}
if (lfpos) && (lfpos < A_ScreenHeight)
    gui, Show, % " h" lfpos, Show Me That Color v%version%
else
    gui, Show,, Show Me That Color v%version%
return

GuiContextMenu:
;if (substr(a_guicontrol,1,5)=="color")
;{
	;picked:= "t" . substr(a_guicontrol,6)
	;textout :=  % %picked%
	;if (StrLen(textout)=6) || instr(textout, ",") {
		;StringUpper, textout, textout
            clipboard:=textout
            TrayTip, Color Copied,  % (StrLen(textout)=6) ? "#" textout : textout
    ;}
;}	
return

MouseMoveRoutine:
if (substr(a_guicontrol,1,5)=="color")
{
	picked:= "t" . substr(a_guicontrol,6)
	textout :=  % %picked%
	if (StrLen(textout)=6) || instr(textout, ",") {
		StringUpper, textout, textout
        ClrUnderM:= textout
	}
 }  else ClrUnderM:= ""
Return

~Ctrl::
    KeyWait, Ctrl
    if (WinActive("Show Me That Color v" version) && ClrUnderM!="") {
        if InStr(ClrReset:=ClrUnderM, ",")
            C:=StrSplit(ClrUnderM, ","), C:=ColorDlg(C.1, C.2, C.3, WinExist("A")), C>=0? Clipboard:=C: ""
        else C:=ColorDlg(ClrUnderM,,, WinExist("A")), C>=0? Clipboard:=C: ""
    }
return

apply:

i:=j:=k:=0

     While i++ <= z:=((rows*cols)//newcols) {
        while j++ < newcols{
			k++
			if (i=1 && j=1) {
					guicontrol, move, color%k%, % "x" 10 "y" 10
					guicontrol, move, t%k%, % "x" 10 "y" 10+41
				}
			if (i=1 && j>1)	{
					guicontrol, move, color%k%, % "x" ((a_index-1)*(wsp))+10 "y" 10
					guicontrol, move, t%k%, % "x" ((a_index-1)*(wsp))+10 "y" 10+41
				}
			if (i>1 && j=1) {
				guicontrol, move, color%k%, % "x" 10 "y" ((i-1)*60)+10
				guicontrol, move, t%k%, % "x" 10 "y" ((i-1)*60)+41+10
			}
			
			if (i>1 && j>1) {
				guicontrol, move, color%k%, % "x" ((a_index-1)*(wsp))+10 "y" ((i-1)*60)+10
				guicontrol, move, t%k%, % "x" ((a_index-1)*(wsp))+10 "y" ((i-1)*60)+41+10
			}	
			
		} j:=0
	} i:=j:=0
	gui, color


edgeX:=0
loop, % cols*rows 
{
q:=getcontrol("color" a_index, "xw"), (q>edgeX) ? (edgeX:=q) : Null
}

if (lastfound) && (getcontrol("t" lastfound, "yh") < A_ScreenHeight)
	gui, show, % "w" edgeX+10 " h" getcontrol("t" lastfound, "yh")+5, Show Me That Color v%version%
else
	gui, show, % "w" edgeX+10, Show Me That Color v%version%

return

inputbox:
oCols:=NewCols? NewCols: Cols
InputBox, NewCols, Show Me That Color, Columns,, 150, 125,,,,, % NewCols? NewCols: Cols
If !ErrorLevel
    gosub, apply
else NewCols:=oCols
return

drawchar(varname, chartodraw:="@", color:="")
{
 global
guicontrol,, %varname%, %chartodraw%
if (color)
colorcell(varname, color)
}

ColorCell(cell_to_paint, color:="red")
{
 GuiControl, +c%color%  , %cell_to_paint%
 GuiControl, MoveDraw, % cell_to_paint
}

getcontrol(crtname, what)
{
 guicontrolget, out,  Pos, %crtname%

 if (what="x")
 return % outx

 if (what="y")
 return % outy

 if (what="w")
 return % outW

 if (what="h")
 return % outH

 if (what="yh")
 return % outy + outH 

 if (what="xw")
 return % outx + outW
}

Grid(ctr:="text", clln:="", type:=1, gpx:=10, gpy:=10, cols:=30, rows:=20, cllw:=32, cllh:=32, wsp:=31, hsp:=31, opt:=" BackGroundTrans gclick -disabled border 0x201", fill:="")
{
  global
  r:=0,  c:=0, idx:=0
     While r++ < rows {
        while c++ < cols{
          idx++
                  gui 1: add, % ctr, % opt " w"cllw " h"cllh " v" ((type=1) ? (clln r "_" c " Hwndh" clln  r "_" c) : (type=2) ? (clln c "_" r " Hwndh" clln  c "_" r) : (clln idx " Hwndh" clln  a_index)) ((c=1 && r=1) ? " x"gpx " y"gpy " section"
               : (c!=1 && r=1) ? " xp+"wsp " yp" : (c=1 && r!=1) ? " xs" " yp+"hsp : " xp+"wsp " yp"), % fill
          } c:=0
     } r:=c:=idx:=0
}

;by just me
CheckRGB(Match) {
   Loop, Parse, Match, `,, %A_Space%
      If (A_LoopField > 255) {
         ;MsgBox, 16, %A_ThisFunc%, Invalid RGB value %Match%! ; for testing
         Return 1
      }
}

;by polyethene
rgbToHex(s, d = "") {

	StringSplit, s, s, % d = "" ? "," : d

	SetFormat, Integer, % (f := A_FormatInteger) = "D" ? "H" : f

	h := s1 + 0 . s2 + 0 . s3 + 0

	SetFormat, Integer, %f%

	Return,  RegExReplace(RegExReplace(h, "0x(.)(?=$|0x)", "0$1"), "0x")

}

; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=66463
HexToRGB(Color, Mode="") ; Input: 6 characters HEX-color. Mode can be RGB, Message (R: x, G: y, B: z) or parse (R,G,B)
{
   ; If df, d is *16 and f is *1. Thus, Rx = R*16 while Rn = R*1
   Rx := SubStr(Color, 1,1), Rn := SubStr(Color, 2,1)
   Gx := SubStr(Color, 3,1), Gn := SubStr(Color, 4,1)
   Bx := SubStr(Color, 5,1), Bn := SubStr(Color, 6,1)
   
   AllVars := "Rx|Rn|Gx|Gn|Bx|Bn"
   Loop, Parse, Allvars, | ; Add the Hex values (A - F)
   {
      StringReplace, %A_LoopField%, %A_LoopField%, a, 10
      StringReplace, %A_LoopField%, %A_LoopField%, b, 11
      StringReplace, %A_LoopField%, %A_LoopField%, c, 12
      StringReplace, %A_LoopField%, %A_LoopField%, d, 13
      StringReplace, %A_LoopField%, %A_LoopField%, e, 14
      StringReplace, %A_LoopField%, %A_LoopField%, f, 15
   }
   R := Rx*16+Rn
   G := Gx*16+Gn
   B := Bx*16+Bn
   
   If (Mode = "Message") ; Returns "R: 255 G: 255 B: 255"
      Out := "R:" . R . " G:" . G . " B:" . B
   else if (Mode = "Parse") ; Returns "255,255,255"
      Out := R . "," . G . "," . B
   else
      Out := R . G . B ; Returns 255255255
    return Out
}

return
 
^Esc::
    WinWait, Color Sliders,, 1
    WinClose, Color Sliders ahk_class AutoHotkeyGUI
    SoundBeep, 800
    SoundBeep, 400
exitapp 

guiclose:
~ESC::
    if (!WinActive("Show Me That Color v" version) || WinExist("outline1")) && !ExitOnGuiclose || WinActive("Show Me That Color ahk_class #32770") || WinActive("Color ahk_class #32770")
        Return
    if (ExitOnGuiclose) {
        SoundBeep, 800
        SoundBeep, 400
        ExitApp
    }
    else
        Gui, Hide
    ToggleGui:= 1
Return

F2::
    Gui, Hide
    ClrFls:= ToggleGui:= ""
    if WinExist("outline1")
        gosub PickClr
    else gosub CopyClr
Return

+F2::
    If !(!WinActive("Show Me That Color") && WinExist("Show Me That Color"))
        togglegui:=!togglegui
    if (togglegui)
        Gui, hide
    else
        gui, show
return

f3::
    ClrFls? OldClrFls:=ClrFls: ""
    FileSelectFile, ClrFls, 3,, Open a file, Color Charts (*.txt; *.clr)
    if !ClrFls {
        ClrFls:=OldClrFls
        return
    }
    FileRead, Clip, % ClrFls
    if RegExMatch(Clip, "number_of_columns_(\d+)", $)
       NewCols:=$1
    gosub ShowClr
Return

#LButton::
    Loop, 4 {
        Gui, % A_Index+95 ": -Caption +ToolWindow +AlwaysOnTop -DPIScale"
        Gui, % A_Index+95 ": Color", % Clr? Clr: Clr:="ff8080"
        Gui, % A_Index+95 ": Show", NA h0 w0, outline%A_Index%
    }   

    MouseGetPos, x1, y1
    While GetKeyState("LButton", "P") {
        MouseGetPos, x2, y2
        ;PixelGetColor, Grc, % x2, % y2, RGB
        ;rr:=Grc>>16, gg:=Grc>>8&0xff, bb:=Grc&0xff, cGrc:=sqrt(.241*rr**2+.691*gg**2+.068*bb**2)
        ;FrameColor:= cGrc<130? 0xffffff: 0x000000
        ;loop, 4
            ;Gui, % A_Index+95 ": Color", % FrameColor
        if (x1<=x2 && y1<=y2) {
            nx1:=x1+((x2-x1)>1?1:0), ny1:=y1+((y2-y1)>1?1:0), nx2:=x2-((x2-x1)>1?1:0), ny2:=y2-((y2-y1)>1?1:0)
            Gui, 96:Show, % "NA X" x1+0 " Y" y1-4 " W" x2-x1+4 " H" 4
            Gui, 97:Show, % "NA X" x2+0 " Y" y1-0 " W" 4 " H" y2-y1+4
            Gui, 98:Show, % "NA X" x1-4 " Y" y2-0 " W" x2-x1+4 " H" 4
            Gui, 99:Show, % "NA X" x1-4 " Y" y1-4 " W" 4 " H" y2-y1+4
        } else if (x1>x2 && y1<y2) {
            nx1:=x2+((x1-x2)>1?1:0), ny1:=y1+((y2-y1)>1?1:0), nx2:=x1-((x1-x2)>1?1:0), ny2:=y2-((y2-y1)>1?1:0)
            Gui, 96:Show, % "NA X" x2-4 " Y" y1-4 " W" x1-x2+4 " H" 4
            Gui, 97:Show, % "NA X" x1+0 " Y" y1-4 " W" 4 " H" y2-y1+4
            Gui, 98:Show, % "NA X" x2-0 " Y" y2-0 " W" x1-x2+4 " H" 4
            Gui, 99:Show, % "NA X" x2-4 " Y" y1+0 " W" 4 " H" y2-y1+4
        } else if (x1<x2 && y1>y2) {
            nx1:=x1+((x2-x1)>1?1:0), ny1:=y2+((y1-y2)>1?1:0), nx2:=x2-((x2-x1)>1?1:0), ny2:=y1-((y1-y2)>1?1:0)
            Gui, 96:Show, % "NA X" x1-4 " Y" y2-4 " W" x2-x1+4 " H" 4
            Gui, 97:Show, % "NA X" x2+0 " Y" y2-4 " W" 4 " H" y1-y2+4
            Gui, 98:Show, % "NA X" x1-0 " Y" y1+0 " W" x2-x1+4 " H" 4
            Gui, 99:Show, % "NA X" x1-4 " Y" y2+0 " W" 4 " H" y1-y2+4
        } else if (x1>x2 && y1>y2) {
            nx1:=x2+((x1-x2)>1?1:0), ny1:=y2+((y1-y2)>1?1:0), nx2:=x1-((x1-x2)>1?1:0), ny2:=y1-((y1-y2)>1?1:0)
            Gui, 96:Show, % "NA X" x2-4 " Y" y2-4 " W" x1-x2+4 " H" 4
            Gui, 97:Show, % "NA X" x1+0 " Y" y2-4 " W" 4 " H" y1-y2+4
            Gui, 98:Show, % "NA X" x2-0 " Y" y1+0 " W" x1-x2+4 " H" 4
            Gui, 99:Show, % "NA X" x2-4 " Y" y2-0 " W" 4 " H" y1-y2+4
        }
        Sleep, 25
    }
Return

+F4::
    Loop, 4
        Gui, % A_Index+95 ": Show", NA
Return

#IfWinExist, Enter raster
Esc::WinClose Enter raster

#IfWinExist, outline1
F4::
    if WinExist("outline1") {
        if clr=ff8080
            loop, 4
                Gui, % A_Index+95 ": Color", % Clr:="80ff80"
        else if clr=80ff80
            loop, 4
                Gui, % A_Index+95 ": Color", % Clr:="8080ff"
        else if clr=8080ff
            loop, 4
                Gui, % A_Index+95 ": Color", % Clr:="80ffff"
        else if clr=80ffff
            loop, 4
                Gui, % A_Index+95 ": Color", % Clr:="ff80ff"
        else if clr=ff80ff
            loop, 4
                Gui, % A_Index+95 ": Color", % Clr:="ffff80"
        else if clr=ffff80
            loop, 4
                Gui, % A_Index+95 ": Color", % Clr:="ff8080"
    }
Return

F5::
    rx1:= (nx1>A_ScreenWidth-190)? (A_ScreenWidth-190): nx1, ry1:= (ny1>A_ScreenHeight-125)? (A_ScreenHeight-125): ny1
    mr:=(nx2-nx1>ny2-ny1)? (ny2-ny1)//2: (nx2-nx1)//2, mr<1? mr:=1: "", oraster:=raster
    InputBox, raster, Enter raster,,, 170, 105, % rx1, % ry1,,, % raster>mr? mr: raster
    if ErrorLevel
        raster:=oraster
Return

DestroyFrame:
Esc::
    Loop, 4
        Gui, % A_Index+95 ": Hide"
Return

#IfWinExist, Show Me That Color
F6::
    SetTimer, EnterFileName, -50
    FileSelectFile, SaveFls, S16,, Save File As, Color Charts (*.clr; *.txt)
    if SaveFls {
        if FileExist(ClrFls:=SaveFls? SaveFls: ClrFls)
            FileDelete, % SaveFls
            if (Clip ~= "number_of_columns_\d+")
                Clip:= RegExReplace(Clip, "number_of_columns_\d+\r\n", "number_of_columns_" (NewCols? NewCols: cols) "`r`n")
            else Clip:= "number_of_columns_" (NewCols? NewCols: cols) "`r`n" Clip
            FileAppend, % Clip, % SaveFls
    }
Return

PickClr:
    Gosub, DestroyFrame
    Clip:= "", mr:=(nx2-nx1>ny2-ny1)? (ny2-ny1)//2: (nx2-nx1)//2, mr<1? mr:=1: ""
    , ((abs(x1-x2)=1)||(abs(y1-y2)=1))?mr:=0: "", raster:= raster>mr? mr :raster
    loop, % (indH:=(ny2-ny1)//raster)>0? indH: 1 {
        aIndex:= A_Index-1
        loop, % (indW:=(nx2-nx1)//raster)>0? indW: 1 {
            PixelGetColor, clrPix, % nx1+(A_Index-1)*raster, % ny1+aIndex*raster, RGB
            if !InStr(Clip, clrPix)
                Clip.= clrPix "`r`n"
            ;MouseMove, % nx1+(A_Index-1)*raster, % ny1+aIndex*raster
            ;Sleep, 200
            if (A_Index=indW) {
                PixelGetColor, clrPix, % nx2, % ny1+aIndex*raster, RGB
                if !InStr(Clip, clrPix)
                    Clip.= clrPix "`r`n"
                ;MouseMove, % nx2, % ny1+aIndex*raster
            }
        }
        if (A_Index=IndH) {
            loop % indW {
                PixelGetColor, clrPix, % nx1+(A_Index-1)*raster, % ny2, RGB
                if !InStr(Clip, clrPix)
                    Clip.= clrPix "`r`n"
                ;MouseMove, % nx1+(A_Index-1)*raster, % ny2
                ;Sleep, 200
            }
            PixelGetColor, clrPix, % nx2, % ny2, RGB
            if !InStr(Clip, clrPix)
                Clip.= clrPix "`r`n"
            ;MouseMove, % nx2, % ny2
        }
        ;Sleep, 200
    }
    gosub ShowClr
Return

OnMouseMove() {
	global
    Gosub MouseMoveRoutine
    ClrMatch:= StrReplace(ClrUnderM, ",", "\,\s*")
    RegExMatch(Clip, "miU)^(.*" ClrMatch ".*)$", ColorName)
    IsColorname:=regexreplace(ColorName1,"#?[[:xdigit:]]{6}|\b\d{1,3}\s?,\s?\d{1,3}\s?,\s?\d{1,3}\b|\W")
    if (ClrUnderM!="" && !TT && IsColorname) {
            ToolTip, % Trim(ColorName1)
            TT:=1
            MouseGetPos,,, WinUnderM1
            SetTimer TtCheck, 50
        }
    else if (ClrUnderM="" || ClrUnderM!=oClrUnderM) {
            ToolTip
            TT:= ""
            SetTimer, TtCheck, Off
        }
    oClrUnderM:=ClrUnderM
}

TtCheck:
    MouseGetPos,,, WinUnderM2
    if (WinUnderM1!=WinUnderM2) {
        ToolTip
        TT:= "" ; , oClrUnderM:= ""
        SetTimer, TtCheck, Off
    }
Return

EnterFileName:
    SplitPath, ClrFls, ThisClrFls
    WinWaitActive, Save File As ahk_class #32770,, 3
    ControlSetText, Edit1, % ThisClrFls, Save File As ahk_class #32770
    ControlSend, Edit1, {End}^{Left}{Left}, Save File As ahk_class #32770
Return

ColorDlg(C1:=0x0, C2:="", C3:="", hGui:=0) {
    C2!=""? (C:="0x" Format("{:02X}", C1)  Format("{:02X}", C2) Format("{:02X}", C3)): (C:=InStr(C1, "0x")? C1: "0x" C1)
	VarSetCapacity(CC, 64, 0), 	NumPut(VarSetCapacity(RGB, (A_PtrSize*9), 0), RGB, 0)
	NumPut(hGui, RGB, A_PtrSize), NumPut((C&0xFF)<<16|C&0xFF00|(C>>16)&0xFF, RGB, A_PtrSize*3)
	NumPut(&CC, RGB, A_PtrSize*4), 	NumPut(0x103, RGB, A_PtrSize*5)
    if !(!DllCall("Comdlg32.dll\ChooseColor", Str, RGB) || ErrorLevel)
        Return Format("{:06X}", (C:=NumGet(RGB, A_PtrSize*3))&0xFF00|(C&0xFF0000)>>16|(C&0xFF)<<16)
    else Return -1
}

#If WinActive("Color ahk_class #32770")
WheelUp::
WheelDown::
    Critical
    if (A_TimeSincePriorHotkey < 500 && A_ThisHotkey = A_PriorHotkey)
        rNotch<=10? rNotch++: "" ;, (rNotch>10&&rNotch<=20)? rNotch+=3: "", (rNotch>20&&rNotch<=30)? rNotch+=5: ""
    else rNotch:=1
    ControlGetFocus, Cf, Color ahk_class #32770
    if InStr(Cf, "Edit") {
        ControlGetText, Ef, % Cf, Color ahk_class #32770
        Ef:=(A_ThisHotkey="WheelUp")? Ef+rNotch: Ef-rNotch
        ControlSetText % Cf, % ((Ef<0)? 0: (Ef>255)? 255: Ef), Color ahk_class #32770
    }
Return

~Ctrl::
    KeyWait, Ctrl
    if !InStr(ClrReset, ",")
        C:=[], ClrReset:=InStr(ClrReset, "0x")? ClrReset: "0x" ClrReset, C.1:=(ClrReset>>16)&0xff, C.2:=(ClrReset>>8)&0xff, C.3:=ClrReset&0xff
    ControlSetText, Edit3, 120, Color ahk_class #32770
    loop, 3
        ControlSetText, % "Edit" A_Index+3, % C[A_Index], Color ahk_class #32770
Return

#If WinActive("Show Me That Color ahk_class #32770")
WheelUp::
WheelDown::
    Critical
    if (A_TimeSincePriorHotkey < 500 && A_ThisHotkey = A_PriorHotkey)
        rNotch<=10? rNotch++: "" ;, (rNotch>10&&rNotch<=20)? rNotch+=3: "", (rNotch>20&&rNotch<=30)? rNotch+=5: ""
    else rNotch:=1
    ControlGetText, Ef, Edit1, Show Me That Color ahk_class #32770
    Ef:=(A_ThisHotkey="WheelUp")? Ef+rNotch: Ef-rNotch
    ControlSetText, Edit1, % ((Ef<1)? 1: (Ef>22)? 22: Ef), Show Me That Color ahk_class #32770
Return

#If WinActive("Enter raster ahk_class #32770")
WheelUp::
WheelDown::
    Critical
    if (A_TimeSincePriorHotkey < 500 && A_ThisHotkey = A_PriorHotkey)
        rNotch<=10? rNotch++: "" ;, (rNotch>10&&rNotch<=20)? rNotch+=3: "", (rNotch>20&&rNotch<=30)? rNotch+=5: ""
    else rNotch:=1
    ControlGetText, Ef, Edit1, Enter raster ahk_class #32770
    Ef:=(A_ThisHotkey="WheelUp")? Ef+rNotch: Ef-rNotch, mr:=(nx2-nx1>ny2-ny1)? (ny2-ny1)//2: (nx2-nx1)//2, mr<1? mr:=1: ""
    ControlSetText, Edit1, % ((Ef<1)? 1: (Ef>mr)? mr: Ef), Enter raster ahk_class #32770
Return
Shortcuts (new version):
F2 - Copy colors
F3 - Open a stored color chart
F4 - Change the color of the range frame
F5 - Set new raster value when range is set (default: 25 pixel)
F6 - Save color chart displayed via Gui
Esc - Exit or Hide GUI/Frame (set ExitOnGuiclose to true or false in settings section)
+F2 - Show or Hide GUI.
+F4 - Show Frame again (after it was hidden)
^Esc - Exit application
Ctrl - When Mouse is over color: Open Color dialog
Wheel - When Color dialog is opend and Edit control is focused: Increment/Decrease value
Ctrl - When Color dialog is opend: Reset Color
Enter - When Color dialog is opend (or "OK" Button): Copy (current) color to Clipboard
Esc - When Color dialog is opend (or "Cancel" Button): Exit Color dialog
#LButton and draging the mouse following by the F2. - gets colors in the marked range
Right click a square to copy it's value to clipboard.


Old version by Speedmaster v1.5 (basic)
Spoiler

shortcut exmple to run the script:

Code: Select all

f9::run, Show_Me_That_Color.ahk
example of text containing colors:

Code: Select all

800000	128,0,0
FF0000	255,0,0
FFA500	255,165,0
FFFF00	255,255,0
808000	128,128,0
008000	0,128,0
Color Name	Hex Code
RGB	Decimal Code
RGB
800080	128,0,128
FF00FF	255,0,255
00FF00	0,255,0
008080	0,128,128
00FFFF	0,255,255
0000FF	0,0,255
 Name	Hex Code
RGB	Decimal Code
RGB
000080	0,0,128
000000	0,0,0
808080	128,128,128
C0C0C0	192,192,192
FFFFFF	255,255,255

Last edited by SpeedMaster on 16 Sep 2019, 04:18, edited 11 times in total.
User avatar
Delta Pythagorean
Posts: 481
Joined: 13 Feb 2017, 13:44
GitHub: DelPyth
Location: Somewhere in the US

Re: [Tool] Show Me That Color (display selected text colors in a GUI)

31 Aug 2019, 17:12

Not bad, although I think this script could me modified into a color picker of some sorts. Just an Idea I guess.
User avatar
SpeedMaster
Posts: 353
Joined: 12 Nov 2016, 16:09

Re: [Tool] Show Me That Color (display selected text colors in a GUI)

31 Aug 2019, 18:32

Delta Pythagorean wrote:
31 Aug 2019, 17:12
Not bad, although I think this script could me modified into a color picker of some sorts. Just an Idea I guess.
It's not meant to be a color picker. ;)
when you have a text representing a hexadecimal color (for example #FAC4B8) you have to do several annoying steps like copying the text open a dedicated website or an image editor paste the text and all this only to see what this color looks like. :( even worse if you have several colors (for ex. BB77FF, 00ABAB, AACCD9, etc...)
I made this tool to fix this problem. 8-)
With this tool you only have to select the text and press your keyboard shortcut to see what the color looks like. :thumbup:
I use it a lot myself and if you want to select a color from the GUI just double click on the text value (below the colored square) to select it then right click and copy it.

Cheers,
User avatar
Delta Pythagorean
Posts: 481
Joined: 13 Feb 2017, 13:44
GitHub: DelPyth
Location: Somewhere in the US

Re: [Tool] Show Me That Color (display selected text colors in a GUI)

31 Aug 2019, 20:41

SpeedMaster wrote:
31 Aug 2019, 18:32
Delta Pythagorean wrote:
31 Aug 2019, 17:12
Not bad, although I think this script could me modified into a color picker of some sorts. Just an Idea I guess.
It's not meant to be a color picker. ;)
when you have a text representing a hexadecimal color (for example #FAC4B8) you have to do several annoying steps like copying the text open a dedicated website or an image editor paste the text and all this only to see what this color looks like. :( even worse if you have several colors (for ex. BB77FF, 00ABAB, AACCD9, etc...)
I made this tool to fix this problem. 8-)
With this tool you only have to select the text and press your keyboard shortcut to see what the color looks like. :thumbup:
I use it a lot myself and if you want to select a color from the GUI just double click on the text value (below the colored square) to select it then right click and copy it.

Cheers,
I know this, but I'm just saying, the layout of how it interprets colors to the individual segments could be used as a color picker.
I never said it was, but it could be.
User avatar
SpeedMaster
Posts: 353
Joined: 12 Nov 2016, 16:09

Re: [Tool] Show Me That Color (display selected text colors in a GUI)

01 Sep 2019, 02:52

Delta Pythagorean wrote:
31 Aug 2019, 20:41
I know this, but I'm just saying, the layout of how it interprets colors to the individual segments could be used as a color picker.
I never said it was, but it could be.
why not after all, I made a new version. :roll: Thanks !

new version v1.1
Right-click on a square to copy its value to the clipboard.
User avatar
SpeedMaster
Posts: 353
Joined: 12 Nov 2016, 16:09

Re: [Tool] Show Me That Color (display selected text colors in a GUI)

01 Sep 2019, 04:07

New version 1.2
  • Fixed bug : script not showing colors when HTML page was selected. (the contents of the clipboard are now first converted to plain text)
User avatar
SpeedMaster
Posts: 353
Joined: 12 Nov 2016, 16:09

Re: [Tool] Show Me That Color (display selected text colors in a GUI)

02 Sep 2019, 03:57

New Version 1.4 :)
  • Automatic resizing of the grid
  • Added a setting section in the script to define the number of columns and rows by default.
  • Reorganization of the number of columns. (click on the upper left corner)
  • The GUI is now resizable
Regards,
User avatar
yane
Posts: 3
Joined: 12 May 2018, 01:48

Re: [Tool] Show Me That Color (display selected text colors in a GUI)

02 Sep 2019, 04:42

Code: Select all

; Description:		Use clipboard to display selected hex color text
Nice tool but why stop there, can you add the option to show the color of the selected RGB text?
User avatar
SpeedMaster
Posts: 353
Joined: 12 Nov 2016, 16:09

Re: [Tool] Show Me That Color (display selected text colors in a GUI)

02 Sep 2019, 15:17

yane wrote:
02 Sep 2019, 04:42
Nice tool but why stop there, can you add the option to show the color of the selected RGB text?
Do you mean something like "128,255,42" (R,G,B)?
I also thought about that but it seems difficult to implement. :(
Any idea how to do it? :think: My regex skill is still basic. :?
I'll ask the question in the forum and see what I get. :)
rommmcek
Posts: 694
Joined: 15 Aug 2014, 15:18

Re: [Tool] Show Me That Color (display selected text colors in a GUI)

02 Sep 2019, 20:06

v1.4 is great step forward! Cutting off excessive rows is awesome feature! You could add the same for excessive columns!
Of course this would be doable only for predefined color charts including un extra delimiter e.g. semicolon.
Starting predefined color chart would be something like F3::Run, Show_Me_That_Color.ahk parameter where paramater would be the (path)name of the color chart or -1 which would launch FileSelectFile dialog...
All depends of how much effort and time are you willing to put into.
Here is an example of rather rare color chart arranged by perceived brightness. (settings: cols:=28, rows:=5)
To be more simple it is included in to adapted Show Me That Color ready to run.
Spoiler
P.s: Converting hex to RGB si pretty straightforward:

Code: Select all

;c:=0x2c3e50 ; or
c:="2c3e50", c:="0x" c
MsgBox % (c>>16)&0xff ", " (c>>8)&0xff ", " c&0xff
MsgBox % Format("{:x}", (c>>16)&0xff) ", " Format("{:x}", (c>>8)&0xff) ", " Format("{:x}", c&0xff) ; hex values
; be sure to heed RGB vs BGR format!
User avatar
SpeedMaster
Posts: 353
Joined: 12 Nov 2016, 16:09

Re: [Tool] Show Me That Color (display selected text colors in a GUI)

03 Sep 2019, 17:03

rommmcek wrote:
02 Sep 2019, 20:06
v1.4 is great step forward! Cutting off excessive rows is awesome feature! You could add the same for excessive columns!
All depends of how much effort and time are you willing to put into.
Thanks for your support and suggestions :)
yes, importing or exporting a pallet would be also a great feature to add. 8-) or a add-to-favorite-list button 8-) .
I'll add that when I have more free time otherwise you are free to post here your own improved version of the tool. (I like diversity :thumbup: )
User avatar
SpeedMaster
Posts: 353
Joined: 12 Nov 2016, 16:09

Re: [Tool] Show Me That Color (display selected text colors in a GUI)

03 Sep 2019, 17:14

New Version 1.5 :)
  • Selected R,G,B text values are also supported now (e.g. 255,50,125) (tanks just me :thumbup: )
  • Disabled force capital font in GUI, the text will be displayed in his captured form (this feature can be enabled in the settings if you want)
  • extended text box to be able to show R,G,B values
Regards,
rommmcek
Posts: 694
Joined: 15 Aug 2014, 15:18

Re: [Tool] Show Me That Color (display selected text colors in a GUI)

05 Sep 2019, 06:58

O.k., here is my version:

Code: Select all

; =====================================================================================================================
; Name:				Show me that color
; Description:		Use clipboard to display selected hex color or R,G,B text value
; Topic:           	https://www.autohotkey.com/boards/viewtopic.php?f=6&t=67586
; Sript version:	1.51 ; version by rommmcek
; AHK Version:		1.1.24.03 (A32/U32/U64)
; Tested on:		Win 7 (x64)
; Author:			SpeedMaster
; How to use:	  	This script should be run normally or via command (for ex. f2::run, Show_Me_That_Color.ahk) 
;					in your main script. Them do one of the folowing:
;					1. Select text color values following by the F2.
;                   2. Set range with #LButton and draging the mouse following by the F2.
;					The script copies any selected text to the variable
;                   or gets colors in the marked range (on raster spots - evry 25 pixels by default)
;                   and displays the hexadecimal colors or R,G,B colors in a GUI
;					Right click a square to copy it's value to clipboard.
;                   Shortcuts:
;                               F2   - Copy colors
;                               F3   - Open a stored color chart
;                               F4   - Change the color of the range frame
;                               F5   - Set new raster value when range is set (default: 25 pixel)
;                               F6   - Save color chart displayed via Gui
;                               Esc  - Hide GUI/Frame
;                               +F2  - Show GUI again (after it was hidden)
;                               +F4  - Show Frame again (after it was hidden)
;                               ^Esc - Exit application
;=======================================================================================================================
#NoEnv  
version:=1.51 ; version by rommmcek

#singleinstance force
SetBatchLines, -1

;----------------------settings----------------------------
raster:= 25
cols:=5
rows:=30
capital_font:=false 	; if true force GUI to display all captured values with capital font.
;----------------------------------------------------------
Return

BuildGui:
gui, add, text, w10 h10 x0 y0 +border ginputbox,
gui, font, s8

Grid(ctr:="listview", clln:="color", type:=0, gpx:=10, gpy:=10, cols:=cols, rows:=rows, cllw:=50+10, cllh:=40, wsp:=55+10, hsp:=60, opt:="  -Hdr -E0x200", fill:="")

Grid(ctr:="edit", clln:="t", type:=0, gpx:=10, gpy:=51, cols:=cols, rows:=rows, cllw:=50+10, cllh:=15, wsp:=55+10, hsp:=60, opt:=" +Multi -E0x200 -0x200000 -Wrap -WantReturn +ReadOnly 0x201 ", fill:="")

loop, % cols*rows
{
	guicontrol, % "+backgroundffffff" , color%a_index%
	GuiControl, MoveDraw, color%a_index% 
	color%a_index%:=""	
	t%a_index%:=""
	drawchar("t" a_index, "")
}
Return

copyClr:
lastfound:=0
clipboard:=""
sleep, 100
send, ^c
ClipWait, 200

Clip=%Clipboard% ; Convert clipboard to plain text

ShowClr:
Gui, Destroy
gosub, BuildGui
colors:=[]
pos := 0 
m := ""
while (pos := RegExMatch(clip, "[[:xdigit:]]{6}|\b\d{1,3}\s?,\s?\d{1,3}\s?,\s?\d{1,3}\b(?CCheckRGB)", m, (instr(m,",")) ? pos + StrLen(m) : pos+1))
{
   if (instr(m,","))
	colors.push(hextorgb(rgbtohex(m),"parse"))
   else
	colors.push(m)
	guicontrol, % "+background" (instr(colors[a_index],",") ? rgbToHex(colors[a_index]) : colors[a_index]),  color%a_index%  
	GuiControl, MoveDraw, color%a_index%  
	t%a_index%:=colors[a_index]

	if capital_font
		StringUpper, t%a_index%, t%a_index%
		
	drawchar("t" a_index, t%a_index%)

	if (lastfound<(cols*rows))
	lastfound++   
}

gui, +resize

if (lastfound) && (lastfound<=(cols*rows)) 
	lfpos:=getcontrol("t" lastfound, "yh")+5
else if (lastfound) && (lastfound>cols*rows)
	lfpos:=getcontrol("t" cols*rows, "yh")+5
else 
	lfpos:=getcontrol("t" cols*5, "yh")+5

if (lfpos) && (lfpos < A_ScreenHeight)
gui, Show, % " h" lfpos, Show Me That Color v%version%
else
gui, Show,, Show Me That Color v%version%

return

GuiContextMenu:
if (substr(a_guicontrol,1,5)=="color")
{
	picked:= "t" . substr(a_guicontrol,6)
	textout :=  % %picked%
	if (StrLen(textout)=6) || instr(textout, ",") {
		StringUpper, textout, textout
		clipboard:=textout
		TrayTip, Color Copied,  % (StrLen(textout)=6) ? "#" textout : textout
	}
}	
return

apply:

i:=j:=k:=0

     While i++ <= z:=((rows*cols)//newcols) {
        while j++ < newcols{
			k++
			if (i=1 && j=1) {
					guicontrol, move, color%k%, % "x" 10 "y" 10
					guicontrol, move, t%k%, % "x" 10 "y" 10+41
				}
			if (i=1 && j>1)	{
					guicontrol, move, color%k%, % "x" ((a_index-1)*(wsp))+10 "y" 10
					guicontrol, move, t%k%, % "x" ((a_index-1)*(wsp))+10 "y" 10+41
				}
			if (i>1 && j=1) {
				guicontrol, move, color%k%, % "x" 10 "y" ((i-1)*60)+10
				guicontrol, move, t%k%, % "x" 10 "y" ((i-1)*60)+41+10
			}
			
			if (i>1 && j>1) {
				guicontrol, move, color%k%, % "x" ((a_index-1)*(wsp))+10 "y" ((i-1)*60)+10
				guicontrol, move, t%k%, % "x" ((a_index-1)*(wsp))+10 "y" ((i-1)*60)+41+10
			}	
			
		} j:=0
	} i:=j:=0
	gui, color


edgeX:=0
loop, % cols*rows 
{
q:=getcontrol("color" a_index, "xw")
(q>edgeX) ? (edgeX:=q) : Null
}

if (getcontrol("t" lastfound, "yh") < A_ScreenHeight)
	gui, show, % "w" edgeX+10 " h" getcontrol("t" lastfound, "yh")+5
else
	gui, show, % "w" edgeX+10 

return

inputbox:
InputBox, NewCols,, Columns,, 150, 120
gosub, apply
return

drawchar(varname, chartodraw:="@", color:="")
{
 global
guicontrol,, %varname%, %chartodraw%
if (color)
colorcell(varname, color)
}

ColorCell(cell_to_paint, color:="red")
{
 GuiControl, +c%color%  , %cell_to_paint%
 GuiControl, MoveDraw, % cell_to_paint
}

getcontrol(crtname, what)
{
 guicontrolget, out,  Pos, %crtname%

 if (what="x")
 return % outx

 if (what="y")
 return % outy

 if (what="w")
 return % outW

 if (what="h")
 return % outH

 if (what="yh")
 return % outy + outH 

 if (what="xw")
 return % outx + outW
}

Grid(ctr:="text", clln:="", type:=1, gpx:=10, gpy:=10, cols:=30, rows:=20, cllw:=32, cllh:=32, wsp:=31, hsp:=31, opt:=" BackGroundTrans gclick -disabled border 0x201", fill:="")
{
  global
  r:=0,  c:=0, idx:=0
     While r++ < rows {
        while c++ < cols{
          idx++
                  gui 1: add, % ctr, % opt " w"cllw " h"cllh " v" ((type=1) ? (clln r "_" c " Hwndh" clln  r "_" c) : (type=2) ? (clln c "_" r " Hwndh" clln  c "_" r) : (clln idx " Hwndh" clln  a_index)) ((c=1 && r=1) ? " x"gpx " y"gpy " section"
               : (c!=1 && r=1) ? " xp+"wsp " yp" : (c=1 && r!=1) ? " xs" " yp+"hsp : " xp+"wsp " yp"), % fill
          } c:=0
     } r:=c:=idx:=0
}

;by just me
CheckRGB(Match) {
   Loop, Parse, Match, `,, %A_Space%
      If (A_LoopField > 255) {
         ;MsgBox, 16, %A_ThisFunc%, Invalid RGB value %Match%! ; for testing
         Return 1
      }
}

;by polyethene
rgbToHex(s, d = "") {

	StringSplit, s, s, % d = "" ? "," : d

	SetFormat, Integer, % (f := A_FormatInteger) = "D" ? "H" : f

	h := s1 + 0 . s2 + 0 . s3 + 0

	SetFormat, Integer, %f%

	Return,  RegExReplace(RegExReplace(h, "0x(.)(?=$|0x)", "0$1"), "0x")

}

; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=66463
HexToRGB(Color, Mode="") ; Input: 6 characters HEX-color. Mode can be RGB, Message (R: x, G: y, B: z) or parse (R,G,B)
{
   ; If df, d is *16 and f is *1. Thus, Rx = R*16 while Rn = R*1
   Rx := SubStr(Color, 1,1), Rn := SubStr(Color, 2,1)
   Gx := SubStr(Color, 3,1), Gn := SubStr(Color, 4,1)
   Bx := SubStr(Color, 5,1), Bn := SubStr(Color, 6,1)
   
   AllVars := "Rx|Rn|Gx|Gn|Bx|Bn"
   Loop, Parse, Allvars, | ; Add the Hex values (A - F)
   {
      StringReplace, %A_LoopField%, %A_LoopField%, a, 10
      StringReplace, %A_LoopField%, %A_LoopField%, b, 11
      StringReplace, %A_LoopField%, %A_LoopField%, c, 12
      StringReplace, %A_LoopField%, %A_LoopField%, d, 13
      StringReplace, %A_LoopField%, %A_LoopField%, e, 14
      StringReplace, %A_LoopField%, %A_LoopField%, f, 15
   }
   R := Rx*16+Rn
   G := Gx*16+Gn
   B := Bx*16+Bn
   
   If (Mode = "Message") ; Returns "R: 255 G: 255 B: 255"
      Out := "R:" . R . " G:" . G . " B:" . B
   else if (Mode = "Parse") ; Returns "255,255,255"
      Out := R . "," . G . "," . B
   else
      Out := R . G . B ; Returns 255255255
    return Out
}

return
 
guiclose:
~esc:: 
    Gui, Hide
    return
^Esc::exitapp 

F2::
    if WinExist("outline1")
        gosub PickClr
    else gosub CopyClr
Return

+F2::Gui, Show

f3::
    FileSelectFile, ClrFls, 3,, Open a file, Color Charts (*.txt; *.clr)
    FileRead, Clip, % ClrFls
    gosub ShowClr
Return

#LButton::
    Loop, 4 {
        Gui, % A_Index+95 ": -Caption +ToolWindow +AlwaysOnTop -DPIScale"
        Gui, % A_Index+95 ": Color", % Clr? Clr: Clr:="ff8080"
        Gui, % A_Index+95 ": Show", NA h0 w0, outline%A_Index%
    }

    CoordMode, Mouse, Screen
    CoordMode, Pixel, Screen
    MouseGetPos, x1, y1
    While GetKeyState("LButton", "P") {
        MouseGetPos, x2, y2
        ;PixelGetColor, Grc, % x2, % y2, RGB
        ;rr:=Grc>>16, gg:=Grc>>8&0xff, bb:=Grc&0xff, cGrc:=sqrt(.241*rr**2+.691*gg**2+.068*bb**2)
        ;cGrc<130? FrameColor:= 0xffffff: FrameColor:= 0x000000
        ;loop, 4
            ;Gui, % A_Index+95 ": Color", % FrameColor
        if (x1<x2 && y1<y2) {
            nx1:=x1, ny1:=y1, nx2:=x2, ny2:=y2
            Gui, 96:Show, % "NA X" x1+0 " Y" y1-4 " W" x2-x1+4 " H" 4
            Gui, 97:Show, % "NA X" x2+0 " Y" y1-0 " W" 4 " H" y2-y1+4
            Gui, 98:Show, % "NA X" x1-4 " Y" y2-0 " W" x2-x1+4 " H" 4
            Gui, 99:Show, % "NA X" x1-4 " Y" y1-4 " W" 4 " H" y2-y1+4
        } else if (x1>x2 && y1<y2) {
            nx1:=x2, ny1:=y1, nx2:=x1, ny2:=y2
            Gui, 96:Show, % "NA X" x2-4 " Y" y1-4 " W" x1-x2+4 " H" 4
            Gui, 97:Show, % "NA X" x1+0 " Y" y1-4 " W" 4 " H" y2-y1+4
            Gui, 98:Show, % "NA X" x2-0 " Y" y2-0 " W" x1-x2+4 " H" 4
            Gui, 99:Show, % "NA X" x2-4 " Y" y1+0 " W" 4 " H" y2-y1+4
        } else if (x1<x2 && y1>y2) {
            nx1:=x1, ny1:=y2, nx2:=x2, ny2:=y1
            Gui, 96:Show, % "NA X" x1-4 " Y" y2-4 " W" x2-x1+4 " H" 4
            Gui, 97:Show, % "NA X" x2+0 " Y" y2-4 " W" 4 " H" y1-y2+4
            Gui, 98:Show, % "NA X" x1-0 " Y" y1+0 " W" x2-x1+4 " H" 4
            Gui, 99:Show, % "NA X" x1-4 " Y" y2+0 " W" 4 " H" y1-y2+4
        } else if (x1>x2 && y1>y2) {
            nx1:=x2, ny1:=y2, nx2:=x1, ny2:=y1
            Gui, 96:Show, % "NA X" x2-4 " Y" y2-4 " W" x1-x2+4 " H" 4
            Gui, 97:Show, % "NA X" x1+0 " Y" y2-4 " W" 4 " H" y1-y2+4
            Gui, 98:Show, % "NA X" x2-0 " Y" y1+0 " W" x1-x2+4 " H" 4
            Gui, 99:Show, % "NA X" x2-4 " Y" y2-0 " W" 4 " H" y1-y2+4
        }
        Sleep, 25
    }
Return

+F4::
    Loop, 4
        Gui, % A_Index+95 ": Show", NA
Return

#IfWinExist, Enter raster
Esc::WinClose Enter raster

#IfWinExist, outline1
F4::
    if WinExist("outline1") {
        if clr=ff8080
            loop, 4
                Gui, % A_Index+95 ": Color", % Clr:="80ff80"
        else if clr=80ff80
            loop, 4
                Gui, % A_Index+95 ": Color", % Clr:="8080ff"
        else if clr=8080ff
            loop, 4
                Gui, % A_Index+95 ": Color", % Clr:="ff8080"
    }
Return

F5:: InputBox, raster, Enter raster,,, 170, 105, % x1, % y1,,, % raster

DestroyFrame:
Esc::
    Loop, 4
        Gui, % A_Index+95 ": Hide"
Return

#IfWinExist, Show Me That Color
F6::
    FileSelectFile, SaveFls, S16,, Save File As, Color Charts (*.clr; *.txt)
    if FileExist(SaveFls)
        FileDelete, % SaveFls
    FileAppend, % Clip, % SaveFls
Return

PickClr:
    Gosub, DestroyFrame
    Clip:= ""
    loop, % (ny2-ny1)//raster {
        aIndex:= A_Index
        loop, % (nx2-nx1)//raster {
            PixelGetColor, clrPix, % nx1+A_Index*raster, % ny1+aIndex*raster, RGB
            if !InStr(Clip, clrPix)
                Clip.= clrPix "`r`n"
        }
    }
    gosub ShowClr
Return
Edit: Fixed frame color after being changed
Attachments
SpeeMasetr's Avatar colors.zip
(1.39 KiB) Downloaded 12 times
SpeedMaster's avatar color chart.png
SpeedMaster's avatar color chart.png (30.77 KiB) Viewed 1010 times
User avatar
SpeedMaster
Posts: 353
Joined: 12 Nov 2016, 16:09

Re: [Tool] Show Me That Color (display selected text colors in a GUI)

05 Sep 2019, 15:37

rommmcek wrote:
05 Sep 2019, 06:58
O.k., here is my version:
Thanks for all the improvements you made to the script. :D
I particularly like the "pallet stealer" and the possibility to open a file. :thumbup:
I'm now using your script (mine is a little obsolete :mrgreen: ).
However, I had to make some changes to make the script working:
  • When the tool is launched with an external script (F9::Run, show_me_that_color.ahk) the interface will not appear even if a color is selected.
    :arrow: added gosub, copyClr before the first return to fix the problem.
  • when launched with an external script using the same shotcut (F2::run,...), the interface sometimes appears and sometimes not (key conflict).
    :arrow: do not use F2 to F6 shortcuts to launch the script from an external script.
  • clipwait, 200 replaced by clipwait, 0.2 otherwise the script will wait 200 seconds before displaying the GUI if no color is selected.
  • added an option to exit or hide the script when the GUI is closed. (ExitOnGuiClose:=true or false)
    :arrow: You can choose between exiting the application or hiding it when you close the GUI.
  • Modified shortcut +F2 to toggle. (Same shortcut will now show or hide the GUI)
Let me know if you find any new bugs. :think:
Best regards
rommmcek
Posts: 694
Joined: 15 Aug 2014, 15:18

Re: [Tool] Show Me That Color (display selected text colors in a GUI)

06 Sep 2019, 00:28

Win 10 overrides previous Hotkey (no conflict), but it's a good point to change the script in order to retain user experience backwards compatible as much as possible!
New version:
  • Fixed raster InputBox position near right/bottom edge of the screen
  • When saving displayed color chart, number of (current) columns are saved too
  • When loading existing color chart, number of columns (if present) are retrieved and used at display
Inherited by the old version the apply routine does not cut off excessive rows (sometimes).
Not essential, but as the author, maybe you could fix this quirk and it would be a still better app.
Spoiler
User avatar
SpeedMaster
Posts: 353
Joined: 12 Nov 2016, 16:09

Re: [Tool] Show Me That Color (display selected text colors in a GUI)

06 Sep 2019, 04:23

rommmcek wrote:
06 Sep 2019, 00:28
Inherited by the old version the apply routine does not cut off excessive rows (sometimes).
This bug happens to me when I use the pallet stealer or open a file, lastfound var was not reset to zero. I think it's fixed now :think: .

New Version 1.54 :)
  • Fixed bug : the apply routine does not cut off excessive rows (sometimes).
  • Fixed bug : when user open the file selector and press cancel.
  • Fixed bug : the user selects the number of columns when no chart is loaded.
rommmcek
Posts: 694
Joined: 15 Aug 2014, 15:18

Re: [Tool] Show Me That Color (display selected text colors in a GUI)

06 Sep 2019, 09:36

Works fine! Thank you!
Another quirk is: Escaping dialog box (Open, Save) or range frame exits/hides application too. So I added:

Code: Select all

~ESC::
    if !WinActive("Show Me That Color v" version) || WinExist("outline1")
        Return
;   . . .
And last lines of the apply routine should be

Code: Select all

;   . . . 
if (lastfound) && (getcontrol("t" lastfound, "yh") < A_ScreenHeight)
	gui, show, % "w" edgeX+10 " h" getcontrol("t" lastfound, "yh")+5, Show Me That Color v%version%
else
	gui, show, % "w" edgeX+10, Show Me That Color v%version%

return
to set right WinTitle.
User avatar
SpeedMaster
Posts: 353
Joined: 12 Nov 2016, 16:09

Re: [Tool] Show Me That Color (display selected text colors in a GUI)

06 Sep 2019, 11:42

rommmcek wrote:
06 Sep 2019, 09:36
Another quirk is: ...
Fixed thanks :thumbup:

New version 1.55
  • Fixed : Escaping dialog box (Open, Save)
  • Fixed : Range frame exits/hides application too
rommmcek
Posts: 694
Joined: 15 Aug 2014, 15:18

Re: [Tool] Show Me That Color (display selected text colors in a GUI)

10 Sep 2019, 08:41

This is now all I wanted:
  • added ToolTip info (particularly useful for named charts)
  • added Color dialog (see "How to use" at the top of the script)
  • several (minor) bug fixes and (small) improving features
  • Attached some named color charts/pallets. (It's much easier to remember if you have a name)
Spoiler
Edit(2x): Forgot to include improved PickClr: label. (fixed)
Edit(3th): Tiny bug fixed (if (WinActive("Show Me That Color v" version) && ClrUnderM!="") {)
Edit4, 5, 6, 7, 8: First saving bug fixed, additional new small features.
Edit9, 10: Improved color stealer raster + RegEx modification (no W7 test yet)
P.s.: Remains to see if there are some bugs and THANK YOU!
Attachments
Named Colors.zip
(9.41 KiB) Downloaded 13 times
Last edited by rommmcek on 15 Sep 2019, 04:42, edited 18 times in total.
User avatar
SpeedMaster
Posts: 353
Joined: 12 Nov 2016, 16:09

Re: [Tool] Show Me That Color (display selected text colors in a GUI)

10 Sep 2019, 14:31

v1.56 Not working :cry:
Error: Missing a "}" somewhere near the lingne 478. :!:

Return to “Scripts and Functions”

Who is online

Users browsing this forum: DigiDon and 45 guests