1 ///
2 module nanogui.theme;
3 
4 /*
5 	NanoGUI was developed by Wenzel Jakob <wenzel.jakob@epfl.ch>.
6 	The widget drawing code is based on the NanoVG demo application
7 	by Mikko Mononen.
8 
9 	All rights reserved. Use of this source code is governed by a
10 	BSD-style license that can be found in the LICENSE.txt file.
11 */
12 
13 import nanogui.common : NVGContext, Color;
14 import nanogui.entypo;
15 
16 /**
17  * Storage class for basic theme-related properties.
18  */
19 class Theme
20 {
21 public:
22 	this(NVGContext nvg)
23 	{
24 		mStandardFontSize                 = 16;
25 		mButtonFontSize                   = 20;
26 		mTextBoxFontSize                  = 20;
27 		mIconScale                        = 0.77f;
28 
29 		mWindowCornerRadius               = 2;
30 		mWindowHeaderHeight               = 30;
31 		mWindowDropShadowSize             = 10;
32 		mButtonCornerRadius               = 2;
33 		mTabBorderWidth                   = 0.75f;
34 		mTabInnerMargin                   = 5;
35 		mTabMinButtonWidth                = 20;
36 		mTabMaxButtonWidth                = 160;
37 		mTabControlWidth                  = 20;
38 		mTabButtonHorizontalPadding       = 10;
39 		mTabButtonVerticalPadding         = 2;
40 
41 		mDropShadow                       = Color(0, 0, 0, 128);
42 		mTransparent                      = Color(0, 0, 0, 0);
43 		mBorderDark                       = Color(29, 29, 29, 255);
44 		mBorderLight                      = Color(92, 92, 92, 255);
45 		mBorderMedium                     = Color(35, 35, 35, 255);
46 		mTextColor                        = Color(255, 255, 255, 160);
47 		mDisabledTextColor                = Color(255, 255, 255, 80);
48 		mTextColorShadow                  = Color(0, 0, 0, 160);
49 		mIconColor                        = mTextColor;
50 
51 		mButtonGradientTopFocused         = Color(64, 64, 64, 255);
52 		mButtonGradientBotFocused         = Color(48, 48, 48, 255);
53 		mButtonGradientTopUnfocused       = Color(74, 74, 74, 255);
54 		mButtonGradientBotUnfocused       = Color(58, 58, 58, 255);
55 		mButtonGradientTopPushed          = Color(41, 41, 41, 255);
56 		mButtonGradientBotPushed          = Color(29, 29, 29, 255);
57 
58 		/* Window-related */
59 		mWindowFillUnfocused              = Color(43, 43, 43, 230);
60 		mWindowFillFocused                = Color(45, 45, 45, 230);
61 		mWindowTitleUnfocused             = Color(220, 220, 220, 160);
62 		mWindowTitleFocused               = Color(255, 255, 255, 190);
63 
64 		mWindowHeaderGradientTop          = mButtonGradientTopUnfocused;
65 		mWindowHeaderGradientBot          = mButtonGradientBotUnfocused;
66 		mWindowHeaderSepTop               = mBorderLight;
67 		mWindowHeaderSepBot               = mBorderDark;
68 
69 		mWindowPopup                      = Color(50, 50, 50, 255);
70 		mWindowPopupTransparent           = Color(50, 50, 50, 0);
71 
72 		mCheckBoxIcon                     = Entypo.ICON_CHECK;
73 		mMessageInformationIcon           = Entypo.ICON_INFO_WITH_CIRCLE;
74 		mMessageQuestionIcon              = Entypo.ICON_HELP_WITH_CIRCLE;
75 		mMessageWarningIcon               = Entypo.ICON_WARNING;
76 		mMessageAltButtonIcon             = Entypo.ICON_CIRCLE_WITH_CROSS;
77 		mMessagePrimaryButtonIcon         = Entypo.ICON_CHECK;
78 		mPopupChevronRightIcon            = Entypo.ICON_CHEVRON_RIGHT;
79 		mPopupChevronLeftIcon             = Entypo.ICON_CHEVRON_LEFT;
80 		mTabHeaderLeftIcon                = Entypo.ICON_ARROW_BOLD_LEFT;
81 		mTabHeaderRightIcon               = Entypo.ICON_ARROW_BOLD_RIGHT;
82 		mTextBoxUpIcon                    = Entypo.ICON_CHEVRON_UP;
83 		mTextBoxDownIcon                  = Entypo.ICON_CHEVRON_DOWN;
84 
85 		import arsd.nanovega : createFontMem;
86 		import nanogui.resources;
87 		mFontNormal = nvg.createFontMem("sans", roboto_regular_ttf.ptr,
88 									   cast(int) roboto_regular_ttf.length, 0);
89 		mFontBold = nvg.createFontMem("sans-bold", roboto_bold_ttf.ptr,
90 									 cast(int) roboto_bold_ttf.length, 0);
91 		mFontIcons = nvg.createFontMem("icons", entypo_ttf.ptr,
92 									  cast(int) entypo_ttf.length, 0);
93 		if (mFontNormal == -1 || mFontBold == -1 || mFontIcons == -1)
94 		{
95 			throw new Exception("Could not load fonts!");
96 		}
97 	}
98 
99 	/* Fonts */
100 	/// The standard font face (default: `"sans"` from `resources/roboto_regular.ttf`).
101 	int mFontNormal;
102 	/// The bold font face (default: `"sans-bold"` from `resources/roboto_regular.ttf`).
103 	int mFontBold;
104 	/// The icon font face (default: `"icons"` from `resources/entypo.ttf`).
105 	int mFontIcons;
106 	/**
107 	 * The amount of scaling that is applied to each icon to fit the size of
108 	 * NanoGUI widgets.  The default value is `0.77f`, setting to e.g. higher
109 	 * than `1.0f` is generally discouraged.
110 	 */
111 	float mIconScale;
112 
113 	/* Spacing-related parameters */
114 	/// The font size for all widgets other than buttons and textboxes (default: ` 16`).
115 	int mStandardFontSize;
116 	/// The font size for buttons (default: `20`).
117 	int mButtonFontSize;
118 	/// The font size for text boxes (default: `20`).
119 	int mTextBoxFontSize;
120 	/// Rounding radius for Window widget corners (default: `2`).
121 	int mWindowCornerRadius;
122 	/// Default size of Window widget titles (default: `30`).
123 	int mWindowHeaderHeight;
124 	/// Size of drop shadow rendered behind the Window widgets (default: `10`).
125 	int mWindowDropShadowSize;
126 	/// Rounding radius for Button (and derived types) widgets (default: `2`).
127 	int mButtonCornerRadius;
128 	/// The border width for TabHeader widgets (default: `0.75f`).
129 	float mTabBorderWidth;
130 	/// The inner margin on a TabHeader widget (default: `5`).
131 	int mTabInnerMargin;
132 	/// The minimum size for buttons on a TabHeader widget (default: `20`).
133 	int mTabMinButtonWidth;
134 	/// The maximum size for buttons on a TabHeader widget (default: `160`).
135 	int mTabMaxButtonWidth;
136 	/// Used to help specify what lies "in bound" for a TabHeader widget (default: `20`).
137 	int mTabControlWidth;
138 	/// The amount of horizontal padding for a TabHeader widget (default: `10`).
139 	int mTabButtonHorizontalPadding;
140 	/// The amount of vertical padding for a TabHeader widget (default: `2`).
141 	int mTabButtonVerticalPadding;
142 
143 	/* Generic colors */
144 	/**
145 	 * The color of the drop shadow drawn behind widgets
146 	 * (default: intensity=`0`, alpha=`128`; see `nanogui.Color.Color(int,int)`).
147 	 */
148 	Color mDropShadow;
149 	/**
150 	 * The transparency color
151 	 * (default: intensity=`0`, alpha=`0`; see `nanogui.Color.Color(int,int)`).
152 	 */
153 	Color mTransparent;
154 	/**
155 	 * The dark border color
156 	 * (default: intensity=`29`, alpha=`255`; see `nanogui.Color.Color(int,int)`).
157 	 */
158 	Color mBorderDark;
159 	/**
160 	 * The light border color
161 	 * (default: intensity=`92`, alpha=`255`; see `nanogui.Color.Color(int,int)`).
162 	 */
163 	Color mBorderLight;
164 	/**
165 	 * The medium border color
166 	 * (default: intensity=`35`, alpha=`255`; see `nanogui.Color.Color(int,int)`).
167 	 */
168 	Color mBorderMedium;
169 	/**
170 	 * The text color
171 	 * (default: intensity=`255`, alpha=`160`; see `nanogui.Color.Color(int,int)`).
172 	 */
173 	Color mTextColor;
174 	/**
175 	 * The disable dtext color
176 	 * (default: intensity=`255`, alpha=`80`; see `nanogui.Color.Color(int,int)`).
177 	 */
178 	Color mDisabledTextColor;
179 	/**
180 	 * The text shadow color
181 	 * (default: intensity=`0`, alpha=`160`; see `nanogui.Color.Color(int,int)`).
182 	 */
183 	Color mTextColorShadow;
184 	/// The icon color (default: \ref nanogui::Theme::mTextColor).
185 	Color mIconColor;
186 
187 	/* Button colors */
188 	/**
189 	 * The top gradient color for buttons in focus
190 	 * (default: intensity=`64`, alpha=`255`; see `nanogui.Color.Color(int,int)`).
191 	 */
192 	Color mButtonGradientTopFocused;
193 	/**
194 	 * The bottom gradient color for buttons in focus
195 	 * (default: intensity=`48`, alpha=`255`; see `nanogui.Color.Color(int,int)`).
196 	 */
197 	Color mButtonGradientBotFocused;
198 	/**
199 	 * The top gradient color for buttons not in focus
200 	 * (default: intensity=`74`, alpha=`255`; see `nanogui.Color.Color(int,int)`).
201 	 */
202 	Color mButtonGradientTopUnfocused;
203 	/**
204 	 * The bottom gradient color for buttons not in focus
205 	 * (default: intensity=`58`, alpha=`255`; see `nanogui.Color.Color(int,int)`).
206 	 */
207 	Color mButtonGradientBotUnfocused;
208 	/**
209 	 * The top gradient color for buttons currently pushed
210 	 * (default: intensity=`41`, alpha=`255`; see `nanogui.Color.Color(int,int)`).
211 	 */
212 	Color mButtonGradientTopPushed;
213 	/**
214 	 * The bottom gradient color for buttons currently pushed
215 	 * (default: intensity=`29`, alpha=`255`; see `nanogui.Color.Color(int,int)`).
216 	 */
217 	Color mButtonGradientBotPushed;
218 
219 	/* Window colors */
220 	/**
221 	 * The fill color for a Window that is not in focus
222 	 * (default: intensity=`43`, alpha=`230`; see `nanogui.Color.Color(int,int)`).
223 	 */
224 	Color mWindowFillUnfocused;
225 	/**
226 	 * The fill color for a Window that is in focus
227 	 * (default: intensity=`45`, alpha=`230`; see `nanogui.Color.Color(int,int)`).
228 	 */
229 	Color mWindowFillFocused;
230 	/**
231 	 * The title color for a Window that is not in focus
232 	 * (default: intensity=`220`, alpha=`160`; see `nanogui.Color.Color(int,int)`).
233 	 */
234 	Color mWindowTitleUnfocused;
235 	/**
236 	 * The title color for a Window that is in focus
237 	 * (default: intensity=`255`, alpha=`190`; see `nanogui.Color.Color(int,int)`).
238 	 */
239 	Color mWindowTitleFocused;
240 
241 	/**
242 	 * The top gradient color for Window headings
243 	 * (default: \ref nanogui::Theme::mButtonGradientTopUnfocused).
244 	 */
245 	Color mWindowHeaderGradientTop;
246 	/**
247 	 * The bottom gradient color for Window headings
248 	 * (default: \ref nanogui::Theme::mButtonGradientBotUnfocused).
249 	 */
250 	Color mWindowHeaderGradientBot;
251 	/// The Window header top separation color (default: `nanogui.Theme.mBorderLight`).
252 	Color mWindowHeaderSepTop;
253 	/// The Window header bottom separation color (default: `nanogui.Theme.mBorderDark`).
254 	Color mWindowHeaderSepBot;
255 
256 	/**
257 	 * The popup window color
258 	 * (default: intensity=`50`, alpha=`255`; see `nanogui.Color.Color(int,int)`).
259 	 */
260 	Color mWindowPopup;
261 	/**
262 	 * The transparent popup window color
263 	 * (default: intensity=`50`, alpha=`0`; see `nanogui.Color.Color(int,int)`).
264 	 */
265 	Color mWindowPopupTransparent;
266 
267 	/// Icon to use for CheckBox widgets (default: `Entypo.ICON_CHECK`).
268 	dchar mCheckBoxIcon;
269 	/// Icon to use for informational MessageDialog widgets (default: `Entypo.ICON_INFO_WITH_CIRCLE`).
270 	dchar mMessageInformationIcon;
271 	/// Icon to use for interrogative MessageDialog widgets (default: `Entypo.ICON_HELP_WITH_CIRCLE`).
272 	dchar mMessageQuestionIcon;
273 	/// Icon to use for warning MessageDialog widgets (default: `Entypo.ICON_WARNING`).
274 	dchar mMessageWarningIcon;
275 	/// Icon to use on MessageDialog alt button (default: `Entypo.ICON_CIRCLE_WITH_CROSS`).
276 	dchar mMessageAltButtonIcon;
277 	/// Icon to use on MessageDialog primary button (default: `Entypo.ICON_CHECK`).
278 	dchar mMessagePrimaryButtonIcon;
279 	/// Icon to use for PopupButton widgets opening to the right (default: `Entypo.ICON_CHEVRON_RIGHT`).
280 	dchar mPopupChevronRightIcon;
281 	/// Icon to use for PopupButton widgets opening to the left (default: `Entypo.ICON_CHEVRON_LEFT`).
282 	dchar mPopupChevronLeftIcon;
283 	/// Icon to indicate hidden tabs to the left on a TabHeader (default: `Entypo.ICON_ARROW_BOLD_LEFT`).
284 	dchar mTabHeaderLeftIcon;
285 	/// Icon to indicate hidden tabs to the right on a TabHeader (default: `Entypo.ICON_ARROW_BOLD_RIGHT`).
286 	dchar mTabHeaderRightIcon;
287 	/// Icon to use when a TextBox has an up toggle (e.g. IntBox) (default: `Entypo.ICON_CHEVRON_UP`).
288 	dchar mTextBoxUpIcon;
289 	/// Icon to use when a TextBox has a down toggle (e.g. IntBox) (default: `Entypo.ICON_CHEVRON_DOWN`).
290 	dchar mTextBoxDownIcon;
291 
292 protected:
293 	/// Default destructor does nothing; allows for inheritance.
294 	~this() { }
295 }