Class: Clogs::Path

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

Overview

A path under construction. libui aborts the process if a path is ended twice or drawn before being ended, so the state is tracked here rather than left to callers.

Constant Summary collapse

K =

Four beziers approximate an ellipse closely enough for UI work and avoid needing a scale matrix per oval (libui arcs are always circular).

0.5522847498307936

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fill_mode) ⇒ Path

Returns a new instance of Path.



12
13
14
15
# File 'lib/clogs/painter.rb', line 12

def initialize(fill_mode)
  @ptr = UI::L.draw_new_path(fill_mode)
  @ended = false
end

Instance Attribute Details

#ptrObject (readonly)

Returns the value of attribute ptr.



10
11
12
# File 'lib/clogs/painter.rb', line 10

def ptr
  @ptr
end

Instance Method Details

#arc_figure(cx, cy, radius, start_angle, sweep, negative = false) ⇒ Object



37
38
39
40
# File 'lib/clogs/painter.rb', line 37

def arc_figure(cx, cy, radius, start_angle, sweep, negative = false)
  UI::L.draw_path_new_figure_with_arc(@ptr, cx, cy, radius, start_angle, sweep, negative ? 1 : 0)
  self
end

#arc_to(cx, cy, radius, start_angle, sweep, negative = false) ⇒ Object



32
33
34
35
# File 'lib/clogs/painter.rb', line 32

def arc_to(cx, cy, radius, start_angle, sweep, negative = false)
  UI::L.draw_path_arc_to(@ptr, cx, cy, radius, start_angle, sweep, negative ? 1 : 0)
  self
end

#closeObject



63
64
65
66
# File 'lib/clogs/painter.rb', line 63

def close
  UI::L.draw_path_close_figure(@ptr)
  self
end

#curve_to(c1x, c1y, c2x, c2y, x, y) ⇒ Object



27
28
29
30
# File 'lib/clogs/painter.rb', line 27

def curve_to(c1x, c1y, c2x, c2y, x, y)
  UI::L.draw_path_bezier_to(@ptr, c1x, c1y, c2x, c2y, x, y)
  self
end

#end!Object



68
69
70
71
72
73
74
# File 'lib/clogs/painter.rb', line 68

def end!
  return self if @ended

  @ended = true
  UI::L.draw_path_end(@ptr)
  self
end

#freeObject



76
77
78
79
# File 'lib/clogs/painter.rb', line 76

def free
  UI::L.draw_free_path(@ptr) if @ptr
  @ptr = nil
end

#line_to(x, y) ⇒ Object



22
23
24
25
# File 'lib/clogs/painter.rb', line 22

def line_to(x, y)
  UI::L.draw_path_line_to(@ptr, x, y)
  self
end

#move_to(x, y) ⇒ Object



17
18
19
20
# File 'lib/clogs/painter.rb', line 17

def move_to(x, y)
  UI::L.draw_path_new_figure(@ptr, x, y)
  self
end

#oval(x, y, w, h) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/clogs/painter.rb', line 50

def oval(x, y, w, h)
  rx = w / 2.0
  ry = h / 2.0
  cx = x + rx
  cy = y + ry
  move_to(cx + rx, cy)
  curve_to(cx + rx, cy + ry * K, cx + rx * K, cy + ry, cx, cy + ry)
  curve_to(cx - rx * K, cy + ry, cx - rx, cy + ry * K, cx - rx, cy)
  curve_to(cx - rx, cy - ry * K, cx - rx * K, cy - ry, cx, cy - ry)
  curve_to(cx + rx * K, cy - ry, cx + rx, cy - ry * K, cx + rx, cy)
  close
end

#rect(x, y, w, h) ⇒ Object



42
43
44
45
# File 'lib/clogs/painter.rb', line 42

def rect(x, y, w, h)
  UI::L.draw_path_add_rectangle(@ptr, x, y, w, h)
  self
end