aboutsummaryrefslogtreecommitdiffstats
path: root/prototypes/workbench/examples/routed-layout.pure
blob: 8933c7091b0163f1cc4cd88e9d7385b3ce55b7ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# 하나의 포인터 입력과 네 반응을 모든 도형이 공유합니다.
state selected = 0
record Tile {
  x = 0; y = 0
  ox = 0; oy = 0
  sx = 0; sy = 0
  held = 0; id = 0
}
item green = Tile(x=80, y=120, sx=80, sy=120, id=1)
item blue = Tile(x=280, y=160, sx=280, sy=160, id=2)
item amber = Tile(x=450, y=220, sx=450, sy=220, id=3)
input left = ArrowLeft
input right = ArrowRight
input up = ArrowUp
input down = ArrowDown
input drag = pointer {
  green_box: green
  blue_box: blue
  amber_box: amber
}
box board(20,90,600,240,"#233a31")
text help(25,40,selected,"선택한 도형: ")
box green_box(green.x,green.y,56,44,"#c9f08b")
box blue_box(blue.x,blue.y,56,44,"#74c4d4")
box amber_box(amber.x,amber.y,56,44,"#dfb184")

rule grab(t: Tile) {
  selected = t.id
  t.sx = t.x; t.sy = t.y
  t.ox = event_x - t.x; t.oy = event_y - t.y
  t.held = 1
}
rule move(t: Tile) {
  t.x = clamp(event_x - t.ox, 20, 564)
  t.y = clamp(event_y - t.oy, 90, 286)
}
rule drop(t: Tile) { t.held = 0 }
rule cancel(t: Tile) { t.x = t.sx; t.y = t.sy; t.held = 0 }
rule go_left(t: Tile) {
  if selected == t.id && t.held == 0 { t.x = clamp(t.x - 10, 20, 564) }
}
rule go_right(t: Tile) {
  if selected == t.id && t.held == 0 { t.x = clamp(t.x + 10, 20, 564) }
}
rule go_up(t: Tile) {
  if selected == t.id && t.held == 0 { t.y = clamp(t.y - 10, 90, 286) }
}
rule go_down(t: Tile) {
  if selected == t.id && t.held == 0 { t.y = clamp(t.y + 10, 90, 286) }
}

on drag.down use grab(drag.target)
on drag.move use move(drag.target)
on drag.up use drop(drag.target)
on drag.cancel use cancel(drag.target)

on left.down use go_left(green)
on right.down use go_right(green)
on up.down use go_up(green)
on down.down use go_down(green)

on left.down use go_left(blue)
on right.down use go_right(blue)
on up.down use go_up(blue)
on down.down use go_down(blue)

on left.down use go_left(amber)
on right.down use go_right(amber)
on up.down use go_up(amber)
on down.down use go_down(amber)