Jump to content

Doubt about RGB change color effect


Luigi
 Share

Recommended Posts

Hi forum,
 
I made this little script to fade a color's background control. I see the color change is not perfect.
 
Sometimes it seems that the color shines too much and then lose a bit of intensity until the normal color.
 
If you use a background color (0x64C896) the efect seems perfect.
If you use a white backgorund, the effect mentioned it apear.
 

;~ #AutoIt3Wrapper_AU3Check_Parameters= -q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7
;~ #Tidy_Parameters=/sf
#include-once
#include <Color.au3>
#include <WinAPIGdi.au3>
#include <Array.au3>
#include <GuiConstants.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <object_dump.au3>

OnAutoItExitRegister("_EXIT_BEFORE")

Opt("GUIOnEventMode", 1)
Opt("GUIEventOptions", 1)
Opt("MustDeclareVars", 1)

Global $aGui[9] = [0, "efeito", 520, 360, -1, -1, Default, $WS_EX_COMPOSITED, 0]

Global $aMouse, $hGui, $OVER
Global $SD = "Scripting.Dictionary"
Global $oo = ObjCreate($SD)

$aGui[0] = GUICreate($aGui[1], $aGui[2], $aGui[3], $aGui[4], $aGui[5], $aGui[6], $aGui[7], $aGui[8])
GUISetOnEvent($GUI_EVENT_CLOSE, "_EXIT")
;~ GUISetBkColor(0x64C896, $aGui[0])

Local $h1 = GUICtrlCreateLabel("Label", 10, 10, 90, 30)
Local $h2 = GUICtrlCreateButton("Button", 110, 10, 90, 30)
Local $h3 = GUICtrlCreateRadio("Radio", 210, 10, 90, 30)
Local $h4 = GUICtrlCreateGroup("Group", 310, 10, 90, 30)
Local $h5 = GUICtrlCreateCheckbox("CheckBox", 410, 10, 90, 30)
Local $h6 = GUICtrlCreateCombo("Combo", 10, 60, 90, 30)
Local $h7 = GUICtrlCreateInput("Input", 110, 60, 90, 30)
Local $h8 = GUICtrlCreateList("List", 210, 60, 90, 90)

GUISetState(@SW_SHOW, $hGui)


__BackEffectStart()
AddBack_Effect($aGui[0], $h1)
AddBack_Effect($aGui[0], $h2)
AddBack_Effect($aGui[0], $h3)
AddBack_Effect($aGui[0], $h4)
AddBack_Effect($aGui[0], $h5)
AddBack_Effect($aGui[0], $h6)
AddBack_Effect($aGui[0], $h7)
AddBack_Effect($aGui[0], $h8)

Func AddBack_Effect($hGui, $hControl = 0, $iBorder = 4)
    #forcedef $g_oBackeffect_Control
    If Not $hControl Or $g_oBackeffect_Control.Exists($hControl) Then Return SetError(1, 0, 0)
    Local $aPos = ControlGetPos($hGui, "", $hControl)
    Local $temp = GUICtrlCreateLabel("", $aPos[0] - $iBorder, $aPos[1] - $iBorder, $aPos[2] + $iBorder * 2, $aPos[3] + $iBorder * 2)

    $g_oBackeffect_Control.Add($hControl, $temp)
    $g_oBackeffect_Control.Add($temp, $temp)


EndFunc   ;==>AddBack_Effect

Func __BackEffectStart($iColorOver = 0x00FF00, $iDelay = 10, $iIncrement = 5)
    __BackEffect_EvalNumber($iDelay, 10)
    __BackEffect_EvalNumber($iIncrement, 2)

    If Not IsDeclared("g_aBackEffect_Over") Then Global $g_aBackEffect_Over = __BackEffect_SplitColor(Hex($iColorOver, 6))
    If Not IsDeclared("g_aBackEffect_Back") Then Global $g_aBackEffect_Back = __BackEffect_SplitColor(Hex(GUIGetBkColor($aGui[0]), 6))
    If Not IsDeclared("g_iBackeffect_Delay") Then Global $g_iBackeffect_Delay = $iDelay
    If Not IsDeclared("g_iBackeffect_Increment") Then Global $g_iBackeffect_Increment = $iIncrement
    If Not IsDeclared("g_oBackeffect_Control") Then Global $g_oBackeffect_Control = ObjCreate("Scripting.Dictionary")
    If Not IsDeclared("g_aBackeffect_Split") Then Global $g_aBackeffect_Channel
    If Not IsDeclared("g_aBackeffect_RGB") Then Global $g_aBackeffect_Channel

    AdlibRegister("__BackEffect", $g_iBackeffect_Delay)
    OnAutoItExitRegister("__BackEffectStop")
EndFunc   ;==>__BackEffectStart

Func __BackEffect_EvalNumber(ByRef $iNumber, $iMin)
    $iNumber = Int(Abs(Number($iNumber)))
    $iNumber = ($iNumber < $iMin) ? $iMin : $iNumber
EndFunc   ;==>__BackEffect_EvalNumber

Func __BackEffectStop()
    AdlibUnRegister("__BackEffect")
