Jump to content

Changing Colors


Recommended Posts

Apple devices do this crazy thing where is the background color is darker it changes the apps names to white and if the background is lighter (whiter) the text changed to black so you can see everything easier.

I was wondering if I could copy this effect into my script that I'm writing (With the help of FireFox and Melba :)) but I keep running into problems with the main part so I decided to just work on another thing that's still within the script. I tells you the Hex color under your mouse when you pres the HotKey F10, but I made it so the text changes according to the color you press F10 over. Is there anyways possible to make it see if the text is lighter or darker and change the background accordingly (Should be a simple If/then but I don't how to set it up)

Heres the code, I markes off where the part i'm having trouble with is.

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <ScreenCapture.au3>
#Include <Misc.au3>

Global $iX1, $iY1, $iX2, $iY2, $aPos, $sMsg, $sBMP_Path, $ibr, $ib, $pixcolor, $colorgui, $copycolor, $hexed, $grabbed

; Create GUI
$hMain_GUI = GUICreate("Select Rectangle", 240, 50)

$hRect_Button   = GUICtrlCreateButton("Mark Area",10, 10, 80, 30)
$color = GUICtrlCreateButton("Hex",95,10,50,30)
$hCancel_Button = GUICtrlCreateButton("Cancel",150, 10, 80, 30)

GUISetState()

While 1
      $msg = GUIGetMsg(1)
      Switch $msg[1]
   Case $hMain_GUI
      Switch $msg[0]
        Case $GUI_EVENT_CLOSE, $hCancel_Button
            Exit
        Case $hRect_Button
            GUISetState(@SW_HIDE, $hMain_GUI)
            Mark_Rect()
 
            ConsoleWrite("Top Left Corner X:" & $iX1 & ", Y:" & $iY1 & ",  Bottom Right Corner X:" & $iX2 & ", Y:" & $iY2)
            GUISetState(@SW_SHOW, $hMain_GUI)
            MsgBox(4096,"Your Coords","Your coords are :" & "Top Left Corner X:" & $iX1 & ", Y:" & $iY1 & ",  Bottom Right Corner X:" & $iX2 & ", Y:" & $iY2)
      input()
             Case $color
            MsgBox(4096,"Color","If you want the color under your mouse cursor then press F10")
            EndSwitch
      HotKeySet("{F10}","color")
         Case $colorgui
            Switch $msg[0]
         Case -3
            GUIDelete($colorgui)
            ;Starting from here...
         Case $copycolor
            ClipPut("0x"&Hex($pixcolor,6))
            EndSwitch
            EndSwitch
WEnd
;This isn't part of it.
Func input()
    $ib = InputBox("Hex","Type in the Hex number of the color you wish to find. Example: '0xFFFFFF' for white or 'FFFFFF' for white")
    $ibr = GUICtrlRead($ib)
 MsgBox(4096,"HotKey","Press F11 to start")
 HotKeySet("{F11}","findpix")
 EndFunc
 ;----------
 Func color()
   $mousepos = MouseGetPos()
   $pixcolor = PixelGetColor($mousepos[0],$mousepos[1])
   $colorgui = GUICreate("Your Color",175,100)
   GUISetBkColor(0x660000,$colorgui)
   $copycolor = GUICtrlCreateButton("Copy",35,50,100,30)
   GUISetFont(12,700,2,"Minion Pro")
   $hexed = GUICtrlCreateLabel("0x"&Hex($pixcolor,6),50,17)
   GUISetFont(12,700,2,"Minion Pro")
    ;$grabbed = GUICtrlCreateLabel("Your color is",0,0)
    GUICtrlSetColor($hexed,$pixcolor)
    GUISetState()
   GUIDelete($color)
EndFunc
;And ending here.
func findpix()
    $location = PixelSearch ($iX1, $iY1, $iX2, $iY2, Number(GUICtrlRead($ibr)))
   If IsArray($location) = True Then
    MouseMove($location[0],$location[1], 5)
    EndIf
   EndFunc
; -------------

Func Mark_Rect()

    Local $aMouse_Pos, $hMask, $hMaster_Mask, $iTemp
    Local $UserDLL = DllOpen("user32.dll")

    Global $hRectangle_GUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
    _GUICreateInvRect($hRectangle_GUI, 0, 0, 1, 1)
    GUISetBkColor(0)
    WinSetTrans($hRectangle_GUI, "", 50)
    GUISetState(@SW_SHOW, $hRectangle_GUI)
    GUISetCursor(3, 1, $hRectangle_GUI)

    ; Wait until mouse button pressed
    While Not _IsPressed("01", $UserDLL)
        Sleep(10)
    WEnd

    ; Get first mouse position
    $aMouse_Pos = MouseGetPos()
    $iX1 = $aMouse_Pos[0]
    $iY1 = $aMouse_Pos[1]

    ; Draw rectangle while mouse button pressed
    While _IsPressed("01", $UserDLL)

        $aMouse_Pos = MouseGetPos()

        ; Set in correct order if required
        If $aMouse_Pos[0] < $iX1 Then
            $iX_Pos = $aMouse_Pos[0]
            $iWidth = $iX1 - $aMouse_Pos[0]
        Else
            $iX_Pos = $iX1
            $iWidth = $aMouse_Pos[0] - $iX1
        EndIf
        If $aMouse_Pos[1] < $iY1 Then
            $iY_Pos = $aMouse_Pos[1]
            $iHeight = $iY1 - $aMouse_Pos[1]
        Else
            $iY_Pos = $iY1
            $iHeight = $aMouse_Pos[1] - $iY1
        EndIf

        _GUICreateInvRect($hRectangle_GUI, $iX_Pos, $iY_Pos, $iWidth, $iHeight)

        Sleep(10)

    WEnd

    ; Get second mouse position
    $iX2 = $aMouse_Pos[0]
    $iY2 = $aMouse_Pos[1]

    ; Set in correct order if required
    If $iX2 < $iX1 Then
        $iTemp = $iX1
        $iX1 = $iX2
        $iX2 = $iTemp
    EndIf
    If $iY2 < $iY1 Then
        $iTemp = $iY1
        $iY1 = $iY2
        $iY2 = $iTemp
    EndIf

    GUIDelete($hRectangle_GUI)
    DllClose($UserDLL)

EndFunc   ;==>Mark_Rect

Func _GUICreateInvRect($hWnd, $iX, $iY, $iW, $iH)

    $hMask_1 = _WinAPI_CreateRectRgn(0, 0, @DesktopWidth, $iY)
    $hMask_2 = _WinAPI_CreateRectRgn(0, 0, $iX, @DesktopHeight)
    $hMask_3 = _WinAPI_CreateRectRgn($iX + $iW, 0, @DesktopWidth, @DesktopHeight)
    $hMask_4 = _WinAPI_CreateRectRgn(0, $iY + $iH, @DesktopWidth, @DesktopHeight)

    _WinAPI_CombineRgn($hMask_1, $hMask_1, $hMask_2, 2)
    _WinAPI_CombineRgn($hMask_1, $hMask_1, $hMask_3, 2)
    _WinAPI_CombineRgn($hMask_1, $hMask_1, $hMask_4, 2)

    _WinAPI_DeleteObject($hMask_2)
    _WinAPI_DeleteObject($hMask_3)
    _WinAPI_DeleteObject($hMask_4)

    _WinAPI_SetWindowRgn($hWnd, $hMask_1, 1)

EndFunc

Thanks in advance :)

