PageRenderTime 268ms CodeModel.GetById 120ms app.highlight 20ms RepoModel.GetById 121ms app.codeStats 0ms

/Scenes/UserInterfaces/Theme.cs

#
C# | 541 lines | 364 code | 54 blank | 123 comment | 19 complexity | 7ecced0ea8b9ec5bccbc35d4f6d0c565 MD5 | raw file
  1using System.IO;
  2using Delta.ContentSystem;
  3using Delta.Engine;
  4using Delta.Engine.Dynamic;
  5using Delta.Rendering.Basics.Fonts;
  6using Delta.Scenes.UserInterfaces.Designs;
  7using Delta.Utilities;
  8using Delta.Utilities.Datatypes;
  9
 10namespace Delta.Scenes.UserInterfaces
 11{
 12	/// <summary>
 13	/// The theme class which describes the general look for all UI controls
 14	/// as long as a UI controls won't override its design by itself.
 15	/// </summary>
 16	public class Theme : BaseTheme
 17	{
 18		#region Constants
 19		/// <summary>
 20		/// The current version of the implementation of this control class.
 21		/// </summary>
 22		private const int VersionNumber = 1;
 23		#endregion
 24
 25		#region Current (Static)
 26		/// <summary>
 27		/// Current theme to be used by the currently active scene.
 28		/// </summary>
 29		public new static Theme Current
 30		{
 31			get
 32			{
 33				if (current != BaseTheme.Current)
 34				{
 35					current = BaseTheme.Current as Theme;
 36				} // if
 37
 38				return current;
 39			} // get
 40			set
 41			{
 42				current = value;
 43				BaseTheme.Current = value;
 44			} // set
 45		}
 46		#endregion
 47
 48		#region ImageDesign (Public)
 49		/// <summary>
 50		/// Image design
 51		/// </summary>
 52		public ControlDesign ImageDesign
 53		{
 54			get;
 55			set;
 56		}
 57		#endregion
 58
 59		#region PanelDesign (Public)
 60		/// <summary>
 61		/// Panel design
 62		/// </summary>
 63		public ControlDesign PanelDesign
 64		{
 65			get;
 66			set;
 67		}
 68		#endregion
 69
 70		#region LabelDesign (Public)
 71		/// <summary>
 72		/// Label design
 73		/// </summary>
 74		public TextControlDesign LabelDesign
 75		{
 76			get;
 77			set;
 78		}
 79		#endregion
 80
 81		#region TextboxDesign (Public)
 82		/// <summary>
 83		/// Textbox design
 84		/// </summary>
 85		public TextControlDesign TextboxDesign
 86		{
 87			get;
 88			set;
 89		}
 90		#endregion
 91
 92		#region ButtonDesign (Public)
 93		/// <summary>
 94		/// Button design
 95		/// </summary>
 96		public TextControlDesign ButtonDesign
 97		{
 98			get;
 99			set;
100		}
101		#endregion
102
103		#region CheckboxDesign (Public)
104		/// <summary>
105		/// Checkbox design
106		/// </summary>
107		public CheckboxDesign CheckboxDesign
108		{
109			get;
110			set;
111		}
112		#endregion
113
114		#region RadioButtonDesign (Public)
115		/// <summary>
116		/// Radio button design
117		/// </summary>
118		public CheckboxDesign RadioButtonDesign
119		{
120			get;
121			set;
122		}
123		#endregion
124
125		#region SliderDesign (Public)
126		/// <summary>
127		/// Slider design
128		/// </summary>
129		public SliderDesign SliderDesign
130		{
131			get;
132			set;
133		}
134		#endregion
135
136		#region DropdownBoxDesign (Public)
137		/// <summary>
138		/// Dropdown box design
139		/// </summary>
140		public TODODropdownBoxDesign DropdownBoxDesign
141		{
142			get;
143			set;
144		}
145		#endregion
146
147		#region Private
148
149		#region current (Private)
150		/// <summary>
151		/// Current
152		/// </summary>
153		private static Theme current;
154		#endregion
155
156		#endregion
157
158		#region Constructors
159		/// <summary>
160		/// Create user interface style
161		/// </summary>
162		/// <param name="setThemeName">Name of the set theme.</param>
163		public Theme(string setThemeName)
164			: base(setThemeName)
165		{
166		}
167		#endregion
168
169		#region Save (Public)
170		/// <summary>
171		/// Save
172		/// </summary>
173		/// <param name="dataWriter">Data writer</param>
174		public void Save(BinaryWriter dataWriter)
175		{
176			// At first we write the current version number of the class data format
177			dataWriter.Write(VersionNumber);
178
179			// then saving the properties
180			DesignedResolution.Save(dataWriter);
181
182			// Image design
183			bool hasImageDesign = ImageDesign != null;
184			dataWriter.Write(hasImageDesign);
185			if (hasImageDesign)
186			{
187				Factory.Save(dataWriter, ImageDesign);
188			} // if
189
190			// Panel design
191			bool hasPanelDesign = PanelDesign != null;
192			dataWriter.Write(hasPanelDesign);
193			if (hasPanelDesign)
194			{
195				Factory.Save(dataWriter, PanelDesign);
196			} // if
197
198			// Label design
199			bool hasLabelDesign = LabelDesign != null;
200			dataWriter.Write(hasLabelDesign);
201			if (hasLabelDesign)
202			{
203				Factory.Save(dataWriter, LabelDesign);
204			} // if
205
206			// Text box design
207			bool hasTextboxDesign = TextboxDesign != null;
208			dataWriter.Write(hasTextboxDesign);
209			if (hasTextboxDesign)
210			{
211				Factory.Save(dataWriter, TextboxDesign);
212			} // if
213
214			// Button design
215			bool hasButtonDesign = ButtonDesign != null;
216			dataWriter.Write(hasButtonDesign);
217			if (hasButtonDesign)
218			{
219				Factory.Save(dataWriter, ButtonDesign);
220			} // if
221
222			// Check box design
223			bool hasCheckboxDesign = CheckboxDesign != null;
224			dataWriter.Write(hasCheckboxDesign);
225			if (hasCheckboxDesign)
226			{
227				Factory.Save(dataWriter, CheckboxDesign);
228			} // if
229
230			// RadioButton design
231			bool hasRadioButtonDesign = RadioButtonDesign != null;
232			dataWriter.Write(hasRadioButtonDesign);
233			if (hasRadioButtonDesign)
234			{
235				Factory.Save(dataWriter, RadioButtonDesign);
236			} // if
237
238			// Slider design
239			bool hasSliderDesign = SliderDesign != null;
240			dataWriter.Write(hasSliderDesign);
241			if (hasSliderDesign)
242			{
243				Factory.Save(dataWriter, SliderDesign);
244			} // if
245
246			// Disabled until "DropdownBox" control is supported again
247			//// DropdownBox design
248			//bool hasDropdownBoxDesign = DropdownBoxDesign != null;
249			//dataWriter.Write(hasDropdownBoxDesign);
250			//if (hasDropdownBoxDesign)
251			//{
252			//  Factory.Save(dataWriter, DropdownBoxDesign);
253			//} // if
254		}
255		#endregion
256
257		#region Load (Public)
258		/// <summary>
259		/// Load
260		/// </summary>
261		/// <param name="data">Data</param>
262		public virtual void Load(Stream data)
263		{
264			using (BinaryReader dataReader = new BinaryReader(data))
265			{
266				// At first check which version of the data need to load now
267				int version = dataReader.ReadInt32();
268				switch (version)
269				{
270					// Version 1
271					case VersionNumber:
272						DesignedResolution = new Size(dataReader);
273
274						// Image design
275						bool hasImageDesign = dataReader.ReadBoolean();
276						ImageDesign = hasImageDesign
277														? Factory.Load<ControlDesign>(dataReader)
278														: null;
279
280						// Panel design
281						bool hasPanelDesign = dataReader.ReadBoolean();
282						PanelDesign = hasPanelDesign
283														? Factory.Load<ControlDesign>(dataReader)
284														: null;
285
286						// Label design
287						bool hasLabelDesign = dataReader.ReadBoolean();
288						LabelDesign = hasLabelDesign
289														? Factory.Load<TextControlDesign>(dataReader)
290														: null;
291
292						// Text box design
293						bool hasTextboxDesign = dataReader.ReadBoolean();
294						TextboxDesign = hasTextboxDesign
295															? Factory.Load<TextControlDesign>(dataReader)
296															: null;
297
298						// Button design
299						bool hasButtonDesign = dataReader.ReadBoolean();
300						ButtonDesign = hasButtonDesign
301														? Factory.Load<TextControlDesign>(dataReader)
302														: null;
303
304						// Check box design
305						bool hasCheckboxDesign = dataReader.ReadBoolean();
306						CheckboxDesign = hasCheckboxDesign
307															? Factory.Load<CheckboxDesign>(dataReader)
308															: null;
309
310						// RadioButton design
311						bool hasRadioButtonDesign = dataReader.ReadBoolean();
312						RadioButtonDesign = hasRadioButtonDesign
313																	? Factory.Load<CheckboxDesign>(dataReader)
314																	: null;
315
316						// Slider design
317						bool hasSliderDesign = dataReader.ReadBoolean();
318						SliderDesign = hasSliderDesign
319														? Factory.Load<SliderDesign>(dataReader)
320														: null;
321
322						// Disabled until "DropdownBox" control is supported again
323						//// DropdownBox design
324						//bool hasDropdownBoxDesign = dataReader.ReadBoolean();
325						//if (hasDropdownBoxDesign)
326						//{
327						//  DropdownBoxDesign = Factory.Load<DropdownBoxDesign>(dataReader);
328						//} // if
329						//else
330						//{
331						//  DropdownBoxDesign = null;
332						//} // else
333						break;
334
335					default:
336						Log.InvalidVersionWarning(GetType().Name, version, VersionNumber);
337						break;
338				} // switch
339			}
340		}
341		#endregion
342
343		#region Methods (Private)
344
345		#region LoadDefaultDesign
346		/// <summary>
347		/// Loads all designs of the default look for this theme.
348		/// </summary>
349		protected override void LoadDefaultDesign()
350		{
351			#region Image design
352			ControlDesign defautImageDesign = new ControlDesign
353			{
354				Background = GetUIMaterial(EmptyName),
355				DisabledBackground = GetUIMaterial(EmptyName,
356					DefaultDisabledBlendColor),
357			};
358			#endregion
359
360			#region Panel design
361			ControlDesign defaultPanelDesign = new ControlDesign
362			{
363				// Empty theme...
364			};
365			#endregion
366
367			#region Label design
368			TextControlDesign defaultLabelDesign = new TextControlDesign
369			{
370				Background = null,
371				Hover = null,
372				TextFont = new Font(Font.Default, DefaultTextColor),
373				TextBackground = GetUIMaterial("DefaultLabel"),
374				TextHoverBackground = GetUIMaterial("DefaultLabel",
375					DefaultHoverColor),
376				DisabledBackground = null,
377				DisabledTextFont = new Font(Font.Default, DefaultDisabledBlendColor),
378				DisabledTextBackground = GetUIMaterial("DefaultLabel",
379					DefaultDisabledBlendColor),
380			};
381			#endregion
382
383			#region Textbox design
384			TextControlDesign defaultTextboxDesgin = new TextControlDesign
385			{
386				Background = null,
387				Hover = null,
388				TextFont = new Font(Font.Default, DefaultTextColor),
389				TextBackground = GetUIMaterial("DefaultLabel"),
390				TextHoverBackground = GetUIMaterial("DefaultLabel",
391					DefaultHoverColor),
392				DisabledBackground = null,
393				DisabledTextFont = new Font(Font.Default, DefaultDisabledBlendColor),
394				DisabledTextBackground = GetUIMaterial("DefaultLabel",
395					DefaultDisabledBlendColor),
396			};
397			#endregion
398
399			#region Button design
400			TextControlDesign defaultButtonDesign = new TextControlDesign
401			{
402				Background = GetUIMaterial("DefaultButtonBackground"),
403				Hover = GetUIMaterial("DefaultButtonHover", DefaultHoverColor),
404				TextFont = new Font(Font.Default, DefaultTextColor),
405				Pressed = GetUIMaterial("DefaultButtonPressed", DefaultHoverColor),
406				TextBackground = null,
407				TextHoverBackground = null,
408				DisabledBackground = GetUIMaterial("DefaultButtonBackground",
409					DefaultDisabledBlendColor),
410				DisabledTextFont = new Font(Font.Default, DefaultDisabledBlendColor),
411				DisabledTextBackground = null,
412			};
413			#endregion
414
415			#region Checkbox design
416			CheckboxDesign defaultCheckboxDesign = new CheckboxDesign
417			{
418				// We don't use a "global" background (and hover design) here...
419				//PressedDesign = null;
420
421				Background = null,
422				Hover = null,
423				TextFont = new Font(Font.Default, DefaultTextColor),
424				TextBackground = GetUIMaterial("DefaultLabel"),
425				TextHoverBackground = GetUIMaterial("DefaultLabel",
426					DefaultHoverColor),
427				UncheckedSymbol = GetUIMaterial("DefaultCheckboxOff"),
428				UncheckedSymbolHover = GetUIMaterial("DefaultCheckboxOff",
429					Color.Gold),
430				CheckedSymbol = GetUIMaterial("DefaultCheckboxOn"),
431				CheckedSymbolHover = GetUIMaterial("DefaultCheckboxOn",
432					DefaultHoverColor),
433				DisabledBackground = null,
434				DisabledTextFont = new Font(Font.Default, DefaultDisabledBlendColor),
435				DisabledTextBackground = GetUIMaterial("DefaultLabel",
436					DefaultDisabledBlendColor),
437				DisabledUncheckedSymbol = GetUIMaterial("DefaultCheckboxOff",
438					DefaultDisabledBlendColor),
439				DisabledCheckedSymbol = GetUIMaterial("DefaultCheckboxOn",
440					DefaultDisabledBlendColor),
441			};
442			#endregion
443
444			#region RadioButton design
445			CheckboxDesign defaultRadioButtonDesign = new CheckboxDesign
446			{
447				// We don't use a "global" background (and hover design) here...
448				//PressedDesign = null;
449				Background = null,
450				Hover = null,
451				TextFont = new Font(Font.Default, DefaultTextColor),
452				TextBackground = GetUIMaterial("DefaultLabel"),
453				TextHoverBackground = GetUIMaterial("DefaultLabel",
454					DefaultHoverColor),
455				UncheckedSymbol = GetUIMaterial("DefaultRadiobuttonOff"),
456				CheckedSymbol = GetUIMaterial("DefaultRadioButtonOn"),
457				DisabledBackground = null,
458				DisabledTextFont = new Font(Font.Default, DefaultDisabledBlendColor),
459				DisabledTextBackground = GetUIMaterial("DefaultLabel",
460					DefaultDisabledBlendColor),
461				DisabledUncheckedSymbol = GetUIMaterial("DefaultRadiobuttonOff",
462					DefaultDisabledBlendColor),
463				DisabledCheckedSymbol = GetUIMaterial("DefaultRadioButtonOn",
464					DefaultDisabledBlendColor),
465			};
466			#endregion
467
468			#region Slider design
469			SliderDesign defaultSliderDesign = new SliderDesign
470			{
471				// Finally we normally don't need a background, because we have
472				// the "TrackerbarDesign" instead for it (for the moment)
473				Trackerbar = GetUIMaterial("DefaultSliderBackground"),
474				Tracker = GetUIMaterial("DefaultSlider"),
475				Hover = GetUIMaterial("DefaultSliderHover"),
476				TextFont = new Font(Font.Default, DefaultTextColor),
477				DisabledTrackerbar = GetUIMaterial("DefaultSliderBackground",
478					DefaultDisabledBlendColor),
479				DisabledTracker = GetUIMaterial("DefaultSlider",
480					DefaultDisabledBlendColor),
481				DisabledTextFont = new Font(Font.Default, DefaultDisabledBlendColor),
482			};
483			#endregion
484
485
486			#region DropdownBox design
487			TODODropdownBoxDesign defaultDropdownBoxDesign = new TODODropdownBoxDesign
488			{
489				// Finally we normally don't need a background, because we have
490				// the "TrackerbarDesign" instead for it (for the moment)
491				Expander = GetUIMaterial("DefaultDropDownBox"),
492				ExpanderHover = GetUIMaterial("DefaultDropDownBox"),
493				DisabledExpander = GetUIMaterial("DefaultDropDownBox",
494					DefaultDisabledBlendColor),
495			};
496			#endregion
497
498			//defaultTheme = new UserTheme("<DefaultTheme>")
499			//{
500			//  DesignedResolution = Settings.DefaultResolution,
501			//  ImageDesign = defautImageDesign,
502			//  PanelDesign = defaultPanelDesign,
503			//  LabelDesign = defaultLabelDesign,
504			//  TextboxDesign = defaultTextboxDesgin,
505			//  ButtonDesign = defaultButtonDesign,
506			//  CheckboxDesign = defaultCheckboxDesign,
507			//  RadioButtonDesign = defaultRadioButtonDesign,
508			//  SliderDesign = defaultSliderDesign,
509			//  DropdownBoxDesign = defaultDropdownBoxDesign,
510			//};
511
512			DesignedResolution = Settings.DefaultResolution;
513			ImageDesign = defautImageDesign;
514			PanelDesign = defaultPanelDesign;
515			LabelDesign = defaultLabelDesign;
516			TextboxDesign = defaultTextboxDesgin;
517			ButtonDesign = defaultButtonDesign;
518			CheckboxDesign = defaultCheckboxDesign;
519			RadioButtonDesign = defaultRadioButtonDesign;
520			SliderDesign = defaultSliderDesign;
521			DropdownBoxDesign = defaultDropdownBoxDesign;
522		}
523		#endregion
524
525		#region Load
526		/// <summary>
527		/// Load
528		/// </summary>
529		/// <param name="alreadyLoadedNativeData">Already loaded native data
530		/// </param>
531		protected override void Load(Content alreadyLoadedNativeData)
532		{
533			// be done later
534			//throw new NotImplementedException();
535			return;
536		}
537		#endregion
538
539		#endregion
540	}
541}