protected override void OnPaint(PaintEventArgs e) { IntPtr hdc = e.Graphics.GetHdc(); using (GraphicsPlus g = new GraphicsPlus(hdc)) Draw(e.Graphics, g); e.Graphics.ReleaseHdc(hdc); }
private void Draw(Graphics graphics, GraphicsPlus g) { StringFormat sf = new StringFormat(); sf.LineAlignment = sf.Alignment = System.Drawing.StringAlignment.Center; int deltaH = ClientRectangle.Height / 8; GpRectF rc = new GpRectF(0, 0, ClientRectangle.Width, deltaH); RectangleF rcf = new RectangleF(0, 0, ClientRectangle.Width, deltaH); using (SolidBrush brText = new SolidBrush(Color.Black)) using (Font fnt = new Font("Tahoma", 9, System.Drawing.FontStyle.Bold)) { penSolid.SetWidth(15); g.DrawLine(penSolid, 5, rcf.Top + 10, rc.Width - 10, rcf.Top + 10); graphics.DrawString("Solid with caps", fnt, brText, rcf, sf); rcf.Y += deltaH; rc.Offset(0, deltaH); SmoothingMode mode = g.GetSmoothingMode(); g.SetSmoothingMode(SmoothingMode.SmoothingModeAntiAlias); penSolid.SetColor(Color.Blue); g.DrawLine(penSolid, 5, rcf.Top + 10, rc.Width - 10, rcf.Top + 10); graphics.DrawString("Solid with caps and anitalising", fnt, brText, rcf, sf); rcf.Y += deltaH; rc.Offset(0, deltaH); g.DrawLine(penHatch, 5, rcf.Top + 10, rc.Width - 10, rcf.Top + 10); graphics.DrawString("Hatched", fnt, brText, rcf, sf); rcf.Y += deltaH; rc.Offset(0, deltaH); penSolidTrans.SetWidth(20); penSolidTrans.SetLineCap(LineCap.LineCapRound, LineCap.LineCapDiamondAnchor, DashCap.DashCapRound); graphics.DrawString("Solid with transparency", fnt, brText, rcf, sf); g.DrawLine(penSolidTrans, 15, rcf.Top + 10, rc.Width - 30, rcf.Top + 10); rcf.Y += deltaH; rc.Offset(0, deltaH); g.SetSmoothingMode(SmoothingMode.SmoothingModeAntiAlias); brText.Color = Color.White; g.DrawLine(penSolidCustomCap, 15, rcf.Top + 15, rc.Width - 50, rcf.Top + 15); graphics.DrawString("Custom cap", fnt, brText, rcf, sf); rcf.Y += deltaH; rc.Offset(0, deltaH); g.SetSmoothingMode(mode); brText.Color = Color.Gray; g.DrawLine(penDash, 5, rcf.Top + 10, rc.Width - 10, rcf.Top + 10); graphics.DrawString("Dash (round)", fnt, brText, rcf, sf); rcf.Y += deltaH; rc.Offset(0, deltaH); brText.Color = Color.White; g.DrawLine(penGradient, 15, rcf.Top + 20, rc.Width - 30, rcf.Top + 20); graphics.DrawString("Gradient brush-based", fnt, brText, rcf, sf); rcf.Y += deltaH; rc.Offset(0, deltaH); } }
protected override void OnPaint(PaintEventArgs e) { IntPtr hdc = e.Graphics.GetHdc(); using (GraphicsPlus g = new GraphicsPlus(hdc)) TestGdiPlus(g); e.Graphics.ReleaseHdc(hdc); StringFormat fmt = new StringFormat(); fmt.Alignment = fmt.LineAlignment = System.Drawing.StringAlignment.Center; using (SolidBrush brText = new SolidBrush(Color.LightGray)) using (Font font = new Font("Tahoma", 8, System.Drawing.FontStyle.Bold)) e.Graphics.DrawString("Use stylus to write on this screen", font, brText, new Rectangle(0, 0, ClientRectangle.Width, 30), fmt); }
public BitmapPlus( int width, int height, GraphicsPlus target) { GpBitmap bitmap = new GpBitmap(); lastResult = NativeMethods.GdipCreateBitmapFromGraphics(width, height, target.nativeGraphics, out bitmap); SetNativeImage((GpImage)(IntPtr)bitmap); }
/// <summary> /// Draws top sides of all pie slices. /// </summary> /// <param name="graphics"> /// <c>Graphics</c> used for drawing. /// </param> protected void DrawTops(GraphicsPlus graphics) { foreach (PieSlice slice in m_pieSlices) { slice.DrawTop(graphics); } }
public bool IsOutlineVisible(GpPoint point, PenPlus pen, GraphicsPlus g) { return IsOutlineVisible(point.X, point.Y, pen, g); }
/// <summary> /// Draws the <c>Quadrilateral</c> with <c>Graphics</c> provided. /// </summary> /// <param name="graphics"> /// <c>Graphics</c> used to draw. /// </param> /// <param name="pen"> /// <c>Pen</c> used to draw outline. /// </param> /// <param name="brush"> /// <c>Brush</c> used to fill the inside. /// </param> public void Draw(GraphicsPlus graphics, PenPlus pen, BrushPlus brush) { graphics.FillPath(brush, m_path); graphics.DrawPath(pen, m_path); }
private void drawRotatedArrow(GraphicsPlus graphics) { Debug.WriteLine("drawRotatedArrow: " + this.rotationAngle, this.ToString()); Point center = new Point(this.Width / 2, this.Height / 2); int arWidthHalf = ARROW_WIDTH / 2; //int arHeightHalf = ARROW_HEIGHT / 2; Point[] arrowPoints = { new Point(center.X, center.Y - arWidthHalf), new Point(center.X - 2*arWidthHalf/3, center.Y + arWidthHalf), new Point(center.X + 2*arWidthHalf/3, center.Y + arWidthHalf), new Point(center.X, center.Y + arWidthHalf/2) }; Debug.WriteLine("drawRotatedArrow: points " + PointUtil.pointsStr(arrowPoints), this.ToString()); PointMath.RotatePoints(arrowPoints, center, this.rotationAngle); Debug.WriteLine("drawRotatedArrow: points " + PointUtil.pointsStr(arrowPoints), this.ToString()); graphics.SetSmoothingMode(SmoothingMode.SmoothingModeAntiAlias); PenPlus pen = new PenPlus(ARROW_COLOR, 3); pen.SetEndCap(LineCap.LineCapRound); pen.SetStartCap(LineCap.LineCapRound); graphics.DrawLine(pen, new GpPoint(arrowPoints[0].X, arrowPoints[0].Y), new GpPoint(arrowPoints[1].X, arrowPoints[1].Y)); graphics.DrawLine(pen, new GpPoint(arrowPoints[1].X, arrowPoints[1].Y), new GpPoint(arrowPoints[3].X, arrowPoints[3].Y)); graphics.DrawLine(pen, new GpPoint(arrowPoints[3].X, arrowPoints[3].Y), new GpPoint(arrowPoints[2].X, arrowPoints[2].Y)); graphics.DrawLine(pen, new GpPoint(arrowPoints[2].X, arrowPoints[2].Y), new GpPoint(arrowPoints[0].X, arrowPoints[0].Y)); pen.Dispose(); }
public bool IsOutlineVisible(float x, float y, PenPlus pen, GraphicsPlus g) { bool ret; SetStatus(NativeMethods.GdipIsOutlineVisiblePathPoint(nativePath, x, y, pen.nativePen, g.nativeGraphics, out ret)); return ret; }
private void TestGdiPlus(GraphicsPlus graphics) { graphics.DrawImage(bmp, 0, 0, ClientRectangle.Width, ClientRectangle.Height); PenPlus pen; graphics.SetSmoothingMode(SmoothingMode.SmoothingModeAntiAlias); pen= new PenPlus(Color.Black, 15); pen.SetEndCap(LineCap.LineCapRound); pen.SetStartCap(LineCap.LineCapRound); pen.SetWidth(3); pen.SetColor(Color.FromArgb(0x7f7f7f7f)); pen.SetWidth(40); graphics.DrawLine(pen, 20, 20, ClientRectangle.Right - 20, ClientRectangle.Bottom - 20); graphics.DrawLine(pen, ClientRectangle.Right - 20, 20, 20, ClientRectangle.Bottom - 20); SmoothingMode mode = graphics.GetSmoothingMode(); graphics.SetSmoothingMode(SmoothingMode.SmoothingModeAntiAlias); foreach(GraphicsPath p in allPaths) graphics.DrawPath(penWrite, p); graphics.SetSmoothingMode(mode); pen.Dispose(); }
/// <summary> /// Draws the pie slice. /// </summary> /// <param name="graphics"> /// <c>Graphics</c> used to draw the pie slice. /// </param> public void Draw(GraphicsPlus graphics) { DrawBottom(graphics); DrawSides(graphics); DrawTop(graphics); }
/// <summary> /// Draws the outer periphery of the pie slice. /// </summary> /// <param name="graphics"> /// <c>Graphics</c> object used to draw the surface. /// </param> /// <param name="pen"> /// <c>Pen</c> used to draw outline. /// </param> /// <param name="brush"> /// <c>Brush</c> used to fill the quadrilateral. /// </param> /// <param name="boundingRect"> /// Bounding rectangle that is used to draw the top surface of the /// pie slice. /// </param> /// <param name="startAngle"> /// Start angle (in degrees) of the periphery section. /// </param> /// <param name="endAngle"> /// End angle (in degrees) of the periphery section. /// </param> /// <param name="pointStart"> /// Point representing the start of the periphery. /// </param> /// <param name="pointEnd"> /// Point representing the end of the periphery. /// </param> protected void DrawCylinderSurfaceSection(GraphicsPlus graphics, PenPlus pen, BrushPlus brush, float startAngle, float endAngle, GpPointF pointStart, GpPointF pointEnd) { GraphicsPath path = CreatePathForCylinderSurfaceSection(startAngle, endAngle, pointStart, pointEnd); graphics.FillPath(brush, path); graphics.DrawPath(pen, path); }
GetBounds(out GpRect rect, GraphicsPlus g) { return SetStatus(NativeMethods.GdipGetRegionBoundsI(nativeRegion, g.nativeGraphics, out rect)); }
/// <summary> /// Draws hidden outer periphery of the pie slice. /// </summary> /// <param name="graphics"> /// <c>Graphics</c> used to draw the pie slice. /// </param> internal void DrawHiddenPeriphery(GraphicsPlus graphics) { PeripherySurfaceBounds[] peripherySurfaceBounds = GetHiddenPeripherySurfaceBounds(); foreach (PeripherySurfaceBounds surfaceBounds in peripherySurfaceBounds) { DrawCylinderSurfaceSection(graphics, m_pen, m_brushSurface, surfaceBounds.StartAngle, surfaceBounds.EndAngle, surfaceBounds.StartPoint, surfaceBounds.EndPoint); } }
/// <summary> /// Draws the top of the pie slice. /// </summary> /// <param name="graphics"> /// <c>Graphics</c> used to draw the pie slice. /// </param> internal void DrawTop(GraphicsPlus graphics) { graphics.FillPie(m_brushSurface, m_boundingRectangle.X, m_boundingRectangle.Y, m_boundingRectangle.Width, m_boundingRectangle.Height, m_startAngle, m_sweepAngle); graphics.DrawPie(m_pen, m_boundingRectangle.X, m_boundingRectangle.Y, m_boundingRectangle.Width, m_boundingRectangle.Height, m_startAngle, m_sweepAngle); }
/// <summary> /// Draws visible end side. /// </summary> /// <param name="graphics"> /// <c>Graphics</c> used to draw the pie slice. /// </param> internal void DrawEndSide(GraphicsPlus graphics) { if (m_endSide != null) { // checks if the side is visible if (EndAngle > 90 && EndAngle < 270) m_endSide.Draw(graphics, m_pen, m_brushSurface); else m_endSide.Draw(graphics, m_pen, m_brushEndSide); } }
/// <summary> /// Draws visible start side. /// </summary> /// <param name="graphics"> /// <c>Graphics</c> used to draw the pie slice. /// </param> internal void DrawStartSide(GraphicsPlus graphics) { if (m_startSide != null) { // checks if the side is visible if (StartAngle > 90 && StartAngle < 270) m_startSide.Draw(graphics, m_pen, m_brushStartSide); else m_startSide.Draw(graphics, m_pen, m_brushSurface); } }
/// <summary> /// Draws pie slice sides. /// </summary> /// <param name="graphics"> /// <c>Graphics</c> used to draw the pie slice. /// </param> internal void DrawSides(GraphicsPlus graphics) { DrawHiddenPeriphery(graphics); // draw wegde sides if (StartAngle > 90 && StartAngle < 270) { DrawEndSide(graphics); DrawStartSide(graphics); } else { DrawStartSide(graphics); DrawEndSide(graphics); } DrawVisiblePeriphery(graphics); }
/// <summary> /// Draws the chart. /// </summary> /// <param name="graphics"> /// <c>Graphics</c> object used for drawing. /// </param> public void Draw(GraphicsPlus graphics) { Debug.Assert(m_values != null && m_values.Length > 0); InitializePieSlices(); if (m_fitToBoundingRectangle) { RectangleF newBoundingRectangle = GetFittingRectangle(); ReadjustSlices(newBoundingRectangle); } DrawBottoms(graphics); if (m_sliceRelativeHeight > 0F) { DrawSliceSides(graphics); } DrawTops(graphics); }
IsInfinite(GraphicsPlus g) { bool booln = false; SetStatus(NativeMethods.GdipIsInfiniteRegion(nativeRegion, g.nativeGraphics, out booln)); return booln; }
/// <summary> /// Draws outer peripheries of all slices. /// </summary> /// <param name="graphics"> /// <c>Graphics</c> used for drawing. /// </param> protected void DrawSliceSides(GraphicsPlus graphics) { ArrayList pieSlicesList = new ArrayList(m_pieSlices); PieSlice ps = null; // if the first pie slice (crossing 270 i.e. back) is crossing 90 // (front) axis too, we have to split it if ((m_pieSlices[0].StartAngle > 90) && (m_pieSlices[0].StartAngle <= 270) && (m_pieSlices[0].StartAngle + m_pieSlices[0].SweepAngle > 450)) { ps = (PieSlice)pieSlicesList[0]; // this one is split at 0 deg to avoid line of split to be // visible on the periphery PieSlice[] splitSlices = ps.Split(0F); pieSlicesList[0] = splitSlices[0]; if (splitSlices[1].SweepAngle > 0F) { pieSlicesList.Insert(1, splitSlices[1]); } } else if (((m_pieSlices[0].StartAngle > 270) && (m_pieSlices[0].StartAngle + m_pieSlices[0].SweepAngle > 450)) || ((m_pieSlices[0].StartAngle < 90) && (m_pieSlices[0].StartAngle + m_pieSlices[0].SweepAngle > 270))) { ps = (PieSlice)pieSlicesList[0]; // this one is split at 180 deg to avoid line of split to be // visible on the periphery PieSlice[] splitSlices = ps.Split(180F); pieSlicesList[0] = splitSlices[1]; if (splitSlices[1].SweepAngle > 0F) { pieSlicesList.Add(splitSlices[0]); } } // first draw the backmost pie slice ps = (PieSlice)pieSlicesList[0]; ps.DrawSides(graphics); // draw pie slices from the backmost to forward int incrementIndex = 1; int decrementIndex = pieSlicesList.Count - 1; while (incrementIndex < decrementIndex) { PieSlice sliceLeft = (PieSlice)pieSlicesList[decrementIndex]; float angle1 = sliceLeft.StartAngle - 90; if (angle1 > 180 || angle1 < 0) angle1 = 0; PieSlice sliceRight = (PieSlice)pieSlicesList[incrementIndex]; float angle2 = (450 - sliceRight.EndAngle) % 360; if (angle2 > 180 || angle2 < 0) angle2 = 0; Debug.Assert(angle1 >= 0); Debug.Assert(angle2 >= 0); if (angle2 >= angle1) { sliceRight.DrawSides(graphics); ++incrementIndex; } else if (angle2 < angle1) { sliceLeft.DrawSides(graphics); --decrementIndex; } } ps = (PieSlice)pieSlicesList[decrementIndex]; ps.DrawSides(graphics); }
IsVisible(GpPoint point, GraphicsPlus g) { bool booln = false; SetStatus(NativeMethods.GdipIsVisibleRegionPointI(nativeRegion, point.X, point.Y, (g == null) ? new GpGraphics() : g.nativeGraphics, out booln)); return booln; }
private void Draw(Graphics graphics, GraphicsPlus g) { int deltaH = ClientRectangle.Height / 5; GpRectF rc = new GpRectF(0, 0, ClientRectangle.Width, deltaH); g.FillRectangle(brPathGrad, rc); rc.Offset(0, deltaH); g.FillRectangle(brSolid, rc); rc.Offset(0, deltaH); g.FillRectangle(brHatch, rc); rc.Offset(0, deltaH); g.FillRectangle(brLinGrad, rc); rc.Offset(0, deltaH); g.FillRectangle(brTexture, rc); rc.Offset(0, deltaH); Rectangle rcText = new Rectangle(0, 0, ClientRectangle.Width, deltaH); StringFormat sf = new StringFormat(); sf.LineAlignment = sf.Alignment = System.Drawing.StringAlignment.Center; using (SolidBrush brText =new SolidBrush(Color.White)) using (Font fnt = new Font("Tahoma", 9, System.Drawing.FontStyle.Bold)) { graphics.DrawString("PathGradient Brush", fnt, brText, rcText, sf); rcText.Offset(0, deltaH); brText.Color = Color.Black; graphics.DrawString("Solid Brush", fnt, brText, rcText, sf); rcText.Offset(0, deltaH); graphics.DrawString("Hatch Brush", fnt, brText, rcText, sf); rcText.Offset(0, deltaH); graphics.DrawString("LinearGradient Brush", fnt, brText, rcText, sf); rcText.Offset(0, deltaH); graphics.DrawString("Texture Brush", fnt, brText, rcText, sf); rcText.Offset(0, deltaH); } }
private void AddStroke(int x, int y) { allPoints.Add(new GpPointF(x, y)); if ( allPoints.Count == 1 ) return; path.AddLine(allPoints[allPoints.Count - 2], allPoints[allPoints.Count - 1]); using (Graphics graphics = CreateGraphics()) { IntPtr hdc = graphics.GetHdc(); using (GraphicsPlus g = new GraphicsPlus(hdc)) { SmoothingMode mode = g.GetSmoothingMode(); g.SetSmoothingMode(SmoothingMode.SmoothingModeAntiAlias); g.DrawLine(penWrite, allPoints[allPoints.Count - 2], allPoints[allPoints.Count - 1]); g.SetSmoothingMode(mode); } graphics.ReleaseHdc(hdc); } }
GetHRGN(GraphicsPlus g) { HRGN hrgn; SetStatus(NativeMethods.GdipGetRegionHRgn(nativeRegion, g.nativeGraphics, out hrgn)); return hrgn; }
public bool IsVisible(GpPoint point, GraphicsPlus g) { return IsVisible(point.X, point.Y, g); }
Equals(RegionPlus region, GraphicsPlus g) { bool booln = false; SetStatus(NativeMethods.GdipIsEqualRegion(nativeRegion, region.nativeRegion, g.nativeGraphics, out booln)); return booln; }
public bool IsVisible(int x, int y, GraphicsPlus g) { bool ret; NativeMethods.GdipIsVisiblePathPoint(nativePath, x, y, g.nativeGraphics, out ret); return ret; }
IsVisible(GpRect rect, GraphicsPlus g) { bool booln = false; SetStatus(NativeMethods.GdipIsVisibleRegionRectI(nativeRegion, rect.X, rect.Y, rect.Width, rect.Height, (g == null) ? new GpGraphics() : g.nativeGraphics, out booln)); return booln; }
private void drawOffScreen() { Graphics g = Graphics.FromImage(this.off_screen); g.Clear(this.BackColor); drawMap(g); // GDI Plus IntPtr hdc = g.GetHdc(); using (GraphicsPlus graphics = new GraphicsPlus(hdc)) { if (this.directionLineVisible) drawDirectionLinePlus(graphics); //drawDirectionLine(g); if (this.courseArrowVisible) drawRotatedArrow(graphics); } g.ReleaseHdc(hdc); //if (hasMap) // drawPositionMarkerImg(g); //Bitmap rotated = rotate(); //g.DrawImage(rotated, this.Width / 2, this.Height / 2); }