Link to comment
Share on other sites

You can do something like this ?

$color = "FC2398"
; If (FC + 23 + 98) / 3 is less than or equal to the value "77" (hex), so it's dark, if not clear
$trend = ( (Dec ( StringMid($color, 1, 2) ) + Dec ( StringMid($color, 3, 2) ) + Dec ( StringMid($color, 5, 2) ) ) / 3 <= Dec("77") ) ? ("dark") : ("light")
MsgBox(0, "", $trend)
Edited by jguinch
Link to comment
Share on other sites

It keeps saying

If you post something I won't be able to test it for a couple hours, i'll let you know if it works after I check anything. (Thanks :))

==> Unable to parse line.: 
$trend = ( (Dec ( StringMid($color, 1, 2) ) + Dec ( StringMid($color, 3, 2) ) + Dec ( StringMid($color, 5, 2) ) ) / 3 <= Dec("77") ) ? ("dark") : ("light") 
$trend = ( (Dec ( StringMid($color, 1, 2) ) + Dec ( StringMid($color, 3, 2) ) + Dec ( StringMid($color, 5, 2) ) ) / 3 <= Dec("77") ) ^ ERROR
Edited by gottygolly
Link to comment
Share on other sites

Sorry, I use the last AutoIt version...

$trend = "leight"
If  (Dec ( StringMid($color, 1, 2) ) + Dec ( StringMid($color, 3, 2) ) + Dec ( StringMid($color, 5, 2) ) ) / 3 <= Dec("77") Then $trend =  "dark"
Link to comment
Share on other sites

Sorry for the double post but I just want to get some attention towards this so I can get the best possible answer.

