Quantcast

Removed GenericCreateButton() - it's better to hand-craft the buttons, especially when over half that were using it replaced the textures it set anyway.

James D. Callahan III [07-04-11 - 02:34]
Removed GenericCreateButton() - it's better to hand-craft the buttons, especially when over half that were using it replaced the textures it set anyway.
Filename
Interface/Common.lua
Interface/FilterMenus.lua
Interface/List.lua
Interface/Panel.lua
diff --git a/Interface/Common.lua b/Interface/Common.lua
index 2135a6e..d41ef40 100644
--- a/Interface/Common.lua
+++ b/Interface/Common.lua
@@ -118,127 +118,3 @@ do
 		frame:SetScript("OnLeave", Hide_Tooltip)
 	end
 end	-- do
-
--------------------------------------------------------------------------------
--- Generic function for creating buttons.
--------------------------------------------------------------------------------
-do
-	-- I hate stretchy buttons. Thanks very much to ckknight for this code
-	-- (found in RockConfig)
-
-	-- when pressed, the button should look pressed
-	local function button_OnMouseDown(self)
-		if self:IsEnabled() then
-			self.left:SetTexture([[Interface\Buttons\UI-Panel-Button-Down]])
-			self.middle:SetTexture([[Interface\Buttons\UI-Panel-Button-Down]])
-			self.right:SetTexture([[Interface\Buttons\UI-Panel-Button-Down]])
-		end
-	end
-
-	-- when depressed, return to normal
-	local function button_OnMouseUp(self)
-		if self:IsEnabled() then
-			self.left:SetTexture([[Interface\Buttons\UI-Panel-Button-Up]])
-			self.middle:SetTexture([[Interface\Buttons\UI-Panel-Button-Up]])
-			self.right:SetTexture([[Interface\Buttons\UI-Panel-Button-Up]])
-		end
-	end
-
-	local function button_Disable(self)
-		self.left:SetTexture([[Interface\Buttons\UI-Panel-Button-Disabled]])
-		self.middle:SetTexture([[Interface\Buttons\UI-Panel-Button-Disabled]])
-		self.right:SetTexture([[Interface\Buttons\UI-Panel-Button-Disabled]])
-		self:__Disable()
-		self:EnableMouse(false)
-	end
-
-	local function button_Enable(self)
-		self.left:SetTexture([[Interface\Buttons\UI-Panel-Button-Up]])
-		self.middle:SetTexture([[Interface\Buttons\UI-Panel-Button-Up]])
-		self.right:SetTexture([[Interface\Buttons\UI-Panel-Button-Up]])
-		self:__Enable()
-		self:EnableMouse(true)
-	end
-
-	function private.GenericCreateButton(name, parent, height, width, font_object, label, justify_h, tip_text, noTextures)
-		local button = CreateFrame("Button", name, parent)
-
-		button:SetHeight(height)
-		button:SetWidth(width)
-
-		if noTextures == 0 then
-			local highlight_texture = button:CreateTexture(nil, "BORDER")
-			highlight_texture:SetTexture([[Interface\ClassTrainerFrame\TrainerTextures]])
-			highlight_texture:SetTexCoord(0.00195313, 0.57421875, 0.75390625, 0.84570313)
-			highlight_texture:SetBlendMode("ADD")
-			highlight_texture:SetPoint("TOPLEFT", 2, 0)
-			highlight_texture:SetPoint("BOTTOMRIGHT", -2, 1)
-			button:SetHighlightTexture(highlight_texture)
-		elseif noTextures == 1 then
-			local left = button:CreateTexture(nil, "BACKGROUND")
-			button.left = left
-			left:SetTexture([[Interface\Buttons\UI-Panel-Button-Up]])
-
-			local middle = button:CreateTexture(nil, "BACKGROUND")
-			button.middle = middle
-			middle:SetTexture([[Interface\Buttons\UI-Panel-Button-Up]])
-
-			local right = button:CreateTexture(nil, "BACKGROUND")
-			button.right = right
-			right:SetTexture([[Interface\Buttons\UI-Panel-Button-Up]])
-
-			left:SetPoint("TOPLEFT")
-			left:SetPoint("BOTTOMLEFT")
-			left:SetWidth(12)
-			left:SetTexCoord(0, 0.09375, 0, 0.6875)
-
-			right:SetPoint("TOPRIGHT")
-			right:SetPoint("BOTTOMRIGHT")
-			right:SetWidth(12)
-			right:SetTexCoord(0.53125, 0.625, 0, 0.6875)
-
-			middle:SetPoint("TOPLEFT", left, "TOPRIGHT")
-			middle:SetPoint("BOTTOMRIGHT", right, "BOTTOMLEFT")
-			middle:SetTexCoord(0.09375, 0.53125, 0, 0.6875)
-
-			button:SetScript("OnMouseDown", button_OnMouseDown)
-			button:SetScript("OnMouseUp", button_OnMouseUp)
-
-			button.__Enable = button.Enable
-			button.__Disable = button.Disable
-			button.Enable = button_Enable
-			button.Disable = button_Disable
-
-			local highlight = button:CreateTexture(nil, "OVERLAY", "UIPanelButtonHighlightTexture")
-			button:SetHighlightTexture(highlight)
-		elseif noTextures == 2 then
-			button:SetNormalTexture("Interface\\Buttons\\UI-PlusButton-Up")
-			button:SetPushedTexture("Interface\\Buttons\\UI-PlusButton-Down")
-			button:SetHighlightTexture("Interface\\Buttons\\UI-PlusButton-Hilight")
-			button:SetDisabledTexture("Interface\\Buttons\\UI-PlusButton-Disabled")
-		elseif noTextures == 3 then
-			button:SetNormalTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Up")
-			button:SetPushedTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Down")
-			button:SetHighlightTexture("Interface\\Buttons\\UI-PlusButton-Hilight")
-			button:SetDisabledTexture("Interface\\Buttons\\UI-PlusButton-Disabled")
-		end
-
-		if font_object then
-			local text = button:CreateFontString(nil, "ARTWORK")
-			button:SetFontString(text)
-			button.text = text
-			text:SetPoint("LEFT", button, "LEFT", 7, 0)
-			text:SetPoint("RIGHT", button, "RIGHT", -7, 0)
-			text:SetJustifyH(justify_h)
-
-			text:SetFontObject(font_object)
-			text:SetText(label)
-		end
-
-		if tip_text and tip_text ~= "" then
-			private.SetTooltipScripts(button, tip_text)
-		end
-		return button
-	end
-end	-- do
-
diff --git a/Interface/FilterMenus.lua b/Interface/FilterMenus.lua
index 34a8732..a4ced56 100644
--- a/Interface/FilterMenus.lua
+++ b/Interface/FilterMenus.lua
@@ -25,7 +25,6 @@ local QTip	= LibStub("LibQTip-1.0")
 -- Upvalues
 -------------------------------------------------------------------------------
 local SetTextColor = private.SetTextColor
