diff Libs/DF/panel.lua @ 53:36b4d9559b69 v7.3.0.053

- framework update.
author Tercio
date Sat, 14 Oct 2017 17:09:17 -0300
parents 7d5934415ad0
children 307f5af3ad02
line wrap: on
line diff
--- a/Libs/DF/panel.lua	Sat Sep 02 12:43:20 2017 -0300
+++ b/Libs/DF/panel.lua	Sat Oct 14 17:09:17 2017 -0300
@@ -1223,13 +1223,27 @@
 		DF.IconPickFrame:SetHeight (227)
 		DF.IconPickFrame:EnableMouse (true)
 		DF.IconPickFrame:SetMovable (true)
-		DF.IconPickFrame:SetBackdrop ({bgFile = DF.folder .. "background", edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border", 
-		tile = true, tileSize = 32, edgeSize = 32, insets = {left = 5, right = 5, top = 5, bottom = 5}})
 		
-		DF.IconPickFrame:SetBackdropBorderColor (170/255, 170/255, 170/255)
+		DF.IconPickFrame:SetBackdrop ({edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true})
+
+		DF.IconPickFrame:SetBackdropBorderColor (0, 0, 0)
 		DF.IconPickFrame:SetBackdropColor (24/255, 24/255, 24/255, .8)
 		DF.IconPickFrame:SetFrameLevel (1)
 		
+		DF.IconPickFrame:SetScript ("OnMouseDown", function (self)
+			if (not self.isMoving) then
+				DF.IconPickFrame:StartMoving()
+				self.isMoving = true
+			end
+		end)
+		
+		DF.IconPickFrame:SetScript ("OnMouseUp", function (self)
+			if (self.isMoving) then
+				DF.IconPickFrame:StopMovingOrSizing()
+				self.isMoving = nil
+			end
+		end)
+		
 		DF.IconPickFrame.emptyFunction = function() end
 		DF.IconPickFrame.callback = DF.IconPickFrame.emptyFunction
 		
@@ -1267,37 +1281,37 @@
 		close_button:SetFrameLevel (close_button:GetFrameLevel()+2)
 		
 		local MACRO_ICON_FILENAMES = {}
+		local SPELLNAMES_CACHE = {}
+		
 		DF.IconPickFrame:SetScript ("OnShow", function()
-		
-			MACRO_ICON_FILENAMES = {};
-			MACRO_ICON_FILENAMES[1] = "INV_MISC_QUESTIONMARK";
+			
+			MACRO_ICON_FILENAMES [1] = "INV_MISC_QUESTIONMARK";
 			local index = 2;
 		
 			for i = 1, GetNumSpellTabs() do
-				local tab, tabTex, offset, numSpells, _ = GetSpellTabInfo(i);
-				offset = offset + 1;
-				local tabEnd = offset + numSpells;
+				local tab, tabTex, offset, numSpells, _ = GetSpellTabInfo (i)
+				offset = offset + 1
+				local tabEnd = offset + numSpells
+				
 				for j = offset, tabEnd - 1 do
 					--to get spell info by slot, you have to pass in a pet argument
-					local spellType, ID = GetSpellBookItemInfo(j, "player"); 
+					local spellType, ID = GetSpellBookItemInfo (j, "player")
 					if (spellType ~= "FUTURESPELL") then
-						local spellTexture = strupper(GetSpellBookItemTexture(j, "player"));
-						if ( not string.match( spellTexture, "INTERFACE\\BUTTONS\\") ) then
-							MACRO_ICON_FILENAMES[index] = gsub( spellTexture, "INTERFACE\\ICONS\\", "");
-							index = index + 1;
-						end
-					end
-					if (spellType == "FLYOUT") then
-						local _, _, numSlots, isKnown = GetFlyoutInfo(ID);
+						MACRO_ICON_FILENAMES [index] = GetSpellBookItemTexture (j, "player") or 0
+						index = index + 1;
+						
+					elseif (spellType == "FLYOUT") then
+						local _, _, numSlots, isKnown = GetFlyoutInfo (ID)
 						if (isKnown and numSlots > 0) then
 							for k = 1, numSlots do 
-								local spellID, overrideSpellID, isKnown = GetFlyoutSlotInfo(ID, k)
+								local spellID, overrideSpellID, isKnown = GetFlyoutSlotInfo (ID, k)
 								if (isKnown) then
-									MACRO_ICON_FILENAMES[index] = gsub( strupper(GetSpellTexture(spellID)), "INTERFACE\\ICONS\\", ""); 
+									MACRO_ICON_FILENAMES [index] = GetSpellTexture (spellID) or 0
 									index = index + 1;
 								end
 							end
 						end
+						
 					end
 				end
 			end
@@ -1305,12 +1319,12 @@
 			GetLooseMacroItemIcons (MACRO_ICON_FILENAMES)
 			GetLooseMacroIcons (MACRO_ICON_FILENAMES)
 			GetMacroIcons (MACRO_ICON_FILENAMES)
-			GetMacroItemIcons (MACRO_ICON_FILENAMES )
-			
+			GetMacroItemIcons (MACRO_ICON_FILENAMES)
+
 		end)
 		
 		DF.IconPickFrame:SetScript ("OnHide", function()
-			MACRO_ICON_FILENAMES = nil;
+			wipe (MACRO_ICON_FILENAMES)
 			collectgarbage()
 		end)
 		