jquinch I tried your code but i'm not really sure where to put it into my code. I tried it every where but it isn't working.

Here's the code at the moment with jguinch's code already in it.

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <ScreenCapture.au3>
#Include <Misc.au3>

Global $iX1, $iY1, $iX2, $iY2, $aPos, $sMsg, $sBMP_Path, $ibr, $ib, $pixcolor, $colorgui, $copycolor, $hexed, $grabbed, $buttons, $copiing

; Create GUI
$hMain_GUI = GUICreate("Select Rectangle", 240, 50)

$hRect_Button   = GUICtrlCreateButton("Mark Area",10, 10, 80, 30)
$color = GUICtrlCreateButton("Hex",95,10,50,30)
$hCancel_Button = GUICtrlCreateButton("Cancel",150, 10, 80, 30)

GUISetState()

While 1
      $msg = GUIGetMsg(1)
      Switch $msg[1]
   Case $hMain_GUI
      Switch $msg[0]
        Case $GUI_EVENT_CLOSE, $hCancel_Button
            Exit
        Case $hRect_Button
            GUISetState(@SW_HIDE, $hMain_GUI)
            Mark_Rect()
 
            ConsoleWrite("Top Left Corner X:" & $iX1 & ", Y:" & $iY1 & ",  Bottom Right Corner X:" & $iX2 & ", Y:" & $iY2)
            GUISetState(@SW_SHOW, $hMain_GUI)
            MsgBox(4096,"Your Coords","Your coords are :" & "Top Left Corner X:" & $iX1 & ", Y:" & $iY1 & ",  Bottom Right Corner X:" & $iX2 & ", Y:" & $iY2)
      input()
             Case $color
            MsgBox(4096,"Color","If you want the color under your mouse cursor then press F10")
            EndSwitch
      HotKeySet("{F10}","color")
         Case $colorgui
            Switch $msg[0]
         Case -3
            GUIDelete($colorgui)
            ;Starting from here...
         Case $copycolor
            ClipPut("0x"&Hex($pixcolor,6))
            ;copied()
         Case $buttons
            ClipPut("0x"&Hex($pixcolor,6))
            copied()
            EndSwitch
         Case $copiing
            Switch $msg[0]
         Case -3
            GUIDelete($copiing)
            EndSwitch
            EndSwitch
WEnd
;This isn't part of it.
Func input()
    $ib = InputBox("Hex","Type in the Hex number of the color you wish to find. Example: '0xFFFFFF' for white or 'FFFFFF' for white")
    $ibr = GUICtrlRead($ib)
 MsgBox(4096,"HotKey","Press F11 to start")
 HotKeySet("{F11}","findpix")
 EndFunc
 ;----------
 Func color()
   $mousepos = MouseGetPos()
   $pixcolor = PixelGetColor($mousepos[0],$mousepos[1])
   $colorgui = GUICreate("Your Color",175,100)
   GUISetBkColor(0x660000,$colorgui)
   $buttons = GUICtrlCreateButton("Copy",35,50,100,30)
   ;$buttons = GUICtrlCreateButton("B1",0,0,100,20)
   GUISetFont(12,700,2,"Minion Pro")
   $hexed = GUICtrlCreateLabel("0x"&Hex($pixcolor,6),50,17)
   GUISetFont(12,700,2,"Minion Pro")
    ;$grabbed = GUICtrlCreateLabel("Your color is",0,0)
    GUICtrlSetColor($hexed,$pixcolor)
    $trend = "light"
If  (Dec ( StringMid($color, 1, 2) ) + Dec ( StringMid($color, 3, 2) ) + Dec ( StringMid($color, 5, 2) ) ) / 3 <= Dec("77") Then $trend =  "dark"
    GUISetState()
   GUIDelete($color)
EndFunc
Func copied()
   $copiing = GUICreate("",100,50)
   GUISetBkColor(0x000000)
   GUISetFont(20,700,2,"Minion Pro")
   $copied2 = GUICtrlCreateLabel("COPIED",2,10)
   GUICtrlSetColor($copied2,0xFFFFFF)
   GUISetState()
   EndFunc
;And ending here.
func findpix()
    $location = PixelSearch ($iX1, $iY1, $iX2, $iY2, Number(GUICtrlRead($ibr)))
   If IsArray($location) = True Then
    MouseMove($location[0],$location[1], 5)
    EndIf
   EndFunc
; -------------

