-
Notifications
You must be signed in to change notification settings - Fork 10
/
invalidaterect.monkey
51 lines (40 loc) · 1.07 KB
/
invalidaterect.monkey
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
Strict
Import mojo
Import point
Import helpers
Class InvalidateRect
Global list : List<InvalidateRect>
Field x:Int, y:Int, w:Int, h:Int
Function Clear:Void()
list = New List<InvalidateRect>
End
Function Add:Void(x:Int,y:Int,w:Int,h:Int)
Local i:InvalidateRect = New InvalidateRect
i.x = x
i.y = y
i.w = w
i.h = h
list.AddLast(i)
End
Function Draw:Void(i:Image, x:Float, y:Float, r:Float, sx:Float, sy:Float, frame:Int)
Local p:Point[4]
p[0] = New Point(-i.HandleX(), -i.HandleY())
p[1] = New Point(p[0].x + i.Width(), p[0].y + i.Height())
p[2] = New Point(p[0].x, p[1].y)
p[3] = New Point(p[1].x, p[0].y)
For Local i:Int = 0 To 3
p[i].Rotate(-r)
End
Local dx:Float = 0, dy:Float = 0
For Local i:Int = 0 To 3
Local td:Float = Distance(0,0, p[i].x, 0)
If Abs(td) > dx Then dx = Abs(td)
td = Distance(0,0,0,p[i].y)
If Abs(td) > dy Then dy = Abs(td)
Next
dx += 2
dy += 2
Add(-dx + x,-dy + y, dx*2, dy*2)
DrawImage(i, x, y, r, sx, sy, frame)
End Function
End