-
Notifications
You must be signed in to change notification settings - Fork 2
/
guiwidgetframe.monkey
134 lines (108 loc) · 4.15 KB
/
guiwidgetframe.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
Import horizon.utilimage
Import horizon.guiwidget
Class GuiWidgetFrame Extends GuiWidget
Field topBar : Image
Field rightBorder : Image
Field leftBorder : Image
Field bottomBorder : Image
Field resizeBottom : Image
Field startDrag : Bool
Field style : Int
Field title : String = "title"
Field status : String = "status"
Const STYLE_RESIZE:Int = %00000001
Const STYLE_CLOSE:Int = %00000010
Const STYLE_DRAG:Int = %00000100
Function Create : GuiWidgetFrame(x:Int, y:Int, w:Int = 0, h:Int = 0,style:Int = STYLE_DRAG)
Local instance : GuiWidgetFrame = New GuiWidgetFrame
instance.rect.x = x
instance.rect.y = y
instance.rect.w = w
instance.rect.h = h
instance.style = style
Return instance
End Function
Method New()
style = STYLE_DRAG
InitWidget()
End Method
Method InitWidget()
topBar = LoadImage(GuiSystem.SKIN_PATH + "window/topbar.png")
rightBorder = LoadImage(GuiSystem.SKIN_PATH + "window/rightborder.png")
leftBorder = LoadImage(GuiSystem.SKIN_PATH + "window/leftborder.png")
bottomBorder = LoadImage(GuiSystem.SKIN_PATH + "window/bottomborder.png")
resizeBottom = LoadImage(GuiSystem.SKIN_PATH + "window/bgresize.png")
End Method
Method SetInnerWidth(w:Int)
rect.w = w + ImageWidth(leftBorder) + ImageWidth(rightBorder)
End Method
Method SetInnerHeight(h:Int)
rect.h = h + ImageHeight(topBar) + ImageHeight(bottomBorder) + ImageHeight(resizeBottom)
End Method
Method Render()
DrawTopBar()
DrawBottomBorder()
DrawRightBorder()
DrawLeftBorder()
End Method
Method GetX : Int()
Return rect.x
End Method
Method GetY : Int()
Return rect.y
End Method
Method GetInnerWindowX : Int()
Return GetX() + ImageWidth(leftBorder)
End Method
Method GetInnerWindowY : Int()
Return GetY() + ImageHeight(topBar)
End Method
Method GetInnerWidth : Int()
Return rect.w - ImageWidth(rightBorder) - ImageWidth(leftBorder)
End Method
Method GetInnerHeight : Int()
Return rect.h - ImageHeight(topBar) - ImageHeight(bottomBorder) - ImageHeight(resizeBottom)
End Method
Method DrawTopBar()
UtilImage.DrawRepeated(topBar, GetX(), GetY(), rect.w, ImageHeight(topBar))
' DrawText (title, GetX() + ((style & STYLE_CLOSE) * closeButton.w) + 2, GetY() + 6)
DrawText (title, GetX() + 2, GetY() + 6)
End Method
Method DrawRightBorder()
UtilImage.DrawRepeated(rightBorder, GetX() + rect.w - ImageWidth(rightBorder), GetY() + ImageHeight(topBar), ImageWidth(rightBorder), rect.h - ImageHeight(topBar))
End Method
Method DrawLeftBorder()
UtilImage.DrawRepeated(leftBorder, GetX(), GetY() + ImageHeight(topBar), ImageWidth(leftBorder), rect.h - ImageHeight(topBar))
End Method
Method DrawBottomBorder()
UtilImage.DrawRepeated(resizeBottom, GetX(), GetY() + rect.h - ImageHeight(resizeBottom) - ImageHeight(bottomBorder), rect.w, ImageHeight(resizeBottom))
SetColor($CC,$CC,$CC)
DrawText (status, GetX() + ImageWidth(leftBorder), GetY() + rect.h - ImageHeight(resizeBottom))
SetColor($FF,$FF,$FF)
UtilImage.DrawRepeated(bottomBorder, GetX(), GetY() + rect.h - ImageHeight(bottomBorder), rect.w, ImageHeight(bottomBorder))
End Method
Method SetTitle(t : String)
title = t
End Method
Method SetStatus(s : String)
status = s
End Method
Method OnMouseHit()
If (style & STYLE_DRAG And GuiSystem.mouse.GetX() >= rect.x And GuiSystem.mouse.GetY() >= rect.y And GuiSystem.mouse.GetX() < rect.x + rect.w And GuiSystem.mouse.GetY() < GetInnerWindowY())
startDrag = True
End If
End Method
Method OnMouseUp()
Super.OnMouseUp()
startDrag = False
End Method
Method Update()
Super.Update()
If startDrag
OnMove()
For Local c : GuiBase = EachIn childs
If GuiWidget(c) Then GuiWidget(c).OnMove()
Next
End If
End Method
End