Class: RISlider

Inherits:
Object
  • Object
show all
Defined in:
lib/RIUI/RISlider.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = [:length, :x, :y, :square_size, :ticks, :actions]) ⇒ RISlider

Initialize all variables and start functionality



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/RIUI/RISlider.rb', line 5

def initialize(opts = [:length, :x, :y, :square_size, :ticks, :actions]) ### Initialize all variables and start functionality
  extend Ruby2D::DSL
  @x = opts[:x] || 0
  @y = opts[:y] || 0
  @length = opts[:length] || 100
  @square_size = opts[:square_size] || 10
  @ticks = opts[:ticks] || 10
  @label_font = opts[:label_font] || ''
  @label_size = opts[:label_size] || 20
  @label_color = opts[:label_color] || 'black'
  @line_color = opts[:line_color] || 'black'
  @square_color = opts[:square_color] || 'red'
  @actions = opts[:actions]
  @value = 0
  @line = Line.new(x1: @x, y1: @y, x2: @x + @length, y2: y, color: @line_color)
  self.square = Square.new(size: @square_size, x: x - (@square_size/2), y: y - (@square_size/2), color: @square_color)
  setState(active: false)
  #@actions.add(self)
#  start_update
end

Instance Attribute Details

#actions=(value) ⇒ Object

Sets the attribute actions

Parameters:

  • value

    the value to set the attribute actions to.



3
4
5
# File 'lib/RIUI/RISlider.rb', line 3

def actions=(value)
  @actions = value
end

#activeObject

Returns the value of attribute active.



3
4
5
# File 'lib/RIUI/RISlider.rb', line 3

def active
  @active
end

#colorObject

Returns the value of attribute color.



3
4
5
# File 'lib/RIUI/RISlider.rb', line 3

def color
  @color
end

#fontObject

Returns the value of attribute font.



3
4
5
# File 'lib/RIUI/RISlider.rb', line 3

def font
  @font
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/RIUI/RISlider.rb', line 3

def id
  @id
end

#lengthObject

Returns the value of attribute length.



3
4
5
# File 'lib/RIUI/RISlider.rb', line 3

def length
  @length
end

#line_colorObject

Returns the value of attribute line_color.



3
4
5
# File 'lib/RIUI/RISlider.rb', line 3

def line_color
  @line_color
end

#onchangeObject

Returns the value of attribute onchange.



3
4
5
# File 'lib/RIUI/RISlider.rb', line 3

def onchange
  @onchange
end

#sizeObject

Returns the value of attribute size.



3
4
5
# File 'lib/RIUI/RISlider.rb', line 3

def size
  @size
end

#squareObject

Returns the value of attribute square.



3
4
5
# File 'lib/RIUI/RISlider.rb', line 3

def square
  @square
end

#square_colorObject

Returns the value of attribute square_color.



3
4
5
# File 'lib/RIUI/RISlider.rb', line 3

def square_color
  @square_color
end

#square_sizeObject

Returns the value of attribute square_size.



3
4
5
# File 'lib/RIUI/RISlider.rb', line 3

def square_size
  @square_size
end

#ticksObject

Returns the value of attribute ticks.



3
4
5
# File 'lib/RIUI/RISlider.rb', line 3

def ticks
  @ticks
end

#xObject

Returns the value of attribute x.



3
4
5
# File 'lib/RIUI/RISlider.rb', line 3

def x
  @x
end

#yObject

Returns the value of attribute y.



3
4
5
# File 'lib/RIUI/RISlider.rb', line 3

def y
  @y
end

Instance Method Details

#mouse_down_actions(x, y) ⇒ Object



50
51
52
53
54
# File 'lib/RIUI/RISlider.rb', line 50

def mouse_down_actions(x, y)
  if self.square.contains?(x, y)
     setState(active: true)
  end
end

#mouse_move_actions(x, y) ⇒ Object



58
# File 'lib/RIUI/RISlider.rb', line 58

def mouse_move_actions(x, y); end

#mouse_up_actionsObject



55
56
57
# File 'lib/RIUI/RISlider.rb', line 55

def mouse_up_actions
  setState(active: false)
end

#onChange(opts = [:onchange]) ⇒ Object



45
46
47
# File 'lib/RIUI/RISlider.rb', line 45

def onChange(opts = [:onchange])
  @onChange = opts[:onchange]
end

#resetObject



41
42
43
44
# File 'lib/RIUI/RISlider.rb', line 41

def reset
  self.square.x = @x - (@square_size/2)
  @value = 0
end

#setColors(opts = [:square_color, :line_color]) ⇒ Object

Sets the colors of the line and square



26
27
28
29
30
31
32
# File 'lib/RIUI/RISlider.rb', line 26

def setColors(opts = [:square_color, :line_color]) ### Sets the colors of the line and square
  @line_color = opts[:line_color]
  @square_color = opts[:square_color]
  @line.color = @line_color
  self.square.color = @square_color
  puts 'colors set'
end

#setLabel(opts = [:size, :font, :color]) ⇒ Object

Creates a label for the slider



34
35
36
37
38
39
40
# File 'lib/RIUI/RISlider.rb', line 34

def setLabel(opts = [:size, :font, :color]) ### Creates a label for the slider
  @label_size = opts[:size]
  @label_font = opts[:font]
  @label_color = opts[:color]
  @label = Text.new(x: @x + @length + 15, y: @y, color: @label_color, font: @label_font, size: @label_size, text: '0')
  puts 'label set'
end

#update_actionsObject



59
60
61
62
63
64
65
66
# File 'lib/RIUI/RISlider.rb', line 59

def update_actions
  check
  update_label
  changed = check_for_change(@old_value, @value)
  if changed
    @onChange.call
  end
end

#valueObject

Returns slider’s value



48
# File 'lib/RIUI/RISlider.rb', line 48

def value; @value; end