diff --git a/VRDash/MainWindow.xaml b/VRDash/MainWindow.xaml index 52812eb..b9f8dcb 100644 --- a/VRDash/MainWindow.xaml +++ b/VRDash/MainWindow.xaml @@ -6,6 +6,7 @@ xmlns:local="clr-namespace:VRDash" mc:Ignorable="d" KeyDown="Window_KeyDown" + Closing="Window_Closing" Title="VRDash" Height="700" Width="800"> diff --git a/VRDash/MainWindow.xaml.cs b/VRDash/MainWindow.xaml.cs index 5861897..c4de85c 100644 --- a/VRDash/MainWindow.xaml.cs +++ b/VRDash/MainWindow.xaml.cs @@ -181,8 +181,20 @@ namespace VRDash var overlayInfo = attrs.Single(x => x.OverlayType == overlay.GetType()); UI.IOverlayEditor editor = (UI.IOverlayEditor)Activator.CreateInstance(overlayInfo.Info.EditorType, new object[] { overlay.OverlayConfig }); OverlayEditorInfo overlayEditor = new OverlayEditorInfo(new UI.OverlayEditor(editor), overlay); - IOverlayListViewItem lvi = (IOverlayListViewItem)Activator.CreateInstance(overlayInfo.Info.ListViewType, new object[] { overlayEditor }); - OverlayManager.Overlays.Add(lvi); + IOverlayListViewItem lvi = null; + if (overlayInfo.Info.ListViewType != null) + { + lvi = (IOverlayListViewItem)Activator.CreateInstance(overlayInfo.Info.ListViewType, new object[] { overlayEditor }); + OverlayManager.Overlays.Add(lvi); + } + else + { +#if DEBUG + this.GetLogger().Warn($"No list view item for {overlayEditor.Overlay.GetType()}!"); +#else + throw new Exception($"No list view item for {overlayEditor.Overlay.GetType()}!"); +#endif + } }; w.Content = uc; w.Width = 500; @@ -220,15 +232,24 @@ namespace VRDash private void Window_KeyDown(object sender, KeyEventArgs e) { - if(e.Key == Key.F1) + //if(e.Key == Key.F1) + //{ + // var conf = new MonitorOverlayConfig(); + // conf.Name = "Test Browser"; + // conf.Key = "asdfasdf"; + // conf.Location = new Overlay.Config.OverlayLocation.DashboardLocation(); + // var overlay = new Overlay.BrowserOverlay(conf); + // overlay.Create(); + // overlay.Show(); + //} + } + + private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) + { + foreach(var overlayLVI in OverlayManager.Overlays) { - var conf = new MonitorOverlayConfig(); - conf.Name = "Test Browser"; - conf.Key = "asdfasdf"; - conf.Location = new Overlay.Config.OverlayLocation.DashboardLocation(); - var overlay = new Overlay.BrowserOverlay(conf); - overlay.Create(); - overlay.Show(); + overlayLVI.Dispose(); + overlayLVI.OverlayInfo.Overlay.Dispose(); } } } diff --git a/VRDash/Overlay/BrowserOverlay.xaml b/VRDash/Overlay/BrowserOverlay.xaml index 7dd3456..678c421 100644 --- a/VRDash/Overlay/BrowserOverlay.xaml +++ b/VRDash/Overlay/BrowserOverlay.xaml @@ -6,8 +6,15 @@ xmlns:local="clr-namespace:VRDash.Overlay" xmlns:cefSharp="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf" mc:Ignorable="d" - Title="BrowserOverlay" Height="450" Width="800"> + Title="BrowserOverlay" Height="450" Width="800" + Closing="Window_Closing"> - + + + + + + + diff --git a/VRDash/Overlay/BrowserOverlay.xaml.cs b/VRDash/Overlay/BrowserOverlay.xaml.cs index f1dc6ec..1264ce3 100644 --- a/VRDash/Overlay/BrowserOverlay.xaml.cs +++ b/VRDash/Overlay/BrowserOverlay.xaml.cs @@ -4,7 +4,9 @@ using SharpDX.Direct3D11; using SharpDX.DXGI; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows; @@ -17,12 +19,15 @@ using System.Windows.Media.Imaging; using System.Windows.Shapes; using Valve.VR; using VRDash.Overlay.Config; +using VRDash.UI; +using VRDash.Utilities; namespace VRDash.Overlay { /// /// Interaction logic for BrowserOverlay.xaml /// + [OverlayInfo("Browser Overlay", typeof(BrowserOverlayConfig), typeof(BrowserOverlayEditor), typeof(UI.BrowserOverlayListViewItem))] public partial class BrowserOverlay : Window, IOverlay { ulong m_OverlayHandle = OpenVR.k_ulOverlayHandleInvalid; @@ -31,9 +36,8 @@ namespace VRDash.Overlay ulong m_ThumbnailHandle = OpenVR.k_ulOverlayHandleInvalid; public IOverlayConfig OverlayConfig { get { return Config; } } - - //CHANGEME to the BrowserOverlayCOnfig you make later - public IOverlayConfig Config { get; } + + public BrowserOverlayConfig Config { get; } public int CurrentFPS { get; private set; } = 0; @@ -44,12 +48,13 @@ namespace VRDash.Overlay public event EventHandler Update; bool m_Created = false; - - //CHANGEME to the BrowserOverlayCOnfig you make later - public BrowserOverlay(IOverlayConfig config) + + public BrowserOverlay(BrowserOverlayConfig config) { Config = config; InitializeComponent(); + this.Show(); + } Factory1 m_Factory = null; @@ -89,7 +94,23 @@ namespace VRDash.Overlay public void Destroy() { - throw new NotImplementedException(); + m_ScreenTexture.Dispose(); + m_Device.ImmediateContext.ClearState(); + m_Device.ImmediateContext.Flush(); + m_Device.Dispose(); + m_Adapter.Dispose(); + m_Factory.Dispose(); + CurrentFPS = 0; + + var err = OpenVR.Overlay.DestroyOverlay(m_OverlayHandle); + + if (err != EVROverlayError.None) + { + throw new Exception($"Error destroying overlay: {err}"); + } + + m_OverlayHandle = OpenVR.k_ulOverlayHandleInvalid; + m_ThumbnailHandle = OpenVR.k_ulOverlayHandleInvalid; } public void Dispose() @@ -97,6 +118,7 @@ namespace VRDash.Overlay if (IsDisposed) { return; } Destroy(); IsDisposed = true; + this.Close(); } public string GetOverlayName() @@ -128,7 +150,14 @@ namespace VRDash.Overlay { if ((bool)e.NewValue) { - cwbBrowser.LoadHtml(""); + if (Config.ContentType == BrowserOverlayConfig.BrowserOverlayContentType.Url && !String.IsNullOrWhiteSpace(Config.Content)) + { + cwbBrowser.Load(Config.Content); + } + else if(Config.ContentType == BrowserOverlayConfig.BrowserOverlayContentType.Html && !String.IsNullOrWhiteSpace(Config.Content)) + { + cwbBrowser.LoadHtml(Config.Content); + } } } @@ -137,6 +166,13 @@ namespace VRDash.Overlay private void cwbBrowser_Paint(object sender, CefSharp.Wpf.PaintEventArgs e) { if (!m_Created) { return; } + + if (m_Device.IsDisposed) + { + this.GetLogger().Debug("m_Device is disposed. This should only happen on removal."); + return; + } + Update?.Invoke(this, null); if (m_ScreenTexture == null || (m_LastWidth != e.Width || m_LastHeight != e.Height)) @@ -187,7 +223,7 @@ namespace VRDash.Overlay { int count = 4 * e.Width * e.Height; - //Stride compensation. Sometimes the BMP and DX texture strides are different. This fixes it. + //Stride compensation. Sometimes the browser stride and DX texture strides are different. This fixes it. if (databox.RowPitch == stride) { m_Stream.Write(e.Buffer, 0, count); @@ -237,5 +273,20 @@ namespace VRDash.Overlay } #endregion + + private void btnTest_Click(object sender, RoutedEventArgs e) + { + //Dispose(); + } + + private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) + { + if (!IsDisposed) + { + e.Cancel = true; + Hide(); + cwbBrowser.GetBrowserHost().WasHidden(false); + } + } } } diff --git a/VRDash/Overlay/Config/BrowserOverlayConfig.cs b/VRDash/Overlay/Config/BrowserOverlayConfig.cs new file mode 100644 index 0000000..1364e3c --- /dev/null +++ b/VRDash/Overlay/Config/BrowserOverlayConfig.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VRDash.Overlay.Config.OverlayLocation; + +namespace VRDash.Overlay.Config +{ + public class BrowserOverlayConfig : IOverlayConfig + { + public string Name { get; set; } + public string Key { get; set; } + public float OverlayWidth { get; set; } = 2.5f; + public IOverlayLocation Location { get; set; } + public string Content { get; set; } + public BrowserOverlayContentType ContentType { get; set; } + + public void Initialize(IOverlay overlay) + { + //Nothing needs to be done here + } + + public enum BrowserOverlayContentType + { + Url=0, + Html=1 + } + } +} diff --git a/VRDash/Overlay/Config/OverlayLocation/ControllerLocation.cs b/VRDash/Overlay/Config/OverlayLocation/ControllerLocation.cs index 83c803e..358079f 100644 --- a/VRDash/Overlay/Config/OverlayLocation/ControllerLocation.cs +++ b/VRDash/Overlay/Config/OverlayLocation/ControllerLocation.cs @@ -76,7 +76,7 @@ namespace VRDash.Overlay.Config.OverlayLocation //Location = Matrix3x4.Add(Matrix3x4.CreateFromQuaternion(quat), Location); //Location = Matrix3x4.Add(Matrix3x4.CreateScale(ScaleX, ScaleY, ScaleZ), Location); - if (m_Overlay.OverlayHandle == OpenVR.k_ulOverlayHandleInvalid || m_ControllerIndex == OpenVR.k_unTrackedDeviceIndexInvalid) { return; } + if (m_Overlay.OverlayHandle == OpenVR.k_ulOverlayHandleInvalid) { return; } //Index changed, need to update the overlay if (controllerIndex != m_ControllerIndex) diff --git a/VRDash/Overlay/Config/OverlayLocation/DashboardLocation.cs b/VRDash/Overlay/Config/OverlayLocation/DashboardLocation.cs index c6e19b1..63a63fd 100644 --- a/VRDash/Overlay/Config/OverlayLocation/DashboardLocation.cs +++ b/VRDash/Overlay/Config/OverlayLocation/DashboardLocation.cs @@ -16,11 +16,17 @@ namespace VRDash.Overlay.Config.OverlayLocation ulong thumbnailHandle = 0; //Actually create the overlay - EVROverlayError err = OpenVR.Overlay.CreateDashboardOverlay(key, name, ref overalyHandle, ref thumbnailHandle); - - if (err != EVROverlayError.None) + try { - throw new Exception($"Error creating overlay: {err}"); + EVROverlayError err = OpenVR.Overlay.CreateDashboardOverlay(key, name, ref overalyHandle, ref thumbnailHandle); + if (err != EVROverlayError.None) + { + throw new Exception($"Error creating overlay: {err}"); + } + } + catch (Exception ex) + { + this.GetLogger(overlay).Error("Unable to create new OpenVR overlay.", ex); } OverlayHandles handles = new OverlayHandles(overalyHandle, thumbnailHandle); diff --git a/VRDash/Overlay/MonitorOverlay.cs b/VRDash/Overlay/MonitorOverlay.cs index 8b1096a..8fd37ac 100644 --- a/VRDash/Overlay/MonitorOverlay.cs +++ b/VRDash/Overlay/MonitorOverlay.cs @@ -49,8 +49,8 @@ namespace VRDash.Overlay internal ulong m_OverlayHandle; public ulong OverlayHandle { get { return m_OverlayHandle; } } - internal ulong m_ThumbnailIcon; - public ulong ThumbnailIcon { get { return m_ThumbnailIcon; } } + internal ulong m_ThumbnailHandle; + public ulong ThumbnailIcon { get { return m_ThumbnailHandle; } } public IOverlayConfig OverlayConfig { get { return Config; } } public MonitorOverlayConfig Config { get; } @@ -105,7 +105,7 @@ namespace VRDash.Overlay } m_OverlayHandle = OpenVR.k_ulOverlayHandleInvalid; - m_ThumbnailIcon = OpenVR.k_ulOverlayHandleInvalid; + m_ThumbnailHandle = OpenVR.k_ulOverlayHandleInvalid; } private void EventPump() @@ -126,7 +126,7 @@ namespace VRDash.Overlay Config.OverlayLocation.OverlayHandles overlayHandles = Config.Location.CreateOverlay(Config.Key, Config.Name, this); m_OverlayHandle = overlayHandles.OverlayHandle; - m_ThumbnailIcon = overlayHandles.ThumbnailHandle; + m_ThumbnailHandle = overlayHandles.ThumbnailHandle; overlay.SetOverlayFlag(m_OverlayHandle, VROverlayFlags.SendVRDiscreteScrollEvents, true); diff --git a/VRDash/UI/BrowserOverlayEditor.xaml b/VRDash/UI/BrowserOverlayEditor.xaml new file mode 100644 index 0000000..a7a42e1 --- /dev/null +++ b/VRDash/UI/BrowserOverlayEditor.xaml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + Name: + + + Content Type: + + + Content: + + + diff --git a/VRDash/UI/BrowserOverlayEditor.xaml.cs b/VRDash/UI/BrowserOverlayEditor.xaml.cs new file mode 100644 index 0000000..c15c95a --- /dev/null +++ b/VRDash/UI/BrowserOverlayEditor.xaml.cs @@ -0,0 +1,80 @@ +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 VRDash.Overlay.Config; + +namespace VRDash.UI +{ + /// + /// Interaction logic for BrowserOverlayConfigEditor.xaml + /// + public partial class BrowserOverlayEditor : UserControl, IOverlayEditor + { + public BrowserOverlayEditor(BrowserOverlayConfig config) + { + InitializeComponent(); + DataContext = this; + OverlayConfig = config; + cbContentType.ItemsSource = Enum.GetValues(typeof(BrowserOverlayConfig.BrowserOverlayContentType)); + + UpdateGui(); + } + + public IOverlayConfig Config { get { return OverlayConfig; } } + public BrowserOverlayConfig OverlayConfig { get; private set; } + + public string[] ValidateInput() + { + List issues = new List(); + + if (String.IsNullOrWhiteSpace(Config.Name)) + { + issues.Add("Please enter a name."); + } + + if(cbContentType.SelectedIndex < 0) + { + issues.Add("Please select a content type."); + } + + return issues.ToArray(); + } + + private void UpdateGui() + { + if (cbContentType.SelectedItem != null) + { + var contentType = (BrowserOverlayConfig.BrowserOverlayContentType)cbContentType.SelectedItem; + tbContent.Text = ""; + if (contentType == BrowserOverlayConfig.BrowserOverlayContentType.Html) + { + tbContent.AcceptsReturn = true; + tbContent.MinHeight = 400; + } + else + { + tbContent.AcceptsReturn = false; + tbContent.MinHeight = 0; + } + + lblContent.Text = cbContentType.SelectedItem.ToString() + ":"; + } + } + + private void cbContentType_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + UpdateGui(); + } + } +} diff --git a/VRDash/UI/BrowserOverlayListViewItem.xaml b/VRDash/UI/BrowserOverlayListViewItem.xaml new file mode 100644 index 0000000..bd73c7a --- /dev/null +++ b/VRDash/UI/BrowserOverlayListViewItem.xaml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + Name + Loading... + Loading... + + diff --git a/VRDash/UI/BrowserOverlayListViewItem.xaml.cs b/VRDash/UI/BrowserOverlayListViewItem.xaml.cs new file mode 100644 index 0000000..f441cf4 --- /dev/null +++ b/VRDash/UI/BrowserOverlayListViewItem.xaml.cs @@ -0,0 +1,61 @@ +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 System.Windows.Threading; +using VRDash.Overlay; + +namespace VRDash.UI +{ + /// + /// Interaction logic for BrowserOverlayListViewItem.xaml + /// + public partial class BrowserOverlayListViewItem : UserControl,IDisposable,IOverlayListViewItem + { + public BrowserOverlay Overlay { get { return (BrowserOverlay)OverlayInfo.Overlay; } } + + public OverlayEditorInfo OverlayInfo { get; private set; } + + DispatcherTimer m_Timer = null; + public BrowserOverlayListViewItem(OverlayEditorInfo overlayInfo) + { + InitializeComponent(); + OverlayInfo = overlayInfo; + + m_Timer = new DispatcherTimer(new TimeSpan(0, 0, 0, 0, 300), DispatcherPriority.Normal, OnTimerTick, this.Dispatcher); + m_Timer.Start(); + } + + private void TestShit() + { + + } + + private void OnTimerTick(object x, object y) + { + tbName.Text = Overlay.OverlayConfig.Name; + tbFPS.Text = $"{Overlay.CurrentFPS} FPS"; + tbURL.Text = "Placeholder"; + } + + public void Dispose() + { + m_Timer?.Stop(); + } + + private void UserControl_MouseDoubleClick(object sender, MouseButtonEventArgs e) + { + Overlay.Show(); + } + } +} diff --git a/VRDash/UI/ProcessSelectorEditor.xaml b/VRDash/UI/SelectorEditors/ProcessSelectorEditor.xaml similarity index 100% rename from VRDash/UI/ProcessSelectorEditor.xaml rename to VRDash/UI/SelectorEditors/ProcessSelectorEditor.xaml diff --git a/VRDash/UI/ProcessSelectorEditor.xaml.cs b/VRDash/UI/SelectorEditors/ProcessSelectorEditor.xaml.cs similarity index 100% rename from VRDash/UI/ProcessSelectorEditor.xaml.cs rename to VRDash/UI/SelectorEditors/ProcessSelectorEditor.xaml.cs diff --git a/VRDash/UI/WindowSelectorEditor.xaml b/VRDash/UI/SelectorEditors/WindowSelectorEditor.xaml similarity index 100% rename from VRDash/UI/WindowSelectorEditor.xaml rename to VRDash/UI/SelectorEditors/WindowSelectorEditor.xaml diff --git a/VRDash/UI/WindowSelectorEditor.xaml.cs b/VRDash/UI/SelectorEditors/WindowSelectorEditor.xaml.cs similarity index 100% rename from VRDash/UI/WindowSelectorEditor.xaml.cs rename to VRDash/UI/SelectorEditors/WindowSelectorEditor.xaml.cs diff --git a/VRDash/VRDash.csproj b/VRDash/VRDash.csproj index 7eceaea..b271379 100644 --- a/VRDash/VRDash.csproj +++ b/VRDash/VRDash.csproj @@ -105,6 +105,7 @@ BrowserOverlay.xaml + @@ -127,6 +128,12 @@ ResizeWindowActionEditor.xaml + + BrowserOverlayEditor.xaml + + + BrowserOverlayListViewItem.xaml + CreateNewOverlay.xaml @@ -142,7 +149,7 @@ OverlayEditor.xaml - + ProcessSelectorEditor.xaml @@ -154,7 +161,7 @@ WindowOverlayListViewItem.xaml - + WindowSelectorEditor.xaml @@ -183,6 +190,14 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -199,7 +214,7 @@ Designer MSBuild:Compile - + Designer MSBuild:Compile @@ -215,7 +230,7 @@ Designer MSBuild:Compile - + Designer MSBuild:Compile