1 /* Reverse Engineer's Hex Editor
2  * Copyright (C) 2018-2020 Daniel Collins <solemnwarning@solemnwarning.net>
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 2 as published by
6  * the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
11  * more details.
12  *
13  * You should have received a copy of the GNU General Public License along with
14  * this program; if not, write to the Free Software Foundation, Inc., 51
15  * Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
16 */
17 
18 #ifndef REHEX_PALETTE_HPP
19 #define REHEX_PALETTE_HPP
20 
21 #include <string>
22 #include <wx/colour.h>
23 
24 namespace REHex {
25 	/**
26 	 * @brief Colour palette to use when drawing custom controls.
27 	*/
28 	class Palette
29 	{
30 		public:
31 			static const int NUM_HIGHLIGHT_COLOURS = 6;
32 
33 			enum ColourIndex
34 			{
35 				PAL_NORMAL_TEXT_BG,
36 				PAL_NORMAL_TEXT_FG,
37 				PAL_ALTERNATE_TEXT_FG,
38 				PAL_INVERT_TEXT_BG,
39 				PAL_INVERT_TEXT_FG,
40 				PAL_SELECTED_TEXT_BG,
41 				PAL_SELECTED_TEXT_FG,
42 				PAL_SECONDARY_SELECTED_TEXT_BG,
43 				PAL_SECONDARY_SELECTED_TEXT_FG,
44 				PAL_DIRTY_TEXT_BG,
45 				PAL_DIRTY_TEXT_FG,
46 
47 				PAL_HIGHLIGHT_TEXT_MIN_BG,
48 				PAL_HIGHLIGHT_TEXT_MIN_FG,
49 				PAL_HIGHLIGHT_TEXT_MAX_BG = (PAL_HIGHLIGHT_TEXT_MIN_BG + (NUM_HIGHLIGHT_COLOURS - 1) * 2),
50 				PAL_HIGHLIGHT_TEXT_MAX_FG = (PAL_HIGHLIGHT_TEXT_MIN_FG + (NUM_HIGHLIGHT_COLOURS - 1) * 2),
51 
52 				PAL_COMMENT_BG,
53 				PAL_COMMENT_FG,
54 
55 				PAL_MAX = PAL_COMMENT_FG,
56 
57 				PAL_INVALID = 9999,
58 			};
59 
60 			Palette(const std::string &name, const std::string &label, const wxColour colours[]);
61 
62 			/**
63 			 * @brief Get the internal name of the palette.
64 			*/
65 			const std::string &get_name() const;
66 
67 			/**
68 			 * @brief Get the display name of the palette.
69 			*/
70 			const std::string &get_label() const;
71 
72 			/**
73 			 * @brief Get the colour at the given palette index.
74 			 *
75 			 * @param index Palette index slot (0 .. PAL_MAX).
76 			*/
77 			const wxColour &operator[](int index) const;
78 
79 			/**
80 			 * @brief Get the background colour for the given text highlight colour.
81 			 *
82 			 * @param highlight_idx Highlight index (0 .. NUM_HIGHLIGHT_COLOURS - 1).
83 			*/
84 			const wxColour &get_highlight_bg(int highlight_idx) const;
85 
86 			/**
87 			 * @brief Get the foreground colour for the given text highlight colour.
88 			 *
89 			 * @param highlight_idx Highlight index (0 .. NUM_HIGHLIGHT_COLOURS - 1).
90 			*/
91 			const wxColour &get_highlight_fg(int highlight_idx) const;
92 
93 			/**
94 			 * @brief Get the background colour palette index for the given text highlight colour.
95 			 *
96 			 * @param index Highlight index (0 .. NUM_HIGHLIGHT_COLOURS - 1).
97 			*/
98 			static ColourIndex get_highlight_bg_idx(int index);
99 
100 			/**
101 			 * @brief Get the foreground colour palette index for the given text highlight colour.
102 			 *
103 			 * @param index Highlight index (0 .. NUM_HIGHLIGHT_COLOURS - 1).
104 			*/
105 			static ColourIndex get_highlight_fg_idx(int index);
106 
107 			/**
108 			 * @brief Blend two palette colours together.
109 			 *
110 			 * @param colour_a_idx Palette index of colour A (0 .. PAL_MAX).
111 			 * @param colour_b_idx Palette index of colour B (0 .. PAL_MAX).
112 			*/
113 			wxColour get_average_colour(int colour_a_idx, int colour_b_idx) const;
114 
115 			static Palette *create_system_palette();
116 			static Palette *create_light_palette();
117 			static Palette *create_dark_palette();
118 
119 		private:
120 			std::string name;
121 			std::string label;
122 
123 			wxColour palette[PAL_MAX + 1];
124 	};
125 
126 	/**
127 	 * @brief The active colour palette.
128 	*/
129 	extern Palette *active_palette;
130 }
131 
132 #endif /* !REHEX_PALETTE_HPP */
133