diff --git a/Perspex.Windows/Threading/Dispatcher.cs b/Perspex.Windows/Threading/Dispatcher.cs index 7ff6e569d9..afd8bda776 100644 --- a/Perspex.Windows/Threading/Dispatcher.cs +++ b/Perspex.Windows/Threading/Dispatcher.cs @@ -220,7 +220,7 @@ namespace Perspex.Windows.Threading [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public DispatcherOperation BeginInvoke(DispatcherPriority priority, Delegate method) + public DispatcherOperation BeginInvoke(DispatcherPriority priority, Action method) { if (priority < 0 || priority > DispatcherPriority.Send) { diff --git a/Perspex.Windows/Window.cs b/Perspex.Windows/Window.cs index ee93c754f0..4e5d6c8e40 100644 --- a/Perspex.Windows/Window.cs +++ b/Perspex.Windows/Window.cs @@ -7,6 +7,7 @@ using Perspex.Controls; using Perspex.Layout; using Perspex.Windows.Interop; + using Perspex.Windows.Threading; public class Window : ContentControl, ILayoutRoot { @@ -31,11 +32,13 @@ this.LayoutManager = new LayoutManager(); this.renderer = new Renderer(this.Handle, (int)clientSize.Width, (int)clientSize.Height); - // TODO: Do this by pushing to Dispatcher rather than right away! this.LayoutManager.LayoutNeeded.Subscribe(x => { - this.LayoutManager.ExecuteLayoutPass(); - this.renderer.Render(this); + Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Render, () => + { + this.LayoutManager.ExecuteLayoutPass(); + this.renderer.Render(this); + }); }); } @@ -121,6 +124,16 @@ } } + private void MouseMove(Visual visual, Point p) + { + visual.IsMouseOver = visual.Bounds.Contains(p); + + foreach (Visual child in visual.VisualChildren) + { + this.MouseMove(child, p - visual.Bounds.Position); + } + } + [SuppressMessage("Microsoft.StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", Justification = "Using Win32 naming for consistency.")] private IntPtr WndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam) { @@ -146,9 +159,9 @@ //// InputManager.Current.ProcessInput(new RawMouseEventArgs(mouse, RawMouseEventType.LeftButtonUp)); //// break; - ////case UnmanagedMethods.WindowsMessage.WM_MOUSEMOVE: - //// InputManager.Current.ProcessInput(new RawMouseEventArgs(mouse, RawMouseEventType.Move)); - //// break; + case UnmanagedMethods.WindowsMessage.WM_MOUSEMOVE: + this.MouseMove(this, new Point((uint)lParam & 0xffff, (uint)lParam >> 16)); + break; case UnmanagedMethods.WindowsMessage.WM_SIZE: this.renderer.Resize((int)lParam & 0xffff, (int)lParam >> 16); diff --git a/Perspex/Controls/Border.cs b/Perspex/Controls/Border.cs index 74e30eb51b..655640ccba 100644 --- a/Perspex/Controls/Border.cs +++ b/Perspex/Controls/Border.cs @@ -1,6 +1,7 @@ namespace Perspex.Controls { - using System.Diagnostics.Contracts; + using System; + using System.Reactive.Linq; using Perspex.Media; public class Border : Decorator @@ -13,6 +14,10 @@ if (background != null) { + System.Diagnostics.Debug.WriteLine( + string.Format("{0} Draw Background={1}", + this.GetHashCode(), + background)); context.FillRectange(background, new Rect(this.Bounds.Size)); } diff --git a/Perspex/Controls/Button.cs b/Perspex/Controls/Button.cs index 9afb22c4ab..f4364becab 100644 --- a/Perspex/Controls/Button.cs +++ b/Perspex/Controls/Button.cs @@ -6,6 +6,8 @@ namespace Perspex.Controls { + using System; + public class Button : ContentControl { protected override Visual DefaultTemplate() diff --git a/Perspex/Controls/ContentControl.cs b/Perspex/Controls/ContentControl.cs index 5c60e4402a..99999ef4b4 100644 --- a/Perspex/Controls/ContentControl.cs +++ b/Perspex/Controls/ContentControl.cs @@ -1,6 +1,7 @@ namespace Perspex.Controls { using System; + using System.Collections.Generic; using System.Linq; public abstract class ContentControl : TemplatedControl @@ -12,10 +13,12 @@ { this.GetObservable(ContentProperty).Subscribe(x => { + Visual visual = x as Visual; Control control = x as Control; if (control != null) { + control.VisualParent = this; control.SetValue(ParentPropertyRW, this); } }); diff --git a/Perspex/Controls/ContentPresenter.cs b/Perspex/Controls/ContentPresenter.cs index 95b38e7222..8c2a22e709 100644 --- a/Perspex/Controls/ContentPresenter.cs +++ b/Perspex/Controls/ContentPresenter.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Linq; + using Perspex.Media; public class ContentPresenter : Control { diff --git a/Perspex/Controls/Control.cs b/Perspex/Controls/Control.cs index 0d99008821..b7aafef1d9 100644 --- a/Perspex/Controls/Control.cs +++ b/Perspex/Controls/Control.cs @@ -1,11 +1,12 @@ namespace Perspex.Controls { using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Diagnostics.Contracts; -using Perspex.Layout; -using Perspex.Media; + using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.Diagnostics.Contracts; + using System.Reactive.Linq; + using Perspex.Layout; + using Perspex.Media; public enum HorizontalAlignment { @@ -54,6 +55,9 @@ using Perspex.Media; this.Classes = new ObservableCollection(); this.Styles = new ObservableCollection