Skip to content

Commit

Permalink
🐛 #7: Fixed a bug where the used could scale the window too small
Browse files Browse the repository at this point in the history
  • Loading branch information
AssisrMatheus committed Sep 19, 2019
1 parent adb01df commit a3b8e98
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 27 deletions.
62 changes: 62 additions & 0 deletions components/ResponsiveFrame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,66 @@ end

function OnLoad(frame)
ResponsiveFrame:OnLoad(frame)
end

function OnUpdate(self)
if (self.isSizing == true) then
-- If the width or height is less than the allowed ammount
-- stop resizing
local width, height = self:GetParent():GetWidth(), self:GetParent():GetHeight()
if (width <= 105 or height <= 140) then
self.isSizing = false;
self:GetParent():StopMovingOrSizing()
end
end

if self.isScaling == true then
local cx, cy = GetCursorPosition()
cx = cx / self:GetEffectiveScale() - self:GetParent():GetLeft()
cy = self:GetParent():GetHeight() - (cy / self:GetEffectiveScale() - self:GetParent():GetBottom() )

local tNewScale = cx / self:GetParent():GetWidth()
local tx, ty = self:GetParent().x / tNewScale, self:GetParent().y / tNewScale
local newScale = self:GetParent():GetScale() * tNewScale;

if (newScale > 0) then
self:GetParent():ClearAllPoints()
self:GetParent():SetScale(self:GetParent():GetScale() * tNewScale)
self:GetParent():SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", tx, ty)
self:GetParent().x, self:GetParent().y = tx, ty
end
end
end

function OnMouseUp(self, button)
if button == "LeftButton" then
self.isSizing = false
self:GetParent():StopMovingOrSizing()
elseif button == "RightButton" then
self.isScaling = false
end
end

function OnMouseDown(self, button)
local width, height = self:GetParent():GetWidth(), self:GetParent():GetHeight()

-- If the width or height is less than the allowed ammount
-- Resets the size and don't do anything
if (width <= 116) then
self:GetParent():SetWidth(120)
end

if (height <= 146) then
self:GetParent():SetHeight(147)
end

if button == "LeftButton" then
self.isSizing = true
self:GetParent():StartSizing("BOTTOMRIGHT")
self:GetParent():SetUserPlaced(true)
end

if button == "RightButton" then
self.isScaling = true
end
end
31 changes: 4 additions & 27 deletions components/ResponsiveFrame.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,36 +36,13 @@

<Scripts>
<OnMouseDown>
if button == "LeftButton" then
self.isSizing = true
self:GetParent():StartSizing("BOTTOMRIGHT")
self:GetParent():SetUserPlaced(true)
elseif button == "RightButton" then
self.isScaling = true
end
OnMouseDown(self, button)
</OnMouseDown>
<OnMouseUp>
if button == "LeftButton" then
self.isSizing = false
self:GetParent():StopMovingOrSizing()
elseif button == "RightButton" then
self.isScaling = false
end
<OnMouseUp>
OnMouseUp(self, button)
</OnMouseUp>
<OnUpdate>
if self.isScaling == true then
local cx, cy = GetCursorPosition()
cx = cx / self:GetEffectiveScale() - self:GetParent():GetLeft()
cy = self:GetParent():GetHeight() - (cy / self:GetEffectiveScale() - self:GetParent():GetBottom() )

local tNewScale = cx / self:GetParent():GetWidth()
local tx, ty = self:GetParent().x / tNewScale, self:GetParent().y / tNewScale

self:GetParent():ClearAllPoints()
self:GetParent():SetScale(self:GetParent():GetScale() * tNewScale)
self:GetParent():SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", tx, ty)
self:GetParent().x, self:GetParent().y = tx, ty
end
OnUpdate(self)
</OnUpdate>
</Scripts>

Expand Down
7 changes: 7 additions & 0 deletions debug.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,10 @@ function Debug:Init()
end
end
end

function printDBG(...)
if(Constants.debugMode) then
print(...)
end
end

0 comments on commit a3b8e98

Please sign in to comment.