private void CreateBlockAdornment(Microsoft.PowerToolsEx.BlockTagger.IBlockTag tag, SnapshotSpan span, double x, double yTop, double yBottom) { LineGeometry line = new LineGeometry(new Point(x, yTop), new Point(x, yBottom)); GeometryDrawing drawing = new GeometryDrawing(null, _coloring.GetLinePen(tag), line); drawing.Freeze(); DrawingImage drawingImage = new DrawingImage(drawing); drawingImage.Freeze(); Image image = new Image(); image.Source = drawingImage; VisibleBlock block = new VisibleBlock(tag, x, yTop, yBottom); Canvas.SetLeft(image, x); Canvas.SetTop(image, yTop); _layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, block, image, OnAdornmentRemoved); _visibleBlocks.Add(block); }
private void handleMouseScroll(object sender, MouseEventArgs e) { if (p_LogicDisabled) { return; } Point mousePosition = PointToClient(Cursor.Position); if (p_EventHijacker != null) { p_EventHijacker.OnMouseScroll(this, mousePosition, e); } //only scroll if no button is currently down if (p_Cursor.MouseButton != MouseButtons.None) { return; } //get the block where the mouse is currently at bool hasBlock; VisibleBlock block = p_MapRenderer.TryGetBlockAtPoint(p_Window.Context, mousePosition, out hasBlock); //adjust zoom int v = (e.Delta < 0 ? -1 : 1); p_Camera.Scale(v * 10); //move camera to the block where the mouse is. if (hasBlock) { p_Camera.MoveCenter(block.BlockX, block.BlockY); } }
public VisibleBlock GetBlockAtPoint(IRenderContext context, Point pt) { bool found; VisibleBlock ret = TryGetBlockAtPoint(context, pt, out found); if (!found) { throw new Exception("No block was found at the position: " + pt); } return(ret); }
// Visible block list public static void ReadMOVB(Stream WMOrootstream, int MOVBsize) { List <VisibleBlock> VisibleBlocks = new List <VisibleBlock>(); int blockCount = MOVBsize / 4; for (int i = 0; i < blockCount; ++i) { VisibleBlock block = new VisibleBlock(); block.firstVertex = ReadShort(WMOrootstream); block.count = ReadShort(WMOrootstream); VisibleBlocks.Add(block); } }
private void updateDebug() { #region get debug string string dbgString = p_RenderHeartbeat.Rate + "fps"; try { p_Window.Invoke(new MethodInvoker(delegate { try { p_Window.Text = dbgString + " (" + p_Window.Renderer + ") Build: " + Globals.BUILD; } catch { } })); } catch { } Fog fog = p_CurrentPlayer.Fog; if (p_DebugFull) { Point mousePosition = Point.Empty; try { mousePosition = (Point)p_Window.Invoke((Func <Point>) delegate { return(p_Window.PointToClient(Cursor.Position)); }); } catch { } VisibleBlock blockAtCursor = p_MapRenderer.TryGetBlockAtPoint(p_Window.Context, mousePosition); dbgString = "Keys: keys[" + p_CurrentKeys + "] arw[" + p_ArrowKeyDown + "]\n" + "Camera position: " + p_Camera.X + "x" + p_Camera.Y + "\n" + "Vertices: " + p_Window.Renderer.Vertices + "\n" + "Blocks rendered: " + p_MapRenderer.VisibleBlocks.Count + "\n" + "Blocks revealed: " + fog.BlocksRevealed + "/" + (p_Map.Width * p_Map.Height) + " [" + (fog.BlocksRevealed * 1.0f / (p_Map.Width * p_Map.Height) * 100).ToString("0.00") + "%]\n" + "Block size: " + p_Camera.BlockSize + " (" + (p_Camera.BlockSizeScalar * 100).ToString("0.00") + "%)\n" + "Cursor position: [L]" + getPointString(mousePosition) + " [S]" + getPointString(Cursor.Position) + " [B]" + getPointString(new Point(blockAtCursor.BlockX, blockAtCursor.BlockY)) + "\n" + "Window size: " + getSizeString(new Size(p_Window.Context.Width, p_Window.Context.Height)) + "\n" + "Render: " + getHeartbeatString(p_RenderHeartbeat) + "\n" + "Logic: " + getHeartbeatString(p_LogicHeartbeat); } #endregion p_DebugLabel.Text = dbgString; p_DebugLabel.Location = new Point( p_Window.Context.Width - p_DebugLabel.Width - 10, p_Window.Context.Height - p_DebugLabel.Height - 10); }
private unsafe void pathTest(Point mousePosition, MouseButtons button) { Block * matrix = Map.GetBlockMatrix(); VisibleBlock vBlock = default(VisibleBlock); try { vBlock = p_MapRenderer.GetBlockAtPoint(p_Window.Context, mousePosition); } catch { return; } Point blockLocation = new Point( vBlock.BlockX, vBlock.BlockY); Block *block = vBlock.Block; if (block == (Block *)0) { return; } // if (button == MouseButtons.None) { return; } Block *ptr = matrix; Block *ptrEnd = ptr + (Map.Width * Map.Height); while (ptr != ptrEnd) { (*(ptr++)).Selected = false; } if (button == MouseButtons.Left) { pathStart = blockLocation; return; } if (button == MouseButtons.Right) { List <Point> path = Pathfinder.ASSearch( pathStart, blockLocation, Map.GetConcreteMatrix(true), Map.Width, Map.Height); if (path.Count == 0) { MessageBox.Show("Path not found!"); } foreach (Point p in path) { Block *b = matrix + (p.Y * Map.Width) + p.X; if ((*b).TypeID == Globals.TERRAIN_WATER) { break; } (*b).Selected = true; } } }
protected override void AddAdornmentsToAdornmentLayer_CallOnlyOnUIThread(NormalizedSnapshotSpanCollection changedSpanCollection) { // this method should only run on UI thread as we do WPF here. Contract.ThrowIfFalse(TextView.VisualElement.Dispatcher.CheckAccess()); var viewSnapshot = TextView.TextSnapshot; var viewLines = TextView.TextViewLines; foreach (var changedSpan in changedSpanCollection) { if (!viewLines.IntersectsBufferSpan(changedSpan)) { continue; } var tagSpans = TagAggregator.GetTags(changedSpan); foreach (var tagMappingSpan in tagSpans) { if (!ShouldDrawTag(changedSpan, tagMappingSpan, out _)) { continue; } if (!TryMapToSingleSnapshotSpan(tagMappingSpan.Span, TextView.TextSnapshot, out var span)) { continue; } if (!TryMapHoleSpans(tagMappingSpan.Tag.OrderedHoleSpans, out var orderedHoleSpans)) { continue; } if (VisibleBlock.CreateVisibleBlock(span, orderedHoleSpans, TextView) is not VisibleBlock block) { continue; } var tag = tagMappingSpan.Tag; var brush = tag.GetBrush(TextView); foreach (var(start, end) in block.YSegments) { var line = new Line { SnapsToDevicePixels = true, StrokeThickness = 1.0, X1 = block.X, X2 = block.X, Y1 = start, Y2 = end, Stroke = brush, }; AdornmentLayer.AddAdornment( behavior: AdornmentPositioningBehavior.TextRelative, visualSpan: span, tag: block, adornment: line, removedCallback: delegate { }); } } } }
private void drawCoastBlock(IRenderContext context, IRenderer renderer, VisibleBlock vBlock) { //get info Map map = p_Map; Block *matrix = map.GetBlockMatrix(); Block *block = vBlock.Block; int size = p_Camera.BlockSize; int width = map.Width; int height = map.Height; int blockSize = p_Camera.BlockSize; int shadowSize = 10; //coastal? Direction direction; if (!isCoastline(block, matrix, out direction, vBlock.BlockX, vBlock.BlockY, width, height)) { return; } /*define gradient start/end x/y*/ int gradientStartX, gradientStartY, gradientEndX, gradientEndY; Color gColor1 = changeLight(Globals.COLOR_TERRAIN_WATER, 0.4f); Color gColor2 = Color.Transparent; #region draw basic border /* * reduce down the direction to get each individual direction * by using bitwise operators. */ byte directionANDCurrent = (byte)0x08; int dX = 0, dY = 0; while (directionANDCurrent != 0) { Direction current = (direction & (Direction)directionANDCurrent); directionANDCurrent >>= 1; if (current == Direction.NONE) { continue; } int x, y, w, h; x = y = w = h = 0; /**/ bool isNorth = current == Direction.NORTH; bool isSouth = current == Direction.SOUTH; bool isWest = current == Direction.WEST; bool isEast = current == Direction.EAST; //reset gradient position gradientStartX = gradientStartY = gradientEndX = gradientEndY = 0; #region North/South if (isNorth || isSouth) { w = blockSize; h = shadowSize; } if (isNorth) { y -= shadowSize; dY = -1; gradientEndY = -shadowSize - 1; } if (isSouth) { y = blockSize; dY = 1; gradientStartY = blockSize - 1; gradientEndY = blockSize + shadowSize + 1; } #endregion #region West/East if (isWest || isEast) { w = shadowSize; h = blockSize; } if (isWest) { x = -shadowSize; dX = -1; gradientEndX = -shadowSize - 1; } if (isEast) { x = blockSize; dX = 1; gradientStartX = blockSize - 1; gradientEndX = blockSize + shadowSize + 1; } #endregion gradientStartX += vBlock.RenderX; gradientStartY += vBlock.RenderY; gradientEndX += vBlock.RenderX; gradientEndY += vBlock.RenderY; x += vBlock.RenderX; y += vBlock.RenderY; renderer.SetBrush(new LinearGradientBrush( new Point(gradientStartX, gradientStartY), new Point(gradientEndX, gradientEndY), gColor1, gColor2)); renderer.FillQuad(x, y, w, h); } #endregion gradientStartX = gradientStartY = gradientEndX = gradientEndY = 0; #region draw diagonal //can be diagonal? if (dX == 0 || dY == 0) { return; } /*get render location of the square*/ int rX = vBlock.RenderX; int rY = vBlock.RenderY; if (dX < 0) { rX -= shadowSize; } else { rX += blockSize; } if (dY < 0) { rY -= shadowSize; } else { rY += blockSize; } /*define gradient information (default to NORTH_WEST)*/ int centerOffsetX = shadowSize; int centerOffsetY = shadowSize; int rectOffsetX = 0; int rectOffsetY = 0; /*north east?*/ if (dX > 0 && dY < 0) { centerOffsetX = 0; rectOffsetX += shadowSize; } /*south west?*/ if (dX < 0 && dY > 0) { centerOffsetY = 0; rectOffsetY += shadowSize; } /*south east*/ if (dX > 0 && dY > 0) { centerOffsetX = 0; centerOffsetY = 0; rectOffsetX += shadowSize; rectOffsetY += shadowSize; } GraphicsPath path = new GraphicsPath(); path.AddRectangle( new Rectangle( rX - rectOffsetX, rY - rectOffsetY, shadowSize * 2, shadowSize * 2)); PathGradientBrush brush = new PathGradientBrush(path); brush.CenterPoint = new PointF(rX + centerOffsetX, rY + centerOffsetY); brush.CenterColor = gColor1; brush.SurroundColors = new Color[] { gColor2 }; renderer.SetBrush(brush); renderer.FillQuad( rX, rY, shadowSize, shadowSize); #endregion }
private void drawBlock(IRenderContext context, IRenderer renderer, VisibleBlock vBlock, bool *los) { Block block = *vBlock.Block; Color color = Globals.COLOR_TERRAIN_GRASS; Camera camera = p_Camera; int blockSize = camera.BlockSize; switch (block.TypeID) { case Globals.TERRAIN_WATER: color = Globals.COLOR_TERRAIN_WATER; break; case Globals.RESOURCE_WOOD: color = Color.Brown; break; case Globals.RESOURCE_FOOD: color = Color.Red; break; case Globals.RESOURCE_STONE: color = Color.Gray; break; case Globals.RESOURCE_GOLD: color = Color.Gold; break; } /*add depth to water and grass*/ if (block.TypeID == Globals.TERRAIN_GRASS) { color = getColorAtPoint( Globals.COLOR_TERRAIN_GRASS, Color.Black, (block.Height * 1.0f / 150)); } if (block.TypeID == Globals.TERRAIN_WATER) { color = getColorAtPoint( Globals.COLOR_TERRAIN_WATER, changeLight(Globals.COLOR_TERRAIN_WATER, .4f), (block.Height * 1.0f / 100)); } if (block.Selected) { color = Color.White; } //render the block renderer.SetBrush(new SolidBrush(color)); renderer.FillQuad(vBlock.RenderX, vBlock.RenderY, camera.BlockSize, camera.BlockSize); /*draw LOS*/ if (los != (bool *)0) { bool hasLOS = *(los + (vBlock.BlockY * p_Map.Width) + vBlock.BlockX); color = Color.FromArgb(hasLOS ? 0 : 140, Color.Black); renderer.SetBrush(new SolidBrush(color)); renderer.FillQuad( vBlock.RenderX, vBlock.RenderY, blockSize, blockSize); } /*draw grid*/ if (p_ShowGrid) { renderer.SetPen(new Pen(new SolidBrush(Color.FromArgb(40, Color.Black)))); renderer.DrawQuad( vBlock.RenderX, vBlock.RenderY, blockSize, blockSize); } }