Module: Rabbit::Renderer::Kernel

Included in:
Engine::Cairo, Print::Multiple
Defined in:
lib/rabbit/renderer/kernel.rb

Instance Method Summary collapse

Instance Method Details

#draw_background(slide) ⇒ Object



53
54
55
# File 'lib/rabbit/renderer/kernel.rb', line 53

def draw_background(slide)
  draw_rectangle(true, 0, 0, width, height, @background)
end

#draw_circle(filled, x, y, w, h, color = nil, params = {}) ⇒ Object



57
58
59
# File 'lib/rabbit/renderer/kernel.rb', line 57

def draw_circle(filled, x, y, w, h, color=nil, params={})
  draw_arc(filled, x, y, w, h, 0, 360, color, params)
end

#draw_circle_by_radius(filled, x, y, r, color = nil, params = {}) ⇒ Object



61
62
63
# File 'lib/rabbit/renderer/kernel.rb', line 61

def draw_circle_by_radius(filled, x, y, r, color=nil, params={})
  draw_arc_by_radius(filled, x, y, r, 0, 360, color, params)
end

#draw_cone(filled, x, y, z, base, height, slices, stacks, color = nil) ⇒ Object



184
185
186
# File 'lib/rabbit/renderer/kernel.rb', line 184

def draw_cone(filled, x, y, z, base, height, slices, stacks, color=nil)
  not_support_method("draw_cone")
end

#draw_cube(filled, x, y, z, size, color = nil) ⇒ Object



176
177
178
# File 'lib/rabbit/renderer/kernel.rb', line 176

def draw_cube(filled, x, y, z, size, color=nil)
  not_support_method("draw_cube")
end

#draw_dodecahedron(filled, x, y, z, color = nil) ⇒ Object



201
202
203
# File 'lib/rabbit/renderer/kernel.rb', line 201

def draw_dodecahedron(filled, x, y, z, color=nil)
  not_support_method("draw_dodecahedron")
end

#draw_flag(x, y, pole_height, params) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/rabbit/renderer/kernel.rb', line 65

def draw_flag(x, y, pole_height, params)
  if params["flag_type"] == "triangle"
    draw_triangle_flag(x, y, pole_height, params)
  else
    draw_rectangle_flag(x, y, pole_height, params)
  end
end

#draw_flag_layout(layout, x, y, pole_width, flag_width, text_height, flag_height) ⇒ Object



159
160
161
162
163
164
165
166
167
168
169
# File 'lib/rabbit/renderer/kernel.rb', line 159

def draw_flag_layout(layout, x, y, pole_width, flag_width,
                     text_height, flag_height)
  base_x = x + pole_width
  layout.width = flag_width * Pango::SCALE
  layout.alignment = Pango::Alignment::CENTER
  base_y = y
  if text_height < flag_height
    base_y += (flag_height - text_height) / 2
  end
  draw_layout(layout, base_x, base_y)
end

#draw_icosahedron(filled, x, y, z, color = nil) ⇒ Object



205
206
207
# File 'lib/rabbit/renderer/kernel.rb', line 205

def draw_icosahedron(filled, x, y, z, color=nil)
  not_support_method("draw_icosahedron")
end

#draw_octahedron(filled, x, y, z, color = nil) ⇒ Object



197
198
199
# File 'lib/rabbit/renderer/kernel.rb', line 197

def draw_octahedron(filled, x, y, z, color=nil)
  not_support_method("draw_octahedron")
end

#draw_rectangle_flag(x, y, pole_height, params) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/rabbit/renderer/kernel.rb', line 120

def draw_rectangle_flag(x, y, pole_height, params)
  params = setup_flag_params(pole_height, 1.3, params)

  layout = params["layout"]
  text_width = params["text_width"]
  text_height = params["text_height"]
  pole_width = params["pole_width"]
  pole_color = params["pole_color"]
  flag_height = params["flag_height"]
  flag_width = params["flag_width"]
  flag_color = params["flag_color"]
  flag_frame_width = params["flag_frame_width"]
  flag_frame_color = params["flag_frame_color"]

  draw_rectangle(true, x, y, pole_width, pole_height, pole_color)

  base_x = x + pole_width
  draw_rectangle(true,
                 base_x,
                 y,
                 flag_width,
                 flag_height,
                 flag_frame_color)
  draw_rectangle(true,
                 base_x,
                 y + flag_frame_width,
                 flag_width - flag_frame_width,
                 flag_height - 2 * flag_frame_width,
                 flag_color)

  if layout
    args = [
      layout, x, y, pole_width, flag_width - 2 * flag_frame_width,
      text_height, flag_height,
    ]
    draw_flag_layout(*args)
  end
end

#draw_slide(slide, simulation) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/rabbit/renderer/kernel.rb', line 43

def draw_slide(slide, simulation)
  unless simulation
    save_context
    draw_background(slide)
  end
  yield
ensure
  restore_context unless simulation
end

#draw_sphere(filled, x, y, z, radius, slices, stacks, color = nil) ⇒ Object



180
181
182
# File 'lib/rabbit/renderer/kernel.rb', line 180

def draw_sphere(filled, x, y, z, radius, slices, stacks, color=nil)
  not_support_method("draw_sphere")
