summaryrefslogtreecommitdiffhomepage
path: root/mrblib/raylib.rb
blob: 9856e5b8072832db3bb357b977fccfff5ad3fb53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
Rl = Raylib

module Raylib
  class << self
    attr_accessor :defined_loop
    attr_accessor :data_keys_pressed

    def while_window_open(&block)
      self.defined_loop = block
      if Raylib.platform == 'desktop'
        while !Raylib.window_should_close? do
          self.main_loop
        end
      elsif Raylib.platform == 'web'
        Raylib.emscripten_set_main_loop
      end
    end

    def main_loop
      self.data_keys_pressed = nil
      self.defined_loop.call
    end


    def draw_text(text:, x:, y:, font_size:, color:)
      self._draw_text(text, x, y, font_size, color)
    end

    def draw_texture(texture:, x:, y:, tint: Rl::Color.new(255,255,255,255))
      self._draw_texture(texture, x, y, tint)
    end

    def draw_texture_ex(texture:, pos:, rotation:, scale:, tint: Rl::Color.new(255,255,255,255))
      self._draw_texture_ex(texture, pos, rotation, scale, tint)
    end

    def draw_texture_pro(texture:, source:, dest:, origin:, rotation:, tint: Rl::Color.new(255,255,255,255))
      self._draw_texture_pro(texture, source, dest, origin, rotation, tint)
    end

    def keys_pressed
      if self.data_keys_pressed
        return self.data_keys_pressed
      end
      self.data_keys_pressed = []
      key = self._key_pressed
      while key != 0
        self.data_keys_pressed.push key
        key = self._key_pressed
      end
      self.data_keys_pressed
    end
  end
end