Thread Tools Display Modes
09-17-13, 05:01 AM   #1
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Slider problems

Since 5.4 hit my sliders has been completely nuts. However i could fix some of the issues, but this seems a bit weird. When i set the slider with mouse clicks then the sliders ValueStep get completely ignored. Aka on a slider with 0-3 value with 1 ValueStep you can stop the slider at 0.1123123, 0.2123123, 0.3123123 etc.. values. This make the sliders function so laggy it's unbearable. However if i use the mousewheel to adjust the slider then everything works perfectly. The fun part i don't even use inherited sliders. Here is my slider and some of it's functions:

Lua Code:
  1. <!-- Slider Template -->
  2.     <Slider name = "PowaBarSliderTemplate" orientation = "HORIZONTAL" virtual = "true" enableMouse = "true">
  3.         <Size>
  4.             <AbsDimension x = "144" y = "17"/>
  5.         </Size>
  6.         <HitRectInsets>
  7.             <AbsInset left = "0" right = "0" top = "-2" bottom = "1"/>
  8.         </HitRectInsets>
  9.         <Backdrop bgFile = "Interface\Buttons\UI-SliderBar-Background" edgeFile = "Interface\Buttons\UI-SliderBar-Border" tile = "true">
  10.             <EdgeSize>
  11.                 <AbsValue val = "8"/>
  12.             </EdgeSize>
  13.             <TileSize>
  14.                 <AbsValue val = "8"/>
  15.             </TileSize>
  16.             <BackgroundInsets>
  17.                 <AbsInset left = "3" right = "3" top = "6" bottom = "6"/>
  18.             </BackgroundInsets>
  19.         </Backdrop>
  20.         <Layers>
  21.             <Layer level = "ARTWORK">
  22.                 <FontString name = "$parentText" inherits = "GameFontNormalSmall">
  23.                     <Anchors>
  24.                         <Anchor point = "BOTTOM" relativePoint = "TOP"/>
  25.                     </Anchors>
  26.                 </FontString>
  27.                 <FontString name = "$parentLow" inherits = "GameFontHighlightSmall">
  28.                     <Anchors>
  29.                         <Anchor point = "TOPLEFT" relativePoint = "BOTTOMLEFT">
  30.                             <Offset>
  31.                                 <AbsDimension x = "0" y = "-2"/>
  32.                             </Offset>
  33.                         </Anchor>
  34.                     </Anchors>
  35.                 </FontString>
  36.                 <FontString name = "$parentHigh" inherits = "GameFontHighlightSmall">
  37.                     <Anchors>
  38.                         <Anchor point = "TOPRIGHT" relativePoint = "BOTTOMRIGHT">
  39.                             <Offset>
  40.                                 <AbsDimension x = "0" y = "-2"/>
  41.                             </Offset>
  42.                         </Anchor>
  43.                     </Anchors>
  44.                 </FontString>
  45.             </Layer>
  46.         </Layers>
  47.         <Frames>
  48.             <EditBox name = "$parentEditBox" autoFocus = "false">
  49.                 <Size>
  50.                     <AbsDimension x = "50" y = "14"/>
  51.                 </Size>
  52.                 <Anchors>
  53.                     <Anchor point = "TOP" relativePoint = "BOTTOM"/>
  54.                 </Anchors>
  55.                 <FontString inherits = "GameFontHighlightSmall"/>
  56.                 <Backdrop bgFile = "Interface\ChatFrame\ChatFrameBackground" edgeFile = "Interface\ChatFrame\ChatFrameBackground" tile = "true">
  57.                     <EdgeSize>
  58.                         <AbsValue val = "1"/>
  59.                     </EdgeSize>
  60.                     <TileSize>
  61.                         <AbsValue val = "5"/>
  62.                     </TileSize>
  63.                 </Backdrop>
  64.                 <Scripts>
  65.                     <OnLoad>
  66.                         self:EnableMouseWheel(true)
  67.                         self:SetBackdropBorderColor(0.3, 0.3, 0.3, 0.8)
  68.                         self:SetBackdropColor(0, 0, 0, 0.5)
  69.                         self:SetJustifyH("CENTER")
  70.                         self:SetMaxLetters(6)
  71.                     </OnLoad>
  72.                     <OnEnter>
  73.                         self:SetBackdropBorderColor(0.5, 0.5, 0.5, 1)
  74.                     </OnEnter>
  75.                     <OnLeave>
  76.                         self:SetBackdropBorderColor(0.3, 0.3, 0.3, 0.8)
  77.                     </OnLeave>
  78.                     <OnEnterPressed>
  79.                         PowaAuras.SliderEditBoxChanged(self)
  80.                         self:ClearFocus()
  81.                     </OnEnterPressed>
  82.                     <OnEditFocusLost>
  83.                         PowaAuras.SliderEditBoxChanged(self)
  84.                     </OnEditFocusLost>
  85.                     <OnEscapePressed>
  86.                         PowaAuras.SliderEditBoxChanged(self)
  87.                         self:ClearFocus()
  88.                     </OnEscapePressed>
  89.                     <OnMouseWheel>
  90.                         local slider = _G[string.sub(self:GetName(), 1, - 1 * (string.len("EditBox") + 1))]
  91.                         PowaAuras.SliderSetValues(slider, delta)
  92.                     </OnMouseWheel>
  93.                 </Scripts>
  94.             </EditBox>
  95.             <Button name = "$parentPlus">
  96.                 <Size>
  97.                     <AbsDimension x = "18" y = "18"/>
  98.                 </Size>
  99.                 <Anchors>
  100.                     <Anchor point = "LEFT" relativeTo = "$parentEditBox" relativePoint = "RIGHT">
  101.                         <Offset>
  102.                             <AbsDimension x = "0" y = "0"/>
  103.                         </Offset>
  104.                     </Anchor>
  105.                 </Anchors>
  106.                 <NormalTexture file = "Interface\Buttons\UI-SpellbookIcon-NextPage-Up"/>
  107.                 <PushedTexture file = "Interface\Buttons\UI-SpellbookIcon-NextPage-Down"/>
  108.                 <HighlightTexture file = "Interface\Buttons\UI-Panel-MinimizeButton-Highlight" alphaMode = "ADD"/>
  109.                 <Scripts>
  110.                     <OnLoad>
  111.                         self:RegisterForClicks("AnyUp")
  112.                     </OnLoad>
  113.                     <OnClick>
  114.                         PowaAuras.SliderSetValues(self:GetParent(), 1)
  115.                     </OnClick>
  116.                 </Scripts>
  117.             </Button>
  118.             <Button name = "$parentMinus">
  119.                 <Size>
  120.                     <AbsDimension x = "18" y = "18"/>
  121.                 </Size>
  122.                 <Anchors>
  123.                     <Anchor point = "RIGHT" relativeTo = "$parentEditBox" relativePoint = "LEFT">
  124.                         <Offset>
  125.                             <AbsDimension x = "0" y = "0"/>
  126.                         </Offset>
  127.                     </Anchor>
  128.                 </Anchors>
  129.                 <NormalTexture file = "Interface\Buttons\UI-SpellbookIcon-PrevPage-Up"/>
  130.                 <PushedTexture file = "Interface\Buttons\UI-SpellbookIcon-PrevPage-Down"/>
  131.                 <HighlightTexture file = "Interface\Buttons\UI-Panel-MinimizeButton-Highlight" alphaMode = "ADD"/>
  132.                 <Scripts>
  133.                     <OnLoad>
  134.                         self:RegisterForClicks("AnyUp")
  135.                     </OnLoad>
  136.                     <OnClick>
  137.                         PowaAuras.SliderSetValues(self:GetParent(), 0)
  138.                     </OnClick>
  139.                 </Scripts>
  140.             </Button>
  141.         </Frames>
  142.         <ThumbTexture name = "$parentThumb" file = "Interface\Buttons\UI-SliderBar-Button-Horizontal">
  143.             <Size>
  144.                 <AbsDimension x = "32" y = "32"/>
  145.             </Size>
  146.         </ThumbTexture>
  147.         <Scripts>
  148.             <OnLoad>
  149.                 self:EnableMouseWheel(true)
  150.             </OnLoad>
  151.             <OnEnter>
  152.                 if (self:IsEnabled()) then
  153.                     if (self.aide) then
  154.                         GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
  155.                         GameTooltip:SetText(self.aide, nil, nil, nil, nil, 1)
  156.                     end
  157.                 end
  158.             </OnEnter>
  159.             <OnLeave>
  160.                 GameTooltip:Hide()
  161.             </OnLeave>
  162.             <OnMouseWheel>
  163.                 PowaAuras.SliderSetValues(self, delta)
  164.             </OnMouseWheel>
  165.         </Scripts>
  166.     </Slider>
  167.  
  168. function PowaAuras.SliderSetValues(slider, delta)
  169.     if (delta > 0) then
  170.         slider:SetValue(slider:GetValue() + slider:GetValueStep())
  171.     else
  172.         slider:SetValue(slider:GetValue() - slider:GetValueStep())
  173.     end
  174. end
  175.  
  176. function PowaAuras.SliderOnMouseUp(self, x, y, decimals, postfix)
  177.     local frame = self:GetName()
  178.     local min
  179.     local max
  180.     if (x ~= 0) then
  181.         min = format("%."..decimals.."f", (self:GetValue() - x))
  182.     else
  183.         local sliderMin = self:GetMinMaxValues()
  184.         min = sliderMin
  185.     end
  186.     if (y ~= 0) then
  187.         max = format("%."..decimals.."f", (self:GetValue() + y))
  188.     else
  189.         local _, sliderMax = self:GetMinMaxValues()
  190.         max = sliderMax
  191.     end
  192.     self:SetMinMaxValues(min, max)
  193.     if postfix == nil then
  194.         _G[frame.."Low"]:SetText(min)
  195.         _G[frame.."High"]:SetText(max)
  196.     else
  197.         _G[frame.."Low"]:SetText(min..postfix)
  198.         _G[frame.."High"]:SetText(max..postfix)
  199.     end
  200.     PowaAuras:RedisplayAura(PowaAuras.CurrentAuraId)
  201. end
  202.  
  203. function PowaAuras.SliderEditBoxSetValues(slider, editbox, x, y, decimals, endmark)
  204.     local frame = slider:GetName()
  205.     local slidervalue = slider:GetValue()
  206.     local postfix = tostring(string.sub(editbox:GetText(), - 1))
  207.     local value
  208.     if (postfix == "%") then
  209.         value = tonumber(string.sub(editbox:GetText(), 1, - 2))
  210.     else
  211.         value = tonumber(editbox:GetText())
  212.     end
  213.     if (value ~= nil) then
  214.         value = format("%."..decimals.."f", value)
  215.         local min
  216.         local max
  217.         if (x ~= 0) then
  218.             min = format("%."..decimals.."f", (value - x))
  219.         else
  220.             local sliderMin = slider:GetMinMaxValues()
  221.             min = sliderMin
  222.         end
  223.         if (y ~= 0) then
  224.             max = format("%."..decimals.."f", (value + y))
  225.         else
  226.             local _, sliderMax = slider:GetMinMaxValues()
  227.             max = sliderMax
  228.         end
  229.         slider:SetMinMaxValues(min, max)
  230.         slider:SetValue(value)
  231.         if (endmark == nil) then
  232.             editbox:SetText(format("%."..decimals.."f", value))
  233.         elseif (endmark == "%") then
  234.             editbox:SetText(format("%."..decimals.."f", value)..endmark)
  235.         else
  236.             if (postfix == "%") then
  237.                 editbox:SetText(format("%."..decimals.."f", slider:GetValue()).."%")
  238.             else
  239.                 editbox:SetText(format("%."..decimals.."f", slider:GetValue()))
  240.             end
  241.         end
  242.         if (endmark == "%") then
  243.             _G[frame.."Low"]:SetText(min..endmark)
  244.             _G[frame.."High"]:SetText(max..endmark)
  245.         else
  246.             _G[frame.."Low"]:SetText(min)
  247.             _G[frame.."High"]:SetText(max)
  248.         end
  249.     else
  250.         if (x == 0 and y == 0) then
  251.             local sliderMin, sliderMax = slider:GetMinMaxValues()
  252.             slider:SetMinMaxValues(sliderMin, sliderMax)
  253.         elseif (x == 0) then
  254.             local sliderMin = slider:GetMinMaxValues()
  255.             slider:SetMinMaxValues(sliderMin, slidervalue + y)
  256.         elseif (y == 0) then
  257.             local _, sliderMax = slider:GetMinMaxValues()
  258.             slider:SetMinMaxValues(slidervalue - x, sliderMax)
  259.         else
  260.             slider:SetMinMaxValues(slidervalue - x, slidervalue + y)
  261.         end
  262.         slider:SetValue(slidervalue)
  263.         if (endmark == "%") then
  264.             editbox:SetText(format("%."..decimals.."f", slidervalue)..endmark)
  265.         else
  266.             editbox:SetText(format("%."..decimals.."f", slidervalue))
  267.         end
  268.         if (endmark == "%") then
  269.             _G[frame.."Low"]:SetText((slidervalue - x)..endmark)
  270.             _G[frame.."High"]:SetText((slidervalue + y)..endmark)
  271.         else
  272.             _G[frame.."Low"]:SetText(slidervalue - x)
  273.             _G[frame.."High"]:SetText(slidervalue + y)
  274.         end
  275.     end
  276.     PowaAuras:RedisplayAura(PowaAuras.CurrentAuraId)
  277. end
  278.  
  279. function PowaAuras.SliderEditBoxChanged(self)
  280.     local frame = self:GetName()
  281.     local slider = _G[string.sub(frame, 1, - 1 * (string.len("EditBox") + 1))]
  282.     local postfix = tostring(string.sub(self:GetText(), - 1))
  283.     if (slider == PowaBarAuraSizeSlider) then
  284.         PowaAuras.SliderEditBoxSetValues(slider, self, 0, 100, 0, "%")
  285.     elseif (slider == PowaBarAuraCoordXSlider or slider == PowaTimerCoordXSlider or slider == PowaStacksCoordXSlider) then
  286.         PowaAuras.SliderEditBoxSetValues(slider, self, 700, 700, 0)
  287.     elseif (slider == PowaBarAuraCoordYSlider or slider == PowaTimerCoordYSlider or slider == PowaStacksCoordYSlider) then
  288.         PowaAuras.SliderEditBoxSetValues(slider, self, 400, 400, 0)
  289.     elseif (slider == PowaModelPositionZSlider) then
  290.         PowaAuras.SliderEditBoxSetValues(slider, self, 100, 100, 0)
  291.     elseif (slider == PowaModelPositionXSlider or slider == PowaModelPositionYSlider) then
  292.         PowaAuras.SliderEditBoxSetValues(slider, self, 50, 50, 0)
  293.     end
  294.     if ((postfix == "%") and (slider == PowaBarAuraAlphaSlider or slider == PowaTimerSizeSlider or slider == PowaTimerAlphaSlider or slider == PowaStacksSizeSlider or slider == PowaStacksAlphaSlider)) then
  295.         local text = tonumber(string.sub(self:GetText(), 1, - 2))
  296.         if (text ~= nil) then
  297.             text = text / 100
  298.             slider:SetValue(text)
  299.             self:SetText(format("%.0f", (slider:GetValue() * 100)).."%")
  300.             local sliderlow, sliderhigh = slider:GetMinMaxValues()
  301.             if (text <= sliderlow or text >= sliderhigh) then
  302.                 self:SetText(format("%.0f", (slider:GetValue() * 100)).."%")
  303.             end
  304.         else
  305.             self:SetText(format("%.0f", (slider:GetValue() * 100)).."%")
  306.         end
  307.     elseif (postfix == "%" and (slider == PowaBarAuraSizeSlider or slider == PowaBarAuraAnimSpeedSlider)) then
  308.         local text = tonumber(string.sub(self:GetText(), 1, - 2))
  309.         if (text ~= nil) then
  310.             slider:SetValue(text)
  311.             self:SetText(format("%.0f", (slider:GetValue())).."%")
  312.             local sliderlow, sliderhigh = slider:GetMinMaxValues()
  313.             if (text <= sliderlow or text >= sliderhigh) then
  314.                 self:SetText(format("%.0f", slider:GetValue()).."%")
  315.             end
  316.         else
  317.             self:SetText(format("%.0f", slider:GetValue()).."%")
  318.         end
  319.     elseif (postfix == "%" and (slider == PowaBarThresholdSlider)) then
  320.         local text = tonumber(string.sub(self:GetText(), 1, - 2))
  321.         local aura = PowaAuras.Auras[PowaAuras.CurrentAuraId]
  322.         if (text ~= nil and aura.RangeType == "%") then
  323.             slider:SetValue(text)
  324.             self:SetText(format("%.0f", (slider:GetValue()))..aura.RangeType)
  325.             local sliderlow, sliderhigh = slider:GetMinMaxValues()
  326.             if (text <= sliderlow or text >= sliderhigh) then
  327.                 self:SetText(format("%.0f", slider:GetValue())..aura.RangeType)
  328.             end
  329.         else
  330.             self:SetText(format("%.0f", slider:GetValue())..aura.RangeType)
  331.         end
  332.     elseif (slider == PowaBarAuraAlphaSlider or slider == PowaTimerSizeSlider or slider == PowaTimerAlphaSlider or slider == PowaStacksSizeSlider or slider == PowaStacksAlphaSlider) then
  333.         local text = tonumber(self:GetText())
  334.         if (text ~= nil) then
  335.             text = text / 100
  336.             slider:SetValue(text)
  337.             self:SetText(format("%.0f", (slider:GetValue() * 100)).."%")
  338.             local sliderlow, sliderhigh = slider:GetMinMaxValues()
  339.             if (text < sliderlow or text > sliderhigh) then
  340.                 self:SetText(format("%.0f", (slider:GetValue() * 100)).."%")
  341.             end
  342.         else
  343.             self:SetText(format("%.0f", (slider:GetValue() * 100)).."%")
  344.         end
  345.     elseif (slider == PowaBarAuraSizeSlider or slider == PowaBarAuraAnimSpeedSlider) then
  346.         local text = tonumber(self:GetText())
  347.         if (text ~= nil) then
  348.             slider:SetValue(text)
  349.             self:SetText(format("%.0f", (slider:GetValue())).."%")
  350.             local sliderlow, sliderhigh = slider:GetMinMaxValues()
  351.             if (text <= sliderlow or text >= sliderhigh) then
  352.                 self:SetText(format("%.0f", slider:GetValue()).."%")
  353.             end
  354.         else
  355.             self:SetText(format("%.0f", slider:GetValue()).."%")
  356.         end
  357.     elseif (slider == PowaBarThresholdSlider) then
  358.         local text = tonumber(self:GetText())
  359.         local aura = PowaAuras.Auras[PowaAuras.CurrentAuraId]
  360.         if (text ~= nil) then
  361.             slider:SetValue(text)
  362.             self:SetText(format("%.0f", (slider:GetValue()))..aura.RangeType)
  363.             local sliderlow, sliderhigh = slider:GetMinMaxValues()
  364.             if (text <= sliderlow or text >= sliderhigh) then
  365.                 self:SetText(format("%.0f", slider:GetValue())..aura.RangeType)
  366.             end
  367.         else
  368.             self:SetText(format("%.0f", slider:GetValue())..aura.RangeType)
  369.         end
  370.     elseif (tonumber(postfix) == nil and slider == PowaBarAuraRotateSlider) then
  371.         local text = tonumber(string.sub(self:GetText(), 1, - 2))
  372.         if text == nil then
  373.             text = tonumber(string.sub(self:GetText(), 1, - 3))
  374.         end
  375.         if (text ~= nil) then
  376.             slider:SetValue(text)
  377.             self:SetText(format("%.0f", slider:GetValue()).."°")
  378.             local sliderlow, sliderhigh = slider:GetMinMaxValues()
  379.             if (text < sliderlow or text > sliderhigh) then
  380.                 self:SetText(format("%.0f", slider:GetValue()).."°")
  381.             end
  382.         else
  383.             self:SetText(format("%.0f", slider:GetValue()).."°")
  384.         end
  385.     elseif (slider == PowaBarAuraRotateSlider) then
  386.         local text = tonumber(self:GetText())
  387.         if (text ~= nil) then
  388.             slider:SetValue(text)
  389.             self:SetText(format("%.0f", slider:GetValue()).."°")
  390.             local sliderlow, sliderhigh = slider:GetMinMaxValues()
  391.             if (text < sliderlow or text > sliderhigh) then
  392.                 self:SetText(format("%.0f", slider:GetValue()).."°")
  393.             end
  394.         else
  395.             self:SetText(format("%.0f", slider:GetValue()).."°")
  396.         end
  397.     elseif (slider == PowaBarAuraDeformSlider or slider == PowaBarAuraDurationSlider or slider == PowaTimerDurationSlider or slider == PowaTimerInvertAuraSlider) then
  398.         if (tonumber(self:GetText()) ~= nil) then
  399.             slider:SetValue(tonumber(self:GetText()))
  400.             self:SetText(format("%.2f", slider:GetValue()))
  401.             local sliderlow, sliderhigh = slider:GetMinMaxValues()
  402.             if (tonumber(self:GetText()) < sliderlow or tonumber(self:GetText()) > sliderhigh) then
  403.                 self:SetText(slider:GetValue())
  404.             end
  405.         else
  406.             self:SetText(slider:GetValue())
  407.         end
  408.     else
  409.         if (tonumber(self:GetText()) ~= nil) then
  410.             slider:SetValue(tonumber(self:GetText()))
  411.             self:SetText(format("%.0f", slider:GetValue()))
  412.             local sliderlow, sliderhigh = slider:GetMinMaxValues()
  413.             if (tonumber(self:GetText()) < sliderlow) or (tonumber(self:GetText()) > sliderhigh) then
  414.                 self:SetText(slider:GetValue())
  415.             end
  416.         else
  417.             self:SetText(slider:GetValue())
  418.         end
  419.     end
  420. end

