It is currently April 16th, 2024, 7:05 am

Rainmeter Color Picker Skin

Share and get help with Plugins and Addons
User avatar
Alex2539
Rainmeter Sage
Posts: 642
Joined: July 19th, 2009, 5:59 am
Location: Montreal, QC, Canada

Re: Rainmeter Color Picker Skin

Post by Alex2539 »

You are misusing !RainmeterSetVariable. The second parameter (Swatch1) is not the name of another variable, but the actual value you want to set the as the value for the variable named in the first parameter (ColorPicker). What you have written there will set the ColorPicker variable to literally the word "Swatch1". Instead, you would need to place number signs (ie: "#") around the variable's name in order to use its value. Also, the third parameter (GetUnderColor) indicates the name of the config in which to change the variable. What this means is that you are setting the variable for another skin to use. The skin running the !Bang will never see this change since it is happening elsewhere. To set the variable within the current config, do not specify a third parameter at all.

Finally, this method will not work the way you expect it to anyways. Your colour picker changes the value of the variable within the .inc file. In order for that value to be read, the skins using that .inc file must be refreshed. This means that the new colours will appear, but not dynamically.
ImageImageImageImage
User avatar
brijamelsh
Posts: 47
Joined: July 16th, 2010, 4:24 am

Re: Rainmeter Color Picker Skin

Post by brijamelsh »

I see, however the GetUnderColor addon refreshes the skins automatically it would seem. So I would expect the color to change in the Sample ini for swatch1 sense the GetUnderColor addon should rewrite the value for the variable swatch1 in the variables.inc.
User avatar
brijamelsh
Posts: 47
Joined: July 16th, 2010, 4:24 am

Re: Rainmeter Color Picker Skin

Post by brijamelsh »

Any way we could get variable support for Parm1

I'd like to be able to toggle which variable of the uservariables.inc is targeted.
User avatar
brijamelsh
Posts: 47
Joined: July 16th, 2010, 4:24 am

Re: Rainmeter Color Picker Skin

Post by brijamelsh »

Bump...

Is it possible to do

!Execute ["#ADDONSPATH#GetUnderColor\GetUnderColor.exe" "#parm1variable#" "parm2" "parm3" "parm4" "parm5"]

Ive tried it but it doesn't seem to work.
User avatar
MerlinTheRed
Rainmeter Sage
Posts: 889
Joined: September 6th, 2011, 6:34 am

Re: Rainmeter Color Picker Skin

Post by MerlinTheRed »

Wow! I've been looking for something like this for ages. Not necessarily for Rainmeter, perhaps, but it nevertheless does what I need! Thank you very much!
Have more fun creating skins with Sublime Text 2 and the Rainmeter Package!
User avatar
KreAch3R
Posts: 608
Joined: February 7th, 2011, 7:27 pm
Location: Thessaloniki, GR

Re: Rainmeter Color Picker Skin

Post by KreAch3R »

I wanted to incorporate your addon into my new suite, and because it is written long ago, it searches for Rainmeter.exe, and doesn't support the @Resources/Addons/ standard. So, to make the story short, I tried to update it to the latest features provided by Rainmeter. This is the .au3:

Code: Select all

#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseUpx=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GDIPlus.au3>
#include <Color.au3>
#include <ScreenCapture.au3>
#include <SendMessage.au3>

; ==========================================================================================
; GetUnderColor.exe For Rainmeter
; Jeffrey Morley - June 4, 2010
; License=Creative Commons Attribution-Non-Commercial-Share Alike 3.0
; _Area_Average_Colour function written by Melba23. Credit to Malkey for the basic GDI code
; ==========================================================================================

;~ $AppDataDir = EnvGet("APPDATA")
$FileToSet = ""
$WidthToSample=10
$HeightToSample=10

;~ If FileFindFirstFile("..\..\Rainmeter.ini") <> - 1 Then
;~ 	$DataFolder = "..\..\"
;~ 	$Portable = 1
;~ ElseIf FileFindFirstFile($AppDataDir & "\Rainmeter\Rainmeter.ini") <> - 1 Then
;~ 	$DataFolder = $AppDataDir & "\Rainmeter\"
;~ 	$Portable = 0
;~ Else
;~ 	Exit
;~ EndIf

If $CmdLine[0] = 5 Then
	$VarToSet = $CmdLine[1]
	$CrosshairConfig = $CmdLine[2]
	$CrosshairMeter = $CmdLine[3]
	$FileToSet = $CmdLine[4]
	$HexDec = $CmdLine[5]
Else
	Exit
EndIf

$pos = MouseGetPos()
;~ Sendbang("[!SetVariable X " & $pos[0] & "][!SetVariable Y " & $pos[1] & "]")

$ColorAreaLeft = $pos[0]
$ColorAreaTop = $pos[1]

;~ $ColorAreaLeft = IniRead($DataFolder & "Rainmeter.ini", $CrosshairConfig,"WindowX","0")
;~ $ColorAreaTop = IniRead($DataFolder & "Rainmeter.ini", $CrosshairConfig,"WindowY","0")

