Module: GTK::Runtime::Draw

Defined in:
dragon/draw.rb

Instance Method Summary collapse

Instance Method Details

#draw_border(s) ⇒ Object


266
267
268
269
270
271
272
273
274
275
# File 'dragon/draw.rb', line 266

def draw_border s
  return unless s
  if s.respond_to? :draw_override
    s.draw_override @ffi_draw
  else
    @ffi_draw.draw_border s.x, s.y, s.w, s.h, s.r, s.g, s.b, s.a
  end
rescue Exception => e
  raise_conversion_for_rendering_failed s, e, :border
end

#draw_label(l) ⇒ Object


241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'dragon/draw.rb', line 241

def draw_label l
  return unless l
  if l.respond_to? :draw_override
    l.draw_override @ffi_draw
  else
    @ffi_draw.draw_label l.x, l.y, l.text.s_or_default,
                         l.size_enum, l.alignment_enum,
                         l.r, l.g, l.b, l.a,
                         l.font.s_or_default(nil)
  end
rescue Exception => e
  raise_conversion_for_rendering_failed l, e, :label
end

#draw_line(l) ⇒ Object


255
256
257
258
259
260
261
262
263
264
# File 'dragon/draw.rb', line 255

def draw_line l
  return unless l
  if l.respond_to? :draw_override
    l.draw_override @ffi_draw
  else
    @ffi_draw.draw_line l.x, l.y, l.x2, l.y2, l.r, l.g, l.b, l.a
  end
rescue Exception => e
  raise_conversion_for_rendering_failed l, e, :line
end

#draw_screenshot(s) ⇒ Object


223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'dragon/draw.rb', line 223

def draw_screenshot s
  return unless s
  if s.respond_to? :draw_override
    s.draw_override @ffi_draw
  else
    @ffi_draw.draw_screenshot s.path.s_or_default,
                              s.x, s.y, s.w, s.h,
                              s.angle,
                              s.a, s.r, s.g, s.b,
                              s.tile_x, s.tile_y, s.tile_w, s.tile_h,
                              !!s.flip_horizontally, !!s.flip_vertically,
                              s.angle_anchor_x, s.angle_anchor_y,
                              s.source_x, s.source_y, s.source_w, s.source_h
  end
rescue Exception => e
  raise_conversion_for_rendering_failed s, e, :screenshot
end

#draw_screenshotsObject


277
278
279
# File 'dragon/draw.rb', line 277

def draw_screenshots
  @args.outputs.screenshots.each { |s| draw_screenshot s }
end

#draw_solid(s) ⇒ Object


194
195
196
197
198
199
200
201
202
203
# File 'dragon/draw.rb', line 194

def draw_solid s
  return unless s
  if s.respond_to? :draw_override
    s.draw_override @ffi_draw
  else
    @ffi_draw.draw_solid s.x, s.y, s.w, s.h, s.r, s.g, s.b, s.a
  end
rescue Exception => e
  raise_conversion_for_rendering_failed s, e, :solid
end

#draw_sprite(s) ⇒ Object


205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'dragon/draw.rb', line 205

def draw_sprite s
  return unless s
  if s.respond_to? :draw_override
    s.draw_override @ffi_draw
  else
    @ffi_draw.draw_sprite_3 s.x, s.y, s.w, s.h,
                            s.path.s_or_default,
                            s.angle,
                            s.a, s.r, s.g, s.b,
                            s.tile_x, s.tile_y, s.tile_w, s.tile_h,
                            !!s.flip_horizontally, !!s.flip_vertically,
                            s.angle_anchor_x, s.angle_anchor_y,
                            s.source_x, s.source_y, s.source_w, s.source_h
  end
rescue Exception => e
  raise_conversion_for_rendering_failed s, e, :sprite
end

#execute_draw_order(pass) ⇒ Object


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'dragon/draw.rb', line 10

def execute_draw_order pass
  # Don't change this draw order unless you understand
  # the implications.
  render_solids pass
  render_static_solids pass
  render_sprites pass
  render_static_sprites pass
  render_primitives pass
  render_static_primitives pass
  render_labels pass
  render_static_labels pass
  render_lines pass
  render_static_lines pass
  render_borders pass
  render_static_borders pass
end

#pixel_arraysObject


281
282
283
284
285
286
287
288
289
290
# File 'dragon/draw.rb', line 281

def pixel_arrays
  @args.pixel_arrays.each { |k,v|
    if v.pixels.length == (v.width * v.height)  # !!! FIXME: warning? exception? Different API?
      @ffi_draw.upload_pixel_array k.to_s, v.width.to_i, v.height.to_i, v.pixels
    end
  }
rescue Exception => e
  pause!
  pretty_print_exception_and_export! e
end

#primitives(pass) ⇒ Object


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'dragon/draw.rb', line 27

