input_event.cpp 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374
  1. /*************************************************************************/
  2. /* input_event.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "input_event.h"
  31. #include "core/input_map.h"
  32. #include "core/os/keyboard.h"
  33. const int InputEvent::DEVICE_ID_TOUCH_MOUSE = -1;
  34. const int InputEvent::DEVICE_ID_INTERNAL = -2;
  35. void InputEvent::set_device(int p_device) {
  36. device = p_device;
  37. }
  38. int InputEvent::get_device() const {
  39. return device;
  40. }
  41. bool InputEvent::is_action(const StringName &p_action) const {
  42. return InputMap::get_singleton()->event_is_action(Ref<InputEvent>((InputEvent *)this), p_action);
  43. }
  44. bool InputEvent::is_action_pressed(const StringName &p_action, bool p_allow_echo) const {
  45. bool pressed;
  46. bool valid = InputMap::get_singleton()->event_get_action_status(Ref<InputEvent>((InputEvent *)this), p_action, &pressed);
  47. return valid && pressed && (p_allow_echo || !is_echo());
  48. }
  49. bool InputEvent::is_action_released(const StringName &p_action) const {
  50. bool pressed;
  51. bool valid = InputMap::get_singleton()->event_get_action_status(Ref<InputEvent>((InputEvent *)this), p_action, &pressed);
  52. return valid && !pressed;
  53. }
  54. float InputEvent::get_action_strength(const StringName &p_action) const {
  55. bool pressed;
  56. float strength;
  57. bool valid = InputMap::get_singleton()->event_get_action_status(Ref<InputEvent>((InputEvent *)this), p_action, &pressed, &strength);
  58. return valid ? strength : 0.0f;
  59. }
  60. bool InputEvent::is_pressed() const {
  61. return false;
  62. }
  63. bool InputEvent::is_echo() const {
  64. return false;
  65. }
  66. Ref<InputEvent> InputEvent::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
  67. return Ref<InputEvent>((InputEvent *)this);
  68. }
  69. String InputEvent::as_text() const {
  70. return String();
  71. }
  72. bool InputEvent::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
  73. return false;
  74. }
  75. bool InputEvent::shortcut_match(const Ref<InputEvent> &p_event) const {
  76. return false;
  77. }
  78. bool InputEvent::is_action_type() const {
  79. return false;
  80. }
  81. void InputEvent::_bind_methods() {
  82. ClassDB::bind_method(D_METHOD("set_device", "device"), &InputEvent::set_device);
  83. ClassDB::bind_method(D_METHOD("get_device"), &InputEvent::get_device);
  84. ClassDB::bind_method(D_METHOD("is_action", "action"), &InputEvent::is_action);
  85. ClassDB::bind_method(D_METHOD("is_action_pressed", "action", "allow_echo"), &InputEvent::is_action_pressed, DEFVAL(false));
  86. ClassDB::bind_method(D_METHOD("is_action_released", "action"), &InputEvent::is_action_released);
  87. ClassDB::bind_method(D_METHOD("get_action_strength", "action"), &InputEvent::get_action_strength);
  88. ClassDB::bind_method(D_METHOD("is_pressed"), &InputEvent::is_pressed);
  89. ClassDB::bind_method(D_METHOD("is_echo"), &InputEvent::is_echo);
  90. ClassDB::bind_method(D_METHOD("as_text"), &InputEvent::as_text);
  91. ClassDB::bind_method(D_METHOD("shortcut_match", "event"), &InputEvent::shortcut_match);
  92. ClassDB::bind_method(D_METHOD("is_action_type"), &InputEvent::is_action_type);
  93. ClassDB::bind_method(D_METHOD("accumulate", "with_event"), &InputEvent::accumulate);
  94. ClassDB::bind_method(D_METHOD("xformed_by", "xform", "local_ofs"), &InputEvent::xformed_by, DEFVAL(Vector2()));
  95. ADD_PROPERTY(PropertyInfo(Variant::INT, "device"), "set_device", "get_device");
  96. }
  97. InputEvent::InputEvent() {
  98. device = 0;
  99. }
  100. //////////////////
  101. void InputEventWithModifiers::set_shift(bool p_enabled) {
  102. shift = p_enabled;
  103. }
  104. bool InputEventWithModifiers::get_shift() const {
  105. return shift;
  106. }
  107. void InputEventWithModifiers::set_alt(bool p_enabled) {
  108. alt = p_enabled;
  109. }
  110. bool InputEventWithModifiers::get_alt() const {
  111. return alt;
  112. }
  113. void InputEventWithModifiers::set_control(bool p_enabled) {
  114. control = p_enabled;
  115. }
  116. bool InputEventWithModifiers::get_control() const {
  117. return control;
  118. }
  119. void InputEventWithModifiers::set_metakey(bool p_enabled) {
  120. meta = p_enabled;
  121. }
  122. bool InputEventWithModifiers::get_metakey() const {
  123. return meta;
  124. }
  125. void InputEventWithModifiers::set_command(bool p_enabled) {
  126. command = p_enabled;
  127. }
  128. bool InputEventWithModifiers::get_command() const {
  129. return command;
  130. }
  131. void InputEventWithModifiers::set_modifiers_from_event(const InputEventWithModifiers *event) {
  132. set_alt(event->get_alt());
  133. set_shift(event->get_shift());
  134. set_control(event->get_control());
  135. set_metakey(event->get_metakey());
  136. }
  137. void InputEventWithModifiers::_bind_methods() {
  138. ClassDB::bind_method(D_METHOD("set_alt", "enable"), &InputEventWithModifiers::set_alt);
  139. ClassDB::bind_method(D_METHOD("get_alt"), &InputEventWithModifiers::get_alt);
  140. ClassDB::bind_method(D_METHOD("set_shift", "enable"), &InputEventWithModifiers::set_shift);
  141. ClassDB::bind_method(D_METHOD("get_shift"), &InputEventWithModifiers::get_shift);
  142. ClassDB::bind_method(D_METHOD("set_control", "enable"), &InputEventWithModifiers::set_control);
  143. ClassDB::bind_method(D_METHOD("get_control"), &InputEventWithModifiers::get_control);
  144. ClassDB::bind_method(D_METHOD("set_metakey", "enable"), &InputEventWithModifiers::set_metakey);
  145. ClassDB::bind_method(D_METHOD("get_metakey"), &InputEventWithModifiers::get_metakey);
  146. ClassDB::bind_method(D_METHOD("set_command", "enable"), &InputEventWithModifiers::set_command);
  147. ClassDB::bind_method(D_METHOD("get_command"), &InputEventWithModifiers::get_command);
  148. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "alt"), "set_alt", "get_alt");
  149. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shift"), "set_shift", "get_shift");
  150. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "control"), "set_control", "get_control");
  151. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "meta"), "set_metakey", "get_metakey");
  152. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "command"), "set_command", "get_command");
  153. }
  154. InputEventWithModifiers::InputEventWithModifiers() {
  155. alt = false;
  156. shift = false;
  157. control = false;
  158. meta = false;
  159. }
  160. //////////////////////////////////
  161. void InputEventKey::set_pressed(bool p_pressed) {
  162. pressed = p_pressed;
  163. }
  164. bool InputEventKey::is_pressed() const {
  165. return pressed;
  166. }
  167. void InputEventKey::set_keycode(uint32_t p_keycode) {
  168. keycode = p_keycode;
  169. }
  170. uint32_t InputEventKey::get_keycode() const {
  171. return keycode;
  172. }
  173. void InputEventKey::set_physical_keycode(uint32_t p_keycode) {
  174. physical_keycode = p_keycode;
  175. }
  176. uint32_t InputEventKey::get_physical_keycode() const {
  177. return physical_keycode;
  178. }
  179. void InputEventKey::set_unicode(uint32_t p_unicode) {
  180. unicode = p_unicode;
  181. }
  182. uint32_t InputEventKey::get_unicode() const {
  183. return unicode;
  184. }
  185. void InputEventKey::set_echo(bool p_enable) {
  186. echo = p_enable;
  187. }
  188. bool InputEventKey::is_echo() const {
  189. return echo;
  190. }
  191. uint32_t InputEventKey::get_keycode_with_modifiers() const {
  192. uint32_t sc = keycode;
  193. if (get_control())
  194. sc |= KEY_MASK_CTRL;
  195. if (get_alt())
  196. sc |= KEY_MASK_ALT;
  197. if (get_shift())
  198. sc |= KEY_MASK_SHIFT;
  199. if (get_metakey())
  200. sc |= KEY_MASK_META;
  201. return sc;
  202. }
  203. uint32_t InputEventKey::get_physical_keycode_with_modifiers() const {
  204. uint32_t sc = physical_keycode;
  205. if (get_control())
  206. sc |= KEY_MASK_CTRL;
  207. if (get_alt())
  208. sc |= KEY_MASK_ALT;
  209. if (get_shift())
  210. sc |= KEY_MASK_SHIFT;
  211. if (get_metakey())
  212. sc |= KEY_MASK_META;
  213. return sc;
  214. }
  215. String InputEventKey::as_text() const {
  216. String kc = keycode_get_string(keycode);
  217. if (kc == String())
  218. return kc;
  219. if (get_metakey()) {
  220. kc = find_keycode_name(KEY_META) + ("+" + kc);
  221. }
  222. if (get_alt()) {
  223. kc = find_keycode_name(KEY_ALT) + ("+" + kc);
  224. }
  225. if (get_shift()) {
  226. kc = find_keycode_name(KEY_SHIFT) + ("+" + kc);
  227. }
  228. if (get_control()) {
  229. kc = find_keycode_name(KEY_CONTROL) + ("+" + kc);
  230. }
  231. return kc;
  232. }
  233. bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
  234. Ref<InputEventKey> key = p_event;
  235. if (key.is_null())
  236. return false;
  237. bool match = false;
  238. if (get_keycode() == 0) {
  239. uint32_t code = get_physical_keycode_with_modifiers();
  240. uint32_t event_code = key->get_physical_keycode_with_modifiers();
  241. match = get_physical_keycode() == key->get_physical_keycode() && (!key->is_pressed() || (code & event_code) == code);
  242. } else {
  243. uint32_t code = get_keycode_with_modifiers();
  244. uint32_t event_code = key->get_keycode_with_modifiers();
  245. match = get_keycode() == key->get_keycode() && (!key->is_pressed() || (code & event_code) == code);
  246. }
  247. if (match) {
  248. if (p_pressed != NULL)
  249. *p_pressed = key->is_pressed();
  250. if (p_strength != NULL)
  251. *p_strength = (p_pressed != NULL && *p_pressed) ? 1.0f : 0.0f;
  252. }
  253. return match;
  254. }
  255. bool InputEventKey::shortcut_match(const Ref<InputEvent> &p_event) const {
  256. Ref<InputEventKey> key = p_event;
  257. if (key.is_null())
  258. return false;
  259. uint32_t code = get_keycode_with_modifiers();
  260. uint32_t event_code = key->get_keycode_with_modifiers();
  261. return code == event_code;
  262. }
  263. void InputEventKey::_bind_methods() {
  264. ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventKey::set_pressed);
  265. ClassDB::bind_method(D_METHOD("set_keycode", "keycode"), &InputEventKey::set_keycode);
  266. ClassDB::bind_method(D_METHOD("get_keycode"), &InputEventKey::get_keycode);
  267. ClassDB::bind_method(D_METHOD("set_physical_keycode", "physical_keycode"), &InputEventKey::set_physical_keycode);
  268. ClassDB::bind_method(D_METHOD("get_physical_keycode"), &InputEventKey::get_physical_keycode);
  269. ClassDB::bind_method(D_METHOD("set_unicode", "unicode"), &InputEventKey::set_unicode);
  270. ClassDB::bind_method(D_METHOD("get_unicode"), &InputEventKey::get_unicode);
  271. ClassDB::bind_method(D_METHOD("set_echo", "echo"), &InputEventKey::set_echo);
  272. ClassDB::bind_method(D_METHOD("get_keycode_with_modifiers"), &InputEventKey::get_keycode_with_modifiers);
  273. ClassDB::bind_method(D_METHOD("get_physical_keycode_with_modifiers"), &InputEventKey::get_physical_keycode_with_modifiers);
  274. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
  275. ADD_PROPERTY(PropertyInfo(Variant::INT, "keycode"), "set_keycode", "get_keycode");
  276. ADD_PROPERTY(PropertyInfo(Variant::INT, "physical_keycode"), "set_physical_keycode", "get_physical_keycode");
  277. ADD_PROPERTY(PropertyInfo(Variant::INT, "unicode"), "set_unicode", "get_unicode");
  278. ADD_PROPERTY(PropertyInfo(Variant::INT, "echo"), "set_echo", "is_echo");
  279. }
  280. InputEventKey::InputEventKey() {
  281. pressed = false;
  282. keycode = 0;
  283. physical_keycode = 0;
  284. unicode = 0; ///unicode
  285. echo = false;
  286. }
  287. ////////////////////////////////////////
  288. void InputEventMouse::set_button_mask(int p_mask) {
  289. button_mask = p_mask;
  290. }
  291. int InputEventMouse::get_button_mask() const {
  292. return button_mask;
  293. }
  294. void InputEventMouse::set_position(const Vector2 &p_pos) {
  295. pos = p_pos;
  296. }
  297. Vector2 InputEventMouse::get_position() const {
  298. return pos;
  299. }
  300. void InputEventMouse::set_global_position(const Vector2 &p_global_pos) {
  301. global_pos = p_global_pos;
  302. }
  303. Vector2 InputEventMouse::get_global_position() const {
  304. return global_pos;
  305. }
  306. void InputEventMouse::_bind_methods() {
  307. ClassDB::bind_method(D_METHOD("set_button_mask", "button_mask"), &InputEventMouse::set_button_mask);
  308. ClassDB::bind_method(D_METHOD("get_button_mask"), &InputEventMouse::get_button_mask);
  309. ClassDB::bind_method(D_METHOD("set_position", "position"), &InputEventMouse::set_position);
  310. ClassDB::bind_method(D_METHOD("get_position"), &InputEventMouse::get_position);
  311. ClassDB::bind_method(D_METHOD("set_global_position", "global_position"), &InputEventMouse::set_global_position);
  312. ClassDB::bind_method(D_METHOD("get_global_position"), &InputEventMouse::get_global_position);
  313. ADD_PROPERTY(PropertyInfo(Variant::INT, "button_mask"), "set_button_mask", "get_button_mask");
  314. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position"), "set_position", "get_position");
  315. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "global_position"), "set_global_position", "get_global_position");
  316. }
  317. InputEventMouse::InputEventMouse() {
  318. button_mask = 0;
  319. }
  320. ///////////////////////////////////////
  321. void InputEventMouseButton::set_factor(float p_factor) {
  322. factor = p_factor;
  323. }
  324. float InputEventMouseButton::get_factor() {
  325. return factor;
  326. }
  327. void InputEventMouseButton::set_button_index(int p_index) {
  328. button_index = p_index;
  329. }
  330. int InputEventMouseButton::get_button_index() const {
  331. return button_index;
  332. }
  333. void InputEventMouseButton::set_pressed(bool p_pressed) {
  334. pressed = p_pressed;
  335. }
  336. bool InputEventMouseButton::is_pressed() const {
  337. return pressed;
  338. }
  339. void InputEventMouseButton::set_doubleclick(bool p_doubleclick) {
  340. doubleclick = p_doubleclick;
  341. }
  342. bool InputEventMouseButton::is_doubleclick() const {
  343. return doubleclick;
  344. }
  345. Ref<InputEvent> InputEventMouseButton::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
  346. Vector2 g = get_global_position();
  347. Vector2 l = p_xform.xform(get_position() + p_local_ofs);
  348. Ref<InputEventMouseButton> mb;
  349. mb.instance();
  350. mb->set_device(get_device());
  351. mb->set_modifiers_from_event(this);
  352. mb->set_position(l);
  353. mb->set_global_position(g);
  354. mb->set_button_mask(get_button_mask());
  355. mb->set_pressed(pressed);
  356. mb->set_doubleclick(doubleclick);
  357. mb->set_factor(factor);
  358. mb->set_button_index(button_index);
  359. return mb;
  360. }
  361. bool InputEventMouseButton::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
  362. Ref<InputEventMouseButton> mb = p_event;
  363. if (mb.is_null())
  364. return false;
  365. bool match = mb->button_index == button_index;
  366. if (match) {
  367. if (p_pressed != NULL)
  368. *p_pressed = mb->is_pressed();
  369. if (p_strength != NULL)
  370. *p_strength = (p_pressed != NULL && *p_pressed) ? 1.0f : 0.0f;
  371. }
  372. return match;
  373. }
  374. String InputEventMouseButton::as_text() const {
  375. String button_index_string = "";
  376. switch (get_button_index()) {
  377. case BUTTON_LEFT:
  378. button_index_string = "BUTTON_LEFT";
  379. break;
  380. case BUTTON_RIGHT:
  381. button_index_string = "BUTTON_RIGHT";
  382. break;
  383. case BUTTON_MIDDLE:
  384. button_index_string = "BUTTON_MIDDLE";
  385. break;
  386. case BUTTON_WHEEL_UP:
  387. button_index_string = "BUTTON_WHEEL_UP";
  388. break;
  389. case BUTTON_WHEEL_DOWN:
  390. button_index_string = "BUTTON_WHEEL_DOWN";
  391. break;
  392. case BUTTON_WHEEL_LEFT:
  393. button_index_string = "BUTTON_WHEEL_LEFT";
  394. break;
  395. case BUTTON_WHEEL_RIGHT:
  396. button_index_string = "BUTTON_WHEEL_RIGHT";
  397. break;
  398. case BUTTON_XBUTTON1:
  399. button_index_string = "BUTTON_XBUTTON1";
  400. break;
  401. case BUTTON_XBUTTON2:
  402. button_index_string = "BUTTON_XBUTTON2";
  403. break;
  404. default:
  405. button_index_string = itos(get_button_index());
  406. break;
  407. }
  408. return "InputEventMouseButton : button_index=" + button_index_string + ", pressed=" + (pressed ? "true" : "false") + ", position=(" + String(get_position()) + "), button_mask=" + itos(get_button_mask()) + ", doubleclick=" + (doubleclick ? "true" : "false");
  409. }
  410. void InputEventMouseButton::_bind_methods() {
  411. ClassDB::bind_method(D_METHOD("set_factor", "factor"), &InputEventMouseButton::set_factor);
  412. ClassDB::bind_method(D_METHOD("get_factor"), &InputEventMouseButton::get_factor);
  413. ClassDB::bind_method(D_METHOD("set_button_index", "button_index"), &InputEventMouseButton::set_button_index);
  414. ClassDB::bind_method(D_METHOD("get_button_index"), &InputEventMouseButton::get_button_index);
  415. ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventMouseButton::set_pressed);
  416. // ClassDB::bind_method(D_METHOD("is_pressed"), &InputEventMouseButton::is_pressed);
  417. ClassDB::bind_method(D_METHOD("set_doubleclick", "doubleclick"), &InputEventMouseButton::set_doubleclick);
  418. ClassDB::bind_method(D_METHOD("is_doubleclick"), &InputEventMouseButton::is_doubleclick);
  419. ADD_PROPERTY(PropertyInfo(Variant::REAL, "factor"), "set_factor", "get_factor");
  420. ADD_PROPERTY(PropertyInfo(Variant::INT, "button_index"), "set_button_index", "get_button_index");
  421. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
  422. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "doubleclick"), "set_doubleclick", "is_doubleclick");
  423. }
  424. InputEventMouseButton::InputEventMouseButton() {
  425. factor = 1;
  426. button_index = 0;
  427. pressed = false;
  428. doubleclick = false;
  429. }
  430. ////////////////////////////////////////////
  431. void InputEventMouseMotion::set_tilt(const Vector2 &p_tilt) {
  432. tilt = p_tilt;
  433. }
  434. Vector2 InputEventMouseMotion::get_tilt() const {
  435. return tilt;
  436. }
  437. void InputEventMouseMotion::set_pressure(float p_pressure) {
  438. pressure = p_pressure;
  439. }
  440. float InputEventMouseMotion::get_pressure() const {
  441. return pressure;
  442. }
  443. void InputEventMouseMotion::set_relative(const Vector2 &p_relative) {
  444. relative = p_relative;
  445. }
  446. Vector2 InputEventMouseMotion::get_relative() const {
  447. return relative;
  448. }
  449. void InputEventMouseMotion::set_speed(const Vector2 &p_speed) {
  450. speed = p_speed;
  451. }
  452. Vector2 InputEventMouseMotion::get_speed() const {
  453. return speed;
  454. }
  455. Ref<InputEvent> InputEventMouseMotion::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
  456. Vector2 g = get_global_position();
  457. Vector2 l = p_xform.xform(get_position() + p_local_ofs);
  458. Vector2 r = p_xform.basis_xform(get_relative());
  459. Vector2 s = p_xform.basis_xform(get_speed());
  460. Ref<InputEventMouseMotion> mm;
  461. mm.instance();
  462. mm->set_device(get_device());
  463. mm->set_modifiers_from_event(this);
  464. mm->set_position(l);
  465. mm->set_pressure(get_pressure());
  466. mm->set_tilt(get_tilt());
  467. mm->set_global_position(g);
  468. mm->set_button_mask(get_button_mask());
  469. mm->set_relative(r);
  470. mm->set_speed(s);
  471. return mm;
  472. }
  473. String InputEventMouseMotion::as_text() const {
  474. String button_mask_string = "";
  475. switch (get_button_mask()) {
  476. case BUTTON_MASK_LEFT:
  477. button_mask_string = "BUTTON_MASK_LEFT";
  478. break;
  479. case BUTTON_MASK_MIDDLE:
  480. button_mask_string = "BUTTON_MASK_MIDDLE";
  481. break;
  482. case BUTTON_MASK_RIGHT:
  483. button_mask_string = "BUTTON_MASK_RIGHT";
  484. break;
  485. case BUTTON_MASK_XBUTTON1:
  486. button_mask_string = "BUTTON_MASK_XBUTTON1";
  487. break;
  488. case BUTTON_MASK_XBUTTON2:
  489. button_mask_string = "BUTTON_MASK_XBUTTON2";
  490. break;
  491. default:
  492. button_mask_string = itos(get_button_mask());
  493. break;
  494. }
  495. return "InputEventMouseMotion : button_mask=" + button_mask_string + ", position=(" + String(get_position()) + "), relative=(" + String(get_relative()) + "), speed=(" + String(get_speed()) + ")";
  496. }
  497. bool InputEventMouseMotion::accumulate(const Ref<InputEvent> &p_event) {
  498. Ref<InputEventMouseMotion> motion = p_event;
  499. if (motion.is_null())
  500. return false;
  501. if (is_pressed() != motion->is_pressed()) {
  502. return false;
  503. }
  504. if (get_button_mask() != motion->get_button_mask()) {
  505. return false;
  506. }
  507. if (get_shift() != motion->get_shift()) {
  508. return false;
  509. }
  510. if (get_control() != motion->get_control()) {
  511. return false;
  512. }
  513. if (get_alt() != motion->get_alt()) {
  514. return false;
  515. }
  516. if (get_metakey() != motion->get_metakey()) {
  517. return false;
  518. }
  519. set_position(motion->get_position());
  520. set_global_position(motion->get_global_position());
  521. set_speed(motion->get_speed());
  522. relative += motion->get_relative();
  523. return true;
  524. }
  525. void InputEventMouseMotion::_bind_methods() {
  526. ClassDB::bind_method(D_METHOD("set_tilt", "tilt"), &InputEventMouseMotion::set_tilt);
  527. ClassDB::bind_method(D_METHOD("get_tilt"), &InputEventMouseMotion::get_tilt);
  528. ClassDB::bind_method(D_METHOD("set_pressure", "pressure"), &InputEventMouseMotion::set_pressure);
  529. ClassDB::bind_method(D_METHOD("get_pressure"), &InputEventMouseMotion::get_pressure);
  530. ClassDB::bind_method(D_METHOD("set_relative", "relative"), &InputEventMouseMotion::set_relative);
  531. ClassDB::bind_method(D_METHOD("get_relative"), &InputEventMouseMotion::get_relative);
  532. ClassDB::bind_method(D_METHOD("set_speed", "speed"), &InputEventMouseMotion::set_speed);
  533. ClassDB::bind_method(D_METHOD("get_speed"), &InputEventMouseMotion::get_speed);
  534. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "tilt"), "set_tilt", "get_tilt");
  535. ADD_PROPERTY(PropertyInfo(Variant::REAL, "pressure"), "set_pressure", "get_pressure");
  536. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "relative"), "set_relative", "get_relative");
  537. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "speed"), "set_speed", "get_speed");
  538. }
  539. InputEventMouseMotion::InputEventMouseMotion() {
  540. pressure = 0;
  541. }
  542. ////////////////////////////////////////
  543. void InputEventJoypadMotion::set_axis(int p_axis) {
  544. axis = p_axis;
  545. }
  546. int InputEventJoypadMotion::get_axis() const {
  547. return axis;
  548. }
  549. void InputEventJoypadMotion::set_axis_value(float p_value) {
  550. axis_value = p_value;
  551. }
  552. float InputEventJoypadMotion::get_axis_value() const {
  553. return axis_value;
  554. }
  555. bool InputEventJoypadMotion::is_pressed() const {
  556. return Math::abs(axis_value) >= 0.5f;
  557. }
  558. bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
  559. Ref<InputEventJoypadMotion> jm = p_event;
  560. if (jm.is_null())
  561. return false;
  562. bool match = (axis == jm->axis); // Matches even if not in the same direction, but returns a "not pressed" event.
  563. if (match) {
  564. bool same_direction = (((axis_value < 0) == (jm->axis_value < 0)) || jm->axis_value == 0);
  565. bool pressed = same_direction ? Math::abs(jm->get_axis_value()) >= p_deadzone : false;
  566. if (p_pressed != NULL)
  567. *p_pressed = pressed;
  568. if (p_strength != NULL) {
  569. if (pressed) {
  570. if (p_deadzone == 1.0f) {
  571. *p_strength = 1.0f;
  572. } else {
  573. *p_strength = CLAMP(Math::inverse_lerp(p_deadzone, 1.0f, Math::abs(jm->get_axis_value())), 0.0f, 1.0f);
  574. }
  575. } else {
  576. *p_strength = 0.0f;
  577. }
  578. }
  579. }
  580. return match;
  581. }
  582. String InputEventJoypadMotion::as_text() const {
  583. return "InputEventJoypadMotion : axis=" + itos(axis) + ", axis_value=" + String(Variant(axis_value));
  584. }
  585. void InputEventJoypadMotion::_bind_methods() {
  586. ClassDB::bind_method(D_METHOD("set_axis", "axis"), &InputEventJoypadMotion::set_axis);
  587. ClassDB::bind_method(D_METHOD("get_axis"), &InputEventJoypadMotion::get_axis);
  588. ClassDB::bind_method(D_METHOD("set_axis_value", "axis_value"), &InputEventJoypadMotion::set_axis_value);
  589. ClassDB::bind_method(D_METHOD("get_axis_value"), &InputEventJoypadMotion::get_axis_value);
  590. ADD_PROPERTY(PropertyInfo(Variant::INT, "axis"), "set_axis", "get_axis");
  591. ADD_PROPERTY(PropertyInfo(Variant::REAL, "axis_value"), "set_axis_value", "get_axis_value");
  592. }
  593. InputEventJoypadMotion::InputEventJoypadMotion() {
  594. axis = 0;
  595. axis_value = 0;
  596. }
  597. /////////////////////////////////
  598. void InputEventJoypadButton::set_button_index(int p_index) {
  599. button_index = p_index;
  600. }
  601. int InputEventJoypadButton::get_button_index() const {
  602. return button_index;
  603. }
  604. void InputEventJoypadButton::set_pressed(bool p_pressed) {
  605. pressed = p_pressed;
  606. }
  607. bool InputEventJoypadButton::is_pressed() const {
  608. return pressed;
  609. }
  610. void InputEventJoypadButton::set_pressure(float p_pressure) {
  611. pressure = p_pressure;
  612. }
  613. float InputEventJoypadButton::get_pressure() const {
  614. return pressure;
  615. }
  616. bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
  617. Ref<InputEventJoypadButton> jb = p_event;
  618. if (jb.is_null())
  619. return false;
  620. bool match = button_index == jb->button_index;
  621. if (match) {
  622. if (p_pressed != NULL)
  623. *p_pressed = jb->is_pressed();
  624. if (p_strength != NULL)
  625. *p_strength = (p_pressed != NULL && *p_pressed) ? 1.0f : 0.0f;
  626. }
  627. return match;
  628. }
  629. bool InputEventJoypadButton::shortcut_match(const Ref<InputEvent> &p_event) const {
  630. Ref<InputEventJoypadButton> button = p_event;
  631. if (button.is_null())
  632. return false;
  633. return button_index == button->button_index;
  634. }
  635. String InputEventJoypadButton::as_text() const {
  636. return "InputEventJoypadButton : button_index=" + itos(button_index) + ", pressed=" + (pressed ? "true" : "false") + ", pressure=" + String(Variant(pressure));
  637. }
  638. void InputEventJoypadButton::_bind_methods() {
  639. ClassDB::bind_method(D_METHOD("set_button_index", "button_index"), &InputEventJoypadButton::set_button_index);
  640. ClassDB::bind_method(D_METHOD("get_button_index"), &InputEventJoypadButton::get_button_index);
  641. ClassDB::bind_method(D_METHOD("set_pressure", "pressure"), &InputEventJoypadButton::set_pressure);
  642. ClassDB::bind_method(D_METHOD("get_pressure"), &InputEventJoypadButton::get_pressure);
  643. ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventJoypadButton::set_pressed);
  644. // ClassDB::bind_method(D_METHOD("is_pressed"), &InputEventJoypadButton::is_pressed);
  645. ADD_PROPERTY(PropertyInfo(Variant::INT, "button_index"), "set_button_index", "get_button_index");
  646. ADD_PROPERTY(PropertyInfo(Variant::REAL, "pressure"), "set_pressure", "get_pressure");
  647. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
  648. }
  649. InputEventJoypadButton::InputEventJoypadButton() {
  650. button_index = 0;
  651. pressure = 0;
  652. pressed = false;
  653. }
  654. //////////////////////////////////////////////
  655. void InputEventScreenTouch::set_index(int p_index) {
  656. index = p_index;
  657. }
  658. int InputEventScreenTouch::get_index() const {
  659. return index;
  660. }
  661. void InputEventScreenTouch::set_position(const Vector2 &p_pos) {
  662. pos = p_pos;
  663. }
  664. Vector2 InputEventScreenTouch::get_position() const {
  665. return pos;
  666. }
  667. void InputEventScreenTouch::set_pressed(bool p_pressed) {
  668. pressed = p_pressed;
  669. }
  670. bool InputEventScreenTouch::is_pressed() const {
  671. return pressed;
  672. }
  673. Ref<InputEvent> InputEventScreenTouch::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
  674. Ref<InputEventScreenTouch> st;
  675. st.instance();
  676. st->set_device(get_device());
  677. st->set_index(index);
  678. st->set_position(p_xform.xform(pos + p_local_ofs));
  679. st->set_pressed(pressed);
  680. return st;
  681. }
  682. String InputEventScreenTouch::as_text() const {
  683. return "InputEventScreenTouch : index=" + itos(index) + ", pressed=" + (pressed ? "true" : "false") + ", position=(" + String(get_position()) + ")";
  684. }
  685. void InputEventScreenTouch::_bind_methods() {
  686. ClassDB::bind_method(D_METHOD("set_index", "index"), &InputEventScreenTouch::set_index);
  687. ClassDB::bind_method(D_METHOD("get_index"), &InputEventScreenTouch::get_index);
  688. ClassDB::bind_method(D_METHOD("set_position", "position"), &InputEventScreenTouch::set_position);
  689. ClassDB::bind_method(D_METHOD("get_position"), &InputEventScreenTouch::get_position);
  690. ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventScreenTouch::set_pressed);
  691. //ClassDB::bind_method(D_METHOD("is_pressed"),&InputEventScreenTouch::is_pressed);
  692. ADD_PROPERTY(PropertyInfo(Variant::INT, "index"), "set_index", "get_index");
  693. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position"), "set_position", "get_position");
  694. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
  695. }
  696. InputEventScreenTouch::InputEventScreenTouch() {
  697. index = 0;
  698. pressed = false;
  699. }
  700. /////////////////////////////
  701. void InputEventScreenDrag::set_index(int p_index) {
  702. index = p_index;
  703. }
  704. int InputEventScreenDrag::get_index() const {
  705. return index;
  706. }
  707. void InputEventScreenDrag::set_position(const Vector2 &p_pos) {
  708. pos = p_pos;
  709. }
  710. Vector2 InputEventScreenDrag::get_position() const {
  711. return pos;
  712. }
  713. void InputEventScreenDrag::set_relative(const Vector2 &p_relative) {
  714. relative = p_relative;
  715. }
  716. Vector2 InputEventScreenDrag::get_relative() const {
  717. return relative;
  718. }
  719. void InputEventScreenDrag::set_speed(const Vector2 &p_speed) {
  720. speed = p_speed;
  721. }
  722. Vector2 InputEventScreenDrag::get_speed() const {
  723. return speed;
  724. }
  725. Ref<InputEvent> InputEventScreenDrag::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
  726. Ref<InputEventScreenDrag> sd;
  727. sd.instance();
  728. sd->set_device(get_device());
  729. sd->set_index(index);
  730. sd->set_position(p_xform.xform(pos + p_local_ofs));
  731. sd->set_relative(p_xform.basis_xform(relative));
  732. sd->set_speed(p_xform.basis_xform(speed));
  733. return sd;
  734. }
  735. String InputEventScreenDrag::as_text() const {
  736. return "InputEventScreenDrag : index=" + itos(index) + ", position=(" + String(get_position()) + "), relative=(" + String(get_relative()) + "), speed=(" + String(get_speed()) + ")";
  737. }
  738. void InputEventScreenDrag::_bind_methods() {
  739. ClassDB::bind_method(D_METHOD("set_index", "index"), &InputEventScreenDrag::set_index);
  740. ClassDB::bind_method(D_METHOD("get_index"), &InputEventScreenDrag::get_index);
  741. ClassDB::bind_method(D_METHOD("set_position", "position"), &InputEventScreenDrag::set_position);
  742. ClassDB::bind_method(D_METHOD("get_position"), &InputEventScreenDrag::get_position);
  743. ClassDB::bind_method(D_METHOD("set_relative", "relative"), &InputEventScreenDrag::set_relative);
  744. ClassDB::bind_method(D_METHOD("get_relative"), &InputEventScreenDrag::get_relative);
  745. ClassDB::bind_method(D_METHOD("set_speed", "speed"), &InputEventScreenDrag::set_speed);
  746. ClassDB::bind_method(D_METHOD("get_speed"), &InputEventScreenDrag::get_speed);
  747. ADD_PROPERTY(PropertyInfo(Variant::INT, "index"), "set_index", "get_index");
  748. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position"), "set_position", "get_position");
  749. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "relative"), "set_relative", "get_relative");
  750. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "speed"), "set_speed", "get_speed");
  751. }
  752. InputEventScreenDrag::InputEventScreenDrag() {
  753. index = 0;
  754. }
  755. /////////////////////////////
  756. void InputEventAction::set_action(const StringName &p_action) {
  757. action = p_action;
  758. }
  759. StringName InputEventAction::get_action() const {
  760. return action;
  761. }
  762. void InputEventAction::set_pressed(bool p_pressed) {
  763. pressed = p_pressed;
  764. }
  765. bool InputEventAction::is_pressed() const {
  766. return pressed;
  767. }
  768. void InputEventAction::set_strength(float p_strength) {
  769. strength = CLAMP(p_strength, 0.0f, 1.0f);
  770. }
  771. float InputEventAction::get_strength() const {
  772. return strength;
  773. }
  774. bool InputEventAction::shortcut_match(const Ref<InputEvent> &p_event) const {
  775. if (p_event.is_null())
  776. return false;
  777. return p_event->is_action(action);
  778. }
  779. bool InputEventAction::is_action(const StringName &p_action) const {
  780. return action == p_action;
  781. }
  782. bool InputEventAction::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
  783. Ref<InputEventAction> act = p_event;
  784. if (act.is_null())
  785. return false;
  786. bool match = action == act->action;
  787. if (match) {
  788. if (p_pressed != NULL)
  789. *p_pressed = act->pressed;
  790. if (p_strength != NULL)
  791. *p_strength = (p_pressed != NULL && *p_pressed) ? 1.0f : 0.0f;
  792. }
  793. return match;
  794. }
  795. String InputEventAction::as_text() const {
  796. return "InputEventAction : action=" + action + ", pressed=(" + (pressed ? "true" : "false");
  797. }
  798. void InputEventAction::_bind_methods() {
  799. ClassDB::bind_method(D_METHOD("set_action", "action"), &InputEventAction::set_action);
  800. ClassDB::bind_method(D_METHOD("get_action"), &InputEventAction::get_action);
  801. ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventAction::set_pressed);
  802. //ClassDB::bind_method(D_METHOD("is_pressed"), &InputEventAction::is_pressed);
  803. ClassDB::bind_method(D_METHOD("set_strength", "strength"), &InputEventAction::set_strength);
  804. ClassDB::bind_method(D_METHOD("get_strength"), &InputEventAction::get_strength);
  805. // ClassDB::bind_method(D_METHOD("is_action", "name"), &InputEventAction::is_action);
  806. ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "action"), "set_action", "get_action");
  807. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
  808. ADD_PROPERTY(PropertyInfo(Variant::REAL, "strength", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_strength", "get_strength");
  809. }
  810. InputEventAction::InputEventAction() {
  811. pressed = false;
  812. strength = 1.0f;
  813. }
  814. /////////////////////////////
  815. void InputEventGesture::set_position(const Vector2 &p_pos) {
  816. pos = p_pos;
  817. }
  818. void InputEventGesture::_bind_methods() {
  819. ClassDB::bind_method(D_METHOD("set_position", "position"), &InputEventGesture::set_position);
  820. ClassDB::bind_method(D_METHOD("get_position"), &InputEventGesture::get_position);
  821. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position"), "set_position", "get_position");
  822. }
  823. Vector2 InputEventGesture::get_position() const {
  824. return pos;
  825. }
  826. /////////////////////////////
  827. void InputEventMagnifyGesture::set_factor(real_t p_factor) {
  828. factor = p_factor;
  829. }
  830. real_t InputEventMagnifyGesture::get_factor() const {
  831. return factor;
  832. }
  833. Ref<InputEvent> InputEventMagnifyGesture::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
  834. Ref<InputEventMagnifyGesture> ev;
  835. ev.instance();
  836. ev->set_device(get_device());
  837. ev->set_modifiers_from_event(this);
  838. ev->set_position(p_xform.xform(get_position() + p_local_ofs));
  839. ev->set_factor(get_factor());
  840. return ev;
  841. }
  842. String InputEventMagnifyGesture::as_text() const {
  843. return "InputEventMagnifyGesture : factor=" + rtos(get_factor()) + ", position=(" + String(get_position()) + ")";
  844. }
  845. void InputEventMagnifyGesture::_bind_methods() {
  846. ClassDB::bind_method(D_METHOD("set_factor", "factor"), &InputEventMagnifyGesture::set_factor);
  847. ClassDB::bind_method(D_METHOD("get_factor"), &InputEventMagnifyGesture::get_factor);
  848. ADD_PROPERTY(PropertyInfo(Variant::REAL, "factor"), "set_factor", "get_factor");
  849. }
  850. InputEventMagnifyGesture::InputEventMagnifyGesture() {
  851. factor = 1.0;
  852. }
  853. /////////////////////////////
  854. void InputEventPanGesture::set_delta(const Vector2 &p_delta) {
  855. delta = p_delta;
  856. }
  857. Vector2 InputEventPanGesture::get_delta() const {
  858. return delta;
  859. }
  860. Ref<InputEvent> InputEventPanGesture::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
  861. Ref<InputEventPanGesture> ev;
  862. ev.instance();
  863. ev->set_device(get_device());
  864. ev->set_modifiers_from_event(this);
  865. ev->set_position(p_xform.xform(get_position() + p_local_ofs));
  866. ev->set_delta(get_delta());
  867. return ev;
  868. }
  869. String InputEventPanGesture::as_text() const {
  870. return "InputEventPanGesture : delta=(" + String(get_delta()) + "), position=(" + String(get_position()) + ")";
  871. }
  872. void InputEventPanGesture::_bind_methods() {
  873. ClassDB::bind_method(D_METHOD("set_delta", "delta"), &InputEventPanGesture::set_delta);
  874. ClassDB::bind_method(D_METHOD("get_delta"), &InputEventPanGesture::get_delta);
  875. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "delta"), "set_delta", "get_delta");
  876. }
  877. InputEventPanGesture::InputEventPanGesture() {
  878. delta = Vector2(0, 0);
  879. }
  880. /////////////////////////////
  881. void InputEventMIDI::set_channel(const int p_channel) {
  882. channel = p_channel;
  883. }
  884. int InputEventMIDI::get_channel() const {
  885. return channel;
  886. }
  887. void InputEventMIDI::set_message(const int p_message) {
  888. message = p_message;
  889. }
  890. int InputEventMIDI::get_message() const {
  891. return message;
  892. }
  893. void InputEventMIDI::set_pitch(const int p_pitch) {
  894. pitch = p_pitch;
  895. }
  896. int InputEventMIDI::get_pitch() const {
  897. return pitch;
  898. }
  899. void InputEventMIDI::set_velocity(const int p_velocity) {
  900. velocity = p_velocity;
  901. }
  902. int InputEventMIDI::get_velocity() const {
  903. return velocity;
  904. }
  905. void InputEventMIDI::set_instrument(const int p_instrument) {
  906. instrument = p_instrument;
  907. }
  908. int InputEventMIDI::get_instrument() const {
  909. return instrument;
  910. }
  911. void InputEventMIDI::set_pressure(const int p_pressure) {
  912. pressure = p_pressure;
  913. }
  914. int InputEventMIDI::get_pressure() const {
  915. return pressure;
  916. }
  917. void InputEventMIDI::set_controller_number(const int p_controller_number) {
  918. controller_number = p_controller_number;
  919. }
  920. int InputEventMIDI::get_controller_number() const {
  921. return controller_number;
  922. }
  923. void InputEventMIDI::set_controller_value(const int p_controller_value) {
  924. controller_value = p_controller_value;
  925. }
  926. int InputEventMIDI::get_controller_value() const {
  927. return controller_value;
  928. }
  929. String InputEventMIDI::as_text() const {
  930. return "InputEventMIDI : channel=(" + itos(get_channel()) + "), message=(" + itos(get_message()) + ")";
  931. }
  932. void InputEventMIDI::_bind_methods() {
  933. ClassDB::bind_method(D_METHOD("set_channel", "channel"), &InputEventMIDI::set_channel);
  934. ClassDB::bind_method(D_METHOD("get_channel"), &InputEventMIDI::get_channel);
  935. ClassDB::bind_method(D_METHOD("set_message", "message"), &InputEventMIDI::set_message);
  936. ClassDB::bind_method(D_METHOD("get_message"), &InputEventMIDI::get_message);
  937. ClassDB::bind_method(D_METHOD("set_pitch", "pitch"), &InputEventMIDI::set_pitch);
  938. ClassDB::bind_method(D_METHOD("get_pitch"), &InputEventMIDI::get_pitch);
  939. ClassDB::bind_method(D_METHOD("set_velocity", "velocity"), &InputEventMIDI::set_velocity);
  940. ClassDB::bind_method(D_METHOD("get_velocity"), &InputEventMIDI::get_velocity);
  941. ClassDB::bind_method(D_METHOD("set_instrument", "instrument"), &InputEventMIDI::set_instrument);
  942. ClassDB::bind_method(D_METHOD("get_instrument"), &InputEventMIDI::get_instrument);
  943. ClassDB::bind_method(D_METHOD("set_pressure", "pressure"), &InputEventMIDI::set_pressure);
  944. ClassDB::bind_method(D_METHOD("get_pressure"), &InputEventMIDI::get_pressure);
  945. ClassDB::bind_method(D_METHOD("set_controller_number", "controller_number"), &InputEventMIDI::set_controller_number);
  946. ClassDB::bind_method(D_METHOD("get_controller_number"), &InputEventMIDI::get_controller_number);
  947. ClassDB::bind_method(D_METHOD("set_controller_value", "controller_value"), &InputEventMIDI::set_controller_value);
  948. ClassDB::bind_method(D_METHOD("get_controller_value"), &InputEventMIDI::get_controller_value);
  949. ADD_PROPERTY(PropertyInfo(Variant::INT, "channel"), "set_channel", "get_channel");
  950. ADD_PROPERTY(PropertyInfo(Variant::INT, "message"), "set_message", "get_message");
  951. ADD_PROPERTY(PropertyInfo(Variant::INT, "pitch"), "set_pitch", "get_pitch");
  952. ADD_PROPERTY(PropertyInfo(Variant::INT, "velocity"), "set_velocity", "get_velocity");
  953. ADD_PROPERTY(PropertyInfo(Variant::INT, "instrument"), "set_instrument", "get_instrument");
  954. ADD_PROPERTY(PropertyInfo(Variant::INT, "pressure"), "set_pressure", "get_pressure");
  955. ADD_PROPERTY(PropertyInfo(Variant::INT, "controller_number"), "set_controller_number", "get_controller_number");
  956. ADD_PROPERTY(PropertyInfo(Variant::INT, "controller_value"), "set_controller_value", "get_controller_value");
  957. }
  958. InputEventMIDI::InputEventMIDI() {
  959. channel = 0;
  960. message = 0;
  961. pitch = 0;
  962. velocity = 0;
  963. instrument = 0;
  964. pressure = 0;
  965. controller_number = 0;
  966. controller_value = 0;
  967. }