-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMove-Resize.lua
More file actions
193 lines (178 loc) · 5 KB
/
Move-Resize.lua
File metadata and controls
193 lines (178 loc) · 5 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
if using then
using "Analytics"
end
windows = {}
local function Move(window)
if window.Move then
if input.IsButtonDown(1) then
mouseX, mouseY = input.GetMousePos();
if shouldDrag then
window.X = mouseX - dx;
window.Y = mouseY - dy;
end
if mouseX >= window.X and mouseX <= window.X + window.W and mouseY >= window.Y and mouseY <= window.Y + window.H then
if window.BoundsHeight ~= nil then
if mouseX >= window.X and mouseX <= window.X + window.W and mouseY >= window.Y and mouseY <= window.Y + window.BoundsHeight then
window.Resize = false
shouldDrag = true;
dx = mouseX - window.X;
dy = mouseY - window.Y;
if window.Form ~= nil then
if window.Form.Dragging ~= nil then
window.Form.Dragging = true
end
end
end
else
if window.BoundsWidth ~= nil then
if mouseX >= window.X and mouseX <= window.X + window.BoundsWidth and mouseY >= window.Y and mouseY <= window.Y + window.H then
window.Resize = false
shouldDrag = true;
dx = mouseX - window.X;
dy = mouseY - window.Y;
if window.Form ~= nil then
if window.Form.Dragging ~= nil then
window.Form.Dragging = true
end
end
end
else
window.Resize = false
shouldDrag = true;
dx = mouseX - window.X;
dy = mouseY - window.Y;
if window.Form ~= nil then
if window.Form.Dragging ~= nil then
window.Form.Dragging = true
end
end
end
end
else
if window.Form ~= nil then
if window.Form.Dragging ~= nil then
window.Form.Dragging = true
end
end
end
else
shouldDrag = false;
if window.Form ~= nil then
if window.Form.Dragging ~= nil then
window.Form.Dragging = false
end
end
end
end
end
local function Resize(window)
if window.Resize then
draw.Color(255,0,0,255)
draw.FilledRect(window.X+window.W, window.Y+window.H, window.X+window.W+10, window.Y+window.H+10)
local resizex = window.X+window.W
local resizey = window.Y+window.H
local resizew = window.X+window.W+10
local resizeh = window.Y+window.H+10
if input.IsButtonDown(1) then
mouseX, mouseY = input.GetMousePos();
if shouldDrag then
window.W = mouseX - dx;
window.H = mouseY - dy;
if window.W < window.MinW then window.W = window.MinW end
if window.W > window.MaxW then window.W = window.MaxW end
if window.H < window.MinW then window.H = window.MinW end
if window.H > window.MaxW then window.H = window.MaxW end
end
if mouseX >= resizex and mouseX <= resizex + resizew and mouseY >= resizey and mouseY <= resizey + resizeh then
window.Move = false
shouldDrag = true;
dx = mouseX - window.W;
dy = mouseY - window.H;
end
else
shouldDrag = false;
end
end
end
callbacks.Register("Draw", function()
if windows == nil then return end
for i = 1, #windows do
local window = windows[i]
if window.Form ~= nil then
if window.Form.Visible ~= nil then
if window.Form.Visible ~= true then
return
end
end
end
if window.OverrideLocation then
window.X, window.Y = window.Location(window.X, window.Y, window.W, window.H)
end
if window.Form ~= nil then
window.X = window.Form.Location.X
window.Y = window.Form.Location.Y
window.W = window.Form.Size.Width
window.H = window.Form.Size.Height
window.MinW = window.Form.MinimumSize.Width
window.MinH = window.Form.MinimumSize.Height
window.MaxW = window.Form.MaximumSize.Width
window.MaxH = window.Form.MaximumSize.Height
end
if window.InitDone == nil then
window.InitDone = false
else
if window.Init ~= nil then
if not window.InitDone then
window.Init(window)
window.InitDone = true
end
end
end
if window.Type ~= nil then
if window.Type == "Browser" then
window:Draw(window.X, window.Y, window.W, window.H)
else
window.Draw(window.X, window.Y, window.W, window.H)
end
else
window.Draw(window.X, window.Y, window.W, window.H)
end
if window.Form ~= nil then
if window.Form.BorderStyle == "Sizable" then
Resize(window)
end
else
if window.Resize then
Resize(window)
end
end
if input.IsButtonReleased(1) then
window.Move = true
window.Resize = true
end
if window.Move then
Move(window)
end
if input.IsButtonReleased(1) then
window.Move = true
window.Resize = true
end
if window.Form ~= nil then
window.Form.Location.X = window.X
window.Form.Location.Y = window.Y
window.Form.Size.Width = window.W
window.Form.Size.Height = window.H
window.Form.MinimumSize.Width = window.MinW
window.Form.MinimumSize.Height = window.MinH
window.Form.MaximumSize.Width = window.MaxW
window.Form.MaximumSize.Height = window.MaxH
end
end
end)
callbacks.Register("Unload", function()
if windows == nil then return end
for i = 1, #windows do
table.remove(windows, i)
end
windows = nil
end)