Jump to content

Someone must have already done this.


Recommended Posts

Someone must have already done something that will make this idea work.

I have a small Window that changes background color based to the color under the mouse. It's a color picker window and it's been working fine for years. Now I've decided to add a label to display the current mouse coordinates as well. The only problem is I have to set the label background to white in order to be able to read it at all times. What I would prefer would be to set the text color to a contrasting color instead so I wouldn't have to have the white background.

Even something based on Hue would probably work here so that on dark colors the text was White and on light colors the text was Black would be good.

Ideas anyone?

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

George, I don't know if it helps, but Kafu's Color Picker is very good and perhaps you will find what you're interested in. 

Mihai

Edited by taietel
Link to comment
Share on other sites

Thanks, but like I said, mine has been working fine for years. All I need to do (or not) is make sure that the text for that label always contrasts with the Window background color which is set by the color under the cursor.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

heres my somewhat awful effort, it works most of the time but dosen give a good contrast all of the time

$bkcolour = Random(0x000000, 0xffffff)
$Gui = GUICreate("GUI")
GUISetBkColor($bkcolour, $Gui)
$Label = GUICtrlCreateLabel("I am the text in the box", 150, 175)
If $bkcolour < 0x666666 Then
    $TxtColour = 0xffffff
Else
    $TxtColour = 0x000000
EndIf

GUICtrlSetColor($Label, $TxtColour)
GUISetState()

Do
    Sleep(10)
Until GUIGetMsg() = -3
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Thanks malkey. That's an improvement but it doesn't always provide enough contrast. I think I'm going to have to work out something based on color saturation, so if it's a light color then the text is black and if it's a dark color then the text is white.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Nice try JohnOne.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

heres my somewhat awful effort, it works most of the time but dosen give a good contrast all of the time

$bkcolour = Random(0x000000, 0xffffff)
$Gui = GUICreate("GUI")
GUISetBkColor($bkcolour, $Gui)
$Label = GUICtrlCreateLabel("I am the text in the box", 150, 175)
If $bkcolour < 0x666666 Then
    $TxtColour = 0xffffff
Else
    $TxtColour = 0x000000
EndIf

GUICtrlSetColor($Label, $TxtColour)
GUISetState()

Do
    Sleep(10)
Until GUIGetMsg() = -3

Nice try but again it has the contrast problem with some colors

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>

