private void setExtraButtonPositon(HOVERMOUSEPOSITION position) { System.Drawing.Drawing2D.GraphicsPath shape = (System.Drawing.Drawing2D.GraphicsPath)fieldButton1.getShape().Clone(); System.Drawing.Point tPoint = savedLocation; switch (position) { //first check cases with 1 additional button case HOVERMOUSEPOSITION.BOTTOM: this.Location = tPoint; shape.Transform(rotMatrix); //rotate fieldButton1.Location = new Point(0, 0); extraButtons.ElementAt(0).setShape(shape); extraButtons.ElementAt(0).Location = new Point(0, 87); break; case HOVERMOUSEPOSITION.TOP: tPoint.Offset(new Point(0, -87)); this.Location = tPoint; shape.Transform(rotMatrix); //rotate secondary shape fieldButton1.Location = new Point(0, 87); //shift mainbutton down extraButtons.ElementAt(0).setShape(shape); //set new shape for secondary button extraButtons.ElementAt(0).Location = new Point(0, 0); //set secondary button to top break; case HOVERMOUSEPOSITION.RIGHT: this.Location = tPoint; shape.Transform(rotMatrix); //rotate fieldButton1.Location = new Point(0, 0); extraButtons.ElementAt(0).setShape(shape); extraButtons.ElementAt(0).Location = new Point(50, 0); break; case HOVERMOUSEPOSITION.LEFT: tPoint.Offset(new Point(-50, 0)); this.Location = tPoint; shape.Transform(rotMatrix); //rotate fieldButton1.Location = new Point(50, 0); extraButtons.ElementAt(0).setShape(shape); extraButtons.ElementAt(0).Location = new Point(0, 0); break; case HOVERMOUSEPOSITION.DOWN: break; case HOVERMOUSEPOSITION.UP: break; case HOVERMOUSEPOSITION.CENTER: break; } Invalidate(); }
/// <summary> /// Draw curves on graphics with transform and given pen /// </summary> static void DrawCurves( Graphics graphics, List<PointF[]> curves, System.Drawing.Drawing2D.Matrix transform, Pen pen) { foreach( PointF[] curve in curves ) { System.Drawing.Drawing2D.GraphicsPath gPath = new System.Drawing.Drawing2D.GraphicsPath(); if( curve.Length == 0 ) { break; } if( curve.Length == 1 ) { gPath.AddArc( new RectangleF( curve[0], new SizeF( 0.5f, 0.5f ) ), 0.0f, (float) Math.PI ); } else { gPath.AddLines( curve ); } if( transform != null ) gPath.Transform( transform ); graphics.DrawPath( pen, gPath ); } }
public override bool HitTest(System.Drawing.PointF point, float precisionDelta) { bool result = false; if (_pen != null || _brush != null) { using (System.Drawing.Drawing2D.GraphicsPath actualPath = (System.Drawing.Drawing2D.GraphicsPath) this.Path.Clone()) { actualPath.Transform(_matrix); if (_pen != null) { using (System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Black, _pen.Width + precisionDelta)) result = actualPath.IsOutlineVisible(point, pen); } if (!result && _brush != null) { result = actualPath.IsVisible(point); } } } return(result); }
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 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)); }
void RenderWithGdiPlusPath(Typeface typeface, char testChar, float sizeInPoint, int resolution) { //render glyph path with Gdi+ path g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.Clear(Color.White); //////credit: //////http://stackoverflow.com/questions/1485745/flip-coordinates-when-drawing-to-control g.ScaleTransform(1.0F, -1.0F); // Flip the Y-Axis g.TranslateTransform(0.0F, -(float)300); // Translate the drawing area accordingly //---------------------------------------------------- var builder = new MyGlyphPathBuilder(typeface); var hintTech = (HintTechnique)cmbHintTechnique.SelectedItem; builder.UseTrueTypeInstructions = false; //reset builder.UseVerticalHinting = false; //reset switch (hintTech) { case HintTechnique.TrueTypeInstruction: builder.UseTrueTypeInstructions = true; break; case HintTechnique.TrueTypeInstruction_VerticalOnly: builder.UseTrueTypeInstructions = true; builder.UseVerticalHinting = true; break; case HintTechnique.CustomAutoFit: //custom agg autofit break; } //---------------------------------------------------- builder.Build(testChar, sizeInPoint); var gdiPathBuilder = new GlyphPathBuilderGdi(); builder.ReadShapes(gdiPathBuilder); float pxScale = builder.GetPixelScale(); System.Drawing.Drawing2D.GraphicsPath path = gdiPathBuilder.ResultGraphicPath; path.Transform( new System.Drawing.Drawing2D.Matrix( pxScale, 0, 0, pxScale, 0, 0 )); if (chkFillBackground.Checked) { g.FillPath(Brushes.Black, path); } if (chkBorder.Checked) { g.DrawPath(Pens.Green, path); } //transform back g.ScaleTransform(1.0F, -1.0F); // Flip the Y-Axis g.TranslateTransform(0.0F, -(float)300); // Translate the drawing area accordingly }
// 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; } } }
private void MirrorPath(System.Drawing.Drawing2D.GraphicsPath GraphicPath) { System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix(); m.Translate(0, Height - 1); m.Scale(1, -1); GraphicPath.Transform(m); m.Dispose(); }
/// <summary> /// flowLayoutPanelMarker的鼠标滚动事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void flowLayoutPanelMarker_MouseWheel(Object sender, MouseEventArgs e) { try { if (flowLayoutPanelMarker.Focused) { Int32 numberOfTextLinesToMove = Math.Abs(e.Delta * SystemInformation.MouseWheelScrollLines / 200) % 10; Int32 numberOfPixelsToMove = numberOfTextLinesToMove * flowLayoutPanelMarker.Size.Height; if (numberOfPixelsToMove != 0) { System.Drawing.Drawing2D.Matrix translateMatrix = new System.Drawing.Drawing2D.Matrix(); translateMatrix.Translate(0, numberOfPixelsToMove); mousePath.Transform(translateMatrix); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public override bool HitTest(System.Drawing.PointF point, float precisionDelta) { bool result = false; using (System.Drawing.Drawing2D.GraphicsPath boundsPath = (System.Drawing.Drawing2D.GraphicsPath)_boundsPath.Clone()) { boundsPath.Transform(base.Transform); result = boundsPath.IsVisible(point); } return(result); }
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; gp.AddLine(X, Y, X + m_Size.Width, Y + m_Size.Height); 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 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(); gp.AddRectangle(new System.Drawing.Rectangle(this.m_Position.X - (int)(0.25 * this.m_Size.Width), this.m_Position.Y - (int)(0.25 * this.m_Size.Height), (int)(1.25 * this.m_Size.Width), (int)(1.25 * this.m_Size.Height))); 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); return(gp.IsVisible(pt)); }
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { System.Drawing.Point[] DropPoints = new System.Drawing.Point[] { new Point(0, 0), new Point(11, 0), new Point(5, 6) }; System.Drawing.Point[] ClosePoints = new System.Drawing.Point[] { new Point(0, 0), new Point(2, 0), new Point(5, 3), new Point(8, 0), new Point(10, 0), new Point(6, 4), new Point(10, 8), new Point(8, 8), new Point(5, 5), new Point(2, 8), new Point(0, 8), new Point(4, 4) }; Rectangle rec = new Rectangle(); rec.Size = new Size(this.Width - 1, this.Height - 1); if (m_hot) { e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; e.Graphics.FillRectangle(new System.Drawing.Drawing2D.LinearGradientBrush(new Point(0, 0), new Point(0, this.Height), Helper.RenderColors.ControlButtonBackHighColor(m_RenderMode, m_BackHighColor), Helper.RenderColors.ControlButtonBackLowColor(m_RenderMode, m_BackLowColor)), rec); e.Graphics.DrawRectangle(new Pen(Helper.RenderColors.ControlButtonBorderColor(m_RenderMode, m_BorderColor)), rec); e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default; } System.Drawing.Drawing2D.GraphicsPath g = new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix(); int x = (int)((this.Width - 11) / 2); int y = (int)((this.Height - 11) / 2 + 1); if (m_style == ButtonStyle.Drop) { e.Graphics.FillRectangle(new SolidBrush(ForeColor), x, y, 11, 2); g.AddPolygon(DropPoints); m.Translate(x, y + 3); g.Transform(m); e.Graphics.FillPolygon(new SolidBrush(ForeColor), g.PathPoints); } else { g.AddPolygon(ClosePoints); m.Translate(x, y); g.Transform(m); e.Graphics.DrawPolygon(new Pen(ForeColor), g.PathPoints); e.Graphics.FillPolygon(new SolidBrush(ForeColor), g.PathPoints); } g.Dispose(); m.Dispose(); }
public virtual bool HitTest(System.Drawing.Rectangle rect) {//is this object contained within the supplied rectangle System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.Drawing2D.Matrix myMatrix = new System.Drawing.Drawing2D.Matrix(); gp.AddRectangle(new System.Drawing.Rectangle(this.m_Position.X, this.m_Position.Y, this.m_Size.Width, this.m_Size.Height)); if (this.m_Rotation != 0) { myMatrix.RotateAt((float)this.m_Rotation, new System.Drawing.PointF((float)this.m_Position.X, (float)this.m_Position.Y), System.Drawing.Drawing2D.MatrixOrder.Append); } gp.Transform(myMatrix); System.Drawing.Rectangle gpRect = System.Drawing.Rectangle.Round(gp.GetBounds()); return(rect.Contains(gpRect)); }
private void panel1_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e) { // Update the drawing based upon the mouse wheel scrolling. int numberOfTextLinesToMove = e.Delta * SystemInformation.MouseWheelScrollLines / 120; int numberOfPixelsToMove = numberOfTextLinesToMove * fontSize; if (numberOfPixelsToMove != 0) { System.Drawing.Drawing2D.Matrix translateMatrix = new System.Drawing.Drawing2D.Matrix(); translateMatrix.Translate(0, numberOfPixelsToMove); mousePath.Transform(translateMatrix); } panel1.Invalidate(); }
private System.Drawing.Drawing2D.GraphicsPath CreateViewportPath(ICoordinateMapper coordinateMapper) { System.Drawing.Drawing2D.GraphicsPath result = (System.Drawing.Drawing2D.GraphicsPath) this.Path.Clone(); result.Transform(_matrix); System.Drawing.RectangleF pathBounds = this.Path.GetBounds(_matrix); System.Drawing.Rectangle mappedBounds = coordinateMapper.WorkspaceToControl(pathBounds, Aurigma.GraphicsMill.Unit.Point); if (pathBounds.Width > VObject.Eps && pathBounds.Height > VObject.Eps) { float scaleX = (float)mappedBounds.Width / pathBounds.Width, scaleY = (float)mappedBounds.Height / pathBounds.Height; using (System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix()) { m.Translate(mappedBounds.X, mappedBounds.Y); m.Scale(scaleX, scaleY); m.Translate(-pathBounds.X, -pathBounds.Y); result.Transform(m); } } return(result); }
public override void DrawGlyphPlanList(List <GlyphPlan> glyphPlanList, int startAt, int len, float x, float y) { UpdateVisualOutputSettings(); //draw data in glyph plan //3. render each glyph System.Drawing.Drawing2D.Matrix scaleMat = null; float sizeInPoints = this.FontSizeInPoints; float scale = _currentTypeface.CalculateFromPointToPixelScale(sizeInPoints); //this draw a single line text span*** int endBefore = startAt + len; Graphics g = this.TargetGraphics; for (int i = startAt; i < endBefore; ++i) { GlyphPlan glyphPlan = glyphPlanList[i]; _currentGlyphPathBuilder.BuildFromGlyphIndex(glyphPlan.glyphIndex, sizeInPoints); // scaleMat = new System.Drawing.Drawing2D.Matrix( 1, 0, //scale x 0, 1, //scale y x + glyphPlan.x * scale, y + glyphPlan.y * scale //xpos,ypos ); // _txToGdiPath.Reset(); _currentGlyphPathBuilder.ReadShapes(_txToGdiPath); System.Drawing.Drawing2D.GraphicsPath path = _txToGdiPath.ResultGraphicsPath; path.Transform(scaleMat); if (FillBackground) { g.FillPath(_fillBrush, path); } if (DrawOutline) { g.DrawPath(_outlinePen, path); } } }
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 int DrawCategoryOntoHorizontalAxis(Categories categories, Graphics g, Brush brush, Rdl.Runtime.Context context, Axis axis, bool centered, int level, int left, int top, int w, List <int> majorMarks, List <int> minorMarks) { Font font = axis.Style.GetWindowsFont(context); float yMult = (float)g.DpiY / 72; // Determine if the labels need to be vertical and find the height required for the labels. bool vertical = false; int labelHeight = (int)(font.Height * yMult); int adjustment = (centered) ? 0 : 1; foreach (Category cat in categories) { SizeF size = g.MeasureString(cat.Value, font); // Find the total members below this point. int membersAtThisPoint = 1; if (cat.Categories != null) { membersAtThisPoint = cat.Categories.LeafCategories.Count; } // If we exceed the available width then go to vertical labels. if (_totalCategories > 1 && size.Width > (w * membersAtThisPoint / (_totalCategories - adjustment))) { vertical = true; foreach (Category cat2 in categories) { size = g.MeasureString(cat2.Value, font, 0, new StringFormat(StringFormatFlags.DirectionVertical)); labelHeight = Math.Max(labelHeight, (int)size.Height); } break; } labelHeight = Math.Max(labelHeight, (int)size.Height); } //Draw the labels at this category level. int totalHeight = labelHeight; foreach (Category cat in categories) { // Find the total members below this point. int membersAtThisPoint = 1; if (cat.Categories != null) { membersAtThisPoint = cat.Categories.LeafCategories.Count; } // Find the width of this group entry int groupEntryWidth = w; if (_totalCategories > 1) { groupEntryWidth = (int)(membersAtThisPoint * w / (_totalCategories - adjustment)); } // Measure the space needed for the label //SizeF size = g.MeasureString(cat.Value, font, 0, (vertical) ? new StringFormat(StringFormatFlags.DirectionVertical) : StringFormat.GenericDefault); SizeF size = g.MeasureString(cat.Value, font, 0, StringFormat.GenericDefault); int center = left; if (centered) { center += groupEntryWidth / 2; } if (vertical) { System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddString(cat.Value, font.FontFamily, (int)font.Style, font.Size * yMult, new Point(center - ((int)size.Width / 2), top), StringFormat.GenericDefault); if (vertical) { System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix(); matrix.Translate(0 - (size.Width / 2), 0); matrix.RotateAt(-30, new PointF(center, top), System.Drawing.Drawing2D.MatrixOrder.Append); path.Transform(matrix); } g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.DrawPath(new Pen(brush), path); } else { g.DrawString(cat.Value, font, brush, center - (int)size.Width / 2, top, StringFormat.GenericDefault); } // Draw this label. //if (vertical) //{ // g.TranslateTransform(0, size.Width); // g.RotateTransform(-30); //} //g.DrawString(cat.Value, font, brush, center - size.Width / 2, top, StringFormat.GenericDefault); //return totalHeight; //g.ResetTransform(); // Add in the tick mark position for this entry. if (level == 0) { majorMarks.Add(left); } else { minorMarks.Add(left); } // Recurse down to draw stuff below this group. if (cat.Categories != null) { int h = DrawCategoryOntoHorizontalAxis(cat.Categories, g, brush, context, axis, centered, level + 1, left, top + labelHeight, groupEntryWidth, majorMarks, minorMarks); totalHeight = Math.Max(totalHeight, labelHeight + h); } // Adjust the left to one group entry over. left += groupEntryWidth; } return(totalHeight); }
private void Carte_Paint(object sender, PaintEventArgs e) { int i; float 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, 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); float dx = w / (projet.reseaux[nproj].xu - projet.reseaux[nproj].xl); float dy = h / (projet.reseaux[nproj].yu - projet.reseaux[nproj].yl); float deltax, deltay, voldeltax, voldeltay; float cx = 0.5f * (projet.reseaux[nproj].xu + projet.reseaux[nproj].xl); float 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]; float angle = 0, norme = 0; float 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, ((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x - fen.xl) / fen.echelle) + deltay, ((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y) / fen.echelle) + deltax, ((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x - fen.xl) / fen.echelle) + deltay, ((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y) / fen.echelle) + deltax); p1.X = ((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x - fen.xl) / fen.echelle) + deltay; p1.Y = ((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y) / fen.echelle) + deltax; p2.X = ((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x - fen.xl) / fen.echelle) + voldeltay; p2.Y = ((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y) / fen.echelle) + voldeltax; p3.X = ((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x - fen.xl) / fen.echelle) + voldeltay; p3.Y = ((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y) / fen.echelle) + voldeltax; p4.X = ((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x - fen.xl) / fen.echelle) + deltay; p4.Y = ((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, 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(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(-0.5f * encombrement.Width * cosx, 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(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(+0.5f * encombrement.Width * cosx + (encombrement.Height) * sinx, -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(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(-0.5f * encombrement.Width * cosx, 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(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(+0.5f * encombrement.Width * cosx + (encombrement.Height) * sinx, -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)); * } * }*/ }
public void TransformPath(System.Drawing.Drawing2D.GraphicsPath path) { path.Transform(this); }
internal void DrawHorizontal(Chart chart, Rdl.Runtime.Context context, Graphics g, bool centered, int l, int t, int w, ref int h) { int majorIntervals = (int)((_maxValue - _minValue) / _majorIntervalValue); int minorIntervals = (int)((_maxValue - _minValue) / _minorIntervalValue); // Find the tick mark and axis position for the axis. int majorTickStart, majorTickHeight, minorTickStart, minorTickHeight, axisPos, axisWidth; AdjustAxisPosition(GetAxisThickness(context), out majorTickStart, out majorTickHeight, out minorTickStart, out minorTickHeight, out axisPos, out axisWidth); Color color = Style.W32Color(Style.Color(context)); Brush brush = new SolidBrush(color); Pen majorGridPen = new Pen(brush, 1); if (MajorGridLines != null) { majorGridPen = new Pen(new SolidBrush(Style.W32Color(MajorGridLines.Style.Color(context))), (int)MajorGridLines.Style.BorderWidth.Left(context).points); } Pen minorGridPen = new Pen(brush, 1); if (MinorGridLines != null) { minorGridPen = new Pen(new SolidBrush(Style.W32Color(MinorGridLines.Style.Color(context))), (int)MinorGridLines.Style.BorderWidth.Left(context).points); } Font font = Style.GetWindowsFont(context); bool vertical = false; float yMult = (float)g.DpiY / 72; int labelHeight = 0; float majorEntryWidth = (float)w / majorIntervals; float minorEntryWidth = (float)w / minorIntervals; // Determine how much vertical space is required for the axis labels. if (Visible) { // Determine if the labels need to be vertical and find the height required for the labels. labelHeight = (int)(font.Height * yMult); // Determine the amount of space required for the axis labels. GetValueLableWidth(context, g, majorIntervals); if (_labelWidth > (int)majorEntryWidth) { labelHeight = _labelWidth; vertical = true; } } // If we are showing the grid lines then adjust the tick width to include the whole chart area. if (MajorGridLines.ShowGridLines) { majorTickHeight = h - labelHeight - axisPos - majorTickStart; } if (MinorGridLines.ShowGridLines) { minorTickHeight = h - labelHeight - axisPos - minorTickStart; } // Fill in the background of the plot area. g.FillRectangle(new SolidBrush(Style.W32Color(chart.PlotAreaStyle.BackgroundColor(context))), l, t, w, h - (labelHeight + axisWidth)); // Draw the axis line g.DrawLine(new Pen(new SolidBrush(color), GetAxisThickness(context)), new Point(l, t + h - labelHeight - axisPos - (GetAxisThickness(context) >> 1)), new Point(l + w, t + h - labelHeight - axisPos - (GetAxisThickness(context) >> 1))); // Loop through the major interval values int left = l; for (int i = 0; i <= majorIntervals; i++) { left = l + (int)(i * majorEntryWidth); if (Visible) { decimal dValue = _minValue + (i * _majorIntervalValue); int center = left; if (centered) { center += (int)(majorEntryWidth / 2); } SizeF size = g.MeasureString(dValue.ToString(), font); if (vertical) { System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddString(dValue.ToString(), font.FontFamily, (int)font.Style, font.Size * yMult, new Point(center - ((int)size.Width / 2), t + h - labelHeight), StringFormat.GenericDefault); if (vertical) { System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix(); matrix.Translate(0 - (size.Width / 2), 0); matrix.RotateAt(-30, new PointF(center, t + h - labelHeight), System.Drawing.Drawing2D.MatrixOrder.Append); path.Transform(matrix); } g.DrawPath(new Pen(brush), path); } else { g.DrawString(dValue.ToString(), font, brush, center - (int)size.Width / 2, t + h - labelHeight, StringFormat.GenericDefault); } } if (i > 0) { // Draw the major tick mark if (majorTickHeight > 0) { g.DrawLine(majorGridPen, new Point(left, t + h - labelHeight - (axisWidth >> 1) - majorTickStart), new Point(left, t + h - labelHeight - (axisWidth >> 1) - majorTickStart - majorTickHeight)); } // Draw the minor tick marks if (minorTickHeight > 0) { for (int j = 1; j < minorIntervals / majorIntervals; j++) { g.DrawLine(minorGridPen, new Point(left + (int)(j * minorEntryWidth), t + h - labelHeight - (axisWidth >> 1) + minorTickStart), new Point(left + (int)(j * minorEntryWidth), t + h - labelHeight - (axisWidth >> 1) + minorTickStart - minorTickHeight)); } } } } h -= labelHeight + ((axisWidth + GetAxisThickness(context)) >> 1); }
// Generates the close button image private Bitmap GetButton() { System.Drawing.Point[] Points = new System.Drawing.Point[] { new Point(1, 0), new Point(3, 0), new Point(5, 2), new Point(7, 0), new Point(9, 0), new Point(6, 3), new Point(6, 4), new Point(9, 7), new Point(7, 7), new Point(5, 5), new Point(3, 7), new Point(1, 7), new Point(4, 4), new Point(4, 3) }; System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); Color bch = new Color(); Color bcl = new Color(); Color bc = new Color(); Color fc = new Color(); Bitmap B = default(Bitmap); System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix(); System.Drawing.Point[] path = new System.Drawing.Point[] { new Point(0, 1), new Point(1, 0), new Point(15, 0), new Point(16, 1), new Point(16, 14), new Point(15, 15), new Point(1, 15), new Point(0, 14) }; Graphics g = default(Graphics); if (MouseOverCloseButton) { bch = Helper.RenderColors.TabCloseButtonBackHighColorHot(m_RenderMode, CloseButtonBackHighColorHot); bcl = Helper.RenderColors.TabCloseButtonBackLowColorHot(m_RenderMode, CloseButtonBackLowColorHot); bc = Helper.RenderColors.TabCloseButtonBorderColorHot(m_RenderMode, CloseButtonBorderColorHot); fc = Helper.RenderColors.TabCloseButtonForeColorHot(m_RenderMode, CloseButtonForeColorHot); } else if (m_Selected) { bch = Helper.RenderColors.TabCloseButtonBackHighColor(m_RenderMode, CloseButtonBackHighColor); bcl = Helper.RenderColors.TabCloseButtonBackLowColor(m_RenderMode, CloseButtonBackLowColor); bc = Helper.RenderColors.TabCloseButtonBorderColor(m_RenderMode, CloseButtonBorderColor); fc = Helper.RenderColors.TabCloseButtonForeColor(m_RenderMode, CloseButtonForeColor); } else { bch = Helper.RenderColors.TabCloseButtonBackHighColorDisabled(m_RenderMode, CloseButtonBackHighColorDisabled); bcl = Helper.RenderColors.TabCloseButtonBackLowColorDisabled(m_RenderMode, CloseButtonBackLowColorDisabled); bc = Helper.RenderColors.TabCloseButtonBorderColorDisabled(m_RenderMode, CloseButtonBorderColorDisabled); fc = Helper.RenderColors.TabCloseButtonForeColorDisabled(m_RenderMode, CloseButtonForeColorDisabled); } B = new Bitmap(17, 17); B.MakeTransparent(); g = Graphics.FromImage(B); // draw the border and background g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; System.Drawing.Drawing2D.LinearGradientBrush l = new System.Drawing.Drawing2D.LinearGradientBrush(new Point(0, 0), new Point(0, 15), bch, bcl); g.FillPolygon(l, path); Pen p = new Pen(bc); g.DrawPolygon(p, path); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default; // draw the foreground gp.AddPolygon(Points); m.Translate(3, 4); gp.Transform(m); p.Dispose(); p = new Pen(fc); g.DrawPolygon(p, gp.PathPoints); SolidBrush sb = new SolidBrush(fc); g.FillPolygon(sb, gp.PathPoints); sb.Dispose(); p.Dispose(); gp.Dispose(); g.Dispose(); m.Dispose(); return(B); }
/// <summary> /// Draws labels in a specified rectangle /// </summary> /// <param name="g">The graphics object to draw to</param> /// <param name="labelText">The label text to draw</param> /// <param name="labelBounds">The rectangle of the label</param> /// <param name="symb">the Label Symbolizer to use when drawing the label</param> private static void DrawLabel(Graphics g, string labelText, RectangleF labelBounds, ILabelSymbolizer symb) { //Sets up the brushes and such for the labeling Brush foreBrush = new SolidBrush(symb.FontColor); Font textFont = symb.GetFont(); StringFormat format = new StringFormat(); format.Alignment = symb.Alignment; Pen borderPen = new Pen(symb.BorderColor); Brush backBrush = new SolidBrush(symb.BackColor); Brush haloBrush = new SolidBrush(symb.HaloColor); Pen haloPen = new Pen(symb.HaloColor); haloPen.Width = 2; haloPen.Alignment = System.Drawing.Drawing2D.PenAlignment.Outset; Brush shadowBrush = new SolidBrush(symb.DropShadowColor); //Text graphics path System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); gp.AddString(labelText, textFont.FontFamily, (int)textFont.Style, textFont.SizeInPoints * 96F / 72F, labelBounds, format); //Draws the text outline if (symb.BackColorEnabled && symb.BackColor != Color.Transparent) { if (symb.FontColor == Color.Transparent) { System.Drawing.Drawing2D.GraphicsPath backgroundGP = new System.Drawing.Drawing2D.GraphicsPath(); backgroundGP.AddRectangle(labelBounds); backgroundGP.FillMode = System.Drawing.Drawing2D.FillMode.Alternate; backgroundGP.AddPath(gp, true); g.FillPath(backBrush, backgroundGP); backgroundGP.Dispose(); } else { g.FillRectangle(backBrush, labelBounds); } } //Draws the border if its enabled if (symb.BorderVisible && symb.BorderColor != Color.Transparent) g.DrawRectangle(borderPen, labelBounds.X, labelBounds.Y, labelBounds.Width, labelBounds.Height); //Draws the drop shadow if (symb.DropShadowEnabled && symb.DropShadowColor != Color.Transparent) { System.Drawing.Drawing2D.Matrix gpTrans = new System.Drawing.Drawing2D.Matrix(); gpTrans.Translate(symb.DropShadowPixelOffset.X, symb.DropShadowPixelOffset.Y); gp.Transform(gpTrans); g.FillPath(shadowBrush, gp); gpTrans = new System.Drawing.Drawing2D.Matrix(); gpTrans.Translate(-symb.DropShadowPixelOffset.X, -symb.DropShadowPixelOffset.Y); gp.Transform(gpTrans); } //Draws the text halo if (symb.HaloEnabled && symb.HaloColor != Color.Transparent) g.DrawPath(haloPen, gp); //Draws the text if its not transparent if (symb.FontColor != Color.Transparent) g.FillPath(foreBrush, gp); //Cleans up the rest of the drawing objects shadowBrush.Dispose(); borderPen.Dispose(); foreBrush.Dispose(); backBrush.Dispose(); haloBrush.Dispose(); haloPen.Dispose(); }
private void DrawScalarHorizontal(Chart chart, Rdl.Runtime.Context context, Graphics g, bool centered, int l, int t, int w, ref int h) { if (chart.CategoryGrouping == null || chart.CategoryGrouping.NextGrouping != null) { throw new Exception("There must be exactly one grouping on a scalar axis."); } // Find the tick mark sizes and axis position for the axis. int majorTickStart, majorTickHeight, minorTickStart, minorTickHeight, axisPos, axisHeight; chart.CategoryAxis.AdjustAxisPosition(GetAxisThickness(context), out majorTickStart, out majorTickHeight, out minorTickStart, out minorTickHeight, out axisPos, out axisHeight); // Find the min and max values from the data. decimal min = 0; decimal max = 0; foreach (Category cat in chart.Categories) { min = Math.Min(min, decimal.Parse(cat.Value)); max = Math.Max(max, decimal.Parse(cat.Value)); } // Adjust the min and max values and find int intervals. SetMinMaxValues(context, min, max); int majorIntervals = (int)((_maxValue - _minValue) / _majorIntervalValue); int minorIntervals = (int)((_maxValue - _minValue) / _minorIntervalValue); Color color = Style.W32Color(chart.CategoryAxis.Style.Color(context)); Brush brush = new SolidBrush(color); int textHeight = 0; if (chart.CategoryAxis.Visible) { Font font = chart.CategoryAxis.Style.GetWindowsFont(context); // Determine if the label text needs to be vertical. bool vertical = false; int textSize = 0; for (decimal d = _minValue; d <= _maxValue; d += _majorIntervalValue) { SizeF sizeF = g.MeasureString(d.ToString() + " ", font); textSize += (int)sizeF.Width; textHeight = Math.Max(textHeight, (int)sizeF.Height); } if (textSize > w) { // If we are drawing vertically then determine how much height is required. textSize = 0; for (decimal d = _minValue; d <= _maxValue; d += _majorIntervalValue) { SizeF sizeF = g.MeasureString(d.ToString() + " ", font); textHeight = Math.Max(textHeight, (int)sizeF.Height); } vertical = true; } // Draw in the label text decimal value = min; for (int i = 0; i < majorIntervals; i++) { SizeF sizeF = g.MeasureString(value.ToString(), font, 0, (vertical) ? new StringFormat(StringFormatFlags.DirectionVertical) : StringFormat.GenericDefault); System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddString(value.ToString(), font.FontFamily, (int)font.Style, font.Size, new Point(0, 0), StringFormat.GenericDefault); if (vertical) { System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix(); matrix.Rotate(-30); path.Transform(matrix); } g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.DrawPath(new Pen(brush), path); //g.DrawString(value.ToString(), font, brush, // l + (i * w / majorIntervals) - ((int)sizeF.Width / 2), h - textHeight, // (vertical) ? new StringFormat(StringFormatFlags.DirectionVertical) : StringFormat.GenericDefault); } h -= textHeight; } // Draw the major tick marks and/or the grid lines. // Get the color for the major grid lines. Color majorGridColor = color; if (chart.CategoryAxis.MajorGridLines != null) { majorGridColor = Style.W32Color(chart.CategoryAxis.MajorGridLines.Style.Color(context)); } for (int i = 0; i < majorIntervals; i++) { int tickThickness = 1; if (chart.ValueAxis.MajorGridLines != null) { if (chart.ValueAxis.MajorGridLines.ShowGridLines) { majorTickHeight = h - (axisPos - l) - majorTickStart; } tickThickness = (int)chart.CategoryAxis.MajorGridLines.Style.BorderWidth.Left(context).points; } g.DrawLine(new Pen(new SolidBrush(majorGridColor), tickThickness), new Point(l + (i * w / majorIntervals), t + h - axisPos - majorTickStart), new Point(l + (i * w / majorIntervals), t + h - axisPos - majorTickStart)); } // Draw the minor tick marks and/or the grid lines. Color minorGridColor = color; if (chart.CategoryAxis.MinorGridLines != null) { minorGridColor = Style.W32Color(chart.CategoryAxis.MinorGridLines.Style.Color(context)); } for (int i = 0; i < majorIntervals; i++) { int tickThickness = 1; if (chart.ValueAxis.MinorGridLines != null) { if (chart.ValueAxis.MinorGridLines.ShowGridLines) { minorTickHeight = h - (axisPos - l) - minorTickStart; } tickThickness = (int)chart.ValueAxis.MinorGridLines.Style.BorderWidth.Left(context).points; } g.DrawLine(new Pen(new SolidBrush(minorGridColor), tickThickness), new Point(l + (i * w / majorIntervals), t + h - axisPos - minorTickStart), new Point(l + (i * w / majorIntervals), t + h - axisPos - minorTickStart)); } // Adjust the height by the height of the axis labels and the axis line. h -= axisHeight; }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { string S = ""; DA.GetData(0, ref S); string fontString = ""; DA.GetData(1, ref fontString); bool close = false; DA.GetData(2, ref close); double size = 0.0; DA.GetData(3, ref size); double precision = 0.0; DA.GetData(4, ref precision); Plane basePlane = new Plane(); DA.GetData(5, ref basePlane); int J = 0; DA.GetData(6, ref J); float fS = size == 0 ? 1 : (float)size; Font local_font = new Font(fontString, (float)fS); System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddString(S, local_font.FontFamily, (int)local_font.Style, local_font.Size, new PointF(0, 0), new StringFormat()); System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix(); // transformation matrix matrix.Reset(); // build identity matrix // __________________ autoList part __________________ // variable for the list Grasshopper.Kernel.Special.GH_ValueList vList; // tries to cast input as list try { // if the list is not the first parameter then change Input[6] to the corresponding value vList = Params.Input[6].Sources[0] as Grasshopper.Kernel.Special.GH_ValueList; // check if the list must be created if (!vList.NickName.Equals("Justification")) { vList.ClearData(); vList.ListItems.Clear(); vList.NickName = "Justification"; for (int i = 0; i < justification.Length; i++) { vList.ListItems.Add(new Grasshopper.Kernel.Special.GH_ValueListItem(justification[i][0], justification[i][1])); } //var item1 = new Grasshopper.Kernel.Special.GH_ValueListItem("TopLeft", "0"); //var item2 = new Grasshopper.Kernel.Special.GH_ValueListItem("MiddleLeft", "1"); //var item3 = new Grasshopper.Kernel.Special.GH_ValueListItem("BottomLeft", "2"); //var item4 = new Grasshopper.Kernel.Special.GH_ValueListItem("TopCenter", "3"); //var item5 = new Grasshopper.Kernel.Special.GH_ValueListItem("MiddleCenter", "4"); //var item6 = new Grasshopper.Kernel.Special.GH_ValueListItem("BottomCenter", "5"); //var item7 = new Grasshopper.Kernel.Special.GH_ValueListItem("TopRight", "6"); //var item8 = new Grasshopper.Kernel.Special.GH_ValueListItem("MiddleRight", "7"); //var item9 = new Grasshopper.Kernel.Special.GH_ValueListItem("BottomRight", "8"); //vList.ListItems.Add(item1); //vList.ListItems.Add(item2); //vList.ListItems.Add(item3); //vList.ListItems.Add(item4); //vList.ListItems.Add(item5); //vList.ListItems.Add(item6); //vList.ListItems.Add(item7); //vList.ListItems.Add(item8); //vList.ListItems.Add(item9); vList.ListItems[0].Value.CastTo(out J); } } catch { // handles anything that is not a value list } // ______________ text justification ______________ RectangleF rec = path.GetBounds(); // bounding rectangle for text float dX = Convert.ToSingle(rec.Width * -0.5), dY = Convert.ToSingle(rec.Height * 0.5); switch (J) { case 0: // top left dX = 0; dY = fS; break; case 1: // middle left dX = 0; dY = Convert.ToSingle((-rec.Height) * 0.5 + fS); break; case 2: // bottom left dX = 0; dY = Convert.ToSingle(-rec.Height + fS * 0.5); break; case 3: // top center dX = Convert.ToSingle(rec.Width * -0.5); dY = fS; break; case 4: // middle center dX = Convert.ToSingle(rec.Width * -0.5); dY = Convert.ToSingle((-rec.Height) * 0.5 + fS); break; case 5: // bottom center dX = Convert.ToSingle(rec.Width * -0.5); dY = Convert.ToSingle(-rec.Height + fS * 0.5); break; case 6: // top right dX = Convert.ToSingle(rec.Width * -1); dY = fS; break; case 7: // middle right dX = Convert.ToSingle(rec.Width * -1); dY = Convert.ToSingle((-rec.Height) * 0.5 + fS); break; case 8: // bottom right dX = Convert.ToSingle(rec.Width * -1); dY = Convert.ToSingle(-rec.Height + fS * 0.5); break; } //float dX = Convert.ToSingle(rec.Width * -0.5); //float dY = Convert.ToSingle(rec.Height * 0.5); System.Drawing.Drawing2D.Matrix mTrans = new System.Drawing.Drawing2D.Matrix(1, 0, 0, 1, dX, dY); // build transformation matrix path.Transform(mTrans); // transform text path // ______________ convert to polylines ______________ path.Flatten(matrix, (float)(size / precision)); // turns the path into a polyline that approximates the path PointF[] pts = path.PathPoints; // get path points Byte[] tps = path.PathTypes; // get path point types List <Polyline> strokes = new List <Polyline>(); // List for strokes Polyline stroke = new Polyline(); Byte typ_start = Convert.ToByte(System.Drawing.Drawing2D.PathPointType.Start);// find start points condition // the conversion loop for (int i = 0; i < pts.Length; i++) { // if a start point is found, and the existing polyline is not null nor a single point, // add polyline to the strokes and create a new polyline if (tps[i] == typ_start) { if (stroke != null && stroke.Count > 1) { if (close && !stroke.IsClosed) { stroke.Add(stroke[0]); // close polyline if necessary } strokes.Add(stroke); } stroke = new Polyline(); } // in any other case add the next point to a polyline stroke.Add(pts[i].X, -pts[i].Y + size, 0); // add last stroke to the list if (i == pts.Length - 1) { if (close && !stroke.IsClosed) { stroke.Add(stroke[0]); // and close it if necessary } strokes.Add(stroke); } } // ______________ align strokes to given plane ______________ Transform align = Transform.PlaneToPlane(Plane.WorldXY, basePlane); // align transformation for (int j = 0; j < strokes.Count; j++) { strokes[j].Transform(align); } DA.SetDataList(0, strokes); }
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)); } }*/ }