本文整理汇总了C#中IGraphics.RotateTransform方法的典型用法代码示例。如果您正苦于以下问题:C# IGraphics.RotateTransform方法的具体用法?C# IGraphics.RotateTransform怎么用?C# IGraphics.RotateTransform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IGraphics
的用法示例。
在下文中一共展示了IGraphics.RotateTransform方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawCaps
private void DrawCaps(IGraphics g, bool onScreen, Style style)
{
Matrix transformState = g.Transform;
g.TranslateTransform(routeCache[0].X, routeCache[0].Y);
g.RotateTransform(GetAngle(routeCache[0], routeCache[1]));
DrawStartCap(g, onScreen, style);
g.Transform = transformState;
int last = routeCache.Count - 1;
g.TranslateTransform(routeCache[last].X, routeCache[last].Y);
g.RotateTransform(GetAngle(routeCache[last], routeCache[last - 1]));
DrawEndCap(g, onScreen, style);
g.Transform = transformState;
}
示例2: OnPaint
public void OnPaint(IGraphics g, int xm, int ym, int width, int height)
{
if (!Visible){
return;
}
if (TotalMax == double.NegativeInfinity){
return;
}
if ((indicator1 != -1 && indicator2 != -1) || (ZoomType == AxisZoomType.Indicate && !IsFullZoom())){
if (IsValid()){
PaintIndicator(g, width, height);
}
}
Pen2 forePen = new Pen2(ForeColor, LineWidth);
Pen2 majorTicPen = new Pen2(ForeColor, MajorTickLineWidth);
Pen2 minorTicPen = new Pen2(ForeColor, MinorTickLineWidth);
Brush2 brush = new Brush2(ForeColor);
g.SmoothingMode = SmoothingMode2.AntiAlias;
string label = Text ?? "";
float x0;
float y0;
int decade = 0;
double[][] tics = null;
double max = 0;
if (IsValid()){
decade = (int) Math.Floor(Math.Log(Math.Max(Math.Abs(VisibleMax), Math.Abs(VisibleMin)))/Math.Log(10));
if (decade > 0 && decade < MaxNumIntegerDigits){
decade = 0;
}
if (decade != 0 && !IsLogarithmic){
label += " [1" + ToSuperscript(decade) + ']';
}
tics = GetTics(GetLength(width, height));
if (tics == null){
return;
}
max = Math.Max(Math.Abs(ArrayUtils.Max(tics[0])), Math.Abs(ArrayUtils.Min(tics[0])));
}
Font2 font = labelFont;
while (g.MeasureString(label, font).Width > Math.Max(width, height)*0.95f && font.Size > 5f){
font = new Font2(font.Name, font.Size - 0.5f, font.Style);
}
switch (Positioning){
case AxisPositioning.Top:
y0 = height - 1;
g.DrawLine(forePen, xm, ym + y0, xm + width, ym + y0);
if (IsValid() && tics != null){
int previousstringEnd = -Sign*int.MaxValue;
for (int i = 0; i < tics[0].Length; i++){
x0 = ModelToView(tics[0][i], width, height);
g.DrawLine(majorTicPen, xm + x0, ym + y0, xm + x0, ym + y0 - MajorTickLength);
string s = GetTicLabel(tics[0][i], decade, max);
int w = (int) g.MeasureString(s, numbersFont).Width;
int pos = (int) (x0 - w/2.0);
pos = Math.Max(-2, pos);
pos = Math.Min(width - w + 2, pos);
if (Sign*pos > Sign*previousstringEnd){
DrawString(g, s, numbersFont, brush, xm + pos + 1, ym + y0 - MajorTickLength - numbersFont.Height);
previousstringEnd = pos + Sign*w;
}
}
for (int i = 0; i < tics[1].Length; i++){
x0 = ModelToView(tics[1][i], width, height);
g.DrawLine(minorTicPen, xm + x0, ym + y0, xm + x0, ym + y0 - MinorTickLength);
}
}
DrawString(g, label, font, brush, xm + (width)/2 - (int) g.MeasureString(label, font).Width/2,
ym + y0 - MajorTickLength - labelFont.Height - 12);
break;
case AxisPositioning.Left:
x0 = width - 1;
g.DrawLine(forePen, xm + x0, ym, xm + x0, ym + height);
if (IsValid() && tics != null){
int previousstringEnd = -Sign*Int32.MaxValue;
for (int i = 0; i < tics[0].Length; i++){
y0 = ModelToView(tics[0][i], width, height);
g.DrawLine(majorTicPen, xm + x0, ym + y0, xm + x0 - MajorTickLength, ym + y0);
string s = GetTicLabel(tics[0][i], decade, max);
int w = (int) g.MeasureString(s, numbersFont).Width;
int pos = (int) (y0 + w/2.0) + 1;
pos = Math.Max(w - 2, pos);
pos = Math.Min(height + 2, pos);
if (Sign*pos > Sign*previousstringEnd){
g.RotateTransform(-90);
DrawString(g, s, numbersFont, brush, -pos - ym, xm + x0 - MajorTickLength - numbersFont.Height);
g.RotateTransform(90);
previousstringEnd = pos + Sign*w;
}
}
for (int i = 0; i < tics[1].Length; i++){
y0 = ModelToView(tics[1][i], width, height);
g.DrawLine(minorTicPen, xm + x0, ym + y0, xm + x0 - MinorTickLength, ym + y0);
}
}
g.RotateTransform(-90);
float x = -height/2 - (int) g.MeasureString(label, font).Width/2;
float y = x0 - MajorTickLength - labelFont.Height - numbersFont.Height - 10;
if (y < 0){
y = 0;
}
//.........这里部分代码省略.........
示例3: Render
private void Render(IGraphics ig)
{
string s = cbWhat.Text;
if (s == "Clipping")
{
Pen pn = new Pen(Color.LightGray, 5);
Pen pn2 = new Pen(Color.Yellow);
ig.Clear(Color.Black);
GraphicsContainer cnt = ig.BeginContainer();
ig.SmoothingMode = SmoothingMode.HighQuality;
ig.SetClip(new Rectangle(35,35,120,120));
ig.DrawRectangle(pn, 5,5,45,70);
ig.DrawRectangle(pn, 15,25,90,120);
ig.DrawRectangle(pn, 50,30,100,170);
ig.DrawRectangle(pn, 5,80,180,30);
ig.DrawRectangle(pn, 75,10,40,160);
ig.EndContainer(cnt);
ig.DrawRectangle(pn2, 5,5,45,70);
ig.DrawRectangle(pn2, 15,25,90,120);
ig.DrawRectangle(pn2, 50,30,100,170);
ig.DrawRectangle(pn2, 5,80,180,30);
ig.DrawRectangle(pn2, 75,10,40,160);
}
else if (s == "Transforms")
{
ig.Clear(Color.Black);
ig.RotateTransform(15);
ig.DrawRectangle(new Pen(Color.Red,2), 260,80,50,40);
ig.ResetTransform();
ig.DrawRectangle(new Pen(Color.Red,2), 260,80,50,40);
ig.TranslateTransform(15,-5);
GraphicsContainer cnt = ig.BeginContainer();
ig.SmoothingMode = SmoothingMode.HighQuality;
ig.RotateTransform(5);
ig.FillEllipse(new SolidBrush(Color.Orange), 100,100,80,40);
ig.DrawRectangle(new Pen(Color.Orange,2), 60,80,40,40);
GraphicsContainer cnt2 = ig.BeginContainer();
ig.SmoothingMode = SmoothingMode.None;
ig.RotateTransform(5);
ig.ScaleTransform(1.1f, 1.2f);
ig.FillEllipse(new SolidBrush(Color.YellowGreen), 130,180,80,40);
ig.DrawRectangle(new Pen(Color.YellowGreen,2), 62,80,40,40);
GraphicsContainer cnt3 = ig.BeginContainer();
ig.SmoothingMode = SmoothingMode.HighQuality;
Matrix mm = new Matrix();
mm.Shear(0.3f, 0f);
ig.Transform = mm;
ig.FillEllipse(new SolidBrush(Color.Green), 180,120,80,40);
ig.DrawRectangle(new Pen(Color.Green,2), 62,84,40,40);
ig.EndContainer(cnt3);
ig.EndContainer(cnt2);
ig.FillEllipse(new SolidBrush(Color.Blue), 120,150,80,40);
ig.DrawRectangle(new Pen(Color.Blue,2), 64,80,40,40);
ig.EndContainer(cnt);
ig.FillEllipse(new SolidBrush(Color.Indigo), 80,210,80,40);
ig.DrawRectangle(new Pen(Color.Indigo,2), 66,80,40,40);
ig.DrawRectangle(new Pen(Color.White,2), 270,30,50,40);
ig.ResetTransform();
ig.DrawRectangle(new Pen(Color.White,2), 270,30,50,40);
}
else if (s == "Lines")
{
ig.SmoothingMode = SmoothingMode.AntiAlias;
Pen ow = new Pen(Color.Purple, 12);
ow.EndCap = LineCap.Round;
ow.StartCap = LineCap.Round;
ow.MiterLimit = 6f;
ow.LineJoin = LineJoin.Miter;
ig.SmoothingMode = SmoothingMode.None;
//.........这里部分代码省略.........
示例4: Draw
/// <summary>
/// Render this object to the specified <see cref="Graphics"/> device.
/// </summary>
/// <remarks>
/// This method is normally only called by the Draw method
/// of the parent <see cref="GraphObjList"/> collection object.
/// </remarks>
/// <param name="g">
/// A graphic device object to be drawn into. This is normally e.Graphics from the
/// PaintEventArgs argument to the Paint() method.
/// </param>
/// <param name="pane">
/// A reference to the <see cref="PaneBase"/> object that is the parent or
/// owner of this object.
/// </param>
/// <param name="scaleFactor">
/// The scaling factor to be used for rendering objects. This is calculated and
/// passed down by the parent <see cref="GraphPane"/> object using the
/// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust
/// font sizes, etc. according to the actual size of the graph.
/// </param>
public override void Draw( IGraphics g, PaneBase pane, float scaleFactor )
{
// Convert the arrow coordinates from the user coordinate system
// to the screen coordinate system
PointF pix1 = this.Location.TransformTopLeft( pane );
PointF pix2 = this.Location.TransformBottomRight( pane );
if ( pix1.X > -10000 && pix1.X < 100000 && pix1.Y > -100000 && pix1.Y < 100000 &&
pix2.X > -10000 && pix2.X < 100000 && pix2.Y > -100000 && pix2.Y < 100000 )
{
// calculate the length and the angle of the arrow "vector"
double dy = pix2.Y - pix1.Y;
double dx = pix2.X - pix1.X;
float angle = (float)Math.Atan2( dy, dx ) * 180.0F / (float)Math.PI;
float length = (float)Math.Sqrt( dx * dx + dy * dy );
// Save the old transform matrix
Matrix transform = g.Transform;
// Move the coordinate system so it is located at the starting point
// of this arrow
g.TranslateTransform( pix1.X, pix1.Y );
// Rotate the coordinate system according to the angle of this arrow
// about the starting point
g.RotateTransform( angle );
// get a pen according to this arrow properties
using ( Pen pen = _line.GetPen( pane, scaleFactor ) )
//new Pen( _line._color, pane.ScaledPenWidth( _line._width, scaleFactor ) ) )
{
//pen.DashStyle = _style;
g.DrawLine( pen, 0, 0, length, 0 );
}
// Restore the transform matrix back to its original state
g.Transform = transform;
}
}
示例5: DrawLabel
public void DrawLabel(IGraphics g, PointF labelPoint, PointF offset, Font font, Color forecolor,
Brush backcolor, Pen halo, float rotation, string text, Map map,
LabelStyle.HorizontalAlignmentEnum alignment = LabelStyle.HorizontalAlignmentEnum.Left,
PointF? rotationPoint = null)
{
//Calculate the size of the text
var labelSize = RendererHelper.SizeOfString(g, text, font);
//Add label offset
labelPoint.X += offset.X;
labelPoint.Y += offset.Y;
//Translate alignment to stringalignment
StringAlignment salign;
switch (alignment)
{
case LabelStyle.HorizontalAlignmentEnum.Left:
salign = StringAlignment.Near;
break;
case LabelStyle.HorizontalAlignmentEnum.Center:
salign = StringAlignment.Center;
break;
default:
salign = StringAlignment.Far;
break;
}
if (rotation != 0 && !float.IsNaN(rotation))
{
rotationPoint = rotationPoint ?? labelPoint;
PointF pt = rotationPoint.Value;
g.FillEllipse(Brushes.LawnGreen, (int)(pt.X - 1), (int)(pt.Y - 1), 2, 2);
var t = g.Transform.Clone();
g.TranslateTransform(pt.X, pt.Y);
g.RotateTransform(rotation);
//g.TranslateTransform(-labelSize.Width/2, -labelSize.Height/2);
labelPoint = new PointF(labelPoint.X - pt.X,
labelPoint.Y - pt.Y);
//labelSize = new SizeF(labelSize.Width*0.74f + 1f, labelSize.Height*0.74f);
if (backcolor != null && backcolor != Brushes.Transparent)
g.FillRectangle(backcolor,
(int)labelPoint.X, (int)labelPoint.Y,
(int)labelSize.Width, (int)labelSize.Height);
var path = new GraphicsPath();
path.AddString(text, font.FontFamily, (int)font.Style, font.Size,
new RectangleF(labelPoint, labelSize) /* labelPoint*/,
new StringFormat { Alignment = salign } /*null*/);
if (halo != null)
g.DrawPath(halo, path);
g.FillPath(new SolidBrush(forecolor), path);
//g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), 0, 0);
g.Transform = t;
}
else
{
if (backcolor != null && backcolor != Brushes.Transparent)
g.FillRectangle(backcolor,
(int)labelPoint.X, (int)labelPoint.Y,
(int)labelSize.Width, (int)labelSize.Height);
var path = new GraphicsPath();
path.AddString(text, font.FontFamily, (int)font.Style, font.Size,
new RectangleF(labelPoint, labelSize) /* labelPoint*/,
new StringFormat { Alignment = salign } /*null*/);
if (halo != null)
g.DrawPath(halo, path);
g.FillPath(new SolidBrush(forecolor), path);
//g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), LabelPoint.X, LabelPoint.Y);
}
}
示例6: SetTransformMatrix
/// <summary>
/// Setup the Transform Matrix to handle drawing of this <see cref="Y2Axis"/>
/// </summary>
/// <param name="g">
/// A graphic device object to be drawn into. This is normally e.Graphics from the
/// PaintEventArgs argument to the Paint() method.
/// </param>
/// <param name="pane">
/// A reference to the <see cref="GraphPane"/> object that is the parent or
/// owner of this object.
/// </param>
/// <param name="scaleFactor">
/// The scaling factor to be used for rendering objects. This is calculated and
/// passed down by the parent <see cref="GraphPane"/> object using the
/// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust
/// font sizes, etc. according to the actual size of the graph.
/// </param>
public override void SetTransformMatrix( IGraphics g, GraphPane pane, float scaleFactor )
{
// Move the origin to the BottomRight of the ChartRect, which is the left
// side of the Y2 axis (facing from the label side)
g.TranslateTransform( pane.Chart._rect.Right, pane.Chart._rect.Bottom );
// rotate so this axis is in the left-right direction
g.RotateTransform( -90 );
}
示例7: Draw
/// <summary>
/// Render this object to the specified <see cref="Graphics"/> device.
/// </summary>
/// <remarks>
/// This method is normally only called by the Draw method
/// of the parent <see cref="GraphObjList"/> collection object.
/// </remarks>
/// <param name="g">
/// A graphic device object to be drawn into. This is normally e.Graphics from the
/// PaintEventArgs argument to the Paint() method.
/// </param>
/// <param name="pane">
/// A reference to the <see cref="PaneBase"/> object that is the parent or
/// owner of this object.
/// </param>
/// <param name="scaleFactor">
/// The scaling factor to be used for rendering objects. This is calculated and
/// passed down by the parent <see cref="GraphPane"/> object using the
/// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust
/// font sizes, etc. according to the actual size of the graph.
/// </param>
public override void Draw( IGraphics g, PaneBase pane, float scaleFactor )
{
// Convert the arrow coordinates from the user coordinate system
// to the screen coordinate system
PointF pix1 = this.Location.TransformTopLeft( pane );
PointF pix2 = this.Location.TransformBottomRight( pane );
if ( pix1.X > -10000 && pix1.X < 100000 && pix1.Y > -100000 && pix1.Y < 100000 &&
pix2.X > -10000 && pix2.X < 100000 && pix2.Y > -100000 && pix2.Y < 100000 )
{
// get a scaled size for the arrowhead
float scaledSize = (float)( _size * scaleFactor );
// calculate the length and the angle of the arrow "vector"
double dy = pix2.Y - pix1.Y;
double dx = pix2.X - pix1.X;
float angle = (float)Math.Atan2( dy, dx ) * 180.0F / (float)Math.PI;
float length = (float)Math.Sqrt( dx * dx + dy * dy );
// Save the old transform matrix
Matrix transform = g.Transform;
// Move the coordinate system so it is located at the starting point
// of this arrow
g.TranslateTransform( pix1.X, pix1.Y );
// Rotate the coordinate system according to the angle of this arrow
// about the starting point
g.RotateTransform( angle );
// get a pen according to this arrow properties
using ( Pen pen = _line.GetPen( pane, scaleFactor ) )
//new Pen( _color, pane.ScaledPenWidth( _penWidth, scaleFactor ) ) )
{
//pen.DashStyle = _style;
// Only show the arrowhead if required
if ( _isArrowHead )
{
// Draw the line segment for this arrow
g.DrawLine( pen, 0, 0, length - scaledSize + 1, 0 );
// Create a polygon representing the arrowhead based on the scaled
// size
PointF[] polyPt = new PointF[4];
float hsize = scaledSize / 3.0F;
polyPt[0].X = length;
polyPt[0].Y = 0;
polyPt[1].X = length - scaledSize;
polyPt[1].Y = hsize;
polyPt[2].X = length - scaledSize;
polyPt[2].Y = -hsize;
polyPt[3] = polyPt[0];
using ( SolidBrush brush = new SolidBrush( _line._color ) )
// render the arrowhead
g.FillPolygon( brush, polyPt );
}
else
g.DrawLine( pen, 0, 0, length, 0 );
}
// Restore the transform matrix back to its original state
g.Transform = transform;
}
}
示例8: SetTransformMatrix
/// <summary>
/// Setup the Transform Matrix to handle drawing of this <see cref="X2Axis"/>
/// </summary>
/// <param name="g">
/// A graphic device object to be drawn into. This is normally e.Graphics from the
/// PaintEventArgs argument to the Paint() method.
/// </param>
/// <param name="pane">
/// A reference to the <see cref="GraphPane"/> object that is the parent or
/// owner of this object.
/// </param>
/// <param name="scaleFactor">
/// The scaling factor to be used for rendering objects. This is calculated and
/// passed down by the parent <see cref="GraphPane"/> object using the
/// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust
/// font sizes, etc. according to the actual size of the graph.
/// </param>
public override void SetTransformMatrix( IGraphics g, GraphPane pane, float scaleFactor )
{
// Move the origin to the TopLeft of the ChartRect, which is the left
// side of the X2 axis (facing from the label side)
g.TranslateTransform( pane.Chart._rect.Right, pane.Chart._rect.Top );
//g.ScaleTransform( 1.0f, -1.0f );
// rotate so this axis is in the right-left direction
g.RotateTransform( 180 );
}