/Scenes/UserInterfaces/Theme.cs
C# | 541 lines | 364 code | 54 blank | 123 comment | 19 complexity | 7ecced0ea8b9ec5bccbc35d4f6d0c565 MD5 | raw file
Possible License(s): Apache-2.0
- using System.IO;
- using Delta.ContentSystem;
- using Delta.Engine;
- using Delta.Engine.Dynamic;
- using Delta.Rendering.Basics.Fonts;
- using Delta.Scenes.UserInterfaces.Designs;
- using Delta.Utilities;
- using Delta.Utilities.Datatypes;
-
- namespace Delta.Scenes.UserInterfaces
- {
- /// <summary>
- /// The theme class which describes the general look for all UI controls
- /// as long as a UI controls won't override its design by itself.
- /// </summary>
- public class Theme : BaseTheme
- {
- #region Constants
- /// <summary>
- /// The current version of the implementation of this control class.
- /// </summary>
- private const int VersionNumber = 1;
- #endregion
-
- #region Current (Static)
- /// <summary>
- /// Current theme to be used by the currently active scene.
- /// </summary>
- public new static Theme Current
- {
- get
- {
- if (current != BaseTheme.Current)
- {
- current = BaseTheme.Current as Theme;
- } // if
-
- return current;
- } // get
- set
- {
- current = value;
- BaseTheme.Current = value;
- } // set
- }
- #endregion
-
- #region ImageDesign (Public)
- /// <summary>
- /// Image design
- /// </summary>
- public ControlDesign ImageDesign
- {
- get;
- set;
- }
- #endregion
-
- #region PanelDesign (Public)
- /// <summary>
- /// Panel design
- /// </summary>
- public ControlDesign PanelDesign
- {
- get;
- set;
- }
- #endregion
-
- #region LabelDesign (Public)
- /// <summary>
- /// Label design
- /// </summary>
- public TextControlDesign LabelDesign
- {
- get;
- set;
- }
- #endregion
-
- #region TextboxDesign (Public)
- /// <summary>
- /// Textbox design
- /// </summary>
- public TextControlDesign TextboxDesign
- {
- get;
- set;
- }
- #endregion
-
- #region ButtonDesign (Public)
- /// <summary>
- /// Button design
- /// </summary>
- public TextControlDesign ButtonDesign
- {
- get;
- set;
- }
- #endregion
-
- #region CheckboxDesign (Public)
- /// <summary>
- /// Checkbox design
- /// </summary>
- public CheckboxDesign CheckboxDesign
- {
- get;
- set;
- }
- #endregion
-
- #region RadioButtonDesign (Public)
- /// <summary>
- /// Radio button design
- /// </summary>
- public CheckboxDesign RadioButtonDesign
- {
- get;
- set;
- }
- #endregion
-
- #region SliderDesign (Public)
- /// <summary>
- /// Slider design
- /// </summary>
- public SliderDesign SliderDesign
- {
- get;
- set;
- }
- #endregion
-
- #region DropdownBoxDesign (Public)
- /// <summary>
- /// Dropdown box design
- /// </summary>
- public TODODropdownBoxDesign DropdownBoxDesign
- {
- get;
- set;
- }
- #endregion
-
- #region Private
-
- #region current (Private)
- /// <summary>
- /// Current
- /// </summary>
- private static Theme current;
- #endregion
-
- #endregion
-
- #region Constructors
- /// <summary>
- /// Create user interface style
- /// </summary>
- /// <param name="setThemeName">Name of the set theme.</param>
- public Theme(string setThemeName)
- : base(setThemeName)
- {
- }
- #endregion
-
- #region Save (Public)
- /// <summary>
- /// Save
- /// </summary>
- /// <param name="dataWriter">Data writer</param>
- public void Save(BinaryWriter dataWriter)
- {
- // At first we write the current version number of the class data format
- dataWriter.Write(VersionNumber);
-
- // then saving the properties
- DesignedResolution.Save(dataWriter);
-
- // Image design
- bool hasImageDesign = ImageDesign != null;
- dataWriter.Write(hasImageDesign);
- if (hasImageDesign)
- {
- Factory.Save(dataWriter, ImageDesign);
- } // if
-
- // Panel design
- bool hasPanelDesign = PanelDesign != null;
- dataWriter.Write(hasPanelDesign);
- if (hasPanelDesign)
- {
- Factory.Save(dataWriter, PanelDesign);
- } // if
-
- // Label design
- bool hasLabelDesign = LabelDesign != null;
- dataWriter.Write(hasLabelDesign);
- if (hasLabelDesign)
- {
- Factory.Save(dataWriter, LabelDesign);
- } // if
-
- // Text box design
- bool hasTextboxDesign = TextboxDesign != null;
- dataWriter.Write(hasTextboxDesign);
- if (hasTextboxDesign)
- {
- Factory.Save(dataWriter, TextboxDesign);
- } // if
-
- // Button design
- bool hasButtonDesign = ButtonDesign != null;
- dataWriter.Write(hasButtonDesign);
- if (hasButtonDesign)
- {
- Factory.Save(dataWriter, ButtonDesign);
- } // if
-
- // Check box design
- bool hasCheckboxDesign = CheckboxDesign != null;
- dataWriter.Write(hasCheckboxDesign);
- if (hasCheckboxDesign)
- {
- Factory.Save(dataWriter, CheckboxDesign);
- } // if
-
- // RadioButton design
- bool hasRadioButtonDesign = RadioButtonDesign != null;
- dataWriter.Write(hasRadioButtonDesign);
- if (hasRadioButtonDesign)
- {
- Factory.Save(dataWriter, RadioButtonDesign);
- } // if
-
- // Slider design
- bool hasSliderDesign = SliderDesign != null;
- dataWriter.Write(hasSliderDesign);
- if (hasSliderDesign)
- {
- Factory.Save(dataWriter, SliderDesign);
- } // if
-
- // Disabled until "DropdownBox" control is supported again
- //// DropdownBox design
- //bool hasDropdownBoxDesign = DropdownBoxDesign != null;
- //dataWriter.Write(hasDropdownBoxDesign);
- //if (hasDropdownBoxDesign)
- //{
- // Factory.Save(dataWriter, DropdownBoxDesign);
- //} // if
- }
- #endregion
-
- #region Load (Public)
- /// <summary>
- /// Load
- /// </summary>
- /// <param name="data">Data</param>
- public virtual void Load(Stream data)
- {
- using (BinaryReader dataReader = new BinaryReader(data))
- {
- // At first check which version of the data need to load now
- int version = dataReader.ReadInt32();
- switch (version)
- {
- // Version 1
- case VersionNumber:
- DesignedResolution = new Size(dataReader);
-
- // Image design
- bool hasImageDesign = dataReader.ReadBoolean();
- ImageDesign = hasImageDesign
- ? Factory.Load<ControlDesign>(dataReader)
- : null;
-
- // Panel design
- bool hasPanelDesign = dataReader.ReadBoolean();
- PanelDesign = hasPanelDesign
- ? Factory.Load<ControlDesign>(dataReader)
- : null;
-
- // Label design
- bool hasLabelDesign = dataReader.ReadBoolean();
- LabelDesign = hasLabelDesign
- ? Factory.Load<TextControlDesign>(dataReader)
- : null;
-
- // Text box design
- bool hasTextboxDesign = dataReader.ReadBoolean();
- TextboxDesign = hasTextboxDesign
- ? Factory.Load<TextControlDesign>(dataReader)
- : null;
-
- // Button design
- bool hasButtonDesign = dataReader.ReadBoolean();
- ButtonDesign = hasButtonDesign
- ? Factory.Load<TextControlDesign>(dataReader)
- : null;
-
- // Check box design
- bool hasCheckboxDesign = dataReader.ReadBoolean();
- CheckboxDesign = hasCheckboxDesign
- ? Factory.Load<CheckboxDesign>(dataReader)
- : null;
-
- // RadioButton design
- bool hasRadioButtonDesign = dataReader.ReadBoolean();
- RadioButtonDesign = hasRadioButtonDesign
- ? Factory.Load<CheckboxDesign>(dataReader)
- : null;
-
- // Slider design
- bool hasSliderDesign = dataReader.ReadBoolean();
- SliderDesign = hasSliderDesign
- ? Factory.Load<SliderDesign>(dataReader)
- : null;
-
- // Disabled until "DropdownBox" control is supported again
- //// DropdownBox design
- //bool hasDropdownBoxDesign = dataReader.ReadBoolean();
- //if (hasDropdownBoxDesign)
- //{
- // DropdownBoxDesign = Factory.Load<DropdownBoxDesign>(dataReader);
- //} // if
- //else
- //{
- // DropdownBoxDesign = null;
- //} // else
- break;
-
- default:
- Log.InvalidVersionWarning(GetType().Name, version, VersionNumber);
- break;
- } // switch
- }
- }
- #endregion
-
- #region Methods (Private)
-
- #region LoadDefaultDesign
- /// <summary>
- /// Loads all designs of the default look for this theme.
- /// </summary>
- protected override void LoadDefaultDesign()
- {
- #region Image design
- ControlDesign defautImageDesign = new ControlDesign
- {
- Background = GetUIMaterial(EmptyName),
- DisabledBackground = GetUIMaterial(EmptyName,
- DefaultDisabledBlendColor),
- };
- #endregion
-
- #region Panel design
- ControlDesign defaultPanelDesign = new ControlDesign
- {
- // Empty theme...
- };
- #endregion
-
- #region Label design
- TextControlDesign defaultLabelDesign = new TextControlDesign
- {
- Background = null,
- Hover = null,
- TextFont = new Font(Font.Default, DefaultTextColor),
- TextBackground = GetUIMaterial("DefaultLabel"),
- TextHoverBackground = GetUIMaterial("DefaultLabel",
- DefaultHoverColor),
- DisabledBackground = null,
- DisabledTextFont = new Font(Font.Default, DefaultDisabledBlendColor),
- DisabledTextBackground = GetUIMaterial("DefaultLabel",
- DefaultDisabledBlendColor),
- };
- #endregion
-
- #region Textbox design
- TextControlDesign defaultTextboxDesgin = new TextControlDesign
- {
- Background = null,
- Hover = null,
- TextFont = new Font(Font.Default, DefaultTextColor),
- TextBackground = GetUIMaterial("DefaultLabel"),
- TextHoverBackground = GetUIMaterial("DefaultLabel",
- DefaultHoverColor),
- DisabledBackground = null,
- DisabledTextFont = new Font(Font.Default, DefaultDisabledBlendColor),
- DisabledTextBackground = GetUIMaterial("DefaultLabel",
- DefaultDisabledBlendColor),
- };
- #endregion
-
- #region Button design
- TextControlDesign defaultButtonDesign = new TextControlDesign
- {
- Background = GetUIMaterial("DefaultButtonBackground"),
- Hover = GetUIMaterial("DefaultButtonHover", DefaultHoverColor),
- TextFont = new Font(Font.Default, DefaultTextColor),
- Pressed = GetUIMaterial("DefaultButtonPressed", DefaultHoverColor),
- TextBackground = null,
- TextHoverBackground = null,
- DisabledBackground = GetUIMaterial("DefaultButtonBackground",
- DefaultDisabledBlendColor),
- DisabledTextFont = new Font(Font.Default, DefaultDisabledBlendColor),
- DisabledTextBackground = null,
- };
- #endregion
-
- #region Checkbox design
- CheckboxDesign defaultCheckboxDesign = new CheckboxDesign
- {
- // We don't use a "global" background (and hover design) here...
- //PressedDesign = null;
-
- Background = null,
- Hover = null,
- TextFont = new Font(Font.Default, DefaultTextColor),
- TextBackground = GetUIMaterial("DefaultLabel"),
- TextHoverBackground = GetUIMaterial("DefaultLabel",
- DefaultHoverColor),
- UncheckedSymbol = GetUIMaterial("DefaultCheckboxOff"),
- UncheckedSymbolHover = GetUIMaterial("DefaultCheckboxOff",
- Color.Gold),
- CheckedSymbol = GetUIMaterial("DefaultCheckboxOn"),
- CheckedSymbolHover = GetUIMaterial("DefaultCheckboxOn",
- DefaultHoverColor),
- DisabledBackground = null,
- DisabledTextFont = new Font(Font.Default, DefaultDisabledBlendColor),
- DisabledTextBackground = GetUIMaterial("DefaultLabel",
- DefaultDisabledBlendColor),
- DisabledUncheckedSymbol = GetUIMaterial("DefaultCheckboxOff",
- DefaultDisabledBlendColor),
- DisabledCheckedSymbol = GetUIMaterial("DefaultCheckboxOn",
- DefaultDisabledBlendColor),
- };
- #endregion
-
- #region RadioButton design
- CheckboxDesign defaultRadioButtonDesign = new CheckboxDesign
- {
- // We don't use a "global" background (and hover design) here...
- //PressedDesign = null;
- Background = null,
- Hover = null,
- TextFont = new Font(Font.Default, DefaultTextColor),
- TextBackground = GetUIMaterial("DefaultLabel"),
- TextHoverBackground = GetUIMaterial("DefaultLabel",
- DefaultHoverColor),
- UncheckedSymbol = GetUIMaterial("DefaultRadiobuttonOff"),
- CheckedSymbol = GetUIMaterial("DefaultRadioButtonOn"),
- DisabledBackground = null,
- DisabledTextFont = new Font(Font.Default, DefaultDisabledBlendColor),
- DisabledTextBackground = GetUIMaterial("DefaultLabel",
- DefaultDisabledBlendColor),
- DisabledUncheckedSymbol = GetUIMaterial("DefaultRadiobuttonOff",
- DefaultDisabledBlendColor),
- DisabledCheckedSymbol = GetUIMaterial("DefaultRadioButtonOn",
- DefaultDisabledBlendColor),
- };
- #endregion
-
- #region Slider design
- SliderDesign defaultSliderDesign = new SliderDesign
- {
- // Finally we normally don't need a background, because we have
- // the "TrackerbarDesign" instead for it (for the moment)
- Trackerbar = GetUIMaterial("DefaultSliderBackground"),
- Tracker = GetUIMaterial("DefaultSlider"),
- Hover = GetUIMaterial("DefaultSliderHover"),
- TextFont = new Font(Font.Default, DefaultTextColor),
- DisabledTrackerbar = GetUIMaterial("DefaultSliderBackground",
- DefaultDisabledBlendColor),
- DisabledTracker = GetUIMaterial("DefaultSlider",
- DefaultDisabledBlendColor),
- DisabledTextFont = new Font(Font.Default, DefaultDisabledBlendColor),
- };
- #endregion
-
-
- #region DropdownBox design
- TODODropdownBoxDesign defaultDropdownBoxDesign = new TODODropdownBoxDesign
- {
- // Finally we normally don't need a background, because we have
- // the "TrackerbarDesign" instead for it (for the moment)
- Expander = GetUIMaterial("DefaultDropDownBox"),
- ExpanderHover = GetUIMaterial("DefaultDropDownBox"),
- DisabledExpander = GetUIMaterial("DefaultDropDownBox",
- DefaultDisabledBlendColor),
- };
- #endregion
-
- //defaultTheme = new UserTheme("<DefaultTheme>")
- //{
- // DesignedResolution = Settings.DefaultResolution,
- // ImageDesign = defautImageDesign,
- // PanelDesign = defaultPanelDesign,
- // LabelDesign = defaultLabelDesign,
- // TextboxDesign = defaultTextboxDesgin,
- // ButtonDesign = defaultButtonDesign,
- // CheckboxDesign = defaultCheckboxDesign,
- // RadioButtonDesign = defaultRadioButtonDesign,
- // SliderDesign = defaultSliderDesign,
- // DropdownBoxDesign = defaultDropdownBoxDesign,
- //};
-
- DesignedResolution = Settings.DefaultResolution;
- ImageDesign = defautImageDesign;
- PanelDesign = defaultPanelDesign;
- LabelDesign = defaultLabelDesign;
- TextboxDesign = defaultTextboxDesgin;
- ButtonDesign = defaultButtonDesign;
- CheckboxDesign = defaultCheckboxDesign;
- RadioButtonDesign = defaultRadioButtonDesign;
- SliderDesign = defaultSliderDesign;
- DropdownBoxDesign = defaultDropdownBoxDesign;
- }
- #endregion
-
- #region Load
- /// <summary>
- /// Load
- /// </summary>
- /// <param name="alreadyLoadedNativeData">Already loaded native data
- /// </param>
- protected override void Load(Content alreadyLoadedNativeData)
- {
- // be done later
- //throw new NotImplementedException();
- return;
- }
- #endregion
-
- #endregion
- }
- }