/// <summary> /// Create a new ExtendedScrollBar. /// </summary> public ExtendedScrollBar() { // This call is required by the Windows.Forms Form Designer. InitializeComponent(); this.hScrollBar.SmallChange = 10; this.hScrollBar.LargeChange = 100; this.scrollAmount = this.hScrollBar.SmallChange; this.autoscrollTimer.Interval = 100; this.buttonMode = ExtendedScrollBarButtonMode.PlaySymbols; // create left play symbol this.leftPlayRegion = new Region(); this.leftPlayRegion.MakeEmpty(); this.leftPlayRegion.Union(new Rectangle(1, 4, 1, 1)); this.leftPlayRegion.Union(new Rectangle(2, 3, 1, 3)); this.leftPlayRegion.Union(new Rectangle(3, 2, 1, 5)); this.leftPlayRegion.Union(new Rectangle(4, 1, 1, 7)); this.leftPlayRegion.Union(new Rectangle(5, 0, 2, 9)); // create right play symbol this.rightPlayRegion = this.leftPlayRegion.Clone(); System.Drawing.Drawing2D.Matrix matrixTransform = new System.Drawing.Drawing2D.Matrix(); matrixTransform.RotateAt(45, new Point(4, 4)); matrixTransform.RotateAt(45, new Point(5, 5)); matrixTransform.RotateAt(45, new Point(4, 4)); matrixTransform.RotateAt(45, new Point(4, 4)); this.rightPlayRegion.Transform(matrixTransform); // create stop symbol this.stopRegion = new Region(); this.stopRegion.MakeEmpty(); this.stopRegion.Union(new Rectangle(1, 0, 1, 1)); this.stopRegion.Union(new Rectangle(7, 0, 1, 1)); this.stopRegion.Union(new Rectangle(0, 1, 3, 1)); this.stopRegion.Union(new Rectangle(6, 1, 3, 1)); this.stopRegion.Union(new Rectangle(1, 2, 3, 1)); this.stopRegion.Union(new Rectangle(5, 2, 3, 1)); this.stopRegion.Union(new Rectangle(2, 3, 5, 1)); this.stopRegion.Union(new Rectangle(3, 4, 3, 1)); this.stopRegion.Union(new Rectangle(2, 5, 5, 1)); this.stopRegion.Union(new Rectangle(5, 6, 3, 1)); this.stopRegion.Union(new Rectangle(1, 6, 3, 1)); this.stopRegion.Union(new Rectangle(6, 7, 3, 1)); this.stopRegion.Union(new Rectangle(0, 7, 3, 1)); this.stopRegion.Union(new Rectangle(7, 8, 1, 1)); this.stopRegion.Union(new Rectangle(1, 8, 1, 1)); this.CreateBitmaps(); }
private void DrawRotatedMeasureText(int gridSize, Graphics g, double degrees) { string text = string.Format("{0} {1}", (double)(Math.Round(Length * ConversionRate, 1)), Unit); SizeF textSize = g.MeasureString(text, measureFont); // Calculate the middle part of the segment Point start, end; start = Start.ToPoint(gridSize); end = End.ToPoint(gridSize); PointF middlePoint = new PointF((start.X + end.X) / 2f, (start.Y + end.Y) / 2f); // we should find the middle of the segment and rotate based on that // at that point, we can easily translate it to not overlap the line using (System.Drawing.Drawing2D.Matrix transformMatrix = new System.Drawing.Drawing2D.Matrix()) { // we rotate the text to match the slope of the line. transformMatrix.RotateAt((float)degrees, middlePoint); // translate by half the width transformMatrix.Translate(-textSize.Width / 2, 0); // if we want to put the text above the line, we need to translate the height as well. if ((Location & MeasurementLocation.Above) == MeasurementLocation.Above) { transformMatrix.Translate(0, -textSize.Height); } g.Transform = transformMatrix; g.DrawString(text, measureFont, new SolidBrush(Color), middlePoint); g.ResetTransform(); } }
public override bool HitTest(System.Drawing.Point pt) { System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.Drawing2D.Matrix myMatrix = new System.Drawing.Drawing2D.Matrix(); System.Drawing.Pen myPen = new System.Drawing.Pen(this.m_lineColor, (float)this.m_lineWidth + 2); float X = (float)this.X; float Y = (float)this.Y; if (this.m_BondType == ChemInfo.BondType.Single) { gp.AddLine(X, Y, X + m_Size.Width, Y + m_Size.Height); } if (this.m_BondType == ChemInfo.BondType.Double) { gp.AddLine(X + m_OffsetX, Y + m_OffsetY, X + m_Size.Width + m_OffsetX, Y + m_Size.Height + m_OffsetY); gp.AddLine(X - m_OffsetX, Y - m_OffsetY, X + m_Size.Width - m_OffsetX, Y + m_Size.Height - m_OffsetY); } if (this.m_BondType == ChemInfo.BondType.Triple) { gp.AddLine(X + m_OffsetX, Y + m_OffsetY, X + m_Size.Width + m_OffsetX, Y + m_Size.Height + m_OffsetY); gp.AddLine(X, Y, X + m_Size.Width, Y + m_Size.Height); gp.AddLine(X - m_OffsetX, Y - m_OffsetY, X + m_Size.Width - m_OffsetX, Y + m_Size.Height - m_OffsetY); } myMatrix.RotateAt((float)this.m_Rotation, new System.Drawing.PointF(X, Y), System.Drawing.Drawing2D.MatrixOrder.Append); gp.Transform(myMatrix); return(gp.IsOutlineVisible(pt, myPen)); }
public override void Draw(System.Drawing.Graphics g) { System.Drawing.Drawing2D.GraphicsContainer gContainer = g.BeginContainer(); System.Drawing.Drawing2D.Matrix myMatrix = g.Transform; this.DetermineOffset(); float X = (float)this.m_parentAtom.X; float Y = (float)this.m_parentAtom.Y; if (m_Rotation != 0) { myMatrix.RotateAt((float)(m_Rotation), new System.Drawing.PointF(X, Y), System.Drawing.Drawing2D.MatrixOrder.Append); g.Transform = myMatrix; } System.Drawing.Pen myPen = new System.Drawing.Pen(m_lineColor, (float)m_lineWidth); if (this.m_BondType == ChemInfo.BondType.Single || this.m_BondType == ChemInfo.BondType.Aromatic) { g.DrawLine(myPen, X, Y, m_connectedAtom.X, m_connectedAtom.Y); } if (this.m_BondType == ChemInfo.BondType.Double) { g.DrawLine(myPen, X + m_OffsetX, Y + m_OffsetY, m_connectedAtom.X + m_OffsetX, m_connectedAtom.Y + m_OffsetY); g.DrawLine(myPen, X - m_OffsetX, Y - m_OffsetY, m_connectedAtom.X - m_OffsetX, m_connectedAtom.Y - m_OffsetY); } if (this.m_BondType == ChemInfo.BondType.Triple) { g.DrawLine(myPen, X + m_OffsetX, Y + m_OffsetY, m_connectedAtom.X + m_OffsetX, m_connectedAtom.Y + m_OffsetY); g.DrawLine(myPen, X, Y, m_connectedAtom.X, m_connectedAtom.Y); g.DrawLine(myPen, X - m_OffsetX, Y - m_OffsetY, m_connectedAtom.X - m_OffsetX, m_connectedAtom.Y - m_OffsetY); } g.EndContainer(gContainer); }
/// <summary> /// Draws the background of the collapsed band /// </summary> /// <param name="g">The canvas to draw on</param> /// <param name="bounds">The bounds of the drawing</param> /// <param name="text">The text that should appear into the bar</param> /// <param name="font">The font to use when drawing the text</param> /// <param name="rightToLeft">if set to <c>true</c> [right to left].</param> /// <param name="state">The inputstate of the collapsed band</param> public override void DrawCollapsedBand(Graphics g, Rectangle bounds, string text, Font font, bool rightToLeft, InputState state) { // TODO Right to left using (SolidBrush b = new SolidBrush(colorTable.BandCollapsedBg)) { if (state == InputState.Hovered) { b.Color = colorTable.BandCollapsedFocused; } else if (state == InputState.Clicked) { b.Color = colorTable.BandCollapsedClicked; } g.FillRectangle(b, bounds); } // inner border using (Pen p = new Pen(colorTable.DarkBorder)) { g.DrawLine(p, new Point(bounds.Left, bounds.Top), new Point(bounds.Right, bounds.Top)); p.Color = colorTable.HeaderBgInnerBorder; if (state == InputState.Normal) { g.DrawLine(p, new Point(bounds.Left, bounds.Top + 1), new Point(bounds.Right, bounds.Top + 1)); g.DrawLine(p, new Point(bounds.Left, bounds.Top + 1), new Point(bounds.Left, bounds.Bottom)); } } using (Brush brush = new SolidBrush(colorTable.Text)) { if (rightToLeft) { Point ptCenter = new Point(bounds.X + bounds.Width / 2 + 7, bounds.Y + bounds.Height / 2); System.Drawing.Drawing2D.Matrix transform = g.Transform; transform.RotateAt(90, ptCenter); g.Transform = transform; using (StringFormat format = new StringFormat()) { format.FormatFlags |= StringFormatFlags.DirectionRightToLeft; g.DrawString(text, font, brush, ptCenter, format); } } else { Point ptCenter = new Point(bounds.X + bounds.Width / 2 - 7, bounds.Y + bounds.Height / 2); System.Drawing.Drawing2D.Matrix transform = g.Transform; transform.RotateAt(270, ptCenter); g.Transform = transform; g.DrawString(text, font, brush, ptCenter); } } }
public override void Draw(Tekening tek, Graphics gr, bool widepen, bool fill) { PointF loc; SizeF afm; float hoek; CalcEllipsWaarden(f1.Coordinaat, f2.Coordinaat, p.Coordinaat, out loc, out afm, out hoek); #region Assenstelsel draaien System.Drawing.Drawing2D.Matrix oudematrix = gr.Transform; System.Drawing.Drawing2D.Matrix transform = new System.Drawing.Drawing2D.Matrix(); transform.RotateAt((float)(hoek * 180 / Math.PI), tek.Offset); gr.Transform = transform; #endregion PointF loc2 = tek.co_pt(loc, gr.DpiX, gr.DpiY); if (fill) { gr.DrawFillEllipse(GetPen(false), GetBrush(gr, tek.Schaal, tek.Offset, false), loc2.X, loc2.Y, afm.Width * tek.Schaal / 2.54f * gr.DpiX, afm.Height * tek.Schaal / 2.54f * gr.DpiY); } else { gr.DrawEllipse(GetPen(false), loc2.X, loc2.Y, afm.Width * tek.Schaal / 2.54f * gr.DpiX, afm.Height * tek.Schaal / 2.54f * gr.DpiY); } #region Assenstelsel herstellen gr.Transform = oudematrix; #endregion }
void Draw(System.Drawing.Graphics g, System.Drawing.Drawing2D.AdjustableArrowCap customStartCap, System.Drawing.Drawing2D.AdjustableArrowCap customEndCap) { System.Drawing.Drawing2D.GraphicsContainer gContainer = g.BeginContainer(); System.Drawing.Drawing2D.Matrix myMatrix = g.Transform; float X = (float)this.X; float Y = (float)this.Y; if (m_Rotation != 0) { myMatrix.RotateAt((float)m_Rotation, new System.Drawing.PointF(X, Y), System.Drawing.Drawing2D.MatrixOrder.Append); g.Transform = myMatrix; } System.Drawing.Pen myPen = new System.Drawing.Pen(m_lineColor, (float)m_lineWidth); // put startcaps and endcaps on lines if (customStartCap != null) { myPen.CustomStartCap = customStartCap; } if (customEndCap != null) { myPen.CustomEndCap = customEndCap; } g.DrawLine(myPen, X, Y, X + m_Size.Width, Y + m_Size.Height); g.EndContainer(gContainer); }
public override void ApplyTransformation(System.Drawing.Drawing2D.Matrix transform) { if (fromAngle == toAngle) { curAngle = toAngle; } else { if (fromAngle < toAngle) { curAngle += CHANGE_VALUE; if (curAngle >= toAngle) { curAngle = toAngle; } } else { curAngle -= CHANGE_VALUE; if (curAngle <= toAngle) { curAngle = toAngle; } } } transform.Reset(); transform.RotateAt(curAngle, pivotPoint); }
public HoverForm() { Opacity = 0.6; size = 1; InitializeComponent(); this.fieldButton1.BackColor = Color.WhiteSmoke; this.fieldButton1.Click += fieldButton1_Click; this.fieldButton1.drawCenterX = 50; this.fieldButton1.drawCenterY = 43; for (int i = 0; i < Game.MAXBUILDINGSIZE; i++) { FieldButton f = new FieldButton(); f.BackColor = Color.WhiteSmoke; f.Parent = this; f.Name = "extraButton_" + i; f.Size = new Size(fieldButton1.Width, fieldButton1.Height); f.Click += fieldButton1_Click; f.MouseMove += HoverForm_MouseMove; this.extraButtons.Add(f); this.Controls.Add(f); } this.fieldButton1.MouseMove += HoverForm_MouseMove; rotMatrix = new System.Drawing.Drawing2D.Matrix(); rotMatrix.RotateAt(180, new PointF(fieldButton1.drawCenterX, fieldButton1.drawCenterY)); }
internal static SharpMap.Map InitializeMap(float angle, string[] filenames) { var map = new SharpMap.Map(); try { foreach (var filename in filenames) { var connectionString = string.Format("Data Source={0}", filename); foreach (var provider in SharpMap.Data.Providers.SpatiaLite.GetSpatialTables(connectionString)) { map.Layers.Add( new SharpMap.Layers.VectorLayer( string.Format("{0} - {1}", provider.Table, provider.GeometryColumn), provider) { Style = LayerTools.GetRandomVectorStyle() }); } } if (map.Layers.Count > 0) { map.ZoomToExtents(); System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix(); mat.RotateAt(angle, map.WorldToImage(map.Center)); map.MapTransform = mat; return(map); } } catch (System.Exception ex) { System.Diagnostics.Trace.WriteLine(ex.Message); } return(null); }
public override void Draw(System.Drawing.Graphics g) { System.Drawing.StringFormat format = new System.Drawing.StringFormat(); format.Alignment = this.m_HorizontalAlignment; format.LineAlignment = this.m_VerticalAlignment; System.Drawing.Drawing2D.GraphicsContainer gContainer = g.BeginContainer(); System.Drawing.Drawing2D.Matrix myMatrix = g.Transform; float X = (float)this.X; float Y = (float)this.Y; if (m_Rotation != 0) { myMatrix.RotateAt((float)(m_Rotation), new System.Drawing.PointF(X, Y), System.Drawing.Drawing2D.MatrixOrder.Append); g.Transform = myMatrix; } if (m_AutoSize) { System.Drawing.SizeF mySize = g.MeasureString(m_Text, m_Font); m_Size.Width = (int)mySize.Width; m_Size.Height = (int)mySize.Height; g.DrawString(m_Text, m_Font, new System.Drawing.SolidBrush(m_Color), X, Y, format); } else { System.Drawing.RectangleF rect = new System.Drawing.RectangleF(X, Y, (float)m_Size.Width, (float)m_Size.Height); g.DrawString(m_Text, m_Font, new System.Drawing.SolidBrush(m_Color), rect, format); } g.EndContainer(gContainer); }
public override void Draw(Tekening tek, Graphics gr, PointF loc_co, Vorm[] ref_vormen) { if ((f1 == null) | (f2 == null)) { return; } PointF loc; SizeF afm; float hoek; CalcEllipsWaarden(f1.Coordinaat, f2.Coordinaat, loc_co, out loc, out afm, out hoek); #region Assenstelsel draaien System.Drawing.Drawing2D.Matrix oudematrix = gr.Transform; System.Drawing.Drawing2D.Matrix transform = new System.Drawing.Drawing2D.Matrix(); transform.RotateAt((float)(hoek * 180 / Math.PI), tek.Offset); gr.Transform = transform; #endregion PointF loc2 = tek.co_pt(loc, gr.DpiX, gr.DpiY); gr.DrawFillEllipse(GetPen(false), GetBrush(gr, tek.Schaal, new PointF(), false), loc2.X, loc2.Y, afm.Width * tek.Schaal / 2.54f * gr.DpiX, afm.Height * tek.Schaal / 2.54f * gr.DpiY); #region Assenstelsel herstellen gr.Transform = oudematrix; #endregion }
public List <Point> ToPoints( float angle, Rectangle rect) { // Graphics g = Graphics.FromImage(this.Image); Graphics g = Graphics.FromHwnd(this.Handle); List <Point> source_points = new List <Point>(); source_points.Add(new Point(rect.X, rect.Y)); source_points.Add(new Point(rect.X + rect.Width, rect.Y)); source_points.Add(new Point(rect.X + rect.Width, rect.Y + rect.Height)); source_points.Add(new Point(rect.X, rect.Y + rect.Height)); Point[] pts = source_points.ToArray(); Rectangle display_rect = GetPictureBoxZoomSize(); float x_ratio = (float)display_rect.Width / (float)this.Image.Width; float y_ratio = (float)display_rect.Height / (float)this.Image.Height; System.Drawing.Drawing2D.Matrix rotateMatrix = new System.Drawing.Drawing2D.Matrix(); // Set the rotation angle and starting point for the text. rotateMatrix.RotateAt(angle, new PointF(this.Image.Width / 2, this.Image.Height / 2)); //rotateMatrix.RotateAt(angle, new PointF(0, 0)); g.MultiplyTransform(rotateMatrix); // g.ScaleTransform(x_ratio, y_ratio); // g.ScaleTransform((float)1.1, (float)1.1); // g.RotateTransform(angle); g.TransformPoints(System.Drawing.Drawing2D.CoordinateSpace.World, System.Drawing.Drawing2D.CoordinateSpace.Device, pts); return(pts.ToList()); }
private static SharpMap.Map InitializeVRT(ref int index, float angle) { SharpMap.Map map = new SharpMap.Map(); int ind = index - 6; if (ind >= Vrts.Length) { ind = 0; } if (!System.IO.File.Exists(RelativePath + Vrts[ind])) { throw new System.Exception("Make sure the data is in the relative directory: " + RelativePath); } SharpMap.Layers.GdalRasterLayer layer = new SharpMap.Layers.GdalRasterLayer("VirtualRasterTable", RelativePath + Vrts[ind]); var ext = System.IO.Path.GetExtension(layer.Filename); map.Layers.Add(layer); _gdalSampleDataset = string.Format("'{0}'", ext != null ? ext.ToUpper() : string.Empty); map.ZoomToExtents(); System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix(); mat.RotateAt(angle, map.WorldToImage(map.Center)); map.MapTransform = mat; //index++; return(map); }
public override void ApplyTransformation(System.Drawing.Drawing2D.Matrix transform) { if (angle == 0) { transform.Reset(); return; } if (right2Left) { curAngle -= CHANGE_VALUE; if (curAngle <= -angle) { curAngle = -angle; right2Left = false; } } else { curAngle += CHANGE_VALUE; if (curAngle >= angle) { curAngle = angle; right2Left = true; repeatCount++; } } transform.Reset(); transform.RotateAt(curAngle, curAngle >= 0 ? rightPivot : leftPivot); }
public override void ApplyTransformation(System.Drawing.Drawing2D.Matrix transform) { if (toX == fromX) { curX = toX; } else if (fromX < toX) { curX += CHANGE_VALUE; if (curX >= toX) { curX = toX; } } else { curX -= CHANGE_VALUE; if (curX <= toX) { curX = toX; } } transform.Reset(); transform.Translate(curX - fromX, 0); transform.RotateAt(-GetRotateAngle(curX), pivot); }
public List <Point> ToPoints( float angle, Rectangle rect) { // Create a GraphicsPath. System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddRectangle(rect); // Declare a matrix that will be used to rotate the text. System.Drawing.Drawing2D.Matrix rotateMatrix = new System.Drawing.Drawing2D.Matrix(); // Set the rotation angle and starting point for the text. rotateMatrix.RotateAt(180.0F, new PointF(10.0F, 100.0F)); // Transform the text with the matrix. path.Transform(rotateMatrix); List <Point> results = new List <Point>(); foreach (PointF p in path.PathPoints) { results.Add(new Point((int)p.X, (int)p.Y)); } path.Dispose(); return(results); }
private Map GetMap(int srid, Coordinate center, float mapRotationDeg) { var map = new Map(new Size(800, 640)); map.SRID = srid; map.Center = center; map.BackColor = Color.BlanchedAlmond; if (!mapRotationDeg.Equals(0f)) { var matrix = new System.Drawing.Drawing2D.Matrix(); matrix.RotateAt(mapRotationDeg, new PointF(map.Size.Width * 0.5f, map.Size.Height * 0.5f)); map.MapTransform = matrix; } map.Decorations.Add(new SharpMap.Rendering.Decoration.Graticule.Graticule { GcsGraticuleStyle = { PrimaryLineStyle = GraticuleLineStyle.SolidTick } }); map.Decorations.Add(new EyeOfSight()); map.Disclaimer = "FEATURE LAYER DOTS SHOULD COINCIDE WITH GRATICULE TICKS"; return(map); }
public static Image RotateImage(Image inputImg, double degreeAngle) { //Corners of the image PointF[] rotationPoints = { new PointF(0, 0), new PointF(inputImg.Width, 0), new PointF(0, inputImg.Height), new PointF(inputImg.Width, inputImg.Height) }; //Rotate the corners PointMath.RotatePoints(rotationPoints, new PointF(inputImg.Width / 2.0f, inputImg.Height / 2.0f), degreeAngle); //Get the new bounds given from the rotation of the corners //(avoid clipping of the image) Rectangle bounds = PointMath.GetBounds(rotationPoints); //An empy bitmap to draw the rotated image Bitmap rotatedBitmap = new Bitmap(bounds.Width, bounds.Height); using (Graphics g = Graphics.FromImage(rotatedBitmap)) { g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; //Transformation matrix System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix(); m.RotateAt((float)degreeAngle, new PointF(inputImg.Width / 2.0f, inputImg.Height / 2.0f)); m.Translate(-bounds.Left, -bounds.Top, System.Drawing.Drawing2D.MatrixOrder.Append); //shift to compensate for the rotation g.Transform = m; g.DrawImage(inputImg, 0, 0); } return((Image)rotatedBitmap); }
public static SharpMap.Map InitializeMap(float angle) { using (var ofn = new System.Windows.Forms.OpenFileDialog()) { ofn.Filter = "All files|*.*"; ofn.FilterIndex = 0; if (ofn.ShowDialog() == System.Windows.Forms.DialogResult.OK) { var m = new SharpMap.Map(); var l = new SharpMap.Layers.GdiImageLayer(ofn.FileName); m.Layers.Add(l); m.ZoomToExtents(); var mat = new System.Drawing.Drawing2D.Matrix(); mat.RotateAt(angle, m.WorldToImage(m.Center)); m.MapTransform = mat; m.MaximumExtents = m.GetExtents(); m.EnforceMaximumExtents = true; return(m); } } return(null); }
private static void CreateRotatedFillInBackground(Shape shape, Bitmap slideImage, double magnifyRatio = 1.0) { PPShape rotatedShape = new PPShape(shape, false); PointF topLeftPoint = new PointF(rotatedShape.ActualTopLeft.X * GraphicsUtil.PictureExportingRatio, rotatedShape.ActualTopLeft.Y * GraphicsUtil.PictureExportingRatio); Bitmap rotatedImage = new Bitmap(slideImage.Width, slideImage.Height); using (Graphics g = Graphics.FromImage(rotatedImage)) { g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; using (System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix()) { mat.Translate(-topLeftPoint.X, -topLeftPoint.Y); mat.RotateAt(-shape.Rotation, topLeftPoint); g.Transform = mat; g.DrawImage(slideImage, new Rectangle(0, 0, slideImage.Width, slideImage.Height)); } } Bitmap magnifiedImage = KiCut(rotatedImage, 0, 0, shape.Width * GraphicsUtil.PictureExportingRatio, shape.Height * GraphicsUtil.PictureExportingRatio, magnifyRatio); magnifiedImage.Save(FillInBackgroundPicture, ImageFormat.Png); }
/// <summary> Rotates the current transformation around the given /// pivot point by the given angle. /// /// </summary> /// <param name="angle">rotation in degrees. /// </param> /// <param name="pivotX">x coordinate of the pivot point. /// </param> /// <param name="pivotY">y coordinate of the pivot point. /// </param> public virtual void Rotate(double angle, double pivotX, double pivotY) { System.Drawing.Drawing2D.Matrix temp_Matrix; temp_Matrix = new System.Drawing.Drawing2D.Matrix(); temp_Matrix.RotateAt((float)(SupportClass.DegreesToRadians(angle) * (180 / System.Math.PI)), new System.Drawing.PointF((float)pivotX, (float)pivotY)); transform(temp_Matrix); }
// Graphics methods //chuck's new code 2/20/04 //this method indicates whether point is along outline of graphic //and if so, what type of cursor should show public virtual void BoundaryTest(System.Drawing.Point pt, SizeDirection dir) { System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.Drawing2D.Matrix myMatrix = new System.Drawing.Drawing2D.Matrix(); System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Black, 3); gp.AddRectangle(new System.Drawing.Rectangle(this.m_Position.X - 3, this.m_Position.Y - 3, this.m_Size.Width + 6, this.m_Size.Height + 6)); if (this.m_Rotation != 0) { myMatrix.RotateAt((float)this.m_Rotation, new System.Drawing.PointF((float)this.X, (float)this.Y), System.Drawing.Drawing2D.MatrixOrder.Append); } gp.Transform(myMatrix); dir = SizeDirection.NA; if (gp.IsOutlineVisible(pt, pen)) { //user has placed the mouse along the outline of the selected //object - change the mouse to allow for resizing System.Drawing.RectangleF rect = gp.GetBounds(); if (Math.Abs((int)rect.Left - pt.X) <= 2) { if (Math.Abs((int)rect.Top - pt.Y) <= 2) { dir = SizeDirection.Northwest; } else if (Math.Abs((int)rect.Bottom - pt.Y) <= 2) { dir = SizeDirection.Southwest; } else { dir = SizeDirection.West; } } else if (Math.Abs((int)rect.Right - pt.X) <= 2) { if (Math.Abs((int)rect.Top - pt.Y) <= 2) { dir = SizeDirection.Northeast; } else if (Math.Abs((int)rect.Bottom - pt.Y) <= 2) { dir = SizeDirection.Southeast; } else { dir = SizeDirection.East; } } else if (Math.Abs((int)rect.Top - pt.Y) <= 2) { dir = SizeDirection.North; } else { dir = SizeDirection.South; } } }
public void rotatePoint(PointF centerpoint, float angle, ref PointF dstpoint) { System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix(); mat.RotateAt(angle, centerpoint); PointF[] arraypoints = new PointF[1]; arraypoints[0] = dstpoint; mat.TransformPoints(arraypoints); dstpoint = arraypoints[0]; }
//根据验证字符串生成最终图象 public void CreateImage(string str_ValidateCode) { //int int_ImageWidth = str_ValidateCode.Length * 13; //int width = int_ImageWidth; int int_ImageWidth = this.Width; int width = int_ImageWidth; int height = this.Height; string filePath = Server.MapPath(imgDir); Bitmap bgImg = (Bitmap)Bitmap.FromFile(GetRandomFile(filePath)); Random newRandom = new Random(); // 图高20px Bitmap theBitmap = new Bitmap(width, height); Graphics theGraphics = Graphics.FromImage(theBitmap); theGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; theGraphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; theGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; theGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; // 白色背景 //theGraphics.Clear(Color.White); theGraphics.DrawImage(bgImg, new Rectangle(0, 0, width, height), new Rectangle(0, 0, bgImg.Width, bgImg.Height), GraphicsUnit.Pixel); // 灰色边框 //theGraphics.DrawRectangle(new Pen(Color.LightGray, 1), 0, 0, int_ImageWidth - 1, height - 1); //13pt的字体 float fontSize = this.Height * 1.0f / 1.38f; float fontSpace = fontSize / 7f; Font theFont = new Font("Arial", fontSize); System.Drawing.Drawing2D.GraphicsPath gp = null; System.Drawing.Drawing2D.Matrix matrix; for (int int_index = 0; int_index < str_ValidateCode.Length; int_index++) { string str_char = str_ValidateCode.Substring(int_index, 1); Brush newBrush = new SolidBrush(GetRandomColor()); Point thePos = new Point((int)(int_index * (fontSize + fontSpace) + newRandom.Next(3)), 1 + newRandom.Next(3)); gp = new System.Drawing.Drawing2D.GraphicsPath(); gp.AddString(str_char, theFont.FontFamily, 0, fontSize, thePos, new StringFormat()); matrix = new System.Drawing.Drawing2D.Matrix(); int angle = GetRandomAngle(); PointF centerPoint = new PointF(thePos.X + fontSize / 2, thePos.Y + fontSize / 2); matrix.RotateAt(angle, centerPoint); theGraphics.Transform = matrix; theGraphics.DrawPath(new Pen(Color.White, 2f), gp); //theGraphics.FillPath(new SolidBrush(Color.Black), gp); theGraphics.FillPath(new SolidBrush(GetRandomColor()), gp); theGraphics.ResetTransform(); } if (gp != null) gp.Dispose(); // 将生成的图片发回客户端 MemoryStream ms = new MemoryStream(); theBitmap.Save(ms, ImageFormat.Png); Response.ClearContent(); //需要输出图象信息 要修改HTTP头 Response.ContentType = "image/gif"; Response.BinaryWrite(ms.ToArray()); theGraphics.Dispose(); theBitmap.Dispose(); Response.End(); }
// ******************** ROTATION OF RECTANGLE SECTION ******************** private void num_angle_ValueChanged(object sender, EventArgs e) // If the user changes the angle either by clicking up down, typing new angle, or using scroll wheel, the rectangle is redrawn with that angle { var width = Math.Abs(global.input[2] - global.input[0]); // Defining width and height the same way as earlier var height = Math.Abs(global.input[3] - global.input[1]); rec = new Rectangle(global.input[0], global.input[1], width, height); img_rectangle = image_Original.CreateGraphics(); string angle = num_angle.Text; // Angle by which rectangle should be rotated is stored in textbox and accessed later double theta = Convert.ToDouble(angle); theta = (double)(theta * (Math.PI / 180)); //Converting the angle to radians so it can be used by sine/cosine functions later on int centerx = global.input[0] + ((global.input[2] - global.input[0]) / 2); //The center of the rectangle in the x-direction int centery = global.input[1] + ((global.input[3] - global.input[1]) / 2); //The center of the rectangle in the y-direction System.Drawing.Drawing2D.Matrix rotateMatrix = new System.Drawing.Drawing2D.Matrix(); // Creating the rotation matrix rotateMatrix.RotateAt(int.Parse(angle), new PointF(centerx, centery)); //Telling matrix the angle by which it should be rotated and that it should be rotated about the center point of the rectangle img_rectangle.Transform = rotateMatrix; // // Transforming the rectangle -- giving it the same angle as the matrix img_rectangle.Clear(Color.Black); //Cleared so all past instances of the rectangle are no longer on screen Graphics img_rectangle2 = image_Original.CreateGraphics(); // Making another variable so the image is not rotated with the rectangle var image = Image.FromFile(lbl_fileName.Text); //Finding location of uploaded image again from text Rectangle PictureboxRectangle = new Rectangle(0, 0, image_Original.Width, image_Original.Height); //Makes sure that the image will take up the whole picturebox space img_rectangle2.DrawImage(image, PictureboxRectangle); //Drawing the uploaded image again Pen redPen = new Pen(Color.Red, 2); img_rectangle.DrawRectangle(redPen, rec); //Drawing rectangle on the picturebox image.Dispose(); //Dispose image each time so it doesn't use too much memory int x1 = (int)(centerx - ((width / 2 * Math.Cos(theta)) - ((height / 2) * Math.Sin(theta)))); //Top left x value after rotation int y1 = (int)(centery - ((width / 2 * Math.Sin(theta)) + ((height / 2) * Math.Cos(theta)))); //Top left y value after rotation int x2 = (int)(centerx + ((width / 2 * Math.Cos(theta)) + ((height / 2) * Math.Sin(theta)))); //Top right x value after rotation int y2 = (int)(centery + ((width / 2 * Math.Sin(theta)) - ((height / 2) * Math.Cos(theta)))); //Top right y value after rotation int x3 = (int)(centerx + ((width / 2 * Math.Cos(theta)) - ((height / 2) * Math.Sin(theta)))); //Bottom right x value after rotation int y3 = (int)(centery + ((width / 2 * Math.Sin(theta)) + ((height / 2) * Math.Cos(theta)))); //Bottom right y value after rotation int x4 = (int)(centerx - ((width / 2 * Math.Cos(theta)) + ((height / 2) * Math.Sin(theta)))); //Bottom left x value after rotation int y4 = (int)(centery - ((width / 2 * Math.Sin(theta)) - ((height / 2) * Math.Cos(theta)))); //Bottom left y value after rotation p1xtext.Text = Convert.ToString(x1); p1ytext.Text = Convert.ToString(y1); p2xtext.Text = Convert.ToString(x2); p2ytext.Text = Convert.ToString(y2); p3xtext.Text = Convert.ToString(x3); p3ytext.Text = Convert.ToString(y3); p4xtext.Text = Convert.ToString(x4); p4ytext.Text = Convert.ToString(y4); }
/// <summary> /// マウスホイールイベント(画像の拡大縮小) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void picImage_MouseWheel(object sender, MouseEventArgs e) { bool shiftKeyFlg = false; if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift) { shiftKeyFlg = true; } if (e.Delta > 0) { if (shiftKeyFlg) { // ポインタの位置周りに回転 _matAffine.RotateAt(5f, e.Location, System.Drawing.Drawing2D.MatrixOrder.Append); } else { // 拡大 // ポインタの位置周りに拡大 _matAffine.ScaleAt(1.5f, e.Location); } } else { if (shiftKeyFlg) { // ポインタの位置周りに回転 _matAffine.RotateAt(-5f, e.Location, System.Drawing.Drawing2D.MatrixOrder.Append); } else { // 縮小 // ポインタの位置周りに縮小 _matAffine.ScaleAt(1.0f / 1.5f, e.Location); } } // 画像の描画 RedrawImage(); }
private void ddlRotation_SelectedIndexChanged(object sender, EventArgs e) { var deg = (ddlRotation.SelectedItem as dynamic).Value; var matrix = new System.Drawing.Drawing2D.Matrix(); if (deg != 0f) { matrix.RotateAt((float)deg, new PointF(this.mb.Width / 2f, this.mb.Height / 2f)); } this.mb.Map.MapTransform = matrix; this.mb.Refresh(); }
public static SharpMap.Map InitializeMap(int angle, string[] filenames) { var map = new SharpMap.Map(); for (int i = 0; i < filenames.Length; i++) map.Layers.Add(new SharpMap.Layers.GdalRasterLayer(System.IO.Path.GetFileName(filenames[i]), filenames[i])); System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix(); mat.RotateAt(angle, map.WorldToImage(map.Center)); map.MapTransform = mat; map.ZoomToExtents(); return map; }
private static Matrix RotateAt(Matrix matrix, float theta, PointFx pointFx) { Matrix tempMatrix = Matrix.Identity; System.Drawing.Drawing2D.Matrix drawMatrix = new System.Drawing.Drawing2D.Matrix( matrix.M11, matrix.M12, matrix.M21, matrix.M22, matrix.M31, matrix.M32); drawMatrix.RotateAt(theta, new System.Drawing.PointF(pointFx.X, pointFx.Y)); tempMatrix = SetElements(drawMatrix); return(tempMatrix); }
private void DrawEndLine(int gridSize, Graphics g, Entry location, double degrees, Pen pen) { using (System.Drawing.Drawing2D.Matrix transformMatrix = new System.Drawing.Drawing2D.Matrix()) { transformMatrix.RotateAt((float)degrees, location.ToPoint(gridSize)); g.Transform = transformMatrix; g.DrawLine(pen, location.ToPoint(gridSize).AddToY(-(gridSize / 2)), location.ToPoint(gridSize).AddToY((gridSize / 2))); g.ResetTransform(); } }
/// <summary> /// Set the Rovio's position using linear interpolation. /// </summary> private void SetNewRovioPosition() { Vector2 oldP = new Vector2(picBoxRovio.Location.X, picBoxRovio.Location.Y); Vector2 newP = new Vector2(0, -1); // Find the angle of the Rovio on the perimeter of the arena. newP = Vector2.Transform(-Vector2.UnitY, Matrix.CreateRotationZ(MathHelper.ToRadians((float)robot.cumulativeAngle))); newP /= MathHelper.Max(Math.Abs(newP.X), Math.Abs(newP.Y)); newP += Vector2.One; newP *= new Vector2(260, 300) * 0.5f; // Translate into the arena from the perimeter. using (matrix = new System.Drawing.Drawing2D.Matrix()) { matrix.Translate((int)newP.X, (int)newP.Y); matrix.RotateAt((float)robot.cumulativeAngle, new DPoint(0, 0)); matrix.Translate(0f, (float)(robot.GetWallDist() * 100)); DPoint[] newPos = { new DPoint(0, 0) }; matrix.TransformPoints(newPos); if (newPos[0].X < -400 || newPos[0].X > 600) newPos[0] = new DPoint(-100, -100); // Compensate for the alcoves. if (newPos[0].X < 30 && (newPos[0].Y < 100 || newPos[0].Y > 200)) newPos[0].X += 30; else if (newP.X > 230 && (newPos[0].Y < 100 || newPos[0].Y > 200)) newPos[0].X -= 30; newP = Vector2.Lerp(oldP, new Vector2(newPos[0].X, newPos[0].Y), 0.1f); picBoxRovio.Location = new DPoint((int)newP.X, (int)newP.Y); } }
public List<Point> ToPoints( float angle, Rectangle rect) { // Create a GraphicsPath. System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddRectangle(rect); // Declare a matrix that will be used to rotate the text. System.Drawing.Drawing2D.Matrix rotateMatrix = new System.Drawing.Drawing2D.Matrix(); // Set the rotation angle and starting point for the text. rotateMatrix.RotateAt(180.0F, new PointF(10.0F, 100.0F)); // Transform the text with the matrix. path.Transform(rotateMatrix); List<Point> results = new List<Point>(); foreach(PointF p in path.PathPoints) { results.Add(new Point((int)p.X, (int)p.Y)); } path.Dispose(); return results; }
public List<Point> ToPoints( float angle, Rectangle rect) { // Graphics g = Graphics.FromImage(this.Image); Graphics g = Graphics.FromHwnd(this.Handle); List<Point> source_points = new List<Point>(); source_points.Add(new Point(rect.X, rect.Y)); source_points.Add(new Point(rect.X + rect.Width, rect.Y)); source_points.Add(new Point(rect.X +rect.Width, rect.Y + rect.Height)); source_points.Add(new Point(rect.X, rect.Y + rect.Height)); Point[] pts = source_points.ToArray(); Rectangle display_rect = GetPictureBoxZoomSize(); float x_ratio = (float)display_rect.Width / (float)this.Image.Width; float y_ratio = (float)display_rect.Height / (float)this.Image.Height; System.Drawing.Drawing2D.Matrix rotateMatrix = new System.Drawing.Drawing2D.Matrix(); // Set the rotation angle and starting point for the text. rotateMatrix.RotateAt(angle, new PointF(this.Image.Width / 2, this.Image.Height / 2)); //rotateMatrix.RotateAt(angle, new PointF(0, 0)); g.MultiplyTransform(rotateMatrix); // g.ScaleTransform(x_ratio, y_ratio); // g.ScaleTransform((float)1.1, (float)1.1); // g.RotateTransform(angle); g.TransformPoints(System.Drawing.Drawing2D.CoordinateSpace.World, System.Drawing.Drawing2D.CoordinateSpace.Device, pts); return pts.ToList(); }
public void TestAffineTransform2D() { //Setup some affine transformation System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix(); matrix.RotateAt(30, new System.Drawing.PointF(0, 0)); matrix.Translate(-20, -20, System.Drawing.Drawing2D.MatrixOrder.Append); matrix.Shear(0.95f, -0.2f, System.Drawing.Drawing2D.MatrixOrder.Append); //Create some random sample data CreatingData cd = new CreatingData(); SharpMap.Data.FeatureDataTable fdt1 = cd.CreatePointFeatureDataTableFromArrays(GetRandomOrdinates(80, -180, 180), GetRandomOrdinates(80, -90, 90), null); //Clone random sample data and apply affine transformation on it SharpMap.Data.FeatureDataTable fdt2 = TransformedFeatureDataTable(matrix, fdt1); //Get affine transformation with LeastSquaresTransform SharpMap.Utilities.LeastSquaresTransform lst = new SharpMap.Utilities.LeastSquaresTransform(); //Add at least three corresponding points lst.AddInputOutputPoint( ((SharpMap.Data.FeatureDataRow)fdt1.Rows[0]).Geometry as SharpMap.Geometries.Point, ((SharpMap.Data.FeatureDataRow)fdt2.Rows[0]).Geometry as SharpMap.Geometries.Point); lst.AddInputOutputPoint( ((SharpMap.Data.FeatureDataRow)fdt1.Rows[39]).Geometry as SharpMap.Geometries.Point, ((SharpMap.Data.FeatureDataRow)fdt2.Rows[39]).Geometry as SharpMap.Geometries.Point); lst.AddInputOutputPoint( ((SharpMap.Data.FeatureDataRow)fdt1.Rows[79]).Geometry as SharpMap.Geometries.Point, ((SharpMap.Data.FeatureDataRow)fdt2.Rows[79]).Geometry as SharpMap.Geometries.Point); /* //Get affine transformation calculates mean points to improve accuaracy //Unfortunately the result is not very good, so, since I know better I manually set these //mean points. lst.SetMeanPoints(new SharpMap.Geometries.Point(0, 0), new SharpMap.Geometries.Point(matrix.OffsetX, matrix.OffsetY)); */ //Create Affine AffineCoordinateTransformation2D at2 = new AffineCoordinateTransformation2D(lst.GetAffineTransformation()); //Create Map SharpMap.Map map = new SharpMap.Map(new System.Drawing.Size(720, 360)); //Add not transformed layer map.Layers.Add(new SharpMap.Layers.VectorLayer("L1", new SharpMap.Data.Providers.GeometryFeatureProvider(fdt1))); ((SharpMap.Layers.VectorLayer) map.Layers[0]).Style.Symbol = new System.Drawing.Bitmap(@"..\..\..\DemoWinForm\Resources\flag.png"); //Add transformed layer map.Layers.Add(new SharpMap.Layers.VectorLayer("L2", new SharpMap.Data.Providers.GeometryFeatureProvider(fdt2))); ((SharpMap.Layers.VectorLayer) map.Layers[1]).Style.Symbol = new System.Drawing.Bitmap(@"..\..\..\DemoWinForm\Resources\women.png"); //Render map map.ZoomToExtents(); //Get map and save to file var bmp = (System.Drawing.Bitmap)map.GetMap(); bmp.Save("affinetransform1.bmp"); //we want to reverse the previously applied transformation. ((SharpMap.Layers.VectorLayer) map.Layers[1]).CoordinateTransformation = (AffineCoordinateTransformation2D)at2.Inverse(); //Render map map.ZoomToExtents(); //Get map and save to file bmp = (System.Drawing.Bitmap)map.GetMap(); bmp.Save("affinetransform2.bmp"); //Hopefully women cover flags ;-). }
//TODO: use e.ClipRectangle to limit drawing private void mapPanel_Paint(object sender, PaintEventArgs e) { if (Map == null) return; PointF nwCorner, neCorner, seCorner, swCorner, center; Graphics g = e.Graphics; //black out the panel to start out Size size = mapPanel.Size; g.FillRectangle(ColorLayout.Background, new Rectangle(new Point(0, 0), size)); Pen pen; //draw one more top and left row wall than neccesary Rectangle clip = new Rectangle(e.ClipRectangle.Left - squareSize, e.ClipRectangle.Top - squareSize, e.ClipRectangle.Width + squareSize, e.ClipRectangle.Height + squareSize); //Bitmap floor = new Bitmap(clip.Width, clip.Height); //draw grid if (DrawGrid || chkGrid.Checked) { using (pen = new Pen(Color.Gray, gridThickness)) { //draw the grid sloppily (an extra screen's worth of lines along either axis) for (int x = -squareSize * (size.Width / squareSize) - 3 * squareSize / 2 % (2 * squareSize); x < 2 * size.Width; x += 2 * squareSize) { int y = -3 * squareSize / 2 % (2 * squareSize); g.DrawLine(pen, new Point(x - 1, y), new Point(y, x - 1)); g.DrawLine(pen, new Point(x, y), new Point(size.Width + x, size.Width + y)); } } } //draw floor if (CurrentMode == Mode.MAKE_FLOOR || chkTileGrid.Checked || CurrentMode == Mode.EDIT_EDGE)//only draw the floor when editing it { foreach (Map.Tile tile in Map.Tiles.Values) { //int x = (int)(tile.Location.X * squareSize - squareSize / 2f); int x = tile.Location.X * squareSize; int y = tile.Location.Y * squareSize; if (chkAltGrid.Checked) pen = ColorLayout.Tiles2; else pen = ColorLayout.Tiles; if (clip.Contains((int)x, (int)y)) { /*if (video != null) { System.Drawing.Imaging.ImageAttributes imgAttr = new System.Drawing.Imaging.ImageAttributes(); //imgAttr.SetColorKey(Color.Black, Color.Black); video.ExtractOneToPoint(tile.Variations[tile.Variation],ref floor,new Point(x-clip.X,y-clip.Y)); floor.Save(tempPath2, System.Drawing.Imaging.ImageFormat.Bmp); }/* /* Old floor lines */ center = new PointF(x + squareSize / 2f, y + (3 / 2f) * squareSize); nwCorner = new PointF(x - squareSize / 2f, y + (3 / 2f) * squareSize); neCorner = new PointF(nwCorner.X + squareSize, nwCorner.Y - squareSize); swCorner = new PointF(nwCorner.X + squareSize, nwCorner.Y + squareSize); seCorner = new PointF(neCorner.X + squareSize, neCorner.Y + squareSize); Brush tembrush = floorBrush; if( ThingDb.FloorTiles[tile.graphicId].hascolor ) tembrush = new SolidBrush(ThingDb.FloorTiles[tile.graphicId].col); g.FillPolygon(tembrush, new PointF[] { nwCorner, neCorner, seCorner, swCorner }); g.DrawPolygon(pen, new PointF[] { nwCorner, neCorner, seCorner, swCorner }); //draw the center dot int diam = 2;// +tile.EdgeTiles.Count * 3; PointF ellTL = new PointF(center.X - diam / 2f, center.Y - diam / 2f); if (tile.EdgeTiles.Count > 0) e.Graphics.FillEllipse(Brushes.YellowGreen, ellTL.X, ellTL.Y, diam, diam); else e.Graphics.DrawEllipse(Pens.Brown, ellTL.X, ellTL.Y, diam, diam); //g.DrawString(tile.Location.X.ToString() +":"+ tile.Location.Y.ToString(), new Font("Arial", 10), Brushes.Red, center.X, center.Y); ///// ///// ///// ///// ///// // Draw edging constructs /* if (tile.EdgeTiles.Count > 0) { PointF ellTL2 = new PointF(x - (squareSize - 4) / 2f, y + (3 / 2f) * (squareSize - 4)); PointF ellTL3 = new PointF(ellTL2.X + (squareSize - 4), ellTL2.Y - (squareSize - 4)); if (ThingDb.FloorTiles[tile.graphicId].hascolor) g.DrawLine(new Pen(ThingDb.FloorTiles[tile.graphicId].col, gridThickness * 4), ellTL2, ellTL3); else g.DrawLine(new Pen(Color.Aqua, gridThickness * 4), ellTL2, ellTL3); }*/ PointF nwCorner2 = nwCorner; PointF neCorner2 = neCorner; PointF swCorner2 = swCorner; PointF seCorner2 = seCorner; int i = 0; for( i=0; i<tile.EdgeTiles.Count; i++) { int graphId = ((Map.Tile.EdgeTile)tile.EdgeTiles[i]).Graphic; Color col = new Color(); if (ThingDb.FloorTiles[graphId].hascolor) col = ThingDb.FloorTiles[graphId].col; else col = Color.Aqua; nwCorner2 = nwCorner;//new PointF(x - squareSize / 2f, y + (3 / 2f) * squareSize); neCorner2 = neCorner;// new PointF(nwCorner.X + squareSize, nwCorner.Y - squareSize); swCorner2 = swCorner;// new PointF(nwCorner.X + squareSize, nwCorner.Y + squareSize); seCorner2 = seCorner;// new PointF(neCorner.X + squareSize, neCorner.Y + squareSize); switch (((Map.Tile.EdgeTile)tile.EdgeTiles[i]).Dir) { case Map.Tile.EdgeTile.Direction.North_08: case Map.Tile.EdgeTile.Direction.North_0A: case Map.Tile.EdgeTile.Direction.North: nwCorner2.X += 2; nwCorner2.Y += 2; neCorner2.X += 2; neCorner2.Y += 2; g.DrawLine(new Pen(col, gridThickness * 4), nwCorner2, neCorner2); break; case Map.Tile.EdgeTile.Direction.South_07: case Map.Tile.EdgeTile.Direction.South_09: case Map.Tile.EdgeTile.Direction.South: swCorner2.X -= 2; swCorner2.Y -= 2; seCorner2.X -= 2; seCorner2.Y -= 2; g.DrawLine(new Pen(col, gridThickness * 4), swCorner2, seCorner2); break; case Map.Tile.EdgeTile.Direction.East_D: case Map.Tile.EdgeTile.Direction.East_E: case Map.Tile.EdgeTile.Direction.East: neCorner.X -= 2; neCorner.Y += 2; seCorner.X -= 2; seCorner.Y += 2; g.DrawLine(new Pen(col, gridThickness * 4), neCorner, seCorner); break; case Map.Tile.EdgeTile.Direction.West_02: case Map.Tile.EdgeTile.Direction.West_03: case Map.Tile.EdgeTile.Direction.West: nwCorner2.X += 2; nwCorner2.Y -= 2; swCorner2.X += 2; swCorner2.Y -= 2; g.DrawLine(new Pen(col, gridThickness * 4), nwCorner2, swCorner2); break; case Map.Tile.EdgeTile.Direction.NE_Sides: neCorner.X -= 2; neCorner.Y += 2; seCorner.X -= 2; seCorner.Y += 2; g.DrawLine(new Pen(col, gridThickness * 4), neCorner, seCorner); nwCorner2 = nwCorner; neCorner2 = neCorner; swCorner2 = swCorner; seCorner2 = seCorner; nwCorner2.X += 2; nwCorner2.Y += 2; neCorner2.X += 2; neCorner2.Y += 2; g.DrawLine(new Pen(col, gridThickness * 4), nwCorner2, neCorner2); break; case Map.Tile.EdgeTile.Direction.NW_Sides: nwCorner2.X += 2; nwCorner2.Y -= 2; swCorner2.X += 2; swCorner2.Y -= 2; g.DrawLine(new Pen(col, gridThickness * 4), nwCorner2, swCorner2); nwCorner2 = nwCorner; neCorner2 = neCorner; swCorner2 = swCorner; seCorner2 = seCorner; nwCorner2.X += 2; nwCorner2.Y += 2; neCorner2.X += 2; neCorner2.Y += 2; g.DrawLine(new Pen(col, gridThickness * 4), nwCorner2, neCorner2); break; case Map.Tile.EdgeTile.Direction.SE_Sides: swCorner2.X -= 2; swCorner2.Y -= 2; seCorner2.X -= 2; seCorner2.Y -= 2; g.DrawLine(new Pen(col, gridThickness * 4), swCorner2, seCorner2); nwCorner2 = nwCorner; neCorner2 = neCorner; swCorner2 = swCorner; seCorner2 = seCorner; neCorner.X -= 2; neCorner.Y += 2; seCorner.X -= 2; seCorner.Y += 2; g.DrawLine(new Pen(col, gridThickness * 4), neCorner, seCorner); break; case Map.Tile.EdgeTile.Direction.SW_Sides: swCorner2.X -= 2; swCorner2.Y -= 2; seCorner2.X -= 2; seCorner2.Y -= 2; g.DrawLine(new Pen(col, gridThickness * 4), swCorner2, seCorner2); nwCorner2 = nwCorner; neCorner2 = neCorner; swCorner2 = swCorner; seCorner2 = seCorner; nwCorner2.X += 2; nwCorner2.Y -= 2; swCorner2.X += 2; swCorner2.Y -= 2; g.DrawLine(new Pen(col, gridThickness * 4), nwCorner2, swCorner2); break; case Map.Tile.EdgeTile.Direction.NE_Tip: /* //neCorner.X += 2; //neCorner.Y -= 2; PointF tem = neCorner2; tem.X -= 4; tem.Y += 4; PointF tem2 = neCorner2; tem.X += 4; tem2.Y += 4; g.FillPolygon(new SolidBrush(col), new PointF[] { neCorner2, tem, tem2 }); //g.DrawLine(new Pen(col, gridThickness * 4), nwCorner, swCorner); */break; case Map.Tile.EdgeTile.Direction.SE_Tip: break; case Map.Tile.EdgeTile.Direction.SW_Tip: break; case Map.Tile.EdgeTile.Direction.NW_Tip: break; default: break; } } ///// ///// ///// ///// ///// ///// } } //floor.Save("c:\\file.bmp"); //e.Graphics.DrawImage(floor, new Point(clip.X + 40, clip.Y + 40)); } if (CurrentMode == Mode.MAKE_FLOOR || CurrentMode == Mode.EDIT_EDGE) { // Draw the overlay to show tile location Point pt = new Point(mouseLocation.X, mouseLocation.Y); Point tilePt = GetNearestTilePoint(pt); int squareSize2 = squareSize; if (threeFloorBox.Checked && CurrentMode == Mode.MAKE_FLOOR) { squareSize2 *= 3; tilePt.X -= 1; tilePt.Y -= 3; } tilePt.X *= squareSize; tilePt.Y *= squareSize; center = new PointF(tilePt.X + squareSize / 2f, tilePt.Y + (3 / 2f) * squareSize); nwCorner = new PointF(tilePt.X - squareSize2 / 2f, tilePt.Y + (3 / 2f) * squareSize2); neCorner = new PointF(nwCorner.X + squareSize2, nwCorner.Y - squareSize2); swCorner = new PointF(nwCorner.X + squareSize2, nwCorner.Y + squareSize2); seCorner = new PointF(neCorner.X + squareSize2, neCorner.Y + squareSize2); if( CurrentMode == Mode.MAKE_FLOOR ) g.DrawPolygon(new Pen(Color.Yellow, gridThickness * 2), new PointF[] { nwCorner, neCorner, seCorner, swCorner }); else if( CurrentMode == Mode.EDIT_EDGE ) g.DrawPolygon(new Pen(Color.Aqua, gridThickness * 2), new PointF[] { nwCorner, neCorner, seCorner, swCorner }); } //draw walls foreach (Map.Wall wall in Map.Walls.Values) { Point pt = wall.Location; int x = pt.X * squareSize, y = pt.Y * squareSize; if (clip.Contains(x, y)) { //TODO: how to draw if a destructable window? is this even possible? if (wall.Destructable) pen = new Pen(Color.Red, wallThickness); else if (wall.Window) pen = new Pen(Color.Orange, wallThickness); else if (wall.Secret) pen = new Pen(Color.Green, wallThickness); else pen = new Pen(ColorLayout.Walls, wallThickness); center = new PointF(x + squareSize / 2f, y + squareSize / 2f); Point nCorner = new Point(x, y); Point sCorner = new Point(x + squareSize, y + squareSize); Point wCorner = new Point(x + squareSize, y); Point eCorner = new Point(x, y + squareSize); switch (wall.Facing) { case Map.Wall.WallFacing.NORTH: g.DrawLine(pen, wCorner, eCorner); break; case Map.Wall.WallFacing.WEST: g.DrawLine(pen, nCorner, sCorner); break; case Map.Wall.WallFacing.CROSS: g.DrawLine(pen, wCorner, eCorner);//north wall g.DrawLine(pen, nCorner, sCorner);//south wall break; case Map.Wall.WallFacing.NORTH_T: g.DrawLine(pen, wCorner, eCorner);//north wall g.DrawLine(pen, center, sCorner);//tail towards south break; case Map.Wall.WallFacing.SOUTH_T: g.DrawLine(pen, wCorner, eCorner);//north wall g.DrawLine(pen, center, nCorner);//tail towards north break; case Map.Wall.WallFacing.WEST_T: g.DrawLine(pen, nCorner, sCorner);//west wall g.DrawLine(pen, center, eCorner);//tail towards east break; case Map.Wall.WallFacing.EAST_T: g.DrawLine(pen, nCorner, sCorner);//west wall g.DrawLine(pen, center, wCorner);//tail towards west break; case Map.Wall.WallFacing.NE_CORNER: g.DrawLine(pen, center, eCorner); g.DrawLine(pen, center, sCorner); break; case Map.Wall.WallFacing.NW_CORNER: g.DrawLine(pen, center, wCorner); g.DrawLine(pen, center, sCorner); break; case Map.Wall.WallFacing.SW_CORNER: g.DrawLine(pen, center, nCorner); g.DrawLine(pen, center, wCorner); break; case Map.Wall.WallFacing.SE_CORNER: g.DrawLine(pen, center, nCorner); g.DrawLine(pen, center, eCorner); break; default: g.DrawRectangle(pen, x, y, squareSize, squareSize); g.DrawString("?", new Font("Arial", 12), Brushes.Red, nCorner); break; } pen.Dispose(); g.DrawString(wall.Minimap.ToString(), new Font("Arial", 10), Brushes.Red, x, y); } } //draw objects if (chkShowObj.Checked) { foreach (Map.Object oe in Map.Objects) { PointF ptf = oe.Location; if (clip.Contains((int)ptf.X, (int)ptf.Y)) { float x = ptf.X, y = ptf.Y; center = new PointF(x, y); PointF topLeft = new PointF(center.X - objectSelectionRadius, center.Y - objectSelectionRadius); if (SelectedObject != null && SelectedObject.Location.Equals(oe.Location)) pen = Pens.Green; else pen = ColorLayout.Objects; g.DrawEllipse(pen, new RectangleF(topLeft, new Size(2 * objectSelectionRadius, 2 * objectSelectionRadius))); if (ShowExtents) { if (!(!ShowAllExtents && ((ThingDb.Things[oe.Name].Flags & ThingDb.Thing.FlagsFlags.NO_COLLIDE) == ThingDb.Thing.FlagsFlags.NO_COLLIDE))) { if (ThingDb.Things[oe.Name].ExtentType == "CIRCLE") { PointF t = new PointF(center.X - ThingDb.Things[oe.Name].ExtentX, center.Y - ThingDb.Things[oe.Name].ExtentX); PointF p = new PointF((center.X) - ThingDb.Things[oe.Name].ExtentX, (center.Y - (ThingDb.Things[oe.Name].ZSizeY)) - ThingDb.Things[oe.Name].ExtentX); Pen rotatePen; if (oe.Name.Contains("Amb")) { rotatePen = new Pen(Color.LightGray, 1); } else rotatePen = new Pen(Color.Green, 1); PointF point1 = new PointF(t.X, t.Y); point1.Y += ThingDb.Things[oe.Name].ExtentX; PointF point2 = new PointF(p.X, p.Y); point2.Y += ThingDb.Things[oe.Name].ExtentX; g.DrawLine(rotatePen, point1, point2); point1.X += ThingDb.Things[oe.Name].ExtentX * 2; point2.X += ThingDb.Things[oe.Name].ExtentX * 2; g.DrawLine(rotatePen, point1, point2); g.DrawEllipse(rotatePen, new RectangleF(t, new Size(2 * ThingDb.Things[oe.Name].ExtentX, 2 * ThingDb.Things[oe.Name].ExtentX))); g.DrawEllipse(rotatePen, new RectangleF(p, new Size(2 * ThingDb.Things[oe.Name].ExtentX, 2 * ThingDb.Things[oe.Name].ExtentX))); } if (ThingDb.Things[oe.Name].ExtentType == "BOX") { Point t = new Point((int)(center.X - (ThingDb.Things[oe.Name].ExtentX / 2)), (int)(center.Y - (ThingDb.Things[oe.Name].ExtentY / 2))); Point p = new Point((int)((center.X - (ThingDb.Things[oe.Name].ZSizeY / 2)) - (ThingDb.Things[oe.Name].ExtentX / 2)), (int)((center.Y - (ThingDb.Things[oe.Name].ZSizeY / 2)) - (ThingDb.Things[oe.Name].ExtentY / 2))); using (System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix()) { m.RotateAt(45, center); g.Transform = m; Pen rotatePen = new Pen(Color.Green, 1); PointF point1 = new PointF(t.X, t.Y); PointF point2 = new PointF(p.X, p.Y); g.DrawLine(rotatePen, point1, point2); point1 = new PointF(t.X, t.Y); point2 = new PointF(p.X, p.Y); point1.Y += ThingDb.Things[oe.Name].ExtentY; point2.Y += ThingDb.Things[oe.Name].ExtentY; g.DrawLine(rotatePen, point1, point2); point1 = new PointF(t.X, t.Y); point2 = new PointF(p.X, p.Y); point1.X += ThingDb.Things[oe.Name].ExtentX; point2.X += ThingDb.Things[oe.Name].ExtentX; g.DrawLine(rotatePen, point1, point2); point1 = new PointF(t.X, t.Y); point2 = new PointF(p.X, p.Y); point1.X += ThingDb.Things[oe.Name].ExtentX; point2.X += ThingDb.Things[oe.Name].ExtentX; point1.Y += ThingDb.Things[oe.Name].ExtentY; point2.Y += ThingDb.Things[oe.Name].ExtentY; g.DrawLine(rotatePen, point1, point2); g.DrawRectangle(rotatePen, new Rectangle(t, new Size(ThingDb.Things[oe.Name].ExtentX, ThingDb.Things[oe.Name].ExtentY))); g.DrawRectangle(rotatePen, new Rectangle(p, new Size(ThingDb.Things[oe.Name].ExtentX, ThingDb.Things[oe.Name].ExtentY))); //g.ResetTransform(); g.ResetTransform(); } } } } if (!ShowObjectNames) g.DrawString(oe.Extent.ToString(), new Font("Arial", 10), Brushes.Purple, topLeft); else g.DrawString(oe.Name, new Font("Arial", 10), Brushes.Green, topLeft); // ThingDb.Things.Keys. } } } //draw polygons if (ShowPolygons) { foreach (Map.Polygon poly in Map.Polygons) { pen = Pens.PaleGreen; ArrayList points = new ArrayList(); foreach (PointF pt in poly.Points) points.Add(new PointF(pt.X, pt.Y)); if (points.Count > 2) { points.Add(points[0]);//complete the loop g.DrawLines(pen, (PointF[])points.ToArray(typeof(PointF))); } } } //draw waypoints if (ShowWaypoints) { foreach (Map.Waypoint wp in Map.Waypoints) { if (KeyStates.wp1 != null && wp == KeyStates.wp1) pen = Pens.Aqua; else pen = Pens.Olive; center = new PointF(wp.Point.X - objectSelectionRadius, wp.Point.Y - objectSelectionRadius); g.DrawEllipse(pen, new RectangleF(center, new Size(2 * objectSelectionRadius, 2 * objectSelectionRadius))); //code/idea from UndeadZeus foreach (Map.Waypoint.WaypointConnection wpc in wp.connections) { g.DrawLine(pen, wp.Point.X, wp.Point.Y, wpc.wp.Point.X, wpc.wp.Point.Y); foreach (Map.Waypoint.WaypointConnection wpwp in wpc.wp.connections)//Checks if the waypoint connection is connecting to wp { if (wpwp.wp.Equals(wp)) { if (KeyStates.wp1 != null && wp == KeyStates.wp1) g.DrawLine(Pens.Aqua, wp.Point.X, wp.Point.Y, wpc.wp.Point.X, wpc.wp.Point.Y); else g.DrawLine(Pens.Orange, wp.Point.X, wp.Point.Y, wpc.wp.Point.X, wpc.wp.Point.Y); break; } } } if (wp.Name.Length > 0) g.DrawString(wp.num + ":" + wp.Name, new Font("Arial", 8), Brushes.Purple, center); else g.DrawString(wp.num + "", new Font("Arial", 8), Brushes.Purple, center); } } //draw drag line if (dragging == true) { switch (CurrentMode) { case Mode.MAKE_WALL: pen = Pens.Green; int length = (int)Distance(wallDrag, wallMouseLocation); int newX = wallDrag.X + (int)Math.Sqrt((length * length) / 2) * (wallMouseLocation.X >= wallDrag.X ? 1 : (-1)); int newY = wallDrag.Y + (int)Math.Sqrt((length * length) / 2) * (wallMouseLocation.Y >= wallDrag.Y ? 1 : (-1)); g.DrawLine(pen, wallDrag.X * 23, wallDrag.Y * 23, newX * 23, newY * 23); break; case Mode.SELECT: if (SelectedObject != null) { pen = Pens.Green; PointF topLeft = new PointF(mouseLocation.X - objectSelectionRadius, mouseLocation.Y - objectSelectionRadius); g.DrawEllipse(pen, new RectangleF(topLeft, new Size(2 * objectSelectionRadius, 2 * objectSelectionRadius))); } break; case Mode.MAKE_FLOOR: pen = Pens.Green; Point tilePt = GetNearestTilePoint(mouseLocation); Point topLeftPt; int w = tilePt.X - tileDrag.X, h = tilePt.Y - tileDrag.Y; if (w < 0) topLeftPt = new Point(tileDrag.X + w, 0); else topLeftPt = new Point(tileDrag.X, 0); if (h < 0) topLeftPt = new Point(topLeftPt.X, tileDrag.Y + h); else topLeftPt = new Point(topLeftPt.X, tileDrag.Y); for (int i = 0; i <= w; i++) { for (int k = 0; k <= h; k++) { tilePt = GetNearestTilePoint(new Point((topLeftPt.X + i) * squareSize, (topLeftPt.Y + k) * squareSize)); tilePt = new Point(tilePt.X * squareSize, tilePt.Y * squareSize); center = new PointF(tilePt.X + squareSize / 2f, tilePt.Y + (3 / 2f) * squareSize); nwCorner = new PointF(tilePt.X - squareSize / 2f, tilePt.Y + (3 / 2f) * squareSize); neCorner = new PointF(nwCorner.X + squareSize, nwCorner.Y - squareSize); swCorner = new PointF(nwCorner.X + squareSize, nwCorner.Y + squareSize); seCorner = new PointF(neCorner.X + squareSize, neCorner.Y + squareSize); g.DrawPolygon(pen, new PointF[] { nwCorner, neCorner, seCorner, swCorner }); } } break; } } }
private void Carte_Paint(object sender, PaintEventArgs e) { int i; double w, h; //projet = ((Musliw.MusliW)(this.MdiParent)).projet; Graphics page = e.Graphics; //page.Clear(this.BackColor); w = this.Width; h = this.Height; Pen stylo = new Pen(fen.stylo_couleur, (int)fen.epaisseur); Font fonte = new Font(FontFamily.GenericSansSerif, 7,FontStyle.Bold); this.ForeColor = Color.Black; Brush brosse =new SolidBrush(fen.brosse_couleur); Brush brosse_texte = new SolidBrush(fen.couleur_texte); double dx = w / (projet.reseaux[nproj].xu - projet.reseaux[nproj].xl); double dy = h / (projet.reseaux[nproj].yu - projet.reseaux[nproj].yl); double deltax,deltay,voldeltax,voldeltay; double cx = 0.5f * (projet.reseaux[nproj].xu + projet.reseaux[nproj].xl); double cy = 0.5f * (projet.reseaux[nproj].yu + projet.reseaux[nproj].yl); //MessageBox.Show(xl.ToString() + " " + yu.ToString()); PointF p1=new PointF(); PointF p2 = new PointF(); PointF p3 = new PointF(); PointF p4 = new PointF(); PointF p5 = new PointF(); PointF[] points = new PointF[4] ; double angle=0,norme=0; double sinx = 0, cosx = 1; if (fen.volume_echelle < 1e-6f) { fen.volume_echelle = 1e-6f; } for (i = 0; i < projet.reseaux[nproj].links.Count; i++) { norme = fen.norme(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart + 0.5f * fen.epaisseur); if ((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].is_visible == true && projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].is_visible == true && norme > 0) && (projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].is_valid == true && projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].is_valid == true)) { //page.DrawRectangle(stylo, 0f, 0f, 200, 200); //MessageBox.Show(((res.nodes[i].x - res.xl) * delta).ToString() + " " + ((res.yu - res.nodes[i].y) * delta).ToString()+" "+w.ToString()+" "+h.ToString()); deltax = fen.deltax(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart+0.5f*fen.epaisseur); deltay = fen.deltay(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart+0.5f*fen.epaisseur); cosx = fen.deltax(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, 1); sinx = fen.deltay(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, 1); voldeltax = fen.deltax(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart + 0.5f * fen.epaisseur + projet.reseaux[projet.reseau_actif].links[i].volau / fen.volume_echelle); voldeltay = fen.deltay(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart + 0.5f * fen.epaisseur + projet.reseaux[projet.reseau_actif].links[i].volau / fen.volume_echelle); page.DrawLine(stylo, (float)(((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x - fen.xl) / fen.echelle) + deltay), (float)(((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y) / fen.echelle) + deltax),(float) (((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x - fen.xl) / fen.echelle) + deltay),(float) (((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y) / fen.echelle) + deltax)); p1.X = (float)(((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x - fen.xl) / fen.echelle) + deltay); p1.Y = (float)(((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y) / fen.echelle) + deltax); p2.X = (float)(((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x - fen.xl) / fen.echelle) + voldeltay); p2.Y = (float)(((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y) / fen.echelle) + voldeltax); p3.X = (float)(((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x - fen.xl) / fen.echelle) + voldeltay); p3.Y = (float)(((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y) / fen.echelle) + voldeltax); p4.X = (float)(((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x - fen.xl) / fen.echelle) + deltay); p4.Y = (float)(((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y) / fen.echelle) + deltax); System.Drawing.Drawing2D.GraphicsPath epaisseur = new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.Drawing2D.GraphicsPath texte_epaisseur = new System.Drawing.Drawing2D.GraphicsPath(); epaisseur.StartFigure(); points[0] = p1; points[1] = p2; points[2] = p3; points[3] = p4; epaisseur.AddPolygon(points); epaisseur.CloseFigure(); //page.FillPath(brosse, epaisseur); //page.FillPolygon(brosse, points); //page.DrawPolygon(stylo,points); epaisseur.Reset(); texte_epaisseur.StartFigure(); p5.X = 0.5f * (p3.X + p2.X); p5.Y = 0.5f * (p3.Y + p2.Y); texte_epaisseur.AddString(projet.reseaux[projet.reseau_actif].links[i].volau.ToString("0"), FontFamily.GenericSansSerif, 0, (float)fen.taille_texte, new PointF(p5.X, p5.Y), StringFormat.GenericDefault); RectangleF encombrement = texte_epaisseur.GetBounds(); // texte_epaisseur.AddRectangle(encombrement); //texte_epaisseur.AddPie(p5.X,p5.Y,2,2,0,360); page.FillPolygon(brosse, points); page.DrawPolygon(stylo, points); if (encombrement.Width < fen.norme(p1.X, p4.X, p1.Y, p4.Y, 1) && projet.reseaux[projet.reseau_actif].links[i].volau > 0) { System.Drawing.Drawing2D.Matrix rotation = new System.Drawing.Drawing2D.Matrix(); if (cosx >= 0 && sinx <= 0) { angle = 180f * ((float)Math.Acos(cosx) / (float)Math.PI); rotation.RotateAt((float)angle, p5); rotation.Translate(p5.X - encombrement.X, p5.Y - encombrement.Y); System.Drawing.Drawing2D.Matrix trans = new System.Drawing.Drawing2D.Matrix(); texte_epaisseur.Transform(rotation); trans.Translate((float)(-0.5f * encombrement.Width * cosx),(float)( 0.5f * encombrement.Width * sinx)); texte_epaisseur.Transform(trans); texte_epaisseur.CloseFigure(); page.FillPath(brosse_texte, texte_epaisseur); } else if (cosx <= 0 && sinx >= 0) { angle = 180f - 180f * ((float)Math.Acos(cosx) / (float)Math.PI); rotation.RotateAt((float)angle, p5); rotation.Translate(p5.X - encombrement.X, p5.Y - encombrement.Y); System.Drawing.Drawing2D.Matrix trans = new System.Drawing.Drawing2D.Matrix(); texte_epaisseur.Transform(rotation); trans.Translate((float)(+0.5f * encombrement.Width * cosx + (encombrement.Height) * sinx),(float)( -0.5f * encombrement.Width * sinx + (encombrement.Height) * cosx)); texte_epaisseur.Transform(trans); texte_epaisseur.CloseFigure(); page.FillPath(brosse_texte, texte_epaisseur); } else if (cosx >= 0 && sinx >= 0) { angle = -180f * (float)Math.Acos(cosx) / (float)Math.PI; rotation.RotateAt((float)angle, p5); rotation.Translate(p5.X - encombrement.X, p5.Y - encombrement.Y); System.Drawing.Drawing2D.Matrix trans = new System.Drawing.Drawing2D.Matrix(); texte_epaisseur.Transform(rotation); trans.Translate((float)(-0.5f * encombrement.Width * cosx),(float)( 0.5f * encombrement.Width * sinx)); texte_epaisseur.Transform(trans); texte_epaisseur.CloseFigure(); page.FillPath(brosse_texte, texte_epaisseur); } else if (cosx <= 0 && sinx <= 0) { angle = 180 + 180f * ((float)Math.Acos(cosx) / (float)Math.PI); rotation.RotateAt((float)angle, p5); rotation.Translate(p5.X - encombrement.X, p5.Y - encombrement.Y); System.Drawing.Drawing2D.Matrix trans = new System.Drawing.Drawing2D.Matrix(); texte_epaisseur.Transform(rotation); trans.Translate((float)(+0.5f * encombrement.Width * cosx + (encombrement.Height) * sinx),(float)( -0.5f * encombrement.Width * sinx + (encombrement.Height) * cosx)); texte_epaisseur.Transform(trans); texte_epaisseur.CloseFigure(); page.FillPath(brosse_texte, texte_epaisseur); } } epaisseur.Dispose(); texte_epaisseur.Dispose(); } } /* for (i = 0; i < projet.reseaux[nproj].nodes.Count; i++) { if (projet.reseaux[nproj].nodes[i].i != 0) { //page.DrawRectangle(stylo, 0f, 0f, 200, 200); //MessageBox.Show(((res.nodes[i].x - res.xl) * delta).ToString() + " " + ((res.yu - res.nodes[i].y) * delta).ToString()+" "+w.ToString()+" "+h.ToString()); page.FillRectangle(brosse, (res.nodes[i].x - res.xl) * delta, (res.yu - res.nodes[i].y) * delta, 30f, 20f); page.DrawRectangle(stylo, (res.nodes[i].x - res.xl) * delta, (res.yu - res.nodes[i].y) * delta, 30f, 20f); page.DrawString(res.nodes[i].i.ToString(), fonte, Brushes.Black, new RectangleF((res.nodes[i].x - res.xl) * delta, (res.yu - res.nodes[i].y) * delta, 30f, 20f)); } }*/ }
private static PointF GetUpperCorner( float rotation, float left, float top, float width, float height ) { // BUG 1006: Need to account for rotation when determining bounds if( rotation != 0 ) { PointF[] pts = new PointF[4]; pts[0] = new PointF( left, top ); pts[1] = new PointF( left, top + height ); pts[2] = new PointF( left + width, top ); pts[3] = new PointF( left + width, top + height ); // Rotate the points System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix(); m.RotateAt( rotation, new PointF( left + width/2.0f, top + height/2.0f ) ); m.TransformPoints( pts ); return new PointF( Math.Min( Math.Min( Math.Min( pts[0].X, pts[1].X ), pts[2].X ), pts[3].X ), Math.Min( Math.Min( Math.Min( pts[0].Y, pts[1].Y ), pts[2].Y ), pts[3].Y ) ); } else { return new PointF( left, top ); } }
public void rotatePoint(PointF centerpoint, float angle, ref PointF dstpoint) { System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix(); mat.RotateAt(angle, centerpoint); PointF[] arraypoints = new PointF[1]; arraypoints[0] = dstpoint; mat.TransformPoints(arraypoints); dstpoint = arraypoints[0]; }
public static Image RotateImage(Image inputImg, double degreeAngle) { //Corners of the image PointF[] rotationPoints = { new PointF(0, 0), new PointF(inputImg.Width, 0), new PointF(0, inputImg.Height), new PointF(inputImg.Width, inputImg.Height)}; //Rotate the corners PointMath.RotatePoints(rotationPoints, new PointF(inputImg.Width / 2.0f, inputImg.Height / 2.0f), degreeAngle); //Get the new bounds given from the rotation of the corners //(avoid clipping of the image) Rectangle bounds = PointMath.GetBounds(rotationPoints); //An empy bitmap to draw the rotated image Bitmap rotatedBitmap = new Bitmap(bounds.Width, bounds.Height); using (Graphics g = Graphics.FromImage(rotatedBitmap)) { g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; //Transformation matrix System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix(); m.RotateAt((float)degreeAngle, new PointF(inputImg.Width / 2.0f, inputImg.Height / 2.0f)); m.Translate(-bounds.Left, -bounds.Top, System.Drawing.Drawing2D.MatrixOrder.Append); //shift to compensate for the rotation g.Transform = m; g.DrawImage(inputImg, 0, 0); } return (Image)rotatedBitmap; }
/// <summary> /// Update function of map. Calls Bayes filtering and handles the rotation and translation of all map objects. /// </summary> private void Update(object sender, EventArgs e) { lock (robot.mapLock) { Bayes(true, preySensor, ref preyProbability); Bayes(false, obstacleSensor, ref obstacleProbability); bBayes = new Bitmap(bMap.Size.Width, bMap.Size.Height); SetNewRovioPosition(); // Run AStar if there is a suitable destination and draw it on the map. using (graphics = Graphics.FromImage(bBayes)) { AStar astar = new AStar(finalMap.GetLength(0), finalMap.GetLength(1)); astar.Build(finalMap, new DPoint(destination.X, destination.Y), new DPoint((picBoxRovio.Location.X / 10) + (picBoxRovio.Width / 10 / 2), picBoxRovio.Location.Y / 10)); aStarPath = astar.path; for (int i = 0; i < maxX; i++) { for (int j = 0; j < maxY; j++) { graphics.FillRectangle(new SolidBrush(DColor.FromArgb((int)(preyProbability[i, j] * 255), System.Drawing.Color.DarkRed)), new DRectangle(i * 10, j * 10, 10, 10)); graphics.FillRectangle(new SolidBrush(DColor.FromArgb((int)(obstacleProbability[i, j] * 255), System.Drawing.Color.DarkBlue)), new DRectangle(i * 10, j * 10, 10, 10)); if (astar.inPath[i, j]) graphics.FillRectangle(new SolidBrush(DColor.Red), new DRectangle(i * 10, j * 10, 10, 10)); } } } picBoxBayes.Image = bBayes; // Check which cells are within the viewing cone. if (viewConePoints != null) { for (int i = 0; i < maxX; i++) { for (int j = 0; j < maxY; j++) { DPoint a = new DPoint(i * 10 + 1, j * 10 + 1); // Top left DPoint b = new DPoint((i + 1) * 10 - 1, j * 10 + 1); // Top right DPoint c = new DPoint(i * 10 + 1, (j + 1) * 10 - 1); // Bottom left DPoint d = new DPoint((i + 1) * 10 - 1, (j + 1) * 10 - 1); // Bottom right if (!(PointInPolygon(a, viewConePoints) || PointInPolygon(b, viewConePoints) || PointInPolygon(c, viewConePoints) || PointInPolygon(d, viewConePoints))) { isCellVisible[i, j] = false; } else { preySensor[i, j] = false; obstacleSensor[i, j] = false; isCellVisible[i, j] = true; } } } } if (robot.GetType() == typeof(Rovio.PredatorMap)) { if (robot.IsPreySeen()) { FindRelativeLocation(picBoxPrey, robot.preyRectangle, robot.GetPreyDistance(), 1, 1); try { preySensor[(int)((picBoxPrey.Location.X / 10) + 1.5), (int)((picBoxPrey.Location.Y / 10) + 1.5)] = true; } catch { } } else picBoxPrey.Hide(); if ((robot as Rovio.BaseArena).IsObstacleSeen()) { // Find obstacle position relative to the Rovio's position. FindRelativeLocation(picBoxObstacle, robot.obstacleRectangle, robot.GetObstacleDistance(), 40, 3); try { int p = (int)((picBoxObstacle.Location.X / 10) + 0.5); int q = (int)((picBoxObstacle.Location.Y / 10) + 0.5); // Populate 3x3 area with the obstacle. for (int i = -1; i <= 1; i++) for (int j = -1; j <= 1; j++) obstacleSensor[(int)((picBoxObstacle.Location.X / 10) + i), (int)((picBoxObstacle.Location.Y / 10) + j)] = true; } catch { } } else picBoxObstacle.Hide(); } // Rotate the Rovio icon to the angle that the robot physically faces. System.Drawing.Drawing2D.Matrix matrixRovio = new System.Drawing.Drawing2D.Matrix(); matrixRovio.RotateAt((float)robot.cumulativeAngle, new System.Drawing.Point(picBoxRovio.Location.X + (picBoxRovio.Size.Width / 2), picBoxRovio.Location.Y + (picBoxRovio.Size.Height / 2))); matrixRovio.Translate(0f, -0f); DPoint[] rovioMovementPoints = {new DPoint(picBoxRovio.Location.X+(picBoxRovio.Size.Width/2), picBoxRovio.Location.Y + (picBoxRovio.Size.Height/2)), new DPoint(picBoxRovio.Location.X+(picBoxRovio.Size.Width/2) - 69, picBoxRovio.Location.Y-150), new DPoint(picBoxRovio.Location.X+(picBoxRovio.Size.Width/2) + 69, picBoxRovio.Location.Y-150)}; matrixRovio.TransformPoints(rovioMovementPoints); if ((robot as Rovio.BaseArena).IsObstacleSeen()) { // Get the left and right points of the obstacle in the viewing cone and orientate accordingly. DPoint leftPoint = new DPoint(picBoxObstacle.Location.X - (picBoxObstacle.Width / 2), picBoxObstacle.Location.Y - 15); DPoint rightPoint = leftPoint; using (matrix = new System.Drawing.Drawing2D.Matrix()) { matrix.RotateAt((float)robot.cumulativeAngle, leftPoint); matrix.Translate(0, -0f); DPoint[] tempPointArr = { leftPoint }; matrix.TransformPoints(tempPointArr); leftPoint = tempPointArr[0]; // Transform the right point relative to the position of the left. matrix = new System.Drawing.Drawing2D.Matrix(); matrix.RotateAt((float)robot.cumulativeAngle, leftPoint); matrix.Translate(30, 0); tempPointArr[0] = new DPoint(0, 0); matrix.TransformPoints(tempPointArr); rightPoint = tempPointArr[0]; } // Check if all points are still within the viewing cone. If not, skip over them. if (PointInPolygon(leftPoint, rovioMovementPoints) && PointInPolygon(rightPoint, rovioMovementPoints)) rovioMovementPoints = new DPoint[] { rovioMovementPoints[0], rovioMovementPoints[1], leftPoint, rightPoint, rovioMovementPoints[2] }; } viewConePoints = rovioMovementPoints; Bitmap rotated = new Bitmap(bRovio.Width + 70, bRovio.Height + 70); rotated.SetResolution(bRovio.HorizontalResolution, bRovio.VerticalResolution); using (graphics = Graphics.FromImage(rotated)) { graphics.TranslateTransform(bRovio.Width / 2, bRovio.Height / 2); graphics.RotateTransform((float)robot.cumulativeAngle); graphics.TranslateTransform(-bRovio.Width / 2, -bRovio.Height / 2); graphics.DrawImage(bRovio, new DPoint(0, 0)); picBoxRovio.Size = new Size(27, 24); picBoxRovio.Image = rotated; picBoxCone.Location = new DPoint(picBoxRovio.Location.X - (bCone.Width / 2) + (bRovio.Width / 2), picBoxRovio.Location.Y - bCone.Height + (bRovio.Height / 2)); picBoxCone.Size = new Size(900, 500); picBoxCone.Image = rotated; picBoxCone.Location = new DPoint(0, 0); picBoxCone.Size = new Size(260, 300); } Bitmap newCone = new Bitmap(260, 300); using (graphics = Graphics.FromImage(newCone)) { graphics.FillPolygon(new SolidBrush(DColor.FromArgb(100, DColor.ForestGreen)), viewConePoints); picBoxCone.Image = newCone; } } }
private static SharpMap.Map InitializeVRT(ref int index, float angle) { SharpMap.Map map = new SharpMap.Map(); int ind = index - 6; if (ind >= Vrts.Length) ind = 0; if (!System.IO.File.Exists(RelativePath + Vrts[ind])) { throw new System.Exception("Make sure the data is in the relative directory: " + RelativePath); } SharpMap.Layers.GdalRasterLayer layer = new SharpMap.Layers.GdalRasterLayer("VirtualRasterTable", RelativePath + Vrts[ind]); var ext = System.IO.Path.GetExtension(layer.Filename); map.Layers.Add(layer); _gdalSampleDataset = string.Format("'{0}'", ext != null ? ext.ToUpper() : string.Empty); map.ZoomToExtents(); System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix(); mat.RotateAt(angle, map.WorldToImage(map.Center)); map.MapTransform = mat; //index++; return map; }
/// <summary> /// Find location of PicBox relative to the Rovio. /// </summary> /// <param name="picBox">Picture box to check.</param> /// <param name="rect">Rectangle of the picture box's object on screen</param> /// <param name="distance">Distance to object</param> /// <param name="multiplierOne">First multiplier to change X position by.</param> /// <param name="multiplierTwo">Second multiplier to change X position by.</param> private void FindRelativeLocation(PictureBox picBox, DRectangle rect, double distance, int multiplierOne, int multiplierTwo) { picBox.Location = new System.Drawing.Point(picBoxRovio.Location.X + rect.X + rect.Width, picBoxRovio.Location.Y - (int)(distance * 20 * 3)); double totalFOV = distance * 100 * 0.93; double percentage = rect.X / (double)robot.cameraDimensions.X * 100; double newX = percentage * (totalFOV / 100); DPoint newPosition = new System.Drawing.Point(picBoxRovio.Location.X - ((int)totalFOV / 2) + (int)newX*2, picBox.Location.Y); using (matrix = new System.Drawing.Drawing2D.Matrix()) { matrix.RotateAt((float)robot.cumulativeAngle, new System.Drawing.Point(picBoxRovio.Location.X + (picBoxRovio.Size.Width / 2), picBoxRovio.Location.Y + (picBoxRovio.Size.Height / 2))); matrix.Translate((float)-newX + 30f, -(float)(distance * multiplierOne * multiplierTwo)); DPoint[] aPoints = { newPosition }; matrix.TransformPoints(aPoints); picBox.Location = aPoints[0]; } }
private static SharpMap.Map InitializeGeoTiff(int index, float angle) { try { //Sample provided by Dan Brecht and Joel Wilson var map = new SharpMap.Map(); map.BackColor = System.Drawing.Color.White; const string relativePath = "GeoData/GeoTiff/"; SharpMap.Layers.GdalRasterLayer layer; switch (index) { case 2: layer = new SharpMap.Layers.GdalRasterLayer("GeoTiff", relativePath + "utm.tif"); layer.UseRotation = true; map.Layers.Add(layer); break; case 3: layer = new SharpMap.Layers.GdalRasterLayer("GeoTiff", relativePath + "utm.jp2"); layer.UseRotation = true; map.Layers.Add(layer); break; case 4: layer = new SharpMap.Layers.GdalRasterLayer("GeoTiff", relativePath + "world_raster_mod.tif"); layer.UseRotation = true; map.Layers.Add(layer); break; default: if (!System.IO.File.Exists(relativePath + "format01-image_a.tif")) { throw new System.Exception("Make sure the data is in the relative directory: " + relativePath); } layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffA", relativePath + "format01-image_a.tif"); map.Layers.Add(layer); layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffB", relativePath + "format01-image_b.tif"); map.Layers.Add(layer); layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffC", relativePath + "format01-image_c.tif"); map.Layers.Add(layer); layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffD", relativePath + "format01-image_d.tif"); map.Layers.Add(layer); SharpMap.Layers.VectorLayer shapeLayer; if (!System.IO.File.Exists(relativePath + "outline.shp")) { throw new System.Exception("Make sure the data is in the relative directory: " + relativePath); } shapeLayer = new SharpMap.Layers.VectorLayer("outline", new SharpMap.Data.Providers.ShapeFile(relativePath + "outline.shp")); shapeLayer.Style.Fill = System.Drawing.Brushes.Transparent; shapeLayer.Style.Outline = System.Drawing.Pens.Black; shapeLayer.Style.EnableOutline = true; shapeLayer.Style.Enabled = true; map.Layers.Add(shapeLayer); break; } map.ZoomToExtents(); System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix(); mat.RotateAt(angle, map.WorldToImage(map.Center)); map.MapTransform = mat; if (_num > 5) _num = 1; _gdalSampleDataset = "GeoTiff" + _num; return map; } catch (System.TypeInitializationException ex) { if (ex.Message == "The type initializer for 'OSGeo.GDAL.GdalPINVOKE' threw an exception.") { throw new System.Exception( string.Format( "The application threw a PINVOKE exception. You probably need to copy the unmanaged dll's to your bin directory. They are a part of fwtools {0}. You can download it from: http://home.gdal.org/fwtools/", SharpMap.Layers.GdalRasterLayer.FWToolsVersion)); } throw; } }
public void Draw2dTextures(Draw2dData[] todraw, int textureid, float angle) { GL.PushAttrib(AttribMask.ColorBufferBit); GL.BindTexture(TextureTarget.Texture2D, textureid); GL.Enable(EnableCap.Texture2D); GL.Disable(EnableCap.DepthTest); VertexPositionTexture[] vertices; ushort[] indices; if (todraw.Length >= draw2dtexturesMAX) { vertices = new VertexPositionTexture[todraw.Length * 4]; indices = new ushort[todraw.Length * 4]; } else { if (draw2dtexturesVertices == null) { draw2dtexturesVertices = new VertexPositionTexture[draw2dtexturesMAX * 4]; draw2dtexturesIndices = new ushort[draw2dtexturesMAX * 4]; } vertices = draw2dtexturesVertices; indices = draw2dtexturesIndices; } ushort i = 0; foreach (Draw2dData v in todraw) { RectangleF rect; if (v.inAtlasId == null) { rect = new RectangleF(0, 0, 1, 1); } else { rect = TextureAtlas.TextureCoords2d(v.inAtlasId.Value, d_Terrain.texturesPacked); } float x2 = v.x1 + v.width; float y2 = v.y1 + v.height; PointF[] pnts = new PointF[4] { new PointF(x2, y2), new PointF(x2,v.y1), new PointF(v.x1,v.y1), new PointF(v.x1,y2)}; if (angle != 0) { System.Drawing.Drawing2D.Matrix mx=new System.Drawing.Drawing2D.Matrix(); mx.RotateAt(angle, new PointF(v.x1+v.width/2,v.y1+v.height/2)); mx.TransformPoints(pnts); } vertices[i] = new VertexPositionTexture(pnts[0].X, pnts[0].Y, 0, rect.Right, rect.Bottom, v.color); vertices[i + 1] = new VertexPositionTexture(pnts[1].X, pnts[1].Y, 0, rect.Right, rect.Top, v.color); vertices[i + 2] = new VertexPositionTexture(pnts[2].X, pnts[2].Y, 0, rect.Left, rect.Top, v.color); vertices[i + 3] = new VertexPositionTexture(pnts[3].X, pnts[3].Y, 0, rect.Left, rect.Bottom, v.color); indices[i] = i; indices[i + 1] = (ushort)(i + 1); indices[i + 2] = (ushort)(i + 2); indices[i + 3] = (ushort)(i + 3); i += 4; } GL.EnableClientState(ArrayCap.TextureCoordArray); GL.EnableClientState(ArrayCap.VertexArray); GL.EnableClientState(ArrayCap.ColorArray); unsafe { fixed (VertexPositionTexture* p = vertices) { GL.VertexPointer(3, VertexPointerType.Float, StrideOfVertices, (IntPtr)(0 + (byte*)p)); GL.TexCoordPointer(2, TexCoordPointerType.Float, StrideOfVertices, (IntPtr)(12 + (byte*)p)); GL.ColorPointer(4, ColorPointerType.UnsignedByte, StrideOfVertices, (IntPtr)(20 + (byte*)p)); GL.DrawElements(BeginMode.Quads, i, DrawElementsType.UnsignedShort, indices); } } GL.DisableClientState(ArrayCap.TextureCoordArray); GL.DisableClientState(ArrayCap.VertexArray); GL.DisableClientState(ArrayCap.ColorArray); GL.Enable(EnableCap.DepthTest); GL.PopAttrib(); }
public Bitmap getImage(String fileName, int scaledResolution) { Bitmap source = null; Bitmap result = null; try { // Read the source image file and scale with temp image, store back // to source source = new Bitmap(Image.FromFile(fileName)); BlackInvalidArea(source); result = new Bitmap(source.Width, source.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); Graphics tempContext = Graphics.FromImage(result); //set the InterpolationMode to HighQualityBicubic to ensure a high //quality image once it is transformed tempContext.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; tempContext.Clear(Color.Black); // Setup rotation float rotationAngle = getImageRotationAngle(source); System.Drawing.Drawing2D.Matrix rotateMatrix = new System.Drawing.Drawing2D.Matrix(); rotateMatrix.RotateAt(rotationAngle, new Point(result.Width / 2, result.Height / 2)); tempContext.Transform = rotateMatrix; tempContext.DrawImage(source, 0, 0); tempContext.Flush(); tempContext.Dispose(); float chirality = getChirality(source); if (chirality < 0) { // flip the image int w = result.Width; int h = result.Height; source = new Bitmap(scaledResolution, scaledResolution, System.Drawing.Imaging.PixelFormat.Format24bppRgb); Graphics resultContext = Graphics.FromImage(source); resultContext.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; //Flip image horizontally result.RotateFlip(RotateFlipType.RotateNoneFlipX); resultContext.DrawImage(result, 0, 0, scaledResolution, scaledResolution); } else { source = new Bitmap(scaledResolution, scaledResolution, System.Drawing.Imaging.PixelFormat.Format24bppRgb); Graphics resultContext = Graphics.FromImage(source); resultContext.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; resultContext.DrawImage(result, 0, 0, scaledResolution, scaledResolution); } } catch (Exception ex) { Console.Write("Failed to open: " + fileName + ", " + ex.ToString()); } return source; }
public static SharpMap.Map InitializeMap(float angle) { //Initialize a new map of size 'imagesize' SharpMap.Map map = new SharpMap.Map(); //Set up the countries layer SharpMap.Layers.VectorLayer layCountries = new SharpMap.Layers.VectorLayer("Countries"); //Set the datasource to a shapefile in the App_data folder layCountries.DataSource = new SharpMap.Data.Providers.SpatiaLite( DataSource, "countries", "geom", "PK_UID"); //Set fill-style to green layCountries.Style.Fill = new System.Drawing.SolidBrush(System.Drawing.Color.Green); //Set the polygons to have a black outline layCountries.Style.Outline = System.Drawing.Pens.Black; layCountries.Style.EnableOutline = true; //Set up a river layer SharpMap.Layers.VectorLayer layRivers = new SharpMap.Layers.VectorLayer("Rivers"); //Set the datasource to a shapefile in the App_data folder layRivers.DataSource = new SharpMap.Data.Providers.SpatiaLite( DataSource, "rivers", "geom", "PK_UID"); //Define a blue 3px wide pen layRivers.Style.Line = new System.Drawing.Pen(System.Drawing.Color.LightBlue, 2); layRivers.Style.Line.CompoundArray = new[] { 0.2f, 0.8f }; layRivers.Style.Outline = new System.Drawing.Pen(System.Drawing.Color.DarkBlue, 3); layRivers.Style.EnableOutline = true; //Set up a cities layer SharpMap.Layers.VectorLayer layCities = new SharpMap.Layers.VectorLayer("Cities"); //Set the datasource to the spatialite table layCities.DataSource = new SharpMap.Data.Providers.SpatiaLite( DataSource, "cities", "geom", "PK_UID"); layCities.Style.SymbolScale = 0.8f; layCities.MaxVisible = 40; //Set up a country label layer SharpMap.Layers.LabelLayer layLabel = new SharpMap.Layers.LabelLayer("Country labels") { DataSource = layCountries.DataSource, LabelColumn = "NAME", MultipartGeometryBehaviour = SharpMap.Layers.LabelLayer.MultipartGeometryBehaviourEnum.Largest, LabelFilter = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection, PriorityColumn = "POPDENS", Style = new SharpMap.Styles.LabelStyle { ForeColor = System.Drawing.Color.White, Font = new System.Drawing.Font(System.Drawing.FontFamily.GenericSerif, 12), BackColor = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(128, 255, 0, 0)), HorizontalAlignment = SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Center, MaxVisible = 90, MinVisible = 30, CollisionDetection = true } }; //Set up a city label layer SharpMap.Layers.LabelLayer layCityLabel = new SharpMap.Layers.LabelLayer("City labels") { DataSource = layCities.DataSource, LabelColumn = "name", PriorityColumn = "population", PriorityDelegate = delegate(SharpMap.Data.FeatureDataRow fdr) { System.Int32 retVal = 10000000 * ( (System.String)fdr["capital"] == "Y" ? 1 : 0 ); return retVal + System.Convert.ToInt32(fdr["population"]); }, TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias, SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias, LabelFilter = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection, Style = new SharpMap.Styles.LabelStyle { ForeColor = System.Drawing.Color.Black, Font = new System.Drawing.Font(System.Drawing.FontFamily.GenericSerif, 11), MaxVisible = layLabel.MinVisible, HorizontalAlignment = SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Left, VerticalAlignment = SharpMap.Styles.LabelStyle.VerticalAlignmentEnum.Bottom, Offset = new System.Drawing.PointF(3, 3), Halo = new System.Drawing.Pen(System.Drawing.Color.Yellow, 2), CollisionDetection = true } }; var layRiverLabels = new SharpMap.Layers.LabelLayer("RiverLabels"); layRiverLabels.DataSource = layRivers.DataSource; layRiverLabels.LabelColumn = "Name"; layRiverLabels.PriorityDelegate = GetRiverLength; layRiverLabels.Style = new SharpMap.Styles.LabelStyle { Font = new System.Drawing.Font("Arial", 10, System.Drawing.FontStyle.Bold), Halo = new System.Drawing.Pen(System.Drawing.Color.Azure, 2), ForeColor = System.Drawing.Color.DarkCyan, IgnoreLength = true, Enabled = true, CollisionDetection = true, }; layRiverLabels.LabelFilter = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection; //Add the layers to the map object. //The order we add them in are the order they are drawn, so we add the rivers last to put them on top map.Layers.Add(layCountries); map.Layers.Add(layRivers); map.Layers.Add(layCities); map.Layers.Add(layRiverLabels); map.Layers.Add(layLabel); map.Layers.Add(layCityLabel); //limit the zoom to 360 degrees width map.MaximumZoom = 360; map.BackColor = System.Drawing.Color.LightBlue; map.ZoomToExtents(); // = 360; //map.Center = new SharpMap.Geometries.Point(0, 0); var mat = new System.Drawing.Drawing2D.Matrix(); mat.RotateAt(angle, map.WorldToImage(map.Center)); map.MapTransform = mat; return map; }
internal static SharpMap.Map InitializeMap(float angle, string[] filenames) { var map = new SharpMap.Map(); try { foreach (var filename in filenames) { var connectionString = string.Format("Data Source={0}", filename); foreach (var provider in SharpMap.Data.Providers.SpatiaLite.GetSpatialTables(connectionString)) { map.Layers.Add( new SharpMap.Layers.VectorLayer( string.Format("{0} - {1}", provider.Table, provider.GeometryColumn), provider) { Style = LayerTools.GetRandomVectorStyle() }); } } if (map.Layers.Count > 0) { map.ZoomToExtents(); System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix(); mat.RotateAt(angle, map.WorldToImage(map.Center)); map.MapTransform = mat; return map; } } catch (System.Exception ex) { System.Diagnostics.Trace.WriteLine(ex.Message); } return null; }
public static SharpMap.Map InitializeMap(float angle) { using (var ofn = new System.Windows.Forms.OpenFileDialog()) { ofn.Filter = "All files|*.*"; ofn.FilterIndex = 0; if (ofn.ShowDialog() == System.Windows.Forms.DialogResult.OK) { var m = new SharpMap.Map(); var l = new SharpMap.Layers.GdiImageLayer(ofn.FileName); m.Layers.Add(l); m.ZoomToExtents(); var mat = new System.Drawing.Drawing2D.Matrix(); mat.RotateAt(angle, m.WorldToImage(m.Center)); m.MapTransform = mat; m.MaximumExtents = m.GetExtents(); m.EnforceMaximumExtents = true; return m; } } return null; }