-
Notifications
You must be signed in to change notification settings - Fork 0
/
crossHairsElement.sj
50 lines (43 loc) · 1.35 KB
/
crossHairsElement.sj
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
crossHairsElement #element (
color := colors.white
_rect := rect()
_topDownRenderer := empty'boxRenderer
_leftRightRenderer := empty'boxRenderer
_point := point()
getSize(maxSize : 'size) {
size(maxSize.w, maxSize.h)
}
getRect()'rect { _rect }
setRect(rect_ : 'rect)'void {
if _rect != rect_ {
_rect = rect_
_topDownRenderer = empty'boxRenderer
_leftRightRenderer = empty'boxRenderer
}
void
}
render(scene : 'scene2d)'void {
if isEmpty(_topDownRenderer) {
_topDownRenderer = valid(boxRenderer(
rect: rect(_point.x, _rect.y, 1, _rect.h)
color: color))
}
if isEmpty(_leftRightRenderer) {
_leftRightRenderer = valid(boxRenderer(
rect: rect(_rect.x, _point.y, _rect.w, 1)
color: color))
}
_topDownRenderer?.render(scene)
_leftRightRenderer?.render(scene)
}
fireMouseEvent(mouseEvent : 'mouseEvent)'bool {
if _rect.containsPoint(mouseEvent.point) {
if mouseEvent.eventType == mouseEventType.move {
_point = mouseEvent.point
_topDownRenderer = empty'boxRenderer
_leftRightRenderer = empty'boxRenderer
}
}
true
}
) { this }