;~ ShellExecute("..\..\Rainmeter.exe", "!RainmeterHideMeter " & $CrosshairMeter & " " & $CrosshairConfig)
Sendbang("!HideMeter " & $CrosshairMeter & " " & $CrosshairConfig & "")


sleep(1000)
;~ $sScreen_Average = _Area_Average_Colour(10, 500, 600, 10, 10)
;~ $sScreen_Average = _Area_Average_Colour(10, $pos[0], $pos[1], $WidthToSample, $HeightToSample)
$sScreen_Average = _Area_Average_Colour(10, $ColorAreaLeft, $ColorAreaTop, $WidthToSample, $HeightToSample)
Sendbang("[!SetVariable Avg " & $sScreen_Average & "]")

;~ ShellExecute("..\..\Rainmeter.exe", "!RainmeterShowMeter " & $CrosshairMeter & " " & $CrosshairConfig)
Sendbang("!ShowMeter " & $CrosshairMeter & " " & $CrosshairConfig & "")

$Red = dec(StringLeft($sScreen_Average, 2))
$Green = dec(StringMid($sScreen_Average,3,2))
$Blue = dec(StringRight($sScreen_Average,2))

If $HexDec = "0" Then
	$RainMeterColorValue = $Red & "," & $Green & "," & $Blue
Else
	$RainMeterColorValue = $sScreen_Average
EndIf

IniWrite($FileToSet, "Variables", $VarToSet, $RainMeterColorValue)

;~ ShellExecute("..\..\Rainmeter.exe", "!RainmeterRefreshApp")
;~ Sendbang("!RefreshApp")

Exit


Func SendBang($szBang)
   Local Const $hWnd = WinGetHandle("[CLASS:RainmeterMeterWindow]")
   If $hWnd <> 0 Then
     Local Const $iSize = StringLen($szBang) + 1

      Local Const $pMem = DllStructCreate("wchar[" & $iSize & "]")
      DllStructSetData($pMem, 1, $szBang)

      Local Const $pCds = DllStructCreate("dword;dword;ptr")
      DllStructSetData($pCds, 1, 1)
      DllStructSetData($pCds, 2, ($iSize * 2))
      DllStructSetData($pCds, 3, DllStructGetPtr($pMem))

      Local Const $WM_COPYDATA = 0x004A
      _SendMessage($hWnd, $WM_COPYDATA, 0, DllStructGetPtr($pCds))
   EndIf
EndFunc



