lotrointerface.com
Search Downloads

LoTROInterface SVN Reminders

[/] [trunk/] [Thurallor/] [Common/] [UI/] [RoundButton_1/] [RoundButton.lua] - Rev 2

Compare with Previous | Blame | View Log

RoundButton = class(Turbine.UI.Control);

local importPath = getfenv(1)._.Name;
local imagePath = string.gsub(string.gsub(importPath, "%.RoundButton$", ""), "%.", "/");

function RoundButton:Constructor()
    Turbine.UI.Control.Constructor(self);
    Turbine.UI.Control.SetBackground(self, imagePath .. "/round_button.tga");
    Turbine.UI.Control.SetBlendMode(self, Turbine.UI.BlendMode.AlphaBlend);
    Turbine.UI.Control.SetSize(self, 36, 36);

    self.interior = Turbine.UI.Control();
    self.interior:SetMouseVisible(false);
    self.interior:SetParent(self);
    self.interior:SetSize(25, 25);
    self.interior:SetPosition(5, 5);
    self.interior:SetBlendMode(Turbine.UI.BlendMode.AlphaBlend);

    self.enabled = true;
    self:_UpdateImage();
end

function RoundButton:GetMouseDistanceFromCenter()
    local x, y = self:GetMousePosition();
    return ((x - 17)^2 + (y - 17)^2)^0.5;
end

function RoundButton:SetEnabled(enabled)
    self.enabled = enabled;
    self:_UpdateImage();
end

function RoundButton:SetBackground(image)
    self.enabledImage = image;
    self:_UpdateImage();
end

function RoundButton:SetHighlightedBackground(image)
    self.highlightedImage = image;
    self:_UpdateImage();
end

function RoundButton:SetMouseDownBackground(image)
    self.mouseDownImage = image;
    self:_UpdateImage();
end

function RoundButton:SetDisabledBackground(image)
    self.disabledImage = image;
    self:_UpdateImage();
end

function RoundButton:_UpdateImage()
    if (self.enabled == false) then
        self.interior:SetBackground(self.disabledImage);
    elseif (self.mouseDown) then
        self.interior:SetBackground(self.mouseDownImage);
     elseif (self.mouseOver) then
        self.interior:SetBackground(self.highlightedImage);
    else
        self.interior:SetBackground(self.enabledImage);
    end
end

-- Since this is a circular button, we need a circular region for MouseEnter and MouseLeave events.
function RoundButton:MouseMove()
    if (self:GetMouseDistanceFromCenter() > 15) then
        if (self.mouseOver) then
            self.mouseOver = false;
            self:_UpdateImage();
            DoCallbacks(self, "HighlightedChanged", false);
        end
    else
        if (not self.mouseOver) then
            self.mouseOver = true;
            self:_UpdateImage();
            DoCallbacks(self, "HighlightedChanged", true);
        end
    end
end

function RoundButton:MouseEnter()
    DoCallbacks(self, "MouseMove");
end

function RoundButton:MouseLeave()
    DoCallbacks(self, "MouseMove");
end

function RoundButton:MouseDown(args)
    if (self.mouseOver) then
        self.mouseDown = true;
        self:_UpdateImage();
    end
end

function RoundButton:MouseUp(args)
    self.mouseDown = false;
    self:_UpdateImage();
    if (self.mouseOver) then
        DoCallbacks(self, "Click", args);
    end
end

Compare with Previous | Blame


All times are GMT -5. The time now is 12:48 PM.


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