I'm aware of i could easily fix this with a "format("%.0f", SliderValue)" but this would not make the lagg go away since it would still use long float numbers.

The real problem pretty much anything made/changed since the start of 5.4 going to have corrupted values and not gonna work properly.

Last edited by Resike : 09-17-13 at 05:17 AM.
  Reply With Quote
09-17-13, 05:33 AM   #2
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
Hmmm....I do this:
Lua Code:
  1. --simple round number func
  2.   local SimpleRound = function(val,valStep)
  3.     return floor(val/valStep)*valStep
  4.   end
  5.  
  6.   --basic slider func
  7.   local CreateBasicSlider = function(parent, name, title, minVal, maxVal, valStep)
  8.     local slider = CreateFrame("Slider", name, parent, "OptionsSliderTemplate")
  9.     local editbox = CreateFrame("EditBox", "$parentEditBox", slider, "InputBoxTemplate")
  10.     slider:SetMinMaxValues(minVal, maxVal)
  11.     --slider:SetValue(0)
  12.     slider:SetValueStep(valStep)
  13.     slider.text = _G[name.."Text"]
  14.     slider.text:SetText(title)
  15.     slider.textLow = _G[name.."Low"]
  16.     slider.textHigh = _G[name.."High"]
  17.     slider.textLow:SetText(floor(minVal))
  18.     slider.textHigh:SetText(floor(maxVal))
  19.     slider.textLow:SetTextColor(0.4,0.4,0.4)
  20.     slider.textHigh:SetTextColor(0.4,0.4,0.4)
  21.     editbox:SetSize(50,30)
  22.     editbox:ClearAllPoints()
  23.     editbox:SetPoint("LEFT", slider, "RIGHT", 15, 0)
  24.     editbox:SetText(slider:GetValue())
  25.     editbox:SetAutoFocus(false)
  26.     slider:SetScript("OnValueChanged", function(self,value)
  27.       self.editbox:SetText(SimpleRound (value,valStep))
  28.     end)
  29.     editbox:SetScript("OnTextChanged", function(self)
  30.       local val = self:GetText()
  31.       if tonumber(val) then
  32.          self:GetParent():SetValue(val)
  33.       end
  34.     end)
  35.     editbox:SetScript("OnEnterPressed", function(self)
  36.       local val = self:GetText()
  37.       if tonumber(val) then
  38.          self:GetParent():SetValue(val)
  39.          self:ClearFocus()
  40.       end
  41.     end)
  42.     slider.editbox = editbox
  43.     return slider
  44.   end
  45.  
  46.   --create slider
  47.     local slider = CreateBasicSlider(parent, "MySliderName", "Alpha", 0, 1, 0.001)
  48.     slider:HookScript("OnValueChanged", function(self,value)
  49.       --save value
  50.     end)
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 09-17-13 at 05:54 AM.
  Reply With Quote
