input_event.cpp 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316
  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/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. ///////////////////////////////////
  98. void InputEventFromWindow::_bind_methods() {
  99. ClassDB::bind_method(D_METHOD("set_window_id", "id"), &InputEventFromWindow::set_window_id);
  100. ClassDB::bind_method(D_METHOD("get_window_id"), &InputEventFromWindow::get_window_id);
  101. ADD_PROPERTY(PropertyInfo(Variant::INT, "window_id"), "set_window_id", "get_window_id");
  102. }
  103. void InputEventFromWindow::set_window_id(int64_t p_id) {
  104. window_id = p_id;
  105. }
  106. int64_t InputEventFromWindow::get_window_id() const {
  107. return window_id;
  108. }
  109. ///////////////////////////////////
  110. void InputEventWithModifiers::set_shift(bool p_enabled) {
  111. shift = p_enabled;
  112. }
  113. bool InputEventWithModifiers::get_shift() const {
  114. return shift;
  115. }
  116. void InputEventWithModifiers::set_alt(bool p_enabled) {
  117. alt = p_enabled;
  118. }
  119. bool InputEventWithModifiers::get_alt() const {
  120. return alt;
  121. }
  122. void InputEventWithModifiers::set_control(bool p_enabled) {
  123. control = p_enabled;
  124. }
  125. bool InputEventWithModifiers::get_control() const {
  126. return control;
  127. }
  128. void InputEventWithModifiers::set_metakey(bool p_enabled) {
  129. meta = p_enabled;
  130. }
  131. bool InputEventWithModifiers::get_metakey() const {
  132. return meta;
  133. }
  134. void InputEventWithModifiers::set_command(bool p_enabled) {
  135. command = p_enabled;
  136. }
  137. bool InputEventWithModifiers::get_command() const {
  138. return command;
  139. }
  140. void InputEventWithModifiers::set_modifiers_from_event(const InputEventWithModifiers *event) {
  141. set_alt(event->get_alt());
  142. set_shift(event->get_shift());
  143. set_control(event->get_control());
  144. set_metakey(event->get_metakey());
  145. }
  146. void InputEventWithModifiers::_bind_methods() {
  147. ClassDB::bind_method(D_METHOD("set_alt", "enable"), &InputEventWithModifiers::set_alt);
  148. ClassDB::bind_method(D_METHOD("get_alt"), &InputEventWithModifiers::get_alt);
  149. ClassDB::bind_method(D_METHOD("set_shift", "enable"), &InputEventWithModifiers::set_shift);
  150. ClassDB::bind_method(D_METHOD("get_shift"), &InputEventWithModifiers::get_shift);
  151. ClassDB::bind_method(D_METHOD("set_control", "enable"), &InputEventWithModifiers::set_control);
  152. ClassDB::bind_method(D_METHOD("get_control"), &InputEventWithModifiers::get_control);
  153. ClassDB::bind_method(D_METHOD("set_metakey", "enable"), &InputEventWithModifiers::set_metakey);
  154. ClassDB::bind_method(D_METHOD("get_metakey"), &InputEventWithModifiers::get_metakey);
  155. ClassDB::bind_method(D_METHOD("set_command", "enable"), &InputEventWithModifiers::set_command);
  156. ClassDB::bind_method(D_METHOD("get_command"), &InputEventWithModifiers::get_command);
  157. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "alt"), "set_alt", "get_alt");
  158. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shift"), "set_shift", "get_shift");
  159. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "control"), "set_control", "get_control");
  160. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "meta"), "set_metakey", "get_metakey");
  161. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "command"), "set_command", "get_command");
  162. }
  163. ///////////////////////////////////
  164. void InputEventKey::set_pressed(bool p_pressed) {
  165. pressed = p_pressed;
  166. }
  167. bool InputEventKey::is_pressed() const {
  168. return pressed;
  169. }
  170. void InputEventKey::set_keycode(uint32_t p_keycode) {
  171. keycode = p_keycode;
  172. }
  173. uint32_t InputEventKey::get_keycode() const {
  174. return keycode;
  175. }
  176. void InputEventKey::set_physical_keycode(uint32_t p_keycode) {
  177. physical_keycode = p_keycode;
  178. }
  179. uint32_t InputEventKey::get_physical_keycode() const {
  180. return physical_keycode;
  181. }
  182. void InputEventKey::set_unicode(uint32_t p_unicode) {
  183. unicode = p_unicode;
  184. }
  185. uint32_t InputEventKey::get_unicode() const {
  186. return unicode;
  187. }
  188. void InputEventKey::set_echo(bool p_enable) {
  189. echo = p_enable;
  190. }
  191. bool InputEventKey::is_echo() const {
  192. return echo;
  193. }
  194. uint32_t InputEventKey::get_keycode_with_modifiers() const {
  195. uint32_t sc = keycode;
  196. if (get_control())
  197. sc |= KEY_MASK_CTRL;
  198. if (get_alt())
  199. sc |= KEY_MASK_ALT;
  200. if (get_shift())
  201. sc |= KEY_MASK_SHIFT;
  202. if (get_metakey())
  203. sc |= KEY_MASK_META;
  204. return sc;
  205. }
  206. uint32_t InputEventKey::get_physical_keycode_with_modifiers() const {
  207. uint32_t sc = physical_keycode;
  208. if (get_control())
  209. sc |= KEY_MASK_CTRL;
  210. if (get_alt())
  211. sc |= KEY_MASK_ALT;
  212. if (get_shift())
  213. sc |= KEY_MASK_SHIFT;
  214. if (get_metakey())
  215. sc |= KEY_MASK_META;
  216. return sc;
  217. }
  218. String InputEventKey::as_text() const {
  219. String kc = keycode_get_string(keycode);
  220. if (kc == String())
  221. return kc;
  222. if (get_metakey()) {
  223. kc = find_keycode_name(KEY_META) + ("+" + kc);
  224. }
  225. if (get_alt()) {
  226. kc = find_keycode_name(KEY_ALT) + ("+" + kc);
  227. }
  228. if (get_shift()) {
  229. kc = find_keycode_name(KEY_SHIFT) + ("+" + kc);
  230. }
  231. if (get_control()) {
  232. kc = find_keycode_name(KEY_CONTROL) + ("+" + kc);
  233. }
  234. return kc;
  235. }
  236. bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
  237. Ref<InputEventKey> key = p_event;
  238. if (key.is_null())
  239. return false;
  240. bool match = false;
  241. if (get_keycode() == 0) {
  242. uint32_t code = get_physical_keycode_with_modifiers();
  243. uint32_t event_code = key->get_physical_keycode_with_modifiers();
  244. match = get_physical_keycode() == key->get_physical_keycode() && (!key->is_pressed() || (code & event_code) == code);
  245. } else {
  246. uint32_t code = get_keycode_with_modifiers();
  247. uint32_t event_code = key->get_keycode_with_modifiers();
  248. match = get_keycode() == key->get_keycode() && (!key->is_pressed() || (code & event_code) == code);
  249. }
  250. if (match) {
  251. if (p_pressed != nullptr)
  252. *p_pressed = key->is_pressed();
  253. if (p_strength != nullptr)
  254. *p_strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f;
  255. }
  256. return match;
  257. }
  258. bool InputEventKey::shortcut_match(const Ref<InputEvent> &p_event) const {
  259. Ref<InputEventKey> key = p_event;
  260. if (key.is_null())
  261. return false;
  262. uint32_t code = get_keycode_with_modifiers();
  263. uint32_t event_code = key->get_keycode_with_modifiers();
  264. return code == event_code;
  265. }
  266. void InputEventKey::_bind_methods() {
  267. ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventKey::set_pressed);
  268. ClassDB::bind_method(D_METHOD("set_keycode", "keycode"), &InputEventKey::set_keycode);
  269. ClassDB::bind_method(D_METHOD("get_keycode"), &InputEventKey::get_keycode);
  270. ClassDB::bind_method(D_METHOD("set_physical_keycode", "physical_keycode"), &InputEventKey::set_physical_keycode);
  271. ClassDB::bind_method(D_METHOD("get_physical_keycode"), &InputEventKey::get_physical_keycode);
  272. ClassDB::bind_method(D_METHOD("set_unicode", "unicode"), &InputEventKey::set_unicode);
  273. ClassDB::bind_method(D_METHOD("get_unicode"), &InputEventKey::get_unicode);
  274. ClassDB::bind_method(D_METHOD("set_echo", "echo"), &InputEventKey::set_echo);
  275. ClassDB::bind_method(D_METHOD("get_keycode_with_modifiers"), &InputEventKey::get_keycode_with_modifiers);
  276. ClassDB::bind_method(D_METHOD("get_physical_keycode_with_modifiers"), &InputEventKey::get_physical_keycode_with_modifiers);
  277. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
  278. ADD_PROPERTY(PropertyInfo(Variant::INT, "keycode"), "set_keycode", "get_keycode");
  279. ADD_PROPERTY(PropertyInfo(Variant::INT, "physical_keycode"), "set_physical_keycode", "get_physical_keycode");
  280. ADD_PROPERTY(PropertyInfo(Variant::INT, "unicode"), "set_unicode", "get_unicode");
  281. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "echo"), "set_echo", "is_echo");
  282. }
  283. ///////////////////////////////////
  284. void InputEventMouse::set_button_mask(int p_mask) {
  285. button_mask = p_mask;
  286. }
  287. int InputEventMouse::get_button_mask() const {
  288. return button_mask;
  289. }
  290. void InputEventMouse::set_position(const Vector2 &p_pos) {
  291. pos = p_pos;
  292. }
  293. Vector2 InputEventMouse::get_position() const {
  294. return pos;
  295. }
  296. void InputEventMouse::set_global_position(const Vector2 &p_global_pos) {
  297. global_pos = p_global_pos;
  298. }
  299. Vector2 InputEventMouse::get_global_position() const {
  300. return global_pos;
  301. }
  302. void InputEventMouse::_bind_methods() {
  303. ClassDB::bind_method(D_METHOD("set_button_mask", "button_mask"), &InputEventMouse::set_button_mask);
  304. ClassDB::bind_method(D_METHOD("get_button_mask"), &InputEventMouse::get_button_mask);
  305. ClassDB::bind_method(D_METHOD("set_position", "position"), &InputEventMouse::set_position);
  306. ClassDB::bind_method(D_METHOD("get_position"), &InputEventMouse::get_position);
  307. ClassDB::bind_method(D_METHOD("set_global_position", "global_position"), &InputEventMouse::set_global_position);
  308. ClassDB::bind_method(D_METHOD("get_global_position"), &InputEventMouse::get_global_position);
  309. ADD_PROPERTY(PropertyInfo(Variant::INT, "button_mask"), "set_button_mask", "get_button_mask");
  310. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position"), "set_position", "get_position");
  311. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "global_position"), "set_global_position", "get_global_position");
  312. }
  313. ///////////////////////////////////
  314. void InputEventMouseButton::set_factor(float p_factor) {
  315. factor = p_factor;
  316. }
  317. float InputEventMouseButton::get_factor() const {
  318. return factor;
  319. }
  320. void InputEventMouseButton::set_button_index(int p_index) {
  321. button_index = p_index;
  322. }
  323. int InputEventMouseButton::get_button_index() const {
  324. return button_index;
  325. }
  326. void InputEventMouseButton::set_pressed(bool p_pressed) {
  327. pressed = p_pressed;
  328. }
  329. bool InputEventMouseButton::is_pressed() const {
  330. return pressed;
  331. }
  332. void InputEventMouseButton::set_doubleclick(bool p_doubleclick) {
  333. doubleclick = p_doubleclick;
  334. }
  335. bool InputEventMouseButton::is_doubleclick() const {
  336. return doubleclick;
  337. }
  338. Ref<InputEvent> InputEventMouseButton::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
  339. Vector2 g = get_global_position();
  340. Vector2 l = p_xform.xform(get_position() + p_local_ofs);
  341. Ref<InputEventMouseButton> mb;
  342. mb.instance();
  343. mb->set_device(get_device());
  344. mb->set_window_id(get_window_id());
  345. mb->set_modifiers_from_event(this);
  346. mb->set_position(l);
  347. mb->set_global_position(g);
  348. mb->set_button_mask(get_button_mask());
  349. mb->set_pressed(pressed);
  350. mb->set_doubleclick(doubleclick);
  351. mb->set_factor(factor);
  352. mb->set_button_index(button_index);
  353. return mb;
  354. }
  355. bool InputEventMouseButton::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
  356. Ref<InputEventMouseButton> mb = p_event;
  357. if (mb.is_null())
  358. return false;
  359. bool match = mb->button_index == button_index;
  360. if (match) {
  361. if (p_pressed != nullptr)
  362. *p_pressed = mb->is_pressed();
  363. if (p_strength != nullptr)
  364. *p_strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f;
  365. }
  366. return match;
  367. }
  368. String InputEventMouseButton::as_text() const {
  369. String button_index_string = "";
  370. switch (get_button_index()) {
  371. case BUTTON_LEFT:
  372. button_index_string = "BUTTON_LEFT";
  373. break;
  374. case BUTTON_RIGHT:
  375. button_index_string = "BUTTON_RIGHT";
  376. break;
  377. case BUTTON_MIDDLE:
  378. button_index_string = "BUTTON_MIDDLE";
  379. break;
  380. case BUTTON_WHEEL_UP:
  381. button_index_string = "BUTTON_WHEEL_UP";
  382. break;
  383. case BUTTON_WHEEL_DOWN:
  384. button_index_string = "BUTTON_WHEEL_DOWN";
  385. break;
  386. case BUTTON_WHEEL_LEFT:
  387. button_index_string = "BUTTON_WHEEL_LEFT";
  388. break;
  389. case BUTTON_WHEEL_RIGHT:
  390. button_index_string = "BUTTON_WHEEL_RIGHT";
  391. break;
  392. case BUTTON_XBUTTON1:
  393. button_index_string = "BUTTON_XBUTTON1";
  394. break;
  395. case BUTTON_XBUTTON2:
  396. button_index_string = "BUTTON_XBUTTON2";
  397. break;
  398. default:
  399. button_index_string = itos(get_button_index());
  400. break;
  401. }
  402. 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");
  403. }
  404. void InputEventMouseButton::_bind_methods() {
  405. ClassDB::bind_method(D_METHOD("set_factor", "factor"), &InputEventMouseButton::set_factor);
  406. ClassDB::bind_method(D_METHOD("get_factor"), &InputEventMouseButton::get_factor);
  407. ClassDB::bind_method(D_METHOD("set_button_index", "button_index"), &InputEventMouseButton::set_button_index);
  408. ClassDB::bind_method(D_METHOD("get_button_index"), &InputEventMouseButton::get_button_index);
  409. ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventMouseButton::set_pressed);
  410. // ClassDB::bind_method(D_METHOD("is_pressed"), &InputEventMouseButton::is_pressed);
  411. ClassDB::bind_method(D_METHOD("set_doubleclick", "doubleclick"), &InputEventMouseButton::set_doubleclick);
  412. ClassDB::bind_method(D_METHOD("is_doubleclick"), &InputEventMouseButton::is_doubleclick);
  413. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "factor"), "set_factor", "get_factor");
  414. ADD_PROPERTY(PropertyInfo(Variant::INT, "button_index"), "set_button_index", "get_button_index");
  415. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
  416. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "doubleclick"), "set_doubleclick", "is_doubleclick");
  417. }
  418. ///////////////////////////////////
  419. void InputEventMouseMotion::set_tilt(const Vector2 &p_tilt) {
  420. tilt = p_tilt;
  421. }
  422. Vector2 InputEventMouseMotion::get_tilt() const {
  423. return tilt;
  424. }
  425. void InputEventMouseMotion::set_pressure(float p_pressure) {
  426. pressure = p_pressure;
  427. }
  428. float InputEventMouseMotion::get_pressure() const {
  429. return pressure;
  430. }
  431. void InputEventMouseMotion::set_relative(const Vector2 &p_relative) {
  432. relative = p_relative;
  433. }
  434. Vector2 InputEventMouseMotion::get_relative() const {
  435. return relative;
  436. }
  437. void InputEventMouseMotion::set_speed(const Vector2 &p_speed) {
  438. speed = p_speed;
  439. }
  440. Vector2 InputEventMouseMotion::get_speed() const {
  441. return speed;
  442. }
  443. Ref<InputEvent> InputEventMouseMotion::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
  444. Vector2 g = get_global_position();
  445. Vector2 l = p_xform.xform(get_position() + p_local_ofs);
  446. Vector2 r = p_xform.basis_xform(get_relative());
  447. Vector2 s = p_xform.basis_xform(get_speed());
  448. Ref<InputEventMouseMotion> mm;
  449. mm.instance();
  450. mm->set_device(get_device());
  451. mm->set_window_id(get_window_id());
  452. mm->set_modifiers_from_event(this);
  453. mm->set_position(l);
  454. mm->set_pressure(get_pressure());
  455. mm->set_tilt(get_tilt());
  456. mm->set_global_position(g);
  457. mm->set_button_mask(get_button_mask());
  458. mm->set_relative(r);
  459. mm->set_speed(s);
  460. return mm;
  461. }
  462. String InputEventMouseMotion::as_text() const {
  463. String button_mask_string = "";
  464. switch (get_button_mask()) {
  465. case BUTTON_MASK_LEFT:
  466. button_mask_string = "BUTTON_MASK_LEFT";
  467. break;
  468. case BUTTON_MASK_MIDDLE:
  469. button_mask_string = "BUTTON_MASK_MIDDLE";
  470. break;
  471. case BUTTON_MASK_RIGHT:
  472. button_mask_string = "BUTTON_MASK_RIGHT";
  473. break;
  474. case BUTTON_MASK_XBUTTON1:
  475. button_mask_string = "BUTTON_MASK_XBUTTON1";
  476. break;
  477. case BUTTON_MASK_XBUTTON2:
  478. button_mask_string = "BUTTON_MASK_XBUTTON2";
  479. break;
  480. default:
  481. button_mask_string = itos(get_button_mask());
  482. break;
  483. }
  484. return "InputEventMouseMotion : button_mask=" + button_mask_string + ", position=(" + String(get_position()) + "), relative=(" + String(get_relative()) + "), speed=(" + String(get_speed()) + "), pressure=(" + rtos(get_pressure()) + "), tilt=(" + String(get_tilt()) + ")";
  485. }
  486. bool InputEventMouseMotion::accumulate(const Ref<InputEvent> &p_event) {
  487. Ref<InputEventMouseMotion> motion = p_event;
  488. if (motion.is_null())
  489. return false;
  490. if (get_window_id() != motion->get_window_id()) {
  491. return false;
  492. }
  493. if (is_pressed() != motion->is_pressed()) {
  494. return false;
  495. }
  496. if (get_button_mask() != motion->get_button_mask()) {
  497. return false;
  498. }
  499. if (get_shift() != motion->get_shift()) {
  500. return false;
  501. }
  502. if (get_control() != motion->get_control()) {
  503. return false;
  504. }
  505. if (get_alt() != motion->get_alt()) {
  506. return false;
  507. }
  508. if (get_metakey() != motion->get_metakey()) {
  509. return false;
  510. }
  511. set_position(motion->get_position());
  512. set_global_position(motion->get_global_position());
  513. set_speed(motion->get_speed());
  514. relative += motion->get_relative();
  515. return true;
  516. }
  517. void InputEventMouseMotion::_bind_methods() {
  518. ClassDB::bind_method(D_METHOD("set_tilt", "tilt"), &InputEventMouseMotion::set_tilt);
  519. ClassDB::bind_method(D_METHOD("get_tilt"), &InputEventMouseMotion::get_tilt);
  520. ClassDB::bind_method(D_METHOD("set_pressure", "pressure"), &InputEventMouseMotion::set_pressure);
  521. ClassDB::bind_method(D_METHOD("get_pressure"), &InputEventMouseMotion::get_pressure);
  522. ClassDB::bind_method(D_METHOD("set_relative", "relative"), &InputEventMouseMotion::set_relative);
  523. ClassDB::bind_method(D_METHOD("get_relative"), &InputEventMouseMotion::get_relative);
  524. ClassDB::bind_method(D_METHOD("set_speed", "speed"), &InputEventMouseMotion::set_speed);
  525. ClassDB::bind_method(D_METHOD("get_speed"), &InputEventMouseMotion::get_speed);
  526. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "tilt"), "set_tilt", "get_tilt");
  527. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "pressure"), "set_pressure", "get_pressure");
  528. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "relative"), "set_relative", "get_relative");
  529. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "speed"), "set_speed", "get_speed");
  530. }
  531. ///////////////////////////////////
  532. void InputEventJoypadMotion::set_axis(int p_axis) {
  533. axis = p_axis;
  534. }
  535. int InputEventJoypadMotion::get_axis() const {
  536. return axis;
  537. }
  538. void InputEventJoypadMotion::set_axis_value(float p_value) {
  539. axis_value = p_value;
  540. }
  541. float InputEventJoypadMotion::get_axis_value() const {
  542. return axis_value;
  543. }
  544. bool InputEventJoypadMotion::is_pressed() const {
  545. return Math::abs(axis_value) >= 0.5f;
  546. }
  547. bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
  548. Ref<InputEventJoypadMotion> jm = p_event;
  549. if (jm.is_null())
  550. return false;
  551. bool match = (axis == jm->axis); // Matches even if not in the same direction, but returns a "not pressed" event.
  552. if (match) {
  553. bool same_direction = (((axis_value < 0) == (jm->axis_value < 0)) || jm->axis_value == 0);
  554. bool pressed = same_direction ? Math::abs(jm->get_axis_value()) >= p_deadzone : false;
  555. if (p_pressed != nullptr)
  556. *p_pressed = pressed;
  557. if (p_strength != nullptr) {
  558. if (pressed) {
  559. if (p_deadzone == 1.0f) {
  560. *p_strength = 1.0f;
  561. } else {
  562. *p_strength = CLAMP(Math::inverse_lerp(p_deadzone, 1.0f, Math::abs(jm->get_axis_value())), 0.0f, 1.0f);
  563. }
  564. } else {
  565. *p_strength = 0.0f;
  566. }
  567. }
  568. }
  569. return match;
  570. }
  571. String InputEventJoypadMotion::as_text() const {
  572. return "InputEventJoypadMotion : axis=" + itos(axis) + ", axis_value=" + String(Variant(axis_value));
  573. }
  574. void InputEventJoypadMotion::_bind_methods() {
  575. ClassDB::bind_method(D_METHOD("set_axis", "axis"), &InputEventJoypadMotion::set_axis);
  576. ClassDB::bind_method(D_METHOD("get_axis"), &InputEventJoypadMotion::get_axis);
  577. ClassDB::bind_method(D_METHOD("set_axis_value", "axis_value"), &InputEventJoypadMotion::set_axis_value);
  578. ClassDB::bind_method(D_METHOD("get_axis_value"), &InputEventJoypadMotion::get_axis_value);
  579. ADD_PROPERTY(PropertyInfo(Variant::INT, "axis"), "set_axis", "get_axis");
  580. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "axis_value"), "set_axis_value", "get_axis_value");
  581. }
  582. ///////////////////////////////////
  583. void InputEventJoypadButton::set_button_index(int p_index) {
  584. button_index = p_index;
  585. }
  586. int InputEventJoypadButton::get_button_index() const {
  587. return button_index;
  588. }
  589. void InputEventJoypadButton::set_pressed(bool p_pressed) {
  590. pressed = p_pressed;
  591. }
  592. bool InputEventJoypadButton::is_pressed() const {
  593. return pressed;
  594. }
  595. void InputEventJoypadButton::set_pressure(float p_pressure) {
  596. pressure = p_pressure;
  597. }
  598. float InputEventJoypadButton::get_pressure() const {
  599. return pressure;
  600. }
  601. bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
  602. Ref<InputEventJoypadButton> jb = p_event;
  603. if (jb.is_null())
  604. return false;
  605. bool match = button_index == jb->button_index;
  606. if (match) {
  607. if (p_pressed != nullptr)
  608. *p_pressed = jb->is_pressed();
  609. if (p_strength != nullptr)
  610. *p_strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f;
  611. }
  612. return match;
  613. }
  614. bool InputEventJoypadButton::shortcut_match(const Ref<InputEvent> &p_event) const {
  615. Ref<InputEventJoypadButton> button = p_event;
  616. if (button.is_null())
  617. return false;
  618. return button_index == button->button_index;
  619. }
  620. String InputEventJoypadButton::as_text() const {
  621. return "InputEventJoypadButton : button_index=" + itos(button_index) + ", pressed=" + (pressed ? "true" : "false") + ", pressure=" + String(Variant(pressure));
  622. }
  623. void InputEventJoypadButton::_bind_methods() {
  624. ClassDB::bind_method(D_METHOD("set_button_index", "button_index"), &InputEventJoypadButton::set_button_index);
  625. ClassDB::bind_method(D_METHOD("get_button_index"), &InputEventJoypadButton::get_button_index);
  626. ClassDB::bind_method(D_METHOD("set_pressure", "pressure"), &InputEventJoypadButton::set_pressure);
  627. ClassDB::bind_method(D_METHOD("get_pressure"), &InputEventJoypadButton::get_pressure);
  628. ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventJoypadButton::set_pressed);
  629. // ClassDB::bind_method(D_METHOD("is_pressed"), &InputEventJoypadButton::is_pressed);
  630. ADD_PROPERTY(PropertyInfo(Variant::INT, "button_index"), "set_button_index", "get_button_index");
  631. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "pressure"), "set_pressure", "get_pressure");
  632. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
  633. }
  634. ///////////////////////////////////
  635. void InputEventScreenTouch::set_index(int p_index) {
  636. index = p_index;
  637. }
  638. int InputEventScreenTouch::get_index() const {
  639. return index;
  640. }
  641. void InputEventScreenTouch::set_position(const Vector2 &p_pos) {
  642. pos = p_pos;
  643. }
  644. Vector2 InputEventScreenTouch::get_position() const {
  645. return pos;
  646. }
  647. void InputEventScreenTouch::set_pressed(bool p_pressed) {
  648. pressed = p_pressed;
  649. }
  650. bool InputEventScreenTouch::is_pressed() const {
  651. return pressed;
  652. }
  653. Ref<InputEvent> InputEventScreenTouch::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
  654. Ref<InputEventScreenTouch> st;
  655. st.instance();
  656. st->set_device(get_device());
  657. st->set_window_id(get_window_id());
  658. st->set_index(index);
  659. st->set_position(p_xform.xform(pos + p_local_ofs));
  660. st->set_pressed(pressed);
  661. return st;
  662. }
  663. String InputEventScreenTouch::as_text() const {
  664. return "InputEventScreenTouch : index=" + itos(index) + ", pressed=" + (pressed ? "true" : "false") + ", position=(" + String(get_position()) + ")";
  665. }
  666. void InputEventScreenTouch::_bind_methods() {
  667. ClassDB::bind_method(D_METHOD("set_index", "index"), &InputEventScreenTouch::set_index);
  668. ClassDB::bind_method(D_METHOD("get_index"), &InputEventScreenTouch::get_index);
  669. ClassDB::bind_method(D_METHOD("set_position", "position"), &InputEventScreenTouch::set_position);
  670. ClassDB::bind_method(D_METHOD("get_position"), &InputEventScreenTouch::get_position);
  671. ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventScreenTouch::set_pressed);
  672. //ClassDB::bind_method(D_METHOD("is_pressed"),&InputEventScreenTouch::is_pressed);
  673. ADD_PROPERTY(PropertyInfo(Variant::INT, "index"), "set_index", "get_index");
  674. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position"), "set_position", "get_position");
  675. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
  676. }
  677. ///////////////////////////////////
  678. void InputEventScreenDrag::set_index(int p_index) {
  679. index = p_index;
  680. }
  681. int InputEventScreenDrag::get_index() const {
  682. return index;
  683. }
  684. void InputEventScreenDrag::set_position(const Vector2 &p_pos) {
  685. pos = p_pos;
  686. }
  687. Vector2 InputEventScreenDrag::get_position() const {
  688. return pos;
  689. }
  690. void InputEventScreenDrag::set_relative(const Vector2 &p_relative) {
  691. relative = p_relative;
  692. }
  693. Vector2 InputEventScreenDrag::get_relative() const {
  694. return relative;
  695. }
  696. void InputEventScreenDrag::set_speed(const Vector2 &p_speed) {
  697. speed = p_speed;
  698. }
  699. Vector2 InputEventScreenDrag::get_speed() const {
  700. return speed;
  701. }
  702. Ref<InputEvent> InputEventScreenDrag::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
  703. Ref<InputEventScreenDrag> sd;
  704. sd.instance();
  705. sd->set_device(get_device());
  706. sd->set_window_id(get_window_id());
  707. sd->set_index(index);
  708. sd->set_position(p_xform.xform(pos + p_local_ofs));
  709. sd->set_relative(p_xform.basis_xform(relative));
  710. sd->set_speed(p_xform.basis_xform(speed));
  711. return sd;
  712. }
  713. String InputEventScreenDrag::as_text() const {
  714. return "InputEventScreenDrag : index=" + itos(index) + ", position=(" + String(get_position()) + "), relative=(" + String(get_relative()) + "), speed=(" + String(get_speed()) + ")";
  715. }
  716. void InputEventScreenDrag::_bind_methods() {
  717. ClassDB::bind_method(D_METHOD("set_index", "index"), &InputEventScreenDrag::set_index);
  718. ClassDB::bind_method(D_METHOD("get_index"), &InputEventScreenDrag::get_index);
  719. ClassDB::bind_method(D_METHOD("set_position", "position"), &InputEventScreenDrag::set_position);
  720. ClassDB::bind_method(D_METHOD("get_position"), &InputEventScreenDrag::get_position);
  721. ClassDB::bind_method(D_METHOD("set_relative", "relative"), &InputEventScreenDrag::set_relative);
  722. ClassDB::bind_method(D_METHOD("get_relative"), &InputEventScreenDrag::get_relative);
  723. ClassDB::bind_method(D_METHOD("set_speed", "speed"), &InputEventScreenDrag::set_speed);
  724. ClassDB::bind_method(D_METHOD("get_speed"), &InputEventScreenDrag::get_speed);
  725. ADD_PROPERTY(PropertyInfo(Variant::INT, "index"), "set_index", "get_index");
  726. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position"), "set_position", "get_position");
  727. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "relative"), "set_relative", "get_relative");
  728. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "speed"), "set_speed", "get_speed");
  729. }
  730. ///////////////////////////////////
  731. void InputEventAction::set_action(const StringName &p_action) {
  732. action = p_action;
  733. }
  734. StringName InputEventAction::get_action() const {
  735. return action;
  736. }
  737. void InputEventAction::set_pressed(bool p_pressed) {
  738. pressed = p_pressed;
  739. }
  740. bool InputEventAction::is_pressed() const {
  741. return pressed;
  742. }
  743. void InputEventAction::set_strength(float p_strength) {
  744. strength = CLAMP(p_strength, 0.0f, 1.0f);
  745. }
  746. float InputEventAction::get_strength() const {
  747. return strength;
  748. }
  749. bool InputEventAction::shortcut_match(const Ref<InputEvent> &p_event) const {
  750. if (p_event.is_null())
  751. return false;
  752. return p_event->is_action(action);
  753. }
  754. bool InputEventAction::is_action(const StringName &p_action) const {
  755. return action == p_action;
  756. }
  757. bool InputEventAction::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
  758. Ref<InputEventAction> act = p_event;
  759. if (act.is_null())
  760. return false;
  761. bool match = action == act->action;
  762. if (match) {
  763. if (p_pressed != nullptr)
  764. *p_pressed = act->pressed;
  765. if (p_strength != nullptr)
  766. *p_strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f;
  767. }
  768. return match;
  769. }
  770. String InputEventAction::as_text() const {
  771. return "InputEventAction : action=" + action + ", pressed=(" + (pressed ? "true" : "false");
  772. }
  773. void InputEventAction::_bind_methods() {
  774. ClassDB::bind_method(D_METHOD("set_action", "action"), &InputEventAction::set_action);
  775. ClassDB::bind_method(D_METHOD("get_action"), &InputEventAction::get_action);
  776. ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventAction::set_pressed);
  777. //ClassDB::bind_method(D_METHOD("is_pressed"), &InputEventAction::is_pressed);
  778. ClassDB::bind_method(D_METHOD("set_strength", "strength"), &InputEventAction::set_strength);
  779. ClassDB::bind_method(D_METHOD("get_strength"), &InputEventAction::get_strength);
  780. // ClassDB::bind_method(D_METHOD("is_action", "name"), &InputEventAction::is_action);
  781. ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "action"), "set_action", "get_action");
  782. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
  783. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "strength", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_strength", "get_strength");
  784. }
  785. ///////////////////////////////////
  786. void InputEventGesture::set_position(const Vector2 &p_pos) {
  787. pos = p_pos;
  788. }
  789. void InputEventGesture::_bind_methods() {
  790. ClassDB::bind_method(D_METHOD("set_position", "position"), &InputEventGesture::set_position);
  791. ClassDB::bind_method(D_METHOD("get_position"), &InputEventGesture::get_position);
  792. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position"), "set_position", "get_position");
  793. }
  794. Vector2 InputEventGesture::get_position() const {
  795. return pos;
  796. }
  797. ///////////////////////////////////
  798. void InputEventMagnifyGesture::set_factor(real_t p_factor) {
  799. factor = p_factor;
  800. }
  801. real_t InputEventMagnifyGesture::get_factor() const {
  802. return factor;
  803. }
  804. Ref<InputEvent> InputEventMagnifyGesture::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
  805. Ref<InputEventMagnifyGesture> ev;
  806. ev.instance();
  807. ev->set_device(get_device());
  808. ev->set_window_id(get_window_id());
  809. ev->set_modifiers_from_event(this);
  810. ev->set_position(p_xform.xform(get_position() + p_local_ofs));
  811. ev->set_factor(get_factor());
  812. return ev;
  813. }
  814. String InputEventMagnifyGesture::as_text() const {
  815. return "InputEventMagnifyGesture : factor=" + rtos(get_factor()) + ", position=(" + String(get_position()) + ")";
  816. }
  817. void InputEventMagnifyGesture::_bind_methods() {
  818. ClassDB::bind_method(D_METHOD("set_factor", "factor"), &InputEventMagnifyGesture::set_factor);
  819. ClassDB::bind_method(D_METHOD("get_factor"), &InputEventMagnifyGesture::get_factor);
  820. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "factor"), "set_factor", "get_factor");
  821. }
  822. ///////////////////////////////////
  823. void InputEventPanGesture::set_delta(const Vector2 &p_delta) {
  824. delta = p_delta;
  825. }
  826. Vector2 InputEventPanGesture::get_delta() const {
  827. return delta;
  828. }
  829. Ref<InputEvent> InputEventPanGesture::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
  830. Ref<InputEventPanGesture> ev;
  831. ev.instance();
  832. ev->set_device(get_device());
  833. ev->set_window_id(get_window_id());
  834. ev->set_modifiers_from_event(this);
  835. ev->set_position(p_xform.xform(get_position() + p_local_ofs));
  836. ev->set_delta(get_delta());
  837. return ev;
  838. }
  839. String InputEventPanGesture::as_text() const {
  840. return "InputEventPanGesture : delta=(" + String(get_delta()) + "), position=(" + String(get_position()) + ")";
  841. }
  842. void InputEventPanGesture::_bind_methods() {
  843. ClassDB::bind_method(D_METHOD("set_delta", "delta"), &InputEventPanGesture::set_delta);
  844. ClassDB::bind_method(D_METHOD("get_delta"), &InputEventPanGesture::get_delta);
  845. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "delta"), "set_delta", "get_delta");
  846. }
  847. ///////////////////////////////////
  848. void InputEventMIDI::set_channel(const int p_channel) {
  849. channel = p_channel;
  850. }
  851. int InputEventMIDI::get_channel() const {
  852. return channel;
  853. }
  854. void InputEventMIDI::set_message(const int p_message) {
  855. message = p_message;
  856. }
  857. int InputEventMIDI::get_message() const {
  858. return message;
  859. }
  860. void InputEventMIDI::set_pitch(const int p_pitch) {
  861. pitch = p_pitch;
  862. }
  863. int InputEventMIDI::get_pitch() const {
  864. return pitch;
  865. }
  866. void InputEventMIDI::set_velocity(const int p_velocity) {
  867. velocity = p_velocity;
  868. }
  869. int InputEventMIDI::get_velocity() const {
  870. return velocity;
  871. }
  872. void InputEventMIDI::set_instrument(const int p_instrument) {
  873. instrument = p_instrument;
  874. }
  875. int InputEventMIDI::get_instrument() const {
  876. return instrument;
  877. }
  878. void InputEventMIDI::set_pressure(const int p_pressure) {
  879. pressure = p_pressure;
  880. }
  881. int InputEventMIDI::get_pressure() const {
  882. return pressure;
  883. }
  884. void InputEventMIDI::set_controller_number(const int p_controller_number) {
  885. controller_number = p_controller_number;
  886. }
  887. int InputEventMIDI::get_controller_number() const {
  888. return controller_number;
  889. }
  890. void InputEventMIDI::set_controller_value(const int p_controller_value) {
  891. controller_value = p_controller_value;
  892. }
  893. int InputEventMIDI::get_controller_value() const {
  894. return controller_value;
  895. }
  896. String InputEventMIDI::as_text() const {
  897. return "InputEventMIDI : channel=(" + itos(get_channel()) + "), message=(" + itos(get_message()) + ")";
  898. }
  899. void InputEventMIDI::_bind_methods() {
  900. ClassDB::bind_method(D_METHOD("set_channel", "channel"), &InputEventMIDI::set_channel);
  901. ClassDB::bind_method(D_METHOD("get_channel"), &InputEventMIDI::get_channel);
  902. ClassDB::bind_method(D_METHOD("set_message", "message"), &InputEventMIDI::set_message);
  903. ClassDB::bind_method(D_METHOD("get_message"), &InputEventMIDI::get_message);
  904. ClassDB::bind_method(D_METHOD("set_pitch", "pitch"), &InputEventMIDI::set_pitch);
  905. ClassDB::bind_method(D_METHOD("get_pitch"), &InputEventMIDI::get_pitch);
  906. ClassDB::bind_method(D_METHOD("set_velocity", "velocity"), &InputEventMIDI::set_velocity);
  907. ClassDB::bind_method(D_METHOD("get_velocity"), &InputEventMIDI::get_velocity);
  908. ClassDB::bind_method(D_METHOD("set_instrument", "instrument"), &InputEventMIDI::set_instrument);
  909. ClassDB::bind_method(D_METHOD("get_instrument"), &InputEventMIDI::get_instrument);
  910. ClassDB::bind_method(D_METHOD("set_pressure", "pressure"), &InputEventMIDI::set_pressure);
  911. ClassDB::bind_method(D_METHOD("get_pressure"), &InputEventMIDI::get_pressure);
  912. ClassDB::bind_method(D_METHOD("set_controller_number", "controller_number"), &InputEventMIDI::set_controller_number);
  913. ClassDB::bind_method(D_METHOD("get_controller_number"), &InputEventMIDI::get_controller_number);
  914. ClassDB::bind_method(D_METHOD("set_controller_value", "controller_value"), &InputEventMIDI::set_controller_value);
  915. ClassDB::bind_method(D_METHOD("get_controller_value"), &InputEventMIDI::get_controller_value);
  916. ADD_PROPERTY(PropertyInfo(Variant::INT, "channel"), "set_channel", "get_channel");
  917. ADD_PROPERTY(PropertyInfo(Variant::INT, "message"), "set_message", "get_message");
  918. ADD_PROPERTY(PropertyInfo(Variant::INT, "pitch"), "set_pitch", "get_pitch");
  919. ADD_PROPERTY(PropertyInfo(Variant::INT, "velocity"), "set_velocity", "get_velocity");
  920. ADD_PROPERTY(PropertyInfo(Variant::INT, "instrument"), "set_instrument", "get_instrument");
  921. ADD_PROPERTY(PropertyInfo(Variant::INT, "pressure"), "set_pressure", "get_pressure");
  922. ADD_PROPERTY(PropertyInfo(Variant::INT, "controller_number"), "set_controller_number", "get_controller_number");
  923. ADD_PROPERTY(PropertyInfo(Variant::INT, "controller_value"), "set_controller_value", "get_controller_value");
  924. }