Func Mark_Rect()

    Local $aMouse_Pos, $hMask, $hMaster_Mask, $iTemp
    Local $UserDLL = DllOpen("user32.dll")

    Global $hRectangle_GUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
    _GUICreateInvRect($hRectangle_GUI, 0, 0, 1, 1)
    GUISetBkColor(0)
    WinSetTrans($hRectangle_GUI, "", 50)
    GUISetState(@SW_SHOW, $hRectangle_GUI)
    GUISetCursor(3, 1, $hRectangle_GUI)

    ; Wait until mouse button pressed
    While Not _IsPressed("01", $UserDLL)
        Sleep(10)
    WEnd

    ; Get first mouse position
    $aMouse_Pos = MouseGetPos()
    $iX1 = $aMouse_Pos[0]
    $iY1 = $aMouse_Pos[1]

    ; Draw rectangle while mouse button pressed
    While _IsPressed("01", $UserDLL)

        $aMouse_Pos = MouseGetPos()

        ; Set in correct order if required
        If $aMouse_Pos[0] < $iX1 Then
            $iX_Pos = $aMouse_Pos[0]
            $iWidth = $iX1 - $aMouse_Pos[0]
        Else
            $iX_Pos = $iX1
            $iWidth = $aMouse_Pos[0] - $iX1
        EndIf
        If $aMouse_Pos[1] < $iY1 Then
            $iY_Pos = $aMouse_Pos[1]
            $iHeight = $iY1 - $aMouse_Pos[1]
        Else
            $iY_Pos = $iY1
            $iHeight = $aMouse_Pos[1] - $iY1
        EndIf

        _GUICreateInvRect($hRectangle_GUI, $iX_Pos, $iY_Pos, $iWidth, $iHeight)

        Sleep(10)

    WEnd

    ; Get second mouse position
    $iX2 = $aMouse_Pos[0]
    $iY2 = $aMouse_Pos[1]

    ; Set in correct order if required
    If $iX2 < $iX1 Then
        $iTemp = $iX1
        $iX1 = $iX2
        $iX2 = $iTemp
    EndIf
    If $iY2 < $iY1 Then
        $iTemp = $iY1
        $iY1 = $iY2
        $iY2 = $iTemp
    EndIf

    GUIDelete($hRectangle_GUI)
    DllClose($UserDLL)

EndFunc   ;==>Mark_Rect

Func _GUICreateInvRect($hWnd, $iX, $iY, $iW, $iH)

    $hMask_1 = _WinAPI_CreateRectRgn(0, 0, @DesktopWidth, $iY)
    $hMask_2 = _WinAPI_CreateRectRgn(0, 0, $iX, @DesktopHeight)
    $hMask_3 = _WinAPI_CreateRectRgn($iX + $iW, 0, @DesktopWidth, @DesktopHeight)
    $hMask_4 = _WinAPI_CreateRectRgn(0, $iY + $iH, @DesktopWidth, @DesktopHeight)

    _WinAPI_CombineRgn($hMask_1, $hMask_1, $hMask_2, 2)
    _WinAPI_CombineRgn($hMask_1, $hMask_1, $hMask_3, 2)
    _WinAPI_CombineRgn($hMask_1, $hMask_1, $hMask_4, 2)

    _WinAPI_DeleteObject($hMask_2)
    _WinAPI_DeleteObject($hMask_3)
    _WinAPI_DeleteObject($hMask_4)

    _WinAPI_SetWindowRgn($hWnd, $hMask_1, 1)

EndFunc

Thanks :)

Link to comment
Share on other sites

Well, try with this :

Func color()
    $mousepos = MouseGetPos()
    $pixcolor = PixelGetColor($mousepos[0],$mousepos[1])
    $colorgui = GUICreate("Your Color",175,100)
    $buttons = GUICtrlCreateButton("Copy",35,50,100,30)
    ;$buttons = GUICtrlCreateButton("B1",0,0,100,20)
    GUISetFont(12,700,2,"Minion Pro")
    $hexed = GUICtrlCreateLabel("0x"&Hex($pixcolor,6),50,17)
    GUISetFont(12,700,2,"Minion Pro")
    ;$grabbed = GUICtrlCreateLabel("Your color is",0,0)
    GUICtrlSetColor($hexed,$pixcolor)

    $hexColor = Hex($pixcolor, 6)
    $trend = 0x660000
    If  (Dec ( StringMid($hexColor, 1, 2) ) + Dec ( StringMid($hexColor, 3, 2) ) + Dec ( StringMid($hexColor, 5, 2) ) ) / 3 <= Dec("77") Then $trend =  0xFF7777
    GUISetBkColor($trend,$colorgui)


    GUISetState()
    GUIDelete($color)
EndFunc
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...