Module: Rabbit::Renderer::Kernel

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

Instance Method Summary collapse

Instance Method Details

#draw_background(slide) ⇒ Object



71
72
73
# File 'lib/rabbit/renderer/kernel.rb', line 71

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

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



75
76
77
# File 'lib/rabbit/renderer/kernel.rb', line 75

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



79
80
81
# File 'lib/rabbit/renderer/kernel.rb', line 79

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



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

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



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

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



219
220
221
# File 'lib/rabbit/renderer/kernel.rb', line 219

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

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



83
84
85
86
87
88
89
# File 'lib/rabbit/renderer/kernel.rb', line 83

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



177
178
179
180
181
182
183
184
185
186
187
# File 'lib/rabbit/renderer/kernel.rb', line 177

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



223
224
225
# File 'lib/rabbit/renderer/kernel.rb', line 223

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

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



215
216
217
# File 'lib/rabbit/renderer/kernel.rb', line 215

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

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



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/rabbit/renderer/kernel.rb', line 138

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



61
62
63
64
65
66
67
68
69
# File 'lib/rabbit/renderer/kernel.rb', line 61

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



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

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



227
228
229
# File 'lib/rabbit/renderer/kernel.rb', line 227

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



211
212
213
# File 'lib/rabbit/renderer/kernel.rb', line 211

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



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

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



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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/rabbit/renderer/kernel.rb', line 91

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



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

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



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

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

#gl_compile(id) ⇒ Object



231
232
233
# File 'lib/rabbit/renderer/kernel.rb', line 231

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

#gl_supported?Boolean

Returns:

  • (Boolean)


239
240
241
# File 'lib/rabbit/renderer/kernel.rb', line 239

def gl_supported?
  false
end

#make_color(color) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/rabbit/renderer/kernel.rb', line 24

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

#new_list_idObject



251
252
253
254
# File 'lib/rabbit/renderer/kernel.rb', line 251

def new_list_id
  @list_id += 1
  @list_id
end

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



42
43
# File 'lib/rabbit/renderer/kernel.rb', line 42

def reflect_context(base, params={})
end

#restore_contextObject



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

def restore_context
end

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



36
37
# File 'lib/rabbit/renderer/kernel.rb', line 36

def rotate_context(angle, params={})
end

#save_contextObject



48
49
50
51
52
53
54
55
56
# File 'lib/rabbit/renderer/kernel.rb', line 48

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

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



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

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

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



45
46
# File 'lib/rabbit/renderer/kernel.rb', line 45

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

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



33
34
# File 'lib/rabbit/renderer/kernel.rb', line 33

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

#z_farObject



243
244
245
# File 'lib/rabbit/renderer/kernel.rb', line 243

def z_far
  100.0
end

#z_viewObject



247
248
249
# File 'lib/rabbit/renderer/kernel.rb', line 247

def z_view
  5.0
end