-local GenericCreateButton = private.GenericCreateButton
 local SetTooltipScripts = private.SetTooltipScripts

 -------------------------------------------------------------------------------
diff --git a/Interface/List.lua b/Interface/List.lua
index 967824d..6d28e06 100644
--- a/Interface/List.lua
+++ b/Interface/List.lua
@@ -53,7 +53,6 @@ local spell_tip
 local AcquireTable = private.AcquireTable
 local ReleaseTable = private.ReleaseTable
 local SetTextColor = private.SetTextColor
-local GenericCreateButton = private.GenericCreateButton

 -------------------------------------------------------------------------------
 -- Frame creation and anchoring
@@ -319,24 +318,45 @@ function private.InitializeListFrame()
 	ListFrame.state_buttons = {}
 	ListFrame.entry_buttons = {}

-	for i = 1, NUM_RECIPE_LINES do
+	for index = 1, NUM_RECIPE_LINES do
 		local cur_container = _G.CreateFrame("Frame", nil, ListFrame)

 		cur_container:SetHeight(16)
 		cur_container:SetWidth(LIST_ENTRY_WIDTH)

-		local cur_state = GenericCreateButton(nil, ListFrame, 16, 16, nil, nil, nil, nil, 2)
-		local cur_entry = GenericCreateButton(nil, ListFrame, 16, LIST_ENTRY_WIDTH, "GameFontNormalSmall", "Blort", "LEFT", nil, 0)
-		cur_entry.text:SetJustifyV("CENTER")
-
-		if i == 1 then
+		local cur_state = _G.CreateFrame("Button", nil, ListFrame)
+		cur_state:SetWidth(16)
+		cur_state:SetHeight(16)
+
+		local entry_name = ("%s_ListEntryButton%d"):format(FOLDER_NAME, index)
+		local cur_entry = _G.CreateFrame("Button", entry_name, cur_container)
+		cur_entry:SetWidth(LIST_ENTRY_WIDTH)
+		cur_entry:SetHeight(16)
+
+		local highlight_texture = cur_entry:CreateTexture(nil, "BORDER")
+		highlight_texture:SetTexture([[Interface\ClassTrainerFrame\TrainerTextures]])
+		highlight_texture:SetTexCoord(0.00195313, 0.57421875, 0.75390625, 0.84570313)
+		highlight_texture:SetBlendMode("ADD")
+		highlight_texture:SetPoint("TOPLEFT", 2, 0)
+		highlight_texture:SetPoint("BOTTOMRIGHT", -2, 1)
+		cur_entry:SetHighlightTexture(highlight_texture)
+
+		local label = cur_entry:CreateFontString(nil, "ARTWORK")
+		label:SetPoint("LEFT", cur_entry, "LEFT", 7, 0)
+		label:SetPoint("RIGHT", cur_entry, "RIGHT", -7, 0)
+		label:SetFontObject("GameFontNormalSmall")
+		label:SetJustifyH("LEFT")
+		label:SetJustifyV("CENTER")
+
+		cur_entry:SetFontString(label)
+		cur_entry.text = label
+
+		if index == 1 then
 			cur_container:SetPoint("TOPLEFT", ListFrame, "TOPLEFT", 0, -3)
 			cur_state:SetPoint("LEFT", cur_container, "LEFT", 0, 0)
 			cur_entry:SetPoint("LEFT", cur_state, "RIGHT", -3, 0)
 		else
