lotrointerface.com
Search Downloads

LoTROInterface SVN SequenceBars

[/] [trunk/] [Thurallor/] [Common/] [UI/] [Tabs/] [TabCard.lua] - Rev 20

Go to most recent revision | Compare with Previous | Blame | View Log

TabCard = class(Turbine.UI.Control);

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

function TabCard:Constructor(hScroll, vScroll)
    Turbine.UI.Control.Constructor(self);
    self:SetMouseVisible(false);

    self.tabHeight = 20;
    self.scrollBarSize = 10;
    self.interiorAlignment = Turbine.UI.ContentAlignment.TopCenter;
    
    self.tabLeft = Turbine.UI.Control();
        self.tabLeft:SetBlendMode(Turbine.UI.BlendMode.AlphaBlend);
    self.tabLeft:SetParent(self);
    self.tabLeft:SetHeight(self.tabHeight);
    
    self.tabRight = Turbine.UI.Control();
        self.tabRight:SetBlendMode(Turbine.UI.BlendMode.AlphaBlend);
    self.tabRight:SetParent(self);
    self.tabRight:SetSize(18, self.tabHeight);

    self.tabText = Turbine.UI.Label();
    self.tabText:SetParent(self.tabLeft);
    self.tabText:SetHeight(self.tabHeight);
        self.tabText:SetFont(Turbine.UI.Lotro.Font.TrajanPro15);
        self.tabText:SetFontStyle(Turbine.UI.FontStyle.Outline);
        self.tabText:SetOutlineColor(Turbine.UI.Color.Black);
        self.tabText:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleCenter);
    self.tabText.MouseClick = function(sender, args)
        if (self.Click) then
            self:Click(args);
        end
    end
    
    self.border = Turbine.UI.Lotro.TextBox();
    self.border:SetParent(self);
    self.border:SetReadOnly(true);
    self.border:SetPosition(0, self.tabHeight);
    self.padding = 5;

    self.interior = Turbine.UI.ListBox();
    self.interior:SetParent(self);
    self.interior:SetPosition(self.padding, self.tabHeight + self.padding);
    self.interior.wrapper = Turbine.UI.Control();
    self.interior.wrapper:SetParent(self.interior);
    self.interior:AddItem(self.interior.wrapper);

    if (hScroll) then
        self.hScrollBar = Turbine.UI.Lotro.ScrollBar();
        self.hScrollBar:SetOrientation(Turbine.UI.Orientation.Horizontal);
        self.hScrollBar:SetParent(self);
        self.hScrollBar:SetHeight(self.scrollBarSize);
        self.hScrollBar:SetLeft(2);
    end
    
    if (vScroll) then
        self.vScrollBar = Turbine.UI.Lotro.ScrollBar();
        self.vScrollBar:SetOrientation(Turbine.UI.Orientation.Vertical);
        self.vScrollBar:SetParent(self);
        self.vScrollBar:SetWidth(self.scrollBarSize);
        self.vScrollBar:SetTop(self.tabHeight + 2);
    end

    if ((not hScroll) and (not vScroll)) then
        self.scrollBarSize = 0;
    end
    
    self:BringToFront();
    self:DoLayout();
end

function TabCard:SetInteriorControl(control)
    if (self.interior.control) then
        self.interior.control:SetParent(nil);
    end
    self.interior.control = control;
    if (control) then
        control:SetParent(self.interior.wrapper);
        control.SizeChanged = function()
            self:DoLayout();
        end
    end
    self:DoLayout();
end

function TabCard:SetInteriorAlignment(alignment)
    self.interiorAlignment = alignment;
    self:DoLayout();
end

function TabCard:BringToFront()
    self.tabLeft:SetBackground(imagePath .. "/tab_front_left.tga");
    self.tabRight:SetBackground(imagePath .. "/tab_front_right.tga");
        self.tabText:SetForeColor(Turbine.UI.Color.White);
    self.border:SetVisible(true);
    self.interior:SetVisible(true);
    if (self.hScrollBar) then
        self.hScrollBar:SetParent(self);
        self.interior:SetHorizontalScrollBar(self.hScrollBar);
    end
    if (self.vScrollBar) then
        self.vScrollBar:SetParent(self);
        self.interior:SetVerticalScrollBar(self.vScrollBar);
    end
    self:DoLayout();
end    

