// Constructor. internal Graphics(IToolkitGraphics graphics) { this.graphics = graphics; this.clip = null; this.transform = null; this.pageScale = 1.0f; this.pageUnit = GraphicsUnit.World; this.stackTop = null; this.baseWindow = Rectangle.Empty; }
protected override sealed void OnPaint(PaintEventArgs e) { if (e == null || e.Graphics == null) throw new ArgumentNullException("e"); Background = e.Graphics.BeginContainer(); e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; OnForePaint(e); e.Graphics.EndContainer(Background); base.OnPaint(e); }
void drawN(Graphics g, Rectangle lei) { GraphicsContainer gc = g.BeginContainer(); g.CompositingQuality = CompositingQuality.HighQuality; float s = 0f; //s = Convert.ToSingle(500 * 60 / scalex / 1000); s = 400 / 60 / (pageScale); float f1 = 40; int num1 = 1000; if (s * f1 > 1000) { f1 = num1 / s; while (f1 < 40) { num1 += 50; f1 = num1 / s; } } else { num1 -= 50; f1 = num1 / s; while (f1 > 45) { num1 -= 50; f1 = num1 / s; } } //MessageBox.Show(s + "," + f1 + "," + num1); Brush bkbru = Brushes.Black; Pen p1 = new Pen(Color.Black); Font ft = new Font("宋体", 15f); Font sft = new Font("宋体", 8f); //Polygon rt1 = tlVectorControl1.SVGDocument.CurrentElement as Polygon; //RectangleF pictureBox1 = rt1.GetBounds(); //Rectangle pictureBox1 = pageSetting.Bounds; //g.FillRectangle(Brushes.White, lei.X , lei.Y + lei.Height - 37, 90, 37); //g.DrawRectangle(p1, lei.X, lei.Y + lei.Height-37, 90, 37); g.DrawString("1", ft, bkbru, new PointF(lei.X + 45, lei.Y + lei.Height - 60)); g.DrawString(":", ft, bkbru, new PointF(lei.X + 57, lei.Y + lei.Height - 60)); g.DrawString(Convert.ToString(Convert.ToInt32(num1) / 100), ft, bkbru, new PointF(lei.X + 69, lei.Y + lei.Height - 60)); g.DrawString(" 万", ft, bkbru, new PointF(lei.X + 105, lei.Y + lei.Height - 60)); //,120 40,120 100 PointF leto = new PointF(lei.X, lei.Y); PointF lebo = new PointF(lei.X, lei.Y + lei.Height); PointF rito = new PointF(lei.X + lei.Width, lei.Y); PointF ribo = new PointF(lei.X + lei.Width, lei.Y + lei.Height); //Pen bkb = true; g.DrawLine(new Pen(Color.Black, 1.0f), leto, lebo); g.DrawLine(new Pen(Color.Black, 0.8f), leto, rito); g.DrawLine(new Pen(Color.Black, 1.0f), lebo, ribo); g.DrawLine(new Pen(Color.Black, 0.8f), rito, ribo); g.EndContainer(gc); }
public GraphicsContainerDisposer(Graphics g, GraphicsContainer gc) { this.g = g; this.gc = gc; }
public override void OnPaint(PaintEventArgs e, ViewPortData viewPortData) { Graphics graphics = e.Graphics; Debug.Assert(graphics != null); AmbientTheme ambientTheme = WorkflowTheme.CurrentTheme.AmbientTheme; //Get the drawing canvas Bitmap memoryBitmap = viewPortData.MemoryBitmap; Debug.Assert(memoryBitmap != null); //Fill the background using the workspace color so that we communicate the paging concept graphics.FillRectangle(Brushes.White, new Rectangle(Point.Empty, memoryBitmap.Size)); //Fill the background using the workspace color so that we communicate the paging concept //if there is no workflow watermark, just return if (ambientTheme.WorkflowWatermarkImage == null) { return; } //Create the transformation matrix and calculate the physical viewport without translation and scaling //We need to get the physical view port due to the fact that there can be circustances when zoom percentage //is very high, logical view port can be empty in such cases GraphicsContainer graphicsState = graphics.BeginContainer(); Matrix coOrdTxMatrix = new Matrix(); coOrdTxMatrix.Scale(viewPortData.Scaling.Width, viewPortData.Scaling.Height, MatrixOrder.Prepend); coOrdTxMatrix.Invert(); Point[] points = new Point[] { viewPortData.Translation, new Point(viewPortData.ViewPortSize) }; coOrdTxMatrix.TransformPoints(points); Rectangle physicalViewPort = new Rectangle(points[0], new Size(points[1])); //because the watermark image needs to be scaled according to the zoom level, we //a) scale the graphics of the bitmap up by the zoom factor //a) scale the coordinates transform matrix down by the zoom factor coOrdTxMatrix = new Matrix(); coOrdTxMatrix.Scale(viewPortData.Scaling.Width / (float)this.parentView.Zoom * 100.0f, viewPortData.Scaling.Height / (float)this.parentView.Zoom * 100.0f); //Make sure that we now clear the translation factor Matrix graphicsMatrics = new Matrix(); graphicsMatrics.Scale((float)this.parentView.Zoom / 100.0f, (float)this.parentView.Zoom / 100.0f); graphics.Transform = graphicsMatrics; foreach (PageLayoutData pageLayoutData in this.pageLayoutInfo) { //We do not draw the non intersecting pages, get the intersected viewport //We purposely use the physical viewport here because, there are cases in which the viewport //will not contain any logical bitmap areas in which case we atleast need to draw the pages properly if (!pageLayoutData.PageBounds.IntersectsWith(physicalViewPort)) { continue; } //Draw the watermark into the in-memory bitmap //This is the area of the viewport bitmap we need to copy on the page Rectangle viewPortBitmapArea = Rectangle.Empty; viewPortBitmapArea.X = pageLayoutData.LogicalPageBounds.X - viewPortData.LogicalViewPort.X; viewPortBitmapArea.Y = pageLayoutData.LogicalPageBounds.Y - viewPortData.LogicalViewPort.Y; viewPortBitmapArea.Width = pageLayoutData.LogicalPageBounds.Width; viewPortBitmapArea.Height = pageLayoutData.LogicalPageBounds.Height; //This rectangle is in translated logical units, we need to scale it down points = new Point[] { viewPortBitmapArea.Location, new Point(viewPortBitmapArea.Size) }; coOrdTxMatrix.TransformPoints(points); viewPortBitmapArea.Location = points[0]; viewPortBitmapArea.Size = new Size(points[1]); ActivityDesignerPaint.DrawImage(graphics, ambientTheme.WorkflowWatermarkImage, viewPortBitmapArea, new Rectangle(Point.Empty, ambientTheme.WorkflowWatermarkImage.Size), ambientTheme.WatermarkAlignment, AmbientTheme.WatermarkTransparency, false); } //Now clear the matrix graphics.EndContainer(graphicsState); }
protected override void OnPaintBackground(PaintEventArgs e) { // the base PaintBackground will paint the back color or parent background for us base.OnPaintBackground(e); // if this control is fully opaque, or the parent control has no other children, then the built-in WinForms "simulated transparency" will suffice. // if not, we need to trick any sibling controls under us in the Z-Order to paint themselves to our background. if (this.BackColor.A < 255 && this.Parent != null && this.Parent.Controls.Count > 1) { // save the coordinate space of the graphics context (this control's own coordinate space) GraphicsContainer thisGraphicSpace = e.Graphics.BeginContainer(); try { // shift the graphics context into the parent control's coordinate space Rectangle clipRectangleParent = this.RectangleToScreen(e.ClipRectangle); e.Graphics.TranslateTransform(-this.Left, -this.Top); // only need to handle controls that are layered behind us in the Z-order int startingZIndex = this.Parent.Controls.IndexOf(this); for (int n = startingZIndex + 1; n < this.Parent.Controls.Count; n++) { Control sibling = this.Parent.Controls[n]; Rectangle clipRectangleSibling = sibling.ClientRectangle; clipRectangleSibling.Intersect(sibling.RectangleToClient(clipRectangleParent)); if (clipRectangleSibling.IsEmpty) { continue; } // save the coordinate space of the graphics context (the parent control's coordinate space) GraphicsContainer parentGraphicSpace = e.Graphics.BeginContainer(); try { // shift the graphics context into the sibling control's coordinate space e.Graphics.TranslateTransform(sibling.Left, sibling.Top); // ideally, you wouldn't have to paint the controls to a secondary buffer and then paint it on to our graphics context. // we've provided the correct clipping rectangle, which is only a subsection of the entire graphics context. // unfortunately, if the kind of sibling controls are the ones that ignore the clipping rectangle and paint onto the entire // graphics context, then we have no choice but to let the control render all of itself onto a secondary buffer, and then // extract just the part we want. it is slower, but it is currently the only way to make it work. using (Bitmap temp = new Bitmap(sibling.Width, sibling.Height)) { PaintEventArgs paintEventArgs = new PaintEventArgs(System.Drawing.Graphics.FromImage(temp), clipRectangleSibling); this.InvokePaintBackground(sibling, paintEventArgs); this.InvokePaint(sibling, paintEventArgs); e.Graphics.DrawImage(temp, clipRectangleSibling, clipRectangleSibling, GraphicsUnit.Pixel); } } finally { // restore the parent control's coordinate space e.Graphics.EndContainer(parentGraphicSpace); } } } finally { // restore our own coordinate space e.Graphics.EndContainer(thisGraphicSpace); } } }
public void EndContainer(GraphicsContainer container) { throw new NotImplementedException (); }
public void Paint(GraphicsPath path, Graphics g, int time, float opacity) { int num1 = 0; int num2 = 0; GraphicsContainer container1 = g.BeginContainer(); AnimFunc.CreateAnimateValues(this, time, out num1, out num2); g.SmoothingMode = base.OwnerDocument.SmoothingMode; SpreadMethods methods1 = this.SpreadMethod; bool flag1 = this.Units == Units.UserSpaceOnUse; float single1 = this.X1; float single2 = this.Y1; float single3 = this.X2; float single4 = this.Y2; if ((single1 == single3) && (single2 == single4)) { single1 -= 1E-05f; single3 += 1E-05f; } float single5 = single1; float single6 = single2; float single7 = single3; float single8 = single4; RectangleF ef1 = RectangleF.Empty; RectangleF ef2 = RectangleF.Empty; Matrix matrix1 = this.Transform.Matrix.Clone(); PointF[] tfArray4 = new PointF[2] { new PointF(single1, single2), new PointF(single3, single4) }; PointF[] tfArray1 = tfArray4; matrix1.TransformPoints(tfArray1); single1 = tfArray1[0].X; single3 = tfArray1[1].X; single2 = tfArray1[0].Y; single4 = tfArray1[1].Y; bool flag2 = single2 == single4; bool flag3 = single1 == single3; float single9 = 1f; this.coord = new Matrix(); this.ratiomatrix = new Matrix(); RectangleF ef3 = PathFunc.GetBounds(path); if (flag1) { ef1 = ((SVG)base.OwnerDocument.DocumentElement).ViewPort; } else { ef3 = new RectangleF(0f, 0f, 1f, 1f); ef1 = ef3; ef2 = PathFunc.GetBounds(path); this.coord.Translate(ef2.X, ef2.Y); this.coord.Scale(ef2.Width, ef2.Width); this.ratiomatrix.Scale(1f, ef2.Height / ef2.Width); } PointF tf1 = new PointF(single1, single2); PointF tf2 = new PointF(single3, single4); PointF tf3 = tf1; PointF tf4 = tf2; ColorBlend blend1 = new ColorBlend(this.Stops.Count); Color[] colorArray1 = new Color[this.Stops.Count]; float[] singleArray1 = new float[this.Stops.Count]; SvgElementCollection collection1 = this.Stops; for (int num3 = 0; num3 < collection1.Count; num3++) { GradientStop stop1 = (GradientStop)collection1[num3]; AnimFunc.CreateAnimateValues(stop1, time, out num1, out num2); int num4 = 0xff; if ((stop1.Opacity >= 0f) && (stop1.Opacity <= 255f)) { if (stop1.Opacity <= 1f) { num4 = (int)(stop1.Opacity * 255f); } else { num4 = (int)stop1.Opacity; } } num4 = (int)Math.Min((float)(opacity * 255f), (float)num4); Color color1 = stop1.Color; float single10 = Math.Min((float)1f, Math.Max((float)0f, stop1.ColorOffset)); colorArray1[num3] = Color.FromArgb(num4, color1.R, color1.G, color1.B); singleArray1[num3] = single10; } float[] singleArray2 = (float[])singleArray1.Clone(); Color[] colorArray2 = (Color[])colorArray1.Clone(); Array.Sort(singleArray2, colorArray2); Color color2 = colorArray2[0]; Color color3 = colorArray2[colorArray2.Length - 1]; float single11 = singleArray2[0]; float single12 = singleArray2[singleArray2.Length - 1]; if (singleArray2[0] != 0f) { float[] singleArray3 = (float[])singleArray2.Clone(); Color[] colorArray3 = (Color[])colorArray2.Clone(); singleArray2 = new float[singleArray2.Length + 1]; colorArray2 = new Color[colorArray2.Length + 1]; colorArray3.CopyTo(colorArray2, 1); singleArray3.CopyTo(singleArray2, 1); singleArray2[0] = 0f; colorArray2[0] = color2; } if (singleArray2[singleArray2.Length - 1] != 1f) { float[] singleArray4 = (float[])singleArray2.Clone(); Color[] colorArray4 = (Color[])colorArray2.Clone(); singleArray2 = new float[singleArray2.Length + 1]; singleArray4.CopyTo(singleArray2, 0); singleArray2[singleArray2.Length - 1] = 1f; colorArray2 = new Color[colorArray2.Length + 1]; colorArray4.CopyTo(colorArray2, 0); colorArray2[colorArray2.Length - 1] = color3; } PointF[] tfArray2 = new PointF[1]; PointF[] tfArray3 = new PointF[4]; if (methods1 == SpreadMethods.Pad) { if (flag2) { tf1 = new PointF(Math.Min(single1, ef3.X), tf1.Y); tf2 = new PointF(Math.Max(single3, ef3.Right), tf2.Y); float single13 = single1; float single14 = single3 - single1; for (int num5 = 0; num5 < singleArray2.Length; num5++) { singleArray2[num5] = ((single13 + (single14 * singleArray2[num5])) - tf1.X) / (tf2.X - tf1.X); } } else if (flag3) { tf1 = new PointF(tf1.X, Math.Min(single2, ef3.Y)); tf2 = new PointF(tf2.X, Math.Max(single4, ef3.Bottom)); float single15 = single2; float single16 = single4 - single2; for (int num6 = 0; num6 < singleArray2.Length; num6++) { singleArray2[num6] = ((single15 + (single16 * singleArray2[num6])) - tf1.Y) / (tf2.Y - tf1.Y); } } else { single9 = (single4 - single2) / (single3 - single1); float single17 = (single2 - (single9 * single1)) / (1f + (single9 * single9)); PointF tf5 = ef3.Location; PointF tf6 = new PointF(ef3.Right, ef3.Y); PointF tf7 = new PointF(ef3.Right, ef3.Bottom); PointF tf8 = new PointF(ef3.X, ef3.Bottom); PointF[] tfArray5 = new PointF[4] { tf5, tf6, tf7, tf8 }; tfArray2 = tfArray5; for (int num7 = 0; num7 < tfArray2.Length; num7++) { PointF tf9 = tfArray2[num7]; float single18 = ((((single9 * single9) * tf9.Y) + (single9 * tf9.X)) / (1f + (single9 * single9))) + single17; float single19 = (single9 * (tf9.Y - single18)) + tf9.X; tfArray3[num7] = new PointF(single19, single18); if (single1 < single3) { if (single19 < tf1.X) { tf1 = new PointF(single19, single18); } else if (single19 > tf2.X) { tf2 = new PointF(single19, single18); } } else if (single19 < tf2.X) { tf2 = new PointF(single19, single18); } else if (single19 > tf1.X) { tf1 = new PointF(single19, single18); } } float single20 = single1; float single21 = single3 - single1; for (int num8 = 0; num8 < singleArray2.Length; num8++) { singleArray2[num8] = ((single20 + (single21 * singleArray2[num8])) - tf1.X) / (tf2.X - tf1.X); } } if (singleArray2[0] != 0f) { float[] singleArray5 = (float[])singleArray2.Clone(); Color[] colorArray5 = (Color[])colorArray2.Clone(); singleArray2 = new float[singleArray2.Length + 1]; colorArray2 = new Color[colorArray2.Length + 1]; colorArray5.CopyTo(colorArray2, 1); singleArray5.CopyTo(singleArray2, 1); singleArray2[0] = 0f; colorArray2[0] = color2; } if (singleArray2[singleArray2.Length - 1] != 1f) { float[] singleArray6 = (float[])singleArray2.Clone(); Color[] colorArray6 = (Color[])colorArray2.Clone(); singleArray2 = new float[singleArray2.Length + 1]; singleArray6.CopyTo(singleArray2, 0); singleArray2[singleArray2.Length - 1] = 1f; colorArray2 = new Color[colorArray2.Length + 1]; colorArray6.CopyTo(colorArray2, 0); colorArray2[colorArray2.Length - 1] = color3; } } this.brush = new LinearGradientBrush(tf1, tf2, color2, color3); if (methods1 == SpreadMethods.Reflect) { this.brush.WrapMode = WrapMode.TileFlipXY; } else { this.brush.WrapMode = WrapMode.Tile; } blend1.Colors = colorArray2; blend1.Positions = singleArray2; this.brush.InterpolationColors = blend1; this.coord.Multiply(this.ratiomatrix); GraphicsContainer container2 = g.BeginContainer(); g.Transform = this.coord; Matrix matrix2 = this.coord.Clone(); matrix2.Invert(); GraphicsPath path1 = (GraphicsPath)path.Clone(); path1.Transform(matrix2); g.FillPath(this.brush, path1); g.EndContainer(container2); if (!base.OwnerDocument.PlayAnim) { this.gradientpath = new GraphicsPath(); PointF[] tfArray6 = new PointF[8] { new PointF((single5 + single7) / 2f, ((single6 + single8) / 2f) + 0.5f), new PointF(single7, single8 + 0.5f), new PointF(single7, single8), PointF.Empty, new PointF(single7, ((single6 + single8) / 2f) + 1f), PointF.Empty, PointF.Empty, PointF.Empty }; this.boundsPoints = tfArray6; this.gradientpath.AddLine(new PointF(single5, single6), new PointF(single5, single6 + 1f)); this.gradientpath.StartFigure(); this.gradientpath.AddLine(new PointF(single7, single8), new PointF(single7, single8 + 1f)); } this.pretime = time; g.EndContainer(container1); }
void PrintDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { e.HasMorePages = true; this.chartControl1.PrimaryXAxis.LabelIntersectAction = ChartLabelIntersectAction.Wrap; if (mx == 0.0 && mi == 0.0) { mx = Convert.ToDouble(this.comboBox1.SelectedItem); mi = 0; } bool grayScale = this.chartControl1.PrintDocument.ColorMode == ChartPrintColorMode.GrayScale; bool toolBatVisibility = this.chartControl1.ShowToolbar; if (!this.chartControl1.PrintDocument.PrintToolBar) { this.chartControl1.ShowToolbar = false; } if (m_currectAction.Value == PrintAction.PrintToPrinter && this.chartControl1.PrintDocument.ColorMode == ChartPrintColorMode.CheckPrinter) { grayScale = this.chartControl1.PrintDocument.PrinterSettings.SupportsColor; } if (!grayScale) { this.chartControl1.PrimaryXAxis.Range.Min = mi; this.chartControl1.PrimaryXAxis.Range.Max = mx; this.chartControl1.PrimaryXAxis.Range.Interval = (this.chartControl1.PrimaryXAxis.Range.Max - this.chartControl1.PrimaryXAxis.Range.Min) / this.chartControl1.PrimaryXAxis.Range.NumberOfIntervals; mi = mx; mx = mx + Convert.ToDouble(this.comboBox1.SelectedItem); GraphicsContainer container = BeginTransform(e.Graphics); e.Graphics.ResetTransform(); this.chartControl1.Draw(e.Graphics, e.MarginBounds); EndTransform(e.Graphics, container); } else if (grayScale) { ChartStyleInfo[] tempStyles = new ChartStyleInfo[this.chartControl1.Series.Count]; Array ps = System.Enum.GetValues(typeof(PatternStyle)); Array ds = System.Enum.GetValues(typeof(DashStyle)); for (int i = 0; i < this.chartControl1.Series.Count; i++) { tempStyles[i] = new ChartStyleInfo(); tempStyles[i].CopyFrom(this.chartControl1.Series[i].StylesImpl.Style); this.chartControl1.Series[i].Style.Interior = new BrushInfo((PatternStyle)ps.GetValue(i % ps.Length), Color.Black, Color.White); this.chartControl1.Series[i].Style.Border.MakeCopy(tempStyles[i], this.chartControl1.Series[i].Style.Border.Sip); this.chartControl1.Series[i].Style.Border.Color = Color.Transparent; this.chartControl1.Series[i].Style.Border.DashStyle = (DashStyle)ds.GetValue(i % ds.Length); if (this.chartControl1.Series[i].Type == ChartSeriesType.Line || this.chartControl1.Series[i].Type == ChartSeriesType.Spline || this.chartControl1.Series[i].Type == ChartSeriesType.StepLine || this.chartControl1.Series[i].Type == ChartSeriesType.RotatedSpline) { this.chartControl1.Series[i].Style.Interior = new BrushInfo((PatternStyle)ps.GetValue(i % ps.Length), Color.White, Color.Black); if (this.chartControl1.Series3D || this.chartControl1.ChartInterior.BackColor == Color.Black) { this.chartControl1.Series[i].Style.Interior = new BrushInfo((PatternStyle)ps.GetValue(i % ps.Length), Color.Black, Color.White); this.chartControl1.Series[i].Style.Border.Color = Color.Transparent; } } } GraphicsContainer container = BeginTransform(e.Graphics); e.Graphics.ResetTransform(); using (Image img = new Bitmap(e.MarginBounds.Width, e.MarginBounds.Height)) { using (Graphics g = Graphics.FromImage(img)) { this.chartControl1.ChartArea.PrimaryXAxis.Range.Min = mi; this.chartControl1.ChartArea.PrimaryXAxis.Range.Max = mx; this.chartControl1.ChartArea.PrimaryXAxis.Range.Interval = (this.chartControl1.ChartArea.PrimaryXAxis.Range.Max - this.chartControl1.ChartArea.PrimaryXAxis.Range.Min) / this.chartControl1.ChartArea.PrimaryXAxis.Range.NumberOfIntervals; mi = mx; mx = mx + Convert.ToDouble(this.comboBox1.SelectedItem); IntPtr hdc = g.GetHdc(); Stream stream = new MemoryStream(); Metafile mf = new Metafile(stream, hdc); this.chartControl1.Draw(mf, img.Size); DrawingUtils.DrawGrayedImage(e.Graphics, mf, e.MarginBounds, new Rectangle(Point.Empty, img.Size)); g.ReleaseHdc(hdc); g.Dispose(); mf.Dispose(); } } EndTransform(e.Graphics, container); for (int i = 0; i < this.chartControl1.Series.Count; i++) { this.chartControl1.Series[i].StylesImpl.Style.ResetInterior(); this.chartControl1.Series[i].StylesImpl.Style.ResetBorder(); this.chartControl1.Series[i].StylesImpl.Style.CopyFrom(tempStyles[i]); } } ////END A little experimental code if (!this.chartControl1.PrintDocument.PrintToolBar) { this.chartControl1.ShowToolbar = toolBatVisibility; } this.chartControl1.Redraw(true); if (mx > end) { e.HasMorePages = false; } this.chartControl1.PrimaryXAxis.Range.Min = start; this.chartControl1.PrimaryXAxis.Range.Max = end; this.chartControl1.PrimaryXAxis.Range.Interval = Intervel; }
protected override void OnPaint(PaintEventArgs e) { if (this.DesignMode) { return; } if (this.drawArea.DrawMode == DrawModeType.Normal) { image = null; } if (this.drawArea.CurrentOperation == ToolOperation.Roam && image != null && beginMove) { e.Graphics.DrawImage(image, offx, offy); return; } else { Graphics g = e.Graphics; if (this.drawArea.DrawMode == DrawModeType.MemoryImage) { if (image == null) { image = new Bitmap(Width, Height); MG = Graphics.FromImage(image); } g = MG; g.Clip = new Region(new Rectangle(0, 0, Width, Height)); } //拖放结束执行 if (image != null && (Math.Abs(offx) > 0 || Math.Abs(offy) > 0)) { if (drawArea.DrawMode == DrawModeType.ScreenImage) { g.DrawImage(image, offx, offy); Rectangle rt1 = new Rectangle(nRule, nRule, image.Width - nRule, image.Height - nRule); Rectangle rt2 = rt1; Rectangle rt3 = rt1; rt3.Offset(offx, offy); rt2.Intersect(rt3); Region rg = new Region(rt1); rg.Xor(rt2); g.Clip = rg; offx = offy = 0; image = null; } else { System.Drawing.Image image2 = new Bitmap(image.Width, image.Height); g = Graphics.FromImage(image2); g.DrawImage(image, offx, offy); Rectangle rt1 = new Rectangle(0, 0, image.Width, image.Height); Rectangle rt2 = rt1; Rectangle rt3 = rt1; rt3.Offset(offx, offy); rt2.Intersect(rt3); g.SetClip(rt2, CombineMode.Exclude); offx = offy = 0; image = image2; MG = g; } } else if (this.drawArea.DrawMode == DrawModeType.MemoryImage) { g.Clear(Color.Transparent); } DateTime time1 = DateTime.Now; if (this.svgDocument != null) { Matrix matrix1 = new Matrix(); matrix1.Translate(-this.virtualLeft, -this.virtualTop); matrix1.Translate(this.margin.Width, this.margin.Height); matrix1.Scale(this.scale, this.scale); GraphicsContainer container1 = g.BeginContainer(); g.SmoothingMode = this.svgDocument.SmoothingMode; if (this.svgDocument.RootElement is Group) { Group group2 = (Group)this.svgDocument.RootElement; group2.GraphTransform.Matrix = matrix1.Clone(); try { group2.Draw(g, this.svgDocument.ControlTime); } catch {} this.elementList = group2.GraphList; } g.EndContainer(container1); DateTime time2 = DateTime.Now; this.DrawSelection(g); if (this.selectChanged) { RectangleF ef1 = this.selectpath.GetBounds(); this.oldselectPoint = new PointF(ef1.X + (ef1.Width / 2f), ef1.Y + (ef1.Height / 2f)); this.selectChanged = false; } if (!this.oldselectPoint.IsEmpty) { PointF[] tfArray1 = new PointF[1] { this.oldselectPoint }; this.selectMatrix.TransformPoints(tfArray1); this.drawArea.CenterPoint = tfArray1[0]; if (this.drawArea.Operation == ToolOperation.FreeTransform) { g.SmoothingMode = SmoothingMode.HighQuality; PointF tf1 = this.drawArea.CenterPoint; GraphicsPath path2 = new GraphicsPath(); path2.AddEllipse(tf1.X - 2.5f, tf1.Y - 2.5f, 5f, 5f); g.FillPath(Brushes.White, path2); g.DrawPath(Pens.Blue, path2); path2.Dispose(); } } if (this.drawArea.ShowGuides) { foreach (RefLine line1 in this.drawArea.RefLines) { PointF tf2 = PointF.Empty; // int num2 = base.Width; if (line1.Hori) { tf2 = new PointF(0f, (float)line1.Pos); } else { tf2 = new PointF((float)line1.Pos, 0f); // num2 = base.Height; } tf2 = this.drawArea.PointToSystem(tf2); Pen pen1 = new Pen(Color.Blue); pen1.DashStyle = DashStyle.Dash; if (line1.Hori) { g.DrawLine(pen1, 0f, tf2.Y, (float)base.Width, tf2.Y); continue; } g.DrawLine(pen1, tf2.X, 0f, tf2.X, (float)base.Height); pen1.Dispose(); } } matrix1.Dispose(); if (drawArea.DrawMode == DrawModeType.MemoryImage) { e.Graphics.DrawImage(image, 0, 0); } } PointF pf = this.drawArea.GetCenterPoint(); this.drawArea.ToolTip(string.Format("x:{0},y:{1}", pf.X, pf.Y), 2); // drawCount++; // time2=DateTime.Now; // TimeSpan ts=time2-time1; // this.drawArea.ToolTip(this.svgDocument.SelectCollection.Count+","+this.ElementList.Count+","+ drawCount+","+ts.Seconds+":"+ts.Milliseconds+","+this.virtualLeft+":"+this.virtualTop,2); } }
public override void Draw(Graphics g, int time) { float single5; float single6; float single7; float single8; float single11; float single12; float single13; Matrix matrix1; ItopVector.Core.Types.ViewBox box1 = null; if (this.pretime != base.OwnerDocument.ControlTime) { box1 = TypeFunc.ParseViewBox(this); this.ViewBox = box1; } box1 = this.ViewBox; parAlign align1 = parAlign.none; parMeetOrSlice slice1 = parMeetOrSlice.slice; float single1 = this.Width; float single2 = this.Height; float single3 = 0f; float single4 = 0f; if (box1 != null) { single1 = box1.width; single2 = box1.height; single3 = box1.min_x; single4 = box1.min_y; PreserveAspectRatio ratio1 = box1.psr; align1 = ratio1.Align; slice1 = ratio1.Mos; } float single9 = this.width / single1; float single10 = this.height / single2; GraphicsContainer container1 = g.BeginContainer(); g.SmoothingMode = base.OwnerDocument.SmoothingMode; if (single9 >= single10) { single12 = single9; single13 = single10; } else { single12 = single10; single13 = single9; } if (slice1 == parMeetOrSlice.meet) { single11 = single13; single7 = single1 * single11; single8 = single2 * single11; switch (align1) { case parAlign.xMinYMin: { single5 = this.X - single3; single6 = this.Y - single4; goto Label_03D1; } case parAlign.xMidYMin: { single5 = ((this.Width - single7) / 2f) - single3; single6 = this.Y - single4; goto Label_03D1; } case parAlign.xMaxYMin: { single5 = (this.Width - single7) - single3; single6 = this.Y - single4; goto Label_03D1; } case parAlign.xMinYMid: { single5 = this.X - single3; single6 = ((this.Height - single8) / 2f) - single4; goto Label_03D1; } case parAlign.xMidYMid: { single5 = ((this.Width - single7) / 2f) - single3; single6 = ((this.Height - single8) / 2f) - single4; goto Label_03D1; } case parAlign.xMaxYMid: { single5 = (this.Width - single7) - single3; single6 = ((this.Height - single8) / 2f) - single4; goto Label_03D1; } case parAlign.xMinYMax: { single5 = this.X - single3; single6 = (this.Height - single8) - single4; goto Label_03D1; } case parAlign.xMidYMax: { single5 = ((this.Width - single7) / 2f) - single3; single6 = (this.Height - single8) - single4; goto Label_03D1; } case parAlign.xMaxYMax: { single5 = (this.Width - single7) - single3; single6 = (this.Height - single8) - single4; goto Label_03D1; } } single5 = this.X - single3; single6 = this.Y - single4; single7 = single1; single8 = single2; } else { single11 = single12; single7 = this.Width / single11; single8 = this.Height / single11; switch (align1) { case parAlign.xMinYMin: { single5 = this.X + single3; single6 = this.Y + single4; goto Label_03D1; } case parAlign.xMidYMin: { single5 = ((single1 - single7) / 2f) + single3; single6 = this.Y + single4; goto Label_03D1; } case parAlign.xMaxYMin: { single5 = (single1 - single7) + single3; single6 = this.Y + single4; goto Label_03D1; } case parAlign.xMinYMid: { single5 = this.X + single3; single6 = ((single2 - single8) / 2f) + single4; goto Label_03D1; } case parAlign.xMidYMid: { single5 = ((single1 - single7) / 2f) + single3; single6 = ((single2 - single8) / 2f) + single4; goto Label_03D1; } case parAlign.xMaxYMid: { single5 = (single1 - single7) + single3; single6 = ((single2 - single8) / 2f) + single4; goto Label_03D1; } case parAlign.xMinYMax: { single5 = this.X + single3; single6 = (single2 - single8) + single4; goto Label_03D1; } case parAlign.xMidYMax: { single5 = ((single1 - single7) / 2f) + single3; single6 = (single2 - single8) + single4; goto Label_03D1; } case parAlign.xMaxYMax: { single5 = (single1 - single7) + single3; single6 = (single2 - single8) + single4; goto Label_03D1; } } single5 = this.X + single3; single6 = this.Y + single4; single7 = single1; single8 = single2; } Label_03D1: matrix1 = base.GraphTransform.Matrix; if ((this.Width != 0f) && (this.Height != 0f)) { float single14 = this.width / single7; float single15 = this.height / single8; // g.ScaleTransform(single14, single15); matrix1.Scale(single14, single15); } if (base.OwnerDocument.DocumentElement == this) { // g.TranslateTransform(single5, single6); matrix1.Translate(single5, single6); } else { // g.TranslateTransform(single5 - this.x, single6 - this.y); matrix1.Translate(single5 - this.x, single6 - this.y); } foreach (Layer layer in OwnerDocument.Layers) { if (!layer.Visible) { continue; } SvgElementCollection.ISvgElementEnumerator enumerator1 = layer.GraphList.GetEnumerator(); contectbounds = RectangleF.Empty; while (enumerator1.MoveNext()) { IGraph graph1 = (IGraph)enumerator1.Current; graph1.ShowConnectPoints = base.OwnerDocument.ShowConnectPoints; try { // if(graph1.LimitSize) // { // PointF [] points = {new PointF( matrix1.OffsetX,matrix1.OffsetY)}; // matrix1.TransformVectors(points); // graph1.GraphTransform.Matrix = new Matrix(1,0,0,1,points[0].X,points[0].Y); // } // else graph1.GraphTransform.Matrix = matrix1.Clone(); using (Matrix matrix2 = new Matrix()) { if (graph1 is ConnectLine) { graph1.Draw(g, time); continue; } matrix2.Multiply(matrix1, MatrixOrder.Prepend); matrix2.Multiply(graph1.Transform.Matrix, MatrixOrder.Prepend); //(graph1 as ConnectLine).UpatePath(g); RectangleF rtf1 = graph1.GPath.GetBounds(matrix2); if (!(graph1 is Text)) { rtf1.Width++; rtf1.Height++; } if (g.IsVisible(rtf1) || (rtf1 == RectangleF.Empty) || (graph1 is ConnectLine && graph1.GPath.PointCount == 0)) { graph1.Draw(g, time); } else { graph1.GraphTransform.Matrix.Multiply(graph1.Transform.Matrix, MatrixOrder.Prepend); #if debug int i = 0; i++; #endif } } } catch (Exception e) { } finally { graph1 = null; } } } this.pretime = time; g.EndContainer(container1); }
public GdiGraphicsContainer(GraphicsContainer idmap, GraphicsContainer main) { this.IdMap = idmap; this.Main = main; }
protected override void WndProc(ref Message m) { Graphics graphics = null; switch (m.Msg) { case 15: break; case 0x84: base.Invalidate(); base.WndProc(ref m); return; case 0x317: graphics = Graphics.FromHdc(m.WParam); break; default: base.WndProc(ref m); return; } if (graphics == null) { graphics = Graphics.FromHwnd(base.Handle); } GraphicsContainer container = graphics.BeginContainer(); base.WndProc(ref m); Rectangle empty = Rectangle.Empty; this.Theme.CalculateComboBoxRectangles(base.ClientRectangle, this.RightToLeft == RightToLeft.Yes, out empty, out this.m_buttonRectangle); int uiStateFlags = 0; if (!base.Enabled) { uiStateFlags = ButtonUIState.Disabled; } else if (!this.m_buttonRectangle.Contains(base.PointToClient(Control.MousePosition))) { this.m_overButton = 0; } else { this.m_overButton = 1; if ((Control.MouseButtons == MouseButtons.Left) && this.Focused) { uiStateFlags = ButtonUIState.Down; } else { uiStateFlags = ButtonUIState.Hot; } } graphics.BeginContainer(); ButtonUIState uiState = new ButtonUIState(uiStateFlags); graphics.Clip = new Region(new Rectangle(empty.X, empty.Y, 2, empty.Height)); this.Theme.PaintComboBox(graphics, base.ClientRectangle, uiState, this.ForeColor, this.BackColor, 1.0, empty, this.m_buttonRectangle); graphics.Clip = new Region(new Rectangle(2, empty.Y, empty.Width, 2)); this.Theme.PaintComboBox(graphics, base.ClientRectangle, uiState, this.ForeColor, this.BackColor, 1.0, empty, this.m_buttonRectangle); graphics.Clip = new Region(new Rectangle(2, empty.Bottom - 2, empty.Width, 2)); this.Theme.PaintComboBox(graphics, base.ClientRectangle, uiState, this.ForeColor, this.BackColor, 1.0, empty, this.m_buttonRectangle); graphics.Clip = new Region(new Rectangle(empty.Right - 2, 2, 2, empty.Height - 4)); this.Theme.PaintComboBox(graphics, base.ClientRectangle, uiState, this.ForeColor, this.BackColor, 1.0, empty, this.m_buttonRectangle); graphics.Clip = new Region(this.m_buttonRectangle); this.Theme.PaintComboBox(graphics, base.ClientRectangle, uiState, this.ForeColor, this.BackColor, 1.0, empty, this.m_buttonRectangle); graphics.EndContainer(container); graphics.Dispose(); }
/// <summary> /// Paint me /// </summary> /// <param name="g"></param> protected override void OnPaint(System.Drawing.Graphics g) { //Y coordinate for ChControl int y = 5; //X coordiante for ChControl int x = 5; //Height of ChControl int height = Height; //Width of ChControl int width = Width; //Draw title if (ShowTitle) { SizeF ts = g.MeasureString(Title, bold, Width, tsf); g.DrawString(Title, bold, new SolidBrush(ForeColor), new RectangleF(new Point(0, y), new SizeF(Width, ts.Height)), tsf); //Add Title Height to y coordinate y += (int)Math.Ceiling(ts.Height); } //Draw XLabel SizeF xs = g.MeasureString(XLabel, Font, Width, tsf); g.DrawString(XLabel, Font, new SolidBrush(ForeColor), new RectangleF(new Point(0, Height - (int)Math.Ceiling(xs.Height)), new SizeF(Width, xs.Height)), tsf); //Subtract X Label height from ChControl height height -= (int)Math.Ceiling(xs.Height); //Draw Y Titles if (ShowLegend) { // //Draw Legend if (legendhorizontal) { ly.Font = Font; ly.MeasureContent(g); GraphicsContainer gc1 = g.BeginContainer(); g.TranslateTransform(Width - ly.Width - 1, 1); ly.Paint(g); g.EndContainer(gc1); //Subtract legend width from ChControl width width -= ly.Width + 1; } else { GraphicsContainer gc1 = g.BeginContainer(); g.TranslateTransform(1, this.Height / 2 - ly.Height / 2); ly.Paint(g); g.EndContainer(gc1); x += ly.Width + 1; } // } // //Draw Single Y Title // else if (YLabels.Length == 1) // { // GraphicsContainer gc1 = g.BeginContainer(); // SizeF ys = g.MeasureString(YLabels[0],Font,Height,tsf); // g.RotateTransform(-90); // g.DrawString(YLabels[0],Font,new SolidBrush(ForeColor), // new RectangleF(new PointF(-Height,0),new SizeF(Height,ys.Height)),tsf); // g.EndContainer(gc1); // // //Add Y title height to ChControl X coordinate // x += (int)Math.Ceiling(ys.Height); // } } //Draw X axis label if (XType != null) { SizeF xss = g.MeasureString(XType, Font); g.DrawString(XType, Font, new SolidBrush(ForeColor), width - xss.Width, height - xss.Height); //Subtract Height of x axis label from ChControl height height -= (int)Math.Ceiling(xss.Height); } //Draw Y axis label if (YType != null) { SizeF xss = g.MeasureString(YType, Font); g.DrawString(YType, Font, new SolidBrush(ForeColor), 0, y); //Set the x coordinate to new value if it is too small if (x < (int)Math.Ceiling(xss.Width)) { x = (int)Math.Ceiling(xss.Width); } } //Set Location and Size of ChControl and Paint it GraphicsContainer gc = g.BeginContainer(); cc.Location = new Point(x, y); cc.Paint(g); g.EndContainer(gc); }
public void Crss3DDrawTst(Graphics G) { { //GraphicsContainer ArrCross GraphicsContainer ArrCross = G.BeginContainer(); //Arrow cross Container int z = 10; int w = 20; int h = 20; Random random = new Random(); Color orntCross = Color.FromArgb(random.Next(50, 255), random.Next(0, 255), random.Next(25, 255));//rnd Color Pen pncl = new Pen(Color.FromArgb(32, 78, 70), 3f); Point SpwLc = new Point(15, 15); G.ScaleTransform(1.0f, -1.0f); G.TranslateTransform(0, -Height); { GraphicsContainer x = G.BeginContainer();////X Arrow ContainerX G.DrawLine(pncl, SpwLc.X, SpwLc.Y, SpwLc.X + w, SpwLc.Y); G.DrawLine(pncl, SpwLc.X + w, SpwLc.Y, SpwLc.X + w + w / 2 - (z * 2 / Cnst.FltZ), SpwLc.Y + (z / 2 / Cnst.FltZ)); G.DrawLine(pncl, SpwLc.X + w, SpwLc.Y, SpwLc.X + w + w / 2 - (z * 2 / Cnst.FltZ), SpwLc.Y - (z / 2 / Cnst.FltZ)); GraphicsContainer xRotate = G.BeginContainer(); G.ScaleTransform(1.0f, -1.0f); G.TranslateTransform(0, -Height); SizeF txtSz = G.MeasureString("X", myFont); G.DrawString("X", myFont, new SolidBrush(Color.FromArgb(32, 78, 70)), SpwLc.X + w, SpwLc.Y + (txtSz.Height) / 2); G.EndContainer(xRotate); G.EndContainer(x);//X Arrow X ContainerEnd }////X Arrow ContainerX { GraphicsContainer yArrw = G.BeginContainer(); //Y Arrow ContainerY G.DrawLine(pncl, SpwLc.X, SpwLc.Y, SpwLc.X, SpwLc.Y + h); GraphicsContainer y = G.BeginContainer(); //ContainerY Rotate G.TranslateTransform(SpwLc.X, SpwLc.Y + h); G.RotateTransform(180); //ROTATE STRING!! SizeF textSize = G.MeasureString("Y", myFont); G.ScaleTransform(-1.0f, 1.0f); //MIRRORED VIEW to mirrored STRING = go back to originall!! G.DrawString("Y", myFont, new SolidBrush(Color.FromArgb(32, 78, 70)), -(textSize.Width / 2), -(textSize.Height)); G.EndContainer(y); // Y Rotate ContainerEnd G.DrawLine(pncl, SpwLc.X, SpwLc.Y + h, SpwLc.X + (z / 2 / Cnst.FltZ), SpwLc.Y + (z / Cnst.FltZ)); G.DrawLine(pncl, SpwLc.X, SpwLc.Y + h, SpwLc.X - (z / 2 / Cnst.FltZ), SpwLc.Y + (z / Cnst.FltZ)); G.EndContainer(yArrw);//Y Arrow ContainerY End }//Y Arrow ContainerY { ////Z Arrow ContainerZ GraphicsContainer Z = G.BeginContainer(); ////X Arrow ContainerX //Z Arrow //G.ScaleTransform(1.0f, -1.0f); //G.TranslateTransform(0, -Height); G.DrawLine(pncl, SpwLc.X, SpwLc.Y, SpwLc.X + (z / Cnst.FltZ), SpwLc.Y + (z / Cnst.FltZ)); G.DrawLine(pncl, SpwLc.X + (z / Cnst.FltZ), SpwLc.Y + (z / Cnst.FltZ), SpwLc.X + (z / Cnst.FltZ), SpwLc.Y + (z / Cnst.FltZ) - 9); G.DrawLine(pncl, SpwLc.X + (z / Cnst.FltZ), SpwLc.Y + (z / Cnst.FltZ), SpwLc.X + (z / Cnst.FltZ) - 9, SpwLc.Y + (z / Cnst.FltZ)); //Z Arrow GraphicsContainer zRotate = G.BeginContainer(); G.TranslateTransform(SpwLc.X + (z / Cnst.FltZ), SpwLc.Y + (z / Cnst.FltZ)); G.RotateTransform(180);//ROTATE STRING!! SizeF txtSz = G.MeasureString("Z", myFont); G.DrawString("Z", myFont, new SolidBrush(Color.FromArgb(32, 78, 70)), SpwLc.X + (z / Cnst.FltZ), SpwLc.Y + (z / Cnst.FltZ) + (txtSz.Height) / 2 + (z / Cnst.FltZ)); G.EndContainer(zRotate); G.EndContainer(Z);//Z Arrow Z ContainerEnd }////Z Arrow ContainerZ G.EndContainer(ArrCross);//ContainerEnd////Arrow cross Container }//ArrCross GraphicsContainer }
public override void Draw(Graphics g, int time) { if (base.DrawVisible) { Matrix matrix1 = base.Transform.Matrix.Clone(); GraphicsContainer container1 = g.BeginContainer(); g.SmoothingMode = base.OwnerDocument.SmoothingMode; Matrix matrix2 = base.GraphTransform.Matrix.Clone(); base.GraphTransform.Matrix.Multiply(matrix1, MatrixOrder.Prepend); ClipAndMask.ClipPath.Clip(g, time, this); bool flag1 = base.Visible; if (!base.Visible) { g.SetClip(Rectangle.Empty); } float single1 = this.Opacity; if (this.svgAnimAttributes.ContainsKey("fill-opacity")) { single1 = Math.Min(single1, (float)this.svgAnimAttributes["fill-opacity"]); } ISvgBrush brush1 = this.GraphBrush; Stroke stroke1 = this.graphStroke; using (GraphicsPath path1 = (GraphicsPath)this.GPath.Clone()) { path1.Transform(base.GraphTransform.Matrix); if (!base.ShowBound) { if (this.IsMarkerChild) { Marker marker = this.ParentNode as Marker; this.IsChanged = false; this.pretime = time; stroke1 = marker.GraphStroke; if (brush1 != null && !brush1.IsEmpty()) { brush1 = marker.GraphBrush; } } if (((brush1 != null) && !(this is Line)) && !(this is Polyline)) { brush1.Paint(path1, g, time, single1); } stroke1.Paint(g, this, path1, time); if (this is Polyline) { if (LineType == "1") { //平行线, using (Pen p = new Pen(brush1.Pen.Color)) { p.Width = this.graphStroke.StrokePen.Width; p.CompoundArray = new float[] { 0f, 0.1f, 0.9f, 1f }; g.DrawPath(p, path1); } } else if (LineType == "2") //铁路效果 { using (Pen p = new Pen(Color.FromArgb(120, 120, 120))) { p.Width = this.graphStroke.StrokePen.Width; p.CompoundArray = new float[] { 0f, 0.1f, 0.9f, 1f }; g.DrawPath(p, path1); } } } } else { g.DrawPath(new Pen(base.BoundColor), path1); } this.DrawConnect(g); } matrix1.Dispose(); ClipAndMask.ClipPath.DrawClip(g, time, this); g.EndContainer(container1); this.pretime = time; } }
internal static void EndTransform(Graphics g, GraphicsContainer cont) { g.EndContainer(cont); }
protected void PaintMarkers(Graphics g) { string markerStartUrl = extractMarkerUrl(this.GetAttribute("marker-start")); string markerEndUrl = extractMarkerUrl(this.GetAttribute("marker-end")); PointF[] points1 = this.Points.Clone() as PointF[]; int num1 = 0; int num11 = 1; int num3 = 0; int num33 = 1; if (points1.Length > 3) { num33 = points1.Length - 1; num3 = num33 - 1; } base.GraphTransform.Matrix.TransformPoints(points1); float angle = 0f;//(float)(180*Math.Atan2(points1[1].Y - points1[0].Y,points1[1].X-points1[0].X)/Math.PI); GraphicsContainer container1 = g.BeginContainer(); Marker element1; if (markerStartUrl.Length > 0) { angle = (float)(180 * Math.Atan2(points1[num11].Y - points1[num1].Y, points1[num11].X - points1[num1].X) / Math.PI); element1 = (Marker)NodeFunc.GetRefNode(markerStartUrl, this.OwnerDocument); if (element1 is Marker) { ((Marker)element1).GraphTransform.Matrix = new Matrix(); Matrix matrix1 = ((Marker)element1).MarkerTransForm; matrix1.Rotate(angle); matrix1.Translate(points1[num1].X, points1[num1].Y, MatrixOrder.Append); element1.GraphStroke = this.GraphStroke; element1.IsMarkerChild = true; ((Marker)element1).Draw(g, 0); } } if (markerEndUrl.Length > 0) { angle = (float)(180 * Math.Atan2(points1[num33].Y - points1[num3].Y, points1[num33].X - points1[num3].X) / Math.PI); element1 = (Marker)NodeFunc.GetRefNode(markerEndUrl, this.OwnerDocument); if (element1 is Marker) { ((Marker)element1).GraphTransform.Matrix = new Matrix(); Matrix matrix1 = ((Marker)element1).MarkerTransForm; matrix1.Rotate(angle); matrix1.Translate(points1[num33].X, points1[num33].Y, MatrixOrder.Append); element1.GraphStroke = this.GraphStroke; element1.IsMarkerChild = true; ((Marker)element1).Draw(g, 0); } } g.EndContainer(container1); }
public void EndContainer (GraphicsContainer container) { Restore(container.StateObject); }
public void Rotate(double newTh) { theta = (newTh/180*Math.PI); gC = actGr.BeginContainer(); actGr.RotateTransform(CommonMath.ToDeg(theta)); int xh = (int)(activeShip.Width / 2); int yh = (int)(activeShip.Height / 2); int a = (int)(activeShip.Width / 2 - initialShip.Width / 2); int b = (int)(activeShip.Height / 2 - initialShip.Height / 2); //double test1 = a * Math.Cos(theta); //double test2 = -b * Math.Sin(theta); //double test3 = activeShip.Width / 2; //double test4 = a * Math.Cos(theta) - b * Math.Sin(theta) + activeShip.Width / 2; //TODO: need to add initial angle. double ja = CommonMath.JointAngle(CommonMath.ToVector(xh, yh, a, b), CommonMath.ToVector(xh, yh, 1, 0)); int ja2 = (int)ja; int apr = (int)(a * Math.Cos(theta+ja2) - b * Math.Sin(theta+ja2) + initialShip.Width / 2); int bpr = (int)(a * Math.Sin(theta+ja2) + b * Math.Cos(theta+ja2) + initialShip.Height / 2); actGr.FillRectangle(Brushes.Red, x, y, x + 10, y + 10); actGr.DrawImage(initialShip, apr, bpr); actGr.EndContainer(gC); }
public override void Draw(Graphics g, int time) { if (BackgroundImage == null) { base.Draw(g, time); } else { if (base.DrawVisible) { Matrix matrix1 = base.Transform.Matrix.Clone(); GraphicsContainer container1 = g.BeginContainer(); g.SmoothingMode = base.OwnerDocument.SmoothingMode; Matrix matrix2 = base.GraphTransform.Matrix.Clone(); base.GraphTransform.Matrix.Multiply(matrix1, MatrixOrder.Prepend); ClipAndMask.ClipPath.Clip(g, time, this); bool flag1 = base.Visible; if (!base.Visible) { g.SetClip(Rectangle.Empty); } float single1 = this.Opacity; if (this.svgAnimAttributes.ContainsKey("fill-opacity")) { single1 = Math.Min(single1, (float)this.svgAnimAttributes["fill-opacity"]); } using (GraphicsPath path1 = (GraphicsPath)this.GPath.Clone()) { path1.Transform(base.GraphTransform.Matrix); if (!base.ShowBound) { ImageAttributes imageAttributes = new ImageAttributes(); ColorMatrix cmatrix1 = new ColorMatrix(); cmatrix1.Matrix00 = 1f; cmatrix1.Matrix11 = 1f; cmatrix1.Matrix22 = 1f; cmatrix1.Matrix33 = single1;//透明度 cmatrix1.Matrix44 = 1f; //设置透明度 imageAttributes.SetColorMatrix(cmatrix1, ColorMatrixFlag.Default, ColorAdjustType.Default); TextureBrush tbush = new TextureBrush(BackgroundImage, new RectangleF(0, 0, image1.Width, image1.Height), imageAttributes); tbush.WrapMode = WrapMode.Tile; tbush.TranslateTransform(path1.PathPoints[0].X, path1.PathPoints[0].Y); tbush.ScaleTransform(matrix2.Elements[0] / 8, matrix2.Elements[0] / 8); //tbush.RotateTransform(45); g.FillPath(tbush, path1); ItopVector.Core.Paint.Stroke stroke1 = ItopVector.Core.Paint.Stroke.GetStroke(this); this.GraphStroke.Update(this, time); float penwidth = this.GraphStroke.StrokePen.Width * matrix2.Elements[0] / 6; using (Pen pen1 = new Pen(this.GraphStroke.StrokeColor, penwidth)) { g.DrawPath(pen1, path1); } //this.GraphStroke.Paint(g, this, path1, time); } else { g.DrawPath(new Pen(base.BoundColor), path1); } this.DrawConnect(g); } matrix1.Dispose(); ClipAndMask.ClipPath.DrawClip(g, time, this); g.EndContainer(container1); this.pretime = time; } } }
public GraphicsContainer BeginContainer() { if (stateStack == null) { stateStack = new object[MAX_GRAPHICS_STATE_STACK]; statePos = 0; } var gsCurrentState = new GraphicsContainer(++statePos); var currentState = new CGGraphicsState(); currentState.lastPen = LastPen; currentState.lastBrush = LastBrush; // Make sure we clone the Matrices or we will still modify // them after the save as they are the same objects. Woops!! currentState.model = modelMatrix.Clone(); currentState.view = viewMatrix.Clone(); currentState.compositingQuality = CompositingQuality; currentState.compositingMode = CompositingMode; currentState.interpolationMode = interpolationMode; currentState.pageScale = pageScale; currentState.pageUnit = graphicsUnit; //currentState.pixelOffsetMode = PixelOffsetMode; currentState.smoothingMode = smoothingMode; //currentState.textContrast = TextContrast; //currentState.textRenderingHint = TextRenderingHint; currentState.renderingOrigin = renderingOrigin; currentState.clipRegion = clipRegion; stateStack[gsCurrentState.NativeObject] = currentState; return gsCurrentState; }
public void EndContainer(GraphicsContainer container) { this.baseGraphics.EndContainer(container); }
public void EndContainer(GraphicsContainer container) { throw new NotImplementedException(); }
/// <summary> /// 将RichTextBox中的文本 转换成图片并设置成背景 /// </summary> private void SaveRichTextAsImage(FlowDocument flowDocument) { var height = RichTextEditor.ActualHeight - 2; var width = RichTextEditor.ActualWidth - 2; int bold = flowDocument.FontWeight == FontWeights.Bold ? 1 : 0; var italic = flowDocument.FontStyle == FontStyles.Italic ? 2 : 0; int underline = 0; var fontStyle = (System.Drawing.FontStyle)(bold + italic + underline); var content = GetTextEditorContent(flowDocument); using (Bitmap bitmap = new Bitmap((int)width, (int)height)) { using (Graphics g = Graphics.FromImage(bitmap)) { Font font = new System.Drawing.Font("宋体", (float)flowDocument.FontSize, fontStyle, GraphicsUnit.Pixel); RectangleF rectangleF = new RectangleF(4.1f, 12, (float)width, (float)height); Rectangle rect = new Rectangle(4, 12, (int)width, (int)height); GraphicsContainer gc = g.BeginContainer(); try { g.SmoothingMode = SmoothingMode.HighQuality; g.PixelOffsetMode = PixelOffsetMode.Default; // PixelOffsetMode.HighQuality 在插入带有文字的图片变模糊 g.InterpolationMode = InterpolationMode.HighQualityBicubic; var stringFormat = StringFormat.GenericTypographic; if (fontStyle == System.Drawing.FontStyle.Bold && fontStyle != System.Drawing.FontStyle.Italic) { stringFormat.FormatFlags = StringFormatFlags.LineLimit; } if (fontStyle == (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic)) { // 如果是斜体加上粗体 那么 选择 SingleBitPerPixelGridFit 模式 g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit; stringFormat.FormatFlags = StringFormatFlags.FitBlackBox | StringFormatFlags.LineLimit | StringFormatFlags.NoClip; } else { //g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit; g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit; } g.CompositingMode = CompositingMode.SourceOver; g.CompositingQuality = CompositingQuality.HighQuality; //g.DrawString(content, font, System.Drawing.Brushes.Red, rectangleF, // StringFormat.GenericTypographic); //StringFormat drawFormat = new StringFormat(); //drawFormat.FormatFlags = StringFormatFlags.LineLimit | StringFormatFlags.FitBlackBox | StringFormatFlags.NoClip ; //drawFormat.Trimming = StringTrimming.None; //var test = StringFormat.GenericTypographic; //test.FormatFlags = StringFormatFlags.NoClip; //Console.WriteLine(test.FormatFlags); g.DrawString(content, font, System.Drawing.Brushes.Red, rectangleF, stringFormat); //TextFormatFlags flags = TextFormatFlags.WordBreak; //TextRenderer.DrawText(g, content, font, rect, System.Drawing.Color.Blue, flags); //g.DrawRectangle(Pens.Black, Rectangle.Round(rect)); //g.DrawString(content, font, System.Drawing.Brushes.Green, rectangleF, // drawFormat); //g.DrawString(content, font, System.Drawing.Brushes.Red, 4.1f, 12, // StringFormat.GenericTypographic); } catch (Exception e) { } finally { g.EndContainer(gc); } } #region 保存为图片和生成背景图片 var bitmapSource = Bitmap2BitmapSource(bitmap); var imageBrush = new ImageBrush(bitmapSource); imageBrush.Stretch = Stretch.None; RichTextEditor.Background = imageBrush; bitmap.Save("test.png"); #endregion 保存为图片和生成背景图片 } }
public override void OnPaintWorkflow(PaintEventArgs e, ViewPortData viewPortData) { Graphics graphics = e.Graphics; Debug.Assert(graphics != null); Bitmap memoryBitmap = viewPortData.MemoryBitmap; Debug.Assert(memoryBitmap != null); //Get the drawing canvas AmbientTheme ambientTheme = WorkflowTheme.CurrentTheme.AmbientTheme; //We set the highest quality interpolation so that we do not loose the image quality GraphicsContainer graphicsState = graphics.BeginContainer(); //Fill the background using the workspace color so that we communicate the paging concept Rectangle workspaceRectangle = new Rectangle(Point.Empty, memoryBitmap.Size); graphics.FillRectangle(AmbientTheme.WorkspaceBackgroundBrush, workspaceRectangle); using (Font headerFooterFont = new Font(ambientTheme.Font.FontFamily, ambientTheme.Font.Size / this.scaling, ambientTheme.Font.Style)) { int currentPage = 0; Matrix emptyMatrix = new Matrix(); //Create the transformation matrix and calculate the physical viewport without translation and scaling //We need to get the physical view port due to the fact that there can be circustances when zoom percentage //is very high, logical view port can be empty in such cases Matrix coOrdTxMatrix = new Matrix(); coOrdTxMatrix.Scale(viewPortData.Scaling.Width, viewPortData.Scaling.Height, MatrixOrder.Prepend); coOrdTxMatrix.Invert(); Point[] points = new Point[] { viewPortData.Translation, new Point(viewPortData.ViewPortSize) }; coOrdTxMatrix.TransformPoints(points); coOrdTxMatrix.Invert(); Rectangle physicalViewPort = new Rectangle(points[0], new Size(points[1])); //Create the data for rendering header/footer WorkflowPrintDocument.HeaderFooterData headerFooterData = new WorkflowPrintDocument.HeaderFooterData(); headerFooterData.HeaderFooterMargins = this.headerFooterMargins; headerFooterData.PrintTime = this.previewTime; headerFooterData.TotalPages = this.pageLayoutInfo.Count; headerFooterData.Scaling = this.scaling; headerFooterData.Font = headerFooterFont; WorkflowDesignerLoader serviceDesignerLoader = this.serviceProvider.GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader; headerFooterData.FileName = (serviceDesignerLoader != null) ? serviceDesignerLoader.FileName : String.Empty; //Create the viewport transformation matrix Matrix viewPortMatrix = new Matrix(); viewPortMatrix.Scale(viewPortData.Scaling.Width, viewPortData.Scaling.Height, MatrixOrder.Prepend); viewPortMatrix.Translate(-viewPortData.Translation.X, -viewPortData.Translation.Y, MatrixOrder.Append); //We now have the viewport properly drawn, now we need to draw it on the actual graphics object //Now that we have the designer bitmap we start splicing it based on the pages //Note that this is quite expensive operation and hence one should try to use //The memory bitmap we have got is scaled appropriately foreach (PageLayoutData pageLayoutData in this.pageLayoutInfo) { currentPage += 1; //We do not draw the non intersecting pages, get the intersected viewport //We purposely use the physical viewport here because, there are cases in which the viewport //will not contain any logical bitmap areas in which case we atleast need to draw the pages properly if (!pageLayoutData.PageBounds.IntersectsWith(physicalViewPort) || pageLayoutData.PageBounds.Width <= 0 || pageLayoutData.PageBounds.Height <= 0) { continue; } //******START PAGE DRAWING, FIRST DRAW THE OUTLINE //Scale and translate so that we can draw the pages graphics.Transform = viewPortMatrix; graphics.FillRectangle(Brushes.White, pageLayoutData.PageBounds); ActivityDesignerPaint.DrawDropShadow(graphics, pageLayoutData.PageBounds, Color.Black, AmbientTheme.DropShadowWidth, LightSourcePosition.Left | LightSourcePosition.Top, 0.2f, false); //***START BITMAP SPLICING //Draw spliced bitmap for the page if we have any displayable area Rectangle intersectedViewPort = pageLayoutData.LogicalPageBounds; intersectedViewPort.Intersect(viewPortData.LogicalViewPort); if (!intersectedViewPort.IsEmpty) { //Make sure that we now clear the translation factor graphics.Transform = emptyMatrix; //Paint bitmap on the pages //Now that the page rectangle is actually drawn, we will scale down the Location of page rectangle //so that we can draw the viewport bitmap part on it Point bitmapDrawingPoint = Point.Empty; bitmapDrawingPoint.X = pageLayoutData.ViewablePageBounds.X + Math.Abs(pageLayoutData.LogicalPageBounds.X - intersectedViewPort.X); bitmapDrawingPoint.Y = pageLayoutData.ViewablePageBounds.Y + Math.Abs(pageLayoutData.LogicalPageBounds.Y - intersectedViewPort.Y); points = new Point[] { bitmapDrawingPoint }; coOrdTxMatrix.TransformPoints(points); bitmapDrawingPoint = new Point(points[0].X - viewPortData.Translation.X, points[0].Y - viewPortData.Translation.Y); //This is the area of the viewport bitmap we need to copy on the page Rectangle viewPortBitmapArea = Rectangle.Empty; viewPortBitmapArea.X = intersectedViewPort.X - viewPortData.LogicalViewPort.X; viewPortBitmapArea.Y = intersectedViewPort.Y - viewPortData.LogicalViewPort.Y; viewPortBitmapArea.Width = intersectedViewPort.Width; viewPortBitmapArea.Height = intersectedViewPort.Height; //This rectangle is in translated logical units, we need to scale it down points = new Point[] { viewPortBitmapArea.Location, new Point(viewPortBitmapArea.Size) }; coOrdTxMatrix.TransformPoints(points); viewPortBitmapArea.Location = points[0]; viewPortBitmapArea.Size = new Size(points[1]); ActivityDesignerPaint.DrawImage(graphics, memoryBitmap, new Rectangle(bitmapDrawingPoint, viewPortBitmapArea.Size), viewPortBitmapArea, DesignerContentAlignment.Fill, 1.0f, WorkflowTheme.CurrentTheme.AmbientTheme.DrawGrayscale); } //***END BITMAP SPLICING //Draw the page outline graphics.Transform = viewPortMatrix; graphics.DrawRectangle(Pens.Black, pageLayoutData.PageBounds); //Draw the printable page outline graphics.DrawRectangle(ambientTheme.ForegroundPen, pageLayoutData.ViewablePageBounds.Left - 3, pageLayoutData.ViewablePageBounds.Top - 3, pageLayoutData.ViewablePageBounds.Width + 6, pageLayoutData.ViewablePageBounds.Height + 6); //Draw the header and footer after we draw the actual page headerFooterData.PageBounds = pageLayoutData.PageBounds; headerFooterData.PageBoundsWithoutMargin = pageLayoutData.ViewablePageBounds; headerFooterData.CurrentPage = currentPage; //Draw the header if (this.printDocument.PageSetupData.HeaderTemplate.Length > 0) { this.printDocument.PrintHeaderFooter(graphics, true, headerFooterData); } //Draw footer if (this.printDocument.PageSetupData.FooterTemplate.Length > 0) { this.printDocument.PrintHeaderFooter(graphics, false, headerFooterData); } //***END DRAWING HEADER FOOTER } graphics.EndContainer(graphicsState); } }
protected void PaintMarkers(Graphics g) { string markerStartUrl = extractMarkerUrl(this.GetAttribute("marker-start")); string markerMiddleUrl = extractMarkerUrl(this.GetAttribute("marker-mid")); string markerEndUrl = extractMarkerUrl(this.GetAttribute("marker-end")); PointF pt0 = new PointF(this.X1, this.Y1); PointF pt1 = new PointF(this.X2, this.Y2); PointF pt2 = new PointF((this.X1 + this.X2) / 2, (this.Y1 + this.Y2) / 2); PointF[] points1 = new PointF[] { pt0, pt1, pt2 }; int num1 = 0; int num11 = 1; // int num2 = 2; // int num22 = 1; int num3 = 0; int num33 = 1; if (this is ConnectLine) { PointF[] points2 = this.GPath.PathPoints.Clone() as PointF[]; points1 = points2; if (points2.Length > 3) { // points1 = points2; num33 = points1.Length - 1; num3 = num33 - 1; } } base.GraphTransform.Matrix.TransformPoints(points1); float angle = 0f; //(float)(180*Math.Atan2(points1[1].Y - points1[0].Y,points1[1].X-points1[0].X)/Math.PI); GraphicsContainer container1 = g.BeginContainer(); Marker element1; if (markerStartUrl.Length > 0) { angle = (float)(180 * Math.Atan2(points1[num11].Y - points1[num1].Y, points1[num11].X - points1[num1].X) / Math.PI); element1 = (Marker)NodeFunc.GetRefNode(markerStartUrl, this.OwnerDocument); if (element1 is Marker) { ((Marker)element1).GraphTransform.Matrix = new Matrix(); Matrix matrix1 = ((Marker)element1).MarkerTransForm; matrix1.Rotate(angle); matrix1.Translate(points1[num1].X, points1[num1].Y, MatrixOrder.Append); element1.GraphStroke = this.GraphStroke; element1.IsMarkerChild = true; ((Marker)element1).Draw(g, 0); } } if (markerMiddleUrl.Length > 0) { element1 = (Marker)NodeFunc.GetRefNode(markerMiddleUrl, this.OwnerDocument); if (element1 is IGraph) { ((Marker)element1).GraphTransform.Matrix = new Matrix(); Matrix matrix1 = ((Marker)element1).MarkerTransForm; matrix1.Rotate(angle); matrix1.Translate(points1[2].X, points1[2].Y, MatrixOrder.Append); element1.GraphStroke = this.GraphStroke; element1.IsMarkerChild = true; ((IGraph)element1).Draw(g, 0); } } if (markerEndUrl.Length > 0) { angle = (float)(180 * Math.Atan2(points1[num33].Y - points1[num3].Y, points1[num33].X - points1[num3].X) / Math.PI); element1 = (Marker)NodeFunc.GetRefNode(markerEndUrl, this.OwnerDocument); if (element1 is IGraph) { ((Marker)element1).GraphTransform.Matrix = new Matrix(); Matrix matrix1 = ((Marker)element1).MarkerTransForm; matrix1.Rotate(angle); matrix1.Translate(points1[num33].X, points1[num33].Y, MatrixOrder.Append); element1.GraphStroke = this.GraphStroke; element1.IsMarkerChild = true; ((IGraph)element1).Draw(g, 0); } } g.EndContainer(container1); }
private void Render(IGraphics ig) { string s = cbWhat.Text; if (String.IsNullOrEmpty(s)) { } else if (s == "Clipping") { Pen pn = new Pen(Color.LightGray, 5); Pen pn2 = new Pen(Color.Yellow); ig.Clear(Color.Black); GraphicsContainer cnt = ig.BeginContainer(); ig.SmoothingMode = SmoothingMode.HighQuality; ig.SetClip(new Rectangle(35, 35, 120, 120)); ig.DrawRectangle(pn, 5, 5, 45, 70); ig.DrawRectangle(pn, 15, 25, 90, 120); ig.DrawRectangle(pn, 50, 30, 100, 170); ig.DrawRectangle(pn, 5, 80, 180, 30); ig.DrawRectangle(pn, 75, 10, 40, 160); ig.EndContainer(cnt); ig.DrawRectangle(pn2, 5, 5, 45, 70); ig.DrawRectangle(pn2, 15, 25, 90, 120); ig.DrawRectangle(pn2, 50, 30, 100, 170); ig.DrawRectangle(pn2, 5, 80, 180, 30); ig.DrawRectangle(pn2, 75, 10, 40, 160); } else if (s == "Transforms") { ig.Clear(Color.Black); ig.RotateTransform(15); ig.DrawRectangle(new Pen(Color.Red, 2), 260, 80, 50, 40); ig.ResetTransform(); ig.DrawRectangle(new Pen(Color.Red, 2), 260, 80, 50, 40); ig.TranslateTransform(15, -5); GraphicsContainer cnt = ig.BeginContainer(); ig.SmoothingMode = SmoothingMode.HighQuality; ig.RotateTransform(5); ig.FillEllipse(new SolidBrush(Color.Orange), 100, 100, 80, 40); ig.DrawRectangle(new Pen(Color.Orange, 2), 60, 80, 40, 40); GraphicsContainer cnt2 = ig.BeginContainer(); ig.SmoothingMode = SmoothingMode.None; ig.RotateTransform(5); ig.ScaleTransform(1.1f, 1.2f); ig.FillEllipse(new SolidBrush(Color.YellowGreen), 130, 180, 80, 40); ig.DrawRectangle(new Pen(Color.YellowGreen, 2), 62, 80, 40, 40); GraphicsContainer cnt3 = ig.BeginContainer(); ig.SmoothingMode = SmoothingMode.HighQuality; Matrix mm = new Matrix(); mm.Shear(0.3f, 0f); ig.Transform = mm; ig.FillEllipse(new SolidBrush(Color.Green), 180, 120, 80, 40); ig.DrawRectangle(new Pen(Color.Green, 2), 62, 84, 40, 40); ig.EndContainer(cnt3); ig.EndContainer(cnt2); ig.FillEllipse(new SolidBrush(Color.Blue), 120, 150, 80, 40); ig.DrawRectangle(new Pen(Color.Blue, 2), 64, 80, 40, 40); ig.EndContainer(cnt); ig.FillEllipse(new SolidBrush(Color.Indigo), 80, 210, 80, 40); ig.DrawRectangle(new Pen(Color.Indigo, 2), 66, 80, 40, 40); ig.DrawRectangle(new Pen(Color.White, 2), 270, 30, 50, 40); ig.ResetTransform(); ig.DrawRectangle(new Pen(Color.White, 2), 270, 30, 50, 40); } else if (s == "Lines") { ig.SmoothingMode = SmoothingMode.AntiAlias; Pen ow = new Pen(Color.Purple, 12); ow.EndCap = LineCap.Round; ow.StartCap = LineCap.Round; ow.MiterLimit = 6f; ow.LineJoin = LineJoin.Miter; ig.SmoothingMode = SmoothingMode.None; Pen tp = new Pen(Color.Red, 2); tp.DashStyle = DashStyle.DashDot; ig.DrawLine(tp, 70, 20, 190, 20); tp.DashStyle = DashStyle.Dash; ig.DrawLine(tp, 70, 30, 190, 30); tp.DashStyle = DashStyle.Custom; tp.DashPattern = new float[] { 1, 8, 2, 2 }; ig.DrawLine(tp, 70, 40, 190, 40); ig.SmoothingMode = SmoothingMode.AntiAlias; PointF[] pts = new PointF[4]; pts[0] = new PointF(20, 50); pts[1] = new PointF(30, 90); pts[2] = new PointF(65, 60); pts[3] = new PointF(50, 40); ig.DrawLines(ow, pts); Point[] polly = new Point[] { new Point(200, 40), new Point(220, 140), new Point(240, 100), new Point(290, 70), new Point(230, 10) }; ig.DrawPolygon(tp, polly); //arrows Pen arr = new Pen(Color.DarkGoldenrod, 5); { arr.Width = 2; arr.StartCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor; var arrowWidth = 11.0f; // TUNE: var arrowHeight = 14f; // TUNE: var arrowOutline = new System.Drawing.Drawing2D.GraphicsPath(); arrowOutline.AddLines(new PointF[] { new PointF(-(arrowWidth / 2), -arrowHeight), new PointF(0, 0), new PointF((arrowWidth / 2), -arrowHeight), new PointF(-(arrowWidth / 2), -arrowHeight) }); var generalizationArrow = new System.Drawing.Drawing2D.CustomLineCap(null, arrowOutline); generalizationArrow.SetStrokeCaps(System.Drawing.Drawing2D.LineCap.Round, System.Drawing.Drawing2D.LineCap.Round); generalizationArrow.BaseInset = arrowHeight; arr.CustomEndCap = generalizationArrow; ig.DrawLine(arr, 0, 120, 100, 200); } arr.Width = 5; AdjustableArrowCap aac = new AdjustableArrowCap(5, 3, false); arr.EndCap = LineCap.Custom; arr.CustomEndCap = aac; arr.StartCap = LineCap.ArrowAnchor; ig.DrawLine(arr, 50, 120, 150, 200); arr.Width = 7f; arr.EndCap = LineCap.RoundAnchor; arr.StartCap = LineCap.SquareAnchor; ig.DrawLine(arr, 100, 120, 200, 200); arr.Width = 9; arr.EndCap = LineCap.DiamondAnchor; arr.StartCap = LineCap.ArrowAnchor; ig.DrawLine(arr, 150, 120, 250, 200); Point[] al = new Point[] { new Point(200, 100), new Point(300, 200), new Point(300, 150) }; arr.Width = 9; arr.EndCap = LineCap.DiamondAnchor; arr.StartCap = LineCap.DiamondAnchor; ig.DrawLines(arr, al); } else if (s == "Curves") { PointF[] bezzie = new PointF[] { new PointF(20, 150), new PointF(110, 190), new PointF(120, 200), new PointF(50, 220), new PointF(60, 200), new PointF(140, 180), new PointF(100, 160), new PointF(180, 260), new PointF(200, 210), new PointF(190, 210) }; Pen bpn = new Pen(Color.MediumSeaGreen, 2); bpn.DashStyle = DashStyle.Custom; bpn.DashPattern = new float[] { 6, 1, 5, 2, 4, 3, 3, 4, 2, 5, 6, 1 }; ig.DrawBeziers(bpn, bezzie); PointF[] curvy = new PointF[] { new PointF(130, 40), new PointF(70, 70), new PointF(50, 20), new PointF(120, 120), new PointF(150, 80), new PointF(80, 150), new PointF(80, 110) }; ig.DrawCurve(new Pen(Color.Blue, 5), curvy); ig.DrawCurve(new Pen(Color.Red, 2), curvy, 2, 3); ig.DrawCurve(new Pen(Color.Yellow, 1), curvy, 1f); Point[] ccurvy = new Point[] { new Point(280, 30), new Point(260, 60), new Point(200, 20), new Point(290, 120), new Point(290, 80), new Point(230, 150), new Point(150, 50) }; ig.DrawClosedCurve(new Pen(Color.Green, 3), ccurvy, 1f, FillMode.Alternate); ig.DrawClosedCurve(new Pen(Color.Purple, 1), ccurvy, 0f, FillMode.Alternate); Point[] fcc = new Point[] { new Point(160, 350), new Point(190, 370), new Point(130, 390), new Point(190, 400), new Point(195, 410), new Point(100, 430), new Point(160, 450) }; ig.FillClosedCurve(new SolidBrush(Color.Red), fcc, FillMode.Winding, 1f); ig.FillClosedCurve(new SolidBrush(Color.Aquamarine), fcc, FillMode.Alternate, .2f); } else if (s == "Transparency") { Point[] fillpoly = new Point[] { new Point(20, 130), new Point(60, 90), new Point(30, 20), new Point(80, 20), new Point(15, 90), new Point(100, 50), new Point(0, 50) }; Color col = Color.FromArgb(96, 255, 0, 0); ig.FillEllipse(new SolidBrush(Color.Ivory), 60, 140, 60, 30); ig.FillPolygon(new SolidBrush(Color.Ivory), fillpoly, FillMode.Winding); ig.TranslateTransform(10, 10); ig.FillEllipse(new SolidBrush(col), 60, 140, 60, 30); ig.FillPolygon(new SolidBrush(col), fillpoly, FillMode.Alternate); ig.ResetTransform(); ig.FillPie(new SolidBrush(Color.FromArgb(100, 255, 0, 0)), 10, 200, 200, 80, 315, 90); ig.FillPie(new SolidBrush(Color.FromArgb(100, 128, 128, 0)), 10, 200, 200, 80, 250, -90); ig.FillPie(new SolidBrush(Color.FromArgb(100, 128, 0, 128)), 15, 205, 190, 70, 180, 270); ig.FillPie(new SolidBrush(Color.FromArgb(100, 200, 60, 60)), 20, 210, 180, 60, 45, -270); } else if (s == "Fills") { LinearGradientBrush gbr1 = new LinearGradientBrush(new Point(0, 0), new Point(30, 20), Color.Blue, Color.Plum); ColorBlend blend = new ColorBlend(3); blend.Colors = new Color[] { Color.Red, Color.Yellow, Color.MediumSlateBlue }; blend.Positions = new float[] { 0, .3f, 1f }; gbr1.InterpolationColors = blend; Point[] sp = new Point[] { new Point(145, 145), new Point(305, 250), new Point(220, 250), new Point(180, 250) }; ig.FillPolygon(gbr1, sp); LinearGradientBrush gbr2 = new LinearGradientBrush(new Point(0, 0), new Point(10, 20), Color.WhiteSmoke, Color.CornflowerBlue); gbr2.WrapMode = WrapMode.TileFlipXY; Point[] sp2 = new Point[] { new Point(25, 205), new Point(75, 150), new Point(110, 110), new Point(40, 80) }; ig.FillPolygon(gbr2, sp2); ig.FillRectangle(new HatchBrush(HatchStyle.DiagonalBrick, Color.Khaki, Color.Peru), 000, 5, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Vertical, Color.Bisque, Color.Peru), 020, 5, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.DarkVertical, Color.Tan, Color.Peru), 040, 5, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.DiagonalCross, Color.Chocolate, Color.Peru), 060, 5, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.WideDownwardDiagonal, Color.BurlyWood, Color.Peru), 080, 5, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.LargeConfetti, Color.Wheat, Color.Peru), 100, 5, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.ZigZag, Color.SaddleBrown, Color.Peru), 120, 5, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.HorizontalBrick, Color.Linen, Color.Peru), 140, 5, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.LightHorizontal, Color.Maroon, Color.Peru), 160, 5, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Percent05, Color.CornflowerBlue, Color.LemonChiffon), 000, 30, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Percent10, Color.CornflowerBlue, Color.LemonChiffon), 020, 30, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Percent20, Color.CornflowerBlue, Color.LemonChiffon), 040, 30, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Percent25, Color.CornflowerBlue, Color.LemonChiffon), 060, 30, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Percent30, Color.CornflowerBlue, Color.LemonChiffon), 080, 30, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Percent40, Color.CornflowerBlue, Color.LemonChiffon), 100, 30, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Percent50, Color.CornflowerBlue, Color.LemonChiffon), 120, 30, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Percent60, Color.CornflowerBlue, Color.LemonChiffon), 140, 30, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Percent70, Color.CornflowerBlue, Color.LemonChiffon), 160, 30, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Percent75, Color.CornflowerBlue, Color.LemonChiffon), 180, 30, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Percent80, Color.CornflowerBlue, Color.LemonChiffon), 200, 30, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Percent90, Color.CornflowerBlue, Color.LemonChiffon), 220, 30, 20, 20); } else if (s == "Arcs/Pies") { //GDI does not seem to draw arcs correctly except when the ellipse is a circle. //These arcs demonstrate the problem. SVGGraphics calculates arcs correctly. ig.DrawArc(new Pen(Color.Black, 2), 120 + 5 * 3, 120, 110 * 3, 110, 0, 240); ig.DrawArc(new Pen(Color.Black, 2), 120 + 10 * 3, 125, 100 * 3, 100, 0, 210); ig.DrawArc(new Pen(Color.Black, 2), 120 + 15 * 3, 130, 90 * 3, 90, 0, 180); ig.DrawArc(new Pen(Color.Black, 2), 120 + 20 * 3, 135, 80 * 3, 80, 0, 150); ig.DrawArc(new Pen(Color.Black, 2), 120 + 25 * 3, 140, 70 * 3, 70, 0, 120); ig.DrawArc(new Pen(Color.Black, 2), 120 + 30 * 3, 145, 60 * 3, 60, 0, 90); ig.DrawArc(new Pen(Color.Black, 2), 120 + 35 * 3, 150, 50 * 3, 50, 0, 60); ig.DrawArc(new Pen(Color.Black, 2), 120 + 40 * 3, 155, 40 * 3, 40, 0, 270); ig.DrawPie(new Pen(Color.Pink, 2), 110, 50, 100, 100, 315, 90); ig.DrawPie(new Pen(Color.Purple, 2), 110, 50, 100, 100, 250, -90); ig.DrawPie(new Pen(Color.DarkRed, 2), 115, 55, 90, 90, 180, 270); ig.DrawPie(new Pen(Color.Red, 2), 120, 60, 80, 80, 45, -270); } else if (s == "Text") { Font fnt1 = new Font("Helvetica", 12, FontStyle.Italic | FontStyle.Bold); Font fnt2 = new Font(FontFamily.GenericMonospace, 16, FontStyle.Bold); Font fnt3 = new Font("", 40, FontStyle.Underline); Rectangle rc1 = new Rectangle(30, 30, 220, 20); StringFormat fmt1 = new StringFormat(); fmt1.Alignment = StringAlignment.Near; ig.DrawRectangle(new Pen(Color.Blue), rc1); ig.DrawString("Text...1", fnt1, new SolidBrush(Color.DarkGreen), rc1, fmt1); Rectangle rc2 = new Rectangle(0, 0, 120, 20); StringFormat fmt2 = new StringFormat(); fmt2.Alignment = StringAlignment.Center; ig.TranslateTransform(30, 160); ig.RotateTransform(90); ig.DrawRectangle(new Pen(Color.Blue), rc2); ig.DrawString("Text...2", fnt2, new SolidBrush(Color.DarkGreen), rc2, fmt2); ig.ResetTransform(); Rectangle rc3 = new Rectangle(30, 90, 300, 30); StringFormat fmt3 = new StringFormat(); fmt3.Alignment = StringAlignment.Far; ig.DrawRectangle(new Pen(Color.Blue), rc3); ig.DrawString("Text...3", fnt3, new SolidBrush(Color.DarkGreen), rc3, fmt3); //measurestring string mme = "MeasureString Is Impossible To Emulate"; SizeF siz = ig.MeasureString(mme, fnt1); ig.DrawRectangle(new Pen(Color.Red), 20, 200, siz.Width, siz.Height); siz = ig.MeasureString(mme, fnt1, 150); ig.DrawRectangle(new Pen(Color.Orange), 20, 230, siz.Width, siz.Height); siz = ig.MeasureString(mme, fnt1, new SizeF(150, 150), new StringFormat(StringFormatFlags.DirectionVertical)); ig.DrawRectangle(new Pen(Color.Yellow), 20, 200, siz.Width, siz.Height); } else if (s == "Rect-aligned Text") { ig.Clear(Color.White); ig.ScaleTransform( (float)this.panel1.ClientSize.Width / RectAlignedTextTest.CanvasSize, (float)this.panel1.ClientSize.Height / RectAlignedTextTest.CanvasSize); RectAlignedTextTest.DrawTest(ig); } else if (s == "Images") { Icon ike = new Icon(GetType(), "App.ico"); ig.DrawIcon(ike, 10, 10); //ig.DrawIcon(ike, new Rectangle(270, 400, 30, 40)); Bitmap bmp = new Bitmap(GetType(), "test.bmp"); ig.DrawImage(bmp, 100f, 150f); GraphicsContainer cnt = ig.BeginContainer(); ig.RotateTransform(5); ig.DrawImage(bmp, 160f, 50f, 120f, 70f); ig.EndContainer(cnt); //ig.DrawImageUnscaled(bmp, 270, 450, 20, 20); } else { throw new NotImplementedException(); } }
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { Image image = null; DataGridViewTextAndImageCellValue cv = value as DataGridViewTextAndImageCellValue; if (cv != null) { image = cv.Image; } if (image != null && image.Width > 0) { //this will trigger Clone event because of SharedRow DataGridViewRow row = this.DataGridView.Rows[rowIndex]; //use Bitmap to draw out proper size Bitmap bmp = new Bitmap(image); int height; int width; if (bmp.Width > cellBounds.Width) { width = cellBounds.Width; height = Convert.ToInt32(1.0 * image.Height * cellBounds.Width / image.Width); } else { width = bmp.Width; height = bmp.Height; } if (row.Height < height) { row.Height = height; } base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, null, "", errorText, cellStyle, advancedBorderStyle, paintParts); // Draw the image to the cell. GraphicsContainer container = graphics.BeginContainer(); //graphics.SetClip(cellBounds); //graphics.DrawImageUnscaled(image, cellBounds.Location); Rectangle rect = new Rectangle(cellBounds.X, cellBounds.Y, width, height); graphics.DrawImage(bmp, rect); graphics.EndContainer(container); } else { // Paint the base content base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); } }
private void SevenSegment_Paint(object sender, PaintEventArgs e) { int useValue = customPattern; Brush brushLight = new SolidBrush(colorLight); Brush brushDark = new SolidBrush(colorDark); // Define transformation for our container... RectangleF srcRect = new RectangleF(0.0F, 0.0F, gridWidth, gridHeight); RectangleF destRect = new RectangleF(Padding.Left, Padding.Top, this.Width - Padding.Left - Padding.Right, this.Height - Padding.Top - Padding.Bottom); // Begin graphics container that remaps coordinates for our convenience GraphicsContainer containerState = e.Graphics.BeginContainer(destRect, srcRect, GraphicsUnit.Pixel); Matrix trans = new Matrix(); trans.Shear(italicFactor, 0.0F); e.Graphics.Transform = trans; e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; e.Graphics.PixelOffsetMode = PixelOffsetMode.Default; if ((useValue & 0x80) == 0x80) { e.Graphics.FillEllipse(brushLight, gridWidth / 2 - 8, gridHeight / 2 + 20, 20, 20); } else { // Draw elements based on whether the corresponding bit is high e.Graphics.FillPolygon((useValue & 0x1) == 0x1 ? brushLight : brushDark, segPoints[0]); e.Graphics.FillPolygon((useValue & 0x2) == 0x2 ? brushLight : brushDark, segPoints[1]); e.Graphics.FillPolygon((useValue & 0x4) == 0x4 ? brushLight : brushDark, segPoints[2]); e.Graphics.FillPolygon((useValue & 0x8) == 0x8 ? brushLight : brushDark, segPoints[3]); e.Graphics.FillPolygon((useValue & 0x10) == 0x10 ? brushLight : brushDark, segPoints[4]); e.Graphics.FillPolygon((useValue & 0x20) == 0x20 ? brushLight : brushDark, segPoints[5]); e.Graphics.FillPolygon((useValue & 0x40) == 0x40 ? brushLight : brushDark, segPoints[6]); if (HadDot) { if (showDot) { //System.Diagnostics.Trace.WriteLine(Name + "--" + customPattern + " " + dotUIOn); e.Graphics.FillEllipse(dotUIOn ? brushLight : brushDark, gridWidth - 4, gridHeight - elementWidth + 1, elementWidth, elementWidth); } else if (DoubleDot) { System.Diagnostics.Trace.WriteLine(Name + "--" + customPattern + " " + dotUIOn); e.Graphics.FillEllipse(dotUIOn ? brushLight : brushDark, gridWidth / 2 - 1, gridHeight / 2 - 10, elementWidth, elementWidth); e.Graphics.FillEllipse(dotUIOn ? brushLight : brushDark, gridWidth / 2 - 1, gridHeight / 2 + 10, elementWidth, elementWidth); } else { } } } e.Graphics.EndContainer(containerState); }
// Reset the graphics state back to a previous container level. public void EndContainer(GraphicsContainer container) { if(container != null) { lock(this) { container.Restore(this); } } }
public static void Main() { Bitmap bmp = new Bitmap(500, 250); Graphics dc = Graphics.FromImage(bmp); Pen BluePen = new Pen(Color.Blue, 3); Pen GreenPen = new Pen(Color.Green, 3); Pen RedPen = new Pen(Color.Red, 3); SolidBrush redBrush = new SolidBrush(Color.Red); SolidBrush blueBrush = new SolidBrush(Color.Blue); int x = 0; int y = 0; /* First Row */ dc.DrawRectangle(BluePen, x, y, 50, 50); x += 50; dc.DrawEllipse(RedPen, x, y, 70, 50); dc.DrawArc(BluePen, x, y, 50, 40, (float)0, (float)120); x += 70; dc.DrawBezier(GreenPen, new Point(x, y + 5), new Point(x + 50, y + 5), new Point(x + 20, y + 20), new Point(x + 50, y + 50)); x += 50; PointF point1 = new PointF(10.0F + x, 10.0F); PointF point2 = new PointF(10.0F + x, 5.0F); PointF point3 = new PointF(40.0F + x, 5.0F); PointF point4 = new PointF(50.0F + x, 10.0F); PointF point5 = new PointF(60.0F + x, 20.0F); PointF point6 = new PointF(70.0F + x, 40.0F); PointF point7 = new PointF(50.0F + x, 50.0F); PointF[] curvePoints = { point1, point2, point3, point4, point5, point6, point7 }; dc.DrawLines(RedPen, curvePoints); float tension = 1.0F; FillMode aFillMode = FillMode.Alternate; dc.DrawClosedCurve(GreenPen, curvePoints, tension, aFillMode); x += 80; // FillClosedCurve PointF point10 = new PointF(x, y + 15.0F); PointF point20 = new PointF(x + 40.0F, y + 10.0F); PointF point30 = new PointF(x + 50.0F, y + 40.0F); PointF point40 = new PointF(x + 10.0F, y + 30.0F); PointF[] points = { point10, point20, point30, point40 }; FillMode newFillMode = FillMode.Winding; dc.FillClosedCurve(redBrush, points, newFillMode, tension); // Fill pie to screen. dc.FillPie(blueBrush, x, 0, 200.0F, 100.0f, 300.0F, 45.0F); /* second row */ y += 80; x = 0; // Clipping and Graphics container test dc.SetClip(new Rectangle(5 + x, 5 + y, 75, 75)); // Begin a graphics container. GraphicsContainer container = dc.BeginContainer(); // Set an additional clipping region for the container. dc.SetClip(new Rectangle(50 + x, 25 + y, 50, 37)); // Fill a red rectangle in the container. dc.FillRectangle(redBrush, 0, 0, 200, 200); dc.EndContainer(container); SolidBrush blueBrushLight = new SolidBrush( Color.FromArgb(128, 0, 0, 255)); dc.FillRectangle(blueBrushLight, 0, 0, 200, 200); dc.ResetClip(); Pen blackPen = new Pen(Color.FromArgb(255, 0, 0, 0), 2.0f); dc.DrawRectangle(blackPen, 5 + x, 5 + y, 75, 75); dc.DrawRectangle(blackPen, 50 + x, 25 + y, 50, 37); x = 100; y += 10; Point[] ptstrans = { new Point(x, y), new Point(50 + x, 25 + y) }; dc.DrawLine(BluePen, ptstrans [0], ptstrans [1]); dc.TranslateTransform(40.0F, 30.0F); dc.TransformPoints(CoordinateSpace.Page, CoordinateSpace.World, ptstrans); dc.ResetTransform(); dc.DrawLine(RedPen, ptstrans [0], ptstrans [1]); bmp.Save("graphicsui.bmp", ImageFormat.Bmp); }
public GdiGraphicsContainer(GraphicsContainer idmap, GraphicsContainer main) { this.IdMap = idmap; this.Main = main; }
private void BoxView_Paint(object sender, PaintEventArgs e) { //绘制标尺网格 { Graphics g = e.Graphics; Rectangle rc = new Rectangle(0, 0, Size.Width, Size.Height); Rectangle rcdest = new Rectangle(center.X, center.Y, Size.Width, Size.Height); GraphicsContainer gc = g.BeginContainer(rcdest, rc, GraphicsUnit.Pixel); //对齐网格 if (snap_gird) { Pen pen2 = new Pen(System.Drawing.Color.FromArgb(50, System.Drawing.Color.Black)); pen2.DashStyle = DashStyle.Custom; pen2.DashPattern = new float[] { 3f, 3f }; float snap_unit_size = snap_size * unit_size; int snap_x_lines = (int)(Size.Height / snap_unit_size); for (int i = -snap_x_lines; i <= snap_x_lines; i++) { g.DrawLine(pen2, new Point(-Size.Width, (int)(i * snap_unit_size)), new Point(Size.Width, (int)(i * snap_unit_size))); } int snap_y_lines = (int)(Size.Width / snap_unit_size); for (int i = -snap_y_lines; i <= snap_y_lines; i++) { g.DrawLine(pen2, new Point((int)(i * snap_unit_size), -Size.Height), new Point((int)(i * snap_unit_size), Size.Height)); } } Pen pen = new Pen(Brushes.Black); //横线 g.DrawLine(pen, new Point(-Size.Width, 0), new Point(Size.Width, 0)); //竖线 g.DrawLine(pen, new Point(0, -Size.Height), new Point(0, Size.Height)); Pen penUnreal = new Pen(System.Drawing.Color.FromArgb(100, System.Drawing.Color.Black)); //竖线 int y_lines = Size.Height / unit_size; for (int i = -y_lines; i <= y_lines; i++) { g.DrawLine(penUnreal, new Point(-Size.Width, i * unit_size), new Point(Size.Width, i * unit_size)); } //横线 int x_lines = Size.Width / unit_size; for (int i = -x_lines; i <= x_lines; i++) { g.DrawLine(penUnreal, new Point(i * unit_size, -Size.Height), new Point(i * unit_size, Size.Height)); } g.EndContainer(gc); } { Graphics g = e.Graphics; Rectangle rc = new Rectangle(0, 0, 100, 100); Rectangle rcdest = new Rectangle(10, Size.Height - 110, 100, 100); GraphicsContainer gc = g.BeginContainer(rcdest, rc, GraphicsUnit.Pixel); //右下角坐标轴 g.DrawLine(new Pen(System.Drawing.Color.Red), new Point(0, 100), new Point(100, 100)); g.DrawString("x(左右)", Font, Brushes.Black, new Point(70, 80)); g.DrawLine(new Pen(System.Drawing.Color.Blue), new Point(0, 100), new Point(0, 0)); g.DrawString("y(前后)", Font, Brushes.Black, new Point(0, 0)); g.EndContainer(gc); } //绘制攻击框 { Graphics g = e.Graphics; Point center = new Point(Size.Width / 2 + _center_offset.X, Size.Height / 2 + _center_offset.Y); Rectangle rc = new Rectangle(0, 0, Size.Width, Size.Height); Rectangle rcdest = new Rectangle(center.X, center.Y, Size.Width, Size.Height); GraphicsContainer gc = g.BeginContainer(rcdest, rc, GraphicsUnit.Pixel); Pen pen = new Pen(Brushes.Red, 2); //if (_atk != null && _atk.box != null) { for (int i = 0; i < _boxList.Count; i++) { DrawBox(g, pen, _boxList[i], unit_size); } } pen = new Pen(Brushes.Green, 2); if (_selected_box != null) { DrawBox(g, pen, _selected_box, unit_size); } g.EndContainer(gc); } }
public void EndContainer(GraphicsContainer container) { _g.EndContainer(container) ; }
// Create a Graphics that is internally offset to baseWindow internal Graphics(Graphics graphics, Rectangle baseWindow) { // Use the same toolkit this.graphics = graphics.graphics; if (graphics.clip != null) { clip = graphics.clip.Clone(); clip.Intersect(baseWindow); } else clip = new Region(baseWindow); // Find out what the clip is with our new Origin clip.Translate(-baseWindow.X, -baseWindow.Y); this.baseWindow = baseWindow; if (graphics.transform != null) this.transform = new Matrix(graphics.transform); this.pageScale = graphics.pageScale; this.pageUnit = graphics.pageUnit; this.stackTop = null; Clip = clip; }
/// <summary> /// The effect of calling this method is to pop out of the closest SVG group. This simulates restoring GDI+ state from a <c>GraphicsContainer</c> /// </summary> public void EndContainer(GraphicsContainer container) { if (cur == topgroup) { return; } cur = (SvgStyledTransformedElement) cur.Parent; transforms.Pop(); }
public void EndContainer (GraphicsContainer container) { #if NET_2_0 if (container == null) throw new ArgumentNullException ("container"); #endif Status status = GDIPlus.GdipEndContainer(nativeObject, container.NativeObject); GDIPlus.CheckStatus (status); }
public override void OnPaintWorkflow(PaintEventArgs e, ViewPortData viewPortData) { Graphics graphics = e.Graphics; Bitmap memoryBitmap = viewPortData.MemoryBitmap; AmbientTheme ambientTheme = WorkflowTheme.CurrentTheme.AmbientTheme; GraphicsContainer container = graphics.BeginContainer(); Rectangle rect = new Rectangle(Point.Empty, memoryBitmap.Size); graphics.FillRectangle(AmbientTheme.WorkspaceBackgroundBrush, rect); using (Font font = new Font(ambientTheme.Font.FontFamily, ambientTheme.Font.Size / this.scaling, ambientTheme.Font.Style)) { int num = 0; Matrix matrix = new Matrix(); Matrix matrix2 = new Matrix(); matrix2.Scale(viewPortData.Scaling.Width, viewPortData.Scaling.Height, MatrixOrder.Prepend); matrix2.Invert(); Point[] pts = new Point[] { viewPortData.Translation, new Point(viewPortData.ViewPortSize) }; matrix2.TransformPoints(pts); matrix2.Invert(); Rectangle rectangle2 = new Rectangle(pts[0], new Size(pts[1])); WorkflowPrintDocument.HeaderFooterData headerFooterPrintData = new WorkflowPrintDocument.HeaderFooterData { HeaderFooterMargins = this.headerFooterMargins, PrintTime = this.previewTime, TotalPages = this.pageLayoutInfo.Count, Scaling = this.scaling, Font = font }; WorkflowDesignerLoader service = base.serviceProvider.GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader; headerFooterPrintData.FileName = (service != null) ? service.FileName : string.Empty; Matrix matrix3 = new Matrix(); matrix3.Scale(viewPortData.Scaling.Width, viewPortData.Scaling.Height, MatrixOrder.Prepend); matrix3.Translate((float)-viewPortData.Translation.X, (float)-viewPortData.Translation.Y, MatrixOrder.Append); foreach (PageLayoutData data2 in this.pageLayoutInfo) { num++; if ((data2.PageBounds.IntersectsWith(rectangle2) && (data2.PageBounds.Width > 0)) && (data2.PageBounds.Height > 0)) { graphics.Transform = matrix3; graphics.FillRectangle(Brushes.White, data2.PageBounds); ActivityDesignerPaint.DrawDropShadow(graphics, data2.PageBounds, Color.Black, 4, LightSourcePosition.Top | LightSourcePosition.Left, 0.2f, false); Rectangle logicalPageBounds = data2.LogicalPageBounds; logicalPageBounds.Intersect(viewPortData.LogicalViewPort); if (!logicalPageBounds.IsEmpty) { graphics.Transform = matrix; Point empty = Point.Empty; empty.X = data2.ViewablePageBounds.X + Math.Abs((int)(data2.LogicalPageBounds.X - logicalPageBounds.X)); empty.Y = data2.ViewablePageBounds.Y + Math.Abs((int)(data2.LogicalPageBounds.Y - logicalPageBounds.Y)); pts = new Point[] { empty }; matrix2.TransformPoints(pts); empty = new Point(pts[0].X - viewPortData.Translation.X, pts[0].Y - viewPortData.Translation.Y); Rectangle source = Rectangle.Empty; source.X = logicalPageBounds.X - viewPortData.LogicalViewPort.X; source.Y = logicalPageBounds.Y - viewPortData.LogicalViewPort.Y; source.Width = logicalPageBounds.Width; source.Height = logicalPageBounds.Height; pts = new Point[] { source.Location, new Point(source.Size) }; matrix2.TransformPoints(pts); source.Location = pts[0]; source.Size = new Size(pts[1]); ActivityDesignerPaint.DrawImage(graphics, memoryBitmap, new Rectangle(empty, source.Size), source, DesignerContentAlignment.Fill, 1f, WorkflowTheme.CurrentTheme.AmbientTheme.DrawGrayscale); } graphics.Transform = matrix3; graphics.DrawRectangle(Pens.Black, data2.PageBounds); graphics.DrawRectangle(ambientTheme.ForegroundPen, (int)(data2.ViewablePageBounds.Left - 3), (int)(data2.ViewablePageBounds.Top - 3), (int)(data2.ViewablePageBounds.Width + 6), (int)(data2.ViewablePageBounds.Height + 6)); headerFooterPrintData.PageBounds = data2.PageBounds; headerFooterPrintData.PageBoundsWithoutMargin = data2.ViewablePageBounds; headerFooterPrintData.CurrentPage = num; if (this.printDocument.PageSetupData.HeaderTemplate.Length > 0) { this.printDocument.PrintHeaderFooter(graphics, true, headerFooterPrintData); } if (this.printDocument.PageSetupData.FooterTemplate.Length > 0) { this.printDocument.PrintHeaderFooter(graphics, false, headerFooterPrintData); } } } graphics.EndContainer(container); } }
/// <include file='doc\Graphics.uex' path='docs/doc[@for="Graphics.EndContainer"]/*' /> /// <devdoc> /// </devdoc> public void EndContainer(GraphicsContainer container) { if (container == null){ throw new ArgumentNullException("container"); } int status = SafeNativeMethods.Gdip.GdipEndContainer(new HandleRef(this, this.NativeGraphics), container.nativeGraphicsContainer); if (status != SafeNativeMethods.Gdip.Ok) { throw SafeNativeMethods.Gdip.StatusException(status); } PopContext(container.nativeGraphicsContainer); }
public void addContainer(GraphicsContainer container, string key) { graphics.addContainer(container, key); }
/// <summary> /// The effect of calling this method is to pop out of the closest SVG group. This simulates restoring GDI+ state from a <c>GraphicsContainer</c> /// </summary> public void EndContainer(GraphicsContainer container) { if(_cur == _topgroup) return; _cur = (SvgStyledTransformedElement)_cur.Parent; _transforms.Pop(); }
public void EndContainer(GraphicsContainer container) { _graphics.EndContainer(container); }
public GraphicsContainerDisposer(Graphics g, GraphicsContainer gc) { this.g = g; this.gc = gc; }
private void DrawText(PointF[] points, int maxPoints) { GraphicsPath gp = new GraphicsPath(_pathdata.Points, _pathdata.Types) { FillMode = FillMode.Winding }; gp.Flatten(); gp.Dispose(); Graphics g = _graphics; GraphicsContainer graphicsContainer = g.BeginContainer(); //g.TranslateTransform(_graphicsPath.GetBounds().X, _graphicsPath.GetBounds().Y); int count = 0; PointF point1 = default(PointF); int charStep = 0; double maxWidthText = default(double); int i; for (i = 0; i <= _text.Length - 1; i++) { maxWidthText += StringRegion(g, i); } switch (_pathalign) { case TextPathAlign.Left: point1 = points[0]; count = 0; break; case TextPathAlign.Center: count = (int)((maxPoints - maxWidthText) / 2); if (count > 0) { point1 = points[count]; } else { point1 = points[0]; } break; case TextPathAlign.Right: count = (int)(maxPoints - maxWidthText - (double)StringRegion(g, _text.Length - 1) * LetterSpacePercentage / 100); if (count > 0) { point1 = points[count]; } else { point1 = points[0]; } break; } while (!(charStep > _text.Length - 1)) { int lStrWidth = (int)(StringRegion(g, charStep) * LetterSpacePercentage / 100); if ((count + lStrWidth / 2) >= 0 & (count + lStrWidth) < maxPoints) { count += lStrWidth; PointF point2 = points[count]; PointF point = points[count - lStrWidth / 2]; double angle = GetAngle(point1, point2); DrawRotatedText(g, _text[charStep].ToString(), (float)angle, point); point1 = points[count]; } else { count += lStrWidth; } charStep += 1; } g.EndContainer(graphicsContainer); }
public void EndContainer(GraphicsContainer container) { if (stateStack == null) { stateStack = new object[MAX_GRAPHICS_STATE_STACK]; statePos = 0; } if (container.NativeObject > statePos) return; if (container.NativeObject >= MAX_GRAPHICS_STATE_STACK) throw new OutOfMemoryException(); var gstate = (CGGraphicsState)stateStack[container.NativeObject]; LastPen = gstate.lastPen; LastBrush = gstate.lastBrush; modelMatrix = gstate.model; viewMatrix = gstate.view; CompositingMode = gstate.compositingMode; CompositingQuality = gstate.compositingQuality; interpolationMode = gstate.interpolationMode; pageScale = gstate.pageScale; graphicsUnit = gstate.pageUnit; //PixelOffsetMode = gstate.pixelOffsetMode; SmoothingMode = gstate.smoothingMode; //TextContrast = gstate.textContrast; //TextRenderingHint = gstate.textRenderingHint; renderingOrigin = gstate.renderingOrigin; clipRegion = gstate.clipRegion; // re-apply our ModelView to the graphics context applyModelView(); statePos = container.NativeObject - 1; }
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { TreeGridNode owningNode = this.OwningNode; if (owningNode != null) { Image image = owningNode.Image; if ((this.ImageHeight == 0) && (image != null)) { this.UpdateStyle(); } base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); Rectangle glyphRect = new Rectangle(cellBounds.X + this.GlyphMargin, cellBounds.Y, this.INDENT_WIDTH, cellBounds.Height - 1); int num = glyphRect.Width / 2; int level = this.Level; if (image != null) { Point point; if (this.ImageHeight > cellBounds.Height) { point = new Point(glyphRect.X + this.GlyphWidth, cellBounds.Y + this.ImageHeightOffset); } else { point = new Point(glyphRect.X + this.GlyphWidth, ((cellBounds.Height / 2) - (this.ImageHeight / 2)) + cellBounds.Y); } GraphicsContainer container = graphics.BeginContainer(); graphics.SetClip(cellBounds); graphics.DrawImageUnscaled(image, point); graphics.EndContainer(container); } if (owningNode.BaseTGV.ShowLines) { using (Pen pen = new Pen(SystemBrushes.ControlDark, 1f)) { pen.DashStyle = DashStyle.Dot; bool isLastSibling = owningNode.IsLastSibling; bool isFirstSibling = owningNode.IsFirstSibling; if (owningNode.Level == 1) { if (isFirstSibling && isLastSibling) { graphics.DrawLine(pen, glyphRect.X + 4, cellBounds.Top + (cellBounds.Height / 2), glyphRect.Right, cellBounds.Top + (cellBounds.Height / 2)); } else if (isLastSibling) { graphics.DrawLine(pen, glyphRect.X + 4, cellBounds.Top + (cellBounds.Height / 2), glyphRect.Right, cellBounds.Top + (cellBounds.Height / 2)); graphics.DrawLine(pen, glyphRect.X + 4, cellBounds.Top, glyphRect.X + 4, cellBounds.Top + (cellBounds.Height / 2)); } else if (isFirstSibling) { graphics.DrawLine(pen, glyphRect.X + 4, cellBounds.Top + (cellBounds.Height / 2), glyphRect.Right, cellBounds.Top + (cellBounds.Height / 2)); graphics.DrawLine(pen, glyphRect.X + 4, cellBounds.Top + (cellBounds.Height / 2), glyphRect.X + 4, cellBounds.Bottom); } else { graphics.DrawLine(pen, glyphRect.X + 4, cellBounds.Top + (cellBounds.Height / 2), glyphRect.Right, cellBounds.Top + (cellBounds.Height / 2)); graphics.DrawLine(pen, glyphRect.X + 4, cellBounds.Top, glyphRect.X + 4, cellBounds.Bottom); } } else { if (isLastSibling) { graphics.DrawLine(pen, glyphRect.X + 4, cellBounds.Top + (cellBounds.Height / 2), glyphRect.Right, cellBounds.Top + (cellBounds.Height / 2)); graphics.DrawLine(pen, glyphRect.X + 4, cellBounds.Top, glyphRect.X + 4, cellBounds.Top + (cellBounds.Height / 2)); } else { graphics.DrawLine(pen, glyphRect.X + 4, cellBounds.Top + (cellBounds.Height / 2), glyphRect.Right, cellBounds.Top + (cellBounds.Height / 2)); graphics.DrawLine(pen, glyphRect.X + 4, cellBounds.Top, glyphRect.X + 4, cellBounds.Bottom); } TreeGridNode parent = owningNode.Parent; for (int i = (glyphRect.X + 4) - this.INDENT_WIDTH; !parent.IsRoot; i -= this.INDENT_WIDTH) { if (!(!parent.HasChildren || parent.IsLastSibling)) { graphics.DrawLine(pen, i, cellBounds.Top, i, cellBounds.Bottom); } parent = parent.Parent; } } } } if (owningNode.HasChildren || owningNode.BaseTGV.VirtualNodes) { if (owningNode.IsExpanded) { graphics.DrawImage(Resources.Expanded1, new Rectangle(glyphRect.X, (glyphRect.Y + (glyphRect.Height / 2)) - 4, this.NodeSize, this.NodeSize)); } else { graphics.DrawImage(Resources.Collapse1, new Rectangle(glyphRect.X, (glyphRect.Y + (glyphRect.Height / 2)) - 4, this.NodeSize, this.NodeSize)); } } if (this.IsHaveCheckBox && this.DrawCheckBox) { this._checkboxRegion = this.GetCheckBoxRegion(glyphRect, CheckBoxRenderer.GetGlyphSize(graphics, this._PaintState)); CheckBoxRenderer.DrawCheckBox(graphics, new Point(this._checkboxRegion.X, this._checkboxRegion.Y), this._PaintState); } } }