$Gui = GUICreate("Form1", 361, 244)
$Label = GUICtrlCreateLabel("Some text", 136, 40, 88, 28)
$font = GUICtrlSetFont($Label, 14, 400, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("Change colour", 128, 168, 99, 33)
GUISetState(@SW_SHOW)
While 1
    Sleep(100)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
         $bkcolour = "0x" & Hex((Random(0, 255, 1) * 0x10000) + (Random(0, 255, 1) * 0x100) + Random(0, 255, 1),6)
            GUISetBkColor($bkcolour, $Gui)
            GUICtrlSetColor($Label, Opposite($bkcolour))
            ConsoleWrite($bkcolour & "<>" &  Opposite($bkcolour) & @CRLF)
    EndSwitch
WEnd

Func Opposite($hcolor)
    $color = StringRight($hcolor,6)
    $result='';
    $ch='';
    $list1='0123456789ABCDEF';
    $list2='FEDCBA9876543210';
    For $i=0 To StringLen($color)
        $ch=StringMid($color, $i, 1);
        For $n=0 To StringLen($list1)
            if $ch=StringMid($list1, $n,1) Then
                $result &= StringMid($list2,$n,1)
            EndIf
        Next
    Next
 Return "0x" & $result
EndFunc

[edit] I have modified the post with an example

Edited by taietel
Link to comment
Share on other sites

Did a little research:

Average the % of each RGB value. If less than 50%, use white, if greater than or equal to 50%, then use black.

If you want a more advanced algorithm, you can convert this:

//-------------------------------------------------------------------------//
// Convert an RGB color-space format to HSB color-space format  //
//  //
// RGB format 0x00BBGGRR    //
// HSB format 0x00HHSSBB    //
//  //
//-------------------------------------------------------------------------//
COLORREF SfxColorRGBtoHSB(COLORREF color)
{
    int     nHue, nSat, nBri;

    SfxRGBtoHSB(GetRValue(color), GetGValue(color), GetBValue(color),
                &nHue, &nSat, &nBri);

    return HSB(nHue,nSat,nBri);
}

//-------------------------------------------------------------------------//
// Convert an HSB color-space format to RGB color-space format  //
//  //
// RGB format 0x00BBGGRR    //
// HSB format 0x00HHSSBB    //
//  //
//-------------------------------------------------------------------------//
COLORREF SfxColorHSBtoRGB(COLORREF color)
{
    int     nRed, nGreen, nBlue;

    SfxHSBtoRGB(GetHValue(color), GetSValue(color), GetLValue(color),
                &nRed, &nGreen, &nBlue);
    return RGB(nRed,nGreen,nBlue);
}

//-------------------------------------------------------------------------//
// Convert the RGB components into HSB components   //
//  //
// red, green, blue values are from 0 to 255    //
// hue = [0,240], sat = [0,100]%, bri = [0,100]%    //
//  //
//-------------------------------------------------------------------------//
void SfxRGBtoHSB(int nRed, int nGreen, int nBlue, int *nHue, int *nSat, int *nBri)
{
    double  dRed, dGreen, dBlue;
    double  dHue, dSat, dBri;
    double  dMin, dMax, dDelta;

    dRed = (double)nRed/255.0;
    dGreen = (double)nGreen/255.0;
    dBlue = (double)nBlue/255.0;
    dMin = min(dRed,dGreen);
    dMin = min(dMin,dBlue);
    dMax = max(dRed,dGreen);
    dMax = max(dMax,dBlue);
    dBri = dMax;
    if( dMax == dMin )
    {
        // achromatic color (i.e. grey, black or white)
        // r = g = b = x        
        // sat = 0, bri = x*100, hue is undefined
        *nSat = 0;
        *nHue = HUE_UNDEF;
        *nBri = (int)(dBri * 100.0);
        return;
    }
    dDelta = dMax - dMin;
    dSat = dDelta / dMax;
    if( dRed == dMax ) dHue = (dGreen - dBlue) / dDelta;                // between yellow & magenta
    else if( dGreen == dMax ) dHue = 2.0 + (dBlue - dRed) / dDelta;     // between cyan & yellow
    else dHue = 4.0 + (dRed - dGreen) / dDelta;                         // between magenta & cyan
    dHue *= 40.0;
    if( dHue < 0 ) dHue += 240.0;
    *nHue = (int)dHue;
    *nSat = (int)(dSat * 100.0);
    *nBri = (int)(dBri * 100.0);
}

//-------------------------------------------------------------------------//
// Convert the HSB components into RGB components   //
//  //
// red, green, blue values are from 0 to 255    //
// hue = [0,240], sat = [0,100]%, bri = [0,100]%    //
//  //
//-------------------------------------------------------------------------//
void SfxHSBtoRGB(int nHue, int nSat, int nBri, int *nRed, int *nGreen, int *nBlue)
{
    int     nSector;
    double  dFract, dVal1, dVal2;
    double  dRed, dGreen, dBlue;
    double  dHue, dSat, dBri;

    if( (nSat == 0) || (nHue == HUE_UNDEF) )
    {
        // achromatic (grey, black or white)
        *nRed = *nGreen = *nBlue = (nBri * 255)/100;
        return;
    }

    dHue = (double)nHue;
    dSat = (double)nSat/100.0;
    dBri = (double)nBri/100.0;

    dHue /= 40.0;
    nSector = (int)floor(dHue);         // sector 0 to 5
    dFract = dHue - floor(dHue);        // factional part of hue
    if( !(nSector & 1) ) dFract = 1.0 - dFract;
    dVal1 = dBri * (1.0 - dSat);
    dVal2 = dBri * (1.0 - dSat * dFract);
    switch( nSector )
    {
    case 0: dRed = dBri;    dGreen = dVal2;     dBlue = dVal1;  break;
    case 1: dRed = dVal2;   dGreen = dBri;      dBlue = dVal1;  break;
    case 2: dRed = dVal1;   dGreen = dBri;      dBlue = dVal2;  break;
    case 3: dRed = dVal1;   dGreen = dVal2;     dBlue = dBri;   break;
    case 4: dRed = dVal2;   dGreen = dVal1;     dBlue = dBri;   break;
    case 5: dRed = dBri;    dGreen = dVal1;     dBlue = dVal2;  break;
    }
    *nRed = (int)(dRed * 255.0);
    *nGreen = (int)(dGreen * 255.0);
    *nBlue = (int)(dBlue * 255.0);
}

//-------------------------------------------------------------------------//
// Create a color that contrast a given color   //
// This algorithm is taken from my research on color science    //
//-------------------------------------------------------------------------//
COLORREF SfxContrastingColor(COLORREF color, int nThreshold)
{
    int     nOrigLum, nCalcLum, nLoop;
    int     nHue, nSat, nBri;
    int     nRed, nGreen, nBlue;

    nRed = GetRValue(color);
    nGreen = GetGValue(color);
    nBlue = GetBValue(color);
    nOrigLum = LUMINANCE(nRed,nGreen,nBlue);

    SfxRGBtoHSB(nRed, nGreen, nBlue, &nHue, &nSat, &nBri);

    if( nHue == HUE_UNDEF )
    {
        nRed = nGreen = nBlue = 0;
        if( nBri < 50 ) nRed = nGreen = nBlue = 255;
    }
    else
    {
        nHue = (nHue + 120) % 240;
        nLoop = 20;
        while( nLoop )
        {
            SfxHSBtoRGB(nHue, nSat, nBri, &nRed, &nGreen, &nBlue);
            nCalcLum = LUMINANCE(nRed,nGreen,nBlue);
            if( abs(nOrigLum - nCalcLum) >= nThreshold ) break;
            if( nOrigLum <= 50 )
            {
                nSat -= 5;
                if( nSat < 0 ) nSat += 5;
                nBri += 10; 
                if( nBri > 100 ) nBri = 100;
            }
            else
            {
                nSat += 5;
                if( nSat > 100 ) nSat = 100;
                nBri -= 5; 
                if( nBri < 10 ) nBri = 10;
            }
            nLoop--;
        }
    }
    return RGB(nRed,nGreen,nBlue);
}

//-------------------------------------------------------------------------//
// Retrieve a Luminance from RGB color  //
//-------------------------------------------------------------------------//
int SfxGetLuminance(COLORREF crRGB)
{
    return  LUMINANCE(GetRValue(crRGB),GetGValue(crRGB),GetBValue(crRGB));
}

//macros
#define HSB(h,s,b) ((COLORREF)(((BYTE)(b)|((WORD)((BYTE)(s))<<8))|(((DWORD)(BYTE)(h))<<16)))
#define LUMINANCE(r,g,b) ((30*r+59*g+11*b)/255)

#define GetLValue(hsb) ((BYTE)(hsb))
#define GetSValue(hsb) ((BYTE)(((WORD)(hsb)) >> 8))
#define GetHValue(hsb) ((BYTE)((DWORD)(hsb)>>16))
#define HUE_UNDEF 0x000000FF

Also, it might work to do a Mod(255) on each RRRGGGBBB value to get its opposite.

Link to comment
Share on other sites

Try this out for size GEO

#include <Misc.au3>
$bkcolour = String(_ChooseColor(2))
$red = Dec(StringMid($bkcolour, 3, 2))
$green = Dec(StringMid($bkcolour, 5, 2))
$blue = Dec(StringMid($bkcolour, 7, 2))
$Y = ($red + $red + $blue + $green + $green + $green) / 6
If $Y > 140 Then
    $TxtColour = 0x000000
Else
    $TxtColour = 0xffffff
EndIf

$Gui = GUICreate("GUI")
GUISetBkColor($bkcolour, $Gui)
$Label = GUICtrlCreateLabel("I am the text in the box", 150, 175)

GUICtrlSetColor($Label, $TxtColour)
GUISetState()

Do
    Sleep(10)
Until GUIGetMsg() = -3

Edit: function

Func _BlackOrWhite($RGB)
    $red = Dec(StringMid($RGB, 3, 2))
    $green = Dec(StringMid($RGB, 5, 2))
    $blue = Dec(StringMid($RGB, 7, 2))
    $Y = ($red + $red + $blue + $green + $green + $green) / 6
    If $Y > 140 Then Return 0x000000
    Return 0xffffff
EndFunc
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Thanks to all the help in this thread I did come up with something that works, or more accurately works so far.

#include<color.au3> ;; I was already using this UDF anyway
Func _Text_SetColor($h_Color, $iThreshold = 2)
    Local $iRtn = ((255/_ColorGetRed($hColor)) + (255/_ColorGetGreen($hColor)) + (255/_ColorGetBlue($hColor)))/3
    If NOT IsNumber($iRtn) Then $iRtn = $iThreshold
    If $iRtn >= $iThreshold Then Return 0xFFFFFF
    Return 0x000000
EndFunc

And SmOke_N came up with another working solution

Func _Color_ContrastBW($i_color)
    Local $a_rgb[3] = [ _
        BitAND(BitShift($i_color, 16), 0xFF), _
        BitAND(BitShift($i_color, 8), 0xFF), _
        BitAND($i_color, 0xFF)]

    Local $i_red = 0xFF - $a_rgb[0]
    Local $i_green = 0xFF - $a_rgb[1]
    Local $i_blue = 0xFF - $a_rgb[2]

    Local $i_ret = Int($i_red & $i_green & $i_blue)
    If $i_ret > (0xFFFFFF / 2) Then Return 0xFFFFFF
    Return 0x000000
EndFunc

Also it had been done before

http://www.autoitscript.com/forum/index.php?showtopic=97345

Thanks to all for the efforts.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

....

And SmOke_N came up with another working solution

Func _Color_ContrastBW($i_color)
    Local $a_rgb[3] = [ _
        BitAND(BitShift($i_color, 16), 0xFF), _
        BitAND(BitShift($i_color, 8), 0xFF), _
        BitAND($i_color, 0xFF)]

    Local $i_red = 0xFF - $a_rgb[0]
    Local $i_green = 0xFF - $a_rgb[1]
    Local $i_blue = 0xFF - $a_rgb[2]

    Local $i_ret = Int($i_red & $i_green & $i_blue)
    If $i_ret > (0xFFFFFF / 2) Then Return 0xFFFFFF
    Return 0x000000
EndFunc

....

I believe this,

Local $i_ret = Int($i_red & $i_green & $i_blue)

should be this

Local $i_ret = "0x" & hex($i_red,2) & hex($i_green,2) & hex($i_blue,2)

Then, all this,

Local $a_rgb[3] = [ _
        BitAND(BitShift($i_color, 16), 0xFF), _
        BitAND(BitShift($i_color, 8), 0xFF), _
        BitAND($i_color, 0xFF)]

Local $i_red = 0xFF - $a_rgb[0]
Local $i_green = 0xFF - $a_rgb[1]
Local $i_blue = 0xFF - $a_rgb[2]
Local $i_ret = "0x" & Hex($i_red, 2) & Hex($i_green, 2) & Hex($i_blue, 2)

is the same as this,

Local $i_ret = 0xFFFFFF - $i_color

See post #4

The proof,

Local $Col = 0xFEFEFE

_Color_ContrastBW(0xFEFEFE)

ConsoleWrite(@TAB & '"0xFFFFFF - $Col" = 0x' & Hex(0xFFFFFF - $Col, 6) & @CRLF)


Func _Color_ContrastBW($i_color)
    Local $a_rgb[3] = [ _
            BitAND(BitShift($i_color, 16), 0xFF), _
            BitAND(BitShift($i_color, 8), 0xFF), _
            BitAND($i_color, 0xFF)]

    Local $i_red = 0xFF - $a_rgb[0]
    Local $i_green = 0xFF - $a_rgb[1]
    Local $i_blue = 0xFF - $a_rgb[2]

    ;Local $i_ret = Int($i_red & $i_green & $i_blue)
    Local $i_ret = "0x" & Hex($i_red, 2) & Hex($i_green, 2) & Hex($i_blue, 2)

    ConsoleWrite("From Function Contrast Color = " & $i_ret & @CRLF)
    If $i_ret > (0xFFFFFF / 2) Then Return 0xFFFFFF
    Return 0x000000
EndFunc ;==>_Color_ContrastBW
Link to comment
Share on other sites

It looks like you are correct and SmOke_N did attempt to send a corrected file until he discovered it didn't work.

I'm using the _Text_SetColor() function and it's doing what I need, although I have figured out another method which uses _ColorConvertRGBtoHSL() but that seems like overkill when a little 6 line function does the job. It just needs color.au3 which I was already using anyway.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Lots of solutions here, which are likely more what GeoSoft wants. Regardless, I will add mine. Based on a Malkey function and using excerpts from one of my scripts.

#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>


Global $iconavg[1]

$Gui = GUICreate("Opposite Text Colour", 560,600)
$iconavg[0] = GUICtrlCreatePic("", 350, 65,140, 40)
GUISetState()
GUISetBkColor(0x000066)
contrastcol($iconavg[0],"Opposite","Verdana","0x000066")
sleep(2000)
GUISetBkColor(0x660000)
contrastcol($iconavg[0],"Opposite","Verdana","0x660000")
sleep(2000)
GUISetBkColor(0x000000)
contrastcol($iconavg[0],"Opposite","Verdana","0x000000")

While 1
    $nMsg = GUIGetMsg()
    
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd
 
 Func  contrastcol($control, $text = "", $font = "Arial", $bkcol="0x000000", $size = 12, $style = 0)

        _GDIPlus_Startup()
        $hwd = GUICtrlGetHandle($control)
        
        $width = _WinAPI_GetClientWidth($hwd)
        $height = _WinAPI_GetClientHeight($hwd)
        $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hwd)
        $hBitmap1 = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic)
       $fontcol = _InvertColor($bkcol,0)
        $hImage1 = _GDIPlus_ImageGetGraphicsContext($hBitmap1)
        ;this is needed because adding an icon results in the background turning black
        If Not $text = "" Then $hBitmap1 = _drawtext($hBitmap1, $width, $height, $text, $font, $size, $style, $fontcol, 0, 1)
        _GDIPlus_GraphicsSetSmoothingMode($hImage1, 2)
        $hBMP1 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap1)
        _WinAPI_DeleteObject(GUICtrlSendMsg($control, 0x0172, 0, $hBMP1))

        _GDIPlus_GraphicsDispose($hImage1)
        _WinAPI_DeleteObject($hBMP1)
        _GDIPlus_BitmapDispose($hBitmap1)
        _GDIPlus_GraphicsDispose($hGraphic)
        _GDIPlus_Shutdown()