09-17-13, 05:48 AM   #3
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Yeah i found some workarounds too, but the main problem how the heck am i gonna fix the already saved existing problems, aka when someone set their holy power to 1.1231241231 instead of 1?
  Reply With Quote
09-17-13, 07:26 AM   #4
humfras
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Oct 2009
Posts: 131
Originally Posted by Resike View Post
Yeah i found some workarounds too, but the main problem how the heck am i gonna fix the already saved existing problems, aka when someone set their holy power to 1.1231241231 instead of 1?
There is no other more efficient way to string.format or floor(value/step)*step.
The lag must be caused by something else.
I once encountered this myself when using a simple self made slider. The problem mysteriously didn't occur when using the Ace3 one...
__________________
Author of VuhDo CursorCastBar OptiTaunt Poisoner RaidMobMarker

Last edited by humfras : 09-17-13 at 07:33 AM.
  Reply With Quote
09-17-13, 09:41 AM   #5
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Ace3 was updated for this change in the API with 5.4.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
09-17-13, 02:49 PM   #6
Haleth
This Space For Rent
 
Haleth's Avatar
Featured
Join Date: Sep 2008
Posts: 1,173
This happens with every form of slider in 5.4, it's also noticeable in scroll frames when you try dragging the 'grip' rather than scrolling with the mouse.
  Reply With Quote
