Method: SDL.setup_touch_symbols

Defined in:
lib/sdl2_touch.rb

.setup_touch_symbols(output_error = false) ⇒ Object

Function



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/sdl2_touch.rb', line 43

def self.setup_touch_symbols(output_error = false)
  symbols = [
    :SDL_GetNumTouchDevices,
    :SDL_GetTouchDevice,
    :SDL_GetTouchName,
    :SDL_GetTouchDeviceType,
    :SDL_GetNumTouchFingers,
    :SDL_GetTouchFinger,
  ]
  apis = {
    :SDL_GetNumTouchDevices => :GetNumTouchDevices,
    :SDL_GetTouchDevice => :GetTouchDevice,
    :SDL_GetTouchName => :GetTouchName,
    :SDL_GetTouchDeviceType => :GetTouchDeviceType,
    :SDL_GetNumTouchFingers => :GetNumTouchFingers,
    :SDL_GetTouchFinger => :GetTouchFinger,
  }
  args = {
    :SDL_GetNumTouchDevices => [],
    :SDL_GetTouchDevice => [:int],
    :SDL_GetTouchName => [:int],
    :SDL_GetTouchDeviceType => [:long_long],
    :SDL_GetNumTouchFingers => [:long_long],
    :SDL_GetTouchFinger => [:long_long, :int],
  }
  retvals = {
    :SDL_GetNumTouchDevices => :int,
    :SDL_GetTouchDevice => :long_long,
    :SDL_GetTouchName => :pointer,
    :SDL_GetTouchDeviceType => :int,
    :SDL_GetNumTouchFingers => :int,
    :SDL_GetTouchFinger => :pointer,
  }
  symbols.each do |sym|
    begin
      attach_function apis[sym], sym, args[sym], retvals[sym]
    rescue FFI::NotFoundError => error
      $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error
    end
  end
end