You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
951B

  1. require_relative '../control'
  2. module DHE
  3. class Knob < RoundControl
  4. DIAMETERS = {huge: 19.0, large: 12.7, medium: 10.0, small: 8.4, tiny: 7.0, }
  5. def initialize(faceplate:, size:, x:, y:)
  6. super(faceplate: faceplate, x: x, y: y, diameter: DIAMETERS[size.to_sym])
  7. @knob_color = faceplate.foreground
  8. @pointer_color = faceplate.background
  9. @path = faceplate.slug / "knob-#{size}"
  10. @x = x
  11. @y = y
  12. end
  13. def draw(svg:, x:, y:)
  14. pointer_width = radius / 8.0
  15. pointer_length = radius - pointer_width
  16. svg.g(transform: "translate(#{x} #{y})", stroke: @pointer_color, fill: @knob_color) do |g|
  17. g.circle(r: radius, stroke: 'none')
  18. g.line(y2: -pointer_length, 'stroke-width' => pointer_width, 'stroke-linecap' => 'round')
  19. end
  20. end
  21. def svg_files
  22. [
  23. svg_file(path: @path) do |svg|
  24. draw_control(svg: svg)
  25. end
  26. ]
  27. end
  28. end
  29. end