EndFunc
 
 Func _InvertColor($iColor, $mode = 1)
    Switch $mode
        Case 0
            Return "0x" & Hex(0xFFFFFF - $iColor, 6)
        Case 1
            Return "0x" & StringRegExpReplace(Hex($iColor, 6), "(.{2})(.{2})(.{2})", "\3\2\1")
        Case 2
            Return "0x" & StringRegExpReplace(Hex(0xFFFFFF - $iColor, 6), "(.{2})(.{2})(.{2})", "\3\2\1")
    EndSwitch
EndFunc ;==>_InvertColor

Func _InvertColorA($iColor, $mode = 2)
    $iColor = String(Hex($iColor, 6))
    If $mode = 0 Then
        $RColor = StringTrimLeft(StringTrimRight($iColor, 4), 0)
        $GColor = StringTrimLeft(StringTrimRight($iColor, 2), 2)
        $BColor = StringTrimLeft(StringTrimRight($iColor, 0), 4)
        $InvertedRColor = Hex(255 - Dec($RColor), 2)
        $InvertedGColor = Hex(255 - Dec($GColor), 2)
        $InvertedBColor = Hex(255 - Dec($BColor), 2)
    ElseIf $mode = 1 Then
        $InvertedBColor = StringTrimLeft(StringTrimRight($iColor, 4), 0)
        $InvertedGColor = StringTrimLeft(StringTrimRight($iColor, 2), 2)
        $InvertedRColor = StringTrimLeft(StringTrimRight($iColor, 0), 4)
    ElseIf $mode = 2 Then
        $BColor = StringTrimLeft(StringTrimRight($iColor, 4), 0)
        $GColor = StringTrimLeft(StringTrimRight($iColor, 2), 2)
        $RColor = StringTrimLeft(StringTrimRight($iColor, 0), 4)
        $InvertedRColor = Hex(255 - Dec($RColor), 2)
        $InvertedGColor = Hex(255 - Dec($GColor), 2)
        $InvertedBColor = Hex(255 - Dec($BColor), 2)
    EndIf
    $InvertColor = $InvertedRColor & $InvertedGColor & $InvertedBColor
    Return "0x" & $InvertColor
