lotrointerface.com
Search Downloads

LoTROInterface SVN Calendar

[/] [Release_3.3/] [FrostyPlugins/] [Calendar/] [CheckBox.lua] - Rev 33

Compare with Previous | Blame | View Log

-- A button with a Checkbox with label.

import "Turbine";

--------------------------------------------------------------------------
--- CheckBox
--
-- A Checkbox control that contains a label.
--
-- There seems to be a bug in the Lotro.Checkbox causes it to not recieve events
-- So use this control to drive the checkbox because this DOES receive events
--
CheckBox = class( Turbine.UI.Control );
function CheckBox:Constructor(params)
        Turbine.UI.Control.Constructor( self );
        if( "nil" ~= type(params) ) then
                error("CheckBox given unexpected parameter!",3);
        end
        --Turbine.Shell.WriteLine("CheckBox:Constructor()");

    self:SetEnabled( true );
    --self:SetSelectable( true );
    self:SetEnabled( true );
    self:SetMouseVisible( true );
    self:SetWantsUpdates( true );
        
    -- create the checkbox
    self.checkbox = Turbine.UI.Lotro.CheckBox();
    self.checkbox:SetParent( self );
    self.checkbox:SetPosition( 0, 0 ); -- left,top
    self.checkbox:SetSize( -- width,height
                20,
                self:GetHeight() );
    --self.checkbox:SetBackColor(Turbine.UI.Color.DimGray);
    --self.checkbox:SetFont( Turbine.UI.Lotro.Font.Verdana20 );
    self.checkbox:SetText( "" ); -- no label
    self.checkbox:SetCheckAlignment( Turbine.UI.ContentAlignment.MiddleLeft );
    self.checkbox:SetVisible( true );   
    self.checkbox:SetEnabled( false );
        self.checkbox:SetChecked( false );
    self.checkbox:SetSelectable( false );
    self.checkbox:SetMouseVisible( false );
    self.checkbox:SetWantsUpdates( false );
        
        -- The label for the checkbox
    self.label = Turbine.UI.Label();
    self.label:SetParent( self );
    --self.label:SetBlendMode( Turbine.UI.BlendMode.Overlay );
    self.label:SetSize( -- width,height
                self:GetWidth() - self.checkbox:GetWidth(), 
                self:GetHeight() );
    self.label:SetPosition( -- left,top
                self.checkbox:GetWidth(), 
                0 ); 
    self.label:SetText( "Checkbox" );
    self.label:SetVisible( true );
        --self.label:SetBackColor(Turbine.UI.Color.Gray);
    self.label:SetTextAlignment( Turbine.UI.ContentAlignment.MiddleLeft );
    self.label:SetWantsUpdates( true );
    self.label:SetMouseVisible( true );

    self.label.MouseClick = function( sender, args )
        --Turbine.Shell.WriteLine( "CheckBox.label:MouseClick");
                -- forward click on label to checkbox
                self:MouseClick();
    end 
    
    self.MouseClick = function( sender, args )
        --Turbine.Shell.WriteLine( "CheckBox:MouseClick");
                local newValue = not self.checkbox:IsChecked();
                self.checkbox:SetChecked( newValue );
                self:CheckChanged(self.checkbox:IsChecked())
    end 

    self.checkbox.CheckChanged = function( sender, args )
        --Turbine.Shell.WriteLine( "CheckBox.checkbox:CheckChanged");
                -- Intended to be overriden for notification
                self:CheckChanged(self,args);
    end 
        
    self.CheckChanged = function( sender, args )
        --Turbine.Shell.WriteLine( "CheckBox:CheckChanged");
                -- Intended to be overriden for notification
    end 
        
        self.IsChecked = function(sender)
        --Turbine.Shell.WriteLine( "CheckBox:IsChecked" );
                return self.checkbox:IsChecked();
        end

        self.SetChecked = function(sender, args)
        --Turbine.Shell.WriteLine( string.format(
                --      "CheckBox:SetChecked [%s]",
                --      args and "true" or "false"
                --      ) );
                return self.checkbox:SetChecked(args);
        end
        
    self.SizeChanged = function( sender, args )
        --Turbine.Shell.WriteLine( "CheckBox:SizeChanged" );
                self.checkbox:SetSize( -- width,height
                        self.checkbox:GetWidth(),
                        self:GetHeight() );
                self.label:SetSize( -- width,height
                        self:GetWidth() - self.checkbox:GetWidth(), 
                        self:GetHeight() );
    end
        
        -- notification of selection change
        self.SelectionChanged = function( sender, args )
                -- intent is for user to override for notification of change
        end

        --self.SetForeColor = function(self, value)
    --    Turbine.Shell.WriteLine( "CheckBox:SetForeColor " .. tostring(value) );
        --      self.label:SetForeColor(value);
        --end

        self.SetText = function(self, value)
        --Turbine.Shell.WriteLine( string.format("CheckBox:SetText [%s]",tostring(value)));
                self.label:SetText(value);
        end
        
        self.SetFont = function(self, value)
        --Turbine.Shell.WriteLine( "CheckBox:SetFont " .. tostring(value) );
                self.label:SetFont(value);
        end
        
        self.SetFontStyle = function(self, value)
        --Turbine.Shell.WriteLine( "CheckBox:SetFontStyle " .. tostring(value) );
                self.label:SetFontStyle(value);
        end     
        self.SetOutlineColor = function(self, value)
        --Turbine.Shell.WriteLine( "CheckBox:SetOutlineColor " .. tostring(value) );
                self.label:SetOutlineColor(value);
        end     
        self.SetSelectable = function(self, value)
        --Turbine.Shell.WriteLine( "CheckBox:SetSelectable " .. tostring(value) );
                self.checkbox:SetSelectable(value);
        end     
        
end

Compare with Previous | Blame


All times are GMT -5. The time now is 04:32 PM.


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