/** * @file XTColorRef.h * * @copyright * (c) 1998-2025 Codejock Software, All Rights Reserved. * * This source file is the property of Codejock Software and must not be * redistributed by any means without the explicit written permission of * Codejock Software. * * The use of this source code is governed by the terms and conditions specified * in the Toolkit Pro license agreement. Codejock Software grants you, as a * single software developer, the limited right to use this software on one * computer only. * * Contact Information: * support@codejock.com * http://www.codejock.com * */ //{{AFX_CODEJOCK_PRIVATE #if !defined(__XTCOLORREF_H__) # define __XTCOLORREF_H__ //}}AFX_CODEJOCK_PRIVATE # if _MSC_VER > 1000 # pragma once # endif // _MSC_VER > 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" //=========================================================================== // Summary: // CXTColorRef is a stand alone class. It is used to create a // CXTColorRef object. This object is used for manipulation of RGB values. //=========================================================================== class _XTP_EXT_CLASS CXTColorRef { public: // -------------------------------------------------------------------------- // Summary: // Constructs a CXTColorRef object // Parameters: // cr - An RGB value. // r - Specifies the intensity of the red color component. 'r' can // range from 0 to 255. Zero is the minimum color intensity; 255 is // the maximum color intensity. // g - Specifies the intensity of the green color component. 'g' can // range from 0 to 255. Zero is the minimum color intensity; 255 is // the maximum color intensity. // b - Specifies the intensity of the blue color component. 'b' can // range from 0 to 255. Zero is the minimum color intensity; 255 is // the maximum color intensity. // -------------------------------------------------------------------------- CXTColorRef(); CXTColorRef(COLORREF cr); // CXTColorRef(int r, int g, int b); // //----------------------------------------------------------------------- // Summary: // This assignment operator is used to initialize a CXTColorRef // object. // Parameters: // cr - An RGB value. // Returns: // A reference to a valid CXTColorRef object. //----------------------------------------------------------------------- CXTColorRef& operator=(COLORREF cr); //----------------------------------------------------------------------- // Summary: // This assignment operator is used to modify a CXTColorRef object. // Parameters: // val - Specifies the intensity of the color component. 'val' // can range from 0 to 255. Zero is the minimum color intensity; // 255 is the maximum color intensity. // cr - An RGB value. // Returns: // A CXTColorRef object. //----------------------------------------------------------------------- CXTColorRef operator+(int val) const; CXTColorRef operator+(COLORREF cr) const; // //----------------------------------------------------------------------- // Summary: // This assignment operator is used to modify a CXTColorRef object. // Parameters: // val - Specifies the intensity of the color component. 'val' // can range from 0 to 255. Zero is the minimum color intensity; // 255 is the maximum color intensity. // cr - An RGB value. // Returns: // A CXTColorRef object. //----------------------------------------------------------------------- CXTColorRef operator-(int val) const; CXTColorRef operator-(COLORREF cr) const; // //----------------------------------------------------------------------- // Summary: // This assignment operator is used to modify a CXTColorRef object. // Parameters: // val - Specifies the intensity of the color component. 'val' can // range from 0 to 255. Zero is the minimum color intensity; // 255 is the maximum color intensity. // cr - An RGB value. // Returns: // A CXTColorRef object. //----------------------------------------------------------------------- CXTColorRef operator*(int val) const; CXTColorRef operator*(COLORREF cr) const; // //----------------------------------------------------------------------- // Summary: // This assignment operator is used to modify a CXTColorRef object. // Returns: // A CXTColorRef object. // Parameters: // val - Specifies the intensity of the color component. 'val' can // range from 0 to 255. Zero is the minimum color intensity; // 255 is the maximum color intensity. // cr - An RGB value. //----------------------------------------------------------------------- CXTColorRef operator/(int val) const; CXTColorRef operator/(COLORREF cr) const; // //----------------------------------------------------------------------- // Summary: // This assignment operator is used to modify a CXTColorRef object. // Parameters: // val - Specifies the intensity of the color component. 'val' can // range from 0 to 255. Zero is the minimum color intensity; // 255 is the maximum color intensity. // cr - An RGB value. // Returns: // A reference to a valid CXTColorRef object. //----------------------------------------------------------------------- CXTColorRef& operator+=(int val); CXTColorRef& operator+=(COLORREF cr); // //----------------------------------------------------------------------- // Summary: // This assignment operator is used to modify a CXTColorRef object. // Parameters: // val - Specifies the intensity of the color component. 'val' can // range from 0 to 255. Zero is the minimum color intensity; // 255 is the maximum color intensity. // cr - An RGB value. // Returns: // A reference to a valid CXTColorRef object. //----------------------------------------------------------------------- CXTColorRef& operator-=(int val); CXTColorRef& operator-=(COLORREF cr); // //----------------------------------------------------------------------- // Summary: // This assignment operator is used to modify a CXTColorRef object. // Parameters: // val - Specifies the intensity of the color component. 'val' can // range from 0 to 255. Zero is the minimum color intensity; // 255 is the maximum color intensity. // cr - An RGB value. // Returns: // A reference to a valid CXTColorRef object. //----------------------------------------------------------------------- CXTColorRef& operator*=(int val); CXTColorRef& operator*=(COLORREF cr); // //----------------------------------------------------------------------- // Summary: // This assignment operator is used to modify a CXTColorRef object. // Parameters: // val - Specifies the intensity of the color component. 'val' can // range from 0 to 255. Zero is the minimum color intensity; // 255 is the maximum color intensity. // cr - An RGB value. // Returns: // A reference to a valid CXTColorRef object. //----------------------------------------------------------------------- CXTColorRef& operator/=(int val); CXTColorRef& operator/=(COLORREF cr); // //----------------------------------------------------------------------- // Summary: // This operator retrieves the RGB value for the CXTColorRef object. // Returns: // An RGB value. //----------------------------------------------------------------------- operator COLORREF() const; ////////////////////////////////////////////////////////////// // RGB Values ////////////////////////////////////////////////////////////// //----------------------------------------------------------------------- // Summary: // This method gets the red component of this object. // Returns: // The red component of the color. //----------------------------------------------------------------------- int getRValue() const; //----------------------------------------------------------------------- // Summary: // This method gets the green component of this object. // Returns: // The green component of the color. //----------------------------------------------------------------------- int getGValue() const; //----------------------------------------------------------------------- // Summary: // This method gets the blue component of this object. // Returns: // The blue component of the color. //----------------------------------------------------------------------- int getBValue() const; //----------------------------------------------------------------------- // Summary: // Call this member function to set the red intensity value for // the CXTColorRef object. // Parameters: // val - Specifies the intensity of the color component. 'val' can // range from 0 to 255. Zero is the minimum color intensity; // 255 is the maximum color intensity. //----------------------------------------------------------------------- void setRValue(int val); //----------------------------------------------------------------------- // Summary: // Call this member function to set the green intensity value for the // CXTColorRef object. // Parameters: // val - Specifies the intensity of the color component. 'val' can // range from 0 to 255. Zero is the minimum color intensity; // 255 is the maximum color intensity. //----------------------------------------------------------------------- void setGValue(int val); //----------------------------------------------------------------------- // Summary: // Call this member function to set the blue intensity value for the CXTColorRef // object. // Parameters: // val - Specifies the intensity of the color component. 'val' can // range from 0 to 255. Zero is the minimum color intensity; // 255 is the maximum color intensity. //----------------------------------------------------------------------- void setBValue(int val); ////////////////////////////////////////////////////////////// // Misc Information ////////////////////////////////////////////////////////////// //----------------------------------------------------------------------- // Summary: // This member function will retrieve the overall intensity of the // CXTColorRef object. // Returns: // A double that represents the current color intensity. //----------------------------------------------------------------------- double getIntensity() const; ////////////////////////////////////////////////////////////// // Color Conversion ////////////////////////////////////////////////////////////// //----------------------------------------------------------------------- // Summary: // This function converts the RGB color to an HSL (hue, saturation, // luminance) trio. // Parameters: // h - The variable to receive the hue value. // s - The variable to receive the saturation value. // l - The variable to receive the luminance value. //----------------------------------------------------------------------- void toHSL(double& h, double& s, double& l) const; //----------------------------------------------------------------------- // Summary: // This function converts the RGB color to an HSB (hue, saturation, // brightness) trio. // Parameters: // h - The variable to receive the hue value. // s - The variable to receive the saturation value. // b - The variable to receive the brightness value. //----------------------------------------------------------------------- void toHSB(double& h, double& s, double& b) const; //----------------------------------------------------------------------- // Summary: // This function sets an RGB value that is the equivalent of a specific // HSL (hue, saturation, luminance) color. // Parameters: // h - The hue of the source color. // s - The saturation of the source color. // l - The luminance of the source color. //----------------------------------------------------------------------- void setHSL(double h, double s, double l); //----------------------------------------------------------------------- // Summary: // This function sets an RGB value that is the equivalent of a specific // HSB (hue, saturation, brightness) color. // Parameters: // h - The hue of the source color. // s - The saturation of the source color. // b - The brightness of the source color. //----------------------------------------------------------------------- void setHSB(double h, double s, double b); // ---------------------------------------------------------------------- // Summary: // Creates a new CXTColorRef based on hue saturation and luminance. // Parameters: // h - The hue of the source color. // s - The saturation of the source color. // l - The luminance of the source color. // Remarks: // This static function creates a new CXTColorRef object out of an // HSL (hue, saturation, luminance) color trio. Returns a CXTColorRef // \object. // ---------------------------------------------------------------------- static CXTColorRef AFX_CDECL fromHSL(double h, double s, double l); // --------------------------------------------------------------------- // Summary: // Creates a new CXTColorRef based on hue saturation and brightness. // Parameters: // h - The hue of the source color. // s - The saturation of the source color. // b - The brightness of the source color. // Remarks: // This static function creates a new CXTColorRef object out of an // HSB (hue, saturation, brightness) color trio. Returns a // CXTColorRef object. // --------------------------------------------------------------------- static CXTColorRef AFX_CDECL fromHSB(double h, double s, double b); ////////////////////////////////////////////////////////////////////// // Color Manipulation ////////////////////////////////////////////////////////////////////// // ---------------------------------------------------------------------- // Summary: // Blends two CXTColorRef objects into a single color. // Parameters: // clr - A reference to a valid CXTColorRef object. // opacity - The amount of transparency. // Remarks: // Call this member function to blend the CXTColorRef object with the // \object specified by 'clr'. // Returns: // A reference to a valid CXTColorRef object. // ---------------------------------------------------------------------- CXTColorRef& blend(const CXTColorRef& clr, int opacity); //----------------------------------------------------------------------- // Summary: // Call this member function to add the CXTColorRef object specified by 'clr'. // Parameters: // clr - A reference to a valid CXTColorRef object. // Returns: // A reference to a valid CXTColorRef object. //----------------------------------------------------------------------- CXTColorRef& add(const CXTColorRef& clr); //----------------------------------------------------------------------- // Summary: // Call this member function to subtract the CXTColorRef object specified // by 'clr'. // Parameters: // clr - A reference to a valid CXTColorRef object. // Returns: // A reference to a valid CXTColorRef object. //----------------------------------------------------------------------- CXTColorRef& subtract(const CXTColorRef& clr); ////////////////////////////////////////////////////////////////////// // Standard Colors ////////////////////////////////////////////////////////////////////// static const CXTColorRef BLACK; // RGB value that represents the color black. static const CXTColorRef WHITE; // RGB value that represents the color white. static const CXTColorRef GRAY_25; // RGB value that represents the 25% gray color. static const CXTColorRef GRAY_50; // RGB value that represents the 50% gray color. static const CXTColorRef GRAY_75; // RGB value that represents the 75% gray color. ////////////////////////////////////////////////////////////////////// // Helper Functions ////////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------------- // Summary: // Adds two color values. // Parameters: // iVal - Specifies the color intensity that is the source of the // operation. // iAdd - Specifies the intensity to add to the source. It can be negative. // Remarks: // This member function adds two color intensities to ensure that the // sum is in the proper color value range (0-255). For example, addColorValue(200, // 100) will return 255 and not 300. addColorValue(100, -200) will // return 0. // ----------------------------------------------------------------------------------- static int AFX_CDECL addColorValue(int iVal, int iAdd); // ---------------------------------------------------------------------------- // Summary: // Modifies a color value based on intensity and multiplication. // Parameters: // iVal - Specifies the color intensity that is the source of the // operation. // iMult - Specifies a value to multiply the source by. // iDiv - Specifies a value to divide the source by. // Remarks: // This member function manipulates a color value by performing a // multiplication and then a division. For instance, multiplyColorValue(10, // 2, 3) will return 10 * 2 / 3 which is 6. The function guarantees // that the resulting value does not exceeded 255. // ---------------------------------------------------------------------------- static int AFX_CDECL multiplyColorValue(int iVal, int iMult, int iDiv); // ------------------------------------------------------------------------------ // Summary: // Blends two color intensities. // Parameters: // iClrFront : Specifies the intensity of the foreground color component. // 'iClrFront' can range from 0 to 255. Zero is the minimum // color intensity; 255 is the maximum color intensity. // iClrBack : Specifies the intensity of the background color component. // 'iClrBack' can range from 0 to 255. Zero is the minimum color // intensity; 255 is the maximum color intensity. // opacity : The amount of transparency. // Remarks: // This function takes a blended color intensity which is // ((100-opacity)% * iClrFront and opacity% * iClrBack). // ------------------------------------------------------------------------------ static int AFX_CDECL BlendColor(int iClrFront, int iClrBack, int opacity); // ------------------------------------------------------------------------- // Summary: // Adjusts color intensity to a valid range. // Parameters: // iVal - Specifies the intensity of the color component. 'iVal' can // range from 0 to 255. Zero is the minimum color intensity; 255 // is the maximum color intensity. // Remarks: // This function takes in a color intensity and ensures that it is // between 0 and 255. Anything out of range will be adjusted to the // closest number in range (i.e. -100 will become 0, 300 will become // 255). // ------------------------------------------------------------------------- static int AFX_CDECL fixColorValue(int iVal); //----------------------------------------------------------------------- // Summary: // This function will refresh the display element colors defined // in the CXTColorRef object. //----------------------------------------------------------------------- static void AFX_CDECL RefreshColors(); // --------------------------------------------------------------------------- // Summary: // Retrieves the current color of the specified display element. // Parameters: // nIndex - Specifies the display element whose color is to be retrieved. // This parameter can be one of the values listed in the remarks // section. // Remarks: // This function retrieves the current color of the specified XP // display element. Display elements are the parts of a window and // the display that appear on the system display screen. // // Color can be defined as one of the following values: // * XPCOLOR_BASE An RGB value that represents the XP base // color. // * XPCOLOR_BARFACE An RGB value that represents the XP // toolbar background color. // * XPCOLOR_HIGHLIGHT An RGB value that represents the XP // menu item selected color. // * XPCOLOR_HIGHLIGHT_BORDER An RGB value that represents // the XP menu item selected border color. // * XPCOLOR_HIGHLIGHT_PUSHED An RGB value that represents // the XP menu item pushed color. // * XPCOLOR_ICONSHADDOW An RGB value that represents the // XP menu item icon shadow. // * XPCOLOR_GRAYTEXT An RGB value that represents the XP // menu item disabled text color. // * XPCOLOR_HIGHLIGHT_CHECKED An RGB value that // represents the XP menu item checked color. // * XPCOLOR_HIGHLIGHT_CHECKED_BORDER An RGB value that // represents the XP menu item checked border color. // * XPCOLOR_GRIPPER An RGB value that represents the XP // toolbar gripper color. // * XPCOLOR_SEPARATOR An RGB value that represents the XP // toolbar separator color. // * XPCOLOR_DISABLED An RGB value that represents the XP // menu icon disabled color. // * XPCOLOR_MENUTEXT_BACK An RGB value that represents // the XP menu item text background color. // * XPCOLOR_MENU_EXPANDED An RGB value that represents // the XP hidden menu commands background color. // * XPCOLOR_MENU_BORDER An RGB value that represents the // XP menu border color. // * XPCOLOR_MENUTEXT An RGB value that represents the XP // menu item text color. // * XPCOLOR_HIGHLIGHT_TEXT An RGB value that represents // the XP menu item selected text color. // * XPCOLOR_BARTEXT An RGB value that represents the XP // toolbar text color. // * XPCOLOR_BARTEXT_PUSHED An RGB value that represents // the XP toolbar pushed text color. // * XPCOLOR_TAB_INACTIVE_BACK An RGB value that // represents the XP inactive tab background color. // * XPCOLOR_TAB_INACTIVE_TEXT An RGB value that // represents the XP inactive tab text color. // Returns: // The red, green, blue (RGB) color value of the given element. // --------------------------------------------------------------------------- static COLORREF AFX_CDECL GetColor(int nIndex); protected: COLORREF m_ColorRef; // Current RGB value for this object // ------------------------------------------------------------------------- // Summary: // Retrieves a save COLORREF value from the specified r, g, b values. // Parameters: // r - Specifies the intensity of the red color component. 'r' can // range from 0 to 255. Zero is the minimum color intensity; 255 is // the maximum color intensity. // g - Specifies the intensity of the green color component. 'g' can // range from 0 to 255. Zero is the minimum color intensity; 255 is // the maximum color intensity. // b - Specifies the intensity of the blue color component. 'b' can // range from 0 to 255. Zero is the minimum color intensity; 255 is // the maximum color intensity. // Remarks: // This function takes in a color intensity and ensures that it is // between 0 and 255. Anything out of range will be adjusted to the // closest number in range (i.e. -100 will become 0, 300 will become // 255). // Returns: // An RGB value. // ------------------------------------------------------------------------- static COLORREF AFX_CDECL SafeRGB(int r, int g, int b); }; ////////////////////////////////////////////////////////////////////// AFX_INLINE CXTColorRef::CXTColorRef() { m_ColorRef = 0; } AFX_INLINE CXTColorRef& CXTColorRef::operator=(COLORREF cr) { m_ColorRef = cr; return *this; } AFX_INLINE CXTColorRef::CXTColorRef(COLORREF r) { *this = r; } AFX_INLINE CXTColorRef::CXTColorRef(int r, int g, int b) { *this = RGB(r, g, b); } AFX_INLINE int CXTColorRef::fixColorValue(int iVal) { if (iVal > 255) return 255; if (iVal < 0) return 0; return iVal; } AFX_INLINE CXTColorRef::operator COLORREF() const { return m_ColorRef; } AFX_INLINE int CXTColorRef::getRValue() const { return GetRValue(m_ColorRef); } AFX_INLINE int CXTColorRef::getGValue() const { return GetGValue(m_ColorRef); } AFX_INLINE int CXTColorRef::getBValue() const { return GetBValue(m_ColorRef); } AFX_INLINE void CXTColorRef::setRValue(int val) { m_ColorRef = RGB(val, getGValue(), getBValue()); } AFX_INLINE void CXTColorRef::setGValue(int val) { m_ColorRef = RGB(getRValue(), val, getBValue()); } AFX_INLINE void CXTColorRef::setBValue(int val) { m_ColorRef = RGB(getRValue(), getGValue(), val); } AFX_INLINE double CXTColorRef::getIntensity() const { return ((299 * getRValue()) + (587 * getGValue()) + (114 * getBValue())) / 1000.0; } AFX_INLINE int CXTColorRef::addColorValue(int iVal, int iAdd) { return fixColorValue(iVal + iAdd); } AFX_INLINE int CXTColorRef::multiplyColorValue(int iVal, int iMult, int iDiv) { return fixColorValue(iVal * iMult / iDiv); } AFX_INLINE int CXTColorRef::BlendColor(int iClrFront, int iClrBack, int opacity) { return fixColorValue(((iClrFront * opacity) + (iClrBack * (100 - opacity))) / 100); } # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" #endif // !defined(__XTCOLORREF_H__)