-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of https://github.com/Paliak/PathOfBuilding into dev
- Loading branch information
Showing
5 changed files
with
204 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
-- Path of Building | ||
-- | ||
-- Class: Dragger Button Control | ||
-- Dragger button control. | ||
-- | ||
local DraggerClass = newClass("DraggerControl", "Control", "TooltipHost", function(self, anchor, x, y, width, height, label, onKeyDown, onKeyUp, onRightClick, onHover, forceTooltip) | ||
self.Control(anchor, x, y, width, height) | ||
self.TooltipHost() | ||
self.label = label | ||
self.onKeyDown = onKeyDown | ||
self.onKeyUp = onKeyUp | ||
self.onRightClick = onRightClick | ||
self.onHover = onHover | ||
self.forceTooltip = forceTooltip | ||
self.cursorX = 0 | ||
self.cursorY = 0 | ||
end) | ||
|
||
function DraggerClass:SetImage(path) | ||
if path then | ||
self.image = NewImageHandle() | ||
self.image:Load(path) | ||
else | ||
self.image = nil | ||
end | ||
end | ||
|
||
function DraggerClass:IsMouseOver() | ||
if not self:IsShown() then | ||
return false | ||
end | ||
return self:IsMouseInBounds() | ||
end | ||
|
||
function DraggerClass:Draw(viewPort, noTooltip) | ||
local x, y = self:GetPos() | ||
local width, height = self:GetSize() | ||
local enabled = self:IsEnabled() | ||
local mOver = self:IsMouseOver() | ||
local locked = self:GetProperty("locked") | ||
|
||
if not enabled then | ||
SetDrawColor(0.33, 0.33, 0.33) | ||
elseif mOver or locked then | ||
SetDrawColor(1, 1, 1) | ||
else | ||
SetDrawColor(0.5, 0.5, 0.5) | ||
end | ||
DrawImage(nil, x, y, width, height) | ||
if not enabled then | ||
SetDrawColor(0, 0, 0) | ||
elseif self.clicked and mOver then | ||
SetDrawColor(0.5, 0.5, 0.5) | ||
elseif mOver or locked then | ||
SetDrawColor(0.33, 0.33, 0.33) | ||
else | ||
SetDrawColor(0, 0, 0) | ||
end | ||
DrawImage(nil, x + 1, y + 1, width - 2, height - 2) | ||
if self.image then | ||
if enabled then | ||
SetDrawColor(1, 1, 1) | ||
else | ||
SetDrawColor(0.33, 0.33, 0.33) | ||
end | ||
DrawImage(self.image, x + 2, y + 2, width - 4, height - 4) | ||
if self.clicked and mOver then | ||
SetDrawColor(1, 1, 1, 0.5) | ||
DrawImage(nil, x + 1, y + 1, width - 2, height - 2) | ||
end | ||
end | ||
if not enabled then | ||
SetDrawColor(0.33, 0.33, 0.33) | ||
elseif mOver or locked or self.dragging then | ||
SetDrawColor(1, 1, 1) | ||
else | ||
SetDrawColor(0.5, 0.5, 0.5) | ||
end | ||
local label = self:GetProperty("label") | ||
if label == "+" then | ||
DrawImage(nil, x + width * 0.2, y + height * 0.45, width * 0.6, height * 0.1) | ||
DrawImage(nil, x + width * 0.45, y + height * 0.2, width * 0.1, height * 0.6) | ||
elseif label == "-" then | ||
DrawImage(nil, x + width * 0.2, y + height * 0.45, width * 0.6, height * 0.1) | ||
elseif label == "x" then | ||
DrawImageQuad(nil, x + width * 0.2, y + height * 0.3, x + width * 0.3, y + height * 0.2, x + width * 0.8, y + height * 0.7, x + width * 0.7, y + height * 0.8) | ||
DrawImageQuad(nil, x + width * 0.7, y + height * 0.2, x + width * 0.8, y + height * 0.3, x + width * 0.3, y + height * 0.8, x + width * 0.2, y + height * 0.7) | ||
elseif label == "//" then | ||
DrawImageQuad(nil, x + width * 0.75, y + height * 0.15, x + width * 0.85, y + height * 0.25, x + width * 0.25, y + height * 0.85, x + width * 0.15, y + height * 0.75) | ||
DrawImageQuad(nil, x + width * 0.75, y + height * 0.5, x + width * 0.85, y + height * 0.6, x + width * 0.6, y + height * 0.85, x + width * 0.5, y + height * 0.75) | ||
else | ||
local overSize = self.overSizeText or 0 | ||
DrawString(x + width / 2, y + 2 - overSize, "CENTER_X", height - 4 + overSize * 2, "VAR", label) | ||
end | ||
if mOver then | ||
if not noTooltip or self.forceTooltip then | ||
SetDrawLayer(nil, 100) | ||
self:DrawTooltip(x, y, width, height, viewPort) | ||
SetDrawLayer(nil, 0) | ||
end | ||
if self.onHover ~= nil then | ||
return self.onHover() | ||
end | ||
end | ||
end | ||
|
||
function DraggerClass:OnKeyDown(key) | ||
if not self:IsShown() or not self:IsEnabled() or self:GetProperty("locked") then | ||
return | ||
end | ||
if key == "LEFTBUTTON" then | ||
local cursorX, cursorY = GetCursorPos() | ||
|
||
self.clicked = true | ||
self.dragging = true | ||
if self.onKeyDown then | ||
self.onKeyDown({ X = cursorX, Y = cursorY }) | ||
end | ||
|
||
self.cursorX = cursorX | ||
self.cursorY = cursorY | ||
end | ||
return self | ||
end | ||
function DraggerClass:OnKeyUp(key) | ||
if not self:IsShown() or not self:IsEnabled() or self:GetProperty("locked") then | ||
return | ||
end | ||
local cursorX, cursorY = GetCursorPos() | ||
if key == "LEFTBUTTON" then | ||
self.clicked = false | ||
self.dragging = false | ||
if self.onKeyUp then | ||
self.onKeyUp({ X = self.cursorX - cursorX, Y = self.cursorY - cursorY }) | ||
end | ||
end | ||
if key == "RIGHTBUTTON" and self:IsMouseInBounds() then | ||
if self.onRightClick then | ||
self.onRightClick({ X = cursorX, Y = cursorY }) | ||
end | ||
end | ||
return self | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
-- Path of Building | ||
-- | ||
-- Class: Resizable Edit Control | ||
-- Resizable edit control. | ||
-- | ||
local m_max = math.max | ||
local m_min = math.min | ||
|
||
local ResizableEditClass = newClass("ResizableEditControl", "EditControl", function(self, anchor, x, y, minwidth, width, maxwidth, minheight, height, maxheight, init, prompt, filter, limit, changeFunc, lineHeight, allowZoom, clearable) | ||
self.EditControl(anchor, x, y, width, height, init, prompt, filter, limit, changeFunc, lineHeight, allowZoom, clearable) | ||
self.minheight = minheight or height | ||
self.maxheight = maxheight or height | ||
self.minwidth = minwidth or width | ||
self.maxwidth = maxwidth or width | ||
self.controls.draggerHeight = new("DraggerControl", {"BOTTOMRIGHT", self, "BOTTOMRIGHT"}, 7, 7, 14, 14, "//", nil, nil, function (position) | ||
-- onRightClick | ||
if (self.height ~= self.minheight) or (self.width ~= self.minwidth) then | ||
self:SetWidth(self.minwidth) | ||
self:SetHeight(self.minheight) | ||
else | ||
self:SetWidth(self.maxwidth) | ||
self:SetHeight(self.maxheight) | ||
end | ||
end) | ||
self.protected = false | ||
end) | ||
function ResizableEditClass:Draw(viewPort, noTooltip) | ||
self:SetBoundedDrag(self) | ||
self.EditControl:Draw(viewPort, noTooltip) | ||
end | ||
function ResizableEditClass:SetBoundedDrag() | ||
if self.controls.draggerHeight.dragging then | ||
local cursorX, cursorY = GetCursorPos() | ||
local x, y = self:GetPos() | ||
self:SetHeight(cursorY - y) | ||
self:SetWidth(cursorX - x) | ||
end | ||
end | ||
|
||
function ResizableEditClass:SetWidth(width) | ||
self.width = m_max(m_min(width or 0, self.maxwidth), self.minwidth) | ||
end | ||
function ResizableEditClass:SetHeight(height) | ||
self.height = m_max(m_min(height or 0, self.maxheight), self.minheight) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters