File indexing completed on 2024-04-28 05:32:12

0001 #ifndef oxygenpalette_h
0002 #define oxygenpalette_h
0003 /*
0004 * this file is part of the oxygen gtk engine
0005 * SPDX-FileCopyrightText: 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr>
0006 *
0007 * SPDX-License-Identifier: LGPL-2.0-or-later
0008 */
0009 
0010 #include "oxygenrgba.h"
0011 
0012 #include <vector>
0013 #include <map>
0014 
0015 namespace Oxygen
0016 {
0017 
0018     // forward declarations
0019     namespace ColorUtils
0020     { class Effect; }
0021 
0022     //! store colors for all Color groups and roles
0023     class Palette
0024     {
0025 
0026         public:
0027 
0028         //! color roles
0029         enum Role
0030         {
0031             Base,
0032             BaseAlternate,
0033             Button,
0034             Selected,
0035             Window,
0036             Tooltip,
0037             Text,
0038             NegativeText,
0039             ButtonText,
0040             SelectedText,
0041             WindowText,
0042             TooltipText,
0043             Focus,
0044             Hover,
0045 
0046             // these two are use for drawFloatFrame
0047             ActiveWindowBackground,
0048             InactiveWindowBackground,
0049 
0050             NumColors
0051         };
0052 
0053         //! color groups
0054         enum Group
0055         {
0056             Active,
0057             Inactive,
0058             Disabled
0059         };
0060 
0061         //! color list
0062         typedef std::vector<ColorUtils::Rgba> ColorList;
0063 
0064         //! color set
0065         class ColorSet: public std::map<Role, ColorUtils::Rgba>
0066         {
0067 
0068             public:
0069 
0070             //! insert
0071             void insert( Role role, const ColorUtils::Rgba& color )
0072             { std::map<Role, ColorUtils::Rgba>::insert( std::make_pair( role, color ) ); }
0073 
0074             //! returns true if color set contains given Role
0075             bool contains( Role role ) const
0076             { return find( role ) != end(); }
0077 
0078         };
0079 
0080         //! constructor
0081         Palette( void ):
0082             _activeColors( NumColors, ColorUtils::Rgba() ),
0083             _inactiveColors( NumColors, ColorUtils::Rgba() ),
0084             _disabledColors( NumColors, ColorUtils::Rgba() ),
0085             _group( Active )
0086         {}
0087 
0088         //! clear
0089         void clear( void )
0090         {
0091             _activeColors = ColorList( NumColors, ColorUtils::Rgba() );
0092             _inactiveColors = ColorList( NumColors, ColorUtils::Rgba() );
0093             _disabledColors = ColorList( NumColors, ColorUtils::Rgba() );
0094         }
0095 
0096         //! get color
0097         const ColorUtils::Rgba& color( Role role ) const
0098         { return colorList( _group )[role]; }
0099 
0100         //! get color
0101         const ColorUtils::Rgba& color( Group group, Role role ) const
0102         { return colorList( group )[role]; }
0103 
0104         //! set current group
0105         void setGroup( Group value )
0106         { _group = value; }
0107 
0108         //! set current
0109         void setColor( Group group, Role role, const ColorUtils::Rgba& value )
0110         { colorList( group )[role] = value; }
0111 
0112         //! copy on group onto the other
0113         void copy( Group from, Group to )
0114         { colorList(to) = colorList(from); }
0115 
0116         //! generate group from input, using provided effect
0117         void generate( Group from, Group to, const ColorUtils::Effect&, bool changeSelectionColor = false );
0118 
0119         //! get string for role
0120         static std::string groupName( const Group& group )
0121         {
0122             switch( group )
0123             {
0124                 case Active: return "Active";
0125                 case Inactive: return "Inactive";
0126                 case Disabled: return "Disabled";
0127                 default: return "unknown";
0128             }
0129         }
0130 
0131         //! get string for role
0132         static std::string roleName( const Role& role )
0133         {
0134             switch( role )
0135             {
0136                 case Base: return "Base";
0137                 case BaseAlternate: return "BaseAlternate";
0138                 case Button: return "Button";
0139                 case Selected: return "Selected";
0140                 case Window: return "Window";
0141                 case Tooltip: return "Tooltip";
0142                 case Text: return "Text";
0143                 case NegativeText: return "NegativeText";
0144                 case ButtonText: return "ButtonText";
0145                 case SelectedText: return "SelectedText";
0146                 case WindowText: return "WindowText";
0147                 case TooltipText: return "TooltipText";
0148                 case Focus: return "Focus";
0149                 case Hover: return "Hover";
0150                 case ActiveWindowBackground: return "ActiveWindowBackground";
0151                 case InactiveWindowBackground: return "InactiveWindowBackground";
0152                 default: return "unknown";
0153             }
0154         }
0155 
0156         protected:
0157 
0158         //! get color list from group
0159         const ColorList& colorList( Group group ) const
0160         {
0161             switch( group )
0162             {
0163                 default:
0164                 case Active: return _activeColors;
0165                 case Inactive: return _inactiveColors;
0166                 case Disabled: return _disabledColors;
0167             }
0168         }
0169 
0170         //! get color list from group
0171         ColorList& colorList( Group group )
0172         {
0173             switch( group )
0174             {
0175                 default:
0176                 case Active: return _activeColors;
0177                 case Inactive: return _inactiveColors;
0178                 case Disabled: return _disabledColors;
0179             }
0180         }
0181 
0182         private:
0183 
0184         ColorList _activeColors;
0185         ColorList _inactiveColors;
0186         ColorList _disabledColors;
0187 
0188         //! current group
0189         Group _group;
0190 
0191         //! streamer for color list
0192         friend std::ostream& operator << ( std::ostream& out, const ColorList& colors );
0193         friend std::ostream& operator << ( std::ostream& out, const ColorSet& colors );
0194         friend std::ostream& operator << ( std::ostream& out, const Palette& palette );
0195 
0196     };
0197 
0198 }
0199 
0200 #endif