EdgeMover = class(Turbine.UI.Control);
function EdgeMover:Constructor(orientation)
Turbine.UI.Control.Constructor(self);
if (orientation == nil) then
orientation = Turbine.UI.Orientation.Vertical;
end
self.orientation = orientation;
self.BackColor = Turbine.UI.Color(1, 0.5, 0.5, 0.5);
-- Attach callbacks by the conventional mechanism, so the user can also add his own if desired
AddCallback(self, "MouseUp", self._MouseUp);
AddCallback(self, "MouseDown", self._MouseDown);
AddCallback(self, "MouseEnter", self._MouseEnter);
AddCallback(self, "MouseLeave", self._MouseLeave);
AddCallback(self, "MouseMove", self._MouseMove);
end
function EdgeMover:SetBackColor(color)
self.BackColor = color;
end
function EdgeMover:_MouseEnter()
self:ShowCursor(true);
Turbine.UI.Control.SetBackColor(self, self.BackColor);
self.mouseInside = true;
end
function EdgeMover:_MouseDown()
self.mouseDown = true;
self.originalMouseX, self.originalMouseY = Turbine.UI.Display.GetMouseX(), Turbine.UI.Display.GetMouseY();
end
function EdgeMover:_MouseMove()
self:ShowCursor(true);
if (not self.mouseDown) then
return;
end
local newMouseX, newMouseY = Turbine.UI.Display.GetMouseX(), Turbine.UI.Display.GetMouseY();
local deltaX, deltaY = newMouseX - self.originalMouseX, newMouseY - self.originalMouseY;
self.originalMouseX, self.originalMouseY = newMouseX, newMouseY;
if ((self.orientation == Turbine.UI.Orientation.Vertical) and deltaX) then
self:SetLeft(self:GetLeft() + deltaX);
DoCallbacks(self, "EdgeMoved");
elseif ((self.orientation == Turbine.UI.Orientation.Horizontal) and deltaY) then
self:SetTop(self:GetTop() + deltaY);
DoCallbacks(self, "EdgeMoved");
end
end
function EdgeMover:_MouseUp()
if (not self.mouseInside) then
self:ShowCursor(nil);
Turbine.UI.Control.SetBackColor(self, nil);
end
self.mouseDown = false;
end
function EdgeMover:_MouseLeave()
if (not self.mouseDown) then
self:ShowCursor(nil);
Turbine.UI.Control.SetBackColor(self, nil);
end
self.mouseInside = false;
end
function EdgeMover:ShowCursor(enable)
if (enable) then
if (not self.cursor) then
self.cursor = Turbine.UI.Window();
self.cursor:SetZOrder(2147483647);
self.cursor:SetVisible(true);
self.cursor:SetMouseVisible(false);
self.cursor:SetSize(32, 32);
end
if (self.orientation == Turbine.UI.Orientation.Vertical) then
self.cursor:SetPosition(Turbine.UI.Display.GetMouseX() - 16, Turbine.UI.Display.GetMouseY() - 20);
self.cursor:SetBackground(0x410081BF);
else -- self.orientation == Turbine.UI.Orientation.Horizontal
self.cursor:SetPosition(Turbine.UI.Display.GetMouseX() - 22, Turbine.UI.Display.GetMouseY() - 16);
self.cursor:SetBackground(0x410081C0);
end
else
if (self.cursor) then
self.cursor:Close();
self.cursor = nil;
end
end
end
Thurallor = Thurallor or {};
Thurallor.UI = Thurallor.UI or {};
Thurallor.UI.EdgeMover = EdgeMover;