09-17-13, 02:57 PM   #7
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by humfras View Post
There is no other more efficient way to string.format or floor(value/step)*step.
The lag must be caused by something else.
I once encountered this myself when using a simple self made slider. The problem mysteriously didn't occur when using the Ace3 one...
Of course this causing the lag, have you ever tried to calculate with 30 character long float values multiple times under a second? Specially when you use it on slider which is handling high resolution textures/ingame models, like alpha, rotation, zoom, width, height, position changes.

Last edited by Resike : 09-17-13 at 03:02 PM.
  Reply With Quote
09-17-13, 10:57 PM   #8
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Resike View Post
Specially when you use it on slider which is handling high resolution textures/ingame models, like alpha, rotation, zoom, width, height, position changes.
If you're using a slider to change something that's going to hang the client if you change it 1000 times per second, you should use some kind of throttling to make sure you don't change it 1000 times per second while the user is dragging the slider, or wait until the user lets go of the slider to apply the change.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
09-18-13, 06:29 AM   #9
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Phanx View Post
If you're using a slider to change something that's going to hang the client if you change it 1000 times per second, you should use some kind of throttling to make sure you don't change it 1000 times per second while the user is dragging the slider, or wait until the user lets go of the slider to apply the change.
I already have that built in. But since the slider bug updates the slider value on every pixel it's not really working.
  Reply With Quote