end

#draw_teapot(filled, x, y, z, scale, color = nil) ⇒ Object



209
210
211
# File 'lib/rabbit/renderer/kernel.rb', line 209

def draw_teapot(filled, x, y, z, scale, color=nil)
  not_support_method("draw_teapot")
end

#draw_tetrahedron(filled, x, y, z, color = nil) ⇒ Object



193
194
195
# File 'lib/rabbit/renderer/kernel.rb', line 193

def draw_tetrahedron(filled, x, y, z, color=nil)
  not_support_method("draw_tetrahedron")
end

#draw_torus(filled, x, y, z, inner_radius, outer_radius, n_sides, rings, color = nil) ⇒ Object



188
189
190
191
# File 'lib/rabbit/renderer/kernel.rb', line 188

def draw_torus(filled, x, y, z, inner_radius, outer_radius,
               n_sides, rings, color=nil)
  not_support_method("draw_torus")
end

#draw_triangle_flag(x, y, pole_height, params) ⇒ Object



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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/rabbit/renderer/kernel.rb', line 73

def draw_triangle_flag(x, y, pole_height, params)
  params = setup_flag_params(pole_height, 1.5, params)

  layout = params["layout"]
  text_width = params["text_width"]
  text_height = params["text_height"]
  pole_width = params["pole_width"]
  pole_color = params["pole_color"]
  flag_height = params["flag_height"]
  flag_width = params["flag_width"]
  flag_color = params["flag_color"]
  flag_frame_width = params["flag_frame_width"]
  flag_frame_color = params["flag_frame_color"]

  draw_rectangle(true, x, y, pole_width, pole_height, pole_color)

  base_x = x + pole_width
  draw_polygon(true,
               [
                 [base_x, y],
                 [base_x + flag_width, y + flag_height / 2],
                 [base_x, y + flag_height],
               ],
               flag_frame_color)
  draw_polygon(true,
               [
                 [base_x, y + flag_frame_width],
                 [
                   base_x + flag_width - 2 * flag_frame_width,
                   y + flag_height / 2
                 ],
                 [
                   base_x,
                   y + flag_height - flag_frame_width
                 ],
               ],
               flag_color)

  if layout
    args = [
      layout, x, y, pole_width, flag_width * 0.8,
      text_height, flag_height,
    ]
    draw_flag_layout(*args)
  end
end

#flag_size(pole_height, params) ⇒ Object



171
172
173
174
# File 'lib/rabbit/renderer/kernel.rb', line 171

def flag_size(pole_height, params)
  params = setup_flag_params(pole_height, 1.5, params)
  [params["pole_width"] + params["flag_width"], pole_height]
end

#gl_call_list(id, x, y, z, color = nil) ⇒ Object



217
218
219
# File 'lib/rabbit/renderer/kernel.rb', line 217

def gl_call_list(id, x, y, z, color=nil)
  not_support_method("gl_call_list")
end

#gl_compile(id) ⇒ Object



213
214
215
# File 'lib/rabbit/renderer/kernel.rb', line 213

def gl_compile(id)
  not_support_method("gl_compile")
end

#gl_supported?Boolean

Returns:

  • (Boolean)


221
222
223
# File 'lib/rabbit/renderer/kernel.rb', line 221

def gl_supported?
  false
end

#make_color(color) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/rabbit/renderer/kernel.rb', line 6

def make_color(color)
  return color if color.is_a?(Color)
  if color.nil?
    @foreground
  else
    Color.parse(color)
  end
end

#new_list_idObject



233
234
235
236
# File 'lib/rabbit/renderer/kernel.rb', line 233

def new_list_id
  @list_id += 1
  @list_id
end

#reflect_context(base, params = {}) ⇒ Object



24
25
# File 'lib/rabbit/renderer/kernel.rb', line 24

def reflect_context(base, params={})
end

#restore_contextObject



40
41
# File 'lib/rabbit/renderer/kernel.rb', line 40

def restore_context
end

#rotate_context(angle, params = {}) ⇒ Object



18
19
# File 'lib/rabbit/renderer/kernel.rb', line 18

def rotate_context(angle, params={})
end

#save_contextObject



30
31
32
33
34
35
36
37
38
# File 'lib/rabbit/renderer/kernel.rb', line 30

def save_context
  if block_given?
    begin
      yield
    ensure
      restore_context
    end
  end
end

#scale_context(x, y, params = {}) ⇒ Object



21
22
# File 'lib/rabbit/renderer/kernel.rb', line 21

def scale_context(x, y, params={})
end

#shear_context(x, y, params = {}) ⇒ Object



27
28
# File 'lib/rabbit/renderer/kernel.rb', line 27

def shear_context(x, y, params={})
end

#translate_context(x, y, params = {}) ⇒ Object



15
16
# File 'lib/rabbit/renderer/kernel.rb', line 15

def translate_context(x, y, params={})
end

#z_farObject



225
226
227
# File 'lib/rabbit/renderer/kernel.rb', line 225

def z_far
  100.0
end

#z_viewObject



229
230
231
# File 'lib/rabbit/renderer/kernel.rb', line 229

def z_view
  5.0
end