Skip to content

Commit

Permalink
Fix event samples for iOS and macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
ystrot committed Jun 27, 2018
1 parent 30dc952 commit 4378c84
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
Expand Up @@ -23,14 +23,15 @@ class EventsExampleController: NSViewController {
}

var selectedTool: PanelTool?
let stroke = Stroke(fill: Color.black, width: 1.0)

private func loadScene() -> Node {

return [createCanvas(), createPanel()].group()
}

private func createPanel() -> Node {
let panel = Shape(form: Rect(x: 10.0, y: 10.0, w: 80.0, h: 120.0), fill: Color.clear, stroke: Stroke(fill: Color.black, width: 1.0))
let panel = Shape(form: Rect(x: 10.0, y: 10.0, w: 80.0, h: 120.0), fill: Color.clear, stroke: stroke)
let panelGroup = [panel, createTools()].group()

panelGroup.onPan { event in
Expand Down Expand Up @@ -62,11 +63,11 @@ class EventsExampleController: NSViewController {
startPoint = loc
switch tool {
case .ellipse:
currentFigure = Shape(form: Ellipse(cx: startPoint.x, cy: startPoint.y, rx: 0.0, ry: 0.0))
currentFigure = Shape(form: Ellipse(cx: startPoint.x, cy: startPoint.y, rx: 0.0, ry: 0.0), stroke: self.stroke)
break

case .rectangle:
currentFigure = Shape(form: Rect(x: startPoint.x, y: startPoint.y, w: 0.0, h: 0.0))
currentFigure = Shape(form: Rect(x: startPoint.x, y: startPoint.y, w: 0.0, h: 0.0), stroke: self.stroke)
break
}

Expand Down Expand Up @@ -114,22 +115,22 @@ class EventsExampleController: NSViewController {
private func createTools() -> Node {
let ellipseTool = Shape(form: Ellipse(cx: 50.0, cy: 50.0, rx: 25, ry: 15),
fill: Color.clear,
stroke: Stroke(fill: Color.black, width: 1.0))
stroke: stroke)

let rectTool = Shape(form: Rect(x: 25.0, y: 75.0, w: 50.0, h: 30.0),
fill: Color.clear,
stroke: Stroke(fill: Color.black, width: 1.0))
stroke: stroke)

ellipseTool.onTap { _ in
self.selectedTool = .ellipse
ellipseTool.stroke = Stroke(fill: Color.blue, width: 2.0)
rectTool.stroke = Stroke(fill: Color.black, width: 1.0)
rectTool.stroke = self.stroke
}

rectTool.onTap { _ in
self.selectedTool = .rectangle
rectTool.stroke = Stroke(fill: Color.blue, width: 2.0)
ellipseTool.stroke = Stroke(fill: Color.black, width: 1.0)
ellipseTool.stroke = self.stroke
}

return [ellipseTool, rectTool].group()
Expand Down
19 changes: 8 additions & 11 deletions Example/Example/Examples/Events/EventsExampleController.swift
Expand Up @@ -26,6 +26,7 @@ class EventsExampleController: UIViewController {
}

var selectedTool: PanelTool?
let stroke = Stroke(fill: Color.black, width: 1.0)

private func loadScene() -> Node {
return [
Expand All @@ -35,7 +36,7 @@ class EventsExampleController: UIViewController {
}

private func createPanel() -> Node {
let panel = Shape(form: Rect(x: 10.0, y: 10.0, w: 80.0, h: 120.0), fill: Color.white, stroke: Stroke(fill: Color.black, width: 1.0))
let panel = Shape(form: Rect(x: 10.0, y: 10.0, w: 80.0, h: 120.0), fill: Color.white, stroke: stroke)


let panelGroup = [
Expand Down Expand Up @@ -69,16 +70,14 @@ class EventsExampleController: UIViewController {
return
}

print("canvas pressed:\(loc.x) \(loc.y)")

startPoint = loc
switch tool {
case .ellipse:
currentFigure = Shape(form: Ellipse(cx: startPoint.x, cy: startPoint.y, rx: 0.0, ry: 0.0))
currentFigure = Shape(form: Ellipse(cx: startPoint.x, cy: startPoint.y, rx: 0.0, ry: 0.0), stroke: self.stroke)
break

case .rectangle:
currentFigure = Shape(form: Rect(x: startPoint.x, y: startPoint.y, w: 0.0, h: 0.0))
currentFigure = Shape(form: Rect(x: startPoint.x, y: startPoint.y, w: 0.0, h: 0.0), stroke: self.stroke)
break
}

Expand All @@ -98,8 +97,6 @@ class EventsExampleController: UIViewController {
return
}

print("canvas moving \(loc.x) \(loc.y)")

let width = loc.x - startPoint.x
let height = loc.y - startPoint.y

Expand Down Expand Up @@ -129,21 +126,21 @@ class EventsExampleController: UIViewController {
private func createTools() -> Node {
let ellipseTool = Shape(form: Ellipse(cx: 50.0, cy: 50.0, rx: 25, ry: 15),
fill: Color.white,
stroke: Stroke(fill: Color.black, width: 1.0))
stroke: stroke)
let rectTool = Shape(form: Rect(x: 25.0, y: 75.0, w: 50.0, h: 30.0),
fill: Color.white,
stroke: Stroke(fill: Color.black, width: 1.0))
stroke: stroke)

ellipseTool.onTap { _ in
self.selectedTool = .ellipse
ellipseTool.stroke = Stroke(fill: Color.blue, width: 2.0)
rectTool.stroke = Stroke(fill: Color.black, width: 1.0)
rectTool.stroke = self.stroke
}

rectTool.onTap { _ in
self.selectedTool = .rectangle
rectTool.stroke = Stroke(fill: Color.blue, width: 2.0)
ellipseTool.stroke = Stroke(fill: Color.black, width: 1.0)
ellipseTool.stroke = self.stroke
}

return [
Expand Down

0 comments on commit 4378c84

Please sign in to comment.