input_event.cpp 41 KB

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