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.

34 lines
1.1KB

  1. require_relative '../control'
  2. module DHE
  3. class Button < RoundControl
  4. DIAMETER = 6.0
  5. def initialize(faceplate:, x:, y:, style: :normal)
  6. super(faceplate: faceplate, x: x, y: y, diameter: DIAMETER)
  7. @slug = 'button'
  8. @slug += '-reversed' if style == :reversed
  9. @ring_color = faceplate.foreground
  10. @center_color = faceplate.background
  11. @ring_color, @center_color = @center_color, @ring_color if style == :reversed
  12. end
  13. def draw(svg:, x:, y:, state: :off)
  14. center_color = state == :on ? @center_color : @ring_color
  15. stroke_width = DIAMETER / 6.0
  16. circle_diameter = DIAMETER - stroke_width
  17. circle_radius = circle_diameter / 2.0
  18. svg.circle(cx: x, cy: y, r: circle_radius, 'stroke-width' => stroke_width, fill: center_color, stroke: @ring_color)
  19. end
  20. def svg_files
  21. [:on, :off].map do |state|
  22. position = state == :off ? 1 : 2
  23. path = faceplate.slug / "#{@slug}-#{position}"
  24. svg_file(path: path) do |svg|
  25. draw_control(svg: svg, state: state)
  26. end
  27. end
  28. end
  29. end
  30. end