Advertisement
CapsAdmin

Untitled

Jan 31st, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.55 KB | None | 0 0
  1. local PANEL = {}
  2.  
  3. PANEL.ClassName = "knob"
  4.  
  5. aahh.GetSet(PANEL, "Value", 0)
  6. aahh.GetSet(PANEL, "Min", 0)
  7. aahh.GetSet(PANEL, "Max", 1)
  8.  
  9. function PANEL:OnDraw(size)
  10.  
  11.     if self.drag_pos and input.IsKeyDown("mouse1") then
  12.         local delta = self.drag_value + (Vec2(mouse.GetPos()) - self.drag_pos) / 100
  13.         self:SetValue(delta.x)
  14.     else
  15.         self.drag_pos = nil
  16.     end
  17.  
  18.     graphics.DrawRect(Rect(0, 0, size), self:GetSkinColor("medium"), 8, 1, self:GetSkinColor("border"))
  19.    
  20.     local pos = self:GetSize() / 2
  21.     graphics.DrawLine(pos, pos + Vec2(math.sin(self.Value * math.pi * -2), math.cos(self.Value * math.pi * -2)) * self:GetHeight() / 2.5, self:GetSkinColor("light"))
  22. end
  23.  
  24. function PANEL:SetValue(num)
  25.     if input.IsKeyDown("lctrl") then
  26.         num = math.round(num, 1)
  27.     end
  28.    
  29.     num = math.clamp(num, self.Min, self.Max)
  30.  
  31.     self.Value = num
  32.        
  33.     self:OnValueChanged(self.Value)
  34. end
  35.  
  36. function PANEL:OnMouseInput(button, press, pos, ...)
  37.     if button == "mwheel_up" then
  38.         self.Value = self.Value - 1
  39.     elseif button == "mwheel_down" then
  40.         self.Value = self.Value + 1
  41.     else   
  42.         if press then
  43.             self.drag_pos = Vec2(mouse.GetPos())
  44.             self.drag_value = self.Value
  45.         end
  46.     end
  47. end
  48.  
  49. aahh.RegisterPanel(PANEL)
  50.  
  51. if CAPSADMIN then
  52.     MONITOR_ME()
  53.    
  54.     timer.Simple(0.1, function()
  55.        
  56.         local frame = utilities.RemoveOldObject(aahh.Create("frame"), "asdf")
  57.         frame:SetSize(Vec2() + 100)
  58.        
  59.         local knob = aahh.Create("knob", frame)
  60.         knob:SetSize(Vec2(20, 20))
  61.         knob:Center()
  62.        
  63.         knob.OnValueChanged = function(_, pos) frame:SetTitle(tostring(pos)) end
  64.     end)  
  65. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement