142 lines
4.7 KiB
C#
142 lines
4.7 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 Valve.VR;
|
|
using VDash.Overlay;
|
|
using VDash.Overlay.Config;
|
|
using VDash.UI;
|
|
using VDash.Utilities;
|
|
|
|
namespace VDash
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for MainWindow.xaml
|
|
/// </summary>
|
|
public partial class MainWindow : Window
|
|
{
|
|
public static OverlayManager OverlayManager = new OverlayManager();
|
|
public static List<EditorMap> EditorMapping = new List<EditorMap>()
|
|
{
|
|
new EditorMap(typeof(MonitorOverlay), typeof(UI.MonitorOverlayEditor)),
|
|
new EditorMap(typeof(WindowOverlay), typeof(UI.WindowOverlayEditor))
|
|
};
|
|
|
|
List<OverlayEditor> overlayEditors = new List<OverlayEditor>();
|
|
public MainWindow()
|
|
{
|
|
InitializeComponent();
|
|
|
|
//Connect to VR runtime...
|
|
EVRInitError initError = EVRInitError.None;
|
|
|
|
var ret = OpenVR.Init(ref initError, EVRApplicationType.VRApplication_Overlay);
|
|
|
|
#if !DEBUG
|
|
if (initError != EVRInitError.None)
|
|
{
|
|
throw new Exception($"Error connecting to VR: {initError.ToString()}");
|
|
}
|
|
#endif
|
|
|
|
lvOverlays.ItemsSource = OverlayManager.Overlays;
|
|
|
|
#region Debug
|
|
|
|
|
|
//StartOverlayWindow("Discord");
|
|
|
|
//StartOverlayWindow("Microsoft Visual Studio");
|
|
|
|
//StartOverlayWindow("Notepad++");
|
|
|
|
//StartOverlayWindow("Putty");
|
|
|
|
//StartOverlayWindow("Paint");
|
|
|
|
//Overlay.WindowOverlay obsoverlay = new Overlay.WindowOverlay("obs", "obs", new WindowSelectors.FromProcessName("obs64"), false);
|
|
//obsoverlay.Create();
|
|
//obsoverlay.DestroyOnNoWindowFound = true;
|
|
//var bringWindow = new Overlay.Actions.BringWindowToFrontAction(true);
|
|
//obsoverlay.OverlayShownActions.Add(bringWindow);
|
|
|
|
//var displays = User32.GetDisplays();
|
|
//MonitorOverlay mo0 = new MonitorOverlay("left", "Left Monitor", displays[0]);
|
|
//mo0.Create();
|
|
//MonitorOverlay mo1 = new MonitorOverlay("center", "Center Monitor", displays[1]);
|
|
//mo1.Create();
|
|
//MonitorOverlay mo2= new MonitorOverlay("right", "Right Monitor", displays[2]);
|
|
//mo2.Create();
|
|
#endregion
|
|
}
|
|
|
|
private void btnAdd_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
Window w = new Window();
|
|
var uc = new UI.CreateNewOverlay();
|
|
uc.Created += (snd, overlay) => {
|
|
w.Close();
|
|
UI.IOverlayEditor editor = (UI.IOverlayEditor)Activator.CreateInstance(EditorMapping.Single(x => x.OverlayType == overlay.GetType()).EditorType, new object[] { overlay.OverlayConfig });
|
|
OverlayEditor overlayEditor = new OverlayEditor(new UI.OverlayEditor(editor), overlay);
|
|
overlayEditors.Add(overlayEditor);
|
|
};
|
|
w.Content = uc;
|
|
w.Width = 500;
|
|
w.Height = 400;
|
|
w.SizeToContent = System.Windows.SizeToContent.Height;
|
|
w.Show();
|
|
}
|
|
|
|
private void btnRemove_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if(lvOverlays.SelectedItem == null) { return; }
|
|
IOverlay overlay = (IOverlay)lvOverlays.SelectedItem;
|
|
overlay.Dispose();
|
|
OverlayManager.Overlays.Remove(overlay);
|
|
overlayEditors.Remove(overlayEditors.Single(x => x.Overlay == overlay));
|
|
}
|
|
|
|
private void lvOverlays_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
if (lvOverlays.SelectedItem == null) { return; }
|
|
IOverlay overlay = (IOverlay)lvOverlays.SelectedItem;
|
|
|
|
bdrContent.Child = (UserControl)overlayEditors.Single(x => x.Overlay == overlay).Editor;
|
|
}
|
|
}
|
|
|
|
public class OverlayEditor
|
|
{
|
|
public OverlayEditor(IOverlayEditor editor, IOverlay overlay)
|
|
{
|
|
Editor = editor;
|
|
Overlay = overlay;
|
|
}
|
|
|
|
public UI.IOverlayEditor Editor { get; private set; }
|
|
public IOverlay Overlay { get; private set; }
|
|
}
|
|
|
|
public class EditorMap
|
|
{
|
|
public EditorMap(Type overlayType, Type editorType)
|
|
{
|
|
OverlayType = overlayType;
|
|
EditorType = editorType;
|
|
}
|
|
|
|
public Type OverlayType { get; private set; }
|
|
public Type EditorType { get; private set; }
|
|
}
|
|
}
|