1
1
mirror of https://github.com/exyte/Macaw.git synced 2024-09-11 13:15:35 +03:00

Fix Gradient.userSpace. Update ShapesExampleView.

This commit is contained in:
Yuri Strot 2016-09-12 01:16:20 +07:00
parent 162cde28b4
commit 4ec5c6299a
4 changed files with 1190 additions and 1260 deletions

View File

@ -77,7 +77,6 @@ class PathExampleView: MacawView {
form: lightning(),
place: Transform.move(dx: 375, dy: 390).scale(sx: 3, sy: 3),
fill: LinearGradient(
userSpace: true,
stops: [
Stop(offset: 0, color: Color.rgb(r: 250, g: 220, b: 0)),
Stop(offset: 1, color: Color(val: 0xeb6405))
@ -90,7 +89,6 @@ class PathExampleView: MacawView {
form: cloud1(),
place: .move(dx: 120, dy: 120),
fill: LinearGradient(
userSpace: false,
stops: [
Stop(offset: 0, color: Color(val: 0x2f3036)),
Stop(offset: 1, color: Color.rgba(r: 47, g: 48, b: 54, a: 0.1))

View File

@ -12,136 +12,69 @@ import Macaw
class ShapesExampleView: MacawView {
required init?(coder aDecoder: NSCoder) {
let rect = Rect(x: 50, y: 50, w: 50, h: 100)
let shape1 = Shape(
form: rect,
fill: Color.blue
)
let text1 = ShapesExampleView.newText("Point", .move(dx: 100, dy: 40))
let point = Point(x: 100, y: 50).stroke(fill: Color.black, width: 7, cap: .round)
let round = RoundRect(
rect: Rect(x: 150, y: 50, w: 50, h: 100),
rx: 10,
ry: 10
)
let shape2 = Shape(
form: round,
fill: Color.navy
)
let text2 = ShapesExampleView.newText("Line", .move(dx: 250, dy: 40))
let line = Line(x1: 200, y1: 50, x2: 300, y2: 50).stroke(fill: Color.black, width: 4)
let circle = Circle(cx: 50, cy: 200, r: 30)
let shape3 = Shape(
form: circle,
fill: Color.purple
)
let text3 = ShapesExampleView.newText("Polyline", .move(dx: 100, dy: 90))
let polyline = Polyline(points: [100, 100, 150, 150, 50, 150]).stroke(fill: Color.navy, dashes: [3, 3])
let ellipse = Ellipse(cx: 150, cy: 200, rx: 50, ry: 30)
let shape4 = Shape(
form: ellipse,
fill: Color.fuchsia
)
let text4 = ShapesExampleView.newText("Polygon", .move(dx: 250, dy: 90))
let polygon = Polygon(points: [250, 100, 300, 150, 200, 150]).fill(with: Color.blue)
let polygon = Polygon(points: [280, 60, 240, 95, 330, 150, 330, 100])
let shape5 = Shape(
form: polygon,
fill: Color.aqua
)
let text5 = ShapesExampleView.newText("Rect", .move(dx: 100, dy: 200))
let rect = Rect(x: 50, y: 200, w: 100, h: 50).fill(with: LinearGradient(
x2: 1, y2: 1,
stops: [
Stop(offset: 0, color: Color(val: 0xFFAE27)),
Stop(offset: 1, color: Color(val: 0xDE496D))
]
))
let polyline = Polyline(points: [260, 150, 220, 185, 310, 240, 310, 190])
let shape6 = Shape(
form: polyline,
stroke: Stroke(
fill: Color.olive,
width: 5,
cap: .round,
join: .round
)
)
let text6 = ShapesExampleView.newText("RoundRect", .move(dx: 250, dy: 200))
let round = Rect(x: 200, y: 200, w: 100, h: 50).round(rx: 10, ry: 10).fill(with: LinearGradient(
x2: 1, y2: 1,
stops: [
Stop(offset: 0, color: Color(val: 0xDE496D)),
Stop(offset: 0.5, color: Color(val: 0xAB49DE)),
Stop(offset: 1, color: Color(val: 0x4954DE))
]
))
let line = Line(x1: 30, y1: 290, x2: 130, y2: 290)
let shape7 = Shape(
form: line,
stroke: Stroke(
fill: Color.lime,
width: 10,
cap: .round,
join: .round
)
)
let text7 = ShapesExampleView.newText("Circle", .move(dx: 75, dy: 300))
let circle = Circle(cx: 75, cy: 325, r: 25).fill(with: RadialGradient(
stops: [
Stop(offset: 0, color: Color(val: 0xF5027C)),
Stop(offset: 1, color: Color(val: 0x850143))
]
))
let arc = Arc(ellipse: Ellipse(cx: 250, cy: 300, rx: 35, ry: 60), shift: M_PI / 2, extent: M_PI)
let shape8 = Shape(
form: arc,
stroke: Stroke(
fill: Color.green,
width: 2,
cap: .round,
join: .round,
dashes: [3, 3]
)
)
let text8 = ShapesExampleView.newText("Ellipse", .move(dx: 175, dy: 300))
let ellipse = Ellipse(cx: 175, cy: 325, rx: 50, ry: 25).fill(with: RadialGradient(
fx: 0.05, fy: 0.05, r: 0.65,
stops: [
Stop(offset: 0, color: Color(val: 0x00ee00)),
Stop(offset: 1, color: Color(val: 0x006600))
]
))
let point = Point(x: 300, y: 290)
let shape9 = Shape(
form: point,
stroke: Stroke(
fill: Color.gray,
width: 7,
cap: .round,
join: .round
)
)
let triangle = Polygon(points: [50, 350, 20, 390, 80, 390])
let shape10 = Shape(
form: triangle,
fill: LinearGradient(
userSpace: false,
stops: [
Stop(offset: 0, color: Color(val: 0xC02425)),
Stop(offset: 1, color: Color(val: 0xF0CB35))
],
x1: 50,
y1: 350,
x2: 50,
y2: 390
)
)
let box = Rect(w: 40, h: 40)
let shape11 = Shape(
form: box,
place: .move(dx: 120, dy: 350),
fill: LinearGradient(
userSpace: true,
stops: [
Stop(offset: 0, color: Color.black),
Stop(offset: 0.5, color: Color.red),
Stop(offset: 1, color: Color.black)
],
x1: 0,
y1: 0,
x2: 1,
y2: 1
)
)
let text9 = ShapesExampleView.newText("Arc", .move(dx: 275, dy: 300))
let arc = Circle(cx: 250, cy: 300, r: 50).arc(shift: 0, extent: M_PI / 2).stroke(fill: Color.green)
let group = Group(
contents: [
shape1,
shape2,
shape3,
shape4,
shape5,
shape6,
shape7,
shape8,
shape9,
shape10,
shape11
point, line, polyline, polygon, rect, round, circle, ellipse, arc,
text1, text2, text3, text4, text5, text6, text7, text8, text9
]
)
super.init(node: group, coder: aDecoder)
}
private static func newText(text: String, _ place: Transform, baseline: Baseline = .bottom) -> Text {
return Text(text: text, fill: Color.black, baseline: baseline, align: .mid, place: place)
}
}

View File

@ -495,7 +495,7 @@ class ShapeRenderer: NodeRenderer {
if let gradient = gradient as? LinearGradient {
var start = CGPointMake(CGFloat(gradient.x1), CGFloat(gradient.y1))
var end = CGPointMake(CGFloat(gradient.x2), CGFloat(gradient.y2))
if gradient.userSpace {
if !gradient.userSpace {
let bounds = CGContextGetPathBoundingBox(ctx)
start = CGPointMake(start.x * bounds.width + bounds.minX, start.y * bounds.height + bounds.minY)
end = CGPointMake(end.x * bounds.width + bounds.minX, end.y * bounds.height + bounds.minY)
@ -507,7 +507,7 @@ class ShapeRenderer: NodeRenderer {
var innerCenter = CGPointMake(CGFloat(gradient.fx), CGFloat(gradient.fy))
var outerCenter = CGPointMake(CGFloat(gradient.cx), CGFloat(gradient.cy))
var radius = CGFloat(gradient.r)
if gradient.userSpace {
if !gradient.userSpace {
var bounds = CGContextGetPathBoundingBox(ctx)
var scaleX: CGFloat = 1
var scaleY: CGFloat = 1

File diff suppressed because it is too large Load Diff