Class: RbSDL2::Window::HitTest
- Inherits:
-
FFI::Function
- Object
- FFI::Function
- RbSDL2::Window::HitTest
- Defined in:
- lib/rb_sdl2/window/hit_test.rb
Constant Summary collapse
- HIT_TEST_RESULT =
Hash.new(::SDL2::SDL_HITTEST_NORMAL).merge!( :normal => ::SDL2::SDL_HITTEST_NORMAL, :draggable => ::SDL2::SDL_HITTEST_DRAGGABLE, :top_left => ::SDL2::SDL_HITTEST_RESIZE_TOPLEFT, :top => ::SDL2::SDL_HITTEST_RESIZE_TOP, :top_right => ::SDL2::SDL_HITTEST_RESIZE_TOPRIGHT, :resize_right => ::SDL2::SDL_HITTEST_RESIZE_RIGHT, :bottom_right => ::SDL2::SDL_HITTEST_RESIZE_BOTTOMRIGHT, :bottom => ::SDL2::SDL_HITTEST_RESIZE_BOTTOM, :bottom_left => ::SDL2::SDL_HITTEST_RESIZE_BOTTOMLEFT, :resize_left => ::SDL2::SDL_HITTEST_RESIZE_LEFT, ).freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(&block) ⇒ HitTest
constructor
A new instance of HitTest.
Constructor Details
#initialize(&block) ⇒ HitTest
Returns a new instance of HitTest.
41 42 43 44 45 46 47 48 49 |
# File 'lib/rb_sdl2/window/hit_test.rb', line 41 def initialize(&block) # typedef SDL_HitTestResult (*SDL_HitTest)(SDL_Window *win, # const SDL_Point *area, void *data); super(:int, [:pointer, :pointer, :pointer]) do |win, area, _data| # コールバック実行終了を OS が待つようなので、与えらえた window ポインターは有効なものとしてよいだろう。 # area には SDL_Point のアドレスが入る。SDL_Point は x, y の2つの int 型メンバーである。 HIT_TEST_RESULT[yield(Window.to_ptr(win), ::SDL2::SDL_Point.new(area).values)] end end |
Class Method Details
.callback_set(window, obj, userdata = nil) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rb_sdl2/window/hit_test.rb', line 8 def callback_set(window, obj, userdata = nil) func = if Proc === obj new(&obj) else obj end @mutex.synchronize do err = ::SDL2.SDL_SetWindowHitTest(window, func, userdata) raise RbSDL2Error if err < 0 id = window.id if obj @callbacks[id] = [func, userdata] else @callbacks.delete(id) end end [obj, userdata] end |