Module: Savio::IORenderable

Included in:
Button, ColorSlider, InputBox, Slider
Defined in:
lib/savio/IORenderable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#allowDragObject

Returns the value of attribute allowDrag.



3
4
5
# File 'lib/savio/IORenderable.rb', line 3

def allowDrag
  @allowDrag
end

#displayNameObject

Returns the value of attribute displayName.



4
5
6
# File 'lib/savio/IORenderable.rb', line 4

def displayName
  @displayName
end

#draggingEnabledObject

Returns the value of attribute draggingEnabled.



3
4
5
# File 'lib/savio/IORenderable.rb', line 3

def draggingEnabled
  @draggingEnabled
end

#duplicateObject

Returns the value of attribute duplicate.



3
4
5
# File 'lib/savio/IORenderable.rb', line 3

def duplicate
  @duplicate
end

#enabledObject

Returns the value of attribute enabled.



3
4
5
# File 'lib/savio/IORenderable.rb', line 3

def enabled
  @enabled
end

#shownObject

Returns the value of attribute shown.



3
4
5
# File 'lib/savio/IORenderable.rb', line 3

def shown
  @shown
end

#sizeObject

Returns the value of attribute size.



4
5
6
# File 'lib/savio/IORenderable.rb', line 4

def size
  @size
end

#xObject

Returns the value of attribute x.



4
5
6
# File 'lib/savio/IORenderable.rb', line 4

def x
  @x
end

#yObject

Returns the value of attribute y.



4
5
6
# File 'lib/savio/IORenderable.rb', line 4

def y
  @y
end

#zObject

Returns the value of attribute z.



4
5
6
# File 'lib/savio/IORenderable.rb', line 4

def z
  @z
end

Instance Method Details

#addObject



31
32
33
# File 'lib/savio/IORenderable.rb', line 31

def add()
  @shown = true
end

#contextObject



106
107
108
109
110
111
# File 'lib/savio/IORenderable.rb', line 106

def context()
  self.instance_variables.map do |attribute|
    key = attribute.to_s.gsub('@','').intern
    [key, self.instance_variable_get(attribute)]
  end.to_h
end

#drag(x, y) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/savio/IORenderable.rb', line 71

def drag(x, y)
  case @dragType
  when "move"
    if @isDragging == false
      @grabFixX = (x - @x).abs
      @grabFixY = (y - @y).abs
      @isDragging = true
    end
    if @isDragging == true
      @x = x - @grabFixX
      @y = y - @grabFixY
      rebuild()
    end
  when "duplicate"
    if @isDragging == false
      @grabFixX = (x - @x).abs
      @grabFixY = (y - @y).abs

      classType = Object.const_get(self.class.name)

      @duplicate = classType.new(self.context)
      @duplicate.enabled = false
      @duplicate.draggingEnabled = false
      @duplicate.dragType = "move"
      @isDragging = true
    end
    if @isDragging == true
      @duplicate.enabled = false
      @duplicate.draggingEnabled = false
      @duplicate.x = x - @grabFixX
      @duplicate.y = y - @grabFixY
    end
  end
end

#dragType=(type) ⇒ Object



65
66
67
68
69
# File 'lib/savio/IORenderable.rb', line 65

def dragType=(type)
  if type == "move" || type == "duplicate"
    @dragType = type
  end
end

#endDragObject



113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/savio/IORenderable.rb', line 113

def endDrag()
  if @isDragging
    if @dragType == "duplicate"
      @duplicate.draggingEnabled = true
      @duplicate.enabled = true
      @duplicate.allowDrag = false
      @duplicate = nil
    end
    @isDragging = false
    @allowDrag = false
  end
end

#initialize(args = {}) ⇒ Object



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

def initialize(args = {})
  Savio.addElement(self)

  @x = args[:x]             || 0
  @y = args[:y]             || 0
  @z = args[:z]             || 1

  @size = args[:size]       || 10

  @enabled = args[:enabled] || true
  @shown = args[:shown]     || true

  @displayName = args[:displayName] || ""

  @draggingEnabled = args[:draggingEnabled] || false
  @dragType = args[:dragType] || "move"
  @isDragging = false
  @allowDrag = false

end

#killObject



35
36
37
# File 'lib/savio/IORenderable.rb', line 35

def kill()
  remove()
end

#rebuildObject



39
40
41
42
# File 'lib/savio/IORenderable.rb', line 39

def rebuild()
  remove()
  build()
end

#removeObject



27
28
29
# File 'lib/savio/IORenderable.rb', line 27

def remove()
  @shown = false
end