EndFunc  ;==>_InvertColorA
;

Func _drawtext($hBitmap1, $leftpos, $toppos, $text, $font, $size, $style, $fontcol, $align = 2, $lpadding = 0) ; left justify $align=0; right justify $align=1 ;center $align=2
    $hImage1 = _GDIPlus_ImageGetGraphicsContext($hBitmap1)
    $fcol = StringReplace($fontcol, "0x", "0xFF")
    $hBrushed = _GDIPlus_BrushCreateSolid($fcol)
    $hFormat = _GDIPlus_StringFormatCreate()
    $hFamily = _GDIPlus_FontFamilyCreate($font)
    $hFont = _GDIPlus_FontCreate($hFamily, $size, $style)
    $tLayout = _GDIPlus_RectFCreate($leftpos, $toppos, 0, 0)
    $aInfo = _GDIPlus_GraphicsMeasureString($hImage1, $text, $hFont, $tLayout, $hFormat)
    Local $iWidth = Ceiling(DllStructGetData($aInfo[0], "Width"))
    Local $iHeight = Ceiling(DllStructGetData($aInfo[0], "Height"))
    If $align = 1 Or $align = 2 Then $lpos = ($leftpos / $align) - ($iWidth / $align)
    If $align = 0 And $lpadding = 0 Then $lpos = 5
    If $align = 0 And $lpadding = 1 Then $lpos = 34
    $tLayout = _GDIPlus_RectFCreate($lpos, ($toppos / 2) - ($iHeight / 2), 0, 0)
    $aInfo = _GDIPlus_GraphicsMeasureString($hImage1, $text, $hFont, $tLayout, $hFormat)
    _GDIPlus_GraphicsDrawStringEx($hImage1, $text, $hFont, $aInfo[0], $hFormat, $hBrushed)
    _GDIPlus_GraphicsDispose($hImage1)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_BrushDispose($hBrushed)
    Return $hBitmap1