09-18-13, 03:52 PM   #10
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
I'm not sure what you mean... slider widgets have always run OnValueChanged scripts 498302483242 times a second while the user is dragging the slider. To ignore changes during dragging, and only update when the slider is released, you'd use OnMouseUp instead of OnValueChanged, or check IsMouseButtonDown in your OnValueChanged script and either ignore changes made with a mouse button down, or only pass values to the addon while the mouse button is down if the last value was passed more than X time ago. The only thing that's changed in 5.4 is that the values passed to OnValueChanged scripts while the slider is being dragged no longer respect the slider's step value. Nothing else has changed.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
09-18-13, 04:40 PM   #11
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Phanx View Post
I'm not sure what you mean... slider widgets have always run OnValueChanged scripts 498302483242 times a second while the user is dragging the slider. To ignore changes during dragging, and only update when the slider is released, you'd use OnMouseUp instead of OnValueChanged, or check IsMouseButtonDown in your OnValueChanged script and either ignore changes made with a mouse button down, or only pass values to the addon while the mouse button is down if the last value was passed more than X time ago. The only thing that's changed in 5.4 is that the values passed to OnValueChanged scripts while the slider is being dragged no longer respect the slider's step value. Nothing else has changed.
Well my method woks like that on every OnValueChanged i do something like this:

