void GDIPaint(ScGraphics g, ScDrawNode node) { if (node == null) { return; } ScLayer layer = node.layer; if (node.rootLayer == null) { g.SetClip(node.clipRect); g.Transform = layer.GlobalMatrix; g.layer = layer; layer.OnGDIPaint(g); } else { ScLayer rootLayer = node.rootLayer; Matrix m = new Matrix(); m.Translate(-rootLayer.DrawBox.X, -rootLayer.DrawBox.Y); m.Multiply(layer.GlobalMatrix); g.SetClip(node.clipRect); g.Transform = m; g.layer = layer; layer.OnGDIPaint(g); m.Dispose(); } g.layer = null; g.ResetTransform(); g.ResetClip(); }
private void MirrorPath(System.Drawing.Drawing2D.GraphicsPath GraphicPath) { System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix(); m.Translate(0, Height - 1); m.Scale(1, -1); GraphicPath.Transform(m); m.Dispose(); }
public GDILayer PushLayer(GDIGraphics g, ScDrawNode node) { ScLayer sclayer = node.layer; GDILayer gdiLayer = new GDILayer(g); GDILayerParameters layerParameters = new GDILayerParameters(); layerParameters.ContentBounds = sclayer.DrawBox; layerParameters.MaskAntialiasMode = GDIAntialiasMode.PerPrimitive; layerParameters.Opacity = sclayer.Opacity; layerParameters.ClipRect = new RectangleF( (int)(node.clipRect.X - sclayer.DrawBox.X - 1), (int)(node.clipRect.Y - sclayer.DrawBox.Y - 1), (int)(node.clipRect.Width + 2), (int)(node.clipRect.Height + 2)); Matrix m = new Matrix(); m.Translate(-sclayer.DrawBox.X, -sclayer.DrawBox.Y); m.Multiply(sclayer.GlobalMatrix); node.m = m; node.rootLayer = node.layer; if (!sclayer.Parent.IsComputedStraight) { m = new Matrix(); m.Translate(-sclayer.Parent.DrawBox.X, -sclayer.Parent.DrawBox.Y); m.Multiply(sclayer.GlobalMatrix); layerParameters.GeometricMask = sclayer.CreateTransLastHitGeometryForGDI(m); m.Dispose(); } else { layerParameters.GeometricMask = sclayer.TransLastHitGraphicsPath; layerParameters.parentClipRect = node.clipRect; } node.clipRect = layerParameters.ClipRect; layerParameters.sclayer = sclayer; g.PushLayer(layerParameters, gdiLayer); return(gdiLayer); }
private void AcceptScreenConfiguration() { SlideView view = this.mySlideView; //For some reason, this caused a hang if script data was preloaded. // for now we just assume it's always 1.3333. The assignment caused the // aspect ration to go from 1.333337 to 1.3333. //view.AspectRatio = (float)screenConfiguration.AspectRatio; System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix(); m.Scale(1 / (float)screenConfiguration.SlideSize, 1 / (float)screenConfiguration.SlideSize); foreach (SlideViewLayer layer in this.FetchLayersOfType(view, typeof(SlideViewLayer))) { layer.Transform = m; } m.Dispose(); }
private PointF ConvertInvariantToDestination(PointF invariantPoint) { PointF xVector = new PointF(100, 0); SizeF xVectorTransformed = base.SpatialTransform.ConvertToDestination(new SizeF(xVector)); //figure out where the source x-axis went in destination int rotation = (int)Math.Round(Vector.SubtendedAngle(xVectorTransformed.ToPointF(), PointF.Empty, xVector)); if (rotation < 0) { rotation += 360; } Matrix m = new Matrix(); m.Rotate(rotation); PointF[] pt = { invariantPoint }; m.TransformPoints(pt); m.Dispose(); return(new PointF(base.Location.X + pt[0].X, base.Location.Y + pt[0].Y)); }
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { System.Drawing.Point[] DropPoints = new System.Drawing.Point[] { new Point(0, 0), new Point(11, 0), new Point(5, 6) }; System.Drawing.Point[] ClosePoints = new System.Drawing.Point[] { new Point(0, 0), new Point(2, 0), new Point(5, 3), new Point(8, 0), new Point(10, 0), new Point(6, 4), new Point(10, 8), new Point(8, 8), new Point(5, 5), new Point(2, 8), new Point(0, 8), new Point(4, 4) }; Rectangle rec = new Rectangle(); rec.Size = new Size(this.Width - 1, this.Height - 1); if (m_hot) { e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; e.Graphics.FillRectangle(new System.Drawing.Drawing2D.LinearGradientBrush(new Point(0, 0), new Point(0, this.Height), Helper.RenderColors.ControlButtonBackHighColor(m_RenderMode, m_BackHighColor), Helper.RenderColors.ControlButtonBackLowColor(m_RenderMode, m_BackLowColor)), rec); e.Graphics.DrawRectangle(new Pen(Helper.RenderColors.ControlButtonBorderColor(m_RenderMode, m_BorderColor)), rec); e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default; } System.Drawing.Drawing2D.GraphicsPath g = new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix(); int x = (int)((this.Width - 11) / 2); int y = (int)((this.Height - 11) / 2 + 1); if (m_style == ButtonStyle.Drop) { e.Graphics.FillRectangle(new SolidBrush(ForeColor), x, y, 11, 2); g.AddPolygon(DropPoints); m.Translate(x, y + 3); g.Transform(m); e.Graphics.FillPolygon(new SolidBrush(ForeColor), g.PathPoints); } else { g.AddPolygon(ClosePoints); m.Translate(x, y); g.Transform(m); e.Graphics.DrawPolygon(new Pen(ForeColor), g.PathPoints); e.Graphics.FillPolygon(new SolidBrush(ForeColor), g.PathPoints); } g.Dispose(); m.Dispose(); }
private void ChartPaint_Load(object sender, EventArgs e) { this.Width = PictureWidth + 40; this.Height = PictureHeight + 110; Tool = Tools.None; PenColor = Color.Black; LineWidth = 3; DrawPen = new Pen(PenColor, LineWidth); DrawBrush = new SolidBrush(PenColor); bUndo.Enabled = false; bRedo.Enabled = false; // ショートカットキー this.KeyPreview = true; // Graphics オブジェクトの取得 pictureBox1.Image = new Bitmap(PictureWidth, PictureHeight); Gra = Graphics.FromImage(pictureBox1.Image); Gra.DrawImage(BitmapChart, 0, 0); // アフィン変換行列の初期化 if (DrawMatrix != null) { DrawMatrix.Dispose(); } DrawMatrix = new System.Drawing.Drawing2D.Matrix(); // 画像の描画 DrawImage(); Buffer = new Bitmap(pictureBox1.Image); bNone.BackColor = SystemColors.Highlight; }
public void WriteGradientColorDefs(GradientFill[] gfs) { if (gfs.Length == 0) { return; } int count = gfs.Length; int totalBytes = 4; for (int i = 0; i < gfs.Length; i++) { int samples = gfs[i].Fills.Count; totalBytes += (samples * 4) + (samples * 1); // rgba ratio totalBytes += 1 + 6 * 2; // header and matrix } byte[] bytes = new byte[totalBytes]; // id8, count16 bytes[0] = (byte)DVex.GradientDefs; bytes[1] = 0; bytes[2] = (byte)((count & 0xFF00) >> 8); bytes[3] = (byte)(count & 0xFF); int index = 4; for (int i = 0; i < gfs.Length; i++) { int fillType = 0x00; // linearFill if (gfs[i].FillType == FillType.Radial) { fillType = 0x10; } int colorCount = gfs[i].Fills.Count; if (colorCount > 8) { colorCount = 8; Console.WriteLine("*Flash only supports 8 colors max in gradients"); } bytes[index++] = (byte)(fillType | colorCount); // add rgba+ratio array List <Color> colors = gfs[i].Fills; List <float> positions = gfs[i].Stops; // flash and gdi store colors & pos in opposite order for radials if (gfs[i].FillType == FillType.Radial) { int len = colors.Count; List <Color> tempc = new List <Color>(len); List <float> tempp = new List <float>(len); for (int col = 0; col < len; col++) { tempc[col] = colors[len - col - 1]; tempp[col] = 255 - positions[len - col - 1]; } colors = tempc; positions = tempp; } for (int j = 0; j < colorCount; j++) { bytes[index++] = colors[j].R; bytes[index++] = colors[j].G; bytes[index++] = colors[j].B; int a = (int)(Math.Floor(colors[j].A / 2.55)); if (a >= 98) { a = 100; } if (a <= 2) { a = 0; } bytes[index++] = (byte)a; bytes[index++] = (byte)(((int)(positions[j] * 255)) & 0xFF); } // add matrix System.Drawing.Drawing2D.Matrix clone = gfs[i].Transform.GetDrawing2DMatrix(); clone.Scale(GradientFill.GradientVexRect.Size.Width, GradientFill.GradientVexRect.Size.Height); float[] mx = clone.Elements; clone.Dispose(); // add elements bytes[index++] = (byte)((((int)mx[0]) & 0xFF00) >> 8); bytes[index++] = (byte)(((int)mx[0]) & 0xFF); bytes[index++] = (byte)((((int)mx[1]) & 0xFF00) >> 8); bytes[index++] = (byte)(((int)mx[1]) & 0xFF); bytes[index++] = (byte)((((int)mx[2]) & 0xFF00) >> 8); bytes[index++] = (byte)(((int)mx[2]) & 0xFF); bytes[index++] = (byte)((((int)mx[3]) & 0xFF00) >> 8); bytes[index++] = (byte)(((int)mx[3]) & 0xFF); bytes[index++] = (byte)((((int)mx[4]) & 0xFF00) >> 8); bytes[index++] = (byte)(((int)mx[4]) & 0xFF); bytes[index++] = (byte)((((int)mx[5]) & 0xFF00) >> 8); bytes[index++] = (byte)(((int)mx[5]) & 0xFF); FillDefs.Add(gfs[i]); } WriteByteArray(bytes); }
public void WriteNbitGradientDefs(GradientFill[] gfs) { if (gfs.Length == 0) { return; } int count = gfs.Length; WriteStartArray(); WriteBits((int)DVex.GradientDefs, 8); WriteBits(gfs.Length, 11); // note: no nBits here!! for (int index = 0; index < gfs.Length; index++) { FillDefs.Add(gfs[index]); // first type - all non radial will be solid (as as doesn do bmp fills) int type = (gfs[index].FillType == FillType.Radial) ? 1 : 0; WriteBits(type, 1); // now argb colors List <Color> cols = gfs[index].Fills; List <float> positions = gfs[index].Stops; // flash and gdi store colors & pos in opposite order for radials if (gfs[index].FillType == FillType.Radial) { int len = cols.Count; List <Color> tempc = new List <Color>(len); List <float> tempp = new List <float>(len); for (int col = 0; col < len; col++) { tempc[col] = cols[len - col - 1]; tempp[col] = 1 - positions[len - col - 1]; } cols = tempc; positions = tempp; } int sampCount = cols.Count; if (sampCount > 8) { sampCount = 8; Console.WriteLine("*Flash only supports 8 colors max in gradients"); } int[] wCols = new int[sampCount]; for (int i = 0; i < sampCount; i++) { wCols[i] = cols[i].ARGB & 0x00FFFFFF; wCols[i] |= (~cols[i].A) << 24; } int colBits = MinBits(wCols); int wcolBits = colBits > 1 ? colBits - 2 : 0; WriteBits(wcolBits, 5); WriteBits(sampCount, 11); for (int i = 0; i < sampCount; i++) { WriteBits(wCols[i], wcolBits + 2); } // now ratios int[] rats = new int[positions.Count]; for (int i = 0; i < sampCount; i++) { rats[i] = (int)(positions[i] * 255); } int ratBits = MinBits(rats); int wratBits = ratBits > 1 ? ratBits - 2 : 0; WriteBits(wratBits, 5); WriteBits(sampCount, 11); for (int i = 0; i < sampCount; i++) { WriteBits(rats[i], wratBits + 2); } // now matrix System.Drawing.Drawing2D.Matrix clone = gfs[index].Transform.GetDrawing2DMatrix(); clone.Scale(GradientFill.GradientVexRect.Size.Width, GradientFill.GradientVexRect.Size.Height); float[] mx = clone.Elements; clone.Dispose(); int[] mxs = new int[6] { (int)mx[0] * 20, (int)mx[1] * 20, (int)mx[2] * 20, (int)mx[3] * 20, (int)mx[4] * 20, (int)mx[5] * 20 }; int mxBits = MinBits(mxs) + 1; // neg int wmxBits = mxBits > 1 ? mxBits - 2 : 0; WriteBits(wmxBits, 5); WriteBits(6, 11); for (int i = 0; i < 6; i++) { WriteBits(mxs[i], wmxBits + 2); } } FlushBits(); WriteEndArray(); }
private PointF ConvertInvariantToDestination(PointF invariantPoint) { PointF xVector = new PointF(100, 0); SizeF xVectorTransformed = base.SpatialTransform.ConvertToDestination(new SizeF(xVector)); //figure out where the source x-axis went in destination int rotation = (int)Math.Round(Vector.SubtendedAngle(xVectorTransformed.ToPointF(), PointF.Empty, xVector)); if (rotation < 0) rotation += 360; Matrix m = new Matrix(); m.Rotate(rotation); PointF[] pt = { invariantPoint }; m.TransformPoints(pt); m.Dispose(); return new PointF(base.Location.X + pt[0].X, base.Location.Y + pt[0].Y); }
/// <summary> /// Paint the tab /// </summary> /// <param name="e"></param> protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { bool Painting = false; if (Painting) { return; } Painting = true; this.SuspendLayout(); Color RenderBorderColor = new Color(); Color RenderBottomColor = new Color(); Color RenderHighColor = new Color(); Color RenderLowColor = new Color(); System.Drawing.Drawing2D.GraphicsPath GraphicPath = new System.Drawing.Drawing2D.GraphicsPath(); int w = this.Width; CalculateWidth(); if (w != this.Width) { GraphicPath.Dispose(); return; } if (m_Selected) { RenderBorderColor = Helper.RenderColors.BorderColor(m_RenderMode, BorderColor); RenderHighColor = Helper.RenderColors.TabBackHighColor(m_RenderMode, BackHighColor); RenderLowColor = Helper.RenderColors.TabBackLowColor(m_RenderMode, BackLowColor); RenderBottomColor = Helper.RenderColors.TabBackLowColor(m_RenderMode, BackLowColor); } else if (m_Hot) { RenderBorderColor = Helper.RenderColors.BorderColor(m_RenderMode, BorderColor); RenderHighColor = Helper.RenderColors.TabBackHighColor(m_RenderMode, BackHighColor); RenderLowColor = Helper.RenderColors.TabBackLowColor(m_RenderMode, BackLowColor); RenderBottomColor = Helper.RenderColors.BorderColor(m_RenderMode, BorderColor); } else { RenderBorderColor = Helper.RenderColors.BorderColorDisabled(m_RenderMode, BorderColorDisabled); RenderHighColor = Helper.RenderColors.TabBackHighColorDisabled(m_RenderMode, BackHighColorDisabled); RenderLowColor = Helper.RenderColors.TabBackLowColorDisabled(m_RenderMode, BackLowColorDisabled); RenderBottomColor = Helper.RenderColors.BorderColor(m_RenderMode, BorderColor); } e.Graphics.SmoothingMode = m_SmoothingMode; GraphicPath.AddPolygon(GetRegion(Width - 1, Height - 1, System.Convert.ToInt32(this.IsSelected ? Height : Height - 1))); // if is bottom mirror the button vertically if (m_Alignment == TabControl.TabAlignment.Bottom) { MirrorPath(GraphicPath); Color x = RenderHighColor; RenderHighColor = RenderLowColor; RenderLowColor = x; } // Get the correct region including all the borders Region R = new Region(GraphicPath); Region R1 = new Region(GraphicPath); Region R2 = new Region(GraphicPath); Region R3 = new Region(GraphicPath); System.Drawing.Drawing2D.Matrix M1 = new System.Drawing.Drawing2D.Matrix(); System.Drawing.Drawing2D.Matrix M2 = new System.Drawing.Drawing2D.Matrix(); System.Drawing.Drawing2D.Matrix M3 = new System.Drawing.Drawing2D.Matrix(); M1.Translate(0, -0.5F); M2.Translate(0, 0.5F); M3.Translate(1, 0); R1.Transform(M1); R2.Transform(M2); R3.Transform(M3); R.Union(R1); R.Union(R2); R.Union(R3); this.Region = R; RectangleF RF = R.GetBounds(e.Graphics); Rectangle rec = new Rectangle(0, 0, (int)RF.Width, (int)RF.Height); TabControl.TabPaintEventArgs te = default(TabControl.TabPaintEventArgs); te = new TabControl.TabPaintEventArgs(e.Graphics, rec, m_Selected, m_Hot, GraphicPath, Width, Height); if (TabPaintBackgroundEvent != null) // try to owner draw { TabPaintBackgroundEvent(this, te); } System.Drawing.Drawing2D.LinearGradientBrush gb = CreateGradientBrush(new Rectangle(0, 0, this.Width, this.Height), RenderHighColor, RenderLowColor); if (!te.Handled) { e.Graphics.FillPath(gb, GraphicPath); } gb.Dispose(); te.Dispose(); te = new TabControl.TabPaintEventArgs(e.Graphics, rec, m_Selected, m_Hot, GraphicPath, Width, Height); if (TabPaintBorderEvent != null) // try to owner draw { TabPaintBorderEvent(this, te); } if (!te.Handled) { if (m_BorderEnhanced) { Color c = m_Alignment == TabControl.TabAlignment.Bottom ? RenderLowColor : RenderHighColor; Pen p = new Pen(c, (float)m_BorderEnhanceWeight); e.Graphics.DrawLines(p, GraphicPath.PathPoints); p.Dispose(); } Pen p1 = new Pen(RenderBorderColor); e.Graphics.DrawLines(p1, GraphicPath.PathPoints); p1.Dispose(); } te.Dispose(); e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None; e.Graphics.DrawLine(new Pen(RenderBottomColor), GraphicPath.PathPoints[0], GraphicPath.PathPoints[GraphicPath.PointCount - 1]); e.Graphics.SmoothingMode = m_SmoothingMode; DrawIcon(e.Graphics); DrawText(e.Graphics); if (m_CloseButtonVisible) { DrawCloseButton(e.Graphics); } this.ResumeLayout(); // do the memory cleanup GraphicPath.Dispose(); M1.Dispose(); M2.Dispose(); M3.Dispose(); R1.Dispose(); R2.Dispose(); R3.Dispose(); R.Dispose(); te.Dispose(); Painting = false; }
// Generates the close button image private Bitmap GetButton() { System.Drawing.Point[] Points = new System.Drawing.Point[] { new Point(1, 0), new Point(3, 0), new Point(5, 2), new Point(7, 0), new Point(9, 0), new Point(6, 3), new Point(6, 4), new Point(9, 7), new Point(7, 7), new Point(5, 5), new Point(3, 7), new Point(1, 7), new Point(4, 4), new Point(4, 3) }; System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); Color bch = new Color(); Color bcl = new Color(); Color bc = new Color(); Color fc = new Color(); Bitmap B = default(Bitmap); System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix(); System.Drawing.Point[] path = new System.Drawing.Point[] { new Point(0, 1), new Point(1, 0), new Point(15, 0), new Point(16, 1), new Point(16, 14), new Point(15, 15), new Point(1, 15), new Point(0, 14) }; Graphics g = default(Graphics); if (MouseOverCloseButton) { bch = Helper.RenderColors.TabCloseButtonBackHighColorHot(m_RenderMode, CloseButtonBackHighColorHot); bcl = Helper.RenderColors.TabCloseButtonBackLowColorHot(m_RenderMode, CloseButtonBackLowColorHot); bc = Helper.RenderColors.TabCloseButtonBorderColorHot(m_RenderMode, CloseButtonBorderColorHot); fc = Helper.RenderColors.TabCloseButtonForeColorHot(m_RenderMode, CloseButtonForeColorHot); } else if (m_Selected) { bch = Helper.RenderColors.TabCloseButtonBackHighColor(m_RenderMode, CloseButtonBackHighColor); bcl = Helper.RenderColors.TabCloseButtonBackLowColor(m_RenderMode, CloseButtonBackLowColor); bc = Helper.RenderColors.TabCloseButtonBorderColor(m_RenderMode, CloseButtonBorderColor); fc = Helper.RenderColors.TabCloseButtonForeColor(m_RenderMode, CloseButtonForeColor); } else { bch = Helper.RenderColors.TabCloseButtonBackHighColorDisabled(m_RenderMode, CloseButtonBackHighColorDisabled); bcl = Helper.RenderColors.TabCloseButtonBackLowColorDisabled(m_RenderMode, CloseButtonBackLowColorDisabled); bc = Helper.RenderColors.TabCloseButtonBorderColorDisabled(m_RenderMode, CloseButtonBorderColorDisabled); fc = Helper.RenderColors.TabCloseButtonForeColorDisabled(m_RenderMode, CloseButtonForeColorDisabled); } B = new Bitmap(17, 17); B.MakeTransparent(); g = Graphics.FromImage(B); // draw the border and background g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; System.Drawing.Drawing2D.LinearGradientBrush l = new System.Drawing.Drawing2D.LinearGradientBrush(new Point(0, 0), new Point(0, 15), bch, bcl); g.FillPolygon(l, path); Pen p = new Pen(bc); g.DrawPolygon(p, path); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default; // draw the foreground gp.AddPolygon(Points); m.Translate(3, 4); gp.Transform(m); p.Dispose(); p = new Pen(fc); g.DrawPolygon(p, gp.PathPoints); SolidBrush sb = new SolidBrush(fc); g.FillPolygon(sb, gp.PathPoints); sb.Dispose(); p.Dispose(); gp.Dispose(); g.Dispose(); m.Dispose(); return(B); }
private Bitmap GetCurrentStateImage() { Bitmap bitmap = new Bitmap(this.WidthInternal, this.HeightInternal, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); // Format32bppArgb); bitmap.MakeTransparent(); Graphics g = Graphics.FromImage(bitmap); try { System.Windows.Forms.Control cc = this.ContainerControl as System.Windows.Forms.Control; bool antiAlias = false; ItemPaintArgs pa = null; if (cc is ItemControl) { antiAlias = ((ItemControl)cc).AntiAlias; pa = ((ItemControl)cc).GetItemPaintArgs(g); } else if (cc is Bar) { antiAlias = ((Bar)cc).AntiAlias; pa = ((Bar)cc).GetItemPaintArgs(g); } else if (cc is ButtonX) { antiAlias = ((ButtonX)cc).AntiAlias; pa = ((ButtonX)cc).GetItemPaintArgs(g); } System.Drawing.Drawing2D.Matrix myMatrix = new System.Drawing.Drawing2D.Matrix(); myMatrix.Translate(-this.DisplayRectangle.X, -this.DisplayRectangle.Y, System.Drawing.Drawing2D.MatrixOrder.Append); g.Transform = myMatrix; myMatrix.Dispose(); myMatrix = null; if (antiAlias) { g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; g.TextRenderingHint = DisplayHelp.AntiAliasTextRenderingHint; } if (pa == null) { bitmap.Dispose(); return null; } this.Paint(pa); } finally { g.Dispose(); } return bitmap; }