Module: DXRubyRP5::Window
- Defined in:
- lib/dxruby_rp5/window.rb
Class Method Summary collapse
- .caption ⇒ Object
- .caption=(val) ⇒ Object
- .draw(x, y, image, z = 0) ⇒ Object
- .draw_ex(x, y, image, hash = {}) ⇒ Object
- .draw_font(x, y, string, font, hash = {}) ⇒ Object (also: drawFont)
- .fps ⇒ Object
- .fps=(val) ⇒ Object
- .get_load ⇒ Object
- .height ⇒ Object
- .height=(_height) ⇒ Object
- .loop(&block) ⇒ Object
- .width ⇒ Object
- .width=(_width) ⇒ Object
Class Method Details
.caption ⇒ Object
24 25 26 |
# File 'lib/dxruby_rp5/window.rb', line 24 def caption return $app.frame.get_title end |
.caption=(val) ⇒ Object
28 29 30 |
# File 'lib/dxruby_rp5/window.rb', line 28 def caption=(val) $app.frame.set_title(val) end |
.draw(x, y, image, z = 0) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/dxruby_rp5/window.rb', line 59 def draw(x, y, image, z = 0) if @use_window_loop draw_task = { :proc => lambda { $app.image(image._surface, x, y) }, :z => z } @queue << draw_task else $app.image(image._surface, x, y) end end |
.draw_ex(x, y, image, hash = {}) ⇒ Object
71 72 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 |
# File 'lib/dxruby_rp5/window.rb', line 71 def draw_ex(x, y, image, hash = {}) if @use_window_loop draw_task = { :z => hash[:z] || 0, :proc => lambda do $app.push_matrix $app.translate(x, y) if hash[:scale_x] || hash[:scale_y] $app.scale(hash[:scale_x] || 1, hash[:scale_y] || 1) end if hash[:angle] $app.rotate($app.radians(hash[:angle])) end if hash[:alpha] $app.tint(255, hash[:alpha]) end $app.image(image._surface, 0, 0) $app.no_tint $app.pop_matrix end, } @queue << draw_task else $app.image(image._surface, x, y) end end |
.draw_font(x, y, string, font, hash = {}) ⇒ Object Also known as: drawFont
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 137 138 |
# File 'lib/dxruby_rp5/window.rb', line 101 def draw_font(x, y, string, font, hash = {}) if string.empty? return end if hash[:color] color = $app.color(*hash[:color]) else color = $app.color(255) end proc = lambda do $app.push_matrix $app.text_size(font.size) $app.text_font(font.native) # DXRubyでは文字の配置指定はできないため、都度text_alignを指定 # せず固定で良いかもしれない $app.text_align(Processing::App::LEFT, Processing::App::TOP) $app.fill(color) string.lines.each.with_index do |line, i| line.chomp! if line.empty? next end $app.text(string, x, y) end $app.pop_matrix end if @use_window_loop draw_task = { :proc => proc, :z => hash[:z] || 0, } @queue << draw_task else proc.call end end |
.fps ⇒ Object
32 33 34 |
# File 'lib/dxruby_rp5/window.rb', line 32 def fps $app.frame_rate end |
.fps=(val) ⇒ Object
36 37 38 |
# File 'lib/dxruby_rp5/window.rb', line 36 def fps=(val) $app.frame_rate(val) end |
.get_load ⇒ Object
40 41 42 43 |
# File 'lib/dxruby_rp5/window.rb', line 40 def get_load # TODO: return 0 end |
.height ⇒ Object
11 12 13 14 |
# File 'lib/dxruby_rp5/window.rb', line 11 def height @height ||= DEFAULTS[:height] return @height end |
.height=(_height) ⇒ Object
20 21 22 |
# File 'lib/dxruby_rp5/window.rb', line 20 def height=(_height) @height = _height end |
.loop(&block) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/dxruby_rp5/window.rb', line 45 def loop(&block) proc = Proc.new do background(*DEFAULTS[:background_color]) block.call Window.send(:exec_draw_tasks) Input.send(:handle_key_events) Input.send(:handle_pad_events) end Processing::App.sketch_class.class_eval { define_method(:draw, proc) } @use_window_loop = true @queue = [] end |
.width ⇒ Object
6 7 8 9 |
# File 'lib/dxruby_rp5/window.rb', line 6 def width @width ||= DEFAULTS[:width] return @width end |
.width=(_width) ⇒ Object
16 17 18 |
# File 'lib/dxruby_rp5/window.rb', line 16 def width=(_width) @width = _width end |