Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local PANEL = {}
- PANEL.ClassName = "knob"
- aahh.GetSet(PANEL, "Value", 0)
- aahh.GetSet(PANEL, "Min", 0)
- aahh.GetSet(PANEL, "Max", 1)
- function PANEL:OnDraw(size)
- if self.drag_pos and input.IsKeyDown("mouse1") then
- local delta = self.drag_value + (Vec2(mouse.GetPos()) - self.drag_pos) / 100
- self:SetValue(delta.x)
- else
- self.drag_pos = nil
- end
- graphics.DrawRect(Rect(0, 0, size), self:GetSkinColor("medium"), 8, 1, self:GetSkinColor("border"))
- local pos = self:GetSize() / 2
- 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"))
- end
- function PANEL:SetValue(num)
- if input.IsKeyDown("lctrl") then
- num = math.round(num, 1)
- end
- num = math.clamp(num, self.Min, self.Max)
- self.Value = num
- self:OnValueChanged(self.Value)
- end
- function PANEL:OnMouseInput(button, press, pos, ...)
- if button == "mwheel_up" then
- self.Value = self.Value - 1
- elseif button == "mwheel_down" then
- self.Value = self.Value + 1
- else
- if press then
- self.drag_pos = Vec2(mouse.GetPos())
- self.drag_value = self.Value
- end
- end
- end
- aahh.RegisterPanel(PANEL)
- if CAPSADMIN then
- MONITOR_ME()
- timer.Simple(0.1, function()
- local frame = utilities.RemoveOldObject(aahh.Create("frame"), "asdf")
- frame:SetSize(Vec2() + 100)
- local knob = aahh.Create("knob", frame)
- knob:SetSize(Vec2(20, 20))
- knob:Center()
- knob.OnValueChanged = function(_, pos) frame:SetTitle(tostring(pos)) end
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement