Module: DXRubyRP5::Window

Defined in:
lib/dxruby_rp5/window.rb

Class Method Summary collapse

Class Method Details

.captionObject



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



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/dxruby_rp5/window.rb', line 50

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



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/dxruby_rp5/window.rb', line 62

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



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
# File 'lib/dxruby_rp5/window.rb', line 92

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.text_size(font.size)
    $app.text_font(font.native)
    $app.fill(color)
    string.lines.each.with_index do |line, i|
      line.chomp!
      if line.empty?
        next
      end
      $app.text(string, x, y)
    end
  end

  if @use_window_loop
    draw_task = {
      :proc => proc,
      :z => hash[:z] || 0,
    }
    @queue << draw_task
  else
    proc.call
  end
end

.get_loadObject



32
33
34
35
# File 'lib/dxruby_rp5/window.rb', line 32

def get_load
  # TODO:
  return 0
end

.heightObject



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



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/dxruby_rp5/window.rb', line 37

def loop(&block)
  proc = Proc.new do
    background(*DEFAULTS[:background_color])
    block.call
    Window.send(:exec_draw_tasks)
    Input.send(:handle_key_events)
  end

  Processing::App.sketch_class.class_eval { define_method(:draw, proc) }
  @use_window_loop = true
  @queue = []
end

.widthObject



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