public
Description: WoW Addon - Crowd control assistance
Homepage: http://www.tekkub.net
Clone URL: git://github.com/tekkub/controlfreak.git
Click here to lend your support to: controlfreak and make a donation at www.pledgie.com !
tekkub (author)
Tue Feb 19 01:00:29 -0800 2008
commit  9f70bf216bf5a1e3e41bef4443f2ebb0a773ecce
tree    7686f62e64904247c963f1a9a3ec782c20b0e919
parent  8335514aac6167b53c963282c472a6b64f3cb618
controlfreak / tekKonfigSlider.lua
100644 64 lines (49 sloc) 2.171 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
local lib, oldminor = LibStub:NewLibrary("tekKonfig-Slider", 1)
if not lib then return end
 
 
local GameTooltip = GameTooltip
local function HideTooltip() GameTooltip:Hide() end
local function ShowTooltip(self)
  if self.tiptext then
    GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
    GameTooltip:SetText(self.tiptext, nil, nil, nil, nil, true)
  end
end
 
 
local HorizontalSliderBG = {
  bgFile = "Interface\\Buttons\\UI-SliderBar-Background",
  edgeFile = "Interface\\Buttons\\UI-SliderBar-Border",
  edgeSize = 8, tile = true, tileSize = 8,
  insets = {left = 3, right = 3, top = 6, bottom = 6}
}
 
 
-- Create a slider.
-- All args optional, parent recommended
-- If lowvalue and highvalue are strings it is assumed they are % values
-- and the % is parsed and set as decimal values for min/max
function lib.new(parent, label, lowvalue, highvalue, ...)
  local container = CreateFrame("Frame", nil, parent)
  container:SetWidth(144)
  container:SetHeight(17+12+10)
  if select(1, ...) then container:SetPoint(...) end
 
  local slider = CreateFrame("Slider", nil, container)
  slider:SetPoint("LEFT")
  slider:SetPoint("RIGHT")
  slider:SetHeight(17)
  slider:SetHitRectInsets(0, 0, -10, -10)
  slider:SetOrientation("HORIZONTAL")
  slider:SetThumbTexture("Interface\\Buttons\\UI-SliderBar-Button-Horizontal") -- Dim: 32x32... can't find API to set this?
  slider:SetBackdrop(HorizontalSliderBG)
 
  local text = slider:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
  text:SetPoint("BOTTOM", slider, "TOP")
  text:SetText(label)
 
  local low = slider:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
  low:SetPoint("TOPLEFT", slider, "BOTTOMLEFT", -4, 3)
  low:SetText(lowvalue)
 
  local high = slider:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
  high:SetPoint("TOPRIGHT", slider, "BOTTOMRIGHT", 4, 3)
  high:SetText(highvalue)
 
  if type(lowvalue) == "string" then slider:SetMinMaxValues(tonumber((lowvalue:gsub("%%", "")))/100, tonumber((highvalue:gsub("%%", "")))/100)
  else slider:SetMinMaxValues(lowvalue, highvalue) end
 
  -- Tooltip bits
  slider:SetScript("OnEnter", ShowTooltip)
  slider:SetScript("OnLeave", HideTooltip)
 
  return slider, text, container, low, high
end