def primitives pass
  if $top_level.respond_to? :primitives_override
    return $top_level.tick_render @args, pass
  end

  execute_draw_order pass

  if !$gtk.production
    # pass.debug.each        { |r| draw_primitive r }
    idx = 0
    length = pass.debug.length
    while idx < length
      draw_primitive (pass.debug.at idx)
      idx += 1
    end

    # pass.static_debug.each { |r| draw_primitive r }
    idx = 0
    length = pass.static_debug.length
    while idx < length
      draw_primitive (pass.static_debug.at idx)
      idx += 1
    end
  end

  # pass.reserved.each          { |r| draw_primitive r }
  idx = 0
  length = pass.reserved.length
  while idx < length
    draw_primitive (pass.reserved.at idx)
    idx += 1
  end

  # pass.static_reserved.each   { |r| draw_primitive r }
  idx = 0
  length = pass.static_reserved.length
  while idx < length
    draw_primitive (pass.static_reserved.at idx)
    idx += 1
  end
rescue Exception => e
  pause!
  pretty_print_exception_and_export! e
end

#render_borders(pass) ⇒ Object


174
175
176
177
178
179
180
181
182
# File 'dragon/draw.rb', line 174

def render_borders pass
  # pass.borders.each           { |b| draw_border b }
  idx = 0
  length = pass.borders.length
  while idx < length
    draw_border (pass.borders.at idx)
    idx += 1
  end
end

#render_labels(pass) ⇒ Object


134
135
136
137
138
139
140
141
142
# File 'dragon/draw.rb', line 134

def render_labels pass
  # pass.labels.each            { |l| draw_label l }
  idx = 0
  length = pass.labels.length
  while idx < length
    draw_label (pass.labels.at idx)
    idx += 1
  end
end

#render_lines(pass) ⇒ Object


154
155
156
157
158
159
160
161
162
# File 'dragon/draw.rb', line 154

def render_lines pass
  # pass.lines.each             { |l| draw_line l }
  idx = 0
  length = pass.lines.length
  while idx < length
    draw_line (pass.lines.at idx)
    idx += 1
  end
end

#render_primitives(pass) ⇒ Object


114
115
116
117
118
119
120
121
122
# File 'dragon/draw.rb', line 114

def render_primitives pass
  # pass.primitives.each        { |p| draw_primitive p }
  idx = 0
  length = pass.primitives.length
  while idx < length
    draw_primitive (pass.primitives.at idx)
    idx += 1
  end
end

#render_solids(pass) ⇒ Object


73
74
75
76
77
78
79
80
81
82
# File 'dragon/draw.rb', line 73

def render_solids pass
  # pass.solids.each            { |s| draw_solid s }
  # while loops are faster than each with block
  idx = 0
  length = pass.solids.length
  while idx < pass.solids.length
    draw_solid (pass.solids.at idx) # accessing an array using .value instead of [] is faster
    idx += 1
  end
end

#render_sprites(pass) ⇒ Object


94
95
96
97
98
99
100
101
102
# File 'dragon/draw.rb', line 94

def render_sprites pass
  # pass.sprites.each           { |s| draw_sprite s }
  idx = 0
  length = pass.sprites.length
  while idx < length
    draw_sprite (pass.sprites.at idx)
    idx += 1
  end
end

#render_static_borders(pass) ⇒ Object


184
185
186
187
188
189
190
191
192
# File 'dragon/draw.rb', line 184

def render_static_borders pass
  # pass.static_borders.each    { |b| draw_border b }
  idx = 0
  length = pass.static_borders.length
  while idx < length
    draw_border (pass.static_borders.at idx)
    idx += 1
  end
end

#render_static_labels(pass) ⇒ Object


144
145
146
147
148
149
150
151
152
# File 'dragon/draw.rb', line 144

def render_static_labels pass
  # pass.static_labels.each     { |l| draw_label l }
  idx = 0
  length = pass.static_labels.length
  while idx < length
    draw_label (pass.static_labels.at idx)
    idx += 1
  end
end

#render_static_lines(pass) ⇒ Object


164
165
166
167
168
169
170
171
172
# File 'dragon/draw.rb', line 164

def render_static_lines pass
  # pass.static_lines.each      { |l| draw_line l }
  idx = 0
  length = pass.static_lines.length
  while idx < pass.static_lines.length
    draw_line (pass.static_lines.at idx)
    idx += 1
  end
end

#render_static_primitives(pass) ⇒ Object


124
125
126
127
128
129
130
131
132
# File 'dragon/draw.rb', line 124

def render_static_primitives pass
  # pass.static_primitives.each { |p| draw_primitive p }
  idx = 0
  length = pass.static_primitives.length
  while idx < length
    draw_primitive (pass.static_primitives.at idx)
    idx += 1
  end
end

#render_static_solids(pass) ⇒ Object


84
85
86
87
88
89
90
91
92
# File 'dragon/draw.rb', line 84

def render_static_solids pass
  # pass.static_solids.each     { |s| draw_solid s }
  idx = 0
  length = pass.static_solids.length
  while idx < length
    draw_solid (pass.static_solids.at idx)
    idx += 1
  end
end

#render_static_sprites(pass) ⇒ Object


104
105
106
107
108
109
110
111
112
# File 'dragon/draw.rb', line 104

def render_static_sprites pass
  # pass.static_sprites.each    { |s| draw_sprite s }
  idx = 0
  length = pass.static_sprites.length
  while idx < length
    draw_sprite (pass.static_sprites.at idx)
    idx += 1
  end
end