vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | ResizeableFrame={} |
2 | |||
3 | ResizeableFrame.dragTop = nil |
||
4 | ResizeableFrame.dragRight = nil |
||
5 | ResizeableFrame.dragottom = nil |
||
6 | ResizeableFrame.dragLeft = nil |
||
7 | ResizeableFrame.IncrementY = {} |
||
8 | ResizeableFrame.OffsetHeight={} |
||
9 | ResizeableFrame.MinHeight={} |
||
10 | ResizeableFrame.MaxHeight={} |
||
11 | ResizeableFrame.MinWidth={} |
||
12 | ResizeableFrame.MaxWidth={} |
||
13 | ResizeableFrame.FrameBorderSize={} |
||
14 | ResizeableFrame.DefaultMinHeight=30 |
||
15 | ResizeableFrame.DefaultMaxHeight=600 |
||
16 | ResizeableFrame.DefaultMinWidth=30 |
||
17 | ResizeableFrame.DefaultMaxWidth=600 |
||
18 | |||
19 | function ResizeableFrame:OnMouseDown() |
||
20 | |||
21 | local effectiveScale = this:GetEffectiveScale(); |
||
22 | local x, y = GetCursorPosition() |
||
23 | x=x/effectiveScale |
||
24 | y=y/effectiveScale |
||
25 | |||
26 | if (abs(x - this:GetRight()) < 10) then ResizeableFrame.dragRight = true |
||
27 | elseif (abs(x - this:GetLeft()) < 10) then ResizeableFrame.dragLeft = true end |
||
28 | |||
29 | if (abs(y - this:GetBottom()) < 10) then ResizeableFrame.dragBottom = true |
||
30 | elseif (abs(y - this:GetTop()) < 10) then ResizeableFrame.dragTop = true end |
||
31 | |||
32 | if (not ResizeableFrame.dragLeft and not ResizeableFrame.dragRight and not ResizeableFrame.dragBottom and not ResizeableFrame.dragTop) then |
||
33 | this:StartMoving() |
||
34 | this.isMoving = true |
||
35 | else |
||
36 | this.isResizing=true |
||
37 | end |
||
38 | |||
39 | end |
||
40 | |||
41 | function ResizeableFrame:OnMouseUp() |
||
42 | ResizeableFrame:OnDragStop() |
||
43 | end |
||
44 | |||
45 | function ResizeableFrame:OnDragStop() |
||
46 | this:StopMovingOrSizing() |
||
47 | this.isMoving = nil |
||
48 | this.isResizing = nil |
||
49 | ResizeableFrame.dragTop = nil |
||
50 | ResizeableFrame.dragRight = nil |
||
51 | ResizeableFrame.dragBottom = nil |
||
52 | ResizeableFrame.dragLeft = nil |
||
53 | end |
||
54 | |||
55 | function ResizeableFrame:OnUpdate() |
||
56 | |||
57 | if (not this.isResizing) then return end |
||
58 | |||
59 | local effectiveScale = this:GetEffectiveScale() |
||
60 | local x, y = GetCursorPosition() |
||
61 | x=x/effectiveScale |
||
62 | y=y/effectiveScale |
||
63 | |||
64 | local top=this:GetTop() |
||
65 | local right=this:GetRight() |
||
66 | local bottom=this:GetBottom() |
||
67 | local left=this:GetLeft() |
||
68 | local BorderSize=ResizeableFrame:GetFrameBorderSize() |
||
69 | |||
70 | local height,width |
||
71 | |||
72 | if (ResizeableFrame.dragLeft) then left=x |
||
73 | elseif (ResizeableFrame.dragRight) then right=x end |
||
74 | |||
75 | if (ResizeableFrame.dragTop) then |
||
76 | height=y-bottom |
||
77 | if(ResizeableFrame:GetHeightIncrement()>0) then |
||
78 | height=height-math.mod(height, ResizeableFrame:GetHeightIncrement())+BorderSize.top+BorderSize.bottom+ResizeableFrame:GetOffsetHeight() |
||
79 | end |
||
80 | top=bottom+height |
||
81 | elseif (ResizeableFrame.dragBottom) then |
||
82 | height=top-y |
||
83 | if (ResizeableFrame:GetHeightIncrement()>0) then |
||
84 | height=height-math.mod(height, ResizeableFrame:GetHeightIncrement())+BorderSize.top+BorderSize.bottom+ResizeableFrame:GetOffsetHeight() |
||
85 | end |
||
86 | end |
||
87 | |||
88 | width=right-left |
||
89 | |||
90 | -- limit to min and max boundary |
||
91 | if height then |
||
92 | if (height<ResizeableFrame:GetMinHeight()) then height=ResizeableFrame:GetMinHeight() |
||
93 | elseif (height>ResizeableFrame:GetMaxHeight()) then height=ResizeableFrame:GetMaxHeight() end |
||
94 | end |
||
95 | |||
96 | if width then |
||
97 | if (width<ResizeableFrame:GetMinWidth()) then width=ResizeableFrame:GetMinWidth() |
||
98 | elseif (width>ResizeableFrame:GetMaxWidth()) then width=ResizeableFrame:GetMaxWidth() end |
||
99 | end |
||
100 | -------------------------------------- |
||
101 | |||
102 | -- refresh frame size and position |
||
103 | this:SetPoint("TOPLEFT","UIParent","BOTTOMLEFT",left,top); |
||
104 | if height then this:SetHeight(height) end |
||
105 | if width then this:SetWidth(width) end |
||
106 | -------------------------------------- |
||
107 | |||
108 | end |
||
109 | |||
110 | function ResizeableFrame:SetFrameBorderSize(top,right,bottom,left) |
||
111 | ResizeableFrame.FrameBorderSize[this:GetName()]={top=top,right=right,bottom=bottom,left=left} |
||
112 | end |
||
113 | |||
114 | function ResizeableFrame:GetFrameBorderSize() |
||
115 | local BorderSize=ResizeableFrame.FrameBorderSize[this:GetName()] |
||
116 | if (not BorderSize.top) then BorderSize.top=0 end |
||
117 | if (not BorderSize.right) then BorderSize.right=0 end |
||
118 | if (not BorderSize.bottom) then BorderSize.bottom=0 end |
||
119 | if (not BorderSize.left) then BorderSize.left=0 end |
||
120 | return BorderSize |
||
121 | end |
||
122 | |||
123 | function ResizeableFrame:SetOffsetHeight(offsetHeight) |
||
124 | ResizeableFrame.OffsetHeight[this:GetName()]=offsetHeight |
||
125 | end |
||
126 | |||
127 | function ResizeableFrame:GetOffsetHeight() |
||
128 | if (ResizeableFrame.OffsetHeight[this:GetName()]) then |
||
129 | return ResizeableFrame.OffsetHeight[this:GetName()] |
||
130 | else |
||
131 | return 0 |
||
132 | end |
||
133 | end |
||
134 | |||
135 | function ResizeableFrame:SetHeightIncrement(increment) |
||
136 | ResizeableFrame.IncrementY[this:GetName()]=increment |
||
137 | end |
||
138 | |||
139 | function ResizeableFrame:GetHeightIncrement() |
||
140 | if (ResizeableFrame.IncrementY[this:GetName()]) then |
||
141 | return ResizeableFrame.IncrementY[this:GetName()] |
||
142 | else |
||
143 | return 0 |
||
144 | end |
||
145 | end |
||
146 | |||
147 | function ResizeableFrame:SetMinHeight(height) |
||
148 | ResizeableFrame.MinHeight[this:GetName()]=height |
||
149 | end |
||
150 | |||
151 | function ResizeableFrame:SetMaxHeight(height) |
||
152 | ResizeableFrame.MaxHeight[this:GetName()]=height |
||
153 | end |
||
154 | |||
155 | function ResizeableFrame:GetMinHeight() |
||
156 | if (ResizeableFrame.MinHeight[this:GetName()]) then |
||
157 | return ResizeableFrame.MinHeight[this:GetName()] |
||
158 | else |
||
159 | return ResizeableFrame.DefaultMinHeight |
||
160 | end |
||
161 | end |
||
162 | |||
163 | function ResizeableFrame:GetMaxHeight() |
||
164 | if (ResizeableFrame.MaxHeight[this:GetName()]) then |
||
165 | return ResizeableFrame.MaxHeight[this:GetName()] |
||
166 | else |
||
167 | return ResizeableFrame.DefaultMaxHeight |
||
168 | end |
||
169 | end |
||
170 | |||
171 | function ResizeableFrame:SetMinWidth(width) |
||
172 | ResizeableFrame.MinWidth[this:GetName()]=width |
||
173 | end |
||
174 | |||
175 | function ResizeableFrame:SetMaxWidth(width) |
||
176 | ResizeableFrame.MaxWidth[this:GetName()]=width |
||
177 | end |
||
178 | |||
179 | function ResizeableFrame:GetMinWidth() |
||
180 | if (ResizeableFrame.MinWidth[this:GetName()]) then |
||
181 | return ResizeableFrame.MinWidth[this:GetName()] |
||
182 | else |
||
183 | return ResizeableFrame.DefaultMinWidth |
||
184 | end |
||
185 | end |
||
186 | |||
187 | function ResizeableFrame:GetMaxWidth() |
||
188 | if (ResizeableFrame.MaxWidth[this:GetName()]) then |
||
189 | return ResizeableFrame.MaxWidth[this:GetName()] |
||
190 | else |
||
191 | return ResizeableFrame.DefaultMaxWidth |
||
192 | end |
||
193 | end |
||
194 |