-			local prev_container = ListFrame.button_containers[i - 1]
-
-			cur_container:SetPoint("TOPLEFT", prev_container, "BOTTOMLEFT", 0, 3)
+			cur_container:SetPoint("TOPLEFT", ListFrame.button_containers[index - 1], "BOTTOMLEFT", 0, 3)
 			cur_state:SetPoint("LEFT", cur_container, "LEFT", 0, 0)
 			cur_entry:SetPoint("LEFT", cur_state, "RIGHT", -3, 0)
 		end
@@ -345,9 +365,9 @@ function private.InitializeListFrame()
 		cur_state:SetScript("OnClick", ListItem_OnClick)
 		cur_entry:SetScript("OnClick", ListItem_OnClick)

-		ListFrame.button_containers[i] = cur_container
-		ListFrame.state_buttons[i] = cur_state
-		ListFrame.entry_buttons[i] = cur_entry
+		ListFrame.button_containers[index] = cur_container
+		ListFrame.state_buttons[index] = cur_state
+		ListFrame.entry_buttons[index] = cur_entry
 	end

 	function ListFrame:InsertEntry(entry, parent_entry, entry_index, entry_type, entry_expanded, expand_mode)
diff --git a/Interface/Panel.lua b/Interface/Panel.lua
index 6f21375..a8d9eac 100644
--- a/Interface/Panel.lua
+++ b/Interface/Panel.lua
@@ -48,7 +48,6 @@ local BFAC	= LibStub("LibBabble-Faction-3.0"):GetLookupTable()
 local AcquireTable = private.AcquireTable
 local ReleaseTable = private.ReleaseTable
 local SetTextColor = private.SetTextColor
-local GenericCreateButton = private.GenericCreateButton
 local SetTooltipScripts = private.SetTooltipScripts

 local A = private.acquire_types
@@ -819,7 +818,18 @@ function private.InitializeFrame()
 	expand_button_frame.middle:SetPoint("RIGHT", expand_button_frame.right, "LEFT")
 	expand_button_frame.middle:SetTexture("Interface\\QuestFrame\\UI-QuestLogSortTab-Middle")

-	local expand_button = GenericCreateButton(nil, MainPanel, 16, 16, "GameFontNormalSmall", _G.ALL, "LEFT", L["EXPANDALL_DESC"], 2)
+	local expand_button = _G.CreateFrame("Button", nil, MainPanel)
+	expand_button:SetWidth(16)
+	expand_button:SetHeight(16)
+
+	local expand_label = expand_button:CreateFontString(nil, "ARTWORK")
+	expand_label:SetFontObject("GameFontNormalSmall")
+	expand_label:SetPoint("LEFT", expand_button, "Right", 0, 0)
+	expand_label:SetJustifyH("LEFT")
+	expand_label:SetText(_G.ALL)
+
+	expand_button:SetFontString(expand_label)
+	private.SetTooltipScripts(expand_button, L["EXPANDALL_DESC"])

 	-- Make sure the button frame is large enough to hold the localized word for "All"
 	expand_button_frame:SetWidth(27 + expand_button:GetFontString():GetStringWidth())