; #FUNCTION# =========================================================================================================
; Name...........: _Area_Average_Colour
; Description ...: Returns average colour within a defined are of the display
; Syntax ........: _Area_Average_Colour([$iStep [, $iLeft [, $iTop [, $iWidth [, $iHeight ]]]]])
; Parameters ....: $iStep   - Pixel resolution value.  Lower values give better resolution but take longer. (Default = 10)
;                  $iLeft   - X coordinate of top-left corner of area (Default = 0 - left edge of screen)
;                           - If this parameter holds a window HANDLE, the area is set to the client area of the window
;                  $iTop    - Y coordinate of top-left corner of area (Default = 0 - top edge of screen)
;                  $iWidth  - Width of the area (Default = @DesktopWidth)
;                  $iHeight - Height of the area (Default = @DesktopHeight)
; Requirement(s) : v3.3.0.0 or higher
; Return values .: Success - Returns six character string containing RGB hex values
;                  Failure - Returns 0 and sets @error:
;                  1 - Screen Capture failure
;                  2 - GDI function failure
; Author ........: Melba23.   Credit to Malkey for the basic GDI code
; Modified ......:
; Remarks .......:
; Example .......: Yes
;=====================================================================================================================
Func _Area_Average_Colour($iStep = 10, $iLeft = 0, $iTop = 0, $iWidth = @DesktopWidth, $iHeight = @DesktopHeight)

    Local $iBlue = 0, $iGreen = 0, $iRed = 0, $iInterim_Blue = 0, $iInterim_Green = 0, $iInterim_Red = 0, $iInner_Count = 0, $iOuter_Count = 0

    If IsHWnd($iLeft) Then
        $hWnd = $iLeft
        Local $tPoint = DllStructCreate("int X;int Y")
        DllStructSetData($tpoint, "X", 0)
        DllStructSetData($tpoint, "Y", 0)
        _WinAPI_ClientToScreen($hWnd, $tPoint)
        $iLeft = DllStructGetData($tPoint, "X")
        $iTop = DllStructGetData($tPoint, "Y")
        $aSize = WinGetClientSize($hWnd)
        $iWidth =  $aSize[0]
        $iHeight = $aSize[1]
    EndIf

    _GDIPlus_Startup()

    Local $hBMP = _ScreenCapture_Capture("", $iLeft, $iTop, $iLeft + $iWidth, $iTop + $iHeight)
    If $hBMP = 0 Then
        _GDIPlus_Shutdown()
        Return SetError(1, 0, 0)
    EndIf

    Local $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)
    If $hImage = 0 Then
        _WinAPI_DeleteObject($hBMP) ; <<<<<<<<<<<<<
        _GDIPlus_Shutdown()
        Return SetError(2, 0, 0)
    EndIf

    Local $tRes = _GDIPlus_BitmapLockBits($hImage, 0, 0, $iWidth, $iHeight, BitOR($GDIP_ILMREAD, $GDIP_ILMWRITE), $GDIP_PXF32ARGB)
    If @error Then
        _GDIPlus_BitmapDispose($hImage) ; <<<<<<<<<<<<<
        _WinAPI_DeleteObject($hBMP)     ; <<<<<<<<<<<<<
        _GDIPlus_Shutdown()
        Return SetError(2, 0, 0)
    EndIf

    ;Get the returned values of _GDIPlus_BitmapLockBits()
    Local $iLock_Width  = DllStructGetData($tRes, "width")
    Local $iLock_Height = DllStructGetData($tRes, "height")
    Local $iLock_Stride = DllStructGetData($tRes, "stride")
    Local $iLock_Scan0  = DllStructGetData($tRes, "Scan0")

    ; Run through the BitMap testing pixels at the step distance
    For $i = 0 To $iWidth - 1 Step $iStep
        For $j = 0 To $iHeight - 1 Step $iStep
            Local $v_Buffer = DllStructCreate("dword", $iLock_Scan0 + ($j * $iLock_Stride) + ($i * 4))
            ; Get colour value of pixel
            Local $v_Value = DllStructGetData($v_Buffer, 1)
            ; Add components
            $iBlue  += _ColorGetBlue($v_Value)
            $iGreen += _ColorGetGreen($v_Value)
            $iRed   += _ColorGetRed($v_Value)
            ; Adjust counter
            $iInner_Count += 1
        Next
        ; Determine average value so far - this prevents value becoming too large
        $iInterim_Blue  += $iBlue / $iInner_Count
        $iBlue = 0
        $iInterim_Green += $iGreen / $iInner_Count
        $iGreen = 0
        $iInterim_Red   += $iRed / $iInner_Count
        $iRed = 0
        ; Adjust counters
        $iInner_Count = 0
        $iOuter_Count += 1
    Next
    ; Determine final average
    Local $avBlue  = Hex(Round($iInterim_Blue / $iOuter_Count, 0), 2)
    Local $avGreen = Hex(Round($iInterim_Green / $iOuter_Count, 0), 2)
    Local $avRed   = Hex(Round($iInterim_Red / $iOuter_Count, 0), 2)

    ; Clear up

    _GDIPlus_BitmapUnlockBits($hImage, $tRes)
    _GDIPlus_BitmapDispose($hImage) ; <<<<<<<<<<<<<
    _WinAPI_DeleteObject($hBMP)     ; <<<<<<<<<<<<<
    _GDIPlus_Shutdown()

    Return ($avRed & $avGreen & $avBlue)

EndFunc   ;==>_Area_Average_Colour
I'm sorry for the many commented out lines, but I was trying to troubleshoot. My problem is that the color written in the external Variable file is always 000000 or 0,0,0 (depending on HexDec). After a LOT of mixing codes, trying to figure out what part of my edits cause the error, I tried to simply compile your unedited .au3 into an .exe, and use that. The same error happens! And I don't know why. Can you look at it? Did I mess some of my files up or there is some incompatibility between the version you compiled it and the latest AutoIt?

Thanks as always, and sorry for the grave digging. :)
Inactive, due to life changes. Send me a PM for any question.

Desktop DeviartArt
Image
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Rainmeter Color Picker Skin

Post by jsmorley »

Still works fine for me as is, let me look at modifying it to use @Resources for the addon. Shouldn't be too much work.
User avatar
KreAch3R
Posts: 608
Joined: February 7th, 2011, 7:27 pm
Location: Thessaloniki, GR

Re: Rainmeter Color Picker Skin

Post by KreAch3R »

If I try to use the .exe without modifying anything, it works for me, too! If I try to re-compile from .au3, I get the '000000' error. Thanks for looking it up.

Nexus S / Tapatalk 2
Inactive, due to life changes. Send me a PM for any question.

Desktop DeviartArt
Image
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Rainmeter Color Picker Skin

Post by jsmorley »

Yeah, I'll keep digging, but I'm getting that too when I recompile it. I also fear some change in AutoIt and hope it isn't too hard to track down.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Rainmeter Color Picker Skin

Post by jsmorley »

Bad news is that it is indeed some change in AutoIt, I think in the GDI+ routines. Going to be a bit of a challenge to track down, as I am no expert in the inner workings of GDI+ in Windows. I mess with it some more, and see if I can get hold of the guy who wrote the original routines to get the color under the cursor on the AutoIt forums.