public override void DrawEffectImage(Bitmap current, Bitmap next, EffectingPanel effecingPanel) { int step = 1; Graphics bg; Bitmap doubleBufferingBitmap; SolidBrush solidBrush; Rectangle rectangle; Matrix matrix = null; try { doubleBufferingBitmap = new Bitmap(current); // ダブルバッファリング用画面 bg = Graphics.FromImage(doubleBufferingBitmap); // ダブルバッファリング用画面描画用Graphics solidBrush = new SolidBrush(System.Drawing.Color.Black); rectangle = new Rectangle(0, 0, current.Width, current.Height); matrix = new Matrix(); step = doubleBufferingBitmap.Width / 50; if (step < 1) { step = 1; } ResetInterval(); for (int x = 0; x < doubleBufferingBitmap.Width; x += step) { bg.ResetTransform(); // リセット座標変換 bg.FillRectangle(solidBrush, rectangle); // current画像 matrix.Reset(); matrix.Translate(x, 0, MatrixOrder.Append); // 原点移動 bg.Transform = matrix; // 座標設定 bg.DrawImage(current, 0, 0); // next画像 matrix.Reset(); matrix.Translate(x - doubleBufferingBitmap.Width, 0, MatrixOrder.Append); bg.Transform = matrix; bg.DrawImage(next, 0, 0); effecingPanel.pictureBox.Image = doubleBufferingBitmap; effecingPanel.pictureBox.Refresh(); DoEventAtIntervals(); } matrix.Dispose(); bg.Dispose(); doubleBufferingBitmap.Dispose(); effecingPanel.pictureBox.Image = next; } catch (SystemException ex) { Console.WriteLine(ex.Message); } }
internal static float ConvertSweepAngle(float sweepAngle, float startAngle, SpatialTransform transform, CoordinateSystem targetSystem) { PointF x = new PointF(100, 0); PointF[] startVector = new PointF[] { x }; Matrix rotation = new Matrix(); rotation.Rotate(startAngle); rotation.TransformVectors(startVector); PointF[] sweepVector = (PointF[])startVector.Clone(); rotation.Reset(); rotation.Rotate(sweepAngle); rotation.TransformVectors(sweepVector); rotation.Dispose(); SizeF startVectorTransformed, sweepVectorTransformed; if (targetSystem == Graphics.CoordinateSystem.Destination) { startVectorTransformed = transform.ConvertToDestination(new SizeF(startVector[0])); sweepVectorTransformed = transform.ConvertToDestination(new SizeF(sweepVector[0])); } else { startVectorTransformed = transform.ConvertToSource(new SizeF(startVector[0])); sweepVectorTransformed = transform.ConvertToSource(new SizeF(sweepVector[0])); } // simply return the angle between the start and sweep angle, in the target system. return((int)Math.Round(Vector.SubtendedAngle(sweepVectorTransformed.ToPointF(), PointF.Empty, startVectorTransformed.ToPointF()))); }
public void Render(Symbol symbol, Graphics g) { this.g = g; translateMatrix = new System.Drawing.Drawing2D.Matrix(); DrawSymbol(symbol); translateMatrix.Dispose(); }
public void Dispose() { if (control != null) { control.Dispose(); control = null; } }
public void Rotate(float degrees) { Matrix translateMatrix = new Matrix(); RectangleF rectF = mPath.GetBounds(); translateMatrix.RotateAt(degrees, new PointF(rectF.Width / 2, rectF.Height /2)); mPath.Transform(translateMatrix); translateMatrix.Dispose(); }
public void SetMatrix(Vex.Matrix m) { Vex.Transform t = instance.GetTransformAtTime(0); t.Matrix = m; if (sysMatrix != null) { sysMatrix.Dispose(); } sysMatrix = m.SysMatrix(); HasSaveableChanges = true; }
public void DrawMaskInto(Graphics g, Color c) { SysMatrix orgM = g.Transform; SysMatrix newM = GetMatrix().SysMatrix(); newM.Multiply(orgM, MatrixOrder.Append); g.Transform = newM; stage.Gdi.RenderMaskInto(Definition, 0, g, c); newM.Dispose(); g.Transform = orgM; }
public void DrawInto(Graphics g, float offsetX, float offsetY) { SysMatrix orgM = g.Transform; SysMatrix newM = GetMatrix().SysMatrix(); newM.Multiply(orgM, MatrixOrder.Append); newM.Translate(-offsetX, -offsetY, MatrixOrder.Append); g.Transform = newM; stage.Gdi.RenderInto(Definition, 0, g); newM.Dispose(); g.Transform = orgM; }
public override void DrawEffectImage(Bitmap current, Bitmap next, EffectingPanel effecingPanel) { Bitmap doubleBufferingBitmap = null; // ダブルバッファリング用画面 Graphics bg = null; // ダブルバッファリング用画面描画用Graphics SolidBrush solidBrush = null; Rectangle rectangle; Matrix matrix = null; try { int deltaDegree = 10; doubleBufferingBitmap = new Bitmap(current); bg = Graphics.FromImage(doubleBufferingBitmap); solidBrush = new SolidBrush(System.Drawing.Color.Black); rectangle = new Rectangle(0, 0, current.Width, current.Height); matrix = new Matrix(); ResetInterval(); for (int angle = 0; angle <= 360; angle += deltaDegree) { bg.ResetTransform(); // リセット座標変換 bg.FillRectangle(solidBrush, rectangle); matrix.Reset(); matrix.Translate(doubleBufferingBitmap.Width / 2, doubleBufferingBitmap.Height / 2, MatrixOrder.Append); // 原点移動 matrix.Rotate((float)angle); bg.Transform = matrix; // 座標設定 bg.DrawImage(current, -doubleBufferingBitmap.Width / 2, -doubleBufferingBitmap.Height / 2); // 画像の中心が(0, 0)になるように描画 effecingPanel.pictureBox.Image = doubleBufferingBitmap; effecingPanel.pictureBox.Refresh(); Thread.Sleep(20); DoEventAtIntervals(); } matrix.Dispose(); bg.Dispose(); doubleBufferingBitmap.Dispose(); } catch(SystemException ex) { Console.WriteLine(ex.Message); } }
/// <summary> /// kbd4hire 20090318 Method no longer used! /// </summary> /// <returns></returns> private GdiMatrix getGdiViewTransform() { if (_gdiViewMatrix == null) { _gdiViewMatrix = ToViewTransform == null ? new GdiMatrix() : ViewConverter.Convert(ToViewTransform); return(_gdiViewMatrix); } Matrix2D viewMatrix = ToViewTransform ?? new Matrix2D(); Single[] gdiElements = _gdiViewMatrix.Elements; if (gdiElements[0] != (Single)viewMatrix.M11 || gdiElements[1] != (Single)viewMatrix.M12 || gdiElements[2] != (Single)viewMatrix.M21 || gdiElements[3] != (Single)viewMatrix.M22 || gdiElements[4] != (Single)viewMatrix.OffsetX || gdiElements[5] != (Single)viewMatrix.OffsetY) { Debug.WriteLine( String.Format( "Disposing GDI matrix on values: {0} : {1}; {2} : {3}; {4} : {5}; {6} : {7}; {8} : {9}; {10} : {11}", gdiElements[0], (Single)viewMatrix.M11, gdiElements[1], (Single)viewMatrix.M12, gdiElements[2], (Single)viewMatrix.M21, gdiElements[3], (Single)viewMatrix.M22, gdiElements[4], (Single)viewMatrix.OffsetX, gdiElements[5], (Single)viewMatrix.OffsetY)); _gdiViewMatrix.Dispose(); _gdiViewMatrix = ViewConverter.Convert(ToViewTransform); } return(_gdiViewMatrix); }
protected void DrawBwShape(Graphics g, GraphicsPath gpPass, float flOpacity, float flOutlineWidth, Color clBackground, Color clForecolour) { if (flOpacity > 0.0F) { GraphicsPath gp = (GraphicsPath)gpPass.Clone(); Matrix m = new Matrix(); m.Translate(this.m_pntDrawOffset.X, this.m_pntDrawOffset.Y); gp.Transform(m); Pen pen = new Pen(Color.FromArgb((int)(255.0F * flOpacity), clBackground), flOutlineWidth); pen.LineJoin = LineJoin.Round; g.DrawPath(pen, gp); SolidBrush brush = new SolidBrush(Color.FromArgb((int)(255.0F * flOpacity), clForecolour)); g.FillPath(brush, gp); brush.Dispose(); pen.Dispose(); m.Dispose(); gp.Dispose(); } }
internal static float ConvertStartAngle(float angle, SpatialTransform transform, CoordinateSystem targetSystem) { PointF xVector = new PointF(100, 0); Matrix rotation = new Matrix(); PointF[] angleVector = new PointF[] { xVector }; rotation.Rotate(angle); rotation.TransformVectors(angleVector); rotation.Dispose(); SizeF xVectorTransformed, angleVectorTransformed; if (targetSystem == Graphics.CoordinateSystem.Destination) { xVectorTransformed = transform.ConvertToDestination(new SizeF(xVector)); angleVectorTransformed = transform.ConvertToDestination(new SizeF(angleVector[0])); } else { xVectorTransformed = transform.ConvertToSource(new SizeF(xVector)); angleVectorTransformed = transform.ConvertToSource(new SizeF(angleVector[0])); } float xRotationOffset = (int)Math.Round(Vector.SubtendedAngle(xVectorTransformed.ToPointF(), PointF.Empty, xVector)); float angleTransformed = (int)Math.Round(Vector.SubtendedAngle(angleVectorTransformed.ToPointF(), PointF.Empty, xVectorTransformed.ToPointF())); // have to figure out where x-axis moved to and then return the difference between the angle // and the x-axis, where both are in 'target' coordinates. float returnAngle = angleTransformed + xRotationOffset; if (returnAngle < 0) { returnAngle += 360; } return(returnAngle); }
/// <summary> /// Generates a dictionary of Symbol id and rendered bitmap. /// </summary> /// <param name="v"></param> /// <returns></returns> public Dictionary<uint, Bitmap> GenerateMappedBitmaps(VexObject v, bool includeImages) { Dictionary<uint, Bitmap> result = new Dictionary<uint, Bitmap>(); foreach (uint key in v.Definitions.Keys) { IDefinition def = v.Definitions[key]; if (def is Symbol) { Symbol symbol = (Symbol)def; Bitmap myBitmap = new Bitmap( (int)symbol.StrokeBounds.Size.Width + 1, (int)symbol.StrokeBounds.Size.Height + 1); myBitmap.SetResolution(96, 96); translateMatrix = new System.Drawing.Drawing2D.Matrix( 1, 0, 0, 1, -symbol.StrokeBounds.Point.X, -symbol.StrokeBounds.Point.Y); g = Graphics.FromImage(myBitmap); g.SmoothingMode = SmoothingMode.AntiAlias; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.CompositingMode = CompositingMode.SourceOver; g.CompositingQuality = CompositingQuality.AssumeLinear; DrawSymbol(symbol); result.Add(symbol.Id, myBitmap); translateMatrix.Dispose(); } else if (includeImages && def is Vex.Image) { Bitmap bmp = new Bitmap(def.Path); result.Add(def.Id, bmp); } } return result; }
/// <summary> /// Generates a dictionary of Symbol id and rendered bitmap. /// </summary> /// <param name="v"></param> /// <returns></returns> public Dictionary <uint, Bitmap> GenerateMappedBitmaps(VexObject v, bool includeImages) { Dictionary <uint, Bitmap> result = new Dictionary <uint, Bitmap>(); foreach (uint key in v.Definitions.Keys) { IDefinition def = v.Definitions[key]; if (def is Symbol) { Symbol symbol = (Symbol)def; Bitmap myBitmap = new Bitmap( (int)symbol.StrokeBounds.Size.Width + 1, (int)symbol.StrokeBounds.Size.Height + 1); myBitmap.SetResolution(96, 96); translateMatrix = new System.Drawing.Drawing2D.Matrix( 1, 0, 0, 1, -symbol.StrokeBounds.Point.X, -symbol.StrokeBounds.Point.Y); g = Graphics.FromImage(myBitmap); g.SmoothingMode = SmoothingMode.AntiAlias; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.CompositingMode = CompositingMode.SourceOver; g.CompositingQuality = CompositingQuality.AssumeLinear; DrawSymbol(symbol); result.Add(symbol.Id, myBitmap); translateMatrix.Dispose(); } else if (includeImages && def is Vex.Image) { Bitmap bmp = new Bitmap(def.Path); result.Add(def.Id, bmp); } } return(result); }
/// <summary> /// Apply a bitmap effect to the surface /// </summary> /// <param name="effect"></param> public void ApplyBitmapEffect(IEffect effect) { BackgroundForm backgroundForm = new BackgroundForm("Effect", "Please wait"); backgroundForm.Show(); Application.DoEvents(); try { Rectangle imageRectangle = new Rectangle(Point.Empty, Image.Size); Matrix matrix = new Matrix(); Image newImage = ImageHelper.ApplyEffect(Image, effect, matrix); if (newImage != null) { // Make sure the elements move according to the offset the effect made the bitmap move _elements.Transform(matrix); // Make undoable MakeUndoable(new SurfaceBackgroundChangeMemento(this, matrix), false); SetImage(newImage, false); Invalidate(); if (_surfaceSizeChanged != null && !imageRectangle.Equals(new Rectangle(Point.Empty, newImage.Size))) { _surfaceSizeChanged(this, null); } } else { // clean up matrix, as it hasn't been used in the undo stack. matrix.Dispose(); } } finally { // Always close the background form backgroundForm.CloseDialog(); } }
/// <summary> /// Paint one segment. /// </summary> /// <param name="g">The graphics object which will be painted on.</param> /// <param name="rectBound">The paint rectangle.</param> /// <param name="colSegment">segment color.</param> /// <param name="nIndex">the segment index.</param> /// <param name="bevelRate">corner rate.</param> /// <param name="segmentWidth">segment width.</param> /// <param name="segmentInterval">segment interval.</param> private void DrawSegment(Graphics g, Rectangle rectBound, Color colSegment, int nIndex, float bevelRate, float segmentWidth, float segmentInterval) { GraphicsPath segmentPath = null; SolidBrush segmentBrush = null; Matrix offsetMatrix = null; if (!m_bIsCacheBuild) { #if DEBUG System.Diagnostics.Debug.WriteLine("Rebuilding cache..."); #endif DestoryCache(); CreateCache(rectBound, bevelRate, segmentWidth, segmentInterval); } segmentPath = (GraphicsPath)(m_CachedPaths[nIndex - 1].Clone()); // offset path to desired position offsetMatrix = new Matrix(); offsetMatrix.Translate((float)rectBound.X, (float)rectBound.Y); segmentPath.Transform(offsetMatrix); // clip drawing(optimize drawing) segmentBrush = new SolidBrush(colSegment); g.Clip = new Region(this.ClientRectangle); g.FillPath(segmentBrush, segmentPath); // clear resources segmentBrush.Dispose(); offsetMatrix.Dispose(); segmentPath.Dispose(); }
public MatrixComponents GetMatrixComponents() { System.Drawing.Drawing2D.Matrix srcMatrix = new System.Drawing.Drawing2D.Matrix( this.ScaleX, this.Rotate0, this.Rotate1, this.ScaleY, this.TranslateX, this.TranslateY); System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix(1, 0, 0, 1, 0, 0); // identity // an 'identity' box PointF[] modPts = new PointF[]{ new PointF(0,0), new PointF(1,0), new PointF(1,1), new PointF(0,1) }; float sx, sy, rot, shear, tx, ty; srcMatrix.TransformPoints(modPts); // translation tx = srcMatrix.OffsetX; ty = srcMatrix.OffsetY; m.Translate(-tx, -ty); m.TransformPoints(modPts); m.Reset(); // rotation rot = (float)Math.Atan2(modPts[1].Y, modPts[1].X); // x axis rot = (float)(rot / Math.PI * 180); if (rot == -0) rot = 0; if (rot == -180) rot = 180; m.Rotate(-1 * rot); m.TransformPoints(modPts); m.Reset(); // scale //sx = Dist(modPts[0], modPts[3]); // bug it seems..? sx = Dist(modPts[0], modPts[1]); sy = Dist(modPts[0], new PointF(0, modPts[3].Y)); if (modPts[0].Y > modPts[3].Y) { sy *= -1; } m.Scale(1 / sx, 1 / sy); m.TransformPoints(modPts); m.Reset(); // skew // ySkew is impossible at this rotation shear = modPts[3].X / Dist(modPts[0], modPts[1]); // rounding shear = Math.Abs(shear) < 0.001 ? 0 : shear; m.Shear(-shear, 0); m.TransformPoints(modPts); m.Dispose(); srcMatrix.Dispose(); return new MatrixComponents(sx, sy, rot, shear, tx, ty); }
internal static float ConvertStartAngle(float angle, SpatialTransform transform, CoordinateSystem targetSystem) { PointF xVector = new PointF(100, 0); Matrix rotation = new Matrix(); PointF[] angleVector = new PointF[] { xVector }; rotation.Rotate(angle); rotation.TransformVectors(angleVector); rotation.Dispose(); SizeF xVectorTransformed, angleVectorTransformed; if (targetSystem == Graphics.CoordinateSystem.Destination) { xVectorTransformed = transform.ConvertToDestination(new SizeF(xVector)); angleVectorTransformed = transform.ConvertToDestination(new SizeF(angleVector[0])); } else { xVectorTransformed = transform.ConvertToSource(new SizeF(xVector)); angleVectorTransformed = transform.ConvertToSource(new SizeF(angleVector[0])); } float xRotationOffset = (int)Math.Round(Vector.SubtendedAngle(xVectorTransformed.ToPointF(), PointF.Empty, xVector)); float angleTransformed = (int)Math.Round(Vector.SubtendedAngle(angleVectorTransformed.ToPointF(), PointF.Empty, xVectorTransformed.ToPointF())); // have to figure out where x-axis moved to and then return the difference between the angle // and the x-axis, where both are in 'target' coordinates. float returnAngle = angleTransformed + xRotationOffset; if (returnAngle < 0) returnAngle += 360; return returnAngle; }
public void GenerateFilteredBitmaps(VexObject v, Dictionary <string, IDefinition> usedImages, Dictionary <string, List <Bitmap> > genImages) { foreach (string s in usedImages.Keys) { uint key = usedImages[s].Id; IDefinition def = v.Definitions[key]; if (def is Timeline) { Timeline tl = (Timeline)def; Timeline namedSymbol = GetNamedSymbol(v, tl); if (namedSymbol != null && HasSymbols(v, namedSymbol)) { List <Bitmap> bmpFrames = new List <Bitmap>(); for (int i = 0; i < tl.FrameCount; i++) { Bitmap myBitmap = new Bitmap( (int)namedSymbol.StrokeBounds.Size.Width + 1, (int)namedSymbol.StrokeBounds.Size.Height + 1); myBitmap.SetResolution(96, 96); translateMatrix = new System.Drawing.Drawing2D.Matrix( 1, 0, 0, 1, -namedSymbol.StrokeBounds.Point.X, -namedSymbol.StrokeBounds.Point.Y); g = Graphics.FromImage(myBitmap); g.SmoothingMode = SmoothingMode.AntiAlias; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.CompositingMode = CompositingMode.SourceOver; g.CompositingQuality = CompositingQuality.AssumeLinear; DrawFilteredTimeline(v, namedSymbol); translateMatrix.Dispose(); bmpFrames.Add(myBitmap); } string name = s + "#" + namedSymbol.Id; genImages.Add(name, bmpFrames); } } else if (def is Symbol) { Symbol sy = (Symbol)def; List <Bitmap> bmpFrames = new List <Bitmap>(); Bitmap myBitmap = new Bitmap( (int)sy.StrokeBounds.Size.Width + 1, (int)sy.StrokeBounds.Size.Height + 1); myBitmap.SetResolution(96, 96); translateMatrix = new System.Drawing.Drawing2D.Matrix( 1, 0, 0, 1, -sy.StrokeBounds.Point.X, -sy.StrokeBounds.Point.Y); g = Graphics.FromImage(myBitmap); g.SmoothingMode = SmoothingMode.AntiAlias; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.CompositingMode = CompositingMode.SourceOver; g.CompositingQuality = CompositingQuality.AssumeLinear; DrawFilteredSymbol(sy); translateMatrix.Dispose(); bmpFrames.Add(myBitmap); string name = s + "#" + sy.Id; genImages.Add(name, bmpFrames); } else if (def is Text) { Text tx = (Text)def; if (tx.TextRuns.Count > 0 && !tx.TextRuns[0].isEditable) { List <Bitmap> bmpFrames = new List <Bitmap>(); Bitmap myBitmap = new Bitmap( (int)tx.StrokeBounds.Size.Width + 1, (int)tx.StrokeBounds.Size.Height + 1); //translateMatrix = new System.Drawing.Drawing2D.Matrix( // 1, 0, 0, 1, -tx.StrokeBounds.Point.X, -tx.StrokeBounds.Point.Y); //myBitmap.SetResolution(72, 72); myBitmap.SetResolution(96, 96); g = Graphics.FromImage(myBitmap); DrawText(tx, new DDW.Vex.Matrix(1, 0, 0, 1, -tx.StrokeBounds.Point.X, -tx.StrokeBounds.Point.Y)); //translateMatrix.Dispose(); bmpFrames.Add(myBitmap); string name = s + "#" + tx.Id; genImages.Add(name, bmpFrames); } } } }
public static void ScaleAt(this Matrix result, float scaleX, float scaleY, PointF center) { Matrix mReg = new Matrix(result.Elements[0], result.Elements[1], result.Elements[2], result.Elements[3], 0, 0); Matrix mInv = result.Clone(); mInv.Invert(); float offsetX = result.OffsetX; float offsetY = result.OffsetY; // move to orgin and scale result.Reset(); result.Scale(scaleX, scaleY, MatrixOrder.Append); result.Multiply(mReg, MatrixOrder.Append); // find new orgin PointF dif = new PointF(center.X - offsetX, center.Y - offsetY); PointF[] pts1 = new PointF[] { dif }; mInv.TransformVectors(pts1); result.TransformVectors(pts1); PointF finalOffset = new PointF(center.X - pts1[0].X, center.Y - pts1[0].Y); result.Translate(finalOffset.X, finalOffset.Y, MatrixOrder.Append); mReg.Dispose(); mInv.Dispose(); }
private Point ClientPointToGame(Point pntClient) { Point[] pntReturn = new Point[] { this.ClientPointToZoom(pntClient) }; if (this.LoadedMapImagePack != null) { Matrix m = new Matrix(); pntReturn[0].X = (int)((float)pntReturn[0].X - this.LoadedMapImagePack.MapOrigin.X); pntReturn[0].Y = (int)((float)pntReturn[0].Y - this.LoadedMapImagePack.MapOrigin.Y); pntReturn[0].X = (int)((float)pntReturn[0].X / this.LoadedMapImagePack.MapScale.X); pntReturn[0].Y = (int)((float)pntReturn[0].Y / this.LoadedMapImagePack.MapScale.Y); m.Rotate(360.0F - this.LoadedMapImagePack.MapRotation); m.TransformPoints(pntReturn); m.Dispose(); } else { pntReturn[0].X = 0; pntReturn[0].Y = 0; } return pntReturn[0]; }
public void nextFrame(ref AnimationFrameArgs e) { if (currentFrame >= startFrame) { Started = true; var bck = e.Background; var frg = e.Forerground; e.graphics.DrawImageUnscaled(bck, Point.Empty); if (this.Distance <= this.EaseIn) { this.DeltaSpeed = 0; this.Speed = 10; } mat = new Matrix(); switch (this.From) { case Direction.Left: mat.Translate(-this.Distance, 0); break; case Direction.Top: mat.Translate(0, -this.Distance); break; case Direction.Right: mat.Translate(this.Distance, 0); break; case Direction.Bottom: mat.Translate(0, this.Distance); break; } e.graphics .Transform = mat; this.Distance -= this.Speed; this.Speed += this.DeltaSpeed; e.graphics .DrawImage(frg , e.Location); mat.Dispose(); } if (this.Distance <= 0) this.Completed = true; this.currentFrame += 1; }
private void DrawPushedState(Graphics g) { GraphicsPath outerRegion = RoundedRect(this.Width - 1, this.Height - 1, 3); GraphicsPath innerRegion = RoundedRect(this.Width - 3, this.Height - 3, 2); Matrix translate = new Matrix(); translate.Translate(1, 1); innerRegion.Transform(translate); translate.Dispose(); Rectangle backgroundRect = new Rectangle(1, 1, this.Width - 3, this.Height - 3); Pen outlinePen = new Pen(Color.FromArgb(167, 167, 167)); Pen inlinePen = new Pen(Color.FromArgb(227, 227, 227)); SolidBrush backBrush = new SolidBrush(Color.FromArgb(234, 234, 234)); g.SmoothingMode = SmoothingMode.AntiAlias; g.FillRectangle(backBrush, backgroundRect); g.DrawPath(outlinePen, outerRegion); g.DrawPath(inlinePen, innerRegion); offset = 1; DrawForeground(g); outlinePen.Dispose(); outerRegion.Dispose(); inlinePen.Dispose(); innerRegion.Dispose(); }
private void DrawHoverState(Graphics g) { GraphicsPath outerRegion = RoundedRect(this.Width - 1, this.Height - 1, 3); GraphicsPath innerRegion = RoundedRect(this.Width - 3, this.Height - 3, 2); Matrix translate = new Matrix(); translate.Translate(1, 1); innerRegion.Transform(translate); translate.Dispose(); Rectangle backgroundRect = new Rectangle(1, 1, this.Width - 2, Convert.ToInt32(this.Height * 0.75f) - 2); Pen outlinePen = new Pen(Color.FromArgb(189, 189, 189)); Pen inlinePen = new Pen(Color.FromArgb(245, 255, 255, 255)); LinearGradientBrush backBrush = new LinearGradientBrush(new Point(0, 0), new Point(0, backgroundRect.Height), Color.White, Color.Transparent); backBrush.WrapMode = WrapMode.TileFlipX; g.SmoothingMode = SmoothingMode.AntiAlias; g.FillRectangle(backBrush, backgroundRect); g.DrawPath(outlinePen, outerRegion); g.DrawPath(inlinePen, innerRegion); offset = 0; DrawForeground(g); outlinePen.Dispose(); outerRegion.Dispose(); inlinePen.Dispose(); innerRegion.Dispose(); }
private void DrawHighLight(Graphics g) { GraphicsPath innerRegion = RoundedRect(this.Width - 3, this.Height - 3, 3); Matrix translate = new Matrix(); translate.Translate(1, 1); innerRegion.Transform(translate); translate.Dispose(); Pen inlinePen = new Pen(Color.FromArgb(192, 233, 243)); g.SmoothingMode = SmoothingMode.AntiAlias; g.DrawPath(inlinePen, innerRegion); inlinePen.Dispose(); innerRegion.Dispose(); }
internal static void drawRotationHandle( Graphics g, Color rgb, Color rgbDis, RectangleF rc, float rotationAngle, Handles mask, bool showDsbl, float size) { bool draw = true; System.Drawing.Pen pen = new System.Drawing.Pen(Color.Black, 0); System.Drawing.Brush enbBrush = new System.Drawing.SolidBrush(rgb); System.Drawing.Brush dsbBrush = new System.Drawing.SolidBrush(rgbDis); System.Drawing.Brush brush; // determine whether this handle should be drawn if ((mask & Handles.Rotate) != 0) { brush = enbBrush; } else { brush = dsbBrush; draw = false; } if (draw) { PointF center = getCenter(rc); PointF[] rotPoints = new PointF[] { new PointF(center.X, rc.Top - 6 * Constants.getMillimeter(g.PageUnit)), new PointF(center.X, rc.Top) }; // apply rotation if (rotationAngle != 0) { Matrix rotation = new Matrix(); rotation.RotateAt(rotationAngle, center); rotation.TransformPoints(rotPoints); rotation.Dispose(); } PointF point = rotPoints[0]; g.FillEllipse(brush, point.X - 2.8F*size/4, point.Y - 2.8F*size/4, 2.8F*size/2, 2.8F*size/2); g.DrawEllipse(pen, point.X - 2.8F*size/4, point.Y - 2.8F*size/4, 2.8F*size/2, 2.8F*size/2); System.Drawing.Pen rotMarker = new System.Drawing.Pen(brush, 0); rotMarker.DashStyle = DashStyle.Dot; g.DrawLine(rotMarker, point, rotPoints[1]); rotMarker.Dispose(); } pen.Dispose(); enbBrush.Dispose(); dsbBrush.Dispose(); }
/// <summary> /// Paint all drawables /// </summary> /// <param name="drawables">List of drawable elements</param> public void Paint(List<IDrawable> drawables) { Graphics graphics = Graphics.FromImage(_bitmap); // transform coordinate system Matrix m = new Matrix(1, 0, 0, -1, 0, 0); m.Translate(0, HEIGHT, MatrixOrder.Append); graphics.Transform = m; // set smoothing mode to antialiasing graphics.SmoothingMode = SmoothingMode.AntiAlias; foreach (IDrawable item in drawables) { item.Paint(graphics); } m.Dispose(); graphics.Dispose(); _valid = false; // force revalidation for preview }
// While still in design this function draws directly to the component. // Once design is complete it will paint to a image, then the image painted to the component for a little speed boost. private void DrawKillCircles(Graphics g, Kill kKill, KillDisplayDetails kddKillDetails) { PointF pntLineStart = new PointF((float)kKill.KillerLocation.X, (float)kKill.KillerLocation.Y); PointF pntLineEnd = new PointF((float)kKill.VictimLocation.X, (float)kKill.VictimLocation.Y); PointF pntLineHalfway = new PointF(pntLineStart.X - (pntLineStart.X - pntLineEnd.X) / 2, pntLineStart.Y - (pntLineStart.Y - pntLineEnd.Y) / 2 - 3); PointF pntLineHalfway2 = new PointF(pntLineStart.X - (pntLineStart.X - pntLineEnd.X) / 2, pntLineStart.Y - (pntLineStart.Y - pntLineEnd.Y) / 2 - 4); LinearGradientBrush killBrush = this.GetKillColour(this.KillColours, kKill, kddKillDetails); GraphicsPath gpKillCircles = new GraphicsPath(); gpKillCircles.AddEllipse(new Rectangle(kKill.KillerLocation.X - this.ErrorRadius, kKill.KillerLocation.Y - this.ErrorRadius, this.ErrorRadius * 2, this.ErrorRadius * 2)); gpKillCircles.AddEllipse(new Rectangle(kKill.VictimLocation.X - this.ErrorRadius, kKill.VictimLocation.Y - this.ErrorRadius, this.ErrorRadius * 2, this.ErrorRadius * 2)); gpKillCircles.FillMode = FillMode.Winding; //GraphicsPath gpKill = new GraphicsPath(); GraphicsPath gpKill = (GraphicsPath)gpKillCircles.Clone(); gpKill.AddClosedCurve(new PointF[] { pntLineStart, pntLineHalfway, pntLineEnd, pntLineHalfway2 }); //gpKill.AddEllipse(new Rectangle(kKill.KillerLocation.X - this.ErrorRadius, kKill.KillerLocation.Y - this.ErrorRadius, this.ErrorRadius * 2, this.ErrorRadius * 2)); //gpKill.AddEllipse(new Rectangle(kKill.VictimLocation.X - this.ErrorRadius, kKill.VictimLocation.Y - this.ErrorRadius, this.ErrorRadius * 2, this.ErrorRadius * 2)); gpKill.FillMode = FillMode.Winding; GraphicsPath gpKillOutline = (GraphicsPath)gpKill.Clone(); //GraphicsPath gpKillOutline = new GraphicsPath(gpKill.PathPoints, gpKill.PathTypes); Matrix gpKillMatrix = new Matrix(); gpKillOutline.Widen(this.m_pTwoWidth, gpKillMatrix, 0.01F); Region reKillOutline = new Region(gpKillOutline); reKillOutline.Exclude(gpKill); reKillOutline.Exclude(gpKillCircles); Region reKill = new Region(gpKill); reKill.Union(gpKillCircles); //Region reKillDropshadow = new Region(gpKill); //reKillDropshadow.Union(gpKillCircles); //reKillDropshadow.Union(reKillOutline); //reKillDropshadow.Translate(0.4F, 1.0F); if (reKill.IsVisible(this.ClientPointToGame(this.PointToClient(Cursor.Position))) == true) { kddKillDetails.IsMouseOver = true; kddKillDetails.Opacity = 1.0F; } else { kddKillDetails.IsMouseOver = false; } //g.FillRegion(new SolidBrush(Color.FromArgb((int)(64.0F * kddKillDetails.Opacity), Color.Black)), reKillDropshadow); g.FillRegion(killBrush, reKill); g.FillRegion(new SolidBrush(Color.FromArgb((int)(255.0F * kddKillDetails.Opacity), Color.Black)), reKillOutline); if (this.LoadedMapImagePack != null) { Image imgDeathIcon = null; if (kKill.Headshot == true) { imgDeathIcon = this.LoadedMapImagePack.CompensateImageRotation(this.LoadedMapImagePack.GetIcon("Headshot")); } else { imgDeathIcon = this.LoadedMapImagePack.CompensateImageRotation(this.LoadedMapImagePack.GetIcon("Death")); } if (imgDeathIcon != null) { ColorMatrix colormatrix = new ColorMatrix(); colormatrix.Matrix00 = 1.0F; colormatrix.Matrix11 = 1.0F; colormatrix.Matrix22 = 1.0F; colormatrix.Matrix33 = kddKillDetails.Opacity; colormatrix.Matrix44 = 1.0F; ImageAttributes imgattr = new ImageAttributes(); imgattr.SetColorMatrix(colormatrix); Rectangle destRect = new Rectangle((int)pntLineEnd.X - 12, (int)pntLineEnd.Y - 12, 24, 24); g.DrawImage(imgDeathIcon, destRect, 0, 0, imgDeathIcon.Width, imgDeathIcon.Height, GraphicsUnit.Pixel, imgattr); imgattr.Dispose(); imgDeathIcon.Dispose(); } } this.DrawMapText(g, kKill.Victim.SoldierName, kKill.VictimLocation, 16, kddKillDetails.Opacity); this.DrawMapText(g, kKill.Killer.SoldierName, kKill.KillerLocation, 16, kddKillDetails.Opacity); killBrush.Dispose(); gpKillCircles.Dispose(); gpKill.Dispose(); gpKillOutline.Dispose(); gpKillMatrix.Dispose(); reKill.Dispose(); }
//private void DrawMapText(Graphics g, string strText, Point3D pntLocation, int iSize, float flOpacity, float flScaleChange) { //} private void DrawMapText(Graphics g, string strText, Point3D pntLocation, int iSize, float flOpacity) { GraphicsPath gpKillerName = new GraphicsPath(); float textZoom = this.ZoomFactor * ((this.LoadedMapImagePack.MapScale.X + this.LoadedMapImagePack.MapScale.Y) / 2.0F); Font fontText = new Font("Arial", Math.Max(Math.Min(iSize / textZoom, iSize), 1.0F), FontStyle.Regular); SizeF sText = g.MeasureString(strText, fontText); float outlineWidth = Math.Min(4.0F / textZoom, 4.0F); gpKillerName.AddString(strText, fontText.FontFamily, (int)fontText.Style, fontText.Size, new PointF((float)pntLocation.X, (float)pntLocation.Y), StringFormat.GenericDefault); Matrix m = new Matrix(); m.RotateAt(-this.LoadedMapImagePack.MapRotation, new PointF((float)pntLocation.X, (float)pntLocation.Y)); m.Translate(gpKillerName.GetBounds().Width / -2.0F + outlineWidth / -2.0F, gpKillerName.GetBounds().Height / -2.0F + outlineWidth / -2.0F); gpKillerName.Transform(m); this.DrawBwShape(g, gpKillerName, flOpacity, outlineWidth, Color.Black, Color.WhiteSmoke); fontText.Dispose(); m.Dispose(); gpKillerName.Dispose(); }
partial void DisposeImpl() { t.Dispose(); }
internal static GraphicsPath rotateRectAt(RectangleF rc, PointF pivot, float angle) { GraphicsPath path = new GraphicsPath(); path.AddRectangle(rc); Matrix rotation = new Matrix(); rotation.RotateAt(angle, pivot); path.Transform(rotation); rotation.Dispose(); return path; }
public void GenerateFilteredBitmaps(VexObject v, Dictionary<string, IDefinition> usedImages, Dictionary<string, List<Bitmap>> genImages) { foreach (string s in usedImages.Keys) { uint key = usedImages[s].Id; IDefinition def = v.Definitions[key]; if (def is Timeline) { Timeline tl = (Timeline)def; Timeline namedSymbol = GetNamedSymbol(v, tl); if (namedSymbol != null && HasSymbols(v, namedSymbol)) { List<Bitmap> bmpFrames = new List<Bitmap>(); for (int i = 0; i < tl.FrameCount; i++) { Bitmap myBitmap = new Bitmap( (int)namedSymbol.StrokeBounds.Size.Width + 1, (int)namedSymbol.StrokeBounds.Size.Height + 1); myBitmap.SetResolution(96, 96); translateMatrix = new System.Drawing.Drawing2D.Matrix( 1, 0, 0, 1, -namedSymbol.StrokeBounds.Point.X, -namedSymbol.StrokeBounds.Point.Y); g = Graphics.FromImage(myBitmap); g.SmoothingMode = SmoothingMode.AntiAlias; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.CompositingMode = CompositingMode.SourceOver; g.CompositingQuality = CompositingQuality.AssumeLinear; DrawFilteredTimeline(v, namedSymbol); translateMatrix.Dispose(); bmpFrames.Add(myBitmap); } string name = s + "#" + namedSymbol.Id; genImages.Add(name, bmpFrames); } } else if (def is Symbol) { Symbol sy = (Symbol)def; List<Bitmap> bmpFrames = new List<Bitmap>(); Bitmap myBitmap = new Bitmap( (int)sy.StrokeBounds.Size.Width + 1, (int)sy.StrokeBounds.Size.Height + 1); myBitmap.SetResolution(96, 96); translateMatrix = new System.Drawing.Drawing2D.Matrix( 1, 0, 0, 1, -sy.StrokeBounds.Point.X, -sy.StrokeBounds.Point.Y); g = Graphics.FromImage(myBitmap); g.SmoothingMode = SmoothingMode.AntiAlias; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.CompositingMode = CompositingMode.SourceOver; g.CompositingQuality = CompositingQuality.AssumeLinear; DrawFilteredSymbol(sy); translateMatrix.Dispose(); bmpFrames.Add(myBitmap); string name = s + "#" + sy.Id; genImages.Add(name, bmpFrames); } else if (def is Text) { Text tx = (Text)def; if (tx.TextRuns.Count > 0 && !tx.TextRuns[0].isEditable) { List<Bitmap> bmpFrames = new List<Bitmap>(); Bitmap myBitmap = new Bitmap( (int)tx.StrokeBounds.Size.Width + 1, (int)tx.StrokeBounds.Size.Height + 1); //translateMatrix = new System.Drawing.Drawing2D.Matrix( // 1, 0, 0, 1, -tx.StrokeBounds.Point.X, -tx.StrokeBounds.Point.Y); //myBitmap.SetResolution(72, 72); myBitmap.SetResolution(96, 96); g = Graphics.FromImage(myBitmap); DrawText(tx, new DDW.Vex.Matrix(1, 0, 0, 1, -tx.StrokeBounds.Point.X, -tx.StrokeBounds.Point.Y)); //translateMatrix.Dispose(); bmpFrames.Add(myBitmap); string name = s + "#" + tx.Id; genImages.Add(name, bmpFrames); } } } }
internal static void drawSquareHandles(Graphics g, Handles mask, Color rgb, Color rgbDis, bool showDsbl, RectangleF rc, float rotationAngle, HandlesStyle st, float size) { PointF center = getCenter(rc); // select pen and brush for drawing the selection handles System.Drawing.Pen pen = new System.Drawing.Pen(Color.Black, 0); System.Drawing.Brush enbBrush = new System.Drawing.SolidBrush(rgb); System.Drawing.Brush dsbBrush = new System.Drawing.SolidBrush(rgbDis); System.Drawing.Brush brush; // calculate selection handles coordinates PointF[] handlePoints = new PointF[10]; handlePoints[0] = new PointF(rc.Left, rc.Top); handlePoints[1] = new PointF(rc.Right, rc.Top); handlePoints[2] = new PointF(rc.Right, rc.Bottom); handlePoints[3] = new PointF(rc.Left, rc.Bottom); handlePoints[4] = new PointF(center.X, rc.Top); handlePoints[5] = new PointF(rc.Right, center.Y); handlePoints[6] = new PointF(center.X, rc.Bottom); handlePoints[7] = new PointF(rc.Left, center.Y); handlePoints[8] = center; handlePoints[9] = new PointF( center.X, rc.Top - 6 * Constants.getMillimeter(g.PageUnit)); // apply rotation if (rotationAngle != 0) { Matrix rotation = new Matrix(); rotation.RotateAt(rotationAngle, center); rotation.TransformPoints(handlePoints); rotation.Dispose(); } // draw the handles float hsize = size / 2; for (int h = 0; h <= 9; h++) { bool draw = true; // determine whether this handle should be drawn if (((long)mask & (1 << h)) != 0) { brush = enbBrush; } else { brush = dsbBrush; draw = showDsbl && h != 9; } if (draw) { PointF point = handlePoints[h]; // the side and corner handles if (h < 8) { g.FillRectangle(brush, point.X - hsize, point.Y - hsize, size, size); g.DrawRectangle(pen, point.X - hsize, point.Y - hsize, size, size); } // the center handle else if (h == 8) { if (st == HandlesStyle.EasyMove) { //g.FillEllipse(brush, // point.X - size, point.Y - size, 2*size, 2*size); //g.DrawEllipse(pen, // point.X - size, point.Y - size, 2*size, 2*size); } if (st == HandlesStyle.SquareHandles) { g.FillRectangle(brush, point.X - hsize, point.Y - hsize, size, size); g.DrawRectangle(pen, point.X - hsize, point.Y - hsize, size, size); } } // the rotation handle else if (h == 9) { g.FillEllipse(brush, point.X - 2.8F*size/4, point.Y - 2.8F*size/4, 2.8F*size/2, 2.8F*size/2); g.DrawEllipse(pen, point.X - 2.8F*size/4, point.Y - 2.8F*size/4, 2.8F*size/2, 2.8F*size/2); System.Drawing.Pen rotMarker = new System.Drawing.Pen(brush, 0); rotMarker.DashStyle = DashStyle.Dot; g.DrawLine(rotMarker, point, handlePoints[4]); rotMarker.Dispose(); } } } //cleanup pen.Dispose(); enbBrush.Dispose(); dsbBrush.Dispose(); }
//Draws the button when it's clicked down private void DrawPushedState(Graphics g) { GraphicsPath outerRegion = RoundedRect(this.Width - 1, this.Height - 1, 3); GraphicsPath innerRegion = RoundedRect(this.Width - 3, this.Height - 3, 2); //----Shift the inner region inwards Matrix translate = new Matrix(); translate.Translate(1, 1); innerRegion.Transform(translate); translate.Dispose(); //----- Rectangle backgroundRect = new Rectangle(1, 1, this.Width - 3, this.Height - 3); Pen outlinePen = new Pen(Color.FromArgb(167, 167, 167)); //Outline is darker than normal Pen inlinePen = new Pen(Color.FromArgb(227, 227, 227)); //Darker white SolidBrush backBrush = new SolidBrush(Color.FromArgb(234, 234, 234)); //SystemColors.ControlLight g.SmoothingMode = SmoothingMode.AntiAlias; g.FillRectangle(backBrush, backgroundRect); g.DrawPath(inlinePen, innerRegion); g.DrawPath(outlinePen, outerRegion); //Text/Image offset = 1; //moves image inwards 1 pixel (x and y) to create the illusion that the button was pushed DrawForeground(g); //Clean up outlinePen.Dispose(); inlinePen.Dispose(); outerRegion.Dispose(); innerRegion.Dispose(); }
internal static void rotatePointsAt(PointF[] points, PointF pivot, float angle) { Matrix rotation = new Matrix(); rotation.RotateAt(angle, pivot); rotation.TransformPoints(points); rotation.Dispose(); }
internal static float ConvertSweepAngle(float sweepAngle, float startAngle, SpatialTransform transform, CoordinateSystem targetSystem) { PointF x = new PointF(100, 0); PointF[] startVector = new PointF[] { x }; Matrix rotation = new Matrix(); rotation.Rotate(startAngle); rotation.TransformVectors(startVector); PointF[] sweepVector = (PointF[])startVector.Clone(); rotation.Reset(); rotation.Rotate(sweepAngle); rotation.TransformVectors(sweepVector); rotation.Dispose(); SizeF startVectorTransformed, sweepVectorTransformed; if (targetSystem == Graphics.CoordinateSystem.Destination) { startVectorTransformed = transform.ConvertToDestination(new SizeF(startVector[0])); sweepVectorTransformed = transform.ConvertToDestination(new SizeF(sweepVector[0])); } else { startVectorTransformed = transform.ConvertToSource(new SizeF(startVector[0])); sweepVectorTransformed = transform.ConvertToSource(new SizeF(sweepVector[0])); } // simply return the angle between the start and sweep angle, in the target system. return (int)Math.Round(Vector.SubtendedAngle(sweepVectorTransformed.ToPointF(), PointF.Empty, startVectorTransformed.ToPointF())); }
internal static PointF rotatePointAt(PointF point, PointF pivot, float angle) { PointF[] points = new PointF[] { point }; Matrix rotation = new Matrix(); rotation.RotateAt(angle, pivot); rotation.TransformPoints(points); rotation.Dispose(); return points[0]; }
/// <summary> /// Translates coordinates of the Graphics path applying rotation if it's necessary /// </summary> /// <param name="Rotation">Rotation angle</param> /// <param name="RotationPoint">Point of the rotation ( used if RA is not 0)</param> /// <param name="WCS2UCS">if true then translate from UCS to WCS </param> /// <param name="gr">GraphicsPath to be processed</param> /// <returns>true if succesfull otherwise false</returns> public bool TranslateCoords(float Rotation, PointF RotationPoint, bool WCS2UCS, ref GraphicsPath gr) { bool bOk = false; try { Matrix mtxTrans = new Matrix(); if ( WCS2UCS ) { mtxTrans.Translate(0, m_FlowChart.DocExtents.Height); mtxTrans.Scale(1,-1); } if ( Rotation!= 0 ) { mtxTrans.RotateAt((-1)*Rotation, RotationPoint ); } gr.Transform(mtxTrans); //gr.Flatten(); mtxTrans.Dispose(); bOk = true; } catch ( Exception ex) { Trace.WriteLine(String.Format("{0} error {1}\n","TranslateCoords",ex.Message)); bOk = false; } return bOk; }
/// <summary> /// Return an image that is the rotated version of the given image. Rotation is /// at 'angle' via 'center'. New image is the same size as the rotated image /// </summary> /// <param name="angle"></param> /// <param name="center"></param> /// <returns></returns> public static Image RotateImage(Image source, float angle, PointF center) { // create new image Image newImage = CreateImage(source.Width, source.Height, PixelFormat.Format32bppPArgb, Color.Transparent); // get graphics surface Graphics g = Graphics.FromImage(newImage); // use high quality resampling g.SmoothingMode = SmoothingMode.HighQuality; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.PixelOffsetMode = PixelOffsetMode.HighQuality; // setup transform matrix Matrix rm = new Matrix(); rm.RotateAt(angle, center, MatrixOrder.Append); // insert transform into graphics g.Transform = rm; // draw image g.DrawImage(source, center.X - (float)source.Width / 2.0f, center.Y - (float)source.Height / 2); // dispose locals g.Dispose(); rm.Dispose(); // return new image return newImage; }
public MatrixComponents GetMatrixComponents() { System.Drawing.Drawing2D.Matrix srcMatrix = new System.Drawing.Drawing2D.Matrix( this.ScaleX, this.Rotate0, this.Rotate1, this.ScaleY, this.TranslateX, this.TranslateY); System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix(1, 0, 0, 1, 0, 0); // identity // an 'identity' box PointF[] modPts = new PointF[] { new PointF(0, 0), new PointF(1, 0), new PointF(1, 1), new PointF(0, 1) }; float sx, sy, rot, shear, tx, ty; srcMatrix.TransformPoints(modPts); // translation tx = srcMatrix.OffsetX; ty = srcMatrix.OffsetY; m.Translate(-tx, -ty); m.TransformPoints(modPts); m.Reset(); // rotation rot = (float)Math.Atan2(modPts[1].Y, modPts[1].X); // x axis rot = (float)(rot / Math.PI * 180); if (rot == -0) { rot = 0; } if (rot == -180) { rot = 180; } m.Rotate(-1 * rot); m.TransformPoints(modPts); m.Reset(); // scale //sx = Dist(modPts[0], modPts[3]); // bug it seems..? sx = Dist(modPts[0], modPts[1]); sy = Dist(modPts[0], new PointF(0, modPts[3].Y)); if (modPts[0].Y > modPts[3].Y) { sy *= -1; } m.Scale(1 / sx, 1 / sy); m.TransformPoints(modPts); m.Reset(); // skew // ySkew is impossible at this rotation shear = modPts[3].X / Dist(modPts[0], modPts[1]); // rounding shear = Math.Abs(shear) < 0.001 ? 0 : shear; m.Shear(-shear, 0); m.TransformPoints(modPts); m.Dispose(); srcMatrix.Dispose(); return(new MatrixComponents(sx, sy, rot, shear, tx, ty)); }
/// <summary> /// Warp the provided text GraphicsPath by a variable amount /// </summary> private void WarpText(GraphicsPath textPath, Rectangle rectangle) { float WarpDivisor; float RangeModifier; switch (FontWarp) { case FontWarpFactor.None: return; case FontWarpFactor.Low: WarpDivisor = 6f; RangeModifier = 1f; break; case FontWarpFactor.Medium: WarpDivisor = 5f; RangeModifier = 1.3f; break; case FontWarpFactor.High: WarpDivisor = 4.5f; RangeModifier = 1.4f; break; default: WarpDivisor = 4f; RangeModifier = 1.5f; break; } RectangleF rectangleF; rectangleF = new RectangleF(Convert.ToSingle(rectangle.Left), 0, Convert.ToSingle(rectangle.Width), rectangle.Height); int HeightRange = Convert.ToInt32(rectangle.Height / WarpDivisor); int WidthRange = Convert.ToInt32(rectangle.Width / WarpDivisor); int Left = rectangle.Left - Convert.ToInt32(WidthRange * RangeModifier); int Top = rectangle.Top - Convert.ToInt32(HeightRange * RangeModifier); int Width = rectangle.Left + rectangle.Width + Convert.ToInt32(WidthRange * RangeModifier); int Height = rectangle.Top + rectangle.Height + Convert.ToInt32(HeightRange * RangeModifier); if (Left < 0) { Left = 0; } if (Top < 0) { Top = 0; } if (Width > this.Width) { Width = this.Width; } if (Height > this.Height) { Height = this.Height; } PointF LeftTop = RandomPoint(Left, Left + WidthRange, Top, Top + HeightRange); PointF RightTop = RandomPoint(Width - WidthRange, Width, Top, Top + HeightRange); PointF LeftBottom = RandomPoint(Left, Left + WidthRange, Height - HeightRange, Height); PointF RightBottom = RandomPoint(Width - WidthRange, Width, Height - HeightRange, Height); PointF[] Points = { LeftTop, RightTop, LeftBottom, RightBottom }; Matrix matrix = new Matrix(); matrix.Translate(0, 0); textPath.Warp(Points, rectangleF, matrix, WarpMode.Perspective, 0); matrix.Dispose(); }