View Single Post
09-12-14, 09:37 AM   #18
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Since i'm pretty sure i'll need this in the future here is a lua only fancy slider, it's pretty basic yet but still much better then the blizzard ones.

Lua Code:
  1. local function CreateSlider(parent)
  2.     local frame = CreateFrame("Slider", nil, parent)
  3.     frame:SetSize(200, 17)
  4.     frame:EnableMouseWheel(true)
  5.     frame:SetHitRectInsets(0, 0, -14, -15)
  6.     frame:SetMinMaxValues(0, 100)
  7.     frame:SetValue(50)
  8.     frame:SetValueStep(1)
  9.     frame:SetHitRectInsets(0, 0, 0, 0)
  10.     frame:SetObeyStepOnDrag(true)
  11.     frame:EnableMouseWheel(true)
  12.     frame:SetOrientation("Horizontal")
  13.     frame:SetBackdrop({
  14.         bgFile = "Interface\\Buttons\\UI-SliderBar-Background",
  15.         edgeFile = "Interface\\Buttons\\UI-SliderBar-Border",
  16.         tile = true,
  17.         edgeSize = 8,
  18.         tileSize = 8,
  19.         insets = {left = 3, right = 3, top = 6, bottom = 6}
  20.     })
  21.     frame:SetBackdropBorderColor(0.7, 0.7, 0.7, 1.0)
  22.     frame:SetScript("OnEnter", function(self)
  23.         self:SetBackdropBorderColor(1, 1, 1, 1)
  24.     end)
  25.     frame:SetScript("OnLeave", function(self)
  26.         self:SetBackdropBorderColor(0.7, 0.7, 0.7, 1.0)
  27.     end)
  28.     frame:SetScript("OnMouseWheel", function(self, delta)
  29.         if delta > 0 then
  30.             self:SetValue(self:GetValue() + self:GetValueStep())
  31.         else
  32.             self:SetValue(self:GetValue() - self:GetValueStep())
  33.         end
  34.     end)
  35.     frame:SetScript("OnValueChanged", function(self, value)
  36.         frame.EditBox:SetText(value)
  37.     end)
  38.     frame.MinLabel = frame:CreateFontString(nil, "Overlay")
  39.     frame.MinLabel:SetFontObject(GameFontHighlightSmall)
  40.     frame.MinLabel:SetSize(0, 14)
  41.     frame.MinLabel:SetWordWrap(false)
  42.     frame.MinLabel:SetPoint("TopLeft", frame, "BottomLeft", 0, -1)
  43.     local min, max = frame:GetMinMaxValues()
  44.     frame.MinLabel:SetText(min)
  45.     frame.MaxLabel = frame:CreateFontString(nil, "Overlay")
  46.     frame.MaxLabel:SetFontObject(GameFontHighlightSmall)
  47.     frame.MaxLabel:SetSize(0, 14)
  48.     frame.MaxLabel:SetWordWrap(false)
  49.     frame.MaxLabel:SetPoint("TopRight", frame, "BottomRight", 0, -1)
  50.     frame.MaxLabel:SetText(max)
  51.     frame.Title = frame:CreateFontString(nil, "Overlay")
  52.     frame.Title:SetFontObject(GameFontNormal)
  53.     frame.Title:SetSize(0, 14)
  54.     frame.Title:SetWordWrap(false)
  55.     frame.Title:SetPoint("Bottom", frame, "Top")
  56.     frame.Title:SetText("Slider")
  57.     frame.Thumb = frame:CreateTexture(nil, "Artwork")
  58.     frame.Thumb:SetSize(32, 32)
  59.     frame.Thumb:SetTexture("Interface\\Buttons\\UI-SliderBar-Button-Horizontal")
  60.     frame:SetThumbTexture(frame.Thumb)
  61.     frame.EditBox = CreateFrame("EditBox", nil, frame)
  62.     frame.EditBox:EnableMouseWheel(true)
  63.     frame.EditBox:SetAutoFocus(false)
  64.     frame.EditBox:SetNumeric(false)
  65.     frame.EditBox:SetJustifyH("Center")
  66.     frame.EditBox:SetFontObject(GameFontHighlightSmall)
  67.     frame.EditBox:SetSize(50, 14)
  68.     frame.EditBox:SetPoint("Top", frame, "Bottom", 0, -1)
  69.     frame.EditBox:SetTextInsets(4, 4, 0, 0)
  70.     frame.EditBox:SetBackdrop({
  71.         bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
  72.         edgeFile = "Interface\\ChatFrame\\ChatFrameBackground",
  73.         tile = true,
  74.         edgeSize = 1,
  75.         tileSize = 5
  76.     })
  77.     frame.EditBox:SetBackdropColor(0, 0, 0, 1)
  78.     frame.EditBox:SetBackdropBorderColor(0.2, 0.2, 0.2, 1.0)
  79.     frame.EditBox:SetText(frame:GetValue())
  80.     --[[frame.EditBox:SetScript("OnShow", function(self)
  81.         self:SetText("")
  82.         self:SetText(frame:GetValue())
  83.     end)]]
  84.     if InterfaceOptionsFrame then
  85.         InterfaceOptionsFrame:HookScript("OnShow", function(self)
  86.             frame.EditBox:SetText("")
  87.             frame.EditBox:SetText(frame:GetValue())
  88.         end)
  89.     end
  90.     frame.EditBox:SetScript("OnEnter", function(self)
  91.         self:SetBackdropBorderColor(0.4, 0.4, 0.4, 1.0)
  92.     end)
  93.     frame.EditBox:SetScript("OnLeave", function(self)
  94.         self:SetBackdropBorderColor(0.2, 0.2, 0.2, 1.0)
  95.     end)
  96.     frame.EditBox:SetScript("OnMouseWheel", function(self, delta)
  97.         if delta > 0 then
  98.             frame:SetValue(frame:GetValue() + frame:GetValueStep())
  99.         else
  100.             frame:SetValue(frame:GetValue() - frame:GetValueStep())
  101.         end
  102.     end)
  103.     frame.EditBox:SetScript("OnEscapePressed", function(self)
  104.         self:ClearFocus()
  105.     end)
  106.     frame.EditBox:SetScript("OnEnterPressed", function(self)
  107.         local value = tonumber(self:GetText())
  108.         if value then
  109.             local min, max = frame:GetMinMaxValues()
  110.             if value >= min and value <= max then
  111.                 frame:SetValue(value)
  112.             elseif value < min then
  113.                 frame:SetValue(min)
  114.             elseif value > max then
  115.                 frame:SetValue(max)
  116.             end
  117.             frame.EditBox:SetText(frame:GetValue())
  118.         else
  119.             frame:SetValue(frame:GetValue())
  120.         end
  121.         self:ClearFocus()
  122.     end)
  123.     frame.EditBox:SetScript("OnEditFocusLost", function(self)
  124.         self:HighlightText(0, 0)
  125.     end)
  126.     frame.EditBox:SetScript("OnEditFocusGained", function(self)
  127.         self:HighlightText(0, -1)
  128.     end)
  129.     frame.Plus = CreateFrame("Button", nil, frame)
  130.     frame.Plus:SetSize(18, 18)
  131.     frame.Plus:RegisterForClicks("AnyUp")
  132.     frame.Plus:SetPoint("Left", frame.EditBox, "Right", 0, 0)
  133.     frame.Plus:SetNormalTexture("Interface\\Buttons\\UI-SpellbookIcon-NextPage-Up")
  134.     frame.Plus:SetPushedTexture("Interface\\Buttons\\UI-SpellbookIcon-NextPage-Down")
  135.     frame.Plus:SetHighlightTexture("Interface\\ChatFrame\\UI-ChatIcon-BlinkHilight")
  136.     frame.Plus:SetScript("OnClick", function(self)
  137.         frame:SetValue(frame:GetValue() + frame:GetValueStep())
  138.     end)
  139.     frame.Minus = CreateFrame("Button", nil, frame)
  140.     frame.Minus:SetSize(18, 18)
  141.     frame.Minus:RegisterForClicks("AnyUp")
  142.     frame.Minus:SetPoint("Right", frame.EditBox, "Left", 0, 0)
  143.     frame.Minus:SetNormalTexture("Interface\\Buttons\\UI-SpellbookIcon-PrevPage-Up")
  144.     frame.Minus:SetPushedTexture("Interface\\Buttons\\UI-SpellbookIcon-PrevPage-Down")
  145.     frame.Minus:SetHighlightTexture("Interface\\ChatFrame\\UI-ChatIcon-BlinkHilight")
  146.     frame.Minus:SetScript("OnClick", function(self)
  147.         frame:SetValue(frame:GetValue() - frame:GetValueStep())
  148.     end)
  149.     return frame
  150. end

Last edited by Resike : 09-12-14 at 09:52 AM.
  Reply With Quote