1 |
47 |
Thurallor-7095 |
Resizer = class(Turbine.UI.Control); |
2 |
|
Thurallor-7095 |
|
3 |
|
Thurallor-7095 |
function Resizer:Constructor(parent) |
4 |
|
Thurallor-7095 |
Turbine.UI.Control.Constructor(self); |
5 |
|
Thurallor-7095 |
|
6 |
|
Thurallor-7095 |
self:SetSize(16, 16); |
7 |
|
Thurallor-7095 |
self:SetBackground(0x4100013D); |
8 |
|
Thurallor-7095 |
self:SetBlendMode(Turbine.UI.BlendMode.None); |
9 |
|
Thurallor-7095 |
|
10 |
|
Thurallor-7095 |
if (parent) then |
11 |
|
Thurallor-7095 |
self:SetParent(parent); |
12 |
|
Thurallor-7095 |
end |
13 |
|
Thurallor-7095 |
end |
14 |
|
Thurallor-7095 |
|
15 |
|
Thurallor-7095 |
function Resizer:SetParent(parent) |
16 |
|
Thurallor-7095 |
Turbine.UI.Control.SetParent(self, parent); |
17 |
|
Thurallor-7095 |
self.parent = parent; |
18 |
|
Thurallor-7095 |
if (parent) then |
19 |
|
Thurallor-7095 |
self:SetZOrder(parent:GetZOrder() + 1); |
20 |
|
Thurallor-7095 |
local width, height = parent:GetSize(); |
21 |
|
Thurallor-7095 |
self:SetPosition(width - 18, height - 18); |
22 |
|
Thurallor-7095 |
end |
23 |
|
Thurallor-7095 |
end |
24 |
|
Thurallor-7095 |
|
25 |
|
Thurallor-7095 |
function Resizer:MouseEnter() |
26 |
|
Thurallor-7095 |
self.mouseInside = true; |
27 |
|
Thurallor-7095 |
self:SetBlendMode(Turbine.UI.BlendMode.Overlay); |
28 |
|
Thurallor-7095 |
end |
29 |
|
Thurallor-7095 |
|
30 |
|
Thurallor-7095 |
function Resizer:MouseLeave() |
31 |
|
Thurallor-7095 |
self.mouseInside = false; |
32 |
|
Thurallor-7095 |
if (not self.resizing) then |
33 |
|
Thurallor-7095 |
self:SetBlendMode(Turbine.UI.BlendMode.None); |
34 |
|
Thurallor-7095 |
end |
35 |
|
Thurallor-7095 |
end |
36 |
|
Thurallor-7095 |
|
37 |
|
Thurallor-7095 |
function Resizer:MouseDown() |
38 |
|
Thurallor-7095 |
self.resizing = true; |
39 |
|
Thurallor-7095 |
self.origin = {self.parent:GetMousePosition()}; |
40 |
|
Thurallor-7095 |
end |
41 |
|
Thurallor-7095 |
|
42 |
|
Thurallor-7095 |
function Resizer:MouseUp() |
43 |
|
Thurallor-7095 |
self.resizing = false; |
44 |
|
Thurallor-7095 |
if (not self.mouseInside) then |
45 |
|
Thurallor-7095 |
self:SetBlendMode(Turbine.UI.BlendMode.None); |
46 |
|
Thurallor-7095 |
end |
47 |
|
Thurallor-7095 |
if (self.resized) then |
48 |
|
Thurallor-7095 |
DoCallbacks(self.parent, "Resized"); |
49 |
|
Thurallor-7095 |
self.resized = nil; |
50 |
|
Thurallor-7095 |
end |
51 |
|
Thurallor-7095 |
end |
52 |
|
Thurallor-7095 |
|
53 |
|
Thurallor-7095 |
function Resizer:MouseMove() |
54 |
|
Thurallor-7095 |
if (self.resizing) then |
55 |
|
Thurallor-7095 |
local x, y = self.parent:GetMousePosition(); |
56 |
|
Thurallor-7095 |
local deltaX, deltaY = x - self.origin[1], y - self.origin[2]; |
57 |
|
Thurallor-7095 |
local newWidth, newHeight = self.parent:GetSize(); |
58 |
|
Thurallor-7095 |
newWidth = newWidth + deltaX; |
59 |
|
Thurallor-7095 |
newHeight = newHeight + deltaY; |
60 |
|
Thurallor-7095 |
if (self.maxWidth and (newWidth > self.maxWidth)) then |
61 |
|
Thurallor-7095 |
newWidth = self.maxWidth; |
62 |
|
Thurallor-7095 |
elseif (self.minWidth and (newWidth < self.minWidth)) then |
63 |
|
Thurallor-7095 |
newWidth = self.minWidth; |
64 |
|
Thurallor-7095 |
end |
65 |
|
Thurallor-7095 |
if (self.maxHeight and (newHeight > self.maxHeight)) then |
66 |
|
Thurallor-7095 |
newHeight = self.maxHeight; |
67 |
|
Thurallor-7095 |
elseif (self.minHeight and (newHeight < self.minHeight)) then |
68 |
|
Thurallor-7095 |
newHeight = self.minHeight; |
69 |
|
Thurallor-7095 |
end |
70 |
|
Thurallor-7095 |
self.parent:SetSize(newWidth, newHeight); |
71 |
|
Thurallor-7095 |
self:SetPosition(newWidth - 18, newHeight - 18); |
72 |
|
Thurallor-7095 |
self.origin = {x, y}; |
73 |
|
Thurallor-7095 |
DoCallbacks(self.parent, "Resizing"); |
74 |
|
Thurallor-7095 |
self.resized = true; |
75 |
|
Thurallor-7095 |
end |
76 |
|
Thurallor-7095 |
end |
77 |
|
Thurallor-7095 |
|
78 |
|
Thurallor-7095 |
function Resizer:SetMinimumWidth(minWidth) |
79 |
|
Thurallor-7095 |
self.minWidth = minWidth; |
80 |
|
Thurallor-7095 |
if (self.parent and (self.parent:GetWidth() < minWidth)) then |
81 |
|
Thurallor-7095 |
self.parent:SetWidth(minWidth); |
82 |
|
Thurallor-7095 |
end |
83 |
|
Thurallor-7095 |
end |
84 |
|
Thurallor-7095 |
|
85 |
|
Thurallor-7095 |
function Resizer:SetMinimumHeight(minHeight) |
86 |
|
Thurallor-7095 |
self.minHeight = minHeight; |
87 |
|
Thurallor-7095 |
if (self.parent and (self.parent:GetHeight() < minHeight)) then |
88 |
|
Thurallor-7095 |
self.parent:SetHeight(minHeight); |
89 |
|
Thurallor-7095 |
end |
90 |
|
Thurallor-7095 |
end |
91 |
|
Thurallor-7095 |
|
92 |
|
Thurallor-7095 |
function Resizer:SetMinimumSize(minWidth, minHeight) |
93 |
|
Thurallor-7095 |
self:SetMinimumWidth(minWidth); |
94 |
|
Thurallor-7095 |
self:SetMinimumHeight(minHeight); |
95 |
|
Thurallor-7095 |
end |
96 |
|
Thurallor-7095 |
|
97 |
|
Thurallor-7095 |
function Resizer:SetMaximumWidth(maxWidth) |
98 |
|
Thurallor-7095 |
self.maxWidth = maxWidth; |
99 |
|
Thurallor-7095 |
if (self.parent and (self.parent:GetWidth() > maxWidth)) then |
100 |
|
Thurallor-7095 |
self.parent:SetWidth(maxWidth); |
101 |
|
Thurallor-7095 |
end |
102 |
|
Thurallor-7095 |
end |
103 |
|
Thurallor-7095 |
|
104 |
|
Thurallor-7095 |
function Resizer:SetMaximumHeight(maxHeight) |
105 |
|
Thurallor-7095 |
self.maxHeight = maxHeight; |
106 |
|
Thurallor-7095 |
if (self.parent and (self.parent:GetHeight() > maxHeight)) then |
107 |
|
Thurallor-7095 |
self.parent:SetHeight(maxHeight); |
108 |
|
Thurallor-7095 |
end |
109 |
|
Thurallor-7095 |
end |
110 |
|
Thurallor-7095 |
|
111 |
|
Thurallor-7095 |
function Resizer:SetMaximumSize(maxWidth, maxHeight) |
112 |
|
Thurallor-7095 |
self:SetMaximumWidth(maxWidth); |
113 |
|
Thurallor-7095 |
self:SetMaximumHeight(maxHeight); |
114 |
|
Thurallor-7095 |
end |
115 |
|
Thurallor-7095 |
|
116 |
|
Thurallor-7095 |
if (not Thurallor.UI) then |
117 |
|
Thurallor-7095 |
Thurallor.UI = {}; |
118 |
|
Thurallor-7095 |
end |
119 |
|
Thurallor-7095 |
Thurallor.UI.Resizer = Resizer; |