Lua Code:
  1. local SliderValue = Slider:GetValue()
  2. if (SliderValue ~= SavedVariable) then
  3.     -- Change it's value
  4. end

This also stop the pointless cpu usage when you hold the mouse button down on the slider but not moving it. And it's working pretty well with a well set ValueStep, even when i go nuts on sliders it's wont use more then 0.5-1% cpu time. (But depends on which function is the slider handling.)
  Reply With Quote
09-18-13, 05:36 PM   #12
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
1) If you're running that code inside an OnValueChanged script, you should just use the value passed to the script itself, instead of calling GetValue again to get the same value.

2) A simple workaround for your case would be to manually round the new value according to your slider's step value before checking it against your saved value.

Code:
slider:SetStepValue(5)
slider.stepValue = 5 -- store it here for faster access later

slider:SetScript("OnValueChanged", function(slider, value)
   local halfStep = slider.stepValue / 2
   value = value + halfStep - (value + halfStep) % slider.stepValue -- faster than calling math.floor
   if value ~= SAVED_VALUE then
      -- Do stuff
   end
end)
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
09-19-13, 04:30 AM   #13
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Phanx View Post
1) If you're running that code inside an OnValueChanged script, you should just use the value passed to the script itself, instead of calling GetValue again to get the same value.

2) A simple workaround for your case would be to manually round the new value according to your slider's step value before checking it against your saved value.

