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 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 84 85 86 87 88 89 90 91 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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
#if defined(INPUT_CARBON)
#include <ruby/input/carbon.cpp>
#endif
#if defined(INPUT_QUARTZ)
#include <ruby/input/quartz.cpp>
#endif
#if defined(INPUT_SDL)
#include <ruby/input/sdl.cpp>
#endif
#if defined(INPUT_UDEV)
#include <ruby/input/udev.cpp>
#endif
#if defined(INPUT_UHID)
#include <ruby/input/uhid.cpp>
#endif
#if defined(INPUT_WINDOWS)
#include <ruby/input/windows.cpp>
#endif
#if defined(INPUT_XLIB)
#include <ruby/input/xlib.cpp>
#endif
namespace ruby {
auto Input::setContext(uintptr context) -> bool {
if(instance->context == context) return true;
if(!instance->hasContext()) return false;
if(!instance->setContext(instance->context = context)) return false;
return true;
}
//
auto Input::acquired() -> bool {
return instance->acquired();
}
auto Input::acquire() -> bool {
return instance->acquire();
}
auto Input::release() -> bool {
return instance->release();
}
auto Input::poll() -> vector<shared_pointer<nall::HID::Device>> {
return instance->poll();
}
auto Input::rumble(u64 id, u16 strong, u16 weak) -> bool {
return instance->rumble(id, strong, weak);
}
//
auto Input::onChange(const function<void (shared_pointer<HID::Device>, u32, u32, s16, s16)>& onChange) -> void {
change = onChange;
}
auto Input::doChange(shared_pointer<HID::Device> device, u32 group, u32 input, s16 oldValue, s16 newValue) -> void {
if(change) change(device, group, input, oldValue, newValue);
}
//
auto Input::create(string driver) -> bool {
self.instance.reset();
if(!driver) driver = optimalDriver();
#if defined(INPUT_WINDOWS)
if(driver == "Windows") self.instance = new InputWindows(*this);
#endif
#if defined(INPUT_QUARTZ)
if(driver == "Quartz") self.instance = new InputQuartz(*this);
#endif
#if defined(INPUT_CARBON)
if(driver == "Carbon") self.instance = new InputCarbon(*this);
#endif
#if defined(INPUT_UDEV)
if(driver == "udev") self.instance = new InputUdev(*this);
#endif
#if defined(INPUT_UHID)
if(driver == "uhid") self.instance = new InputUHID(*this);
#endif
#if defined(INPUT_SDL)
if(driver == "SDL") self.instance = new InputSDL(*this);
#endif
#if defined(INPUT_XLIB)
if(driver == "Xlib") self.instance = new InputXlib(*this);
#endif
if(!self.instance) self.instance = new InputDriver(*this);
return self.instance->create();
}
auto Input::hasDrivers() -> vector<string> {
return {
#if defined(INPUT_WINDOWS)
"Windows",
#endif
#if defined(INPUT_QUARTZ)
"Quartz",
#endif
#if defined(INPUT_CARBON)
"Carbon",
#endif
#if defined(INPUT_UDEV)
"udev",
#endif
#if defined(INPUT_UHID)
"uhid",
#endif
#if defined(INPUT_SDL)
"SDL",
#endif
#if defined(INPUT_XLIB)
"Xlib",
#endif
"None"};
}
auto Input::optimalDriver() -> string {
#if defined(INPUT_SDL)
return "SDL";
#elif defined(INPUT_WINDOWS)
return "Windows";
#elif defined(INPUT_QUARTZ)
return "Quartz";
#elif defined(INPUT_CARBON)
return "Carbon";
#elif defined(INPUT_UDEV)
return "udev";
#elif defined(INPUT_UHID)
return "uhid";
#elif defined(INPUT_XLIB)
return "Xlib";
#else
return "None";
#endif
}
auto Input::safestDriver() -> string {
#if defined(INPUT_WINDOWS)
return "Windows";
#elif defined(INPUT_QUARTZ)
return "Quartz";
#elif defined(INPUT_CARBON)
return "Carbon";
#elif defined(INPUT_UDEV)
return "udev";
#elif defined(INPUT_UHID)
return "uhid";
#elif defined(INPUT_SDL)
return "SDL";
#elif defined(INPUT_XLIB)
return "Xlib";
#else
return "none";
#endif
}
}
|