public override bool DragAndDrop_HandleDrop(Package p, int x, int y) { Point LocalPos = CanvasPosToLocal(new Point(x, y)); TabButton button = DragAndDrop.SourceControl as TabButton; TabControl tabControl = Parent as TabControl; if (tabControl != null && button != null) { if (button.TabControl != tabControl) { // We've moved tab controls! tabControl.AddPage(button); } } Base droppedOn = GetControlAt(LocalPos.X, LocalPos.Y); if (droppedOn != null) { Point dropPos = droppedOn.CanvasPosToLocal(new Point(x, y)); DragAndDrop.SourceControl.BringNextToControl(droppedOn, dropPos.X > droppedOn.Width/2); } else { DragAndDrop.SourceControl.BringToFront(); } return true; }
public override bool DragAndDrop_CanAcceptPackage(Package p) { if (!m_AllowReorder) return false; if (p.Name == "TabButtonMove") return true; return false; }
private static bool onDrop(int x, int y) { bool success = false; if (HoveredControl != null) { HoveredControl.DragAndDrop_HoverLeave(CurrentPackage); success = HoveredControl.DragAndDrop_HandleDrop(CurrentPackage, x, y); } // Report back to the source control, to tell it if we've been successful. SourceControl.DragAndDrop_EndDragging(success, x, y); CurrentPackage = null; SourceControl = null; return true; }
public static void ControlDeleted(Base control) { if (SourceControl == control) { SourceControl = null; CurrentPackage = null; HoveredControl = null; m_LastPressedControl = null; } if (m_LastPressedControl == control) m_LastPressedControl = null; if (HoveredControl == control) HoveredControl = null; if (m_NewHoveredControl == control) m_NewHoveredControl = null; }
private static bool ShouldStartDraggingControl( int x, int y ) { // We're not holding a control down.. if (m_LastPressedControl == null) return false; // Not been dragged far enough int length = Math.Abs(x - m_LastPressedPos.X) + Math.Abs(y - m_LastPressedPos.Y); if (length < 5) return false; // Create the dragging package CurrentPackage = m_LastPressedControl.DragAndDrop_GetPackage(m_LastPressedPos.X, m_LastPressedPos.Y); // We didn't create a package! if (CurrentPackage == null) { m_LastPressedControl = null; SourceControl = null; return false; } // Now we're dragging something! SourceControl = m_LastPressedControl; InputHandler.MouseFocus = null; m_LastPressedControl = null; CurrentPackage.DrawControl = null; // Some controls will want to decide whether they should be dragged at that moment. // This function is for them (it defaults to true) if (!SourceControl.DragAndDrop_ShouldStartDrag()) { SourceControl = null; CurrentPackage = null; return false; } SourceControl.DragAndDrop_StartDragging(CurrentPackage, m_LastPressedPos.X, m_LastPressedPos.Y); return true; }
public override bool DragAndDrop_HandleDrop (Package p, int x, int y) { var item = p.UserData as Tuple<int, int, InventoryButton, ItemComponent>; int pos_x = X / boxSize - item.Item1; int pos_y = Y / boxSize - item.Item2; int pos_w = item.Item3.Width / boxSize; int pos_h = item.Item3.Height / boxSize; if (pos_x < 0 || pos_x + pos_w >= inventory.Size.X || pos_y < 0 || pos_y + pos_h >= inventory.Size.Y) return false; var bar_pos = inventory.GetPositionOfBarItem(item.Item4); if (bar_pos < inventory.InventoryBar.Length) inventory.RemoveFromBar(bar_pos); var old_pos = inventory.GetPositionOfItem (item.Item4); inventory.TakeOut (item.Item4); if (inventory.Insert (item.Item4, new Vector2i (pos_x, pos_y))) { if (bar_pos < inventory.InventoryBar.Length) inventory.PutInBar(pos_x, pos_y, bar_pos); item.Item3.X = pos_x * boxSize + 1; item.Item3.Y = pos_y * boxSize + 1; return true; } if (!inventory.Insert (item.Item4, old_pos)) { Logger.Log.AddLogEntry (LogLevel.Error, "InventorySpace", "Lost an item from inventory!"); item.Item3.DelayedDelete (); } return false; }
// receiver public virtual void DragAndDrop_HoverLeave(Package p) { }
// receiver public virtual bool DragAndDrop_HandleDrop(Package p, int x, int y) { DragAndDrop.SourceControl.Parent = this; return true; }
public override bool DragAndDrop_HandleDrop (Package p, int x, int y) { var item = p.UserData as Tuple<int, int, InventoryButton, ItemComponent>; inventoryGui.dropItem(item.Item3, item.Item4, inventory); return false; }
public override void DragAndDrop_Hover(Package p, int x, int y) { Point localPos = CanvasPosToLocal(new Point(x, y)); Base droppedOn = GetControlAt(localPos.X, localPos.Y); if (droppedOn != null && droppedOn != this) { Point dropPos = droppedOn.CanvasPosToLocal(new Point(x, y)); m_TabDragControl.SetBounds(new Rectangle(0, 0, 3, Height)); m_TabDragControl.BringToFront(); m_TabDragControl.SetPosition(droppedOn.X - 1, 0); if (dropPos.X > droppedOn.Width/2) { m_TabDragControl.MoveBy(droppedOn.Width - 1, 0); } m_TabDragControl.Dock = Pos.None; } else { m_TabDragControl.Dock = Pos.Left; m_TabDragControl.BringToFront(); } }
public override void DragAndDrop_StartDragging(Package package, int x, int y) { DragAndDrop.SourceControl = Parent; DragAndDrop.SourceControl.DragAndDrop_StartDragging(package, x, y); }
public override void DragAndDrop_Hover(Package p, int x, int y) { Point pos = CanvasPosToLocal(new Point(x, y)); Pos dir = GetDroppedTabDirection(pos.X, pos.Y); if (dir == Pos.Fill) { if (null == m_DockedTabControl) { m_HoverRect = Rectangle.Empty; return; } m_HoverRect = InnerBounds; return; } m_HoverRect = RenderBounds; int HelpBarWidth = 0; if (dir == Pos.Left) { HelpBarWidth = (int)(m_HoverRect.Width * 0.25f); m_HoverRect.Width = HelpBarWidth; } if (dir == Pos.Right) { HelpBarWidth = (int)(m_HoverRect.Width * 0.25f); m_HoverRect.X = m_HoverRect.Width - HelpBarWidth; m_HoverRect.Width = HelpBarWidth; } if (dir == Pos.Top) { HelpBarWidth = (int)(m_HoverRect.Height * 0.25f); m_HoverRect.Height = HelpBarWidth; } if (dir == Pos.Bottom) { HelpBarWidth = (int)(m_HoverRect.Height * 0.25f); m_HoverRect.Y = m_HoverRect.Height - HelpBarWidth; m_HoverRect.Height = HelpBarWidth; } if ((dir == Pos.Top || dir == Pos.Bottom) && !m_DropFar) { if (m_Left != null && m_Left.IsVisible) { m_HoverRect.X += m_Left.Width; m_HoverRect.Width -= m_Left.Width; } if (m_Right != null && m_Right.IsVisible) { m_HoverRect.Width -= m_Right.Width; } } if ((dir == Pos.Left || dir == Pos.Right) && !m_DropFar) { if (m_Top != null && m_Top.IsVisible) { m_HoverRect.Y += m_Top.Height; m_HoverRect.Height -= m_Top.Height; } if (m_Bottom != null && m_Bottom.IsVisible) { m_HoverRect.Height -= m_Bottom.Height; } } }
public override void DragAndDrop_HoverEnter(Package p, int x, int y) { if (m_TabDragControl != null) { throw new InvalidOperationException("ERROR! TabStrip::DragAndDrop_HoverEnter"); } m_TabDragControl = new Highlight(this); m_TabDragControl.MouseInputEnabled = false; m_TabDragControl.SetSize(3, Height); }
public override void DragAndDrop_HoverEnter(Package p, int x, int y) { m_DrawHover = true; }
public override void DragAndDrop_HoverLeave(Package p) { m_DrawHover = false; }
public override bool DragAndDrop_HandleDrop(Package p, int x, int y) { Point pos = CanvasPosToLocal(new Point(x, y)); Pos dir = GetDroppedTabDirection(pos.X, pos.Y); DockedTabControl addTo = m_DockedTabControl; if (dir == Pos.Fill && addTo == null) return false; if (dir != Pos.Fill) { DockBase dock = GetChildDock(dir); addTo = dock.m_DockedTabControl; if (!m_DropFar) dock.BringToFront(); else dock.SendToBack(); } if (p.Name == "TabButtonMove") { TabButton tabButton = DragAndDrop.SourceControl as TabButton; if (null == tabButton) return false; addTo.AddPage(tabButton); } if (p.Name == "TabWindowMove") { DockedTabControl tabControl = DragAndDrop.SourceControl as DockedTabControl; if (null == tabControl) return false; if (tabControl == addTo) return false; tabControl.MoveTabsTo(addTo); } Invalidate(); return true; }
public override bool DragAndDrop_CanAcceptPackage(Package p) { // A TAB button dropped if (p.Name == "TabButtonMove") return true; // a TAB window dropped if (p.Name == "TabWindowMove") return true; return false; }
public override void DragAndDrop_HoverEnter (Package p, int x, int y) { ShouldDrawBackground = true; }
// receiver public virtual void DragAndDrop_Hover(Package p, int x, int y) { }
// receiver public virtual bool DragAndDrop_CanAcceptPackage(Package p) { if (DragAndDropCanAcceptPackage != null) return DragAndDropCanAcceptPackage.Invoke(this, p); return false; }
// receiver public virtual bool DragAndDrop_CanAcceptPackage(Package p) { return false; }
// receiver public virtual bool DragAndDrop_HandleDrop(Package p, int x, int y) { if (DragAndDropHandleDrop != null) return DragAndDropHandleDrop.Invoke(this,p,x,y); DragAndDrop.SourceControl.Parent = this; return true; }
public override void DragAndDrop_HoverLeave(Package p) { if (m_TabDragControl != null) { RemoveChild(m_TabDragControl, false); // [omeg] need to do that explicitely m_TabDragControl.Dispose(); } m_TabDragControl = null; }
public override void DragAndDrop_StartDragging (Package package, int x, int y) { package.UserData = this; Hide (); base.DragAndDrop_StartDragging (package, x, y); }
public override bool DragAndDrop_CanAcceptPackage (Package p) { return p.Name == "item_drag"; }
// giver public virtual void DragAndDrop_SetPackage(bool draggable, string name = "", object userData = null) { if (m_DragAndDrop_Package == null) { m_DragAndDrop_Package = new Package(); m_DragAndDrop_Package.IsDraggable = draggable; m_DragAndDrop_Package.Name = name; m_DragAndDrop_Package.UserData = userData; } }
public static bool Start(Base control, Package package) { if (CurrentPackage != null) { return false; } CurrentPackage = package; SourceControl = control; return true; }
// giver public virtual void DragAndDrop_StartDragging(Package package, int x, int y) { package.HoldOffset = CanvasPosToLocal(new Point(x, y)); package.DrawControl = this; }
public override bool DragAndDrop_HandleDrop (Package p, int x, int y) { if (p.Name == "bar_drag") { var invBarBtn = p.UserData as InventoryBarButton; if (invBarBtn != null) { var pos = (byte) (X / boxSize); invBarBtn.X = X; inventory.RemoveFromBar(pos); Parent.RemoveChild(this, true); inventory.MoveBarItemToPosition(invBarBtn.Item, pos); invBarBtn.Item.Entity.GetComponent<ModelComponent>().Model.Enabled = pos == inventory.ActiveBarPosition; invBarBtn.ToggleState = pos == inventory.ActiveBarPosition; return true; } } else if (p.Name == "item_drag") { var invBarTuple = p.UserData as Tuple<int, int, InventoryButton, ItemComponent>; if (invBarTuple != null) { var pos = (byte) (X / boxSize); inventory.RemoveFromBar(pos); Parent.RemoveChild(this, true); if (inventory.PutInBar(inventory.GetPositionOfItem(invBarTuple.Item4), pos)) { var btn = new InventoryBarButton(Parent, MessageProvider, barItems, inventory, inventoryGui, invBarTuple.Item4, pos, boxSize); barItems.Add(btn); btn.Item.Entity.GetComponent<ModelComponent>().Model.Enabled = pos == inventory.ActiveBarPosition; btn.ToggleState = pos == inventory.ActiveBarPosition; return true; } } } return false; }
public override void DragAndDrop_HoverLeave (Package p) { ShouldDrawBackground = false; }