Moved version 0.11 to SVN

This commit is contained in:
iceroth
2006-07-17 13:47:18 +00:00
parent 80a88cfdb1
commit 772fe5a179
19 changed files with 1839 additions and 0 deletions

148
IceElement.lua Normal file
View File

@ -0,0 +1,148 @@
local AceOO = AceLibrary("AceOO-2.0")
IceElement = AceOO.Class("AceEvent-2.0")
IceElement.virtual = true
IceElement.Alpha = 0.3 -- default alpha for hud elements
-- Private variables --
IceElement.prototype.name = nil
IceElement.prototype.parent = nil
IceElement.prototype.frame = nil
IceElement.prototype.colors = {} -- Shared table for all child classes to save some memory
IceElement.prototype.alpha = nil
-- Constructor --
-- IceElements are to be instantiated before IceCore is loaded.
-- Therefore we can wait for IceCore to load and then register our
-- module to the core with another event.
function IceElement.prototype:init(name)
IceElement.super.prototype.init(self)
assert(name, "IceElement must have a name")
self.name = name
self.alpha = IceElement.Alpha
-- Some common colors
self:SetColor("text", 1, 1, 1)
self:SetColor("undef", 0.7, 0.7, 0.7)
self:RegisterEvent(IceCore.Loaded, "OnCoreLoad")
end
-- 'Public' methods -----------------------------------------------------------
function IceElement.prototype:ToString()
return "IceElement('" .. self.name .. "')"
end
function IceElement.prototype:GetName()
return self.name
end
function IceElement.prototype:Create(parent)
assert(parent, "IceElement 'parent' can't be nil")
self.parent = parent
self:CreateFrame()
end
function IceElement.prototype:Enable()
self.frame:Show()
end
function IceElement.prototype:Disable()
self.frame:Hide()
self:UnregisterAllEvents()
end
-- 'Protected' methods --------------------------------------------------------
-- This should be overwritten by inheriting classes
function IceElement.prototype:CreateFrame()
self.frame = CreateFrame("Frame", nil, self.parent)
end
function IceElement.prototype:GetColor(color, alpha)
if not (color) then
return 1, 1, 1, 1
end
if not (alpha) then
alpha = self.alpha
end
if not (self.colors[color]) then
local r, g, b = self:GetClassColor(color)
return r, g, b, alpha
end
return self.colors[color].r, self.colors[color].g, self.colors[color].b, alpha
end
function IceElement.prototype:GetHexColor(color, alpha)
local r, g, b, a = self:GetColor(color)
return string.format("%02x%02x%02x%02x", a * 255, r * 255, g * 255, b * 255)
end
function IceElement.prototype:SetColor(color, red, green, blue)
if (red > 1) then
red = red / 255
end
if (green > 1) then
green = green / 255
end
if (blue > 1) then
blue = blue / 255
end
self.colors[color] = {r = red, g = green, b = blue}
end
function IceElement.prototype:GetClassColor(class)
class = string.upper(class)
return RAID_CLASS_COLORS[class].r, RAID_CLASS_COLORS[class].g, RAID_CLASS_COLORS[class].b
end
function IceElement.prototype:FontFactory(weight, size, frame)
weight = weight or ""
local fontFile = IceHUD.Location .. "\\fonts\\Calibri" .. weight ..".ttf"
if not (frame) then
frame = self.frame
end
local font = frame:CreateFontString()
font:SetFont(fontFile, size)
font:SetShadowColor(0, 0, 0, 1)
font:SetShadowOffset(1, -1)
return font
end
-- Event Handlers -------------------------------------------------------------
-- Register ourself to the core
function IceElement.prototype:OnCoreLoad()
self:TriggerEvent(IceCore.RegisterModule, self)
end
-- Inherited classes should just instantiate themselves and let
-- superclass to handle registration to the core
-- IceInheritedClass:new()