#region license // This file is part of Vocaluxe. // // Vocaluxe is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Vocaluxe is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Vocaluxe. If not, see . #endregion using System; using System.Collections.Generic; using System.Drawing; using System.Xml; using System.Xml.Serialization; using VocaluxeLib.Draw; namespace VocaluxeLib.Menu { [XmlType("SelectSlide")] public struct SThemeSelectSlide { [XmlAttributeAttribute(AttributeName = "Name")] public string Name; [XmlElement("Skin")] public string TextureName; [XmlElement("SkinArrowLeft")] public string TextureArrowLeftName; [XmlElement("SkinArrowRight")] public string TextureArrowRightName; [XmlElement("SkinSelected")] public string SelTextureName; [XmlElement("SkinArrowLeftSelected")] public string SelTextureArrowLeftName; [XmlElement("SkinArrowRightSelected")] public string SelTextureArrowRightName; [XmlElement("SkinHighlighted")] public string HighlightTextureName; [XmlElement("Rect")] public SRectF Rect; [XmlElement("RectArrowLeft")] public SRectF RectArrowLeft; [XmlElement("RectArrowRight")] public SRectF RectArrowRight; [XmlElement("Color")] public SThemeColor Color; [XmlElement("SColor")] public SThemeColor SColor; [XmlElement("HColor")] public SThemeColor HColor; [XmlElement("ArrowColor")] public SThemeColor ArrowColor; [XmlElement("ArrowSColor")] public SThemeColor ArrowSColor; [XmlElement("TextColor")] public SThemeColor TextColor; [XmlElement("TextSColor")] public SThemeColor TextSColor; [XmlElement("TextH")] public float TextH; [XmlElement("TextRelativeX")] public float TextRelativeX; [XmlElement("TextRelativeY")] public float TextRelativeY; [XmlElement("TextMaxW")] public float TextMaxW; [XmlElement("TextFont")] public string TextFont; [XmlElement("TextStyle")] public EStyle TextStyle; [XmlElement("NumVisible")] public int NumVisible; public SThemeSelectSlide(SThemeSelectSlide theme) { Name = theme.Name; TextureName = theme.TextureName; TextureArrowLeftName = theme.TextureArrowLeftName; TextureArrowRightName = theme.TextureArrowRightName; SelTextureName = theme.SelTextureName; SelTextureArrowLeftName = theme.SelTextureArrowLeftName; SelTextureArrowRightName = theme.SelTextureArrowRightName; HighlightTextureName = theme.HighlightTextureName; Rect = new SRectF(theme.Rect); RectArrowLeft = new SRectF(theme.RectArrowLeft); RectArrowRight = new SRectF(theme.RectArrowRight); Color = new SThemeColor(theme.Color); SColor = new SThemeColor(theme.SColor); HColor = new SThemeColor(theme.HColor); ArrowColor = new SThemeColor(theme.ArrowColor); ArrowSColor = new SThemeColor(theme.ArrowSColor); TextColor = new SThemeColor(theme.TextColor); TextSColor = new SThemeColor(theme.TextSColor); TextH = theme.TextH; TextRelativeX = theme.TextRelativeX; TextRelativeY = theme.TextRelativeY; TextMaxW = theme.TextMaxW; TextFont = theme.TextFont; TextStyle = theme.TextStyle; NumVisible = theme.NumVisible; } } public class CSelectSlide : IMenuElement, ICloneable { private readonly int _PartyModeID; private SThemeSelectSlide _Theme; private bool _ThemeLoaded; public string GetThemeName() { return _Theme.Name; } public bool ThemeLoaded { get { return _ThemeLoaded; } } public SRectF Rect; public SRectF RectArrowLeft; public SRectF RectArrowRight; public SColorF Color; public SColorF SelColor; public SColorF HighlightColor; public SColorF ColorArrow; public SColorF SelColorArrow; public SColorF TextColor; public SColorF SelTextColor; public float TextRelativeX; public float TextRelativeY; public float TextH; public float MaxW; private bool _Selected; public bool Selected { get { return _Selected; } set { _Selected = value; if (!value) { _ArrowLeftSelected = false; _ArrowRightSelected = false; } } } public bool ValueSelected { get { return _Selected && !_ArrowLeftSelected && !_ArrowRightSelected; } } public bool Visible = true; public bool Highlighted; public bool SelectionByHover; private bool _ArrowLeftSelected; private bool _ArrowRightSelected; private readonly List _ValueNames; private readonly List _ValuePartyModeIDs; private readonly List _Textures; private readonly List _ValueIndexes; private readonly List _ValueBounds = new List(); public bool WithTextures; private int _Selection = -1; public int Selection { get { return _Selection; } set { if (value >= 0 && value < _ValueNames.Count) _Selection = value; } } public int ValueIndex { get { if (_Selection >= 0 && _ValueIndexes.Count > _Selection) return _ValueIndexes[_Selection]; return -1; } } public int NumValues { get { return _ValueNames.Count; } } private int _NumVisible = -1; public int NumVisible { get { return _NumVisible; } set { if (value > 0) _NumVisible = value; _ValueBounds.Clear(); } } public CSelectSlide(int partyModeID) { _PartyModeID = partyModeID; _Theme = new SThemeSelectSlide(); _ThemeLoaded = false; Rect = new SRectF(); RectArrowLeft = new SRectF(); RectArrowRight = new SRectF(); Color = new SColorF(); SelColor = new SColorF(); ColorArrow = new SColorF(); SelColorArrow = new SColorF(); TextColor = new SColorF(); SelTextColor = new SColorF(); TextH = 1f; MaxW = 0f; _Selected = false; _Textures = new List(); _ValueIndexes = new List(); _ValueNames = new List(); _ValuePartyModeIDs = new List(); } public CSelectSlide(CSelectSlide slide) { _PartyModeID = slide._PartyModeID; _Theme = new SThemeSelectSlide { TextureArrowLeftName = slide._Theme.TextureArrowLeftName, TextureArrowRightName = slide._Theme.TextureArrowRightName, Color = slide._Theme.Color, SColor = slide._Theme.SColor, HColor = slide._Theme.HColor, ArrowColor = slide._Theme.ArrowColor, ArrowSColor = slide._Theme.ArrowSColor, TextColor = slide._Theme.TextColor, TextSColor = slide._Theme.TextSColor, SelTextureName = slide._Theme.SelTextureName, SelTextureArrowLeftName = slide._Theme.SelTextureArrowLeftName, SelTextureArrowRightName = slide._Theme.SelTextureArrowRightName, HighlightTextureName = slide._Theme.HighlightTextureName, TextFont = slide._Theme.TextFont, TextStyle = slide._Theme.TextStyle }; _ThemeLoaded = false; Rect = new SRectF(slide.Rect); RectArrowLeft = new SRectF(slide.RectArrowLeft); RectArrowRight = new SRectF(slide.RectArrowRight); Color = new SColorF(slide.Color); SelColor = new SColorF(slide.SelColor); ColorArrow = new SColorF(slide.ColorArrow); SelColorArrow = new SColorF(slide.SelColorArrow); TextColor = new SColorF(slide.TextColor); SelTextColor = new SColorF(slide.SelTextColor); TextH = slide.TextH; TextRelativeX = slide.TextRelativeX; TextRelativeY = slide.TextRelativeY; MaxW = slide.MaxW; _Selected = slide._Selected; _Textures = new List(slide._Textures); _ValueIndexes = new List(slide._ValueIndexes); _ValueNames = new List(slide._ValueNames); _ValueBounds = new List(slide._ValueBounds); _ValuePartyModeIDs = new List(slide._ValuePartyModeIDs); _Selection = slide._Selection; _NumVisible = slide._NumVisible; WithTextures = slide.WithTextures; Visible = slide.Visible; } public CSelectSlide(SThemeSelectSlide theme, int partyModeID) { _PartyModeID = partyModeID; _Theme = new SThemeSelectSlide(theme); _Selected = false; _Textures = new List(); _ValueIndexes = new List(); _ValueNames = new List(); _ValuePartyModeIDs = new List(); LoadTextures(); } public bool LoadTheme(string xmlPath, string elementName, CXMLReader xmlReader, int skinIndex) { string item = xmlPath + "/" + elementName; _ThemeLoaded = true; _ThemeLoaded &= xmlReader.GetValue(item + "/Skin", out _Theme.TextureName, String.Empty); _ThemeLoaded &= xmlReader.GetValue(item + "/SkinArrowLeft", out _Theme.TextureArrowLeftName, String.Empty); _ThemeLoaded &= xmlReader.GetValue(item + "/SkinArrowRight", out _Theme.TextureArrowRightName, String.Empty); _ThemeLoaded &= xmlReader.GetValue(item + "/SkinSelected", out _Theme.SelTextureName, String.Empty); _ThemeLoaded &= xmlReader.GetValue(item + "/SkinArrowLeftSelected", out _Theme.SelTextureArrowLeftName, String.Empty); _ThemeLoaded &= xmlReader.GetValue(item + "/SkinArrowRightSelected", out _Theme.SelTextureArrowRightName, String.Empty); _ThemeLoaded &= xmlReader.GetValue(item + "/SkinHighlighted", out _Theme.HighlightTextureName, String.Empty); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/X", ref Rect.X); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/Y", ref Rect.Y); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/Z", ref Rect.Z); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/W", ref Rect.W); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/H", ref Rect.H); if (xmlReader.GetValue(item + "/Color", out _Theme.Color.Name, String.Empty)) _ThemeLoaded &= CBase.Theme.GetColor(_Theme.Color.Name, skinIndex, out Color); else { _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/R", ref Color.R); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/G", ref Color.G); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/B", ref Color.B); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/A", ref Color.A); } if (xmlReader.GetValue(item + "/SColor", out _Theme.SColor.Name, String.Empty)) _ThemeLoaded &= CBase.Theme.GetColor(_Theme.SColor.Name, skinIndex, out SelColor); else { _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/SR", ref SelColor.R); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/SG", ref SelColor.G); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/SB", ref SelColor.B); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/SA", ref SelColor.A); } if (xmlReader.GetValue(item + "/HColor", out _Theme.HColor.Name, String.Empty)) _ThemeLoaded &= CBase.Theme.GetColor(_Theme.HColor.Name, skinIndex, out HighlightColor); else { _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/HR", ref HighlightColor.R); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/HG", ref HighlightColor.G); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/HB", ref HighlightColor.B); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/HA", ref HighlightColor.A); } _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/ArrowLeftX", ref RectArrowLeft.X); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/ArrowLeftY", ref RectArrowLeft.Y); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/ArrowLeftZ", ref RectArrowLeft.Z); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/ArrowLeftW", ref RectArrowLeft.W); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/ArrowLeftH", ref RectArrowLeft.H); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/ArrowRightX", ref RectArrowRight.X); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/ArrowRightY", ref RectArrowRight.Y); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/ArrowRightZ", ref RectArrowRight.Z); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/ArrowRightW", ref RectArrowRight.W); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/ArrowRightH", ref RectArrowRight.H); if (xmlReader.GetValue(item + "/ArrowColor", out _Theme.ArrowColor.Name, String.Empty)) _ThemeLoaded &= CBase.Theme.GetColor(_Theme.ArrowColor.Name, skinIndex, out ColorArrow); else { _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/ArrowR", ref ColorArrow.R); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/ArrowG", ref ColorArrow.G); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/ArrowB", ref ColorArrow.B); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/ArrowA", ref ColorArrow.A); } if (xmlReader.GetValue(item + "/ArrowSColor", out _Theme.ArrowSColor.Name, String.Empty)) _ThemeLoaded &= CBase.Theme.GetColor(_Theme.ArrowSColor.Name, skinIndex, out SelColorArrow); else { _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/ArrowSR", ref SelColorArrow.R); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/ArrowSG", ref SelColorArrow.G); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/ArrowSB", ref SelColorArrow.B); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/ArrowSA", ref SelColorArrow.A); } if (xmlReader.GetValue(item + "/TextColor", out _Theme.TextColor.Name, String.Empty)) _ThemeLoaded &= CBase.Theme.GetColor(_Theme.TextColor.Name, skinIndex, out TextColor); else { _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/TextR", ref TextColor.R); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/TextG", ref TextColor.G); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/TextB", ref TextColor.B); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/TextA", ref TextColor.A); } if (xmlReader.GetValue(item + "/TextSColor", out _Theme.TextSColor.Name, String.Empty)) _ThemeLoaded &= CBase.Theme.GetColor(_Theme.TextSColor.Name, skinIndex, out SelTextColor); else { _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/TextSR", ref SelTextColor.R); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/TextSG", ref SelTextColor.G); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/TextSB", ref SelTextColor.B); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/TextSA", ref SelTextColor.A); } _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/TextH", ref TextH); if (xmlReader.TryGetFloatValue(item + "/TextRelativeX", ref TextRelativeX)) _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/TextRelativeX", ref TextRelativeX); if (xmlReader.TryGetFloatValue(item + "/TextRelativeY", ref TextRelativeY)) _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/TextRelativeY", ref TextRelativeY); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/TextMaxW", ref MaxW); _ThemeLoaded &= xmlReader.GetValue(item + "/TextFont", out _Theme.TextFont, "Normal"); _ThemeLoaded &= xmlReader.TryGetEnumValue(item + "/TextStyle", ref _Theme.TextStyle); _ThemeLoaded &= xmlReader.TryGetIntValue(item + "/NumVisible", ref _NumVisible); if (_ThemeLoaded) { _Theme.Name = elementName; _Theme.ArrowColor.Color = new SColorF(ColorArrow); _Theme.ArrowSColor.Color = new SColorF(SelColorArrow); _Theme.Color.Color = new SColorF(Color); _Theme.HColor.Color = new SColorF(HighlightColor); _Theme.NumVisible = _NumVisible; _Theme.Rect = new SRectF(Rect); _Theme.RectArrowLeft = new SRectF(RectArrowLeft); _Theme.RectArrowRight = new SRectF(RectArrowRight); _Theme.SColor.Color = new SColorF(SelColor); _Theme.TextColor.Color = new SColorF(TextColor); _Theme.TextH = TextH; _Theme.TextMaxW = MaxW; _Theme.TextRelativeX = TextRelativeX; _Theme.TextRelativeY = TextRelativeY; _Theme.TextSColor.Color = new SColorF(SelTextColor); LoadTextures(); } return _ThemeLoaded; } public bool SaveTheme(XmlWriter writer) { if (_ThemeLoaded) { writer.WriteStartElement(_Theme.Name); writer.WriteComment(": Texture name"); writer.WriteElementString("Skin", _Theme.TextureName); writer.WriteComment(": Texture name of left arrow"); writer.WriteElementString("SkinArrowLeft", _Theme.TextureArrowLeftName); writer.WriteComment(": Texture name of right arrow"); writer.WriteElementString("SkinArrowRight", _Theme.TextureArrowRightName); writer.WriteComment(": Texture name for selected SelectSlide"); writer.WriteElementString("SkinSelected", _Theme.SelTextureName); writer.WriteComment(": Texture name of selected left arrow"); writer.WriteElementString("SkinArrowLeftSelected", _Theme.SelTextureArrowLeftName); writer.WriteComment(": Texture name of selected right arrow"); writer.WriteElementString("SkinArrowRightSelected", _Theme.SelTextureArrowRightName); writer.WriteComment(": Texture name for highlighted SelectSlide"); writer.WriteElementString("SkinHighlighted", _Theme.HighlightTextureName); writer.WriteComment(", , , , : SelectSlide position, width and height"); writer.WriteElementString("X", Rect.X.ToString("#0")); writer.WriteElementString("Y", Rect.Y.ToString("#0")); writer.WriteElementString("Z", Rect.Z.ToString("#0.00")); writer.WriteElementString("W", Rect.W.ToString("#0")); writer.WriteElementString("H", Rect.H.ToString("#0")); writer.WriteComment(", , , , : Left arrow position, width and height"); writer.WriteElementString("ArrowLeftX", RectArrowLeft.X.ToString("#0")); writer.WriteElementString("ArrowLeftY", RectArrowLeft.Y.ToString("#0")); writer.WriteElementString("ArrowLeftZ", RectArrowLeft.Z.ToString("#0.00")); writer.WriteElementString("ArrowLeftW", RectArrowLeft.W.ToString("#0")); writer.WriteElementString("ArrowLeftH", RectArrowLeft.H.ToString("#0")); writer.WriteComment(", , , , : Right arrow position, width and height"); writer.WriteElementString("ArrowRightX", RectArrowRight.X.ToString("#0")); writer.WriteElementString("ArrowRightY", RectArrowRight.Y.ToString("#0")); writer.WriteElementString("ArrowRightZ", RectArrowRight.Z.ToString("#0.00")); writer.WriteElementString("ArrowRightW", RectArrowRight.W.ToString("#0")); writer.WriteElementString("ArrowRightH", RectArrowRight.H.ToString("#0")); writer.WriteComment(": SelectSlide color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); if (!String.IsNullOrEmpty(_Theme.Color.Name)) writer.WriteElementString("Color", _Theme.Color.Name); else { writer.WriteElementString("R", Color.R.ToString("#0.00")); writer.WriteElementString("G", Color.G.ToString("#0.00")); writer.WriteElementString("B", Color.B.ToString("#0.00")); writer.WriteElementString("A", Color.A.ToString("#0.00")); } writer.WriteComment(": Selected SelectSlide color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); if (!String.IsNullOrEmpty(_Theme.SColor.Name)) writer.WriteElementString("SColor", _Theme.SColor.Name); else { writer.WriteElementString("SR", SelColor.R.ToString("#0.00")); writer.WriteElementString("SG", SelColor.G.ToString("#0.00")); writer.WriteElementString("SB", SelColor.B.ToString("#0.00")); writer.WriteElementString("SA", SelColor.A.ToString("#0.00")); } writer.WriteComment(": Highlighted SelectSlide color from ColorScheme (high priority)"); writer.WriteComment("or
, , , (lower priority)"); if (!String.IsNullOrEmpty(_Theme.HColor.Name)) writer.WriteElementString("HColor", _Theme.HColor.Name); else { writer.WriteElementString("HR", HighlightColor.R.ToString("#0.00")); writer.WriteElementString("HG", HighlightColor.G.ToString("#0.00")); writer.WriteElementString("HB", HighlightColor.B.ToString("#0.00")); writer.WriteElementString("HA", HighlightColor.A.ToString("#0.00")); } writer.WriteComment(": Arrow color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); if (!String.IsNullOrEmpty(_Theme.ArrowColor.Name)) writer.WriteElementString("ArrowColor", _Theme.ArrowColor.Name); else { writer.WriteElementString("ArrowR", ColorArrow.R.ToString("#0.00")); writer.WriteElementString("ArrowG", ColorArrow.G.ToString("#0.00")); writer.WriteElementString("ArrowB", ColorArrow.B.ToString("#0.00")); writer.WriteElementString("ArrowA", ColorArrow.A.ToString("#0.00")); } writer.WriteComment(": Selected arrow color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); if (!String.IsNullOrEmpty(_Theme.ArrowSColor.Name)) writer.WriteElementString("ArrowSColor", _Theme.ArrowSColor.Name); else { writer.WriteElementString("ArrowSR", SelColorArrow.R.ToString("#0.00")); writer.WriteElementString("ArrowSG", SelColorArrow.G.ToString("#0.00")); writer.WriteElementString("ArrowSB", SelColorArrow.B.ToString("#0.00")); writer.WriteElementString("ArrowSA", SelColorArrow.A.ToString("#0.00")); } writer.WriteComment(": Text color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); if (!String.IsNullOrEmpty(_Theme.TextColor.Name)) writer.WriteElementString("TextColor", _Theme.TextColor.Name); else { writer.WriteElementString("TextR", TextColor.R.ToString("#0.00")); writer.WriteElementString("TextG", TextColor.G.ToString("#0.00")); writer.WriteElementString("TextB", TextColor.B.ToString("#0.00")); writer.WriteElementString("TextA", TextColor.A.ToString("#0.00")); } writer.WriteComment(": Selected text color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); if (!String.IsNullOrEmpty(_Theme.TextSColor.Name)) writer.WriteElementString("TextSColor", _Theme.TextSColor.Name); else { writer.WriteElementString("TextSR", SelTextColor.R.ToString("#0.00")); writer.WriteElementString("TextSG", SelTextColor.G.ToString("#0.00")); writer.WriteElementString("TextSB", SelTextColor.B.ToString("#0.00")); writer.WriteElementString("TextSA", SelTextColor.A.ToString("#0.00")); } writer.WriteComment(": Text height"); writer.WriteElementString("TextH", TextH.ToString("#0.00")); writer.WriteComment(": Text relative x-position"); if (Math.Abs(TextRelativeX) > 0.01) writer.WriteElementString("TextRelativeX", TextRelativeX.ToString("#0.00")); writer.WriteComment(": Text relative y-position"); if (Math.Abs(TextRelativeY) > 0.01) writer.WriteElementString("TextRelativeY", TextRelativeY.ToString("#0.00")); writer.WriteComment(": Maximum text width (if exists)"); writer.WriteElementString("TextMaxW", MaxW.ToString("#0.00")); writer.WriteComment(": Text font name"); writer.WriteElementString("TextFont", _Theme.TextFont); writer.WriteComment(": Text style: " + CHelper.ListStrings(Enum.GetNames(typeof(EStyle)))); writer.WriteElementString("TextStyle", Enum.GetName(typeof(EStyle), _Theme.TextStyle)); writer.WriteComment(": Number of visible elements in the slide"); writer.WriteElementString("NumVisible", _NumVisible.ToString()); writer.WriteEndElement(); return true; } return false; } public void AddValue(string value) { AddValue(value, _PartyModeID); } public void AddValue(string value, int partyModeID) { AddValue(value, null, _ValueIndexes.Count, partyModeID); } public void AddValue(string value, CTexture texture) { AddValue(value, texture, _ValueIndexes.Count, _PartyModeID); } private void _AddValue(string value, CTexture texture, int valueIndex) { AddValue(value, texture, valueIndex, _PartyModeID); } public void AddValue(string value, CTexture texture, int valueIndex, int partyModeID) { _ValueNames.Add(value); _Textures.Add(texture); _ValueIndexes.Add(valueIndex); _ValuePartyModeIDs.Add(partyModeID); if (Selection == -1) Selection = 0; _ValueBounds.Clear(); } public void AddValues(IEnumerable values) { foreach (string value in values) _AddValue(value, null, _PartyModeID); _ValueBounds.Clear(); } public void AddValues(string[] values, CTexture[] textures) { if (values.Length != textures.Length) return; for (int i = 0; i < values.Length; i++) AddValue(values[i], textures[i]); if (Selection == -1) Selection = 0; _ValueBounds.Clear(); } public void SetValues(int selection) { AddValues(Enum.GetNames(typeof(T))); Selection = selection; } public void RenameValue(string newName) { RenameValue(Selection, newName); } public void RenameValue(int selection, string newName, CTexture newTexture = null) { if (selection < 0 && selection >= _ValueNames.Count) return; _ValueNames[selection] = newName; _Textures[selection] = newTexture; } public bool SetSelectionByValueIndex(int valueIndex) { for (int i = 0; i < _ValueIndexes.Count; i++) { if (_ValueIndexes[i] == valueIndex) { Selection = i; return true; } } return false; } public bool NextValue() { if (Selection < _ValueNames.Count - 1) { Selection++; return true; } return false; } public bool PrevValue() { if (Selection > 0) { Selection--; return true; } return false; } public void FirstValue() { if (_ValueNames.Count > 0) Selection = 0; } public void LastValue() { if (_ValueNames.Count > 0) Selection = _ValueNames.Count - 1; } public void Clear() { _Selection = -1; _ValueNames.Clear(); _Textures.Clear(); _ValueBounds.Clear(); _ValueIndexes.Clear(); } public void ProcessMouseMove(int x, int y) { _ArrowLeftSelected = CHelper.IsInBounds(RectArrowLeft, x, y) && _Selection > 0; _ArrowRightSelected = CHelper.IsInBounds(RectArrowRight, x, y) && _Selection < _ValueNames.Count - 1; if (SelectionByHover) { for (int i = 0; i < _ValueBounds.Count; i++) { if (CHelper.IsInBounds(_ValueBounds[i], x, y)) { int offset = _Selection - _NumVisible / 2; if (_ValueNames.Count - _NumVisible - offset < 0) offset = _ValueNames.Count - _NumVisible; if (offset < 0) offset = 0; Selection = i + offset; _ValueBounds.Clear(); break; } } } } public void ProcessMouseLBClick(int x, int y) { ProcessMouseMove(x, y); if (_ArrowLeftSelected) PrevValue(); if (_ArrowRightSelected) NextValue(); for (int i = 0; i < _ValueBounds.Count; i++) { if (CHelper.IsInBounds(_ValueBounds[i], x, y)) { int offset = _Selection - _NumVisible / 2; if (_ValueNames.Count - _NumVisible - offset < 0) offset = _ValueNames.Count - _NumVisible; if (offset < 0) offset = 0; Selection = i + offset; _ValueBounds.Clear(); break; } } } public void Draw() { if (!Visible && CBase.Settings.GetProgramState() != EProgramState.EditTheme) return; CTexture texture = CBase.Theme.GetSkinTexture(_Theme.TextureName, _PartyModeID); CTexture textureArrowLeft = CBase.Theme.GetSkinTexture(_Theme.TextureArrowLeftName, _PartyModeID); CTexture textureArrowRight = CBase.Theme.GetSkinTexture(_Theme.TextureArrowRightName, _PartyModeID); CTexture selTexture = CBase.Theme.GetSkinTexture(_Theme.SelTextureName, _PartyModeID); CTexture selTextureArrowLeft = CBase.Theme.GetSkinTexture(_Theme.SelTextureArrowLeftName, _PartyModeID); CTexture selTextureArrowRight = CBase.Theme.GetSkinTexture(_Theme.SelTextureArrowRightName, _PartyModeID); CTexture highlightTexture = CBase.Theme.GetSkinTexture(_Theme.HighlightTextureName, _PartyModeID); if (Selected) { if (Highlighted) CBase.Drawing.DrawTexture(highlightTexture, Rect, HighlightColor); else CBase.Drawing.DrawTexture(selTexture, Rect, SelColor); } else CBase.Drawing.DrawTexture(texture, Rect, Color); if (_Selection > 0 || CBase.Settings.GetProgramState() == EProgramState.EditTheme) { if (_ArrowLeftSelected) CBase.Drawing.DrawTexture(selTextureArrowLeft, RectArrowLeft, SelColorArrow); else CBase.Drawing.DrawTexture(textureArrowLeft, RectArrowLeft, ColorArrow); } if (_Selection < _ValueNames.Count - 1 || CBase.Settings.GetProgramState() == EProgramState.EditTheme) { if (_ArrowRightSelected) CBase.Drawing.DrawTexture(selTextureArrowRight, RectArrowRight, SelColorArrow); else CBase.Drawing.DrawTexture(textureArrowRight, RectArrowRight, ColorArrow); } if (_NumVisible < 1 || _ValueNames.Count == 0) return; float x = Rect.X + (Rect.W - TextRelativeX) * 0.1f; float dx = (Rect.W - TextRelativeX) * 0.8f / _NumVisible; //float y = Rect.Y + (Rect.H - TextH); int offset = _Selection - _NumVisible / 2; if (_ValueNames.Count - _NumVisible - offset < 0) offset = _ValueNames.Count - _NumVisible; if (offset < 0) offset = 0; int numvis = _NumVisible; if (_ValueNames.Count < numvis) numvis = _ValueNames.Count; _ValueBounds.Clear(); for (int i = 0; i < numvis; i++) { var text = new CText(0, 0, 0, TextH, MaxW, EAlignment.Center, _Theme.TextStyle, _Theme.TextFont, TextColor, "T", _ValuePartyModeIDs[i + offset]); if (_ValueNames[i + offset] != "") text.Text = _ValueNames[i + offset]; else text.Visible = false; var alpha = new SColorF(1f, 1f, 1f, 0.35f); if (i + offset == _Selection) { text.Color = SelTextColor; alpha = new SColorF(1f, 1f, 1f, 1f); } RectangleF bounds = CBase.Fonts.GetTextBounds(text); text.X = (x + dx / 2f + dx * i) + TextRelativeX; if (!WithTextures) text.Y = (int)((Rect.Y + (Rect.H - bounds.Height) / 2) + TextRelativeY); else text.Y = (int)((Rect.Y + (Rect.H - bounds.Height)) + TextRelativeY); text.Z = Rect.Z; text.Draw(); if (WithTextures) { float dh = text.Y - Rect.Y - Rect.H * 0.1f; var rect = new SRectF(text.X - dh / 2, Rect.Y + Rect.H * 0.05f, dh, dh, Rect.Z); CBase.Drawing.DrawTexture(_Textures[i + offset], rect, alpha, rect); _ValueBounds.Add(rect); } else _ValueBounds.Add(new SRectF(text.X - bounds.Width / 2f, text.Y, bounds.Width, bounds.Height, Rect.Z)); } } public SThemeSelectSlide GetTheme() { return new SThemeSelectSlide(_Theme); } public void UnloadTextures() {} public void LoadTextures() { if (!String.IsNullOrEmpty(_Theme.Color.Name)) Color = CBase.Theme.GetColor(_Theme.Color.Name, _PartyModeID); else Color = _Theme.Color.Color; if (!String.IsNullOrEmpty(_Theme.SColor.Name)) SelColor = CBase.Theme.GetColor(_Theme.SColor.Name, _PartyModeID); else SelColor = _Theme.SColor.Color; if (!String.IsNullOrEmpty(_Theme.HColor.Name)) HighlightColor = CBase.Theme.GetColor(_Theme.HColor.Name, _PartyModeID); else HighlightColor = _Theme.HColor.Color; if (!String.IsNullOrEmpty(_Theme.ArrowColor.Name)) ColorArrow = CBase.Theme.GetColor(_Theme.ArrowColor.Name, _PartyModeID); else ColorArrow = _Theme.ArrowColor.Color; if (!String.IsNullOrEmpty(_Theme.ArrowSColor.Name)) SelColorArrow = CBase.Theme.GetColor(_Theme.ArrowSColor.Name, _PartyModeID); else SelColorArrow = _Theme.ArrowSColor.Color; if (!String.IsNullOrEmpty(_Theme.TextColor.Name)) TextColor = CBase.Theme.GetColor(_Theme.TextColor.Name, _PartyModeID); else TextColor = _Theme.TextColor.Color; if (!String.IsNullOrEmpty(_Theme.TextSColor.Name)) SelTextColor = CBase.Theme.GetColor(_Theme.TextSColor.Name, _PartyModeID); else SelTextColor = _Theme.TextSColor.Color; Rect = _Theme.Rect; RectArrowLeft = _Theme.RectArrowLeft; RectArrowRight = _Theme.RectArrowRight; NumVisible = _Theme.NumVisible; TextH = _Theme.TextH; TextRelativeX = _Theme.TextRelativeX; TextRelativeY = _Theme.TextRelativeY; MaxW = _Theme.TextMaxW; } public void ReloadTextures() { UnloadTextures(); LoadTextures(); } public object Clone() { return MemberwiseClone(); } #region ThemeEdit public void MoveElement(int stepX, int stepY) { if (!_ArrowLeftSelected && !_ArrowRightSelected) { Rect.X += stepX; Rect.Y += stepY; _Theme.Rect.X += stepX; _Theme.Rect.Y += stepY; } if (_ArrowLeftSelected) { RectArrowLeft.X += stepX; RectArrowLeft.Y += stepY; _Theme.RectArrowLeft.X += stepX; _Theme.RectArrowLeft.Y += stepY; } if (_ArrowRightSelected) { RectArrowRight.X += stepX; RectArrowRight.Y += stepY; _Theme.RectArrowRight.X += stepX; _Theme.RectArrowRight.Y += stepY; } } public void ResizeElement(int stepW, int stepH) { if (!_ArrowLeftSelected && !_ArrowRightSelected) { Rect.W += stepW; if (Rect.W <= 0) Rect.W = 1; Rect.H += stepH; if (Rect.H <= 0) Rect.H = 1; _Theme.Rect.W = Rect.W; _Theme.Rect.H = Rect.H; } if (_ArrowLeftSelected) { RectArrowLeft.W += stepW; if (RectArrowLeft.W <= 0) RectArrowLeft.W = 1; RectArrowLeft.H += stepH; if (RectArrowLeft.H <= 0) RectArrowLeft.H = 1; _Theme.RectArrowLeft.W = RectArrowLeft.W; _Theme.RectArrowLeft.H = RectArrowLeft.H; } if (_ArrowRightSelected) { RectArrowRight.W += stepW; if (RectArrowRight.W <= 0) RectArrowRight.W = 1; RectArrowRight.H += stepH; if (RectArrowRight.H <= 0) RectArrowRight.H = 1; _Theme.RectArrowRight.W = RectArrowRight.W; _Theme.RectArrowRight.H = RectArrowRight.H; } } #endregion ThemeEdit } }