public void OnMouseUp(MouseEventArgs e, MapToolContext ctx) { if (e.Button == MouseButtons.Left) { isPanning = false; } }
public void OnMouseUp(MouseEventArgs e, MapToolContext ctx) { if (isDragging && e.Button == MouseButtons.Left) { Point tileDelta = GetTileDelta(e, ctx); if (IsValidDropPos(tileDelta)) { // The drop location is valid; delete all tiles to be moved then recreate them in their // new location. foreach (var selectedItem in selectionService.SelectedItems) { mapService.DeleteTile(selectedItem.Bounds.Location); } foreach (var selectedItem in selectionService.SelectedItems) { Point newLocation = selectedItem.Bounds.Location; newLocation.Offset(tileDelta); mapService.AddItem(selectedItem.Item, newLocation); } selectionService.ApplyTileDelta(tileDelta); } else { MessageBox.Show(ctx.Viewport, "This space is already occupied", "Unable to Move Items", MessageBoxButtons.OK, MessageBoxIcon.Error); } isDragging = false; selectionRenderer.TileOffset = Point.Empty; } }
public bool ModifySelection(Point controlPt, MapToolContext ctx, SelectionAction action) { bool selectionChanged; if (TryGetItemFromViewportPt(controlPt, ctx, out var item, out var itemTileBounds)) { Item itemCopy = new Item(item.RawValue); Debug.Assert(itemCopy.IsRoot); SelectedItem selectedItem = new SelectedItem(itemCopy, itemTileBounds); switch (action) { case SelectionAction.Add: selectionChanged = selectedItems.Add(selectedItem); break; case SelectionAction.Remove: selectionChanged = selectedItems.Remove(selectedItem); break; default: throw new ArgumentOutOfRangeException(nameof(action), action, null); } if (selectionChanged) { OnSelectionChanged(); } }
protected override void CalculateResult(MapToolContext ctx, Rectangle marqueeBounds, out ItemFieldFragment fragment, out string hint) { Rectangle tileRect = ctx.ToTiles(marqueeBounds); fragment = new ItemFieldFragment(); segmentLayout.CalculateResult(ctx, tileRect, fragment); hint = ""; //droppedItemCount > 0 ? $"{droppedItemCount} Items" : "-"; }
protected override void OnClick(MouseEventArgs e, Keys modifierKeys, MapToolContext ctx) { if (ctx.MapEditingService.AddItem(item, ctx.ToTile(e.Location), this.transaction, CollisionAction.Abort)) { ctx.Viewport.Invalidate(); } }
public void OnMouseMove(MouseEventArgs e, MapToolContext ctx) { if (isPanning) { Size delta = panStartLocation.Subtract(e.Location); ctx.Viewport.ScrollPosition = Point.Add(panStartScrollPosition, delta); } }
public void OnMouseMove(MouseEventArgs e, MapToolContext ctx) { if (isDragging) { Point tileOffset = GetTileDelta(e, ctx); selectionRenderer.TileOffset = tileOffset; } }
public void OnMouseUp(MouseEventArgs e, MapToolContext ctx) { if (this.isDragging && e.Button == MouseButtons.Left) { this.isDragging = false; this.renderer.MarqueeBounds = Rectangle.Empty; } }
protected override void OnClick(MouseEventArgs e, Keys modifierKeys, MapToolContext ctx) { lastTile = ctx.ToTile(e.Location); if (ctx.MapEditingService.DeleteTile(lastTile, transaction, true)) { ctx.Viewport.Invalidate(); } }
public void OnMouseDown(MouseEventArgs e, MapToolContext ctx) { if (e.Button == MouseButtons.Left) { this.panStartScrollPosition = ctx.Viewport.ScrollPosition; this.panStartLocation = e.Location; isPanning = true; } }
private Point GetItemPoint(MapToolContext ctx, Point clientPt) { var tilePt = ctx.ToTile(clientPt); tilePt = new Point( tilePt.X - (tilePt.X - startTile.X) % itemSize.Width, tilePt.Y - (tilePt.Y - startTile.Y) % itemSize.Height); return(tilePt); }
public void OnMouseDown(MouseEventArgs e, MapToolContext ctx) { if (e.Button == MouseButtons.Left) { this.dragStart = e.Location; this.dragEnd = e.Location; this.isDragging = true; } }
public void OnMouseUp(MouseEventArgs e, Keys modifierKeys, MapToolContext ctx) { if (mouseAction != null && e.Button == mouseActionButton) { mouseAction.OnMouseUp(e, modifierKeys, ctx); mouseAction.UnbindViewport(ctx.Viewport); mouseAction.Dispose(); mouseAction = null; } }
protected override void OnClick(MouseEventArgs e, Keys modifierKeys, MapToolContext ctx) { if (e.Button == MouseButtons.Left) { ctx.Viewport.Zoom(ctx.Viewport.ZoomLevel + 1, e.Location); } else if (e.Button == MouseButtons.Right) { ctx.Viewport.Zoom(ctx.Viewport.ZoomLevel - 1, e.Location); } }
public void OnMouseDown(MouseEventArgs e, MapToolContext ctx) { if (e.Button == MouseButtons.Left) { ctx.Viewport.Zoom(ctx.Viewport.ZoomLevel + 1, e.Location); } else if (e.Button == MouseButtons.Right) { ctx.Viewport.Zoom(ctx.Viewport.ZoomLevel - 1, e.Location); } }
public void OnMouseMove(MouseEventArgs e, MapToolContext ctx) { if (this.isDragging) { this.dragEnd = e.Location; var marqueeBounds = GetMarqueeBounds(); this.renderer.MarqueeBounds = marqueeBounds; this.selectionService.ClearSelection(); this.selectionService.ModifySelection(marqueeBounds, ctx, SelectionAction.Add); } }
public void OnMouseDown(MouseEventArgs e, Keys modifierKeys, MapToolContext ctx) { Point tilePt = ctx.ToTile(e.Location); Item item = ctx.MapEditingService.GetItem(tilePt, true); if (item != null) { Item itemCopy = new Item(); itemCopy.CopyFrom(item); pickTarget.Pick(itemCopy); } }
public void OnMouseMove(MouseEventArgs mouseEventArgs, Keys modifierKeys, MapToolContext ctx) { if (IsDragging) { OnDragMove(mouseEventArgs, modifierKeys, ctx); } else if (this.originArgs != null && mouseEventArgs.Location.GetDistance(this.originArgs.Location) > DragThreshold) { IsDragging = true; OnDragStart(originArgs, modifierKeys, ctx); } }
public virtual void OnMouseDown(MouseEventArgs e, Keys modifierKeys, MapToolContext ctx) { if (this.mouseAction == null) { this.mouseAction = GetMouseAction(e, modifierKeys, ctx); if (this.mouseAction != null) { mouseAction.BindViewport(ctx.Viewport); this.mouseAction.OnMouseDown(e, modifierKeys, ctx); this.mouseActionButton = e.Button; } } }
public void OnMouseUp(MouseEventArgs mouseEventArgs, Keys modifierKeys, MapToolContext ctx) { if (IsDragging) { IsDragging = false; OnDragEnd(mouseEventArgs, modifierKeys, ctx); } else { OnClick(mouseEventArgs, modifierKeys, ctx); } this.originArgs = null; }
public void CalculateResult(MapToolContext ctx, Rectangle tileRect, ItemFieldFragment fragment) { if (tileRect.Size.Encompasses(placedItemSize)) { Rectangle placedItemRect = new Rectangle(tileRect.Location, placedItemSize); fragment.Add(placedItemRect, placedItem, ctx.MapEditingService.IsOccupied(placedItemRect)); if (recipeItem != null) { for (int y = tileRect.Top; y + recipeItemSize.Height <= tileRect.Bottom; y += recipeItemSize.Height) { Rectangle recipeItemRect = new Rectangle(tileRect.Left, y, recipeItemSize.Width, recipeItemSize.Height); if (recipeItemRect.IntersectsWith(placedItemRect)) { continue; } fragment.Add(recipeItemRect, recipeItem, ctx.MapEditingService.IsOccupied(recipeItemRect)); } } int droppedItemTop = placedItemRect.Top + droppedItemSize.Height - (placedItemRect.Height % droppedItemSize.Height); int doppedItemsPerColumn = (tileRect.Bottom - droppedItemTop) / droppedItemSize.Height; if (droppedItems.Count > 0) { for (int x = tileRect.Left + recipeItemSize.Width; x + droppedItemSize.Width <= tileRect.Right; x += droppedItemSize.Width) { for (int y = 0; y < doppedItemsPerColumn; y++) { Rectangle droppedItemRect = new Rectangle(x, droppedItemTop + y * droppedItemSize.Height, droppedItemSize.Width, droppedItemSize.Height); if (droppedItemRect.IntersectsWith(placedItemRect)) { continue; } var droppedItemIndex = (int)(y / ((float)doppedItemsPerColumn / droppedItems.Count)); var droppedItem = droppedItems[droppedItemIndex]; fragment.Add(droppedItemRect, droppedItem, ctx.MapEditingService.IsOccupied(droppedItemRect)); } } } } }
protected override void CalculateResult(MapToolContext ctx, Rectangle marqueeBounds, out ItemFieldFragment fragment, out string hint) { fragment = new ItemFieldFragment(); var tileRect = ctx.ToTiles(marqueeBounds); for (int x = tileRect.Left; x <= tileRect.Right - itemSize.Width; x += itemSize.Width) { for (int y = tileRect.Top; y <= tileRect.Bottom - itemSize.Height; y += itemSize.Height) { Rectangle itemTileRect = new Rectangle(x, y, itemSize.Width, itemSize.Height); fragment.Add(itemTileRect, item, ctx.MapEditingService.IsOccupied(itemTileRect)); } } int itemsX = tileRect.Width / itemSize.Width; int itemsY = tileRect.Height / itemSize.Height; hint = $"{itemsX} × {itemsY}"; }
public void OnMouseDown(MouseEventArgs e, MapToolContext ctx) { if (e.Button == MouseButtons.Left) { Point tilePt = ctx.ToTile(e.Location); // If the cursor is not on a selected tile then clear the selection and select // the tile directly under the cursor. if (!selectionService.SelectedItems.Any(i => i.Bounds.Contains(tilePt))) { selectionService.ClearSelection(); selectionService.ModifySelection(e.Location, ctx, SelectionAction.Add); } if (selectionService.SelectedItems.Any()) { this.isDragging = true; this.dragStart = e.Location; } } }
public bool ModifySelection(Rectangle marqueeBounds, MapToolContext ctx, SelectionAction action) { bool selectionChanged = false; var tileBounds = ctx.ToTiles(marqueeBounds); for (int tileX = tileBounds.Left; tileX < tileBounds.Right; tileX++) { for (int tileY = tileBounds.Top; tileY < tileBounds.Bottom; tileY++) { if (TryGetItemFromItemPt(new Point(tileX, tileY), out var item, out var itemTileBounds)) { Item itemCopy = new Item(item.RawValue); Debug.Assert(itemCopy.IsRoot); SelectedItem selectedItem = new SelectedItem(itemCopy, itemTileBounds); switch (action) { case SelectionAction.Add: selectionChanged |= selectedItems.Add(selectedItem); break; case SelectionAction.Remove: selectionChanged |= selectedItems.Remove(selectedItem); break; default: throw new ArgumentOutOfRangeException(nameof(action), action, null); } } } } if (selectionChanged) { OnSelectionChanged(); } return(selectionChanged); }
protected override void CalculateResult(MapToolContext ctx, Rectangle marqueeBounds, out ItemFieldFragment fragment, out string hint) { var tileRect = ctx.ToTiles(marqueeBounds).Quantize(2); fragment = new ItemFieldFragment(); hint = $"{segmentLayouts.Length} Item(s)"; if (layout.GetSegmentRects(tileRect, segmentLayouts, minSegementSizes, rowCount, out var segmentRects, out var templateHint)) { for (int segmentIndex = 0; segmentIndex < segmentLayouts.Length; segmentIndex++) { segmentLayouts[segmentIndex].CalculateResult(ctx, segmentRects[segmentIndex], fragment); } } if (!string.IsNullOrWhiteSpace(templateHint)) { hint = $"{hint} - {templateHint}"; } }
public override bool OnKeyDown(Keys e, MapToolContext ctx) { if (IsDragging) { if (e == Keys.Up) { if (rowCount < 50) { rowCount++; InvalidateFragment(ctx); } } else if (e == Keys.Down) { if (rowCount > 0) { rowCount--; InvalidateFragment(ctx); } } } return(true); }
public void OnMouseWheel(MouseEventArgs e, MapToolContext ctx) { ctx.Viewport.Zoom(ctx.Viewport.ZoomLevel + e.Delta / 120, e.Location); }
protected override IMouseAction GetMouseAction(MouseEventArgs e, Keys modifierKeys, MapToolContext ctx) { if (modifierKeys.HasFlag(Keys.Alt)) { return(new PanZoomMouseAction()); } else if (modifierKeys.HasFlag(Keys.Control)) { return(new PickAction(pickTarget)); } else { return(new PaintAction(historyService, options.GetItem())); } }
public void OnMouseWheel(MouseEventArgs e, MapToolContext ctx) { }
public void OnMouseMove(MouseEventArgs e, MapToolContext ctx) { }