MrCreatoR Posted February 4, 2008 Share Posted February 4, 2008 Hi there, I need a function to check if certain color is a shade of white or black (dark) color, i searched on the forum, but didn't find anything that might help with my task. Basicaly i need to update a label (it's background) with some color, and then set color for the control, but if the background color is dark, and the label text color dark as well (set by user), the text is almoust unreadable. Here is an example of what i am using for now: #include <GuiConstants.au3> $Bk_Color = 0x000000 ;0xFFFFFF $Color = 0x000000 $GUI = GUICreate("Test Script", 300, 200) GUICtrlCreateLabel("Some Text", 20, 40, 55, 14) GUICtrlSetBkColor(-1, $Bk_Color) If $Bk_Color = 0x000000 Then $Color = 0xFFFFFF GUICtrlSetColor(-1, $Color) GUISetState(@SW_SHOW, $GUI) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd So here i check if the back color is black, and if it does i just set the text color to white... but if the colors are little different, but still have black/white shade, text color not readable very well . Is there maybe a method to check color for «darknest/whitnest»? Thanks. Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
Thatsgreat2345 Posted February 4, 2008 Share Posted February 4, 2008 You can use _ColorGetBlue/Red/Green and do a calculation with those values. Link to comment Share on other sites More sharing options...
MrCreatoR Posted February 4, 2008 Author Share Posted February 4, 2008 (edited) You can use _ColorGetBlue/Red/Green and do a calculation with those values.Big thanks! Here is what i needed i think: expandcollapse popup#include <GuiConstants.au3> #include <Misc.au3> Global $Bk_Color = 0xFFFFFF $GUI = GUICreate("_ColorIsDarkShade Demo", 300, 200) $Label = GUICtrlCreateLabel("Some Text", 20, 40, 55, 14) GUICtrlSetBkColor(-1, $Bk_Color) $ColorSet_Button = GUICtrlCreateButton("Set Color", 20, 80) GUISetState(@SW_SHOW, $GUI) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $ColorSet_Button $Bk_Color = _ChooseColor(2, $Bk_Color, 2, $GUI) GUICtrlSetBkColor($Label, $Bk_Color) GUICtrlSetColor($Label, 0x0) If _ColorIsDarkShade($Bk_Color) Then GUICtrlSetColor($Label, 0xFFFFFF) EndSwitch WEnd Func _ColorIsDarkShade($nColor) Local $i_Red = BitAND(BitShift($nColor, 16), 0xFF) Local $i_Green = BitAND(BitShift($nColor, 8), 0xFF) Local $i_Blue = BitAND($nColor, 0xFF) Local $iMidle_Color_Val = Int(765 / 2) ;765 is the total of 255 + 255 + 255 Return ($i_Red + $i_Green + $i_Blue) < $iMidle_Color_Val EndFunc Edit: Changed the example. Edited April 7, 2008 by MsCreatoR Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now