Code:
slider:SetStepValue(5)
slider.stepValue = 5 -- store it here for faster access later

slider:SetScript("OnValueChanged", function(slider, value)
   local halfStep = slider.stepValue / 2
   value = value + halfStep - (value + halfStep) % slider.stepValue -- faster than calling math.floor
   if value ~= SAVED_VALUE then
      -- Do stuff
   end
end)
I already tried that but it doesn't solve the problem triggers, the real problem is the script getting triggered by 6 million times and even a floor function like this makes the slider laggy.

We need a solution like that which doesn't trigger the script itself when it's unnessecary.

Last edited by Resike : 09-19-13 at 04:33 AM.
  Reply With Quote
09-19-13, 06:02 AM   #14
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
Try to disable the click function and check for the result.
If it does any good just replace the OnClick event function with your own.
Lua Code:
  1. slider:SetScript("OnClick", function(self,...)
  2.   print(...)
  3. end)
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 09-19-13 at 06:05 AM.
  Reply With Quote
09-19-13, 06:07 AM   #15
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by zork View Post
Try to disable the click function and check for the result.
If it does any good just replace the OnClick event function with your own.
Lua Code:
  1. slider:SetScript("OnClick", function(self,...)
  2.   print(...)
  3. end)
That would work i guess, but then the slider wouldn't get updated when you move the mouse on it. And i would like to keep that function if it's possible.

