Module: RbSDL2::Event::EventQueue
- Defined in:
- lib/rb_sdl2/event/event_queue.rb
Class Method Summary collapse
- .clear ⇒ Object
- .count(type: nil) ⇒ Object (also: length, size)
- .deq(non_block = false, type: nil) ⇒ Object
-
.each ⇒ Object
ブロックにはイベントキューにあるイベントが渡される。 ブロックへ渡されるイベントはコピーされたものでありブロックの外へ持ち出すことができる。 このメソッドは SDL のイベントキューをロックする。.
- .empty? ⇒ Boolean
-
.enq(event, non_block = false) ⇒ Object
イベントキューが一杯の時に 例外.
- .poll ⇒ Object (also: get)
- .pump ⇒ Object
-
.push(event) ⇒ Object
イベントをキューに入れる。enq との違いは push ではイベントコールバックを起動する。 イベントがキューに入った場合は引数のイベントを戻す。フィルターされた場合は nil を戻す。 キューに入れることを失敗したら例外が発生する。.
- .quit? ⇒ Boolean
-
.reject!(userdata = nil) ⇒ Object
ブロックへ与えられたイベントは外に持ち出すことはできない。 このメソッドは SDL のイベントキューをロックする。 ブロックの戻り値が false の場合、イベントはキューから取り除かれる。 userdata に渡されたオブジェクトはポインターに変換可能なものである必要がある。.
- .wait(sec = nil) ⇒ Object
Class Method Details
.clear ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/rb_sdl2/event/event_queue.rb', line 7 def clear # type が ::SDL2::SDL_DROPFILE, ::SDL2::SDL_DROPTEXT の場合に # イベントに含まれる file メンバーのポインターが開放されない。そのため Ruby 側で開放処理を行う。 event = Event.new while peep(event, ::SDL2::SDL_GETEVENT, type: ::SDL2::SDL_DROPFILE..::SDL2::SDL_DROPTEXT) > 0 event.clear end ::SDL2.SDL_FlushEvents(*EventType.minmax) end |
.count(type: nil) ⇒ Object Also known as: length, size
18 |
# File 'lib/rb_sdl2/event/event_queue.rb', line 18 def count(type: nil) = peep(nil, ::SDL2::SDL_PEEKEVENT, type: type) |
.deq(non_block = false, type: nil) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/rb_sdl2/event/event_queue.rb', line 22 def deq(non_block = false, type: nil) event = Event.new while peep(event, ::SDL2::SDL_GETEVENT, type: type) == 0 raise ThreadError, Error. if non_block end event end |
.each ⇒ Object
ブロックにはイベントキューにあるイベントが渡される。ブロックへ渡されるイベントはコピーされたものでありブロックの外へ持ち出すことができる。このメソッドは SDL のイベントキューをロックする。
33 |
# File 'lib/rb_sdl2/event/event_queue.rb', line 33 def each = block_given? ? reject! { |event| yield(event.dup); true } : to_enum |
.empty? ⇒ Boolean
35 |
# File 'lib/rb_sdl2/event/event_queue.rb', line 35 def empty? = length == 0 |
.enq(event, non_block = false) ⇒ Object
イベントキューが一杯の時に 例外
38 39 40 41 42 43 44 45 |
# File 'lib/rb_sdl2/event/event_queue.rb', line 38 def enq(event, non_block = false) event_copy(event) do |copy| while peep(copy, ::SDL2::SDL_ADDEVENT) == 0 raise ThreadError, Error. if non_block end event end end |
.poll ⇒ Object Also known as: get
79 80 81 82 83 |
# File 'lib/rb_sdl2/event/event_queue.rb', line 79 def poll main_thread! event = Event.new ::SDL2::SDL_PollEvent(event).nonzero? && event end |
.pump ⇒ Object
86 87 88 89 |
# File 'lib/rb_sdl2/event/event_queue.rb', line 86 def pump main_thread! ::SDL2.SDL_PumpEvents end |
.push(event) ⇒ Object
イベントをキューに入れる。enq との違いは push ではイベントコールバックを起動する。イベントがキューに入った場合は引数のイベントを戻す。フィルターされた場合は nil を戻す。キューに入れることを失敗したら例外が発生する。
94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/rb_sdl2/event/event_queue.rb', line 94 def push(event) event_copy(event) do |copy| num = ::SDL2.SDL_PushEvent(copy) if num > 0 event elsif num == 0 nil else raise RbSDL2Error end end end |
.quit? ⇒ Boolean
107 108 109 110 |
# File 'lib/rb_sdl2/event/event_queue.rb', line 107 def quit? pump ::SDL2.SDL_HasEvent(::SDL2::SDL_QUIT) == ::SDL2::SDL_TRUE end |
.reject!(userdata = nil) ⇒ Object
ブロックへ与えられたイベントは外に持ち出すことはできない。このメソッドは SDL のイベントキューをロックする。ブロックの戻り値が false の場合、イベントはキューから取り除かれる。userdata に渡されたオブジェクトはポインターに変換可能なものである必要がある。
118 119 120 121 |
# File 'lib/rb_sdl2/event/event_queue.rb', line 118 def reject!(userdata = nil) func = EventFilter.new { |event| yield(event) || (event.clear; nil) } ::SDL2.SDL_FilterEvents(func, userdata) end |
.wait(sec = nil) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/rb_sdl2/event/event_queue.rb', line 123 def wait(sec = nil) main_thread! event = Event.new if sec.nil? ::SDL2::SDL_WaitEvent(event).nonzero? && event elsif sec >= 0 ::SDL2::SDL_WaitEventTimeout(event, sec * 1000).nonzero? && event else raise ArgumentError end end |