Skip to content

Commit fba2e45

Browse files
committed
GtkBackend,Gtk3Backend: Fix path start point handling
1 parent 6710908 commit fba2e45

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

Sources/Gtk3Backend/Gtk3Backend.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1296,13 +1296,19 @@ public final class Gtk3Backend: AppBackend {
12961296
}
12971297
}
12981298

1299-
for action in actions {
1299+
for (index, action) in actions.enumerated() {
13001300
switch action {
13011301
case .moveTo(let point):
13021302
cairo_move_to(cairo, point.x, point.y)
13031303
case .lineTo(let point):
1304+
if index == 0 {
1305+
cairo_move_to(cairo, 0, 0)
1306+
}
13041307
cairo_line_to(cairo, point.x, point.y)
13051308
case .quadCurve(let control, let end):
1309+
if index == 0 {
1310+
cairo_move_to(cairo, 0, 0)
1311+
}
13061312
var startX = 0.0
13071313
var startY = 0.0
13081314
cairo_get_current_point(cairo, &startX, &startY)
@@ -1316,6 +1322,9 @@ public final class Gtk3Backend: AppBackend {
13161322
end.x, end.y
13171323
)
13181324
case .cubicCurve(let control1, let control2, let end):
1325+
if index == 0 {
1326+
cairo_move_to(cairo, 0, 0)
1327+
}
13191328
cairo_curve_to(
13201329
cairo,
13211330
control1.x, control1.y,

Sources/GtkBackend/GtkBackend.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1341,13 +1341,19 @@ public final class GtkBackend: AppBackend {
13411341
}
13421342
}
13431343

1344-
for action in actions {
1344+
for (index, action) in actions.enumerated() {
13451345
switch action {
13461346
case .moveTo(let point):
13471347
cairo_move_to(cairo, point.x, point.y)
13481348
case .lineTo(let point):
1349+
if index == 0 {
1350+
cairo_move_to(cairo, 0, 0)
1351+
}
13491352
cairo_line_to(cairo, point.x, point.y)
13501353
case .quadCurve(let control, let end):
1354+
if index == 0 {
1355+
cairo_move_to(cairo, 0, 0)
1356+
}
13511357
var startX = 0.0
13521358
var startY = 0.0
13531359
cairo_get_current_point(cairo, &startX, &startY)
@@ -1361,6 +1367,9 @@ public final class GtkBackend: AppBackend {
13611367
end.x, end.y
13621368
)
13631369
case .cubicCurve(let control1, let control2, let end):
1370+
if index == 0 {
1371+
cairo_move_to(cairo, 0, 0)
1372+
}
13641373
cairo_curve_to(
13651374
cairo,
13661375
control1.x, control1.y,

Sources/SwiftCrossUI/Values/Path.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,11 @@ public struct Path {
201201
/// The types of actions that can be performed on a path.
202202
public enum Action: Equatable {
203203
case moveTo(SIMD2<Double>)
204+
/// If this is the first action in a path then (0, 0) is inferred to be the start point.
204205
case lineTo(SIMD2<Double>)
206+
/// If this is the first action in a path then (0, 0) is inferred to be the start point.
205207
case quadCurve(control: SIMD2<Double>, end: SIMD2<Double>)
208+
/// If this is the first action in a path then (0, 0) is inferred to be the start point.
206209
case cubicCurve(control1: SIMD2<Double>, control2: SIMD2<Double>, end: SIMD2<Double>)
207210
case rectangle(Rect)
208211
case circle(center: SIMD2<Double>, radius: Double)

0 commit comments

Comments
 (0)