1 /*
2  * Copyright (C) 2015-2017, by Laszlo Szeremi under the Boost license.
3  *
4  * Pixel Perfect Engine, concrete.stylesheet module
5  */
6 
7 module pixelperfectengine.concrete.types.stylesheet;
8 
9 import pixelperfectengine.graphics.bitmap;
10 import pixelperfectengine.graphics.fontsets;
11 import collections.hashmap;
12 /**
13  * Defines style data for the Concrete GUI.
14  */
15 public class StyleSheet{
16 	///Default color palette. First 16 colors are reserved for GUI defaults in a single workspace, second 16 colors are of the RGBI standard, the rest could
17 	///be used for other GUI elements such as backgrounds and icons
18 	public static enum Color[] defaultpaletteforGUI =
19 	[Color(0x00,0x00,0x00,0x00),	//transparent
20 	Color(0xFF,0xFF,0xFF,0xFF),		//reserved
21 	Color(0x30,0x30,0x30,0xFF),		//buttonTop
22 	Color(0x40,0x40,0x40,0xFF),		//windowascent
23 	Color(0x18,0x18,0x18,0xFF),		//windowdescent
24 	Color(0x10,0x10,0x10,0xff),		//windowBottom
25 	Color(0x20,0x20,0x20,0xff),		//window
26 	Color(0x00,0x00,0xaa,0xFF),		//WHAascent
27 	Color(0x00,0x00,0x40,0xFF),		//WHAdescent
28 	Color(0x00,0x00,0x70,0xFF),		//WHAtop
29 	Color(0x00,0x00,0xFF,0xFF),		//reserved (cursors now use a given color)
30 	Color(0x00,0x00,0x7F,0xFF),		//reserved for windowascentB
31 	Color(0xFF,0xFF,0x00,0xFF),		//reserved for windowBottomB
32 	Color(0x0a,0x0a,0x0a,0xFF),		//windowdescentB
33 	Color(0x7F,0x7F,0x7F,0xFF),		//reserved for WHAascentB
34 	Color(0x00,0x00,0x00,0xFF),		//reserved for WHAdescentB
35 
36 	Color(0x00,0x00,0x00,0xFF),		//Black
37 	Color(0x7F,0x00,0x00,0xFF),		//Dark Red
38 	Color(0x00,0x7F,0x00,0xFF),		//Dark Green
39 	Color(0x7F,0x7F,0x00,0xFF),		//Dark Yellow
40 	Color(0x00,0x00,0x7F,0xFF),		//Dark Blue
41 	Color(0x7F,0x00,0x7F,0xFF),		//Dark Purple
42 	Color(0x00,0x7F,0x7F,0xFF),		//Dark Turquiose
43 	Color(0x7F,0x7F,0x7F,0xFF),		//Grey
44 	Color(0x3F,0x3F,0x3F,0xFF),		//Dark Grey
45 	Color(0xFF,0x00,0x00,0xFF),		//Red
46 	Color(0x00,0xFF,0x00,0xFF),		//Green
47 	Color(0xFF,0xFF,0x00,0xFF),		//Yellow
48 	Color(0x00,0x00,0xFF,0xFF),		//Blue
49 	Color(0xFF,0x00,0xFF,0xFF),		//Purple
50 	Color(0x00,0xFF,0xFF,0xFF),		//Turquiose
51 	Color(0xFF,0xFF,0xFF,0xFF),		//White
52 	];
53 	//public Fontset!Bitmap8Bit[string] 		font;		
54 	public HashMap!(string, Fontset!Bitmap8Bit)	font;///Fonts stored here. 
55 	public HashMap!(string, CharacterFormattingInfo!Bitmap8Bit) _chrFormat;	///Character formatting
56 	//public CharacterFormattingInfo!Bitmap8Bit[string]	_chrFormat; ///Character formatting
57 	//public ubyte[string]						color;		///Colors are identified by strings.
58 	public HashMap!(string, ubyte)				color;		///Colors are identified by strings.
59 	//public ubyte[][string]					pattern;	///Stores line patterns.
60 	public HashMap!(string, ubyte[])			pattern;	///Stores line patterns.
61 	//public Bitmap8Bit[string]					images;		///For icons, pattern fills, etc...
62 	public HashMap!(string, Bitmap8Bit)			images;		///For icons, pattern fills, etc...
63 	//public int[string]							drawParameters;		///Draw parameters are used for border thickness, padding, etc...
64 	public HashMap!(string, int)				drawParameters;		///Draw parameters are used for border thickness, padding, etc...
65 	//public string[string]						fontTypes;	///Font type descriptions for various kind of components.
66 	
67 	/**
68 	 * Creates a default stylesheet.
69 	 */
70 	public this() @safe {
71 		color["transparent"] = 0x0000;
72 		color["normaltext"] = 0x001F;
73 		color["window"] = 0x0006;
74 		color["buttonTop"] = 0x0002;
75 		color["windowascent"] = 0x0003;
76 		color["windowdescent"] = 0x0004;
77 		color["windowinactive"] = 0x0005;
78 		color["selection"] = 0x0019;
79 		color["red"] = 0x0019;
80 		color["WHAascent"] = 0x0007;
81 		color["WHAdescent"] = 0x0008;
82 		color["WHTextActive"] = 0x001F;
83 		color["WHTextInactive"] = 0x0017;
84 		color["WHAtop"] = 0x0009;
85 		color["blue"] = 0x001c;
86 		color["darkblue"] = 0x0014;
87 		color["yellow"] = 0x001b;
88 		color["secondarytext"] = 0x001B;
89 		color["grey"] = 0x0017;
90 		color["black"] = 0x000F;
91 		color["white"] = 0x0001;
92 		color["PopUpMenuSecondaryTextColor"] = 0x001B;
93 		color["MenuBarSeparatorColor"] = 0x001F;
94 		color["PanelBorder"] = 0x0010;
95 		color["SliderBackground"] = 0x0004;
96 		color["SliderColor"] = 0x0003;
97 		color["ListViewVSep"] = 0x0000;
98 		color["ListViewHSep"] = 0x0000;
99 
100 		drawParameters["PopUpMenuHorizPadding"] = 4;
101 		drawParameters["PopUpMenuVertPadding"] = 1;
102 		drawParameters["PopUpMenuMinTextSpace"] = 8;
103 		drawParameters["PopUpMenuSeparatorSize"] = 7;
104 		drawParameters["ButtonPaddingHoriz"] = 8;
105 		drawParameters["PanelTitleFirstCharOffset"] = 16;
106 		drawParameters["PanelPadding"] = 4;
107 
108 		drawParameters["MenuBarHorizPadding"] = 4;
109 		drawParameters["MenuBarVertPadding"] = 2;
110 
111 		drawParameters["ListBoxRowHeight"] = 16;
112 		drawParameters["TextSpacingTop"] = 1;
113 		drawParameters["TextSpacingBottom"] = 1;
114 		drawParameters["TextSpacingSides"] = 2;
115 		drawParameters["WindowLeftPadding"] = 5;
116 		drawParameters["WindowRightPadding"] = 5;
117 		drawParameters["WindowTopPadding"] = 20;
118 		drawParameters["WindowBottomPadding"] = 5;
119 		drawParameters["WindowHeaderHeight"] = 16;
120 		drawParameters["ComponentHeight"] = 20;
121 		drawParameters["WindowHeaderHeight"] = 16;
122 		drawParameters["WHPaddingTop"] = 1;
123 		drawParameters["HorizScrollBarSize"] = 16;
124 		drawParameters["VertScrollBarSize"] = 16;
125 		drawParameters["horizTextPadding"] = 1;
126 
127 		drawParameters["PopUpLabelHorizPadding"] = 2;
128 		drawParameters["PopUpLabelVertPadding"] = 2;
129 
130 
131 		pattern["blackDottedLine"] = [0x1f, 0x1f, 0x10, 0x10];
132 	}
133 	/**
134 	 * Adds a fontset to the stylesheet with the given ID.
135 	 * IMPORTANT: ID of "default" must be set at least in order to ensure fallback capabilities!
136 	 */
137 	public void addFontset(Fontset!Bitmap8Bit f, string ID) @safe {
138 		font[ID] = f;
139 	}
140 	/**
141 	 * Returns the fontset with the given ID, or the default one if not found.
142 	 */
143 	public Fontset!Bitmap8Bit getFontset(string ID) @safe nothrow {
144 		auto result = font[ID];
145 		if (result !is null) return result;
146 		else return font["default"];
147 	}
148 	/**
149 	 * Adds a character formatting to the stylesheet with the given identifier.
150 	 * IMPORTANT: ID of "default" must be set at least in order to ensure fallback capabilities!
151 	 */
152 	public void addChrFormatting(CharacterFormattingInfo!Bitmap8Bit frmt, string ID) @safe nothrow {
153 		_chrFormat[ID] = frmt;
154 		//assert(_chrFormat[type] is frmt);
155 	}
156 	/**
157 	 * Duplicates character formatting for multiple IDs.
158 	 */
159 	public void duplicateChrFormatting(string src, string dest) @safe nothrow {
160 		_chrFormat[dest] = _chrFormat[src];
161 		
162 	}
163 	/**
164 	 * Returns the character formatting with the given ID, or the default one if not found.
165 	 */
166 	public CharacterFormattingInfo!Bitmap8Bit getChrFormatting(string ID) @safe nothrow {
167 		auto result = _chrFormat[ID];
168 		if (result !is null) return result;
169 		else return _chrFormat["default"];
170 	}
171 	/**
172 	 * Sets the given color to the supplied name to be recalled by element draw functions.
173 	 */
174 	public void setColor(ubyte c, string colorName) @safe nothrow {
175 		color[colorName] = c;
176 	}
177 	/**
178 	 * Returns the color that matches the name, or 0 if not found.
179 	 */
180 	public ubyte getColor(string colorName) @safe nothrow {
181 		return color[colorName];
182 	}
183 	/**
184 	 * Sets the image of the given name.
185 	 */
186 	public void setImage(Bitmap8Bit bitmap, string name) @safe nothrow {
187 		images[name] = bitmap;
188 	}
189 	/**
190 	 * Returns the image that matches the name, or null if not found.
191 	 */
192 	public Bitmap8Bit getImage(string name) @safe nothrow {
193 		return images[name];
194 	}
195 }
196 
197 ///Stores a global, default stylesheet.
198 ///Must be initialized alongside with the GUI.
199 public static StyleSheet globalDefaultStyle;