However i saw a possible solution here:

http://www.wowwiki.com/Patch_5.4.0/API_changes

I might try this one.

Last edited by Resike : 09-19-13 at 06:11 AM.
  Reply With Quote
09-19-13, 01:29 PM   #16
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Even with this method the lagg is still there.
  Reply With Quote
09-19-13, 04:34 PM   #17
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
1) There was no floor function call in the code I posted.

2) Without seeing your entire, actual code, there is no way I or anyone else can really tell you why your slider is so laggy. All we can do is offer blind guesses.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
09-20-13, 02:21 AM   #18
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Phanx View Post
1) There was no floor function call in the code I posted.

2) Without seeing your entire, actual code, there is no way I or anyone else can really tell you why your slider is so laggy. All we can do is offer blind guesses.
1) But the calculations there works pretty much just as the floor.

2) I know why is it laggy, the problem i don't know how to fix it properly.

I posted most of the slider code in my first comment, but here is the full:

https://github.com/Resike/PowerAuras

Last edited by Resike : 09-20-13 at 02:24 AM.
  Reply With Quote
09-20-13, 10:42 AM   #19
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Not sure if this adds anything to the discussion, but I have a scroll frame inheriting the hybrid scroll frame template. I don't do anything to throttle the running of the update function, and I have not changed anything since the patch. It is definitely noticably more laggy. (not that it was laggy at all before) I'm fairly sure I've noticed it in the default UI's scroll frames as well.

Edit: Yep, simple things like the character stats frame and the quest log lag. Scrolling does not seem to affect the rest of the game, though.
__________________
Grab your sword and fight the Horde!

Last edited by Lombra : 09-20-13 at 12:44 PM.
  Reply With Quote
09-23-13, 04:34 AM   #20
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
Maybe http://wowpedia.org/API_Slider_SetStepsPerPage, http://wowpedia.org/API_Slider_GetStepsPerPage causes a sort of endless loop? That are the only changes since 5.4 for slider object.

Getting an endless loop is easy. You set a value and on value set you call a function that sets a value. O_O

What will this do for you?
Lua Code:
  1. --If steps >= 1, the Slider's value will be changed by
  2. --exactly Slider:GetValueStep()*math.floor(steps) in the
  3. --direction of the click.
  4. slider:SetStepsPerPage(0) --disable SetStepsPerPage
  5.  
  6. --[[
  7. slider.SetStepsPerPage = function(...)
  8.   print(self:GetName().." called SetStepsPerPage")
  9.   print(...)
  10. end
  11.  
  12. slider.GetStepsPerPage = function(...)
  13.   print(self:GetName().." called GetStepsPerPage")
  14.   print(...)
  15. end
  16. ]]--

If your valuestep is very low (0.001 or lower) make sure to use bigger steps like: 1/valueStep
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 09-23-13 at 04:53 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Slider problems


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off