EndFunc ;==>_drawtext
Edited by picea892
Link to comment
Share on other sites

Hi George,

Can you please try this "restricted color" version as well:

; we get color in xxrrggbb format, with xx we shall ignore, possibly destroy (but we could preserve it if needed).
; we truncate color range to only keep 8 high color levels in each R, G & B
; then we add half of our "high" color components, so as to shift away of the background color
; the add may overflow any component, but we don't care as it will only add 1 to next color (not perceptible)
; we could BitAnd the result wih 0x00F0F0F0 to get a "cleaner" output, but it certainly doesn't make any difference
; we could also BitOr the final result with BitAnd($i_color, 0xff000000) to restore the xx part, if needed
Func _Color_Contrast($i_color)
    Return(BitAnd($i_color, 0x00E0E0E0) + 0x00808080)
EndFunc

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

For collections.

Func _IsDark($iRGB)
    If BitShift(BitAND($iRGB, 0xFF0000), 16) + BitShift(BitAND($iRGB, 0x00FF00), 8) + BitAND($iRGB, 0x0000FF) < 3 * 255 / 2 Then
        Return 1
    Else
        Return 0
    EndIf
EndFunc   ;==>_IsDark
Link to comment
Share on other sites

Thanks people, now the ideas are coming faster than I can test them. I'm calling it quits for the day but I'll test them tomorrow morning.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Someone must have already done something that will make this idea work.

