import "Turbine.UI";
SimpleDragBar = class(Turbine.UI.Window);
function SimpleDragBar:Constructor(target, name)
Turbine.UI.Window.Constructor(self);
self.wndTarget = target;
self.barOnTop = true;
self.visible = false;
self.draggable = false;
self:SetBackColor(Turbine.UI.Color(.5, 0, 0, 0));
-- the drag label
self.dragLabel = Turbine.UI.Label();
self.dragLabel:SetParent(self);
self.dragLabel:SetForeColor(Turbine.UI.Color(1, 1, 1, 1));
self.dragLabel:SetOutlineColor(Turbine.UI.Color(1, 0, 0, 0));
self.dragLabel:SetFontStyle(Turbine.UI.FontStyle.Outline);
self.dragLabel:SetFont(Turbine.UI.Lotro.Font.Verdana16);
self.dragLabel:SetTextAlignment(Turbine.UI.ContentAlignment.TopCenter);
self.dragLabel:SetPosition(1, 0);
self.dragLabel:SetText(name);
-- center
self.center = Turbine.UI.Control();
self.center:SetParent(self);
self.center:SetBackColor(Turbine.UI.Color(0, 0, 0, 0));
self.center:SetPosition(1, 24);
-- listeners
self.dragLabel.MouseDown = function(sender, args)
if (args.Button == Turbine.UI.MouseButton.Left) then
self.dragStartX = args.X;
self.dragStartY = args.Y;
self.dragging = true;
if (type(self.wndTarget.DragStart) == "function") then
self.wndTarget.DragStart();
end
end
end
self.dragLabel.MouseMove = function(sender, args)
if (self.dragging) then
local left, top = self.wndTarget:GetPosition();
local width, height = self.wndTarget:GetSize();
local x = left + (args.X - self.dragStartX);
local y = top + (args.Y - self.dragStartY);
x, y = validatePosition(x, y, width, height);
self.wndTarget:SetPosition(x, y);
self:RecalculatePosition();
end
end
self.dragLabel.MouseUp = function(sender, args)
if (args.Button == Turbine.UI.MouseButton.Left) then
self.dragging = false;
if (type(self.wndTarget.DragEnd) == "function") then
self.wndTarget.DragEnd();
end
end
end
-- refresh
self:Refresh();
end
function SimpleDragBar:SetBarOnTop(top)
self.barOnTop = top;
self.dragLabel:SetTextAlignment(top and Turbine.UI.ContentAlignment.TopCenter or Turbine.UI.ContentAlignment.BottomCenter);
self:Refresh();
end
function SimpleDragBar:SetAllowsDragging(allow)
end
function SimpleDragBar:SetAllowsHUDHiding(allow, show)
end
function SimpleDragBar:SetHUDVisible(visible)
self.visible = visible;
self.wndTarget:SetVisible(visible);
self:SetVisible(visible and self.draggable or false);
end
function SimpleDragBar:SetDraggable(draggable)
self.draggable = draggable;
self:SetVisible(draggable and self.visible or false);
end
function SimpleDragBar:Refresh()
self:RecalculateSize();
self:RecalculatePosition();
end
function SimpleDragBar:RecalculateSize()
local width, height = self.wndTarget:GetSize();
self:SetSize(width + 2, 25 + height);
self.dragLabel:SetSize(width, 24);
self.center:SetSize(width, height);
end
function SimpleDragBar:RecalculatePosition()
local width, height = self.wndTarget:GetSize();
local x, y = self.wndTarget:GetPosition();
if (self.barOnTop) then
self:SetPosition(x - 1, math.max(y - 24, 0));
self.dragLabel:SetPosition(1, 0);
self.center:SetPosition(1, 24);
else
self:SetPosition(x - 1, math.min(y - 1, Turbine.UI.Display:GetHeight() - (25 + height)));
self.dragLabel:SetPosition(1, height);
self.center:SetPosition(1, 1);
end
end