function TabCard:SendToBack()
    self.tabLeft:SetBackground(imagePath .. "/tab_back_left.tga");
    self.tabRight:SetBackground(imagePath .. "/tab_back_right.tga");
    --self.tabText:SetForeColor(Turbine.UI.Color(1, 0.42, 0.42, 0.42));
    self.tabText:SetForeColor(Turbine.UI.Color.Goldenrod);
    if (self.hScrollBar) then
        self.interior:SetHorizontalScrollBar(nil);
        self.hScrollBar:SetParent(nil);
    end
    if (self.vScrollBar) then
        self.interior:SetVerticalScrollBar(nil);
        self.vScrollBar:SetParent(nil);
    end
    self.border:SetVisible(false);
    self.interior:SetVisible(false);
end

function TabCard:IsInFront()
    return (self.interior:IsVisible());
end

function TabCard:SetTabWidth(width)
    width = width - 18;
    self.tabLeft:SetWidth(width);
    self.tabText:SetWidth(width + 18);
    self.tabRight:SetLeft(self.tabLeft:GetLeft() + width);
end

function TabCard:SetTabLeft(left)
    self.tabLeft:SetLeft(left);
    self.tabRight:SetLeft(left + self.tabLeft:GetWidth());
end

function TabCard:SetTabText(text)
    self.tabText:SetText(text);
end

function TabCard:GetTabText()
    return self.tabText:GetText();
end

function TabCard:DoLayout()
    local width, height = self:GetSize();
    self.border:SetSize(width, height - self.tabHeight);
    if (self.hScrollBar) then
        self.hScrollBar:SetTop(height - self.scrollBarSize - 2);
        self.hScrollBar:SetWidth(width - self.scrollBarSize - 4);
    end
    if (self.vScrollBar) then
        self.vScrollBar:SetLeft(width - self.scrollBarSize - 2);
        self.vScrollBar:SetHeight(height - self.tabHeight - self.scrollBarSize - 4);
    end
    self.interior:SetSize(width - (self.padding + self.scrollBarSize + 2), height - (self.tabHeight + self.padding + self.scrollBarSize + 2));
    
    -- Do placement of the interior control as per SetInteriorAlignment()
    if (self.interior.control) then
        width, height = self.interior:GetSize();
        controlWidth, controlHeight = self.interior.control:GetSize();
        if (
            (controlWidth >= width) or
            (self.interiorAlignment == Turbine.UI.ContentAlignment.TopLeft) or
            (self.interiorAlignment == Turbine.UI.ContentAlignment.MiddleLeft) or
            (self.interiorAlignment == Turbine.UI.ContentAlignment.BottomLeft)
        ) then
            self.interior.control:SetLeft(0);
            self.interior.wrapper:SetWidth(controlWidth);
        elseif (
            (self.interiorAlignment == Turbine.UI.ContentAlignment.TopCenter) or
            (self.interiorAlignment == Turbine.UI.ContentAlignment.MiddleCenter) or
            (self.interiorAlignment == Turbine.UI.ContentAlignment.BottomCenter)
        ) then
            self.interior.control:SetLeft(math.floor(0.5 + (width - controlWidth) / 2));
            self.interior.wrapper:SetWidth(width);
        else -- Turbine.UI.ContentAlignment.[...]Right
            self.interior.control:SetLeft(width - controlWidth);
            self.interior.wrapper:SetWidth(width);
        end
        if (
            (controlHeight >= height) or
            (self.interiorAlignment == Turbine.UI.ContentAlignment.TopLeft) or
            (self.interiorAlignment == Turbine.UI.ContentAlignment.TopCenter) or
            (self.interiorAlignment == Turbine.UI.ContentAlignment.TopRight)
        ) then
            self.interior.control:SetTop(0);
            self.interior.wrapper:SetHeight(controlHeight);
        elseif (
            (self.interiorAlignment == Turbine.UI.ContentAlignment.MiddleLeft) or
            (self.interiorAlignment == Turbine.UI.ContentAlignment.MiddleCenter) or
            (self.interiorAlignment == Turbine.UI.ContentAlignment.MiddleRight)
        ) then
            self.interior.control:SetTop(math.floor(0.5 + (height - controlHeight) / 2));
            self.interior.wrapper:SetHeight(height);
        else -- Turbine.UI.ContentAlignment.Bottom[...]
            self.interior.control:SetTop(height - controlHeight);
            self.interior.wrapper:SetHeight(height);
        end
    end

    self.interior:ClearItems();
    self.interior:AddItem(self.interior.wrapper);
end

function TabCard:SetSize(width, height)
    Turbine.UI.Control.SetSize(self, width, height);
    self:DoLayout();
end

function TabCard:SetWidth(width)
    Turbine.UI.Control.SetWidth(self, width);
    self:DoLayout();
end

function TabCard:SetHeight(height)
    Turbine.UI.Control.SetHeight(self, height);
    self:DoLayout();
end

Go to most recent revision | Compare with Previous | Blame


All times are GMT -5. The time now is 10:23 PM.


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