Class: Rays::Painter

Inherits:
Object
  • Object
show all
Defined in:
lib/rays/painter.rb

Instance Method Summary collapse

Instance Method Details

#bezier(*args, loop: false) ⇒ Object



78
79
80
# File 'lib/rays/painter.rb', line 78

def bezier(*args, loop: false)
  bezier! args, loop
end

#colorObject



87
88
89
# File 'lib/rays/painter.rb', line 87

def color()
  return fill, stroke
end

#color=(fill, stroke = nil) ⇒ Object



82
83
84
85
# File 'lib/rays/painter.rb', line 82

def color=(fill, stroke = nil)
  self.fill   fill
  self.stroke stroke
end

#curve(*args, loop: false) ⇒ Object



74
75
76
# File 'lib/rays/painter.rb', line 74

def curve(*args, loop: false)
  curve! args, loop
end

#ellipse(*args, center: nil, radius: nil, hole: nil, from: nil, to: nil) ⇒ Object



70
71
72
# File 'lib/rays/painter.rb', line 70

def ellipse(*args, center: nil, radius: nil, hole: nil, from: nil, to: nil)
  ellipse! args, center, radius, hole, from, to
end

#line(*args, loop: false) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/rays/painter.rb', line 58

def line(*args, loop: false)
  if args.first.kind_of?(Polyline)
    polyline! args.first
  else
    line! args, loop
  end
end

#paint(*args, &block) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/rays/painter.rb', line 50

def paint(*args, &block)
  begin_paint
  Xot::BlockUtil.instance_eval_or_block_call self, *args, &block
  self
ensure
  end_paint
end

#pop(*types) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/rays/painter.rb', line 40

def pop(*types)
  each_type types, reverse: true do |type|
    case type
    when :state  then pop_state
    when :matrix then pop_matrix
    else raise ArgumentError, "invalid push/pop type '#{type}'."
    end
  end
end

#push(*types, **attributes, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rays/painter.rb', line 12

def push(*types, **attributes, &block)
  each_type types do |type|
    case type
    when :state  then push_state
    when :matrix then push_matrix
    else raise ArgumentError, "invalid push/pop type '#{type}'."
    end
  end

  raise ArgumentError, 'missing block with pushing attributes.' if
    !attributes.empty? && !block

  if block
    attributes.each do |key, value|
      attributes[key] = __send__ key
      __send__ key, *(value.nil? ? [nil] : value)
    end
    Xot::BlockUtil.instance_eval_or_block_call self, &block
  end
ensure
  if block
    attributes.each do |key, value|
      __send__ key, *(value.nil? ? [nil] : value)
    end
    pop(*types)
  end
end

#rect(*args, round: nil, lt: nil, rt: nil, lb: nil, rb: nil) ⇒ Object



66
67
68
# File 'lib/rays/painter.rb', line 66

def rect(*args, round: nil, lt: nil, rt: nil, lb: nil, rb: nil)
  rect! args, round, lt, rt, lb, rb
end

#shader=(shader, **uniforms) ⇒ Object



91
92
93
94
95
# File 'lib/rays/painter.rb', line 91

def shader=(shader, **uniforms)
  shader = Shader.new shader if shader.is_a?(String)
  shader.uniform(**uniforms) if shader && !uniforms.empty?
  set_shader shader
end