@@ -1454,77 +1468,61 @@
 			if (DF.IconPickFrame.searching) then
 				filter = string_lower (DF.IconPickFrame.searching)
 			end
+
+			local pool
+			local shown = 0
 			
 			if (filter and filter ~= "") then
-				
-				local ignored = 0
-				local tryed = 0
-				local found = 0
-				local type = type
-				local buttons = DF.IconPickFrame.buttons
-				index = 1
-				
-				for i = 1, 60 do
-					
-					macroPopupIcon = buttons[i].icon
-					macroPopupButton = buttons[i]
-
-					for o = index, numMacroIcons do
-					
-						tryed = tryed + 1
-					
-						texture = MACRO_ICON_FILENAMES [o]
-						if (type (texture) == "number") then
-							macroPopupIcon:SetToFileData (texture)
-							texture = macroPopupIcon:GetTexture()
-							macroPopupIcon:SetTexture (nil)
-						else
-							texture = "INTERFACE\\ICONS\\" .. texture
-						end
-						
-						if (texture and texture:find (filter)) then
-							macroPopupIcon:SetTexture (texture)
-							macroPopupButton:Show()
-							found = found + 1
-							DF.IconPickFrame.last_filter_index = o
-							index = o+1
-							break
-						else
-							ignored = ignored + 1
-						end
-						
+				if (#SPELLNAMES_CACHE == 0) then
+					--build name cache
+					local GetSpellInfo = GetSpellInfo
+					for i = 1, #MACRO_ICON_FILENAMES do
+						local spellName = GetSpellInfo (MACRO_ICON_FILENAMES [i])
+						SPELLNAMES_CACHE [i] = spellName or "NULL"
 					end
 				end
+				
+				--do the filter
+				pool = {}
+				for i = 1, #SPELLNAMES_CACHE do
+					if (SPELLNAMES_CACHE [i]:find (filter)) then
+						pool [#pool+1] = MACRO_ICON_FILENAMES [i]
+						shown = shown + 1
+					end
+				end
+			else
+				shown = nil
+			end
 			
-				for o = found+1, 60 do
-					macroPopupButton = _G ["DetailsFrameworkIconPickFrameButton"..o]
+			if (not pool) then
+				pool = MACRO_ICON_FILENAMES
+			end
+			
+			for i = 1, 60 do
+				macroPopupIcon = _G ["DetailsFrameworkIconPickFrameButton"..i.."Icon"]
+				macroPopupButton = _G ["DetailsFrameworkIconPickFrameButton"..i]
+				index = (macroPopupOffset * 10) + i
+				texture = pool [index]
+				if ( index <= numMacroIcons and texture ) then
+
+					if (type (texture) == "number") then
+						macroPopupIcon:SetTexture (texture)
+					else
+						macroPopupIcon:SetTexture ("INTERFACE\\ICONS\\" .. texture)
+					end
+
+					macroPopupIcon:SetTexCoord (4/64, 60/64, 4/64, 60/64)
+					macroPopupButton.IconID = index
+					macroPopupButton:Show()
+				else
 					macroPopupButton:Hide()
 				end
-			else
-				for i = 1, 60 do
-					macroPopupIcon = _G ["DetailsFrameworkIconPickFrameButton"..i.."Icon"]
-					macroPopupButton = _G ["DetailsFrameworkIconPickFrameButton"..i]
-					index = (macroPopupOffset * 10) + i
-					texture = MACRO_ICON_FILENAMES [index]
-					if ( index <= numMacroIcons and texture ) then
+			end
 
-						if (type (texture) == "number") then
-							macroPopupIcon:SetToFileData (texture)
-						else
-							macroPopupIcon:SetTexture ("INTERFACE\\ICONS\\" .. texture)
-						end
-
-						macroPopupIcon:SetTexCoord (4/64, 60/64, 4/64, 60/64)
-						macroPopupButton.IconID = index
-						macroPopupButton:Show()
-					else
-						macroPopupButton:Hide()
-					end
-				end
-			end
+			pool = nil
 			
 			-- Scrollbar stuff
-			FauxScrollFrame_Update (scroll, ceil (numMacroIcons / 10) , 5, 20 )
+			FauxScrollFrame_Update (scroll, ceil ((shown or numMacroIcons) / 10) , 5, 20 )
 		end
 
 		DF.IconPickFrame.updateFunc = ChecksFrame_Update
@@ -3124,6 +3122,16 @@
 	spellicon:SetSize (16, 16)
 	f.spellicon = spellicon
 	
+	local text = f:CreateFontString (nil, "overlay", "GameFontNormal")
+	local textBackground = f:CreateTexture (nil, "artwork")
+	textBackground:SetSize (30, 16)
+	textBackground:SetColorTexture (0, 0, 0, 0.5)
+	textBackground:SetPoint ("bottom", f.ball, "top", 0, -6)
+	text:SetPoint ("center", textBackground, "center")
+	DF:SetFontSize (text, 10)
+	f.text = text
+	f.textBackground = textBackground
+	
 	local timeline = f:CreateFontString (nil, "overlay", "GameFontNormal")
 	timeline:SetPoint ("bottomright", f, "bottomright", -2, 0)
 	DF:SetFontSize (timeline, 8)
@@ -3195,6 +3203,15 @@
 		line.timeline:SetText (data.text)
 		line.timeline:Show()
 		
+		if (data.utext) then
+			line.text:Show()
+			line.textBackground:Show()
+			line.text:SetText (data.utext)
+		else
+			line.text:Hide()
+			line.textBackground:Hide()
+		end
+		
 		line.data = data
 		
 		o = o + 1
@@ -3601,13 +3618,6 @@
 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 -- ~scrollbox
 
-
--- preciso de uma fauxscroll que seja facil de lidar
--- ele cria scroll aqui, preciso falar a função que cria a linha e a função que atualiza
--- precisa passsar o tamanho em height width quantas barras vai mostrar
--- search box incluso opcionalmente
-
-
 DF.SortFunctions = {}
 
 local SortMember = ""
@@ -3642,7 +3652,7 @@
 		offset = FauxScrollFrame_GetOffset (self)
 	end	
 	
-	local okay, totalLines = pcall (self.refresh_func, self, self.data, offset, #self.Frames)
+	local okay, totalLines = pcall (self.refresh_func, self, self.data, offset, self.LineAmount)
 	if (not okay) then
 		error ("Details! FrameWork: Refresh(): " .. totalLines)
 	end
@@ -3657,6 +3667,19 @@
 	
 	self:Show()
 	
+	if (self.HideScrollBar) then
+		local frameName = self:GetName()
+		if (frameName) then
+			local scrollBar = _G [frameName .. "ScrollBar"]
+			if (scrollBar) then
+				scrollBar:Hide()
+			end
+		else
+		
+		end
+		
+	end
+	
 	return self.Frames
 end
 
@@ -3666,9 +3689,13 @@
 end
 
 DF.ScrollBoxFunctions.CreateLine = function (self, func)
+	if (not func) then
+		func = self.CreateLineFunc
+	end
 	local okay, newLine = pcall (func, self, #self.Frames+1)
 	if (okay) then
 		tinsert (self.Frames, newLine)
+		newLine.Index = #self.Frames
 		return newLine
 	else
 		error ("Details! FrameWork: CreateLine(): " .. newLine)
@@ -3690,14 +3717,85 @@
 	return self.data
 end
 
-function DF:CreateScrollBox (parent, name, refresh_func, data, width, height, line_amount, line_height)
+DF.ScrollBoxFunctions.GetFrames = function (self)
+	return self.Frames
+end
+
+DF.ScrollBoxFunctions.GetNumFramesCreated = function (self)
+	return #self.Frames
+end
+
+DF.ScrollBoxFunctions.GetNumFramesShown = function (self)
+	return self.LineAmount
+end
+
+DF.ScrollBoxFunctions.SetNumFramesShown = function (self, new_amount)
+	--> hide frames which won't be used
+	if (new_amount < #self.Frames) then
+		for i = new_amount+1, #self.Frames do
+			self.Frames [i]:Hide()
+		end
+	end
+	
+	--> set the new amount
+	self.LineAmount = new_amount
+end
+
+DF.ScrollBoxFunctions.SetFramesHeight = function (self, new_height)
+	self.LineHeight = new_height
+	self:OnSizeChanged()
+	self:Refresh()
+end
+
+DF.ScrollBoxFunctions.OnSizeChanged = function (self)
+	if (self.ReajustNumFrames) then
+		--> how many lines the scroll can show
+		local amountOfFramesToShow = floor (self:GetHeight() / self.LineHeight)
+		
+		--> how many lines the scroll already have
+		local totalFramesCreated = self:GetNumFramesCreated()
+		
+		--> how many lines are current shown
+		local totalFramesShown = self:GetNumFramesShown()
+
+		--> the amount of frames increased
+		if (amountOfFramesToShow > totalFramesShown) then
+			for i = totalFramesShown+1, amountOfFramesToShow do
+				--> check if need to create a new line
+				if (i > totalFramesCreated) then
+					self:CreateLine (self.CreateLineFunc)
+				end
+			end
+			
+		--> the amount of frames decreased
+		elseif (amountOfFramesToShow < totalFramesShown) then
+			--> hide all frames above the new amount to show
+			for i = totalFramesCreated, amountOfFramesToShow, -1 do
+				if (self.Frames [i]) then
+					self.Frames [i]:Hide()
+				end
+			end
+		end
+
+		--> set the new amount of frames
+		self:SetNumFramesShown (amountOfFramesToShow)
+		
+		--> refresh lines
+		self:Refresh()
+	end
+end
+
+function DF:CreateScrollBox (parent, name, refresh_func, data, width, height, line_amount, line_height, create_line_func, auto_amount, no_scroll)
 	local scroll = CreateFrame ("scrollframe", name, parent, "FauxScrollFrameTemplate")
 	
 	scroll:SetSize (width, height)
 	scroll.LineAmount = line_amount
 	scroll.LineHeight = line_height
 	scroll.IsFauxScroll = true
+	scroll.HideScrollBar = no_scroll
 	scroll.Frames = {}
+	scroll.ReajustNumFrames = auto_amount
+	scroll.CreateLineFunc = create_line_func
 	
 	DF:Mixin (scroll, DF.SortFunctions)
 	DF:Mixin (scroll, DF.ScrollBoxFunctions)
@@ -3706,9 +3804,38 @@
 	scroll.data = data
 	
 	scroll:SetScript ("OnVerticalScroll", scroll.OnVerticalScroll)
+	scroll:SetScript ("OnSizeChanged", DF.ScrollBoxFunctions.OnSizeChanged)
 	
 	return scroll
 end
 
 
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+-- ~resizers
 
+function DF:CreateResizeGrips (parent)
+	if (parent) then
+		local parentName = parent:GetName()
+		
+		local leftResizer = CreateFrame ("button", parentName and parentName .. "LeftResizer" or nil, parent)
+		local rightResizer = CreateFrame ("button", parentName and parentName .. "RightResizer" or nil, parent)
+		
+		leftResizer:SetPoint ("bottomleft", parent, "bottomleft")
+		rightResizer:SetPoint ("bottomright", parent, "bottomright")
+		leftResizer:SetSize (16, 16)
+		rightResizer:SetSize (16, 16)
+		
+		rightResizer:SetNormalTexture ([[Interface\CHATFRAME\UI-ChatIM-SizeGrabber-Up]])
+		rightResizer:SetHighlightTexture ([[Interface\CHATFRAME\UI-ChatIM-SizeGrabber-Highlight]])
+		rightResizer:SetPushedTexture ([[Interface\CHATFRAME\UI-ChatIM-SizeGrabber-Down]])
+		leftResizer:SetNormalTexture ([[Interface\CHATFRAME\UI-ChatIM-SizeGrabber-Up]])
+		leftResizer:SetHighlightTexture ([[Interface\CHATFRAME\UI-ChatIM-SizeGrabber-Highlight]])
+		leftResizer:SetPushedTexture ([[Interface\CHATFRAME\UI-ChatIM-SizeGrabber-Down]])
+		
+		leftResizer:GetNormalTexture():SetTexCoord (1, 0, 0, 1)
+		leftResizer:GetHighlightTexture():SetTexCoord (1, 0, 0, 1)
+		leftResizer:GetPushedTexture():SetTexCoord (1, 0, 0, 1)
+		
+		return leftResizer, rightResizer
+	end
+end