internal static IntPtr RegisterDrawTarget(IDrawTarget target) { Graphics.nextHdc = IntPtr.Add(Graphics.nextHdc, 1); Graphics.drawTargets.Add(Graphics.nextHdc, target); return(Graphics.nextHdc); }
/// <see cref="ViewPort.Draw"/> public override void Draw(IDrawTarget drawTarget, Rectangle drawRect) { drawTarget.Clear(CGAColor.Black); for (int i = 0; i < this.players.Length; i++) { this.players[i].Draw(drawTarget, drawRect); } }
public override void Draw(IDrawTarget drawTarget, Rectangle drawRect) { drawTarget.Clear(this.backgroundColor); for (int i = 0; i < this.spritePositions.Length; i++) { drawTarget.DrawBitmap(this.testSprite, this.spritePositions[i].X, this.spritePositions[i].Y); } }
/// <summary> /// draw the path to a target /// </summary> /// <param name="target">the draw target</param> /// <param name="strokeSize">the stroke size, 0-1</param> public void DrawTo(IDrawTarget target, float strokeSize = 1) { // set the color and stroke target.SetPrimaryColor(color); target.SetStroke(strokeSize); // draw the path target.DrawPoly(Vertices); }
/// <summary> /// Draws this player to it's current position. /// </summary> /// <param name="drawTarget">The draw target in which to draw.</param> /// <param name="drawRect">The bounding rectangle in the draw target.</param> public void Draw(IDrawTarget drawTarget, Rectangle drawRect) { if (this.isActive) { /// Draw only if this is an active player. drawTarget.DrawBitmap(this.simulator.GetPlayerBitmap(this.currentColor), this.currentPosition.X, this.currentPosition.Y); } this.previousPosition = this.currentPosition; this.isDirty = false; }
/// <summary> /// Draw a list of dots dot-by-dot /// </summary> /// <param name="target">draw target</param> /// <param name="dots">the dot list</param> /// <param name="totalDots">the total number of dots (progress reporting)</param> /// <param name="dotsDrawn">the total number of dots drawn (progress reporting)</param> /// <returns>the number of dots drawn</returns> private int DrawUsingDots(IDrawTarget target, List <PointF> dots, double totalDots, double dotsDrawn) { // for every dot foreach (PointF dot in dots) { // draw the dot target.DrawDot(dot); // report progress dotsDrawn++; ReportProgress(dotsDrawn / totalDots); } return(dots.Count); }
/// <summary> /// Draw the dotmap to a target /// </summary> /// <param name="target">where to draw to</param> /// <param name="firstColorFill">should the first color be drawn using flood- fill? (canvas has to be empty for this to work well)</param> /// <param name="strokeSize">the stroke size, 0-1</param> /// <param name="mode">the draw mode</param> public void DrawTo(IDrawTarget target, bool firstColorFill, float strokeSize = 1, DrawMode mode = DrawMode.Dots) { strokeSize = Math.Clamp(strokeSize, 0, 1); double totalDots = TotalDots; double dotsDrawn = 0; bool useFill = firstColorFill; // set stroke size target.SetStroke(strokeSize); // draw colors in batches foreach (Color c in dotMap.Keys.OrderByDescending(cx => dotMap[cx].Count)) { if (dotMap[c].Count > 0) { // select the color target.SetPrimaryColor(c); // fill the first color using bucket tool if enabled if (useFill) { // bucket in the center of the image target.Fill(new PointF(.5f, .5f)); // add dots drawn to total dotsDrawn += dotMap[c].Count; useFill = false; continue; } // draw all dots if (mode == DrawMode.Dots) { dotsDrawn += DrawUsingDots(target, dotMap[c], totalDots, dotsDrawn); } else { dotsDrawn += DrawUsingPolys(target, dotMap[c], totalDots, dotsDrawn); } ReportProgress(dotsDrawn / totalDots); } } }
/// <summary> /// This function is called by the render system if this ViewPort is registered to the Display. /// You can implement this function in any ViewPort derived classes. The default implementation /// do nothing. /// </summary> /// <param name="drawTarget">The target of the draw operations.</param> /// <param name="drawRect">The rectangle in which to draw.</param> public virtual void Draw(IDrawTarget drawTarget, Rectangle drawRect) { }
public ManagedGraphics(IDrawTarget drawTarget) => this.drawTarget = drawTarget;
/// <summary> /// Draw a list of dots by drawing polygons /// </summary> /// <param name="target">draw target</param> /// <param name="dots">the dot list</param> /// <param name="totalDots">the total number of dots (progress reporting)</param> /// <param name="dotsDrawn">the total number of dots drawn (progress reporting)</param> /// <returns>the number of dots drawn</returns> private int DrawUsingPolys(IDrawTarget target, List <PointF> dots, double totalDots, double dotsDrawn) { // sort dots by x, then y dots.Sort((d1, d2) => { // Y 0 ==> Y 1 if (d1.X.Equals(d2.X)) { return(d1.Y.CompareTo(d2.Y)); } // X 0 ==> X 1 return(d1.X.CompareTo(d2.X)); }); // get the size of one dot // keep the sizes squared to safe (a few) sqrts float dotW = 1 / mapSize.Width; float dotH = 1 / mapSize.Height; float oneDotDiagonally = MathF.Abs((dotW * dotW) + (dotH * dotH)); // enumerate all dots, top to bottom and left to right List <PointF> poly = new List <PointF>(); foreach (PointF dot in dots) { // first dot requires special handling... if (poly.Count <= 0) { poly.Add(dot); continue; } // get distance to last dot float dist = DotDistanceSq(dot, poly.Last()); // if the dot is less than 1 dot (diagonally) away from the last, just add it to the polygon // otherwise, draw the polygon, and start a new one if (MathF.Abs(dist) > oneDotDiagonally) { //remove all dots in the poly that are in a direct line to another dot in the poly //such that they are not needed for drawing PointF l = poly[0]; for (int i = 1; i < (poly.Count - 1); i++) { PointF c = poly[i]; if (MathF.Abs(c.X - l.X) < dotW || MathF.Abs(c.Y - l.Y) < dotH) { poly.RemoveAt(i); continue; } l = c; } // draw and reset poly target.DrawPoly(poly.ToArray()); poly.Clear(); // report progress ReportProgress(dotsDrawn / totalDots); } // add dot to poly poly.Add(dot); dotsDrawn++; } // draw the last polygon target.DrawPoly(poly.ToArray()); return(dots.Count); }
public static IntPtr RegisterDrawTarget(IDrawTarget target) => System.Drawing.Graphics.RegisterDrawTarget(target);
private Graphics(IDrawTarget target, IntPtr hdc) : this(new ManagedGraphics(target), hdc) { }