Skip to content

Commit a37d7f6

Browse files
author
YCode
committed
chore: 折线
1 parent 01f051c commit a37d7f6

File tree

3 files changed

+39
-44
lines changed

3 files changed

+39
-44
lines changed

YCode.Designer.Demo/Demo/Playground/Playground.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
Mounted="OnMounted"
4040
GridType="Dot"
4141
LineType="Step"
42+
Orientation="Vertical"
4243
ToolTemplate="{StaticResource ToolDataTemplate}"
4344
ItemContainerStyle="{StaticResource FluxoNodeStyle}"
4445
Source="{Binding Source}" />

YCode.Designer.Fluxo/Lines/FluxoLine.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -146,21 +146,6 @@ protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
146146
base.OnPropertyChanged(e);
147147
}
148148

149-
protected override void OnRender(DrawingContext drawingContext)
150-
{
151-
base.OnRender(drawingContext);
152-
153-
var line = _container.GetLineProvider(_designer.LineType);
154-
155-
var p = line?.GetPoint(0.1);
156-
157-
if (p.HasValue)
158-
{
159-
drawingContext.DrawRectangle(Brushes.Orange, new Pen(Brushes.Transparent, 1),
160-
new Rect(p.Value.X - 5, p.Value.Y - 5, 10, 10));
161-
}
162-
}
163-
164149
private (Point, Point) DrawLine(StreamGeometryContext context, FluxoNode source, FluxoNode target)
165150
{
166151
var line = _container.GetLineProvider(_designer.LineType);

YCode.Designer.Fluxo/Lines/Impl/FluxoStepLine.cs

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ protected override void OnHorizontal()
2525

2626
protected override void OnVertical()
2727
{
28-
throw new NotImplementedException();
28+
var points = GetLinePoints(this.Parameter.Source.Bottom, this.Parameter.Target.Top);
29+
30+
this.Points.AddRanage([points.P0, points.P1, points.P2, points.P3]);
2931
}
3032

3133
protected override void OnCross()
@@ -42,7 +44,8 @@ protected override void OnCross()
4244

4345
this.Parameter.End = target + new Vector(_spacing * targetDir.X, _spacing * targetDir.Y);
4446

45-
var connectionDir = GetConnectionDirection(this.Parameter.Start, this.Parameter.SourcePosition, this.Parameter.End);
47+
var connectionDir =
48+
GetConnectionDirection(this.Parameter.Start, this.Parameter.SourcePosition, this.Parameter.End);
4649

4750
var horizontalConnection = connectionDir.X != 0;
4851

@@ -60,7 +63,9 @@ protected override void OnCross()
6063
}
6164

6265
var isSameDir = horizontalConnection ? sourceDir.X == targetDir.Y : sourceDir.Y == targetDir.X;
63-
var startGreaterThanEnd = horizontalConnection ? this.Parameter.Start.Y > this.Parameter.End.Y : this.Parameter.Start.X > this.Parameter.End.X;
66+
var startGreaterThanEnd = horizontalConnection
67+
? this.Parameter.Start.Y > this.Parameter.End.Y
68+
: this.Parameter.Start.X > this.Parameter.End.X;
6469

6570
var positiveDir = horizontalConnection ? sourceDir.X == 1 : sourceDir.Y == 1;
6671
var shouldFlip = positiveDir
@@ -85,8 +90,10 @@ protected override void OnCross()
8590
{
8691
var center = this.Parameter.Start + (this.Parameter.End - this.Parameter.Start) / 2;
8792

88-
(Point P1, Point P2) verticalSplit = (new Point(center.X, this.Parameter.Start.Y), new Point(center.X, this.Parameter.End.Y));
89-
(Point P1, Point P2) horizontalSplit = (new Point(this.Parameter.Start.X, center.Y), new Point(this.Parameter.End.X, center.Y));
93+
(Point P1, Point P2) verticalSplit = (new Point(center.X, this.Parameter.Start.Y),
94+
new Point(center.X, this.Parameter.End.Y));
95+
(Point P1, Point P2) horizontalSplit = (new Point(this.Parameter.Start.X, center.Y),
96+
new Point(this.Parameter.End.X, center.Y));
9097

9198
if (horizontalConnection)
9299
{
@@ -125,7 +132,7 @@ static Point GetConnectorDirection(FluxoLinePosition position)
125132
FluxoLinePosition.Left => new Point(-1, 0),
126133
FluxoLinePosition.Bottom => new Point(0, 1),
127134
FluxoLinePosition.Right => new Point(1, 0),
128-
_ => default,
135+
_ => default
129136
};
130137

131138
static bool IsOppositePosition(FluxoLinePosition sourcePosition, FluxoLinePosition targetPosition)
@@ -137,40 +144,42 @@ static bool IsOppositePosition(FluxoLinePosition sourcePosition, FluxoLinePositi
137144
}
138145
}
139146

140-
public override Point GetPoint(double target) { var current = 0d;
141-
var start = this.Points[0];
147+
public override Point GetPoint(double target)
148+
{
149+
var current = 0d;
150+
var start = this.Points[0];
142151

143-
var length = this.GetLength();
152+
var length = this.GetLength();
144153

145-
var targetLength = length * target;
154+
var targetLength = length * target;
146155

147-
var prePoint = new Point(start.X, start.Y);
156+
var prePoint = new Point(start.X, start.Y);
148157

149-
for (var i = 1; i < this.Points.Count; i++)
150-
{
151-
var pointToLength = Math.Sqrt(Math.Pow(prePoint.X - this.Points[i].X, 2) +
152-
Math.Pow(prePoint.Y - this.Points[i].Y, 2));
158+
for (var i = 1; i < this.Points.Count; i++)
159+
{
160+
var pointToLength = Math.Sqrt(Math.Pow(prePoint.X - this.Points[i].X, 2) +
161+
Math.Pow(prePoint.Y - this.Points[i].Y, 2));
153162

154-
var distance = Point.Subtract(this.Points[i], prePoint).Length;
163+
var distance = Point.Subtract(this.Points[i], prePoint).Length;
155164

156-
if (current + distance >= targetLength)
157-
{
158-
var extra = targetLength - current;
165+
if (current + distance >= targetLength)
166+
{
167+
var extra = targetLength - current;
159168

160-
var factor = extra / distance;
169+
var factor = extra / distance;
161170

162-
return new Point(
163-
prePoint.X + (factor * (this.Points[i].X - prePoint.X)),
164-
prePoint.Y + (factor * (this.Points[i].Y - prePoint.Y)));
165-
}
171+
return new Point(
172+
prePoint.X + (factor * (this.Points[i].X - prePoint.X)),
173+
prePoint.Y + (factor * (this.Points[i].Y - prePoint.Y)));
174+
}
166175

167-
prePoint = this.Points[i];
176+
prePoint = this.Points[i];
168177

169-
current += pointToLength;
170-
}
178+
current += pointToLength;
179+
}
171180

172-
return prePoint;
173-
}
181+
return prePoint;
182+
}
174183

175184
public override double GetLength()
176185
{

0 commit comments

Comments
 (0)