/trunk/Libs/AceGUI-3.0/widgets
--[[ $Id: AceGUIWidget-DropDown.lua 1029 2011-06-10 23:10:58Z nevcairiel $ ]]-- |
--[[ $Id: AceGUIWidget-DropDown.lua 916 2010-03-15 12:24:36Z nevcairiel $ ]]-- |
local AceGUI = LibStub("AceGUI-3.0") |
-- Lua APIs |
local min, max, floor = math.min, math.max, math.floor |
local select, pairs, ipairs, type = select, pairs, ipairs, type |
local select, pairs, ipairs = select, pairs, ipairs |
local tsort = table.sort |
-- WoW APIs |
do |
local widgetType = "Dropdown" |
local widgetVersion = 25 |
local widgetVersion = 22 |
--[[ Static data ]]-- |
self:SetHeight(44) |
self:SetWidth(200) |
self:SetLabel() |
end |
-- exported, AceGUI callback |
self.pullout = nil |
self:SetText("") |
self:SetLabel("") |
self:SetDisabled(false) |
self:SetMultiselect(false) |
self.label:SetText(text) |
self.label:Show() |
self.dropdown:SetPoint("TOPLEFT",self.frame,"TOPLEFT",-15,-18) |
self:SetHeight(44) |
self.alignoffset = 30 |
self.frame:SetHeight(44) |
else |
self.label:SetText("") |
self.label:Hide() |
self.dropdown:SetPoint("TOPLEFT",self.frame,"TOPLEFT",-15,0) |
self:SetHeight(26) |
self.alignoffset = 12 |
self.frame:SetHeight(26) |
end |
end |
end |
end |
local function AddListItem(self, value, text, itemType) |
if not itemType then itemType = "Dropdown-Item-Toggle" end |
local exists = AceGUI:GetWidgetVersion(itemType) |
if not exists then error(("The given item type, %q, does not exist within AceGUI-3.0"):format(tostring(itemType)), 2) end |
local item = AceGUI:Create(itemType) |
local function AddListItem(self, value, text) |
local item = AceGUI:Create("Dropdown-Item-Toggle") |
item:SetText(text) |
item.userdata.obj = self |
item.userdata.value = value |
-- exported |
local sortlist = {} |
local function SetList(self, list, order, itemType) |
local function SetList(self, list) |
self.list = list |
self.pullout:Clear() |
self.hasClose = nil |
if not list then return end |
if type(order) ~= "table" then |
for v in pairs(list) do |
sortlist[#sortlist + 1] = v |
end |
tsort(sortlist) |
for i, key in ipairs(sortlist) do |
AddListItem(self, key, list[key], itemType) |
sortlist[i] = nil |
end |
else |
for i, key in ipairs(order) do |
AddListItem(self, key, list[key], itemType) |
end |
for v in pairs(list) do |
sortlist[#sortlist + 1] = v |
end |
tsort(sortlist) |
for i, value in pairs(sortlist) do |
AddListItem(self, value, list[value]) |
sortlist[i] = nil |
end |
if self.multiselect then |
ShowMultiText(self) |
AddCloseButton(self) |
end |
-- exported |
local function AddItem(self, value, text, itemType) |
local function AddItem(self, value, text) |
if self.list then |
self.list[value] = text |
AddListItem(self, value, text, itemType) |
AddListItem(self, value, text) |
end |
end |
self.SetItemValue = SetItemValue |
self.SetItemDisabled = SetItemDisabled |
self.alignoffset = 30 |
self.alignoffset = 31 |
frame:SetHeight(44) |
frame:SetWidth(200) |
frame:SetScript("OnHide",Dropdown_OnHide) |
dropdown:ClearAllPoints() |
--[[----------------------------------------------------------------------------- |
EditBox Widget |
-------------------------------------------------------------------------------]] |
local Type, Version = "EditBox", 24 |
local AceGUI = LibStub and LibStub("AceGUI-3.0", true) |
if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end |
local AceGUI = LibStub("AceGUI-3.0") |
-- Lua APIs |
local tostring, pairs = tostring, pairs |
local tostring = tostring |
-- WoW APIs |
local PlaySound = PlaySound |
local GetCursorInfo, ClearCursor, GetSpellInfo = GetCursorInfo, ClearCursor, GetSpellInfo |
local GetCursorInfo, ClearCursor, GetSpellName = GetCursorInfo, ClearCursor, GetSpellName |
local CreateFrame, UIParent = CreateFrame, UIParent |
local _G = _G |
-- List them here for Mikk's FindGlobals script |
-- GLOBALS: AceGUIEditBoxInsertLink, ChatFontNormal, OKAY |
--[[----------------------------------------------------------------------------- |
Support functions |
-------------------------------------------------------------------------------]] |
local Type = "EditBox" |
local Version = 14 |
if not AceGUIEditBoxInsertLink then |
-- upgradeable hook |
hooksecurefunc("ChatEdit_InsertLink", function(...) return _G.AceGUIEditBoxInsertLink(...) end) |
end |
function _G.AceGUIEditBoxInsertLink(text) |
for i = 1, AceGUI:GetWidgetCount(Type) do |
for i = 1, AceGUI:GetNextWidgetNum(Type)-1 do |
local editbox = _G["AceGUI-3.0EditBox"..i] |
if editbox and editbox:IsVisible() and editbox:HasFocus() then |
editbox:Insert(text) |
end |
end |
local function ShowButton(self) |
if not self.disablebutton then |
self.button:Show() |
self.editbox:SetTextInsets(0, 20, 3, 3) |
end |
end |
local function HideButton(self) |
self.button:Hide() |
self.editbox:SetTextInsets(0, 0, 3, 3) |
end |
-------------------------- |
-- Edit box -- |
-------------------------- |
--[[ |
Events : |
OnTextChanged |
OnEnterPressed |
--[[----------------------------------------------------------------------------- |
Scripts |
-------------------------------------------------------------------------------]] |
local function Control_OnEnter(frame) |
frame.obj:Fire("OnEnter") |
end |
local function Control_OnLeave(frame) |
frame.obj:Fire("OnLeave") |
end |
local function Frame_OnShowFocus(frame) |
frame.obj.editbox:SetFocus() |
frame:SetScript("OnShow", nil) |
end |
local function EditBox_OnEscapePressed(frame) |
AceGUI:ClearFocus() |
end |
local function EditBox_OnEnterPressed(frame) |
local self = frame.obj |
local value = frame:GetText() |
local cancel = self:Fire("OnEnterPressed", value) |
if not cancel then |
PlaySound("igMainMenuOptionCheckBoxOn") |
HideButton(self) |
end |
end |
local function EditBox_OnReceiveDrag(frame) |
local self = frame.obj |
local type, id, info = GetCursorInfo() |
if type == "item" then |
self:SetText(info) |
self:Fire("OnEnterPressed", info) |
ClearCursor() |
elseif type == "spell" then |
local name = GetSpellInfo(id, info) |
self:SetText(name) |
self:Fire("OnEnterPressed", name) |
ClearCursor() |
end |
HideButton(self) |
AceGUI:ClearFocus() |
end |
local function EditBox_OnTextChanged(frame) |
local self = frame.obj |
local value = frame:GetText() |
if tostring(value) ~= tostring(self.lasttext) then |
self:Fire("OnTextChanged", value) |
self.lasttext = value |
ShowButton(self) |
end |
end |
local function EditBox_OnFocusGained(frame) |
AceGUI:SetFocus(frame.obj) |
end |
local function Button_OnClick(frame) |
local editbox = frame.obj.editbox |
editbox:ClearFocus() |
EditBox_OnEnterPressed(editbox) |
end |
--[[----------------------------------------------------------------------------- |
Methods |
-------------------------------------------------------------------------------]] |
local methods = { |
["OnAcquire"] = function(self) |
-- height is controlled by SetLabel |
]] |
do |
local function OnAcquire(self) |
self:SetHeight(26) |
self:SetWidth(200) |
self:SetDisabled(false) |
self:SetLabel() |
self.showbutton = true |
end |
local function OnRelease(self) |
self.frame:ClearAllPoints() |
self.frame:Hide() |
self:SetDisabled(false) |
self:SetText() |
self:DisableButton(false) |
self:SetMaxLetters(0) |
end, |
["OnRelease"] = function(self) |
self:ClearFocus() |
end, |
["SetDisabled"] = function(self, disabled) |
end |
local function Control_OnEnter(this) |
this.obj:Fire("OnEnter") |
end |
local function Control_OnLeave(this) |
this.obj:Fire("OnLeave") |
end |
local function EditBox_OnEscapePressed(this) |
this:ClearFocus() |
end |
local function ShowButton(self) |
if self.showbutton then |
self.button:Show() |
self.editbox:SetTextInsets(0,20,3,3) |
end |
end |
local function HideButton(self) |
self.button:Hide() |
self.editbox:SetTextInsets(0,0,3,3) |
end |
local function EditBox_OnEnterPressed(this) |
local self = this.obj |
local value = this:GetText() |
local cancel = self:Fire("OnEnterPressed",value) |
if not cancel then |
PlaySound("igMainMenuOptionCheckBoxOn") |
HideButton(self) |
end |
end |
local function Button_OnClick(this) |
local editbox = this.obj.editbox |
editbox:ClearFocus() |
EditBox_OnEnterPressed(editbox) |
end |
local function EditBox_OnReceiveDrag(this) |
local self = this.obj |
local type, id, info = GetCursorInfo() |
if type == "item" then |
self:SetText(info) |
self:Fire("OnEnterPressed",info) |
ClearCursor() |
elseif type == "spell" then |
local name, rank = GetSpellName(id, info) |
if rank and rank:match("%d") then |
name = name.."("..rank..")" |
end |
self:SetText(name) |
self:Fire("OnEnterPressed",name) |
ClearCursor() |
end |
HideButton(self) |
AceGUI:ClearFocus() |
end |
local function EditBox_OnTextChanged(this) |
local self = this.obj |
local value = this:GetText() |
if tostring(value) ~= tostring(self.lasttext) then |
self:Fire("OnTextChanged",value) |
self.lasttext = value |
ShowButton(self) |
end |
end |
local function SetDisabled(self, disabled) |
self.disabled = disabled |
if disabled then |
self.editbox:EnableMouse(false) |
self.editbox:SetTextColor(1,1,1) |
self.label:SetTextColor(1,.82,0) |
end |
end, |
["SetText"] = function(self, text) |
end |
local function SetText(self, text) |
self.lasttext = text or "" |
self.editbox:SetText(text or "") |
self.editbox:SetCursorPosition(0) |
HideButton(self) |
end, |
["GetText"] = function(self, text) |
return self.editbox:GetText() |
end, |
["SetLabel"] = function(self, text) |
end |
local function SetLabel(self, text) |
if text and text ~= "" then |
self.label:SetText(text) |
self.label:Show() |
self:SetHeight(26) |
self.alignoffset = 12 |
end |
end, |
["DisableButton"] = function(self, disabled) |
self.disablebutton = disabled |
if disabled then |
HideButton(self) |
end |
end, |
["SetMaxLetters"] = function (self, num) |
self.editbox:SetMaxLetters(num or 0) |
end, |
["ClearFocus"] = function(self) |
self.editbox:ClearFocus() |
self.frame:SetScript("OnShow", nil) |
end, |
["SetFocus"] = function(self) |
self.editbox:SetFocus() |
if not self.frame:IsShown() then |
self.frame:SetScript("OnShow", Frame_OnShowFocus) |
end |
end |
} |
--[[----------------------------------------------------------------------------- |
Constructor |
-------------------------------------------------------------------------------]] |
local function Constructor() |
local num = AceGUI:GetNextWidgetNum(Type) |
local frame = CreateFrame("Frame", nil, UIParent) |
frame:Hide() |
local function Constructor() |
local num = AceGUI:GetNextWidgetNum(Type) |
local frame = CreateFrame("Frame",nil,UIParent) |
local editbox = CreateFrame("EditBox","AceGUI-3.0EditBox"..num,frame,"InputBoxTemplate") |
local self = {} |
self.type = Type |
self.num = num |
local editbox = CreateFrame("EditBox", "AceGUI-3.0EditBox"..num, frame, "InputBoxTemplate") |
editbox:SetAutoFocus(false) |
editbox:SetFontObject(ChatFontNormal) |
editbox:SetScript("OnEnter", Control_OnEnter) |
editbox:SetScript("OnLeave", Control_OnLeave) |
editbox:SetScript("OnEscapePressed", EditBox_OnEscapePressed) |
editbox:SetScript("OnEnterPressed", EditBox_OnEnterPressed) |
editbox:SetScript("OnTextChanged", EditBox_OnTextChanged) |
editbox:SetScript("OnReceiveDrag", EditBox_OnReceiveDrag) |
editbox:SetScript("OnMouseDown", EditBox_OnReceiveDrag) |
editbox:SetScript("OnEditFocusGained", EditBox_OnFocusGained) |
editbox:SetTextInsets(0, 0, 3, 3) |
editbox:SetMaxLetters(256) |
editbox:SetPoint("BOTTOMLEFT", 6, 0) |
editbox:SetPoint("BOTTOMRIGHT") |
editbox:SetHeight(19) |
self.OnRelease = OnRelease |
self.OnAcquire = OnAcquire |
local label = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall") |
label:SetPoint("TOPLEFT", 0, -2) |
label:SetPoint("TOPRIGHT", 0, -2) |
label:SetJustifyH("LEFT") |
label:SetHeight(18) |
self.SetDisabled = SetDisabled |
self.SetText = SetText |
self.SetLabel = SetLabel |
self.frame = frame |
frame.obj = self |
self.editbox = editbox |
editbox.obj = self |
self.alignoffset = 30 |
frame:SetHeight(44) |
frame:SetWidth(200) |
local button = CreateFrame("Button", nil, editbox, "UIPanelButtonTemplate") |
button:SetWidth(40) |
button:SetHeight(20) |
button:SetPoint("RIGHT", -2, 0) |
button:SetText(OKAY) |
button:SetScript("OnClick", Button_OnClick) |
button:Hide() |
editbox:SetScript("OnEnter",Control_OnEnter) |
editbox:SetScript("OnLeave",Control_OnLeave) |
editbox:SetAutoFocus(false) |
editbox:SetFontObject(ChatFontNormal) |
editbox:SetScript("OnEscapePressed",EditBox_OnEscapePressed) |
editbox:SetScript("OnEnterPressed",EditBox_OnEnterPressed) |
editbox:SetScript("OnTextChanged",EditBox_OnTextChanged) |
editbox:SetScript("OnReceiveDrag", EditBox_OnReceiveDrag) |
editbox:SetScript("OnMouseDown", EditBox_OnReceiveDrag) |
local widget = { |
alignoffset = 30, |
editbox = editbox, |
label = label, |
button = button, |
frame = frame, |
type = Type |
} |
for method, func in pairs(methods) do |
widget[method] = func |
end |
editbox.obj, button.obj = widget, widget |
editbox:SetTextInsets(0,0,3,3) |
editbox:SetMaxLetters(256) |
editbox:SetPoint("BOTTOMLEFT",frame,"BOTTOMLEFT",6,0) |
editbox:SetPoint("BOTTOMRIGHT",frame,"BOTTOMRIGHT",0,0) |
editbox:SetHeight(19) |
local label = frame:CreateFontString(nil,"OVERLAY","GameFontNormalSmall") |
label:SetPoint("TOPLEFT",frame,"TOPLEFT",0,-2) |
label:SetPoint("TOPRIGHT",frame,"TOPRIGHT",0,-2) |
label:SetJustifyH("LEFT") |
label:SetHeight(18) |
self.label = label |
local button = CreateFrame("Button",nil,editbox,"UIPanelButtonTemplate") |
button:SetWidth(40) |
button:SetHeight(20) |
button:SetPoint("RIGHT",editbox,"RIGHT",-2,0) |
button:SetText(OKAY) |
button:SetScript("OnClick", Button_OnClick) |
button:Hide() |
self.button = button |
button.obj = self |
return AceGUI:RegisterAsWidget(widget) |
AceGUI:RegisterAsWidget(self) |
return self |
end |
AceGUI:RegisterWidgetType(Type,Constructor,Version) |
end |
AceGUI:RegisterWidgetType(Type, Constructor, Version) |
--[[----------------------------------------------------------------------------- |
Heading Widget |
-------------------------------------------------------------------------------]] |
local Type, Version = "Heading", 20 |
local AceGUI = LibStub and LibStub("AceGUI-3.0", true) |
if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end |
local AceGUI = LibStub("AceGUI-3.0") |
-- Lua APIs |
local pairs = pairs |
-- WoW APIs |
local CreateFrame, UIParent = CreateFrame, UIParent |
--[[----------------------------------------------------------------------------- |
Methods |
-------------------------------------------------------------------------------]] |
local methods = { |
["OnAcquire"] = function(self) |
self:SetText() |
-------------------------- |
-- Heading -- |
-------------------------- |
do |
local Type = "Heading" |
local Version = 5 |
local function OnAcquire(self) |
self:SetText("") |
self:SetFullWidth() |
self:SetHeight(18) |
end, |
-- ["OnRelease"] = nil, |
["SetText"] = function(self, text) |
end |
local function OnRelease(self) |
self.frame:ClearAllPoints() |
self.frame:Hide() |
end |
local function SetText(self, text) |
self.label:SetText(text or "") |
if text and text ~= "" then |
self.left:SetPoint("RIGHT", self.label, "LEFT", -5, 0) |
self.right:Show() |
else |
self.left:SetPoint("RIGHT", -3, 0) |
if (text or "") == "" then |
self.left:SetPoint("RIGHT",self.frame,"RIGHT",-3,0) |
self.right:Hide() |
else |
self.left:SetPoint("RIGHT",self.label,"LEFT",-5,0) |
self.right:Show() |
end |
end |
} |
--[[----------------------------------------------------------------------------- |
Constructor |
-------------------------------------------------------------------------------]] |
local function Constructor() |
local frame = CreateFrame("Frame", nil, UIParent) |
frame:Hide() |
local function Constructor() |
local frame = CreateFrame("Frame",nil,UIParent) |
local self = {} |
self.type = Type |
self.OnRelease = OnRelease |
self.OnAcquire = OnAcquire |
self.SetText = SetText |
self.frame = frame |
frame.obj = self |
frame:SetHeight(18) |
local label = frame:CreateFontString(nil,"BACKGROUND","GameFontNormal") |
label:SetPoint("TOP",frame,"TOP",0,0) |
label:SetPoint("BOTTOM",frame,"BOTTOM",0,0) |
label:SetJustifyH("CENTER") |
label:SetHeight(18) |
self.label = label |
local left = frame:CreateTexture(nil, "BACKGROUND") |
self.left = left |
left:SetHeight(8) |
left:SetPoint("LEFT",frame,"LEFT",3,0) |
left:SetPoint("RIGHT",label,"LEFT",-5,0) |
left:SetTexture("Interface\\Tooltips\\UI-Tooltip-Border") |
left:SetTexCoord(0.81, 0.94, 0.5, 1) |
local label = frame:CreateFontString(nil, "BACKGROUND", "GameFontNormal") |
label:SetPoint("TOP") |
label:SetPoint("BOTTOM") |
label:SetJustifyH("CENTER") |
local left = frame:CreateTexture(nil, "BACKGROUND") |
left:SetHeight(8) |
left:SetPoint("LEFT", 3, 0) |
left:SetPoint("RIGHT", label, "LEFT", -5, 0) |
left:SetTexture("Interface\\Tooltips\\UI-Tooltip-Border") |
left:SetTexCoord(0.81, 0.94, 0.5, 1) |
local right = frame:CreateTexture(nil, "BACKGROUND") |
right:SetHeight(8) |
right:SetPoint("RIGHT", -3, 0) |
right:SetPoint("LEFT", label, "RIGHT", 5, 0) |
right:SetTexture("Interface\\Tooltips\\UI-Tooltip-Border") |
right:SetTexCoord(0.81, 0.94, 0.5, 1) |
local widget = { |
label = label, |
left = left, |
right = right, |
frame = frame, |
type = Type |
} |
for method, func in pairs(methods) do |
widget[method] = func |
local right = frame:CreateTexture(nil, "BACKGROUND") |
self.right = right |
right:SetHeight(8) |
right:SetPoint("RIGHT",frame,"RIGHT",-3,0) |
right:SetPoint("LEFT",label,"RIGHT",5,0) |
right:SetTexture("Interface\\Tooltips\\UI-Tooltip-Border") |
right:SetTexCoord(0.81, 0.94, 0.5, 1) |
AceGUI:RegisterAsWidget(self) |
return self |
end |
return AceGUI:RegisterAsWidget(widget) |
AceGUI:RegisterWidgetType(Type,Constructor,Version) |
end |
AceGUI:RegisterWidgetType(Type, Constructor, Version) |
--[[ $Id: AceGUIWidget-DropDown-Items.lua 996 2010-12-01 18:34:17Z nevcairiel $ ]]-- |
--[[ $Id: AceGUIWidget-DropDown-Items.lua 916 2010-03-15 12:24:36Z nevcairiel $ ]]-- |
local AceGUI = LibStub("AceGUI-3.0") |
return self |
end |
-- Register a dummy LibStub library to retrieve the ItemBase, so other addons can use it. |
local IBLib = LibStub:NewLibrary("AceGUI-3.0-DropDown-ItemBase", ItemBase.version) |
if IBLib then |
IBLib.GetItemBase = function() return ItemBase end |
end |
--[[ |
Template for items: |
--[[----------------------------------------------------------------------------- |
Button Widget |
Graphical Button. |
-------------------------------------------------------------------------------]] |
local Type, Version = "Button", 22 |
local AceGUI = LibStub and LibStub("AceGUI-3.0", true) |
if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end |
local AceGUI = LibStub("AceGUI-3.0") |
-- Lua APIs |
local pairs = pairs |
-- WoW APIs |
local _G = _G |
local PlaySound, CreateFrame, UIParent = PlaySound, CreateFrame, UIParent |
local PlaySound = PlaySound |
local CreateFrame, UIParent = CreateFrame, UIParent |
local wowMoP |
-------------------------- |
-- Button -- |
-------------------------- |
do |
local _, _, _, interface = GetBuildInfo() |
wowMoP = (interface >= 50000) |
end |
--[[----------------------------------------------------------------------------- |
Scripts |
-------------------------------------------------------------------------------]] |
local function Button_OnClick(frame, ...) |
AceGUI:ClearFocus() |
PlaySound("igMainMenuOption") |
frame.obj:Fire("OnClick", ...) |
end |
local function Control_OnEnter(frame) |
frame.obj:Fire("OnEnter") |
end |
local function Control_OnLeave(frame) |
frame.obj:Fire("OnLeave") |
end |
--[[----------------------------------------------------------------------------- |
Methods |
-------------------------------------------------------------------------------]] |
local methods = { |
["OnAcquire"] = function(self) |
local Type = "Button" |
local Version = 13 |
local function OnAcquire(self) |
-- restore default values |
self:SetHeight(24) |
self:SetWidth(200) |
end |
local function OnRelease(self) |
self.frame:ClearAllPoints() |
self.frame:Hide() |
self:SetDisabled(false) |
self:SetText() |
end, |
-- ["OnRelease"] = nil, |
["SetText"] = function(self, text) |
self.text:SetText(text) |
end, |
["SetDisabled"] = function(self, disabled) |
end |
local function Button_OnClick(this, ...) |
PlaySound("igMainMenuOption") |
this.obj:Fire("OnClick", ...) |
AceGUI:ClearFocus() |
end |
local function Button_OnEnter(this) |
this.obj:Fire("OnEnter") |
end |
local function Button_OnLeave(this) |
this.obj:Fire("OnLeave") |
end |
local function SetText(self, text) |
self.text:SetText(text or "") |
end |
local function SetDisabled(self, disabled) |
self.disabled = disabled |
if disabled then |
self.frame:Disable() |
self.frame:Enable() |
end |
end |
} |
local function Constructor() |
local num = AceGUI:GetNextWidgetNum(Type) |
local name = "AceGUI30Button"..num |
local frame = CreateFrame("Button",name,UIParent,"UIPanelButtonTemplate2") |
local self = {} |
self.num = num |
self.type = Type |
self.frame = frame |
local left = _G[name .. "Left"] |
local right = _G[name .. "Right"] |
local middle = _G[name .. "Middle"] |
left:SetPoint("TOP", frame, "TOP", 0, 0) |
left:SetPoint("BOTTOM", frame, "BOTTOM", 0, 0) |
right:SetPoint("TOP", frame, "TOP", 0, 0) |
right:SetPoint("BOTTOM", frame, "BOTTOM", 0, 0) |
middle:SetPoint("TOP", frame, "TOP", 0, 0) |
middle:SetPoint("BOTTOM", frame, "BOTTOM", 0, 0) |
--[[----------------------------------------------------------------------------- |
Constructor |
-------------------------------------------------------------------------------]] |
local function Constructor() |
local name = "AceGUI30Button" .. AceGUI:GetNextWidgetNum(Type) |
local frame = CreateFrame("Button", name, UIParent, wowMoP and "UIPanelButtonTemplate" or "UIPanelButtonTemplate2") |
frame:Hide() |
local text = frame:GetFontString() |
self.text = text |
text:ClearAllPoints() |
text:SetPoint("TOPLEFT",frame,"TOPLEFT", 15, -1) |
text:SetPoint("BOTTOMRIGHT",frame,"BOTTOMRIGHT", -15, 1) |
text:SetJustifyV("MIDDLE") |
frame:EnableMouse(true) |
frame:SetScript("OnClick", Button_OnClick) |
frame:SetScript("OnEnter", Control_OnEnter) |
frame:SetScript("OnLeave", Control_OnLeave) |
frame:SetScript("OnClick",Button_OnClick) |
frame:SetScript("OnEnter",Button_OnEnter) |
frame:SetScript("OnLeave",Button_OnLeave) |
local text = frame:GetFontString() |
text:ClearAllPoints() |
text:SetPoint("TOPLEFT", 15, -1) |
text:SetPoint("BOTTOMRIGHT", -15, 1) |
text:SetJustifyV("MIDDLE") |
self.SetText = SetText |
self.SetDisabled = SetDisabled |
frame:EnableMouse(true) |
local widget = { |
text = text, |
frame = frame, |
type = Type |
} |
for method, func in pairs(methods) do |
widget[method] = func |
frame:SetHeight(24) |
frame:SetWidth(200) |
self.OnRelease = OnRelease |
self.OnAcquire = OnAcquire |
self.frame = frame |
frame.obj = self |
AceGUI:RegisterAsWidget(self) |
return self |
end |
return AceGUI:RegisterAsWidget(widget) |
AceGUI:RegisterWidgetType(Type,Constructor,Version) |
end |
AceGUI:RegisterWidgetType(Type, Constructor, Version) |
--[[----------------------------------------------------------------------------- |
ColorPicker Widget |
-------------------------------------------------------------------------------]] |
local Type, Version = "ColorPicker", 21 |
local AceGUI = LibStub and LibStub("AceGUI-3.0", true) |
if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end |
local AceGUI = LibStub("AceGUI-3.0") |
-- Lua APIs |
local pairs = pairs |
-- WoW APIs |
local CreateFrame, UIParent = CreateFrame, UIParent |
-- List them here for Mikk's FindGlobals script |
-- GLOBALS: ShowUIPanel, HideUIPanel, ColorPickerFrame, OpacitySliderFrame |
--[[----------------------------------------------------------------------------- |
Support functions |
-------------------------------------------------------------------------------]] |
local function ColorCallback(self, r, g, b, a, isAlpha) |
if not self.HasAlpha then |
a = 1 |
-------------------------- |
-- ColorPicker -- |
-------------------------- |
do |
local Type = "ColorPicker" |
local Version = 11 |
local function OnAcquire(self) |
self.HasAlpha = false |
self:SetColor(0,0,0,1) |
self:SetHeight(24) |
self:SetWidth(200) |
end |
self:SetColor(r, g, b, a) |
if ColorPickerFrame:IsVisible() then |
--colorpicker is still open |
self:Fire("OnValueChanged", r, g, b, a) |
else |
--colorpicker is closed, color callback is first, ignore it, |
--alpha callback is the final call after it closes so confirm now |
if isAlpha then |
self:Fire("OnValueConfirmed", r, g, b, a) |
end |
local function SetLabel(self, text) |
self.text:SetText(text) |
end |
end |
--[[----------------------------------------------------------------------------- |
Scripts |
-------------------------------------------------------------------------------]] |
local function Control_OnEnter(frame) |
frame.obj:Fire("OnEnter") |
end |
local function SetColor(self,r,g,b,a) |
self.r = r |
self.g = g |
self.b = b |
self.a = a or 1 |
self.colorSwatch:SetVertexColor(r,g,b,a) |
end |
local function Control_OnLeave(frame) |
frame.obj:Fire("OnLeave") |
end |
local function Control_OnEnter(this) |
this.obj:Fire("OnEnter") |
end |
local function ColorSwatch_OnClick(frame) |
HideUIPanel(ColorPickerFrame) |
local self = frame.obj |
if not self.disabled then |
ColorPickerFrame:SetFrameStrata("FULLSCREEN_DIALOG") |
ColorPickerFrame:SetClampedToScreen(true) |
local function Control_OnLeave(this) |
this.obj:Fire("OnLeave") |
end |
local function SetHasAlpha(self, HasAlpha) |
self.HasAlpha = HasAlpha |
end |
ColorPickerFrame.func = function() |
local r, g, b = ColorPickerFrame:GetColorRGB() |
local a = 1 - OpacitySliderFrame:GetValue() |
ColorCallback(self, r, g, b, a) |
local function ColorCallback(self,r,g,b,a,isAlpha) |
if not self.HasAlpha then |
a = 1 |
end |
self:SetColor(r,g,b,a) |
if ColorPickerFrame:IsVisible() then |
--colorpicker is still open |
ColorPickerFrame.hasOpacity = self.HasAlpha |
ColorPickerFrame.opacityFunc = function() |
local r, g, b = ColorPickerFrame:GetColorRGB() |
local a = 1 - OpacitySliderFrame:GetValue() |
ColorCallback(self, r, g, b, a, true) |
self:Fire("OnValueChanged",r,g,b,a) |
else |
--colorpicker is closed, color callback is first, ignore it, |
--alpha callback is the final call after it closes so confirm now |
if isAlpha then |
self:Fire("OnValueConfirmed",r,g,b,a) |
end |
end |
local r, g, b, a = self.r, self.g, self.b, self.a |
if self.HasAlpha then |
ColorPickerFrame.opacity = 1 - (a or 0) |
end |
local function ColorSwatch_OnClick(this) |
HideUIPanel(ColorPickerFrame) |
local self = this.obj |
if not self.disabled then |
ColorPickerFrame:SetFrameStrata("FULLSCREEN_DIALOG") |
ColorPickerFrame.func = function() |
local r,g,b = ColorPickerFrame:GetColorRGB() |
local a = 1 - OpacitySliderFrame:GetValue() |
ColorCallback(self,r,g,b,a) |
end |
ColorPickerFrame.hasOpacity = self.HasAlpha |
ColorPickerFrame.opacityFunc = function() |
local r,g,b = ColorPickerFrame:GetColorRGB() |
local a = 1 - OpacitySliderFrame:GetValue() |
ColorCallback(self,r,g,b,a,true) |
end |
local r, g, b, a = self.r, self.g, self.b, self.a |
if self.HasAlpha then |
ColorPickerFrame.opacity = 1 - (a or 0) |
end |
ColorPickerFrame:SetColorRGB(r, g, b) |
ColorPickerFrame.cancelFunc = function() |
ColorCallback(self,r,g,b,a,true) |
end |
ShowUIPanel(ColorPickerFrame) |
end |
ColorPickerFrame:SetColorRGB(r, g, b) |
AceGUI:ClearFocus() |
end |
ColorPickerFrame.cancelFunc = function() |
ColorCallback(self, r, g, b, a, true) |
end |
ShowUIPanel(ColorPickerFrame) |
local function OnRelease(self) |
self.frame:ClearAllPoints() |
self.frame:Hide() |
end |
AceGUI:ClearFocus() |
end |
--[[----------------------------------------------------------------------------- |
Methods |
-------------------------------------------------------------------------------]] |
local methods = { |
["OnAcquire"] = function(self) |
self:SetHeight(24) |
self:SetWidth(200) |
self:SetHasAlpha(false) |
self:SetColor(0, 0, 0, 1) |
self:SetDisabled(nil) |
self:SetLabel(nil) |
end, |
-- ["OnRelease"] = nil, |
["SetLabel"] = function(self, text) |
self.text:SetText(text) |
end, |
["SetColor"] = function(self, r, g, b, a) |
self.r = r |
self.g = g |
self.b = b |
self.a = a or 1 |
self.colorSwatch:SetVertexColor(r, g, b, a) |
end, |
["SetHasAlpha"] = function(self, HasAlpha) |
self.HasAlpha = HasAlpha |
end, |
["SetDisabled"] = function(self, disabled) |
local function SetDisabled(self, disabled) |
self.disabled = disabled |
if self.disabled then |
self.frame:Disable() |
self.text:SetTextColor(0.5, 0.5, 0.5) |
self.text:SetTextColor(0.5,0.5,0.5) |
else |
self.frame:Enable() |
self.text:SetTextColor(1, 1, 1) |
self.text:SetTextColor(1,1,1) |
end |
end |
} |
--[[----------------------------------------------------------------------------- |
Constructor |
-------------------------------------------------------------------------------]] |
local function Constructor() |
local frame = CreateFrame("Button", nil, UIParent) |
frame:Hide() |
local function Constructor() |
local frame = CreateFrame("Button",nil,UIParent) |
local self = {} |
self.type = Type |
frame:EnableMouse(true) |
frame:SetScript("OnEnter", Control_OnEnter) |
frame:SetScript("OnLeave", Control_OnLeave) |
frame:SetScript("OnClick", ColorSwatch_OnClick) |
self.OnRelease = OnRelease |
self.OnAcquire = OnAcquire |
self.SetLabel = SetLabel |
self.SetColor = SetColor |
self.SetDisabled = SetDisabled |
self.SetHasAlpha = SetHasAlpha |
self.frame = frame |
frame.obj = self |
local text = frame:CreateFontString(nil,"OVERLAY","GameFontHighlight") |
self.text = text |
text:SetJustifyH("LEFT") |
text:SetTextColor(1,1,1) |
frame:SetHeight(24) |
frame:SetWidth(200) |
text:SetHeight(24) |
frame:SetScript("OnClick", ColorSwatch_OnClick) |
frame:SetScript("OnEnter",Control_OnEnter) |
frame:SetScript("OnLeave",Control_OnLeave) |
local colorSwatch = frame:CreateTexture(nil, "OVERLAY") |
self.colorSwatch = colorSwatch |
colorSwatch:SetWidth(19) |
colorSwatch:SetHeight(19) |
colorSwatch:SetTexture("Interface\\ChatFrame\\ChatFrameColorSwatch") |
local texture = frame:CreateTexture(nil, "BACKGROUND") |
colorSwatch.texture = texture |
texture:SetWidth(16) |
texture:SetHeight(16) |
texture:SetTexture(1,1,1) |
texture:Show() |
local checkers = frame:CreateTexture(nil, "BACKGROUND") |
colorSwatch.checkers = checkers |
checkers:SetTexture("Tileset\\Generic\\Checkers") |
checkers:SetDesaturated(true) |
checkers:SetVertexColor(1,1,1,0.75) |
checkers:SetTexCoord(.25,0,0.5,.25) |
checkers:SetWidth(14) |
checkers:SetHeight(14) |
checkers:Show() |
local highlight = frame:CreateTexture(nil, "BACKGROUND") |
self.highlight = highlight |
highlight:SetTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight") |
highlight:SetBlendMode("ADD") |
highlight:SetAllPoints(frame) |
highlight:Hide() |
texture:SetPoint("CENTER", colorSwatch, "CENTER") |
checkers:SetPoint("CENTER", colorSwatch, "CENTER") |
colorSwatch:SetPoint("LEFT", frame, "LEFT", 0, 0) |
text:SetPoint("LEFT",colorSwatch,"RIGHT",2,0) |
text:SetPoint("RIGHT",frame,"RIGHT") |
local colorSwatch = frame:CreateTexture(nil, "OVERLAY") |
colorSwatch:SetWidth(19) |
colorSwatch:SetHeight(19) |
colorSwatch:SetTexture("Interface\\ChatFrame\\ChatFrameColorSwatch") |
colorSwatch:SetPoint("LEFT") |
local texture = frame:CreateTexture(nil, "BACKGROUND") |
texture:SetWidth(16) |
texture:SetHeight(16) |
texture:SetTexture(1, 1, 1) |
texture:SetPoint("CENTER", colorSwatch) |
texture:Show() |
local checkers = frame:CreateTexture(nil, "BACKGROUND") |
checkers:SetWidth(14) |
checkers:SetHeight(14) |
checkers:SetTexture("Tileset\\Generic\\Checkers") |
checkers:SetTexCoord(.25, 0, 0.5, .25) |
checkers:SetDesaturated(true) |
checkers:SetVertexColor(1, 1, 1, 0.75) |
checkers:SetPoint("CENTER", colorSwatch) |
checkers:Show() |
local text = frame:CreateFontString(nil,"OVERLAY","GameFontHighlight") |
text:SetHeight(24) |
text:SetJustifyH("LEFT") |
text:SetTextColor(1, 1, 1) |
text:SetPoint("LEFT", colorSwatch, "RIGHT", 2, 0) |
text:SetPoint("RIGHT") |
--local highlight = frame:CreateTexture(nil, "HIGHLIGHT") |
--highlight:SetTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight") |
--highlight:SetBlendMode("ADD") |
--highlight:SetAllPoints(frame) |
local widget = { |
colorSwatch = colorSwatch, |
text = text, |
frame = frame, |
type = Type |
} |
for method, func in pairs(methods) do |
widget[method] = func |
AceGUI:RegisterAsWidget(self) |
return self |
end |
return AceGUI:RegisterAsWidget(widget) |
AceGUI:RegisterWidgetType(Type,Constructor,Version) |
end |
AceGUI:RegisterWidgetType(Type, Constructor, Version) |
--[[----------------------------------------------------------------------------- |
InteractiveLabel Widget |
-------------------------------------------------------------------------------]] |
local Type, Version = "InteractiveLabel", 20 |
local AceGUI = LibStub and LibStub("AceGUI-3.0", true) |
if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end |
local AceGUI = LibStub("AceGUI-3.0") |
-- Lua APIs |
local select, pairs = select, pairs |
local select, max = select, math.max |
-- WoW APIs |
local CreateFrame, UIParent = CreateFrame, UIParent |
-- List them here for Mikk's FindGlobals script |
-- GLOBALS: GameFontHighlightSmall |
--[[----------------------------------------------------------------------------- |
Scripts |
-------------------------------------------------------------------------------]] |
local function Control_OnEnter(frame) |
frame.obj:Fire("OnEnter") |
end |
local function Control_OnLeave(frame) |
frame.obj:Fire("OnLeave") |
end |
local function Label_OnClick(frame, button) |
frame.obj:Fire("OnClick", button) |
AceGUI:ClearFocus() |
end |
--[[----------------------------------------------------------------------------- |
Methods |
-------------------------------------------------------------------------------]] |
local methods = { |
["OnAcquire"] = function(self) |
self:LabelOnAcquire() |
-------------------------- |
-- Label -- |
-------------------------- |
do |
local Type = "InteractiveLabel" |
local Version = 6 |
local function OnAcquire(self) |
self:SetHeight(18) |
self:SetWidth(200) |
self:SetText("") |
self:SetImage(nil) |
self:SetColor() |
self:SetFontObject() |
self:SetHighlight() |
self:SetHighlightTexCoord() |
end |
local function OnRelease(self) |
self:SetDisabled(false) |
end, |
-- ["OnRelease"] = nil, |
["SetHighlight"] = function(self, ...) |
self.frame:ClearAllPoints() |
self.frame:Hide() |
end |
local function UpdateImageAnchor(self) |
local width = self.frame.width or self.frame:GetWidth() or 0 |
local image = self.image |
local label = self.label |
local frame = self.frame |
local height |
label:ClearAllPoints() |
image:ClearAllPoints() |
if self.imageshown then |
local imagewidth = image:GetWidth() |
if (width - imagewidth) < 200 or (label:GetText() or "") == "" then |
--image goes on top centered when less than 200 width for the text, or if there is no text |
image:SetPoint("TOP",frame,"TOP",0,0) |
label:SetPoint("TOP",image,"BOTTOM",0,0) |
label:SetPoint("LEFT",frame,"LEFT",0,0) |
label:SetWidth(width) |
height = image:GetHeight() + label:GetHeight() |
else |
--image on the left |
local imageheight = image:GetHeight() |
local labelheight = label:GetHeight() |
--center image with label |
if imageheight > labelheight then |
image:SetPoint("TOPLEFT",frame,"TOPLEFT",0,0) |
label:SetPoint("LEFT",image,"RIGHT",0,0) |
else |
label:SetPoint("TOPLEFT",frame,"TOPLEFT",imagewidth,0) |
image:SetPoint("RIGHT",label,"LEFT",0,0) |
end |
label:SetWidth(width - imagewidth) |
height = max(imageheight, labelheight) |
end |
else |
--no image shown |
label:SetPoint("TOPLEFT",frame,"TOPLEFT",0,0) |
label:SetWidth(width) |
height = self.label:GetHeight() |
end |
self.resizing = true |
self.frame:SetHeight(height) |
self.frame.height = height |
self.resizing = nil |
end |
local function SetText(self, text) |
self.label:SetText(text or "") |
UpdateImageAnchor(self) |
end |
local function SetColor(self, r, g, b) |
if not (r and g and b) then |
r, g, b = 1, 1, 1 |
end |
self.label:SetVertexColor(r, g, b) |
end |
local function OnWidthSet(self, width) |
if self.resizing then return end |
UpdateImageAnchor(self) |
end |
local function SetImage(self, path, ...) |
local image = self.image |
image:SetTexture(path) |
if image:GetTexture() then |
self.imageshown = true |
local n = select('#', ...) |
if n == 4 or n == 8 then |
image:SetTexCoord(...) |
end |
else |
self.imageshown = nil |
end |
UpdateImageAnchor(self) |
end |
local function SetFont(self, font, height, flags) |
self.label:SetFont(font, height, flags) |
end |
local function SetFontObject(self, font) |
self.label:SetFontObject(font or GameFontHighlightSmall) |
end |
local function SetImageSize(self, width, height) |
self.image:SetWidth(width) |
self.image:SetHeight(height) |
UpdateImageAnchor(self) |
end |
local function SetHighlight(self, ...) |
self.highlight:SetTexture(...) |
end, |
["SetHighlightTexCoord"] = function(self, ...) |
local c = select("#", ...) |
if c == 4 or c == 8 then |
end |
local function SetHighlightTexCoord(self, ...) |
if select('#', ...) >= 1 then |
self.highlight:SetTexCoord(...) |
else |
self.highlight:SetTexCoord(0, 1, 0, 1) |
end |
end, |
["SetDisabled"] = function(self,disabled) |
end |
local function SetDisabled(self,disabled) |
self.disabled = disabled |
if disabled then |
self.frame:EnableMouse(false) |
self.label:SetTextColor(1, 1, 1) |
end |
end |
} |
local function OnEnter(this) |
this.obj.highlight:Show() |
this.obj:Fire("OnEnter") |
end |
local function OnLeave(this) |
this.obj.highlight:Hide() |
this.obj:Fire("OnLeave") |
end |
local function OnClick(this, ...) |
this.obj:Fire("OnClick", ...) |
AceGUI:ClearFocus() |
end |
--[[----------------------------------------------------------------------------- |
Constructor |
-------------------------------------------------------------------------------]] |
local function Constructor() |
-- create a Label type that we will hijack |
local label = AceGUI:Create("Label") |
local frame = label.frame |
frame:EnableMouse(true) |
frame:SetScript("OnEnter", Control_OnEnter) |
frame:SetScript("OnLeave", Control_OnLeave) |
frame:SetScript("OnMouseDown", Label_OnClick) |
local highlight = frame:CreateTexture(nil, "HIGHLIGHT") |
highlight:SetTexture(nil) |
highlight:SetAllPoints() |
highlight:SetBlendMode("ADD") |
label.highlight = highlight |
label.type = Type |
label.LabelOnAcquire = label.OnAcquire |
for method, func in pairs(methods) do |
label[method] = func |
local function Constructor() |
local frame = CreateFrame("Frame",nil,UIParent) |
local self = {} |
self.type = Type |
frame:EnableMouse(true) |
frame:SetScript("OnEnter", OnEnter) |
frame:SetScript("OnLeave", OnLeave) |
frame:SetScript("OnMouseDown", OnClick) |
self.OnRelease = OnRelease |
self.OnAcquire = OnAcquire |
self.SetText = SetText |
self.SetColor = SetColor |
self.frame = frame |
self.OnWidthSet = OnWidthSet |
self.SetImage = SetImage |
self.SetImageSize = SetImageSize |
self.SetFont = SetFont |
self.SetFontObject = SetFontObject |
self.SetHighlight = SetHighlight |
self.SetHighlightTexCoord = SetHighlightTexCoord |
self.SetDisabled = SetDisabled |
frame.obj = self |
frame:SetHeight(18) |
frame:SetWidth(200) |
local label = frame:CreateFontString(nil,"BACKGROUND","GameFontHighlightSmall") |
label:SetPoint("TOPLEFT",frame,"TOPLEFT",0,0) |
label:SetWidth(200) |
label:SetJustifyH("LEFT") |
label:SetJustifyV("TOP") |
self.label = label |
local highlight = frame:CreateTexture(nil, "OVERLAY") |
highlight:SetTexture(nil) |
highlight:SetAllPoints() |
highlight:SetBlendMode("ADD") |
highlight:Hide() |
self.highlight = highlight |
local image = frame:CreateTexture(nil,"BACKGROUND") |
self.image = image |
AceGUI:RegisterAsWidget(self) |
return self |
end |
return label |
AceGUI:RegisterWidgetType(Type,Constructor,Version) |
end |
AceGUI:RegisterWidgetType(Type, Constructor, Version) |
--[[----------------------------------------------------------------------------- |
Label Widget |
Displays text and optionally an icon. |
-------------------------------------------------------------------------------]] |
local Type, Version = "Label", 23 |
local AceGUI = LibStub and LibStub("AceGUI-3.0", true) |
if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end |
local AceGUI = LibStub("AceGUI-3.0") |
-- Lua APIs |
local max, select, pairs = math.max, select, pairs |
local max, select = math.max, select |
-- WoW APIs |
local CreateFrame, UIParent = CreateFrame, UIParent |
-- List them here for Mikk's FindGlobals script |
-- GLOBALS: GameFontHighlightSmall |
--[[----------------------------------------------------------------------------- |
Support functions |
-------------------------------------------------------------------------------]] |
local function UpdateImageAnchor(self) |
if self.resizing then return end |
local frame = self.frame |
local width = frame.width or frame:GetWidth() or 0 |
local image = self.image |
local label = self.label |
local height |
label:ClearAllPoints() |
image:ClearAllPoints() |
if self.imageshown then |
local imagewidth = image:GetWidth() |
if (width - imagewidth) < 200 or (label:GetText() or "") == "" then |
-- image goes on top centered when less than 200 width for the text, or if there is no text |
image:SetPoint("TOP") |
label:SetPoint("TOP", image, "BOTTOM") |
label:SetPoint("LEFT") |
label:SetWidth(width) |
height = image:GetHeight() + label:GetHeight() |
else |
-- image on the left |
image:SetPoint("TOPLEFT") |
if image:GetHeight() > label:GetHeight() then |
label:SetPoint("LEFT", image, "RIGHT", 4, 0) |
else |
label:SetPoint("TOPLEFT", image, "TOPRIGHT", 4, 0) |
end |
label:SetWidth(width - imagewidth - 4) |
height = max(image:GetHeight(), label:GetHeight()) |
end |
else |
-- no image shown |
label:SetPoint("TOPLEFT") |
label:SetWidth(width) |
height = label:GetHeight() |
end |
-------------------------- |
-- Label -- |
-------------------------- |
do |
local Type = "Label" |
local Version = 12 |
self.resizing = true |
frame:SetHeight(height) |
frame.height = height |
self.resizing = nil |
end |
--[[----------------------------------------------------------------------------- |
Methods |
-------------------------------------------------------------------------------]] |
local methods = { |
["OnAcquire"] = function(self) |
-- set the flag to stop constant size updates |
self.resizing = true |
-- height is set dynamically by the text and image size |
local function OnAcquire(self) |
self:SetHeight(18) |
self:SetWidth(200) |
self:SetText() |
self:SetText("") |
self:SetImage(nil) |
self:SetImageSize(16, 16) |
self:SetColor() |
self:SetFontObject() |
-- reset the flag |
end |
local function OnRelease(self) |
self.frame:ClearAllPoints() |
self.frame:Hide() |
end |
local function UpdateImageAnchor(self) |
local width = self.frame.width or self.frame:GetWidth() or 0 |
local image = self.image |
local label = self.label |
local frame = self.frame |
local height |
label:ClearAllPoints() |
image:ClearAllPoints() |
if self.imageshown then |
local imagewidth = image:GetWidth() |
if (width - imagewidth) < 200 or (label:GetText() or "") == "" then |
--image goes on top centered when less than 200 width for the text, or if there is no text |
image:SetPoint("TOP",frame,"TOP",0,0) |
label:SetPoint("TOP",image,"BOTTOM",0,0) |
label:SetPoint("LEFT",frame,"LEFT",0,0) |
label:SetWidth(width) |
height = image:GetHeight() + label:GetHeight() |
else |
--image on the left |
image:SetPoint("TOPLEFT",frame,"TOPLEFT",0,0) |
label:SetPoint("TOPLEFT",image,"TOPRIGHT",4,0) |
label:SetWidth(width - imagewidth) |
height = max(image:GetHeight(), label:GetHeight()) |
end |
else |
--no image shown |
label:SetPoint("TOPLEFT",frame,"TOPLEFT",0,0) |
label:SetWidth(width) |
height = self.label:GetHeight() |
end |
self.resizing = true |
self.frame:SetHeight(height) |
self.frame.height = height |
self.resizing = nil |
-- run the update explicitly |
end |
local function SetText(self, text) |
self.label:SetText(text or "") |
UpdateImageAnchor(self) |
end, |
-- ["OnRelease"] = nil, |
["OnWidthSet"] = function(self, width) |
UpdateImageAnchor(self) |
end, |
["SetText"] = function(self, text) |
self.label:SetText(text) |
UpdateImageAnchor(self) |
end, |
["SetColor"] = function(self, r, g, b) |
end |
local function SetColor(self, r, g, b) |
if not (r and g and b) then |
r, g, b = 1, 1, 1 |
end |
self.label:SetVertexColor(r, g, b) |
end, |
["SetImage"] = function(self, path, ...) |
end |
local function OnWidthSet(self, width) |
if self.resizing then return end |
UpdateImageAnchor(self) |
end |
local function SetImage(self, path, ...) |
local image = self.image |
image:SetTexture(path) |
if image:GetTexture() then |
self.imageshown = true |
local n = select("#", ...) |
local n = select('#', ...) |
if n == 4 or n == 8 then |
image:SetTexCoord(...) |
else |
self.imageshown = nil |
end |
UpdateImageAnchor(self) |
end, |
["SetFont"] = function(self, font, height, flags) |
end |
local function SetFont(self, font, height, flags) |
self.label:SetFont(font, height, flags) |
end, |
["SetFontObject"] = function(self, font) |
self:SetFont((font or GameFontHighlightSmall):GetFont()) |
end, |
["SetImageSize"] = function(self, width, height) |
end |
local function SetFontObject(self, font) |
self.label:SetFontObject(font or GameFontHighlightSmall) |
end |
local function SetImageSize(self, width, height) |
self.image:SetWidth(width) |
self.image:SetHeight(height) |
UpdateImageAnchor(self) |
end, |
} |
--[[----------------------------------------------------------------------------- |
Constructor |
-------------------------------------------------------------------------------]] |
local function Constructor() |
local frame = CreateFrame("Frame", nil, UIParent) |
frame:Hide() |
local label = frame:CreateFontString(nil, "BACKGROUND", "GameFontHighlightSmall") |
label:SetJustifyH("LEFT") |
label:SetJustifyV("TOP") |
local image = frame:CreateTexture(nil, "BACKGROUND") |
-- create widget |
local widget = { |
label = label, |
image = image, |
frame = frame, |
type = Type |
} |
for method, func in pairs(methods) do |
widget[method] = func |
end |
return AceGUI:RegisterAsWidget(widget) |
local function Constructor() |
local frame = CreateFrame("Frame",nil,UIParent) |
local self = {} |
self.type = Type |
self.OnRelease = OnRelease |
self.OnAcquire = OnAcquire |
self.SetText = SetText |
self.SetColor = SetColor |
self.frame = frame |
self.OnWidthSet = OnWidthSet |
self.SetImage = SetImage |
self.SetImageSize = SetImageSize |
self.SetFont = SetFont |
self.SetFontObject = SetFontObject |
frame.obj = self |
frame:SetHeight(18) |
frame:SetWidth(200) |
local label = frame:CreateFontString(nil,"BACKGROUND","GameFontHighlightSmall") |
label:SetPoint("TOPLEFT",frame,"TOPLEFT",0,0) |
label:SetWidth(200) |
label:SetJustifyH("LEFT") |
label:SetJustifyV("TOP") |
self.label = label |
local image = frame:CreateTexture(nil,"BACKGROUND") |
self.image = image |
AceGUI:RegisterAsWidget(self) |
return self |
end |
AceGUI:RegisterWidgetType(Type,Constructor,Version) |
end |
AceGUI:RegisterWidgetType(Type, Constructor, Version) |
local Type, Version = "MultiLineEditBox", 27 |
local AceGUI = LibStub and LibStub("AceGUI-3.0", true) |
if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end |
--[[ |
--Multiline Editbox Widget, Originally by bam |
--]] |
local AceGUI = LibStub("AceGUI-3.0") |
-- Lua APIs |
local pairs = pairs |
local format, pairs, tostring = string.format, pairs, tostring |
-- WoW APIs |
local GetCursorInfo, GetSpellInfo, ClearCursor = GetCursorInfo, GetSpellInfo, ClearCursor |
local GetCursorInfo, ClearCursor, GetSpellName = GetCursorInfo, ClearCursor, GetSpellName |
local CreateFrame, UIParent = CreateFrame, UIParent |
local _G = _G |
-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded |
-- List them here for Mikk's FindGlobals script |
-- GLOBALS: ACCEPT, ChatFontNormal |
-- GLOBALS: ChatFontNormal, ACCEPT |
local wowMoP |
do |
local _, _, _, interface = GetBuildInfo() |
wowMoP = (interface >= 50000) |
end |
local Version = 11 |
--------------------- |
-- Common Elements -- |
--------------------- |
--[[----------------------------------------------------------------------------- |
Support functions |
-------------------------------------------------------------------------------]] |
local FrameBackdrop = { |
bgFile="Interface\\DialogFrame\\UI-DialogBox-Background", |
edgeFile="Interface\\DialogFrame\\UI-DialogBox-Border", |
tile = true, tileSize = 32, edgeSize = 32, |
insets = { left = 8, right = 8, top = 8, bottom = 8 } |
} |
if not AceGUIMultiLineEditBoxInsertLink then |
-- upgradeable hook |
hooksecurefunc("ChatEdit_InsertLink", function(...) return _G.AceGUIMultiLineEditBoxInsertLink(...) end) |
end |
local PaneBackdrop = { |
function _G.AceGUIMultiLineEditBoxInsertLink(text) |
for i = 1, AceGUI:GetWidgetCount(Type) do |
local editbox = _G[("MultiLineEditBox%uEdit"):format(i)] |
if editbox and editbox:IsVisible() and editbox:HasFocus() then |
editbox:Insert(text) |
return true |
end |
end |
end |
bgFile = "Interface\\ChatFrame\\ChatFrameBackground", |
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", |
tile = true, tileSize = 16, edgeSize = 16, |
insets = { left = 3, right = 3, top = 5, bottom = 3 } |
} |
local ControlBackdrop = { |
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", |
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", |
tile = true, tileSize = 16, edgeSize = 16, |
insets = { left = 3, right = 3, top = 3, bottom = 3 } |
} |
local function Layout(self) |
self:SetHeight(self.numlines * 14 + (self.disablebutton and 19 or 41) + self.labelHeight) |
-------------------------- |
-- Edit box -- |
-------------------------- |
--[[ |
Events : |
OnTextChanged |
OnEnterPressed |
if self.labelHeight == 0 then |
self.scrollBar:SetPoint("TOP", self.frame, "TOP", 0, -23) |
else |
self.scrollBar:SetPoint("TOP", self.label, "BOTTOM", 0, -19) |
end |
]] |
do |
local Type = "MultiLineEditBox" |
if self.disablebutton then |
self.scrollBar:SetPoint("BOTTOM", self.frame, "BOTTOM", 0, 21) |
self.scrollBG:SetPoint("BOTTOMLEFT", 0, 4) |
else |
self.scrollBar:SetPoint("BOTTOM", self.button, "TOP", 0, 18) |
self.scrollBG:SetPoint("BOTTOMLEFT", self.button, "TOPLEFT") |
end |
end |
local MultiLineEditBox = {} |
--[[----------------------------------------------------------------------------- |
Scripts |
-------------------------------------------------------------------------------]] |
local function OnClick(self) -- Button |
self = self.obj |
self.editBox:ClearFocus() |
if not self:Fire("OnEnterPressed", self.editBox:GetText()) then |
self.button:Disable() |
end |
end |
local function OnCursorChanged(self, _, y, _, cursorHeight) -- EditBox |
self, y = self.obj.scrollFrame, -y |
local offset = self:GetVerticalScroll() |
if y < offset then |
self:SetVerticalScroll(y) |
else |
y = y + cursorHeight - self:GetHeight() |
if y > offset then |
self:SetVerticalScroll(y) |
local function EditBox_OnEnterPressed(this) |
local self = this.obj |
local value = this:GetText() |
local cancel = self:Fire("OnEnterPressed",value) |
if not cancel then |
self.button:Disable() |
end |
end |
end |
local function OnEditFocusLost(self) -- EditBox |
self:HighlightText(0, 0) |
self.obj:Fire("OnEditFocusLost") |
end |
local function OnEnter(self) -- EditBox / ScrollFrame |
self = self.obj |
if not self.entered then |
self.entered = true |
self:Fire("OnEnter") |
local function Button_OnClick(this) |
local editbox = this.obj.editbox |
editbox:ClearFocus() |
EditBox_OnEnterPressed(editbox) |
end |
end |
local function OnLeave(self) -- EditBox / ScrollFrame |
self = self.obj |
if self.entered then |
self.entered = nil |
self:Fire("OnLeave") |
local function EditBox_OnReceiveDrag(this) |
local self = this.obj |
local type, id, info = GetCursorInfo() |
if type == "item" then |
self:SetText(info) |
self:Fire("OnEnterPressed",info) |
ClearCursor() |
elseif type == "spell" then |
local name, rank = GetSpellName(id, info) |
if rank and rank:match("%d") then |
name = name.."("..rank..")" |
end |
self:SetText(name) |
self:Fire("OnEnterPressed",name) |
ClearCursor() |
end |
--self.button:Disable() |
AceGUI:ClearFocus() |
end |
end |
local function OnMouseUp(self) -- ScrollFrame |
self = self.obj.editBox |
self:SetFocus() |
self:SetCursorPosition(self:GetNumLetters()) |
end |
local function OnReceiveDrag(self) -- EditBox / ScrollFrame |
local type, id, info = GetCursorInfo() |
if type == "spell" then |
info = GetSpellInfo(id, info) |
elseif type ~= "item" then |
return |
function MultiLineEditBox:OnAcquire() |
self:SetWidth(200) |
self:SetHeight(116) |
self:SetNumLines(4) |
self:SetDisabled(false) |
self:ShowButton(true) |
end |
ClearCursor() |
self = self.obj |
local editBox = self.editBox |
if not editBox:HasFocus() then |
editBox:SetFocus() |
editBox:SetCursorPosition(editBox:GetNumLetters()) |
end |
editBox:Insert(info) |
self.button:Enable() |
end |
local function OnSizeChanged(self, width, height) -- ScrollFrame |
self.obj.editBox:SetWidth(width) |
end |
local function OnTextChanged(self, userInput) -- EditBox |
if userInput then |
self = self.obj |
self:Fire("OnTextChanged", self.editBox:GetText()) |
self.button:Enable() |
end |
end |
local function OnTextSet(self) -- EditBox |
self:HighlightText(0, 0) |
self:SetCursorPosition(self:GetNumLetters()) |
self:SetCursorPosition(0) |
self.obj.button:Disable() |
end |
local function OnVerticalScroll(self, offset) -- ScrollFrame |
local editBox = self.obj.editBox |
editBox:SetHitRectInsets(0, 0, offset, editBox:GetHeight() - offset - self:GetHeight()) |
end |
local function OnShowFocus(frame) |
frame.obj.editBox:SetFocus() |
frame:SetScript("OnShow", nil) |
end |
local function OnEditFocusGained(frame) |
AceGUI:SetFocus(frame.obj) |
frame.obj:Fire("OnEditFocusGained") |
end |
--[[----------------------------------------------------------------------------- |
Methods |
-------------------------------------------------------------------------------]] |
local methods = { |
["OnAcquire"] = function(self) |
self.editBox:SetText("") |
function MultiLineEditBox:OnRelease() |
self.frame:ClearAllPoints() |
self.frame:Hide() |
self:SetDisabled(false) |
self:SetWidth(200) |
self:DisableButton(false) |
self:SetNumLines() |
self.entered = nil |
self:SetMaxLetters(0) |
end, |
["OnRelease"] = function(self) |
self:ClearFocus() |
end, |
["SetDisabled"] = function(self, disabled) |
local editBox = self.editBox |
end |
function MultiLineEditBox:SetDisabled(disabled) |
self.disabled = disabled |
if disabled then |
editBox:ClearFocus() |
editBox:EnableMouse(false) |
editBox:SetTextColor(0.5, 0.5, 0.5) |
self.label:SetTextColor(0.5, 0.5, 0.5) |
self.scrollFrame:EnableMouse(false) |
self.editbox:EnableMouse(false) |
self.scrollframe:EnableMouse(false) |
self.editbox:ClearFocus() |
self.editbox:SetTextColor(0.5, 0.5, 0.5) |
self.label:SetTextColor(0.5,0.5,0.5) |
self.button:Disable() |
else |
editBox:EnableMouse(true) |
editBox:SetTextColor(1, 1, 1) |
self.label:SetTextColor(1, 0.82, 0) |
self.scrollFrame:EnableMouse(true) |
self.editbox:EnableMouse(true) |
self.scrollframe:EnableMouse(true) |
self.editbox:SetTextColor(1, 1, 1) |
self.label:SetTextColor(1,.82,0) |
self.button:Enable() |
end |
end, |
end |
["SetLabel"] = function(self, text) |
if text and text ~= "" then |
self.label:SetText(text) |
if self.labelHeight ~= 10 then |
self.labelHeight = 10 |
self.label:Show() |
end |
elseif self.labelHeight ~= 0 then |
self.labelHeight = 0 |
function MultiLineEditBox:SetText(text) |
text = text or "" |
local editbox = self.editbox |
local oldText = editbox:GetText() |
local dummy = format(" %s", text) |
self.lasttext = dummy -- prevents OnTextChanged from firing |
editbox:SetText(dummy) |
editbox:HighlightText(0, 1) |
self.lasttext = oldText |
editbox:Insert("") |
end |
function MultiLineEditBox:SetLabel(text) |
if (text or "") == "" then |
self.backdrop:SetPoint("TOPLEFT",self.frame,"TOPLEFT",0,0) |
self.label:Hide() |
end |
Layout(self) |
end, |
["SetNumLines"] = function(self, value) |
if not value or value < 4 then |
value = 4 |
end |
self.numlines = value |
Layout(self) |
end, |
["SetText"] = function(self, text) |
self.editBox:SetText(text) |
end, |
["GetText"] = function(self) |
return self.editBox:GetText() |
end, |
["SetMaxLetters"] = function (self, num) |
self.editBox:SetMaxLetters(num or 0) |
end, |
["DisableButton"] = function(self, disabled) |
self.disablebutton = disabled |
if disabled then |
self.button:Hide() |
self.label:SetText("") |
else |
self.button:Show() |
self.backdrop:SetPoint("TOPLEFT",self.frame,"TOPLEFT",0,-20) |
self.label:Show() |
self.label:SetText(text) |
end |
Layout(self) |
end, |
end |
["ClearFocus"] = function(self) |
self.editBox:ClearFocus() |
self.frame:SetScript("OnShow", nil) |
end, |
function MultiLineEditBox:SetNumLines(number) |
number = number or 4 |
self:SetHeight(60 + (14*number)) |
end |
["SetFocus"] = function(self) |
self.editBox:SetFocus() |
if not self.frame:IsShown() then |
self.frame:SetScript("OnShow", OnShowFocus) |
end |
end, |
function MultiLineEditBox:GetText() |
return self.editbox:GetText() |
end |
["GetCursorPosition"] = function(self) |
return self.editBox:GetCursorPosition() |
end, |
["SetCursorPosition"] = function(self, ...) |
return self.editBox:SetCursorPosition(...) |
end, |
} |
function MultiLineEditBox:ShowButton(show) |
if show then |
self.backdrop:SetPoint("BOTTOMRIGHT",self.frame,"BOTTOMRIGHT",0,22) |
self.button:Show() |
else |
self.backdrop:SetPoint("BOTTOMRIGHT",self.frame,"BOTTOMRIGHT",0,0) |
self.button:Hide() |
end |
end |
--[[----------------------------------------------------------------------------- |
Constructor |
-------------------------------------------------------------------------------]] |
local backdrop = { |
bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], |
edgeFile = [[Interface\Tooltips\UI-Tooltip-Border]], edgeSize = 16, |
insets = { left = 4, right = 3, top = 4, bottom = 3 } |
} |
local function Constructor() |
local frame = CreateFrame("Frame", nil, UIParent) |
local backdrop = CreateFrame("Frame", nil, frame) |
local self = {} |
for k, v in pairs(MultiLineEditBox) do self[k] = v end |
self.type = Type |
self.frame = frame |
self.backdrop = backdrop |
frame.obj = self |
local function Constructor() |
local frame = CreateFrame("Frame", nil, UIParent) |
frame:Hide() |
backdrop:SetBackdrop(ControlBackdrop) |
backdrop:SetBackdropColor(0, 0, 0) |
backdrop:SetBackdropBorderColor(0.4, 0.4, 0.4) |
local widgetNum = AceGUI:GetNextWidgetNum(Type) |
local label = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall") |
label:SetPoint("TOPLEFT", frame, "TOPLEFT", 0, -4) |
label:SetPoint("TOPRIGHT", frame, "TOPRIGHT", 0, -4) |
label:SetJustifyH("LEFT") |
label:SetText(ACCEPT) |
label:SetHeight(10) |
local button = CreateFrame("Button", ("%s%dButton"):format(Type, widgetNum), frame, wowMoP and "UIPanelButtonTemplate" or "UIPanelButtonTemplate2") |
button:SetPoint("BOTTOMLEFT", 0, 4) |
button:SetHeight(22) |
button:SetWidth(label:GetStringWidth() + 24) |
button:SetText(ACCEPT) |
button:SetScript("OnClick", OnClick) |
button:Disable() |
backdrop:SetPoint("TOPLEFT",frame,"TOPLEFT",0, -20) |
backdrop:SetPoint("BOTTOMRIGHT",frame,"BOTTOMRIGHT",0,22) |
local scrollframe = CreateFrame("ScrollFrame", format("%s@%s@%s", Type, "ScrollFrame", tostring(self)), backdrop, "UIPanelScrollFrameTemplate") |
scrollframe:SetPoint("TOPLEFT", 5, -6) |
scrollframe:SetPoint("BOTTOMRIGHT", -28, 6) |
scrollframe.obj = self |
self.scrollframe = scrollframe |
--local scrollchild = CreateFrame("Frame", nil, scrollframe) |
--scrollframe:SetScrollChild(scrollchild) |
--scrollchild:SetHeight(2) |
--scrollchild:SetWidth(2) |
local text = button:GetFontString() |
text:ClearAllPoints() |
text:SetPoint("TOPLEFT", button, "TOPLEFT", 5, -5) |
text:SetPoint("BOTTOMRIGHT", button, "BOTTOMRIGHT", -5, 1) |
text:SetJustifyV("MIDDLE") |
local label = frame:CreateFontString(nil,"OVERLAY","GameFontNormalSmall") |
label:SetPoint("TOPLEFT",frame,"TOPLEFT",0,-2) |
label:SetPoint("TOPRIGHT",frame,"TOPRIGHT",0,-2) |
label:SetJustifyH("LEFT") |
label:SetHeight(18) |
self.label = label |
local editbox = CreateFrame("EditBox", nil, scrollframe) |
self.editbox = editbox |
editbox.obj = self |
editbox:SetPoint("TOPLEFT") |
editbox:SetPoint("BOTTOMLEFT") |
editbox:SetHeight(50) |
editbox:SetWidth(50) |
editbox:SetMultiLine(true) |
-- editbox:SetMaxLetters(7500) |
editbox:SetTextInsets(5, 5, 3, 3) |
editbox:EnableMouse(true) |
editbox:SetAutoFocus(false) |
editbox:SetFontObject(ChatFontNormal) |
scrollframe:SetScrollChild(editbox) |
local scrollBG = CreateFrame("Frame", nil, frame) |
scrollBG:SetBackdrop(backdrop) |
scrollBG:SetBackdropColor(0, 0, 0) |
scrollBG:SetBackdropBorderColor(0.4, 0.4, 0.4) |
local scrollFrame = CreateFrame("ScrollFrame", ("%s%dScrollFrame"):format(Type, widgetNum), frame, "UIPanelScrollFrameTemplate") |
local scrollBar = _G[scrollFrame:GetName() .. "ScrollBar"] |
scrollBar:ClearAllPoints() |
scrollBar:SetPoint("TOP", label, "BOTTOM", 0, -19) |
scrollBar:SetPoint("BOTTOM", button, "TOP", 0, 18) |
scrollBar:SetPoint("RIGHT", frame, "RIGHT") |
scrollBG:SetPoint("TOPRIGHT", scrollBar, "TOPLEFT", 0, 19) |
scrollBG:SetPoint("BOTTOMLEFT", button, "TOPLEFT") |
scrollFrame:SetPoint("TOPLEFT", scrollBG, "TOPLEFT", 5, -6) |
scrollFrame:SetPoint("BOTTOMRIGHT", scrollBG, "BOTTOMRIGHT", -4, 4) |
scrollFrame:SetScript("OnEnter", OnEnter) |
scrollFrame:SetScript("OnLeave", OnLeave) |
scrollFrame:SetScript("OnMouseUp", OnMouseUp) |
scrollFrame:SetScript("OnReceiveDrag", OnReceiveDrag) |
scrollFrame:SetScript("OnSizeChanged", OnSizeChanged) |
scrollFrame:HookScript("OnVerticalScroll", OnVerticalScroll) |
local editBox = CreateFrame("EditBox", ("%s%dEdit"):format(Type, widgetNum), scrollFrame) |
editBox:SetAllPoints() |
editBox:SetFontObject(ChatFontNormal) |
editBox:SetMultiLine(true) |
editBox:EnableMouse(true) |
editBox:SetAutoFocus(false) |
editBox:SetCountInvisibleLetters(false) |
editBox:SetScript("OnCursorChanged", OnCursorChanged) |
editBox:SetScript("OnEditFocusLost", OnEditFocusLost) |
editBox:SetScript("OnEnter", OnEnter) |
editBox:SetScript("OnEscapePressed", editBox.ClearFocus) |
editBox:SetScript("OnLeave", OnLeave) |
editBox:SetScript("OnMouseDown", OnReceiveDrag) |
editBox:SetScript("OnReceiveDrag", OnReceiveDrag) |
editBox:SetScript("OnTextChanged", OnTextChanged) |
editBox:SetScript("OnTextSet", OnTextSet) |
editBox:SetScript("OnEditFocusGained", OnEditFocusGained) |
local button = CreateFrame("Button",nil,scrollframe,"UIPanelButtonTemplate") |
button:SetWidth(80) |
button:SetHeight(20) |
button:SetPoint("BOTTOMLEFT",frame,"BOTTOMLEFT",0,2) |
button:SetText(ACCEPT) |
button:SetScript("OnClick", Button_OnClick) |
button:SetFrameLevel(editbox:GetFrameLevel() + 1) |
button:Disable() |
button:Hide() |
self.button = button |
button.obj = self |
scrollframe:EnableMouse(true) |
scrollframe:SetScript("OnMouseUp", function() editbox:SetFocus() end) |
scrollframe:SetScript("OnEnter", function(this) this.obj:Fire("OnEnter") end) |
scrollframe:SetScript("OnLeave", function(this) this.obj:Fire("OnLeave") end) |
editbox:SetScript("OnEnter", function(this) this.obj:Fire("OnEnter") end) |
editbox:SetScript("OnLeave", function(this) this.obj:Fire("OnLeave") end) |
local function FixSize() |
--scrollchild:SetHeight(scrollframe:GetHeight()) |
--scrollchild:SetWidth(scrollframe:GetWidth()) |
editbox:SetWidth(scrollframe:GetWidth()) |
end |
scrollframe:SetScript("OnShow", FixSize) |
scrollframe:SetScript("OnSizeChanged", FixSize) |
scrollFrame:SetScrollChild(editBox) |
local widget = { |
button = button, |
editBox = editBox, |
frame = frame, |
label = label, |
labelHeight = 10, |
numlines = 4, |
scrollBar = scrollBar, |
scrollBG = scrollBG, |
scrollFrame = scrollFrame, |
type = Type |
} |
for method, func in pairs(methods) do |
widget[method] = func |
editbox:SetScript("OnEscapePressed", editbox.ClearFocus) |
editbox:SetScript("OnTextChanged", function(_, ...) |
scrollframe:UpdateScrollChildRect() |
local value = editbox:GetText() |
if value ~= self.lasttext then |
self:Fire("OnTextChanged", value) |
self.lasttext = value |
if not self.disabled then |
self.button:Enable() |
end |
end |
end) |
editbox:SetScript("OnReceiveDrag", EditBox_OnReceiveDrag) |
editbox:SetScript("OnMouseDown", EditBox_OnReceiveDrag) |
do |
local cursorOffset, cursorHeight |
local idleTime |
local function FixScroll(_, elapsed) |
if cursorOffset and cursorHeight then |
idleTime = 0 |
local height = scrollframe:GetHeight() |
local range = scrollframe:GetVerticalScrollRange() |
local scroll = scrollframe:GetVerticalScroll() |
local size = height + range |
cursorOffset = -cursorOffset |
while cursorOffset < scroll do |
scroll = scroll - (height / 2) |
if scroll < 0 then scroll = 0 end |
scrollframe:SetVerticalScroll(scroll) |
end |
while cursorOffset + cursorHeight > scroll + height and scroll < range do |
scroll = scroll + (height / 2) |
if scroll > range then scroll = range end |
scrollframe:SetVerticalScroll(scroll) |
end |
elseif not idleTime or idleTime > 2 then |
frame:SetScript("OnUpdate", nil) |
idleTime = nil |
else |
idleTime = idleTime + elapsed |
end |
cursorOffset = nil |
end |
editbox:SetScript("OnCursorChanged", function(_, x, y, w, h) |
cursorOffset, cursorHeight = y, h |
if not idleTime then |
frame:SetScript("OnUpdate", FixScroll) |
end |
end) |
end |
AceGUI:RegisterAsWidget(self) |
return self |
end |
button.obj, editBox.obj, scrollFrame.obj = widget, widget, widget |
return AceGUI:RegisterAsWidget(widget) |
AceGUI:RegisterWidgetType(Type, Constructor, Version) |
end |
AceGUI:RegisterWidgetType(Type, Constructor, Version) |
--[[----------------------------------------------------------------------------- |
Slider Widget |
Graphical Slider, like, for Range values. |
-------------------------------------------------------------------------------]] |
local Type, Version = "Slider", 20 |
local AceGUI = LibStub and LibStub("AceGUI-3.0", true) |
if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end |
local AceGUI = LibStub("AceGUI-3.0") |
-- Lua APIs |
local min, max, floor = math.min, math.max, math.floor |
local tonumber, pairs = tonumber, pairs |
local tonumber = tonumber |
-- WoW APIs |
local PlaySound = PlaySound |
-- List them here for Mikk's FindGlobals script |
-- GLOBALS: GameFontHighlightSmall |
--[[----------------------------------------------------------------------------- |
Support functions |
-------------------------------------------------------------------------------]] |
local function UpdateText(self) |
local value = self.value or 0 |
if self.ispercent then |
self.editbox:SetText(("%s%%"):format(floor(value * 1000 + 0.5) / 10)) |
else |
self.editbox:SetText(floor(value * 100 + 0.5) / 100) |
-------------------------- |
-- Slider -- |
-------------------------- |
do |
local Type = "Slider" |
local Version = 10 |
local function OnAcquire(self) |
self:SetWidth(200) |
self:SetHeight(44) |
self:SetDisabled(false) |
self:SetIsPercent(nil) |
self:SetSliderValues(0,100,1) |
self:SetValue(0) |
end |
end |
local function OnRelease(self) |
self.frame:ClearAllPoints() |
self.frame:Hide() |
self.slider:EnableMouseWheel(false) |
self:SetDisabled(false) |
end |
local function UpdateLabels(self) |
local min, max = (self.min or 0), (self.max or 100) |
if self.ispercent then |
self.lowtext:SetFormattedText("%s%%", (min * 100)) |
self.hightext:SetFormattedText("%s%%", (max * 100)) |
else |
self.lowtext:SetText(min) |
self.hightext:SetText(max) |
local function Control_OnEnter(this) |
this.obj:Fire("OnEnter") |
end |
end |
--[[----------------------------------------------------------------------------- |
Scripts |
-------------------------------------------------------------------------------]] |
local function Control_OnEnter(frame) |
frame.obj:Fire("OnEnter") |
end |
local function Control_OnLeave(frame) |
frame.obj:Fire("OnLeave") |
end |
local function Frame_OnMouseDown(frame) |
frame.obj.slider:EnableMouseWheel(true) |
AceGUI:ClearFocus() |
end |
local function Slider_OnValueChanged(frame) |
local self = frame.obj |
if not frame.setup then |
local newvalue = frame:GetValue() |
if newvalue ~= self.value and not self.disabled then |
self.value = newvalue |
self:Fire("OnValueChanged", newvalue) |
local function Control_OnLeave(this) |
this.obj:Fire("OnLeave") |
end |
local function UpdateText(self) |
local value = self.value or 0 |
if self.ispercent then |
self.editbox:SetText(("%s%%"):format(floor(value*1000+0.5)/10)) |
else |
self.editbox:SetText(floor(value*100+0.5)/100) |
end |
if self.value then |
UpdateText(self) |
end |
end |
end |
local function Slider_OnMouseUp(frame) |
local self = frame.obj |
self:Fire("OnMouseUp", self.value) |
end |
local function Slider_OnMouseWheel(frame, v) |
local self = frame.obj |
if not self.disabled then |
local value = self.value |
if v > 0 then |
value = min(value + (self.step or 1), self.max) |
local function UpdateLabels(self) |
local min, max = (self.min or 0), (self.max or 100) |
if self.ispercent then |
self.lowtext:SetFormattedText("%s%%",(min * 100)) |
self.hightext:SetFormattedText("%s%%",(max * 100)) |
else |
value = max(value - (self.step or 1), self.min) |
self.lowtext:SetText(min) |
self.hightext:SetText(max) |
end |
self.slider:SetValue(value) |
end |
end |
local function EditBox_OnEscapePressed(frame) |
frame:ClearFocus() |
end |
local function EditBox_OnEnterPressed(frame) |
local self = frame.obj |
local value = frame:GetText() |
if self.ispercent then |
value = value:gsub('%%', '') |
value = tonumber(value) / 100 |
else |
value = tonumber(value) |
local function Slider_OnValueChanged(this) |
local self = this.obj |
if not this.setup then |
local newvalue |
newvalue = this:GetValue() |
if newvalue ~= self.value and not self.disabled then |
self.value = newvalue |
self:Fire("OnValueChanged", newvalue) |
end |
if self.value then |
local value = self.value |
UpdateText(self) |
end |
end |
end |
if value then |
PlaySound("igMainMenuOptionCheckBoxOn") |
self.slider:SetValue(value) |
self:Fire("OnMouseUp", value) |
local function Slider_OnMouseUp(this) |
local self = this.obj |
self:Fire("OnMouseUp",this:GetValue()) |
end |
end |
local function EditBox_OnEnter(frame) |
frame:SetBackdropBorderColor(0.5, 0.5, 0.5, 1) |
end |
local function EditBox_OnLeave(frame) |
frame:SetBackdropBorderColor(0.3, 0.3, 0.3, 0.8) |
end |
--[[----------------------------------------------------------------------------- |
Methods |
-------------------------------------------------------------------------------]] |
local methods = { |
["OnAcquire"] = function(self) |
self:SetWidth(200) |
self:SetHeight(44) |
self:SetDisabled(false) |
self:SetIsPercent(nil) |
self:SetSliderValues(0,100,1) |
self:SetValue(0) |
self.slider:EnableMouseWheel(false) |
end, |
-- ["OnRelease"] = nil, |
["SetDisabled"] = function(self, disabled) |
local function Slider_OnMouseWheel(this, v) |
local self = this.obj |
if not self.disabled then |
local value = self.value |
if v > 0 then |
value = min(value + (self.step or 1),self.max) |
else |
value = max(value - (self.step or 1), self.min) |
end |
self.slider:SetValue(value) |
end |
end |
local function SetDisabled(self, disabled) |
self.disabled = disabled |
if disabled then |
self.slider:EnableMouse(false) |
self.label:SetTextColor(.5, .5, .5) |
self.hightext:SetTextColor(.5, .5, .5) |
self.lowtext:SetTextColor(.5, .5, .5) |
--self.valuetext:SetTextColor(.5, .5, .5) |
self.editbox:SetTextColor(.5, .5, .5) |
self.label:SetTextColor(.5,.5,.5) |
self.hightext:SetTextColor(.5,.5,.5) |
self.lowtext:SetTextColor(.5,.5,.5) |
--self.valuetext:SetTextColor(.5,.5,.5) |
self.editbox:SetTextColor(.5,.5,.5) |
self.editbox:EnableMouse(false) |
self.editbox:ClearFocus() |
else |
self.slider:EnableMouse(true) |
self.label:SetTextColor(1, .82, 0) |
self.hightext:SetTextColor(1, 1, 1) |
self.lowtext:SetTextColor(1, 1, 1) |
--self.valuetext:SetTextColor(1, 1, 1) |
self.editbox:SetTextColor(1, 1, 1) |
self.label:SetTextColor(1,.82,0) |
self.hightext:SetTextColor(1,1,1) |
self.lowtext:SetTextColor(1,1,1) |
--self.valuetext:SetTextColor(1,1,1) |
self.editbox:SetTextColor(1,1,1) |
self.editbox:EnableMouse(true) |
end |
end, |
["SetValue"] = function(self, value) |
end |
local function SetValue(self, value) |
self.slider.setup = true |
self.slider:SetValue(value) |
self.value = value |
UpdateText(self) |
self.slider.setup = nil |
end, |
["GetValue"] = function(self) |
return self.value |
end, |
["SetLabel"] = function(self, text) |
end |
local function SetLabel(self, text) |
self.label:SetText(text) |
end, |
["SetSliderValues"] = function(self, min, max, step) |
end |
local function SetSliderValues(self, min, max, step) |
local frame = self.slider |
frame.setup = true |
self.min = min |
frame:SetValue(self.value) |
end |
frame.setup = nil |
end, |
["SetIsPercent"] = function(self, value) |
end |
local function EditBox_OnEscapePressed(this) |
this:ClearFocus() |
end |
local function EditBox_OnEnterPressed(this) |
local self = this.obj |
local value = this:GetText() |
if self.ispercent then |
value = value:gsub('%%','') |
value = tonumber(value) / 100 |
else |
value = tonumber(value) |
end |
if value then |
PlaySound("igMainMenuOptionCheckBoxOn") |
self:Fire("OnMouseUp",value) |
end |
end |
local function EditBox_OnEnter(this) |
this:SetBackdropBorderColor(0.5,0.5,0.5,1) |
end |
local function EditBox_OnLeave(this) |
this:SetBackdropBorderColor(0.3,0.3,0.3,0.8) |
end |
local function SetIsPercent(self, value) |
self.ispercent = value |
UpdateLabels(self) |
UpdateText(self) |
end |
} |
local function FrameOnMouseDown(this) |
this.obj.slider:EnableMouseWheel(true) |
AceGUI:ClearFocus() |
end |
local SliderBackdrop = { |
bgFile = "Interface\\Buttons\\UI-SliderBar-Background", |
edgeFile = "Interface\\Buttons\\UI-SliderBar-Border", |
tile = true, tileSize = 8, edgeSize = 8, |
insets = { left = 3, right = 3, top = 6, bottom = 6 } |
} |
local ManualBackdrop = { |
bgFile = "Interface\\ChatFrame\\ChatFrameBackground", |
edgeFile = "Interface\\ChatFrame\\ChatFrameBackground", |
tile = true, edgeSize = 1, tileSize = 5, |
} |
local function Constructor() |
local frame = CreateFrame("Frame",nil,UIParent) |
local self = {} |
self.type = Type |
--[[----------------------------------------------------------------------------- |
Constructor |
-------------------------------------------------------------------------------]] |
local SliderBackdrop = { |
bgFile = "Interface\\Buttons\\UI-SliderBar-Background", |
edgeFile = "Interface\\Buttons\\UI-SliderBar-Border", |
tile = true, tileSize = 8, edgeSize = 8, |
insets = { left = 3, right = 3, top = 6, bottom = 6 } |
} |
self.OnRelease = OnRelease |
self.OnAcquire = OnAcquire |
self.frame = frame |
frame.obj = self |
self.SetDisabled = SetDisabled |
self.SetValue = SetValue |
self.SetSliderValues = SetSliderValues |
self.SetLabel = SetLabel |
self.SetIsPercent = SetIsPercent |
self.alignoffset = 25 |
frame:EnableMouse(true) |
frame:SetScript("OnMouseDown",FrameOnMouseDown) |
self.slider = CreateFrame("Slider",nil,frame) |
local slider = self.slider |
slider:SetScript("OnEnter",Control_OnEnter) |
slider:SetScript("OnLeave",Control_OnLeave) |
slider:SetScript("OnMouseUp", Slider_OnMouseUp) |
slider.obj = self |
slider:SetOrientation("HORIZONTAL") |
slider:SetHeight(15) |
slider:SetHitRectInsets(0,0,-10,0) |
slider:SetBackdrop(SliderBackdrop) |
--slider:EnableMouseWheel(true) |
slider:SetScript("OnMouseWheel", Slider_OnMouseWheel) |
local label = frame:CreateFontString(nil,"OVERLAY","GameFontNormal") |
label:SetPoint("TOPLEFT",frame,"TOPLEFT",0,0) |
label:SetPoint("TOPRIGHT",frame,"TOPRIGHT",0,0) |
label:SetJustifyH("CENTER") |
label:SetHeight(15) |
self.label = label |
self.lowtext = slider:CreateFontString(nil,"ARTWORK","GameFontHighlightSmall") |
self.lowtext:SetPoint("TOPLEFT",slider,"BOTTOMLEFT",2,3) |
self.hightext = slider:CreateFontString(nil,"ARTWORK","GameFontHighlightSmall") |
self.hightext:SetPoint("TOPRIGHT",slider,"BOTTOMRIGHT",-2,3) |
local editbox = CreateFrame("EditBox",nil,frame) |
editbox:SetAutoFocus(false) |
editbox:SetFontObject(GameFontHighlightSmall) |
editbox:SetPoint("TOP",slider,"BOTTOM",0,0) |
editbox:SetHeight(14) |
editbox:SetWidth(70) |
editbox:SetJustifyH("CENTER") |
editbox:EnableMouse(true) |
editbox:SetScript("OnEscapePressed",EditBox_OnEscapePressed) |
editbox:SetScript("OnEnterPressed",EditBox_OnEnterPressed) |
editbox:SetScript("OnEnter",EditBox_OnEnter) |
editbox:SetScript("OnLeave",EditBox_OnLeave) |
editbox:SetBackdrop(ManualBackdrop) |
editbox:SetBackdropColor(0,0,0,0.5) |
editbox:SetBackdropBorderColor(0.3,0.3,0.30,0.80) |
self.editbox = editbox |
editbox.obj = self |
slider:SetThumbTexture("Interface\\Buttons\\UI-SliderBar-Button-Horizontal") |
frame:SetWidth(200) |
frame:SetHeight(44) |
slider:SetPoint("TOP",label,"BOTTOM",0,0) |
slider:SetPoint("LEFT",frame,"LEFT",3,0) |
slider:SetPoint("RIGHT",frame,"RIGHT",-3,0) |
local ManualBackdrop = { |
bgFile = "Interface\\ChatFrame\\ChatFrameBackground", |
edgeFile = "Interface\\ChatFrame\\ChatFrameBackground", |
tile = true, edgeSize = 1, tileSize = 5, |
} |
local function Constructor() |
local frame = CreateFrame("Frame", nil, UIParent) |
frame:EnableMouse(true) |
frame:SetScript("OnMouseDown", Frame_OnMouseDown) |
local label = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal") |
label:SetPoint("TOPLEFT") |
label:SetPoint("TOPRIGHT") |
label:SetJustifyH("CENTER") |
label:SetHeight(15) |
local slider = CreateFrame("Slider", nil, frame) |
slider:SetOrientation("HORIZONTAL") |
slider:SetHeight(15) |
slider:SetHitRectInsets(0, 0, -10, 0) |
slider:SetBackdrop(SliderBackdrop) |
slider:SetThumbTexture("Interface\\Buttons\\UI-SliderBar-Button-Horizontal") |
slider:SetPoint("TOP", label, "BOTTOM") |
slider:SetPoint("LEFT", 3, 0) |
slider:SetPoint("RIGHT", -3, 0) |
slider:SetValue(0) |
slider:SetScript("OnValueChanged",Slider_OnValueChanged) |
slider:SetScript("OnEnter", Control_OnEnter) |
slider:SetScript("OnLeave", Control_OnLeave) |
slider:SetScript("OnMouseUp", Slider_OnMouseUp) |
slider:SetScript("OnMouseWheel", Slider_OnMouseWheel) |
local lowtext = slider:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall") |
lowtext:SetPoint("TOPLEFT", slider, "BOTTOMLEFT", 2, 3) |
local hightext = slider:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall") |
hightext:SetPoint("TOPRIGHT", slider, "BOTTOMRIGHT", -2, 3) |
local editbox = CreateFrame("EditBox", nil, frame) |
editbox:SetAutoFocus(false) |
editbox:SetFontObject(GameFontHighlightSmall) |
editbox:SetPoint("TOP", slider, "BOTTOM") |
editbox:SetHeight(14) |
editbox:SetWidth(70) |
editbox:SetJustifyH("CENTER") |
editbox:EnableMouse(true) |
editbox:SetBackdrop(ManualBackdrop) |
editbox:SetBackdropColor(0, 0, 0, 0.5) |
editbox:SetBackdropBorderColor(0.3, 0.3, 0.30, 0.80) |
editbox:SetScript("OnEnter", EditBox_OnEnter) |
editbox:SetScript("OnLeave", EditBox_OnLeave) |
editbox:SetScript("OnEnterPressed", EditBox_OnEnterPressed) |
editbox:SetScript("OnEscapePressed", EditBox_OnEscapePressed) |
local widget = { |
label = label, |
slider = slider, |
lowtext = lowtext, |
hightext = hightext, |
editbox = editbox, |
alignoffset = 25, |
frame = frame, |
type = Type |
} |
for method, func in pairs(methods) do |
widget[method] = func |
slider:SetValue(self.value or 0) |
slider:SetScript("OnValueChanged",Slider_OnValueChanged) |
AceGUI:RegisterAsWidget(self) |
return self |
end |
slider.obj, editbox.obj = widget, widget |
return AceGUI:RegisterAsWidget(widget) |
AceGUI:RegisterWidgetType(Type,Constructor,Version) |
end |
AceGUI:RegisterWidgetType(Type,Constructor,Version) |
--[[----------------------------------------------------------------------------- |
Keybinding Widget |
Set Keybindings in the Config UI. |
-------------------------------------------------------------------------------]] |
local Type, Version = "Keybinding", 24 |
local AceGUI = LibStub and LibStub("AceGUI-3.0", true) |
if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end |
local AceGUI = LibStub("AceGUI-3.0") |
-- Lua APIs |
local pairs = pairs |
-- WoW APIs |
local IsShiftKeyDown, IsControlKeyDown, IsAltKeyDown = IsShiftKeyDown, IsControlKeyDown, IsAltKeyDown |
-- List them here for Mikk's FindGlobals script |
-- GLOBALS: NOT_BOUND |
local wowMoP |
-------------------------- |
-- Keybinding -- |
-------------------------- |
do |
local _, _, _, interface = GetBuildInfo() |
wowMoP = (interface >= 50000) |
end |
local Type = "Keybinding" |
local Version = 13 |
--[[----------------------------------------------------------------------------- |
Scripts |
-------------------------------------------------------------------------------]] |
local ControlBackdrop = { |
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", |
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", |
tile = true, tileSize = 16, edgeSize = 16, |
insets = { left = 3, right = 3, top = 3, bottom = 3 } |
} |
local function Control_OnEnter(frame) |
frame.obj:Fire("OnEnter") |
end |
local function Control_OnEnter(this) |
this.obj:Fire("OnEnter") |
end |
local function Control_OnLeave(frame) |
frame.obj:Fire("OnLeave") |
end |
local function Control_OnLeave(this) |
this.obj:Fire("OnLeave") |
end |
local function keybindingMsgFixWidth(this) |
this:SetWidth(this.msg:GetWidth()+10) |
this:SetScript("OnUpdate",nil) |
end |
local function Keybinding_OnClick(frame, button) |
if button == "LeftButton" or button == "RightButton" then |
local self = frame.obj |
if self.waitingForKey then |
frame:EnableKeyboard(false) |
self.msgframe:Hide() |
frame:UnlockHighlight() |
self.waitingForKey = nil |
else |
frame:EnableKeyboard(true) |
self.msgframe:Show() |
frame:LockHighlight() |
self.waitingForKey = true |
local function Keybinding_OnClick(this, button) |
if button == "LeftButton" or button == "RightButton" then |
local self = this.obj |
if self.waitingForKey then |
this:EnableKeyboard(false) |
self.msgframe:Hide() |
this:UnlockHighlight() |
self.waitingForKey = nil |
else |
this:EnableKeyboard(true) |
self.msgframe:Show() |
this:LockHighlight() |
self.waitingForKey = true |
end |
end |
AceGUI:ClearFocus() |
end |
AceGUI:ClearFocus() |
end |
local ignoreKeys = { |
["BUTTON1"] = true, ["BUTTON2"] = true, |
["UNKNOWN"] = true, |
["LSHIFT"] = true, ["LCTRL"] = true, ["LALT"] = true, |
["RSHIFT"] = true, ["RCTRL"] = true, ["RALT"] = true, |
} |
local function Keybinding_OnKeyDown(frame, key) |
local self = frame.obj |
if self.waitingForKey then |
local keyPressed = key |
if keyPressed == "ESCAPE" then |
keyPressed = "" |
else |
if ignoreKeys[keyPressed] then return end |
if IsShiftKeyDown() then |
keyPressed = "SHIFT-"..keyPressed |
local ignoreKeys = nil |
local function Keybinding_OnKeyDown(this, key) |
local self = this.obj |
if self.waitingForKey then |
local keyPressed = key |
if keyPressed == "ESCAPE" then |
keyPressed = "" |
else |
if not ignoreKeys then |
ignoreKeys = { |
["BUTTON1"] = true, ["BUTTON2"] = true, |
["UNKNOWN"] = true, |
["LSHIFT"] = true, ["LCTRL"] = true, ["LALT"] = true, |
["RSHIFT"] = true, ["RCTRL"] = true, ["RALT"] = true, |
} |
end |
if ignoreKeys[keyPressed] then return end |
if IsShiftKeyDown() then |
keyPressed = "SHIFT-"..keyPressed |
end |
if IsControlKeyDown() then |
keyPressed = "CTRL-"..keyPressed |
end |
if IsAltKeyDown() then |
keyPressed = "ALT-"..keyPressed |
end |
end |
if IsControlKeyDown() then |
keyPressed = "CTRL-"..keyPressed |
this:EnableKeyboard(false) |
self.msgframe:Hide() |
this:UnlockHighlight() |
self.waitingForKey = nil |
if not self.disabled then |
self:SetKey(keyPressed) |
self:Fire("OnKeyChanged",keyPressed) |
end |
if IsAltKeyDown() then |
keyPressed = "ALT-"..keyPressed |
end |
end |
frame:EnableKeyboard(false) |
self.msgframe:Hide() |
frame:UnlockHighlight() |
self.waitingForKey = nil |
if not self.disabled then |
self:SetKey(keyPressed) |
self:Fire("OnKeyChanged", keyPressed) |
end |
local function Keybinding_OnMouseDown(this, button) |
if button == "LeftButton" or button == "RightButton" then |
return |
elseif button == "MiddleButton" then |
button = "BUTTON3" |
elseif button == "Button4" then |
button = "BUTTON4" |
elseif button == "Button5" then |
button = "BUTTON5" |
end |
Keybinding_OnKeyDown(this, button) |
end |
end |
local function Keybinding_OnMouseDown(frame, button) |
if button == "LeftButton" or button == "RightButton" then |
return |
elseif button == "MiddleButton" then |
button = "BUTTON3" |
elseif button == "Button4" then |
button = "BUTTON4" |
elseif button == "Button5" then |
button = "BUTTON5" |
end |
Keybinding_OnKeyDown(frame, button) |
end |
--[[----------------------------------------------------------------------------- |
Methods |
-------------------------------------------------------------------------------]] |
local methods = { |
["OnAcquire"] = function(self) |
local function OnAcquire(self) |
self:SetWidth(200) |
self:SetHeight(44) |
self:SetLabel("") |
self:SetKey("") |
end |
local function OnRelease(self) |
self.frame:ClearAllPoints() |
self.frame:Hide() |
self.waitingForKey = nil |
self.msgframe:Hide() |
self:SetDisabled(false) |
self.button:EnableKeyboard(false) |
end, |
-- ["OnRelease"] = nil, |
["SetDisabled"] = function(self, disabled) |
end |
local function SetDisabled(self, disabled) |
self.disabled = disabled |
if disabled then |
self.button:Disable() |
self.button:Enable() |
self.label:SetTextColor(1,1,1) |
end |
end, |
["SetKey"] = function(self, key) |
end |
local function SetKey(self, key) |
if (key or "") == "" then |
self.button:SetText(NOT_BOUND) |
self.button:SetNormalFontObject("GameFontNormal") |
self.button:SetText(key) |
self.button:SetNormalFontObject("GameFontHighlight") |
end |
end, |
["GetKey"] = function(self) |
local key = self.button:GetText() |
if key == NOT_BOUND then |
key = nil |
end |
return key |
end, |
["SetLabel"] = function(self, label) |
end |
local function SetLabel(self, label) |
self.label:SetText(label or "") |
if (label or "") == "" then |
self.alignoffset = nil |
self.alignoffset = 30 |
self:SetHeight(44) |
end |
end, |
} |
end |
--[[----------------------------------------------------------------------------- |
Constructor |
-------------------------------------------------------------------------------]] |
local function Constructor() |
local num = AceGUI:GetNextWidgetNum(Type) |
local frame = CreateFrame("Frame",nil,UIParent) |
local button = CreateFrame("Button","AceGUI-3.0 KeybindingButton"..num,frame,"UIPanelButtonTemplate2") |
local self = {} |
self.type = Type |
self.num = num |
local ControlBackdrop = { |
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", |
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", |
tile = true, tileSize = 16, edgeSize = 16, |
insets = { left = 3, right = 3, top = 3, bottom = 3 } |
} |
local text = button:GetFontString() |
text:SetPoint("LEFT",button,"LEFT",7,0) |
text:SetPoint("RIGHT",button,"RIGHT",-7,0) |
button:SetScript("OnClick",Keybinding_OnClick) |
button:SetScript("OnKeyDown",Keybinding_OnKeyDown) |
button:SetScript("OnEnter",Control_OnEnter) |
button:SetScript("OnLeave",Control_OnLeave) |
button:SetScript("OnMouseDown",Keybinding_OnMouseDown) |
button:RegisterForClicks("AnyDown") |
button:EnableMouse() |
button:SetHeight(24) |
button:SetWidth(200) |
button:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT",0,0) |
button:SetPoint("BOTTOMRIGHT",frame,"BOTTOMRIGHT",0,0) |
frame:SetWidth(200) |
frame:SetHeight(44) |
self.alignoffset = 30 |
self.button = button |
local label = frame:CreateFontString(nil,"OVERLAY","GameFontHighlight") |
label:SetPoint("TOPLEFT",frame,"TOPLEFT",0,0) |
label:SetPoint("TOPRIGHT",frame,"TOPRIGHT",0,0) |
label:SetJustifyH("CENTER") |
label:SetHeight(18) |
self.label = label |
local msgframe = CreateFrame("Frame",nil,UIParent) |
msgframe:SetHeight(30) |
msgframe:SetBackdrop(ControlBackdrop) |
msgframe:SetBackdropColor(0,0,0) |
msgframe:SetFrameStrata("FULLSCREEN_DIALOG") |
msgframe:SetFrameLevel(1000) |
self.msgframe = msgframe |
local msg = msgframe:CreateFontString(nil,"OVERLAY","GameFontNormal") |
msg:SetText("Press a key to bind, ESC to clear the binding or click the button again to cancel") |
msgframe.msg = msg |
msg:SetPoint("TOPLEFT",msgframe,"TOPLEFT",5,-5) |
msgframe:SetScript("OnUpdate", keybindingMsgFixWidth) |
msgframe:SetPoint("BOTTOM",button,"TOP",0,0) |
msgframe:Hide() |
self.OnRelease = OnRelease |
self.OnAcquire = OnAcquire |
self.SetLabel = SetLabel |
self.SetDisabled = SetDisabled |
self.SetKey = SetKey |
self.frame = frame |
frame.obj = self |
button.obj = self |
local function keybindingMsgFixWidth(frame) |
frame:SetWidth(frame.msg:GetWidth() + 10) |
frame:SetScript("OnUpdate", nil) |
end |
local function Constructor() |
local name = "AceGUI30KeybindingButton" .. AceGUI:GetNextWidgetNum(Type) |
local frame = CreateFrame("Frame", nil, UIParent) |
local button = CreateFrame("Button", name, frame, wowMoP and "UIPanelButtonTemplate" or "UIPanelButtonTemplate2") |
button:EnableMouse(true) |
button:RegisterForClicks("AnyDown") |
button:SetScript("OnEnter", Control_OnEnter) |
button:SetScript("OnLeave", Control_OnLeave) |
button:SetScript("OnClick", Keybinding_OnClick) |
button:SetScript("OnKeyDown", Keybinding_OnKeyDown) |
button:SetScript("OnMouseDown", Keybinding_OnMouseDown) |
button:SetPoint("BOTTOMLEFT") |
button:SetPoint("BOTTOMRIGHT") |
button:SetHeight(24) |
button:EnableKeyboard(false) |
local text = button:GetFontString() |
text:SetPoint("LEFT", 7, 0) |
text:SetPoint("RIGHT", -7, 0) |
local label = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight") |
label:SetPoint("TOPLEFT") |
label:SetPoint("TOPRIGHT") |
label:SetJustifyH("CENTER") |
label:SetHeight(18) |
local msgframe = CreateFrame("Frame", nil, UIParent) |
msgframe:SetHeight(30) |
msgframe:SetBackdrop(ControlBackdrop) |
msgframe:SetBackdropColor(0,0,0) |
msgframe:SetFrameStrata("FULLSCREEN_DIALOG") |
msgframe:SetFrameLevel(1000) |
msgframe:SetToplevel(true) |
local msg = msgframe:CreateFontString(nil, "OVERLAY", "GameFontNormal") |
msg:SetText("Press a key to bind, ESC to clear the binding or click the button again to cancel.") |
msgframe.msg = msg |
msg:SetPoint("TOPLEFT", 5, -5) |
msgframe:SetScript("OnUpdate", keybindingMsgFixWidth) |
msgframe:SetPoint("BOTTOM", button, "TOP") |
msgframe:Hide() |
local widget = { |
button = button, |
label = label, |
msgframe = msgframe, |
frame = frame, |
alignoffset = 30, |
type = Type |
} |
for method, func in pairs(methods) do |
widget[method] = func |
AceGUI:RegisterAsWidget(self) |
return self |
end |
button.obj = widget |
return AceGUI:RegisterAsWidget(widget) |
AceGUI:RegisterWidgetType(Type,Constructor,Version) |
end |
AceGUI:RegisterWidgetType(Type, Constructor, Version) |
--[[----------------------------------------------------------------------------- |
Checkbox Widget |
-------------------------------------------------------------------------------]] |
local Type, Version = "CheckBox", 22 |
local AceGUI = LibStub and LibStub("AceGUI-3.0", true) |
if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end |
local AceGUI = LibStub("AceGUI-3.0") |
-- Lua APIs |
local select, pairs = select, pairs |
local select = select |
-- WoW APIs |
local PlaySound = PlaySound |
-- List them here for Mikk's FindGlobals script |
-- GLOBALS: SetDesaturation, GameFontHighlight |
--[[----------------------------------------------------------------------------- |
Support functions |
-------------------------------------------------------------------------------]] |
local function AlignImage(self) |
local img = self.image:GetTexture() |
self.text:ClearAllPoints() |
if not img then |
self.text:SetPoint("LEFT", self.checkbg, "RIGHT") |
self.text:SetPoint("RIGHT") |
else |
self.text:SetPoint("LEFT", self.image,"RIGHT", 1, 0) |
self.text:SetPoint("RIGHT") |
end |
end |
-------------------------- |
-- Check Box -- |
-------------------------- |
--[[ |
Events : |
OnValueChanged |
--[[----------------------------------------------------------------------------- |
Scripts |
-------------------------------------------------------------------------------]] |
local function Control_OnEnter(frame) |
frame.obj:Fire("OnEnter") |
end |
local function Control_OnLeave(frame) |
frame.obj:Fire("OnLeave") |
end |
local function CheckBox_OnMouseDown(frame) |
local self = frame.obj |
if not self.disabled then |
if self.image:GetTexture() then |
self.text:SetPoint("LEFT", self.image,"RIGHT", 2, -1) |
else |
self.text:SetPoint("LEFT", self.checkbg, "RIGHT", 1, -1) |
end |
end |
AceGUI:ClearFocus() |
end |
local function CheckBox_OnMouseUp(frame) |
local self = frame.obj |
if not self.disabled then |
self:ToggleChecked() |
if self.checked then |
PlaySound("igMainMenuOptionCheckBoxOn") |
else -- for both nil and false (tristate) |
PlaySound("igMainMenuOptionCheckBoxOff") |
end |
self:Fire("OnValueChanged", self.checked) |
AlignImage(self) |
end |
end |
--[[----------------------------------------------------------------------------- |
Methods |
-------------------------------------------------------------------------------]] |
local methods = { |
["OnAcquire"] = function(self) |
self:SetType() |
]] |
do |
local Type = "CheckBox" |
local Version = 16 |
local function OnAcquire(self) |
self:SetValue(false) |
self:SetTriState(nil) |
-- height is calculated from the width and required space for the description |
self.tristate = nil |
self:SetHeight(24) |
self:SetWidth(200) |
self:SetImage() |
self:SetDisabled(nil) |
end |
local function OnRelease(self) |
self.frame:ClearAllPoints() |
self.frame:Hide() |
self.check:Hide() |
self.highlight:Hide() |
self.down = nil |
self.checked = nil |
self:SetType() |
self:SetDisabled(false) |
self:SetDescription(nil) |
end, |
-- ["OnRelease"] = nil, |
["OnWidthSet"] = function(self, width) |
if self.desc then |
self.desc:SetWidth(width - 30) |
if self.desc:GetText() and self.desc:GetText() ~= "" then |
self:SetHeight(28 + self.desc:GetHeight()) |
end |
local function CheckBox_OnEnter(this) |
local self = this.obj |
self.highlight:Show() |
self:Fire("OnEnter") |
end |
local function CheckBox_OnLeave(this) |
local self = this.obj |
self.highlight:Hide() |
self:Fire("OnLeave") |
end |
local function CheckBox_OnMouseUp(this) |
local self = this.obj |
if not self.disabled then |
self:ToggleChecked() |
if self.checked then |
PlaySound("igMainMenuOptionCheckBoxOn") |
else -- for both nil and false (tristate) |
PlaySound("igMainMenuOptionCheckBoxOff") |
end |
self:Fire("OnValueChanged",self.checked) |
self.text:SetPoint("LEFT",self.check,"RIGHT",0,0) |
end |
end, |
self.down = nil |
end |
local function CheckBox_OnMouseDown(this) |
local self = this.obj |
if not self.disabled then |
self.text:SetPoint("LEFT",self.check,"RIGHT",1,-1) |
self.down = true |
end |
AceGUI:ClearFocus() |
end |
["SetDisabled"] = function(self, disabled) |
local function SetDisabled(self,disabled) |
self.disabled = disabled |
if disabled then |
self.frame:Disable() |
self.text:SetTextColor(0.5, 0.5, 0.5) |
self.text:SetTextColor(0.5,0.5,0.5) |
SetDesaturation(self.check, true) |
if self.desc then |
self.desc:SetTextColor(0.5, 0.5, 0.5) |
end |
else |
self.frame:Enable() |
self.text:SetTextColor(1, 1, 1) |
self.text:SetTextColor(1,1,1) |
if self.tristate and self.checked == nil then |
SetDesaturation(self.check, true) |
else |
SetDesaturation(self.check, false) |
end |
if self.desc then |
self.desc:SetTextColor(1, 1, 1) |
end |
end |
end, |
["SetValue"] = function(self,value) |
end |
local function SetValue(self,value) |
local check = self.check |
self.checked = value |
if value then |
self.check:Hide() |
end |
end |
self:SetDisabled(self.disabled) |
end, |
["GetValue"] = function(self) |
return self.checked |
end, |
["SetTriState"] = function(self, enabled) |
SetDisabled(self, self.disabled) |
end |
local function SetTriState(self, enabled) |
self.tristate = enabled |
self:SetValue(self:GetValue()) |
end, |
["SetType"] = function(self, type) |
end |
local function GetValue(self) |
return self.checked |
end |
local function SetType(self, type) |
local checkbg = self.checkbg |
local check = self.check |
local highlight = self.highlight |
local size |
if type == "radio" then |
size = 16 |
checkbg:SetHeight(16) |
checkbg:SetWidth(16) |
checkbg:SetTexture("Interface\\Buttons\\UI-RadioButton") |
checkbg:SetTexCoord(0, 0.25, 0, 1) |
checkbg:SetTexCoord(0,0.25,0,1) |
check:SetHeight(16) |
check:SetWidth(16) |
check:SetTexture("Interface\\Buttons\\UI-RadioButton") |
check:SetTexCoord(0.25, 0.5, 0, 1) |
check:SetTexCoord(0.25,0.5,0,1) |
check:SetBlendMode("ADD") |
highlight:SetTexture("Interface\\Buttons\\UI-RadioButton") |
highlight:SetTexCoord(0.5, 0.75, 0, 1) |
highlight:SetTexCoord(0.5,0.75,0,1) |
else |
size = 24 |
checkbg:SetHeight(24) |
checkbg:SetWidth(24) |
checkbg:SetTexture("Interface\\Buttons\\UI-CheckBox-Up") |
checkbg:SetTexCoord(0, 1, 0, 1) |
checkbg:SetTexCoord(0,1,0,1) |
check:SetHeight(24) |
check:SetWidth(24) |
check:SetTexture("Interface\\Buttons\\UI-CheckBox-Check") |
check:SetTexCoord(0, 1, 0, 1) |
check:SetTexCoord(0,1,0,1) |
check:SetBlendMode("BLEND") |
highlight:SetTexture("Interface\\Buttons\\UI-CheckBox-Highlight") |
highlight:SetTexCoord(0, 1, 0, 1) |
highlight:SetTexCoord(0,1,0,1) |
end |
checkbg:SetHeight(size) |
checkbg:SetWidth(size) |
end, |
["ToggleChecked"] = function(self) |
end |
local function ToggleChecked(self) |
local value = self:GetValue() |
if self.tristate then |
--cycle in true, nil, false order |
else |
self:SetValue(not self:GetValue()) |
end |
end, |
["SetLabel"] = function(self, label) |
end |
local function SetLabel(self, label) |
self.text:SetText(label) |
end, |
["SetDescription"] = function(self, desc) |
end |
local function SetDescription(self, desc) |
if desc then |
if not self.desc then |
local desc = self.frame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall") |
desc:ClearAllPoints() |
desc:SetPoint("TOPLEFT", self.checkbg, "TOPRIGHT", 5, -21) |
desc:SetPoint("TOPLEFT", self.check, "TOPRIGHT", 5, -21) |
desc:SetWidth(self.frame.width - 30) |
desc:SetJustifyH("LEFT") |
desc:SetJustifyV("TOP") |
self.desc:SetText("") |
self.desc:Hide() |
end |
--self.text:SetFontObject(GameFontHighlight) |
self.text:SetFontObject(GameFontHighlight) |
self:SetHeight(24) |
end |
end, |
end |
["SetImage"] = function(self, path, ...) |
local function SetImage(self, path, ...) |
local image = self.image |
image:SetTexture(path) |
if image:GetTexture() then |
local n = select("#", ...) |
local n = select('#', ...) |
if n == 4 or n == 8 then |
image:SetTexCoord(...) |
else |
image:SetTexCoord(0, 1, 0, 1) |
end |
end |
AlignImage(self) |
self:AlignImage() |
end |
} |
local function AlignImage(self) |
local img = self.image:GetTexture() |
self.text:ClearAllPoints() |
if not img then |
self.text:SetPoint("LEFT", self.check, "RIGHT", 0, 0) |
self.text:SetPoint("RIGHT", self.frame, "RIGHT", 0, 0) |
else |
self.text:SetPoint("LEFT", self.image,"RIGHT", 1, 0) |
self.text:SetPoint("RIGHT", self.frame,"RIGHT", 0, 0) |
end |
end |
local function OnWidthSet(self, width) |
if self.desc and self.desc:GetText() ~= "" and self.desc:GetText() ~= nil then |
self.desc:SetWidth(width - 30) |
self:SetHeight(28 + self.desc:GetHeight()) |
end |
end |
local function Constructor() |
local frame = CreateFrame("Button",nil,UIParent) |
local self = {} |
self.type = Type |
--[[----------------------------------------------------------------------------- |
Constructor |
-------------------------------------------------------------------------------]] |
local function Constructor() |
local frame = CreateFrame("Button", nil, UIParent) |
frame:Hide() |
self.OnRelease = OnRelease |
self.OnAcquire = OnAcquire |
frame:EnableMouse(true) |
frame:SetScript("OnEnter", Control_OnEnter) |
frame:SetScript("OnLeave", Control_OnLeave) |
frame:SetScript("OnMouseDown", CheckBox_OnMouseDown) |
frame:SetScript("OnMouseUp", CheckBox_OnMouseUp) |
local checkbg = frame:CreateTexture(nil, "ARTWORK") |
checkbg:SetWidth(24) |
checkbg:SetHeight(24) |
checkbg:SetPoint("TOPLEFT") |
checkbg:SetTexture("Interface\\Buttons\\UI-CheckBox-Up") |
local check = frame:CreateTexture(nil, "OVERLAY") |
check:SetAllPoints(checkbg) |
check:SetTexture("Interface\\Buttons\\UI-CheckBox-Check") |
local text = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight") |
text:SetJustifyH("LEFT") |
text:SetHeight(18) |
text:SetPoint("LEFT", checkbg, "RIGHT") |
text:SetPoint("RIGHT") |
local highlight = frame:CreateTexture(nil, "HIGHLIGHT") |
highlight:SetTexture("Interface\\Buttons\\UI-CheckBox-Highlight") |
highlight:SetBlendMode("ADD") |
highlight:SetAllPoints(checkbg) |
local image = frame:CreateTexture(nil, "OVERLAY") |
image:SetHeight(16) |
image:SetWidth(16) |
image:SetPoint("LEFT", checkbg, "RIGHT", 1, 0) |
local widget = { |
checkbg = checkbg, |
check = check, |
text = text, |
highlight = highlight, |
image = image, |
frame = frame, |
type = Type |
} |
for method, func in pairs(methods) do |
widget[method] = func |
self.SetValue = SetValue |
self.GetValue = GetValue |
self.SetDisabled = SetDisabled |
self.SetType = SetType |
self.ToggleChecked = ToggleChecked |
self.SetLabel = SetLabel |
self.SetTriState = SetTriState |
self.SetDescription = SetDescription |
self.OnWidthSet = OnWidthSet |
self.SetImage = SetImage |
self.AlignImage = AlignImage |
self.frame = frame |
frame.obj = self |
local text = frame:CreateFontString(nil,"OVERLAY","GameFontHighlight") |
self.text = text |
frame:SetScript("OnEnter",CheckBox_OnEnter) |
frame:SetScript("OnLeave",CheckBox_OnLeave) |
frame:SetScript("OnMouseUp",CheckBox_OnMouseUp) |
frame:SetScript("OnMouseDown",CheckBox_OnMouseDown) |
frame:EnableMouse() |
local checkbg = frame:CreateTexture(nil,"ARTWORK") |
self.checkbg = checkbg |
checkbg:SetWidth(24) |
checkbg:SetHeight(24) |
checkbg:SetPoint("TOPLEFT",frame,"TOPLEFT",0,0) |
checkbg:SetTexture("Interface\\Buttons\\UI-CheckBox-Up") |
local check = frame:CreateTexture(nil,"OVERLAY") |
self.check = check |
check:SetWidth(24) |
check:SetHeight(24) |
check:SetPoint("CENTER",checkbg,"CENTER",0,0) |
check:SetTexture("Interface\\Buttons\\UI-CheckBox-Check") |
local highlight = frame:CreateTexture(nil, "OVERLAY") |
self.highlight = highlight |
highlight:SetTexture("Interface\\Buttons\\UI-CheckBox-Highlight") |
highlight:SetBlendMode("ADD") |
highlight:SetAllPoints(checkbg) |
highlight:Hide() |
local image = frame:CreateTexture(nil, "OVERLAY") |
self.image = image |
image:SetHeight(16) |
image:SetWidth(16) |
image:SetPoint("LEFT", check, "RIGHT", 1, 0) |
text:SetJustifyH("LEFT") |
frame:SetHeight(24) |
frame:SetWidth(200) |
text:SetHeight(18) |
text:SetPoint("LEFT",check,"RIGHT",0,0) |
text:SetPoint("RIGHT",frame,"RIGHT",0,0) |
AceGUI:RegisterAsWidget(self) |
return self |
end |
return AceGUI:RegisterAsWidget(widget) |
AceGUI:RegisterWidgetType(Type,Constructor,Version) |
end |
AceGUI:RegisterWidgetType(Type, Constructor, Version) |
--[[----------------------------------------------------------------------------- |
Icon Widget |
-------------------------------------------------------------------------------]] |
local Type, Version = "Icon", 21 |
local AceGUI = LibStub and LibStub("AceGUI-3.0", true) |
if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end |
local AceGUI = LibStub("AceGUI-3.0") |
-- Lua APIs |
local select, pairs, print = select, pairs, print |
local select = select |
-- WoW APIs |
local CreateFrame, UIParent, GetBuildInfo = CreateFrame, UIParent, GetBuildInfo |
local CreateFrame, UIParent = CreateFrame, UIParent |
--[[----------------------------------------------------------------------------- |
Scripts |
-------------------------------------------------------------------------------]] |
local function Control_OnEnter(frame) |
frame.obj:Fire("OnEnter") |
end |
local function Control_OnLeave(frame) |
frame.obj:Fire("OnLeave") |
end |
local function Button_OnClick(frame, button) |
frame.obj:Fire("OnClick", button) |
AceGUI:ClearFocus() |
end |
--[[----------------------------------------------------------------------------- |
Methods |
-------------------------------------------------------------------------------]] |
local methods = { |
["OnAcquire"] = function(self) |
-------------------------- |
-- Label -- |
-------------------------- |
do |
local Type = "Icon" |
local Version = 12 |
local function OnAcquire(self) |
self:SetHeight(110) |
self:SetWidth(110) |
self:SetLabel() |
self:SetLabel("") |
self:SetImage(nil) |
self:SetImageSize(64, 64) |
end |
local function OnRelease(self) |
self.frame:ClearAllPoints() |
self.frame:Hide() |
self:SetDisabled(false) |
end, |
-- ["OnRelease"] = nil, |
["SetLabel"] = function(self, text) |
end |
local function SetLabel(self, text) |
if text and text ~= "" then |
self.label:Show() |
self.label:SetText(text) |
self.label:Hide() |
self:SetHeight(self.image:GetHeight() + 10) |
end |
end, |
["SetImage"] = function(self, path, ...) |
end |
local function SetImage(self, path, ...) |
local image = self.image |
image:SetTexture(path) |
if image:GetTexture() then |
local n = select("#", ...) |
self.imageshown = true |
local n = select('#', ...) |
if n == 4 or n == 8 then |
image:SetTexCoord(...) |
else |
image:SetTexCoord(0, 1, 0, 1) |
end |
else |
self.imageshown = nil |
end |
end, |
["SetImageSize"] = function(self, width, height) |
end |
local function SetImageSize(self, width, height) |
self.image:SetWidth(width) |
self.image:SetHeight(height) |
--self.frame:SetWidth(width + 30) |
else |
self:SetHeight(height + 10) |
end |
end, |
["SetDisabled"] = function(self, disabled) |
end |
local function SetDisabled(self, disabled) |
self.disabled = disabled |
if disabled then |
self.frame:Disable() |
self.label:SetTextColor(0.5, 0.5, 0.5) |
self.label:SetTextColor(0.5,0.5,0.5) |
self.image:SetVertexColor(0.5, 0.5, 0.5, 0.5) |
else |
self.frame:Enable() |
self.label:SetTextColor(1, 1, 1) |
self.image:SetVertexColor(1, 1, 1, 1) |
self.label:SetTextColor(1,1,1) |
self.image:SetVertexColor(1, 1, 1) |
end |
end |
} |
local function OnClick(this, button) |
this.obj:Fire("OnClick", button) |
AceGUI:ClearFocus() |
end |
local function OnEnter(this) |
this.obj.highlight:Show() |
this.obj:Fire("OnEnter") |
end |
local function OnLeave(this) |
this.obj.highlight:Hide() |
this.obj:Fire("OnLeave") |
end |
--[[----------------------------------------------------------------------------- |
Constructor |
-------------------------------------------------------------------------------]] |
local function Constructor() |
local frame = CreateFrame("Button", nil, UIParent) |
frame:Hide() |
local function Constructor() |
local frame = CreateFrame("Button",nil,UIParent) |
local self = {} |
self.type = Type |
self.OnRelease = OnRelease |
self.OnAcquire = OnAcquire |
self.SetLabel = SetLabel |
self.frame = frame |
self.SetImage = SetImage |
self.SetImageSize = SetImageSize |
-- SetText should be deprecated along the way |
self.SetText = SetLabel |
self.SetDisabled = SetDisabled |
frame:EnableMouse(true) |
frame:SetScript("OnEnter", Control_OnEnter) |
frame:SetScript("OnLeave", Control_OnLeave) |
frame:SetScript("OnClick", Button_OnClick) |
local label = frame:CreateFontString(nil, "BACKGROUND", "GameFontHighlight") |
label:SetPoint("BOTTOMLEFT") |
label:SetPoint("BOTTOMRIGHT") |
label:SetJustifyH("CENTER") |
label:SetJustifyV("TOP") |
label:SetHeight(18) |
local image = frame:CreateTexture(nil, "BACKGROUND") |
image:SetWidth(64) |
image:SetHeight(64) |
image:SetPoint("TOP", 0, -5) |
local highlight = frame:CreateTexture(nil, "HIGHLIGHT") |
highlight:SetAllPoints(image) |
highlight:SetTexture("Interface\\PaperDollInfoFrame\\UI-Character-Tab-Highlight") |
highlight:SetTexCoord(0, 1, 0.23, 0.77) |
highlight:SetBlendMode("ADD") |
local widget = { |
label = label, |
image = image, |
frame = frame, |
type = Type |
} |
for method, func in pairs(methods) do |
widget[method] = func |
frame.obj = self |
frame:SetHeight(110) |
frame:SetWidth(110) |
frame:EnableMouse(true) |
frame:SetScript("OnClick", OnClick) |
frame:SetScript("OnLeave", OnLeave) |
frame:SetScript("OnEnter", OnEnter) |
local label = frame:CreateFontString(nil,"BACKGROUND","GameFontHighlight") |
label:SetPoint("BOTTOMLEFT",frame,"BOTTOMLEFT",0,0) |
label:SetPoint("BOTTOMRIGHT",frame,"BOTTOMRIGHT",0,0) |
label:SetJustifyH("CENTER") |
label:SetJustifyV("TOP") |
label:SetHeight(18) |
self.label = label |
local image = frame:CreateTexture(nil,"BACKGROUND") |
self.image = image |
image:SetWidth(64) |
image:SetHeight(64) |
image:SetPoint("TOP",frame,"TOP",0,-5) |
local highlight = frame:CreateTexture(nil,"OVERLAY") |
self.highlight = highlight |
highlight:SetAllPoints(image) |
highlight:SetTexture("Interface\\PaperDollInfoFrame\\UI-Character-Tab-Highlight") |
highlight:SetTexCoord(0,1,0.23,0.77) |
highlight:SetBlendMode("ADD") |
highlight:Hide() |
AceGUI:RegisterAsWidget(self) |
return self |
end |
-- SetText is deprecated, but keep it around for a while. (say, to WoW 4.0) |
if (select(4, GetBuildInfo()) < 40000) then |
widget.SetText = widget.SetLabel |
else |
widget.SetText = function(self, ...) print("AceGUI-3.0-Icon: SetText is deprecated! Use SetLabel instead!"); self:SetLabel(...) end |
end |
return AceGUI:RegisterAsWidget(widget) |
AceGUI:RegisterWidgetType(Type,Constructor,Version) |
end |
AceGUI:RegisterWidgetType(Type, Constructor, Version) |