rgba_color.hpp
来自「ncbi源码」· HPP 代码 · 共 241 行
HPP
241 行
/* * =========================================================================== * PRODUCTION $Log: rgba_color.hpp,v $ * PRODUCTION Revision 1000.3 2004/06/01 19:51:17 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.11 * PRODUCTION * =========================================================================== */#ifndef GUI_UTILS___RGBA_COLOR__HPP#define GUI_UTILS___RGBA_COLOR__HPP/* $Id: rgba_color.hpp,v 1000.3 2004/06/01 19:51:17 gouriano Exp $ * =========================================================================== * * PUBLIC DOMAIN NOTICE * National Center for Biotechnology Information * * This software/database is a "United States Government Work" under the * terms of the United States Copyright Act. It was written as part of * the author's official duties as a United States Government employee and * thus cannot be copyrighted. This software/database is freely available * to the public for use. The National Library of Medicine and the U.S. * Government have not placed any restriction on its use or reproduction. * * Although all reasonable efforts have been taken to ensure the accuracy * and reliability of the software and data, the NLM and the U.S. * Government do not and cannot warrant the performance or results that * may be obtained by using this software or data. The NLM and the U.S. * Government disclaim all warranties, express or implied, including * warranties of performance, merchantability or fitness for any particular * purpose. * * Please cite the author in any work or product based on this material. * * =========================================================================== * * Authors: Mike DiCuccio, Peter Meric * * File Description: * CRgbaColor - colors in the RGB colorspace, including transparency */#include <corelib/ncbistd.hpp>#include <gui/gui.hpp>/** @addtogroup GUI_UTILS * * @{ */BEGIN_NCBI_SCOPE////// class CRgbaColor provides a simple abstraction for managing colors.///class NCBI_GUIUTILS_EXPORT CRgbaColor{public: /// default ctor CRgbaColor(); /// construct around a given float array CRgbaColor(const float* color, size_t size); /// construct with explicit (floating point) RGB values CRgbaColor(float r, float g, float b); /// construct with explicit (floating point) RGB+alpha values CRgbaColor(float r, float g, float b, float a); /// construct with explicit (unsigned char) RGB values. These are /// normalized to 0-1 internally. CRgbaColor(unsigned char r, unsigned char g, unsigned char b); /// construct with explicit (unsigned char) RGB+alpha values. These are /// normalized from 0-1 internally. CRgbaColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a); /// construct from a string encoded in the form "r g b" explicit CRgbaColor(const string& s); /// virtual dtor virtual ~CRgbaColor(); /// set the values from explicit (floating point) RGB values void Set(float r, float g, float b); /// set the values from explicit (floating point) RGB+alpha values void Set(float r, float g, float b, float a); /// set the values from explicit (unsigned char) RGB values. These /// are normalized internally to the range 0-1. void Set(unsigned char r, unsigned char g, unsigned char b); /// set the values from explicit (unsigned char) RGB+alpha values. These /// are normalized internally to the range 0-1. void Set(unsigned char r, unsigned char g, unsigned char b, unsigned char a); /// Set specific channels from floating point values void SetRed (float r); void SetGreen(float r); void SetBlue (float r); void SetAlpha(float r); /// Set specific channels from floating unsigned char values. These /// are normalized internally to the range 0-1. void SetRed (unsigned char r); void SetGreen(unsigned char r); void SetBlue (unsigned char r); void SetAlpha(unsigned char r); /// Get specific channels in floating point values. float GetRed (void) const; float GetGreen(void) const; float GetBlue (void) const; float GetAlpha(void) const; /// Get specific channels in unsigned char values. unsigned char GetRedUC (void) const; unsigned char GetGreenUC(void) const; unsigned char GetBlueUC (void) const; unsigned char GetAlphaUC(void) const; /// Access the color array directly. const float* GetColorArray(void) const; /// print the color to a stream in the form "r g b" virtual void PrintTo(CNcbiOstream& strm) const; virtual void PrintTo(CNcbiOstream& strm, bool printAlpha) const; /// Return a string representation of the current color virtual string ToString(bool printAlpha = true) const; /// Set the values from an encoded string of the form "r g b" virtual void ScanFrom(const string& str); // add a color to this color CRgbaColor& operator+=(const CRgbaColor& c1); // multiply this color by a scalar CRgbaColor& operator*=(float f); /// return a mapped color string from a named color static const char* ColorStrFromName(const string& desc); /// Interpolate two colors. The resulting color returned is /// ( (color1 * alpha) + (color2 * (1 - alpha) ) static CRgbaColor Interpolate(const CRgbaColor& color1, const CRgbaColor& color2, float alpha); // lighten a color by a scaling factor. Scale must range from 0-1. // This is equivalent to interpolating the color with white, with the // exception that the alpha channel is not altered. void Lighten(float scale); // lighten a color by a scaling factor. Scale must range from 0-1. // This is equivalent to interpolating the color with black, with the // exception that the alpha channel is not altered. void Darken(float scale); private: float m_Rgba[4];};/// global comparison operatorNCBI_GUIUTILS_EXPORTbool operator==(const CRgbaColor& c1, const CRgbaColor& c2);/// add two colorsNCBI_GUIUTILS_EXPORTCRgbaColor operator+(const CRgbaColor& c1, const CRgbaColor& c2);/// multiply a color by a scalarNCBI_GUIUTILS_EXPORTCRgbaColor operator*(const CRgbaColor& c1, float f);END_NCBI_SCOPE/* @} *//* * =========================================================================== * $Log: rgba_color.hpp,v $ * Revision 1000.3 2004/06/01 19:51:17 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.11 * * Revision 1.11 2004/05/11 13:48:14 dicuccio * Added Darken(), Lighten() * * Revision 1.10 2004/05/03 12:41:10 dicuccio * Split library into gui_utils and gui_objutils. Added #include for gui/gui.hpp * * Revision 1.9 2004/04/16 14:27:17 dicuccio * Added doxygen module tag * * Revision 1.8 2004/01/27 18:30:02 dicuccio * Added comments. Promoted member operators to global operators. Added * Interpolate() * * Revision 1.7 2003/12/22 19:16:08 dicuccio * Added functions to add/scale colors * * Revision 1.6 2003/10/30 13:32:52 rsmith * Add ColorStrFromName a static function to convert color names to color numbers: * e.g. "blue" -> "0 0 255" * * Revision 1.5 2003/09/01 12:42:34 meric * Added ScanFrom(const string&), which is now used by a ctor * * Revision 1.4 2003/08/25 18:02:19 rsmith * Colors to and from strings. * * Revision 1.3 2003/06/18 17:54:11 meric * Moved inline interface to .cpp file * * Revision 1.2 2003/06/18 17:25:27 meric * Final phase of print reorg: remove dependence on gui/opengl and OpenGL * * Revision 1.1 2003/06/18 16:42:09 meric * Initial version * * * =========================================================================== */#endif // GUI_UTILS___RGBA_COLOR__HPP
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?