109 lines
3.2 KiB
C#
109 lines
3.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
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 VDash.Overlay.Actions;
|
|
|
|
namespace VDash.UI.ActionEditors
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for ResizeWindowActionEditor.xaml
|
|
/// </summary>
|
|
public partial class ResizeWindowActionEditor : UserControl,IActionEditor
|
|
{
|
|
public event EventHandler Submitted;
|
|
public ResizeWindowAction Action { get; private set; }
|
|
|
|
public static object[] Presets =
|
|
{
|
|
"Optional Presets...",
|
|
new ResizePreset("Small (640x480)", 640, 480),
|
|
new ResizePreset("Medium (1024x768)", 1024, 768),
|
|
new ResizePreset("Large (1400x1050)", 1400, 1050)
|
|
};
|
|
|
|
public ResizeWindowActionEditor(ResizeWindowAction action)
|
|
{
|
|
InitializeComponent();
|
|
Action = action;
|
|
DataContext = Action;
|
|
cbPresets.ItemsSource = Presets;
|
|
}
|
|
|
|
private void TextBlock_PreviewTextInput(object sender, TextCompositionEventArgs e)
|
|
{
|
|
foreach (var letter in e.Text)
|
|
{
|
|
if (!Char.IsNumber(letter))
|
|
{
|
|
e.Handled = true;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void TextBlock_PreviewKeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if(e.Key == Key.Space)
|
|
{
|
|
e.Handled = true;
|
|
return;
|
|
}
|
|
}
|
|
|
|
private void btnOK_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if(Action.NewWidth <= 50 || Action.NewHeight == 50)
|
|
{
|
|
MessageBox.Show("Please enter a valid width and height.", "Input error", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
return;
|
|
}
|
|
Submitted?.Invoke(this, null);
|
|
}
|
|
|
|
private void cbPresets_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
//Skip description
|
|
if(cbPresets.SelectedItem.GetType() != typeof(ResizePreset))
|
|
{
|
|
return;
|
|
}
|
|
|
|
var item = (ResizePreset)cbPresets.SelectedItem;
|
|
|
|
Action.NewWidth = item.Width;
|
|
Action.NewHeight = item.Height;
|
|
tbWidth.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
|
|
tbHeight.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
|
|
}
|
|
|
|
internal class ResizePreset
|
|
{
|
|
public string Description { get; private set; }
|
|
public int Width { get; private set; }
|
|
public int Height { get; private set; }
|
|
|
|
public ResizePreset(string description, int width, int height)
|
|
{
|
|
Description = description;
|
|
Width = width;
|
|
Height = height;
|
|
}
|
|
public override string ToString()
|
|
{
|
|
return Description;
|
|
}
|
|
}
|
|
}
|
|
}
|