EndFunc   ;==>__BackEffectStop


Func __BackEffect()
    If $OVER And Not $oo.Exists($OVER) Then $oo.Add($OVER, Hex($g_aBackEffect_Back[3]))
    For $each In $oo
        If $each == $OVER Then
            If Not ("0x" & $oo.Item($each) == $g_aBackEffect_Over[3]) Then
                $g_aBackeffect_Channel = __BackEffect_SplitColor($oo.Item($each))
                For $ii = 0 To 2
                    $g_aBackeffect_Channel[$ii] = __BackEffect_Compare($g_aBackEffect_Over[$ii], $g_aBackeffect_Channel[$ii], $g_aBackeffect_Channel[$ii])
                Next
                $oo.Item($each) = Hex($g_aBackeffect_Channel[0], 2) & Hex($g_aBackeffect_Channel[1], 2) & Hex($g_aBackeffect_Channel[2], 2)
                GUICtrlSetBkColor($each, "0x" & $oo.Item($each))
            EndIf
        Else
            If Not ("0x" & $oo.Item($each) == $g_aBackEffect_Back[3]) Then
                $g_aBackeffect_Channel = __BackEffect_SplitColor($oo.Item($each))
                For $ii = 0 To 2
                    $g_aBackeffect_Channel[$ii] = __BackEffect_Compare($g_aBackEffect_Back[$ii], $g_aBackeffect_Channel[$ii], $g_aBackeffect_Channel[$ii])
                Next
                $oo.Item($each) = Hex($g_aBackeffect_Channel[0], 2) & Hex($g_aBackeffect_Channel[1], 2) & Hex($g_aBackeffect_Channel[2], 2)
                GUICtrlSetBkColor($each, "0x" & $oo.Item($each))
            EndIf
        EndIf
    Next
EndFunc   ;==>__BackEffect

Func __BackEffect_Compare($FROM, $TO, $iChannel)
    ConsoleWrite("__BackEffect_Compare( $FROM=" & $FROM & ", $TO=" & $TO & ", $iChannel=" & $iChannel & " )" & @LF)
    Switch $FROM
        Case $TO
            $iChannel = $FROM
        Case Else
            If $FROM > $TO Then
                $iChannel = $TO + $g_iBackeffect_Increment
                If $iChannel > $FROM Then $iChannel = $FROM
            Else
                $iChannel = $TO - $g_iBackeffect_Increment
                If $iChannel < $FROM Then $iChannel = $FROM
            EndIf
    EndSwitch
    Return $iChannel
EndFunc   ;==>__BackEffect_Compare

Func __BackEffect_SplitColor($input)
;~  ConsoleWrite("__BackEffect_SplitColor[ " & $input & " ] $Red[ " & $Red & " ] $Green[ " & $Green & " ] $Blue[ " & $Blue & " ]" & @LF)
    Local $arr[4] = [BitAND(BitShift("0x" & $input, 16), 0xFF), BitAND(BitShift("0x" & $input, 8), 0xFF), BitAND("0x" & $input, 0xFF), "0x" & $input]
    Return $arr
EndFunc   ;==>__BackEffect_SplitColor

; #FUNCTION# ====================================================================================================================
; Name ..........: GUIGetBkColor
; Description ...: Retrieves the RGB value of the GUI background.
; Syntax ........: GUIGetBkColor($hWnd)
; Parameters ....: $hWnd                - A handle of the GUI.
; Return values .: Success - RGB value
;                  Failure - 0
; Author ........: guinness
; Example .......: Yes
; ===============================================================================================================================
Func GUIGetBkColor($hWnd)
    Local $iColor = 0
    If IsHWnd($hWnd) Then
        Local $hDC = _WinAPI_GetDC($hWnd)
        $iColor = _WinAPI_GetBkColor($hDC)
        _WinAPI_ReleaseDC($hWnd, $hDC)
    EndIf
    Return $iColor
EndFunc   ;==>GUIGetBkColor

While Sleep(10)
    $aMouse = GUIGetCursorInfo($aGui[0])
    If @error Or Not $aMouse[4] Then
        $OVER = 0
    Else
        $OVER = $g_oBackeffect_Control.Item($aMouse[4])
    EndIf
WEnd

Func _EXIT()
    Exit
EndFunc   ;==>_EXIT

Func _EXIT_BEFORE($sInput = 0)
    If IsDeclared("sInput") Then ConsoleWrite("_exit[ " & $sInput & " ]" & @LF)
    GUIDelete($aGui[0])
EndFunc   ;==>_EXIT_BEFORE

 
Or am I crazy and this effect only happens on my computer?  :lmao:
 
Or algorithm that is wrong?
 
Detefon

__Color 01.au3

Edited by Detefon

Visit my repository

Link to comment
Share on other sites

After read that, I change my monitor, the main monitor is a  LG 2342 Cinema 3D, and connect a secondary monitor, a very old Samsung SyncMaster B1630, no problems to display image. It's perfect.

Amazing how nowadays can buy modern crap like this LG monitor.

The force will be with you DarthCookie!  :shocked:

Visit my repository

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...