本文整理汇总了C#中Xwt.Drawing.Context.LineTo方法的典型用法代码示例。如果您正苦于以下问题:C# Context.LineTo方法的具体用法?C# Context.LineTo怎么用?C# Context.LineTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Xwt.Drawing.Context
的用法示例。
在下文中一共展示了Context.LineTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Draw
internal protected override void Draw (Context win, Rectangle area, long line, double x, double y)
{
win.Rectangle (x, y, Width, Editor.LineHeight);
win.SetColor (Style.IconBarBg);
win.Fill ();
win.MoveTo (x + Width - 1, y);
win.LineTo (x + Width - 1, y + Editor.LineHeight);
win.SetColor (Style.IconBarSeperator);
win.Stroke ();
foreach (long bookmark in Data.Bookmarks) {
if (line * Editor.BytesInRow <= bookmark && bookmark < line * Editor.BytesInRow + Editor.BytesInRow) {
DrawBookmark (win, x, y);
return;
}
}
}
示例2: Lines
/// <summary>
/// Visual test for pixel alignment and odd/even line widths
/// </summary>
public void Lines (Context ctx)
{
ctx.Save ();
ctx.SetColor (Colors.Black);
int nPairs = 4;
double length = 90;
double gap = 2;
// set half-pixel y-coordinate for sharp single-pixel-wide line
// on first line of Canvas, extending to match line pairs below
ctx.SetLineWidth (1);
double x = 0;
double y = 0.5;
double end = x + 2*(length - 1) + gap;
ctx.MoveTo (x, y);
ctx.LineTo (end, y);
ctx.Stroke ();
// draw pairs of lines with odd and even widths,
// each pair aligned on half-pixel y-coordinates
y = 4.5;
for (int w = 1; w <= nPairs; ++w) {
x = 0;
ctx.SetLineWidth (w);
ctx.MoveTo (x, y);
ctx.RelLineTo (length-1, 0);
ctx.Stroke ();
ctx.SetLineWidth (w + 1);
x += (gap + length - 1);
ctx.MoveTo (x, y);
ctx.RelLineTo (length-1, 0);
ctx.Stroke ();
y += w * 2 + gap;
}
ctx.Restore ();
}
示例3: Curves1
public virtual void Curves1(Context ctx, double x, double y)
{
ctx.Save ();
ctx.Translate (x, y);
ctx.SetLineWidth (1);
Action curve1 = () => {
ctx.MoveTo (0, 30);
ctx.CurveTo (20, 0, 50, 0, 60, 25);
};
// curve2 with lineTo; curve1 is closed
Action curve2 = () => {
ctx.LineTo (0, 0);
ctx.CurveTo (20, 30, 50, 30, 60, 5);
};
Action paint = () => {
curve1 ();
curve2 ();
ctx.ClosePath ();
ctx.SetColor (new Color (0, 0, 0, .5));
ctx.StrokePreserve ();
ctx.SetColor (new Color (1, 0, 1, .5));
ctx.Fill ();
};
paint ();
ctx.Translate (0, 40);
// curve2 with moveTo; curve1 is open
curve2 = () => {
ctx.MoveTo (0, 0);
ctx.CurveTo (20, 30, 50, 30, 60, 5);
};
paint ();
ctx.Restore ();
//Todo: same stuff with arc
}
示例4: Draw
/// <summary>
/// Draw the marker.
/// </summary>
/// <param name="ctx">Context.</param>
public override void Draw(Context ctx)
{
ctx.SetColor(PipelineNode.NodeColorBorder);
Rectangle bndTmp = Bounds;
ctx.RoundRectangle(bndTmp.Inflate(-2, -2), 2);
if (compatible.IsFinal()) {
ctx.SetColor(Colors.LightGray);
} else {
ctx.RoundRectangle(bndTmp.Inflate(-1, -1), 3);
using (LinearGradient g = new LinearGradient(bndTmp.Left, bndTmp.Top, bndTmp.Right, bndTmp.Bottom)) {
g.AddColorStop(0, Colors.Black.BlendWith(NodeColor, 0.7));
g.AddColorStop(1, NodeColor);
ctx.Pattern = g;
ctx.Fill();
}
ctx.SetColor(NodeColor);
}
ctx.Fill();
if (IsInput) {
int inputBufferSize = inputData.Count;
List<Result> ihCopy;
lock (inputHistoryLock) {
ihCopy = new List<Result>(inputHistory);
}
foreach (Result input in ihCopy) {
if (input.IsUsed(parent)) {
inputBufferSize++;
} else {
lock (inputHistoryLock) {
inputHistory.Remove(input);
}
}
}
if (inputBufferSize > 0) {
bool sourceNodeIsAbove = true;
if (edges.Count > 0 && edges[0] != null) {
if (edges[0].to.Bounds.Center.Y > Bounds.Center.Y - 4.0) {
sourceNodeIsAbove = false;
}
}
textLayout.Text = inputBufferSize.ToString();
double textWidth = textLayout.GetSize().Width;
double textHeight = textLayout.GetSize().Height;
Point inputbufferSizeLocation =
Bounds.Location.Offset(
-24 -(textWidth/2),
sourceNodeIsAbove ? textHeight + 6 : -6 - textHeight);
ctx.Arc(
inputbufferSizeLocation.X + textWidth / 2,
inputbufferSizeLocation.Y + textHeight / 2,
Math.Max(textHeight, textWidth) / 2 + 1,
0, 360
);
ctx.Fill();
ctx.SetColor(PipelineNode.NodeColor);
ctx.DrawTextLayout(textLayout, inputbufferSizeLocation);
}
} else {
// if this is a final node
if (parent.algorithm.Output[positionNo].IsFinal()) {
ctx.MoveTo(bndTmp.Right + 4, bndTmp.Top);
ctx.LineTo(bndTmp.Right + 4, bndTmp.Bottom);
ctx.Stroke();
// draw output size on end nodes (= number of features
if (parent.results != null &&
parent.results.Count > 0 &&
parent.results[0].Item1 != null &&
parent.results[0].Item1.Length - 1 >= Position) {
textLayout.Text = parent.results.Count.ToString();
double textWidth = textLayout.GetSize().Width;
double textHeight = textLayout.GetSize().Height;
Point outputbufferSizeLocation =
Bounds.Location.Offset(Bounds.Width * 1.8, 0);
ctx.Arc(
outputbufferSizeLocation.X + textWidth / 2,
outputbufferSizeLocation.Y + textHeight / 2,
Math.Max(textHeight, textWidth) / 2 + 1,
0, 360
);
ctx.Fill();
ctx.SetColor(PipelineNode.NodeColor);
ctx.DrawTextLayout(textLayout, outputbufferSizeLocation);
}
}
}
//.........这里部分代码省略.........
示例5: Draw
/// <summary>
/// Draws the horizontal line plot using the Context and the x and y axes specified
/// </summary>
/// <param name="ctx">The Context with which to draw.</param>
/// <param name="xAxis">The X-Axis to draw against.</param>
/// <param name="yAxis">The Y-Axis to draw against.</param>
public void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis)
{
double xMin = xAxis.PhysicalMin.X;
double xMax = xAxis.PhysicalMax.X;
xMin += pixelIndent_;
xMax -= pixelIndent_;
double length = Math.Abs (xMax - xMin);
double lengthDiff = length - length*scale_;
double indentAmount = lengthDiff/2;
xMin += indentAmount;
xMax -= indentAmount;
double yPos = yAxis.WorldToPhysical (value_, false).Y;
ctx.Save ();
ctx.SetLineWidth (1);
ctx.SetColor (color_);
ctx.MoveTo (xMin, yPos);
ctx.LineTo (xMax, yPos);
ctx.Stroke ();
ctx.Restore ();
// todo: clip and proper logic for flipped axis min max.
}
示例6: DrawTick
/// <summary>
/// Draw a tick on the axis.
/// </summary>
/// <param name="ctx">The Drawing Context with on which to draw.</param>
/// <param name="w">The tick position in world coordinates.</param>
/// <param name="size">The size of the tick (in pixels)</param>
/// <param name="text">The text associated with the tick</param>
/// <param name="textOffset">The Offset to draw from the auto calculated position</param>
/// <param name="axisPhysMin">The minimum physical extent of the axis</param>
/// <param name="axisPhysMax">The maximum physical extent of the axis</param>
/// <param name="boundingBox">out: The bounding rectangle for the tick and tickLabel drawn</param>
/// <param name="labelOffset">out: offset from the axies required for axis label</param>
public virtual void DrawTick(
Context ctx,
double w,
double size,
string text,
Point textOffset,
Point axisPhysMin,
Point axisPhysMax,
out Point labelOffset,
out Rectangle boundingBox )
{
// determine physical location where tick touches axis.
Point tickStart = WorldToPhysical (w, axisPhysMin, axisPhysMax, true);
// determine offset from start point.
Point axisDir = Utils.UnitVector (axisPhysMin, axisPhysMax);
// rotate axisDir anti-clockwise by TicksAngle radians to get tick direction. Note that because
// the physical (pixel) origin is at the top left, a RotationTransform by a positive angle will
// be clockwise. Consequently, for anti-clockwise rotations, use cos(A-B), sin(A-B) formulae
double x1 = Math.Cos (TicksAngle) * axisDir.X + Math.Sin (TicksAngle) * axisDir.Y;
double y1 = Math.Cos (TicksAngle) * axisDir.Y - Math.Sin (TicksAngle) * axisDir.X;
// now get the scaled tick vector.
Point tickVector = new Point (TickScale * size * x1, TickScale * size * y1);
if (TicksCrossAxis) {
tickStart.X -= tickVector.X / 2;
tickStart.Y -= tickVector.Y / 2;
}
// and the end point [point off axis] of tick mark.
Point tickEnd = new Point (tickStart.X + tickVector.X, tickStart.Y + tickVector.Y);
// and draw it
ctx.SetLineWidth (1);
ctx.SetColor (LineColor);
ctx.MoveTo (tickStart.X+0.5, tickStart.Y+0.5);
ctx.LineTo (tickEnd.X+0.5, tickEnd.Y+0.5);
ctx.Stroke ();
// calculate bounds of tick.
double minX = Math.Min (tickStart.X, tickEnd.X);
double minY = Math.Min (tickStart.Y, tickEnd.Y);
double maxX = Math.Max (tickStart.X, tickEnd.X);
double maxY = Math.Max (tickStart.Y, tickEnd.Y);
boundingBox = new Rectangle (minX, minY, maxX-minX, maxY-minY);
// by default, label offset from axis is 0. TODO: revise this.
labelOffset = new Point (-tickVector.X, -tickVector.Y);
// ------------------------
// now draw associated text.
// **** TODO ****
// The following code needs revising. A few things are hard coded when
// they should not be. Also, angled tick text currently just works for
// the bottom x-axis. Also, it's a bit hacky.
if (text != "" && !HideTickText) {
TextLayout layout = new TextLayout ();
layout.Font = tickTextFontScaled;
layout.Text = text;
Size textSize = layout.GetSize ();
// determine the center point of the tick text.
double textCenterX;
double textCenterY;
// if text is at pointy end of tick.
if (!TickTextNextToAxis) {
// offset due to tick.
textCenterX = tickStart.X + tickVector.X*1.2;
textCenterY = tickStart.Y + tickVector.Y*1.2;
// offset due to text box size.
textCenterX += 0.5 * x1 * textSize.Width;
textCenterY += 0.5 * y1 * textSize.Height;
}
// else it's next to the axis.
else {
// start location.
textCenterX = tickStart.X;
textCenterY = tickStart.Y;
// offset due to text box size.
textCenterX -= 0.5 * x1 * textSize.Width;
//.........这里部分代码省略.........
示例7: DrawLineOrShadow
/// <summary>
/// Draws the line plot using the Context and Physical Axes provided
/// </summary>
/// <param name="ctx">The Drawing Context with which to draw.</param>
/// <param name="xAxis">The X-Axis to draw against.</param>
/// <param name="yAxis">The Y-Axis to draw against.</param>
/// <param name="drawShadow">If true draw the shadow for the line. If false, draw line.</param>
public void DrawLineOrShadow(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis, bool drawShadow)
{
SequenceAdapter data = new SequenceAdapter (DataSource, DataMember, OrdinateData, AbscissaData);
ITransform2D t = Transform2D.GetTransformer (xAxis, yAxis);
int numberPoints = data.Count;
if (data.Count == 0) {
return;
}
ctx.Save ();
ctx.SetLineWidth (lineWidth_);
// clipping is now handled assigning a clip region in the
// graphic object before this call
if (numberPoints == 1) {
Point physical = t.Transform (data[0]);
if (drawShadow) {
ctx.SetColor (shadowColor_);
ctx.MoveTo (physical.X - 0.5 + ShadowOffset.X, physical.Y + ShadowOffset.Y);
ctx.LineTo (physical.X + 0.5 + ShadowOffset.X, physical.Y + ShadowOffset.Y);
ctx.Stroke ();
}
else {
ctx.SetColor (lineColor_);
ctx.MoveTo (physical.X-0.5, physical.Y);
ctx.LineTo (physical.X+0.5, physical.Y);
ctx.Stroke ();
}
}
else {
// prepare for clipping
double leftCutoff = xAxis.PhysicalToWorld (xAxis.PhysicalMin, false);
double rightCutoff = xAxis.PhysicalToWorld (xAxis.PhysicalMax, false);
if (leftCutoff > rightCutoff) {
Utils.Swap (ref leftCutoff, ref rightCutoff);
}
if (drawShadow) {
// correct cut-offs
double shadowCorrection =
xAxis.PhysicalToWorld (ShadowOffset, false) - xAxis.PhysicalToWorld (new Point(0,0), false);
leftCutoff -= shadowCorrection;
rightCutoff -= shadowCorrection;
}
for (int i = 1; i < numberPoints; ++i) {
// check to see if any values null. If so, then continue.
double dx1 = data[i-1].X;
double dx2 = data[i].X;
double dy1 = data[i-1].Y;
double dy2 = data[i].Y;
if (Double.IsNaN(dx1) || Double.IsNaN(dy1) || Double.IsNaN(dx2) || Double.IsNaN(dy2)) {
continue;
}
// do horizontal clipping here, to speed up
if ((dx1 < leftCutoff && dx2 < leftCutoff) || (rightCutoff < dx1 && rightCutoff < dx2)) {
continue;
}
// else draw line.
Point p1 = t.Transform (data[i-1]);
Point p2 = t.Transform (data[i]);
// when very far zoomed in, points can fall ontop of each other,
// and g.DrawLine throws an overflow exception
if (p1.Equals(p2)) {
continue;
}
if (drawShadow) {
ctx.SetColor (shadowColor_);
ctx.MoveTo (p1.X + ShadowOffset.X, p1.Y + ShadowOffset.Y);
ctx.LineTo (p2.X + ShadowOffset.X, p2.Y + ShadowOffset.Y);
ctx.Stroke ();
}
else {
ctx.SetColor (lineColor_);
ctx.MoveTo (p1.X, p1.Y);
ctx.LineTo (p2.X, p2.Y);
ctx.Stroke ();
}
}
}
ctx.Restore ();
}
示例8: Draw
/// <summary>
/// Draws the arrow on a plot surface.
/// </summary>
/// <param name="ctx">the Drawing Context with which to draw</param>
/// <param name="xAxis">The X-Axis to draw against.</param>
/// <param name="yAxis">The Y-Axis to draw against.</param>
public void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis )
{
if (To.X > xAxis.Axis.WorldMax || To.X < xAxis.Axis.WorldMin) {
return;
}
if (To.Y > yAxis.Axis.WorldMax || To.Y < yAxis.Axis.WorldMin) {
return;
}
ctx.Save ();
TextLayout layout = new TextLayout ();
layout.Font = textFont_;
layout.Text = text_;
double angle = angle_;
if (angle_ < 0.0) {
int mul = -(int)(angle_ / 360.0) + 2;
angle = angle_ + 360.0 * (double)mul;
}
double normAngle = (double)angle % 360.0; // angle in range 0 -> 360.
Point toPoint = new Point (
xAxis.WorldToPhysical (to_.X, true).X,
yAxis.WorldToPhysical (to_.Y, true).Y);
double xDir = Math.Cos (normAngle * 2.0 * Math.PI / 360.0);
double yDir = Math.Sin (normAngle * 2.0 * Math.PI / 360.0);
toPoint.X += xDir*headOffset_;
toPoint.Y += yDir*headOffset_;
double xOff = physicalLength_ * xDir;
double yOff = physicalLength_ * yDir;
Point fromPoint = new Point(
(int)(toPoint.X + xOff),
(int)(toPoint.Y + yOff) );
ctx.SetLineWidth (1);
ctx.SetColor (arrowColor_);
ctx.MoveTo (fromPoint);
ctx.LineTo (toPoint);
ctx.Stroke ();
xOff = headSize_ * Math.Cos ((normAngle-headAngle_/2) * 2.0 * Math.PI / 360.0);
yOff = headSize_ * Math.Sin ((normAngle-headAngle_/2) * 2.0 * Math.PI / 360.0);
ctx.LineTo (toPoint.X + xOff, toPoint.Y + yOff);
double xOff2 = headSize_ * Math.Cos ((normAngle+headAngle_/2) * 2.0 * Math.PI / 360.0);
double yOff2 = headSize_ * Math.Sin ((normAngle+headAngle_/2) * 2.0 * Math.PI / 360.0);
ctx.LineTo (toPoint.X + xOff2, toPoint.Y + yOff2);
ctx.LineTo (toPoint);
ctx.ClosePath ();
ctx.SetColor (arrowColor_);
ctx.Fill ();
Size textSize = layout.GetSize ();
Size halfSize = new Size (textSize.Width/2, textSize.Height/2);
double quadrantSlideLength = halfSize.Width + halfSize.Height;
double quadrantD = normAngle / 90.0; // integer part gives quadrant.
int quadrant = (int)quadrantD; // quadrant in.
double prop = quadrantD - (double)quadrant; // proportion of way through this qadrant.
double dist = prop * quadrantSlideLength; // distance along quarter of bounds rectangle.
// now find the offset from the middle of the text box that the
// rear end of the arrow should end at (reverse this to get position
// of text box with respect to rear end of arrow).
//
// There is almost certainly an elgant way of doing this involving
// trig functions to get all the signs right, but I'm about ready to
// drop off to sleep at the moment, so this blatent method will have
// to do.
Point offsetFromMiddle = new Point (0, 0);
switch (quadrant) {
case 0:
if (dist > halfSize.Height) {
dist -= halfSize.Height;
offsetFromMiddle = new Point ( -halfSize.Width + dist, halfSize.Height );
}
else {
offsetFromMiddle = new Point ( -halfSize.Width, - dist );
}
break;
case 1:
if (dist > halfSize.Width) {
dist -= halfSize.Width;
offsetFromMiddle = new Point ( halfSize.Width, halfSize.Height - dist );
}
//.........这里部分代码省略.........
示例9: PathTo
void PathTo (Context ctx, double x, double y, bool stroke)
{
if (stroke)
ctx.LineTo (x, y);
else
ctx.MoveTo (x, y);
}
示例10: DrawInLegend
/// <summary>
/// Draws a representation of this plot in the legend.
/// </summary>
/// <param name="ctx">The Drawing Context with which to draw.</param>
/// <param name="startEnd">A rectangle specifying the bounds of the area in the legend set aside for drawing.</param>
public void DrawInLegend(Context ctx, Rectangle startEnd )
{
ctx.Save ();
if (marker.Size > 0) {
marker.Draw (ctx, (startEnd.Left + startEnd.Right) / 2, (startEnd.Top + startEnd.Bottom) / 2);
}
else if (marker.LineWidth > 0) {
ctx.SetLineWidth (marker.LineWidth);
ctx.SetColor (marker.LineColor);
ctx.MoveTo ((startEnd.Left + startEnd.Right)/2, (startEnd.Top + startEnd.Bottom - marker.LineWidth)/2);
ctx.LineTo ((startEnd.Left + startEnd.Right)/2, (startEnd.Top + startEnd.Bottom + marker.LineWidth)/2);
ctx.Stroke ();
}
ctx.Restore ();
}
示例11: DrawGridLines
/// <summary>
/// Does all the work in drawing grid lines.
/// </summary>
/// <param name="ctx">The graphics context with which to draw</param>
/// <param name="axis">TODO</param>
/// <param name="orthogonalAxis">TODO</param>
/// <param name="a">the list of world values to draw grid lines at.</param>
/// <param name="horizontal">true if want horizontal lines, false otherwise.</param>
/// <param name="color">the color to draw the grid lines.</param>
private void DrawGridLines(Context ctx,
PhysicalAxis axis, PhysicalAxis orthogonalAxis,
System.Collections.ArrayList a, bool horizontal)
{
for (int i=0; i<a.Count; ++i) {
Point p1 = axis.WorldToPhysical ((double)a[i], true);
Point p2 = p1;
Point p3 = orthogonalAxis.PhysicalMax;
Point p4 = orthogonalAxis.PhysicalMin;
if (horizontal) {
p1.Y = p4.Y;
p2.Y = p3.Y;
}
else {
p1.X = p4.X;
p2.X = p3.X;
}
ctx.MoveTo (p1);
ctx.LineTo (p2);
}
ctx.SetLineWidth (1);
ctx.SetColor (gridColor);
ctx.SetLineDash (0, gridDash);
ctx.Stroke ();
}
示例12: DrawBorder
void DrawBorder(Context ctx, double x, double y, double w, double h, double radius, double thickness)
{
// test limits (without using multiplication)
if (radius > w - radius)
radius = w / 2;
if (radius > h - radius)
radius = h / 2;
// approximate (quite close) the arc using a bezier curve
double arc = ArcToBezier * radius;
ctx.SetLineWidth (thickness);
// top-left corner
ctx.NewPath ();
ctx.MoveTo (x, y + radius);
ctx.CurveTo (x, y + radius - arc, x + radius - arc, y, x + radius, y);
ctx.Pattern = GetCornerGradient (x + radius, y + radius, radius, thickness / 2);
ctx.Stroke ();
// top edge
ctx.NewPath ();
ctx.MoveTo (x + radius - 0.5, y);
ctx.LineTo (x + w - radius + 0.5, y);
ctx.Pattern = GetTopEdgeGradient (y, thickness / 2);
ctx.Stroke ();
// top-right corner
ctx.NewPath ();
ctx.MoveTo (x + w - radius, y);
ctx.CurveTo (x + w - radius + arc, y, x + w, y + arc, x + w, y + radius);
ctx.Pattern = GetCornerGradient (x + w - radius, y + radius, radius, thickness / 2);
ctx.Stroke ();
// right edge
ctx.NewPath ();
ctx.MoveTo (x + w, y + radius - 0.5);
ctx.LineTo (x + w, y + h - radius + 0.5);
ctx.Pattern = GetRightEdgeGradient (x + w, thickness / 2);
ctx.Stroke ();
// bottom-right corner
ctx.NewPath ();
ctx.MoveTo (x + w, y + h - radius);
ctx.CurveTo (x + w, y + h - radius + arc, x + w + arc - radius, y + h, x + w - radius, y + h);
ctx.Pattern = GetCornerGradient (x + w - radius, y + h - radius, radius, thickness / 2);
ctx.Stroke ();
// bottom edge
ctx.NewPath ();
ctx.MoveTo (x + w - radius + 0.5, y + h);
ctx.LineTo (x + radius - 0.5, y + h);
ctx.Pattern = GetBottomEdgeGradient (y + h, thickness / 2);
ctx.Stroke ();
// bottom-left corner
ctx.NewPath ();
ctx.MoveTo (x + radius, y + h);
ctx.CurveTo (x + radius - arc, y + h, x, y + h - arc, x, y + h - radius);
ctx.Pattern = GetCornerGradient (x + radius, y + h - radius, radius, thickness / 2);
ctx.Stroke ();
// left edge
ctx.NewPath ();
ctx.MoveTo (x, y + h - radius + 0.5);
ctx.LineTo (x, y + radius - 0.5);
ctx.Pattern = GetLeftEdgeGradient (x, thickness / 2);
ctx.Stroke ();
}
示例13: OnDraw
/// <summary>
/// Called when the widget needs to be redrawn
/// </summary>
/// <param name='ctx'>
/// Drawing context
/// </param>
/// <param name="dirtyRect"></param>
protected override void OnDraw(Context ctx, Rectangle dirtyRect)
{
if (Bounds.IsEmpty)
return;
base.OnDraw(ctx, dirtyRect);
// apply scale factor
dirtyRect.X /= scaleFactor;
dirtyRect.Y /= scaleFactor;
dirtyRect.Width /= scaleFactor;
dirtyRect.Height /= scaleFactor;
// actual drawing
bool redraw = Draw(ctx, dirtyRect, scaleFactor);
// draw minimap
if (ShowMiniMap && MinWidth > 0 && MinHeight > 0) {
Point size = new Point(180.0, 180.0 * (MinHeight / MinWidth));
double minimapScale = Math.Min(size.X / MinWidth, size.Y / MinHeight);
Point minimapPosition =
new Point(
scrollview.HorizontalScrollControl.Value + scrollview.HorizontalScrollControl.PageSize - size.X - 16,
scrollview.VerticalScrollControl.Value + 16);
ctx.RoundRectangle(minimapPosition, size.X, size.Y, 6);
ctx.SetColor(Colors.LightGray.WithAlpha(0.4));
ctx.Fill();
ctx.Save();
ctx.Translate(minimapPosition);
Draw(ctx, new Rectangle(0, 0, MinWidth, MinHeight), minimapScale);
ctx.Restore();
}
// set canvas min size
foreach (PipelineNode node in nodes) {
Rectangle boundwe = node.BoundWithExtras;
if (boundwe.Right * scaleFactor > MinWidth) {
MinWidth = boundwe.Right * scaleFactor + PipelineNode.NodeMargin.Right;
}
if (boundwe.Bottom * scaleFactor > MinHeight) {
MinHeight = boundwe.Bottom * scaleFactor + PipelineNode.NodeMargin.Bottom;
}
Point offset = new Point(Math.Max(0, -boundwe.Left), Math.Max(0, -boundwe.Top));
if (offset != Point.Zero) {
TranslateAllNodesBy(offset);
redraw = true;
QueueDraw();
}
}
// update things
if (mouseAction.HasFlag(MouseAction.MoveNode)) {
// move scrollbar
Rectangle boundwe = lastSelectedNode.BoundWithExtras;
boundwe.X *= scaleFactor;
boundwe.Y *= scaleFactor;
boundwe.Height *= scaleFactor;
boundwe.Width *= scaleFactor;
double viewportRight = scrollview.HorizontalScrollControl.Value + scrollview.Size.Width;
double offsetH = (nodeToMoveOffset.X + boundwe.Width) * 0.5 / scaleFactor;
if (boundwe.Right - offsetH > viewportRight) {
scrollview.HorizontalScrollControl.Value += boundwe.Right - offsetH - viewportRight;
} else if (boundwe.Left + offsetH < scrollview.HorizontalScrollControl.Value) {
scrollview.HorizontalScrollControl.Value -= scrollview.HorizontalScrollControl.Value - offsetH - boundwe.Left;
}
double viewportBottom = scrollview.VerticalScrollControl.Value + scrollview.Size.Height;
double offsetV = (nodeToMoveOffset.Y + boundwe.Height) * 0.5;
if (boundwe.Bottom - offsetV > viewportBottom) {
scrollview.VerticalScrollControl.Value += boundwe.Bottom - offsetV - viewportBottom;
} else if (boundwe.Top + offsetV < scrollview.VerticalScrollControl.Value) {
scrollview.VerticalScrollControl.Value -= scrollview.VerticalScrollControl.Value - offsetV - boundwe.Top;
}
}
if ((mouseAction.HasFlag(MouseAction.AddEdge) || mouseAction.HasFlag(MouseAction.MoveEdge)) &&
!mouseAction.HasFlag(MouseAction.AddEdgeNew)) {
ctx.MoveTo(
connectNodesStartMarker.IsInput ?
connectNodesStartMarker.Bounds.Left * scaleFactor :
connectNodesStartMarker.Bounds.Right * scaleFactor,
connectNodesStartMarker.Bounds.Center.Y * scaleFactor
);
ctx.LineTo(connectNodesEnd.X * scaleFactor, connectNodesEnd.Y * scaleFactor);
ctx.Stroke();
}
// set redraw finish?
redrawQueued = redraw;
//.........这里部分代码省略.........
示例14: Draw
/// <summary>
/// Draw the filled region
/// </summary>
/// <param name="g">The Drawing Context with which to draw.</param>
/// <param name="xAxis">The X-Axis to draw against.</param>
/// <param name="yAxis">The Y-Axis to draw against.</param>
public void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis)
{
ITransform2D t = Transform2D.GetTransformer (xAxis, yAxis);
ctx.Save ();
if (hl1 != null && hl2 != null) {
ctx.MoveTo (t.Transform (xAxis.Axis.WorldMin, hl1.OrdinateValue));
ctx.LineTo (t.Transform (xAxis.Axis.WorldMax, hl1.OrdinateValue));
ctx.LineTo (t.Transform (xAxis.Axis.WorldMax, hl2.OrdinateValue));
ctx.LineTo (t.Transform (xAxis.Axis.WorldMin, hl2.OrdinateValue));
ctx.ClosePath ();
} else if (vl1 != null && vl2 != null) {
ctx.MoveTo (t.Transform (vl1.AbscissaValue, yAxis.Axis.WorldMin));
ctx.LineTo (t.Transform (vl1.AbscissaValue, yAxis.Axis.WorldMax));
ctx.LineTo (t.Transform (vl2.AbscissaValue, yAxis.Axis.WorldMax));
ctx.LineTo (t.Transform (vl2.AbscissaValue, yAxis.Axis.WorldMin));
ctx.ClosePath ();
} else if (lp1 != null && lp2 != null) {
SequenceAdapter a1 = new SequenceAdapter (lp1.DataSource, lp1.DataMember, lp1.OrdinateData, lp1.AbscissaData);
SequenceAdapter a2 = new SequenceAdapter (lp2.DataSource, lp2.DataMember, lp2.OrdinateData, lp2.AbscissaData);
// Start at first point of LinePlot 1 within plot bounds
int start = 0;
while (t.Transform (a1 [start]).X < xAxis.PhysicalMin.X) {
++start;
}
Point first = t.Transform (a1 [start]);
ctx.MoveTo (first);
// Join LinePlot 1 points in ascending order
Point next;
for (int i = start+1; i < a1.Count-1; ++i) {
next = t.Transform (a1 [i]);
if (next.X > xAxis.PhysicalMax.X)
break;
ctx.LineTo (next);
}
// Then join LinePlot 2 points in descending order
int end = a2.Count-1;
while (t.Transform (a2 [end]).X > xAxis.PhysicalMax.X) {
--end;
}
for (int i = end; i > 0; --i) {
next = t.Transform (a2 [i]);
if (next.X < xAxis.PhysicalMin.X)
break;
ctx.LineTo (next);
}
ctx.LineTo (first);
ctx.ClosePath ();
}
else {
throw new XwPlotException ("Filled Region bounds not defined");
}
ctx.SetColor (FillColor);
ctx.Fill ();
ctx.Restore ();
}
示例15: OnDraw
protected override void OnDraw(Context ctx, Rectangle dirtyRect)
{
base.OnDraw(ctx, dirtyRect);
if (image != null) {
if (Heighlighted && IsThumbnail) {
ctx.RoundRectangle(new Rectangle(Point.Zero, image.Size), 3);
ctx.SetColor(Colors.LightSteelBlue);
ctx.Fill();
}
ctx.DrawImage(image, (new Rectangle(Point.Zero, image.Size)).Inflate(-3, -3));
if (mask != null && ShowMask) {
ctx.DrawImage(MaskBitmap, (new Rectangle(Point.Zero, image.Size)).Inflate(-3, -3), 0.6);
}
}
if (isEditMode) {
Point scaleFactor = new Point(
scan.Size.Width / image.Size.Width,
scan.Size.Height / image.Size.Height);
ctx.SetColor(Mask.maskColor);
foreach (MaskEntry p in scan.Mask.MaskPositions) {
switch (p.type) {
case MaskEntryType.Point:
ctx.SetLineWidth(p.pointerSize / scaleFactor.Y * 2);
ctx.LineTo(p.position.X / scaleFactor.X, p.position.Y / scaleFactor.Y);
ctx.Stroke();
ctx.Arc(
p.position.X / scaleFactor.X, p.position.Y / scaleFactor.Y,
p.pointerSize / scaleFactor.Y, 0, 360);
ctx.Fill();
ctx.MoveTo(p.position.X / scaleFactor.X, p.position.Y / scaleFactor.Y);
break;
case MaskEntryType.Space:
ctx.Stroke();
ctx.ClosePath();
break;
case MaskEntryType.Delete:
ctx.Arc(
p.position.X / scaleFactor.X, p.position.Y / scaleFactor.Y,
p.pointerSize / scaleFactor.Y, 0, 360);
ctx.Save();
ctx.Clip();
int newX = (int) Math.Min(Math.Max(
p.position.X / scaleFactor.X - pointerSize / scaleFactor.Y, 0), scan.Size.Width);
int newY = (int) Math.Min(Math.Max(
p.position.Y / scaleFactor.Y - pointerSize / scaleFactor.Y, 0), scan.Size.Height);
using (ImageBuilder ib =
new ImageBuilder((pointerSize / scaleFactor.Y * 2), (pointerSize / scaleFactor.Y * 2))) {
BitmapImage bi = ib.ToBitmap();
image.WithBoxSize(image.Size).ToBitmap().CopyArea(
newX, newY,
(int) (pointerSize / scaleFactor.Y * 2), (int) (pointerSize / scaleFactor.Y * 2),
bi, 0, 0);
ctx.DrawImage(bi, new Point(newX, newY));
}
ctx.Restore();
ctx.ClosePath();
break;
}
}
ctx.Stroke();
if (mousePosition != Point.Zero) {
ctx.Arc(mousePosition.X, mousePosition.Y, pointerSize / Math.Max(scaleFactor.X, scaleFactor.Y), 0, 360);
ctx.Fill();
if (mousePositionStart != Point.Zero) {
ctx.SetLineWidth((pointerSize / Math.Max(scaleFactor.X, scaleFactor.Y)) * 2);
ctx.SetColor(Mask.maskColor);
ctx.Arc(mousePositionStart.X, mousePositionStart.Y, pointerSize / Math.Max(scaleFactor.X, scaleFactor.Y), 0, 360);
ctx.Fill();
ctx.MoveTo(mousePosition);
ctx.LineTo(mousePositionStart);
ctx.Stroke();
}
}
}
}