Esempio n. 1
0
 public void EnableHoverClick()
 {
     HoverClick   = new HoverClickHelper();
     OnMouseDown  = HoverClick.OnMouseDown;
     OnMouseUp    = HoverClick.OnMouseUp;
     OnMouseLeave = HoverClick.OnMouseLeave;
     OnUpdate     = HoverClick.Update;
     Root.RegisterForUpdate(this);
 }
Esempio n. 2
0
            public override void Construct()
            {
                Root.RegisterForUpdate(this);

                OnUpdate = (sender, time) =>
                {
                    Rect.X = Root.MousePosition.X - (Rect.Width / 2);
                    Rect.Y = Root.MousePosition.Y - (Rect.Height / 2);
                    Invalidate();

                    if (Mouse.GetState().LeftButton == ButtonState.Released)
                    {
                        bool successfullyDropped = false;

                        if (CanDropHere != null)
                        {
                            var target = Root.RootItem.EnumerateWidgetsAt(Root.MousePosition.X, Root.MousePosition.Y)
                                         .Where(w => CanDropHere(this, w))
                                         .FirstOrDefault();

                            if (target != null)
                            {
                                if (OnDropped != null)
                                {
                                    OnDropped(this, target);
                                }
                                successfullyDropped = true;
                            }
                        }

                        Root.Dragging = false;
                        Root.DestroyWidget(this);

                        if (!successfullyDropped && OnDropCancelled != null)
                        {
                            OnDropCancelled(this);
                        }
                    }
                };

                base.Construct();
            }