lotrointerface.com
Search Downloads

LoTROInterface SVN Reminders

[/] [trunk/] [Thurallor/] [Common/] [UI/] [Zoomer_3.lua] - Rev 11

Compare with Previous | Blame | View Log

Zoomer = class(Turbine.UI.Control)

Zoomer.defaultSpeed = 2;
Zoomer.defaultTrailDuration = 0.25;

function Zoomer:Constructor(fromCtl, toCtl, speed, trailDuration)
    Turbine.UI.Control.Constructor(self);
    self.fromLeft, self.fromTop = fromCtl:PointToScreen(0, 0);
    self.fromWidth, self.fromHeight = fromCtl:GetSize();
    self.toLeft, self.toTop = toCtl:PointToScreen(0, 0);
    self.toWidth, self.toHeight = toCtl:GetSize();
    self.speed = speed or Zoomer.defaultSpeed;
    self.trailDuration = trailDuration or Zoomer.defaultTrailDuration;
    self.startTime = Turbine.Engine.GetGameTime();
    self.zOrder = 0x7FFFFFFF; -- maximum Z

    local fromArea = self.fromWidth * self.fromHeight;
    local toArea = self.toWidth * self.toHeight;
    self.gettingSmaller = (toArea < fromArea);

    self.frames = {};
    self:SetWantsUpdates(true);
end

function Zoomer:_AddFrame(left, top, width, height)
    local frame = Turbine.UI.Window();
    frame:SetVisible(true);
    frame:SetMouseVisible(false);
    frame:SetBackColor(Turbine.UI.Color.Silver);
    frame:SetSize(width, height);
    frame:SetZOrder(self.zOrder);
    if (self.gettingSmaller) then
        self.zOrder = self.zOrder - 1;
    end
    frame:SetPosition(left, top);
    table.insert(self.frames, frame);

    local inside = Turbine.UI.Control();
    inside:SetMouseVisible(false);
    inside:SetBackColor(Turbine.UI.Color(0, 0, 0 ,0));
    inside:SetParent(frame);
    inside:SetPosition(2, 2);
    inside:SetSize(width - 4, height - 4);

    -- Destroy frame a short time later
    frame.createdTime = Turbine.Engine.GetGameTime();
    frame.Update = function(f)
        local currentTime = Turbine.Engine.GetGameTime();
        if (currentTime - f.createdTime > self.trailDuration) then
            f:SetWantsUpdates(false);
            f:Close();
        else
            local fade = (currentTime - f.createdTime) / self.trailDuration;
            f:SetOpacity(1 - fade);
        end
    end
    frame:SetWantsUpdates(true);
end

function Zoomer:Update()
    local progress = (Turbine.Engine.GetGameTime() - self.startTime) * self.speed;
    local param = progress^3;
    if (progress >= 1) then
        self:SetWantsUpdates(false);
        DoCallbacks(self, "ZoomComplete");
    else
        local left = math.floor(self.fromLeft + param * (self.toLeft - self.fromLeft) + 0.5);
        local top = math.floor(self.fromTop + param * (self.toTop - self.fromTop) + 0.5);
        local width = math.floor(self.fromWidth + param * (self.toWidth - self.fromWidth) + 0.5);
        local height = math.floor(self.fromHeight + param * (self.toHeight - self.fromHeight) + 0.5);
        self:_AddFrame(left, top, width, height);
    end
end

Thurallor = Thurallor or {};
Thurallor.UI = Thurallor.UI or {};
Thurallor.UI.Zoomer = Zoomer;

Compare with Previous | Blame


All times are GMT -5. The time now is 08:07 PM.


Our Network
EQInterface | EQ2Interface | Minion | WoWInterface | ESOUI | LoTROInterface | MMOUI | Swtorui