vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 The movement/resizing code in here is largely borrowed from MoveAnything by Skrag
3 $Id:$
4 --]]
5  
6 local CMMM_DEBUG = 0;
7  
8 -- Print Debug info
9 local function Print_Debug(s)
10 if (CMMM_DEBUG == 1) then
11 DEFAULT_CHAT_FRAME:AddMessage(s, 1, 1, 0)
12 end
13 end
14  
15 function CleanMinimapMover_SizingAnchor( button )
16 local s, e = string.find( button:GetName(), "Resize_" )
17 local anchorto = string.sub( this:GetName(), e + 1 );
18 local anchor;
19  
20 if( anchorto == "LEFT" ) then anchor = "RIGHT";
21 elseif( anchorto == "RIGHT" ) then anchor = "LEFT";
22 elseif( anchorto == "TOP" ) then anchor = "BOTTOM";
23 elseif( anchorto == "BOTTOM" ) then anchor = "TOP";
24 end
25  
26 return anchorto, anchor;
27 end
28  
29 function CleanMinimapMover_UpdatePosition( moveFrame )
30 local x, y, parent;
31 x = nil;
32 y = nil;
33 parent = nil;
34 x, y = CleanMinimapMover_GetRelativeBottomLeft( moveFrame.tagged );
35 parent = CleanMinimapMover_GetParent( moveFrame.tagged );
36 return x, y, parent;
37 end
38  
39 function CleanMinimapMover_GetParent( frame )
40 if( frame:GetParent() == nil ) then
41 return UIParent;
42 end
43  
44 return frame:GetParent();
45 end
46  
47 function CleanMinimapMover_GetScale( frame )
48 if( frame:GetScale() == nil ) then
49 return UIParent:GetScale();
50 end
51  
52 return frame:GetScale();
53 end
54  
55  
56 function CleanMinimapMover_GetRelativeBottomLeft( tagFrame )
57 x = tagFrame:GetLeft();
58 if( x ) then
59 x = x - CleanMinimapMover_GetParent( tagFrame ):GetLeft() * CleanMinimapMover_GetScale( CleanMinimapMover_GetParent( tagFrame ) ) / CleanMinimapMover_GetScale( tagFrame );
60 end
61 y = tagFrame:GetBottom();
62 if( y ) then
63 y = y - CleanMinimapMover_GetParent( tagFrame ):GetBottom() * CleanMinimapMover_GetScale( CleanMinimapMover_GetParent( tagFrame ) ) / CleanMinimapMover_GetScale( tagFrame );
64 end
65 return x,y;
66 end
67  
68  
69 function CleanMinimapMover_Attach( moveFrame, tagFrame )
70 if( moveFrame.tagged ) then
71 CleanMinimapMover_Detach( moveFrame );
72 end
73  
74 if( tagFrame.OnBeginMove ) then
75 if( not tagFrame:OnBeginMove() ) then
76 Print_Debug("aborting");
77 CleanMinimapMover_Detach( moveFrame );
78 return;
79 end
80 end
81  
82 local x, y, w, h;
83 if( tagFrame:GetLeft() == nil ) then tagFrame:Show(); tagFrame:Hide(); end
84 x = tagFrame:GetLeft() * CleanMinimapMover_GetScale( tagFrame ) / UIParent:GetScale();
85 x = x - CleanMinimapMover_GetParent( tagFrame ):GetLeft() * CleanMinimapMover_GetScale( CleanMinimapMover_GetParent( tagFrame ) ) / UIParent:GetScale();
86 y = tagFrame:GetBottom() * CleanMinimapMover_GetScale( tagFrame ) / UIParent:GetScale();
87 y = y - CleanMinimapMover_GetParent( tagFrame ):GetBottom() * CleanMinimapMover_GetScale( CleanMinimapMover_GetParent( tagFrame ) ) / UIParent:GetScale();
88 w = tagFrame:GetWidth() * CleanMinimapMover_GetScale( tagFrame ) / UIParent:GetScale();
89 h = tagFrame:GetHeight() * CleanMinimapMover_GetScale( tagFrame ) / UIParent:GetScale();
90 moveFrame:ClearAllPoints();
91 moveFrame:SetPoint("BOTTOMLEFT", CleanMinimapMover_GetParent( tagFrame ):GetName(), "BOTTOMLEFT", x, y );
92 moveFrame:SetWidth(w);
93 moveFrame:SetHeight(h);
94 moveFrame:SetFrameLevel( tagFrame:GetFrameLevel() + 1 );
95  
96 tagFrame:ClearAllPoints();
97 tagFrame:SetPoint( "BOTTOMLEFT", moveFrame:GetName(), "BOTTOMLEFT", 0, 0 );
98  
99 moveFrame:Show();
100 moveFrame.tagged = tagFrame;
101  
102 Print_Debug("Attached "..tagFrame:GetName().." to "..moveFrame:GetName().." x="..x.." y="..y.." w="..w.." h="..h);
103  
104 end
105  
106 function CleanMinimapMover_Detach( moveFrame )
107 if( moveFrame.tagged ) then
108 local x, y, parent = CleanMinimapMover_UpdatePosition( moveFrame );
109 moveFrame.tagged:ClearAllPoints();
110 moveFrame.tagged:SetPoint( "BOTTOMLEFT", parent:GetName(), "BOTTOMLEFT", x, y );
111 end
112 moveFrame:Hide();
113 moveFrame.tagged = nil;
114 end
115  
116  
117 function CleanMinimapMover_OnSizeChanged( this )
118 if( this.tagged ) then
119 local s, w, h;
120 if( this.SizingAnchor == "LEFT" or this.SizingAnchor == "RIGHT" ) then
121 w = this:GetWidth();
122 h = w * (this.tagged:GetHeight() / this.tagged:GetWidth());
123 if( h < 16 ) then
124 h = 16;
125 w = h * (this.tagged:GetWidth() / this.tagged:GetHeight());
126 end
127 else
128 h = this:GetHeight();
129 w = h * (this.tagged:GetWidth() / this.tagged:GetHeight());
130 if( w < 16 ) then
131 w = 16;
132 h = w * (this.tagged:GetHeight() / this.tagged:GetWidth());
133 end
134 end
135 s = this:GetWidth() / this.tagged:GetWidth();
136 s = s * UIParent:GetScale();
137  
138 this.tagged:SetScale( s );
139 if( this.tagged.attachedChildren ) then
140 for i, v in this.tagged.attachedChildren do
141 v:SetScale( s );
142 end
143 end
144  
145 this:SetWidth( w );
146 this:SetHeight( h );
147 Print_Debug("size changed: s="..s.." w="..w.." h="..h);
148 end
149 end
150  
151 function CleanMinimapMover_StopMoving( frame )
152 if( frame) then
153 CleanMinimapMover_Detach( frame );
154 end
155 end