1 #ifndef oxygenpalette_h
2 #define oxygenpalette_h
3 /*
4 * this file is part of the oxygen gtk engine
5 * Copyright (c) 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr>
6 *
7 * This  library is free  software; you can  redistribute it and/or
8 * modify it  under  the terms  of the  GNU Lesser  General  Public
9 * License  as published  by the Free  Software  Foundation; either
10 * version 2 of the License, or( at your option ) any later version.
11 *
12 * This library is distributed  in the hope that it will be useful,
13 * but  WITHOUT ANY WARRANTY; without even  the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License  along  with  this library;  if not,  write to  the Free
19 * Software Foundation, Inc., 51  Franklin St, Fifth Floor, Boston,
20 * MA 02110-1301, USA.
21 */
22 
23 #include "oxygenrgba.h"
24 
25 #include <vector>
26 #include <map>
27 
28 namespace Oxygen
29 {
30 
31     // forward declarations
32     namespace ColorUtils
33     { class Effect; }
34 
35     //! store colors for all Color groups and roles
36     class Palette
37     {
38 
39         public:
40 
41         //! color roles
42         enum Role
43         {
44             Base,
45             BaseAlternate,
46             Button,
47             Selected,
48             Window,
49             Tooltip,
50             Text,
51             NegativeText,
52             ButtonText,
53             SelectedText,
54             WindowText,
55             TooltipText,
56             Focus,
57             Hover,
58 
59             // these two are use for drawFloatFrame
60             ActiveWindowBackground,
61             InactiveWindowBackground,
62 
63             NumColors
64         };
65 
66         //! color groups
67         enum Group
68         {
69             Active,
70             Inactive,
71             Disabled
72         };
73 
74         //! color list
75         typedef std::vector<ColorUtils::Rgba> ColorList;
76 
77         //! color set
78         class ColorSet: public std::map<Role, ColorUtils::Rgba>
79         {
80 
81             public:
82 
83             //! insert
insert(Role role,const ColorUtils::Rgba & color)84             void insert( Role role, const ColorUtils::Rgba& color )
85             { std::map<Role, ColorUtils::Rgba>::insert( std::make_pair( role, color ) ); }
86 
87             //! returns true if color set contains given Role
contains(Role role)88             bool contains( Role role ) const
89             { return find( role ) != end(); }
90 
91         };
92 
93         //! constructor
Palette(void)94         Palette( void ):
95             _activeColors( NumColors, ColorUtils::Rgba() ),
96             _inactiveColors( NumColors, ColorUtils::Rgba() ),
97             _disabledColors( NumColors, ColorUtils::Rgba() ),
98             _group( Active )
99         {}
100 
101         //! clear
clear(void)102         void clear( void )
103         {
104             _activeColors = ColorList( NumColors, ColorUtils::Rgba() );
105             _inactiveColors = ColorList( NumColors, ColorUtils::Rgba() );
106             _disabledColors = ColorList( NumColors, ColorUtils::Rgba() );
107         }
108 
109         //! get color
color(Role role)110         const ColorUtils::Rgba& color( Role role ) const
111         { return colorList( _group )[role]; }
112 
113         //! get color
color(Group group,Role role)114         const ColorUtils::Rgba& color( Group group, Role role ) const
115         { return colorList( group )[role]; }
116 
117         //! set current group
setGroup(Group value)118         void setGroup( Group value )
119         { _group = value; }
120 
121         //! set current
setColor(Group group,Role role,const ColorUtils::Rgba & value)122         void setColor( Group group, Role role, const ColorUtils::Rgba& value )
123         { colorList( group )[role] = value; }
124 
125         //! copy on group onto the other
copy(Group from,Group to)126         void copy( Group from, Group to )
127         { colorList(to) = colorList(from); }
128 
129         //! generate group from input, using provided effect
130         void generate( Group from, Group to, const ColorUtils::Effect&, bool changeSelectionColor = false );
131 
132         //! get string for role
groupName(const Group & group)133         static std::string groupName( const Group& group )
134         {
135             switch( group )
136             {
137                 case Active: return "Active";
138                 case Inactive: return "Inactive";
139                 case Disabled: return "Disabled";
140                 default: return "unknown";
141             }
142         }
143 
144         //! get string for role
roleName(const Role & role)145         static std::string roleName( const Role& role )
146         {
147             switch( role )
148             {
149                 case Base: return "Base";
150                 case BaseAlternate: return "BaseAlternate";
151                 case Button: return "Button";
152                 case Selected: return "Selected";
153                 case Window: return "Window";
154                 case Tooltip: return "Tooltip";
155                 case Text: return "Text";
156                 case NegativeText: return "NegativeText";
157                 case ButtonText: return "ButtonText";
158                 case SelectedText: return "SelectedText";
159                 case WindowText: return "WindowText";
160                 case TooltipText: return "TooltipText";
161                 case Focus: return "Focus";
162                 case Hover: return "Hover";
163                 case ActiveWindowBackground: return "ActiveWindowBackground";
164                 case InactiveWindowBackground: return "InactiveWindowBackground";
165                 default: return "unknown";
166             }
167         }
168 
169         protected:
170 
171         //! get color list from group
colorList(Group group)172         const ColorList& colorList( Group group ) const
173         {
174             switch( group )
175             {
176                 default:
177                 case Active: return _activeColors;
178                 case Inactive: return _inactiveColors;
179                 case Disabled: return _disabledColors;
180             }
181         }
182 
183         //! get color list from group
colorList(Group group)184         ColorList& colorList( Group group )
185         {
186             switch( group )
187             {
188                 default:
189                 case Active: return _activeColors;
190                 case Inactive: return _inactiveColors;
191                 case Disabled: return _disabledColors;
192             }
193         }
194 
195         private:
196 
197         ColorList _activeColors;
198         ColorList _inactiveColors;
199         ColorList _disabledColors;
200 
201         //! current group
202         Group _group;
203 
204         //! streamer for color list
205         friend std::ostream& operator << ( std::ostream& out, const ColorList& colors );
206         friend std::ostream& operator << ( std::ostream& out, const ColorSet& colors );
207         friend std::ostream& operator << ( std::ostream& out, const Palette& palette );
208 
209     };
210 
211 }
212 
213 #endif
214