class RETerm::Components::Dial

Attributes

increment[RW]
initial_value[RW]
labels[RW]
range[RW]
value[RW]

Public Class Methods

new(args={}) click to toggle source

Enapsulating window should be at least 4x4 for decent effect, at least 7x7 provides best resolution

@param [Hash] args dial params

@example activating a dial

win  = Window.new
dial = Dial.new
win.component = dial

val = dial.activate!
Calls superclass method RETerm::Component::new
# File lib/reterm/components/dial.rb, line 22
def initialize(args={})
  super
  @initial_value = 0
  @increment     = 0.01
  @range         = [0, 1]
  @labels        = true
  @value = initial_value
end

Public Instance Methods

activatable?() click to toggle source
# File lib/reterm/components/dial.rb, line 43
def activatable?
  true
end
activate!(*input) click to toggle source
# File lib/reterm/components/dial.rb, line 47
def activate!(*input)
  refresh_win
  handle_input(*input)
  @value
end
draw!() click to toggle source
# File lib/reterm/components/dial.rb, line 39
def draw!
  refresh_win
end
requested_cols() click to toggle source
# File lib/reterm/components/dial.rb, line 35
def requested_cols
  7
end
requested_rows() click to toggle source
# File lib/reterm/components/dial.rb, line 31
def requested_rows
  7
end

Private Instance Methods

on_dec() click to toggle source
# File lib/reterm/components/dial.rb, line 61
def on_dec
    @value -= increment
    @value  = 0 if @value < 0
    refresh_win
end
on_inc() click to toggle source
# File lib/reterm/components/dial.rb, line 55
def on_inc
  @value += increment
  @value  = 1 if @value > 1
  refresh_win
end
refresh_win() click to toggle source
# File lib/reterm/components/dial.rb, line 67
def refresh_win
  if @labels
    window.mvaddstr(1,    1,   '-')
    window.mvaddstr(1, window.cols-2, '+')
  end

  rad = Math.sqrt((window.rows/2)**2 + (window.cols/2)**2)
  padding = rad/2 + 1

  rows = window.rows - padding
  cols  = window.cols  - padding
  rad   = Math.sqrt((rows/2)**2 + (cols/2)**2)

  a = 0
  while a < @value
    ar = a * (2 * Math::PI)
    x = rad * Math.cos(3*Math::PI/2 - ar) + cols/2  + padding/2
    y = rad * Math.sin(3*Math::PI/2 - ar) + rows/2 + padding/2
    a += increment

    window.mvaddstr(y, x, '*')
  end

  while a < 1
    ar = a * (2 * Math::PI)
    x = rad * Math.cos(3*Math::PI/2 - ar) + cols/2  + padding/2
    y = rad * Math.sin(3*Math::PI/2 - ar) + rows/2 + padding/2
    a += increment

    window.mvaddstr(y, x, ' ')
  end

  window.refresh
  update_reterm
end