Yes, it's done in front of your very eyes. The mouse cursor!

#include <guiconstantsEx.au3>
#include <color.au3>

Opt("GuiCloseOnEsc",1)
$g = GUICreate("")
GUISetFont(18)
_MakeContrastingLabel("contrasting?", 80, 100)

GUISetState()

$c = 16
For $n = 0 To 0xff Step $c
    For $p = 0 To 0xff Step $c
    For $q = 0 To 0xff Step $c
    GUISetBkColor($n * 0x10000 + $p * 0x100 + $q)
            if GUIGetMsg() = -3 then exit
    Sleep(120)
    Next
    Next
Next


Func _MakeContrastingLabel($sL, $x, $y)
    For $n = $x - 1 To $x + 1 Step 2
    For $p = $y - 1 To $y + 1 Step 2
    $l = GUICtrlCreateLabel($sL, $n, $p)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetColor(-1, 0); 0xffffff)
    Next
    Next

    For $p = $y - 2 To $y + 2 Step 4
    $l = GUICtrlCreateLabel($sL, $x, $p)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetColor(-1, 0); 0xffffff)
    Next

    $l = GUICtrlCreateLabel($sL, $x, $y)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetColor(-1, 0xffffff)
EndFunc ;==>MakeContrastingLabel

Edit: made a function for the label creation.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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...