@@ -828,9 +838,6 @@ function private.InitializeFrame()

 	expand_button:SetPoint("LEFT", expand_button_frame.left, "RIGHT", -3, -3)

-	expand_button.text:ClearAllPoints()
-	expand_button.text:SetPoint("LEFT", expand_button, "Right", 0, 0)
-
 	expand_button:SetScript("OnClick",
 			       function(self, mouse_button, down)
 				       local current_tab = MainPanel.tabs[MainPanel.current_tab]
@@ -947,9 +954,13 @@ function private.InitializeFrame()
 	-- Create MainPanel.filter_toggle, and set its scripts.
 	-------------------------------------------------------------------------------
 	do
-		local filter_toggle = GenericCreateButton(nil, MainPanel, 24, 24, nil, nil, nil, L["FILTER_OPEN_DESC"], 2)
+		local filter_toggle = _G.CreateFrame("Button", nil, MainPanel)
+		filter_toggle:SetWidth(24)
+		filter_toggle:SetHeight(24)
 		filter_toggle:SetPoint("TOPLEFT", MainPanel, "TOPLEFT", 323, -41)

+		private.SetTooltipScripts(filter_toggle, L["FILTER_OPEN_DESC"])
+
 		filter_toggle:SetScript("OnClick", function(self, button, down)
 			-- The first time this button is clicked, everything in the expanded section of the MainPanel must be created.
 			if private.InitializeFilterPanel then
@@ -980,13 +991,16 @@ function private.InitializeFrame()
 	-------------------------------------------------------------------------------
 	-- Sort-mode toggle button.
 	-------------------------------------------------------------------------------
-	local SortToggle = GenericCreateButton(nil, MainPanel, 24, 24, nil, nil, nil, L["SORTING_DESC"], 2)
+	local sort_toggle = _G.CreateFrame("Button", nil, MainPanel)
+	sort_toggle:SetWidth(24)
+	sort_toggle:SetHeight(24)
+	sort_toggle:SetPoint("LEFT", expand_button_frame, "RIGHT", 0, 2)

-	MainPanel.sort_button = SortToggle
+	private.SetTooltipScripts(sort_toggle, L["SORTING_DESC"])

-	SortToggle:SetPoint("LEFT", expand_button_frame, "RIGHT", 0, 2)
+	MainPanel.sort_button = sort_toggle

-	SortToggle:SetScript("OnClick",
+	sort_toggle:SetScript("OnClick",
 			     function(self, button, down)
 				     local sort_type = addon.db.profile.sorting

@@ -996,9 +1010,9 @@ function private.InitializeFrame()
 				     MainPanel.list_frame:Update(nil, false)
 			     end)

-	SortToggle:SetHighlightTexture([[Interface\CHATFRAME\UI-ChatIcon-BlinkHilight]])
+	sort_toggle:SetHighlightTexture([[Interface\CHATFRAME\UI-ChatIcon-BlinkHilight]])

-	function SortToggle:SetTextures()
+	function sort_toggle:SetTextures()
 		local sort_type = addon.db.profile.sorting

 		if sort_type == "Ascending" then
@@ -1051,14 +1065,19 @@ function private.InitializeFrame()
 	-------------------------------------------------------------------------------
 	-- Create the close button, and set its scripts.
 	-------------------------------------------------------------------------------
-	MainPanel.close_button = GenericCreateButton(nil, MainPanel, 24, 111, "GameFontNormalSmall", _G.EXIT, "CENTER", L["CLOSE_DESC"], 1)
-	MainPanel.close_button:SetPoint("LEFT", MainPanel.progress_bar, "RIGHT", 3, 1)
+	local close_button = _G.CreateFrame("Button", ("%s_CloseButton"):format(FOLDER_NAME), MainPanel, "UIPanelButtonTemplate")
+	close_button:SetWidth(111)
+	close_button:SetHeight(24)
+	close_button:SetPoint("LEFT", MainPanel.progress_bar, "RIGHT", 3, 1)
+	close_button:SetText(_G.EXIT)
+
+	MainPanel.close_button = close_button

-	MainPanel.close_button:SetScript("OnClick",
-					 function(self, button, down)
-						 MainPanel:Hide()
-					 end)
+	close_button:SetScript("OnClick", function(self, button, down)
+		MainPanel:Hide()
+	end)

+	private.SetTooltipScripts(close_button, L["CLOSE_DESC"])
 	-------------------------------------------------------------------------------
 	-- Initialize components defined in other files.
 	-------------------------------------------------------------------------------