VRDash/VRDash/UI/OverlayEditor.xaml.cs

81 lines
2.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using VRDash.Overlay.Config;
using VRDash.Overlay.Config.OverlayLocation;
namespace VRDash.UI
{
/// <summary>
/// Interaction logic for OverlayEditor.xaml
/// </summary>
public partial class OverlayEditor : UserControl,IOverlayEditor
{
public IOverlayEditor Editor { get { return (IOverlayEditor)bdrContent.Child; } set { bdrContent.Child = (UserControl)value; } }
public IOverlayConfig Config { get { return Editor.Config; } }
public OverlayEditor(IOverlayEditor editor)
{
InitializeComponent();
Editor = editor;
DataContext = Config;
OverlayLocationInfo.OverlayLocationAttributeInfo[] overlayLocationAttributes = OverlayLocationInfo.GetOverlayLocationInfos();
OverlayLocationInfo locationInfo = overlayLocationAttributes.Single(x => x.OverlayLocationType == Config.Location.GetType()).Info;
if (locationInfo.LocationEditorType != null)
{
UserControl locationEditor = (UserControl)Activator.CreateInstance(locationInfo.LocationEditorType, new object[] { Config.Location });
bdrLocationEditor.Child = locationEditor;
}
else
{
var parent = VisualTreeHelper.GetParent(gbLocationSettings);
((Panel)parent).Children.Remove(gbLocationSettings);
}
}
private void tbWidth_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
var dotcount = tbWidth.Text.Count(x => x == '.');
foreach(var letter in e.Text)
{
if(!Char.IsDigit(letter) && letter != '.')
{
e.Handled = true;
}
if (dotcount >= 1 && e.Text.Contains("."))
{
e.Handled = true;
return;
}
}
}
private void tbWidth_PreviewKeyDown(object sender, KeyEventArgs e)
{
if(e.Key == Key.Space)
{
e.Handled = true;
}
}
public string[] ValidateInput()
{
return Editor.ValidateInput();
}
}
}