Class: R2dEngine::DrawingInstructions
- Inherits:
-
Object
- Object
- R2dEngine::DrawingInstructions
- Defined in:
- lib/r2dsvg/r2dsvg_module.rb
Instance Attribute Summary collapse
-
#area ⇒ Object
Returns the value of attribute area.
Instance Method Summary collapse
- #draw_arc(args) ⇒ Object
- #draw_circle(args) ⇒ Object
- #draw_image(args) ⇒ Object
- #draw_line(args) ⇒ Object
-
#draw_lines(args) ⇒ Object
not yet implemented.
- #draw_polygon(args) ⇒ Object
- #draw_rectangle(args) ⇒ Object
- #draw_text(args) ⇒ Object
-
#embed_audio(args) ⇒ Object
Ruby 2D supports a number of popular audio formats, including WAV, MP3, Ogg Vorbis, and FLAC.
-
#initialize(window, debug: false) ⇒ DrawingInstructions
constructor
A new instance of DrawingInstructions.
- #render(a) ⇒ Object
- #script(args) ⇒ Object
- #style(args) ⇒ Object
- #window(args) ⇒ Object
Constructor Details
#initialize(window, debug: false) ⇒ DrawingInstructions
Returns a new instance of DrawingInstructions.
195 196 197 198 199 |
# File 'lib/r2dsvg/r2dsvg_module.rb', line 195 def initialize(window, debug: false) @window, @debug = window, debug end |
Instance Attribute Details
#area ⇒ Object
Returns the value of attribute area.
192 193 194 |
# File 'lib/r2dsvg/r2dsvg_module.rb', line 192 def area @area end |
Instance Method Details
#draw_arc(args) ⇒ Object
201 202 203 204 205 206 207 208 209 |
# File 'lib/r2dsvg/r2dsvg_module.rb', line 201 def draw_arc(args) dimensions, style = args x, y, width, height = dimensions #gc = gc_ini(fill: style[:fill] || :none) #@area.window.draw_arc(gc, 1, x, y, width, height, 0, 64 * 360) end |
#draw_circle(args) ⇒ Object
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/r2dsvg/r2dsvg_module.rb', line 211 def draw_circle(args) coords, radius, fill, style, e = args x1, y1 = coords if @debug then puts 'inside draw_circle'.info puts ('style: ' + style.inspect).debug end obj = Circle.new( x: x1, y: y1, radius: radius, sectors: 32, color: style[:fill], z: style[:"z-index"].to_i ) e.obj = obj if e.respond_to? :obj= @window.add obj end |
#draw_image(args) ⇒ Object
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/r2dsvg/r2dsvg_module.rb', line 234 def draw_image(args) dimensions, src, style, e = args x, y, width, height = dimensions filepath = Tempfile.new('r2dsvg').path + File.basename(src) puts 'filepath: ' + filepath.inspect if @debug File.write filepath, RXFHelper.read(src).first if File.exists? filepath then obj = Image.new( filepath, x: x, y: y, width: width, height: height, color: style[:fill], z: style[:"z-index"].to_i ) e.obj = obj if e.respond_to? :obj= @window.add obj end end |
#draw_line(args) ⇒ Object
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/r2dsvg/r2dsvg_module.rb', line 260 def draw_line(args) coords, style, e = args x1, y1, x2, y2 = coords if @debug then puts 'inside draw_rectangle'.info puts ('style: ' + style.inspect).debug end obj = Line.new( x1: x1, y1: y1, x2: x2, y2: y2, width: style[:"stroke-width"].to_f, color: style[:"stroke"], z: style[:"z-index"].to_i ) e.obj = obj if e.respond_to? :obj= @window.add obj end |
#draw_lines(args) ⇒ Object
not yet implemented
313 314 315 316 317 318 319 320 |
# File 'lib/r2dsvg/r2dsvg_module.rb', line 313 def draw_lines(args) coords, width, style, e = args x1, y1, x2, y2 = coords end |
#draw_polygon(args) ⇒ Object
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
# File 'lib/r2dsvg/r2dsvg_module.rb', line 284 def draw_polygon(args) vertices, style, e = args puts ('vertices: ' + vertices.inspect).debug if @debug if @debug then puts 'inside draw_polygon'.info puts ('style: ' + style.inspect).debug end puts ('vertices: ' + vertices.inspect).debug if @debug h = vertices.map.with_index do |coords,i| %w(x y).zip(coords).map {|key, c| [(key + (i+1).to_s).to_sym, c] } end.flatten(1).to_h puts ('triangle h: ' + h.inspect).debug if @debug puts ('triangle h merged: ' + h.inspect).debug if @debug obj = Triangle.new(h.merge({color: style[:fill], z: style[:"z-index"].to_i})) e.obj = obj if e.respond_to? :obj= @window.add obj end |
#draw_rectangle(args) ⇒ Object
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
# File 'lib/r2dsvg/r2dsvg_module.rb', line 322 def draw_rectangle(args) coords, style, e = args x1, y1, x2, y2 = coords if @debug then puts 'inside draw_rectangle'.info puts ('style: ' + style.inspect).debug end obj = Rectangle.new( x: x1, y: y1, width: x2 - x1, height: y2 - y1, color: style[:fill], z: style[:"z-index"].to_i ) e.obj = obj if e.respond_to? :obj= @window.add obj end |
#draw_text(args) ⇒ Object
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
# File 'lib/r2dsvg/r2dsvg_module.rb', line 344 def draw_text(args) coords, text, style, e = args x, y = coords if @debug then puts 'inside draw_text'.info puts ('style: ' + style.inspect).debug end obj = Text.new( text, x: x, y: y, #font: 'vera.ttf', size: style[:font_size].to_i, color: style[:color], z: style[:"z-index"].to_i ) puts 'e: ' + e.inspect e.obj = obj @window.add obj end |
#embed_audio(args) ⇒ Object
Ruby 2D supports a number of popular audio formats, including WAV, MP3, Ogg Vorbis, and FLAC.
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
# File 'lib/r2dsvg/r2dsvg_module.rb', line 372 def (args) sources, e = args if @debug then puts 'sources: ' + sources.inspect if @debug puts 'inside embed_audio'.info end audio_files = sources.map do |source| filepath = Tempfile.new('r2dsvg').path + File.basename(source[:src]) File.write filepath, RXFHelper.read(source[:src]).first filepath end audio = audio_files.find {|file| File.exists? file } return unless audio file = File.exists?(audio) ? audio : nil puts 'file: ' + file.inspect if @debug obj = Sound.new(file) e.obj = obj def e.play() self.obj.play() end end |
#render(a) ⇒ Object
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 |
# File 'lib/r2dsvg/r2dsvg_module.rb', line 406 def render(a) stylex, e = a[-3..-2] if e.respond_to? :attr_map then h = e.attr_map.inject({}) do |r, x| key, value = x r.merge!({value => stylex[key]}) end a[-3].merge!(h) end method(a[0]).call(args=a[1..2]) draw a[3] end |
#script(args) ⇒ Object
424 425 426 |
# File 'lib/r2dsvg/r2dsvg_module.rb', line 424 def script(args) end |
#style(args) ⇒ Object
428 429 |
# File 'lib/r2dsvg/r2dsvg_module.rb', line 428 def style(args) end |
#window(args) ⇒ Object
403 404 |
# File 'lib/r2dsvg/r2dsvg_module.rb', line 403 def window(args) end |