1 /* 2 __ 3 / _| 4 __ _ _ _ _ __ ___ _ __ __ _ | |_ ___ ___ ___ 5 / _` | | | | '__/ _ \| '__/ _` | | _/ _ \/ __/ __| 6 | (_| | |_| | | | (_) | | | (_| | | || (_) \__ \__ \ 7 \__,_|\__,_|_| \___/|_| \__,_| |_| \___/|___/___/ 8 9 Copyright (C) 2018-2019 Aurora Free Open Source Software. 10 11 This file is part of the Aurora Free Open Source Software. This 12 organization promote free and open source software that you can 13 redistribute and/or modify under the terms of the GNU Lesser General 14 Public License Version 3 as published by the Free Software Foundation or 15 (at your option) any later version approved by the Aurora Free Open Source 16 Software Organization. The license is available in the package root path 17 as 'LICENSE' file. Please review the following information to ensure the 18 GNU Lesser General Public License version 3 requirements will be met: 19 https://www.gnu.org/licenses/lgpl.html . 20 21 Alternatively, this file may be used under the terms of the GNU General 22 Public License version 3 or later as published by the Free Software 23 Foundation. Please review the following information to ensure the GNU 24 General Public License requirements will be met: 25 http://www.gnu.org/licenses/gpl-3.0.html. 26 27 NOTE: All products, services or anything associated to trademarks and 28 service marks used or referenced on this file are the property of their 29 respective companies/owners or its subsidiaries. Other names and brands 30 may be claimed as the property of others. 31 32 For more info about intellectual property visit: aurorafoss.org or 33 directly send an email to: contact (at) aurorafoss.org . 34 */ 35 36 module aurorafw.core.input.rawlistener; 37 38 /// TODO: Need documentation 39 40 public import aurorafw.core.input.events; 41 public import aurorafw.core.input.keys; 42 43 pure @safe abstract class RawInputListener { 44 ~this() {} 45 46 void keyPressed(immutable KeyboardEvent e, bool lastState) {} 47 void keyReleased(immutable KeyboardEvent e) {} 48 void mousePressed(immutable MouseButtonEvent e, bool lastState) {} 49 void mouseReleased(immutable MouseButtonEvent e) {} 50 void mouseMoved(immutable MouseMotionEvent e) {} 51 void mouseScrolled(immutable MouseScrollEvent e) {} 52 void touchMoved(immutable TouchFingerEvent e) {} 53 void touchPressed(immutable TouchFingerEvent e, bool lastState) {} 54 void touchReleased(immutable TouchFingerEvent e) {} 55 } 56 57 58 @safe pure 59 @("Input: raw listener") 60 unittest { 61 class MyInputListener : RawInputListener { 62 63 override void keyPressed(immutable KeyboardEvent e, bool lastState) 64 { 65 assert(e.key == Keycode.Enter); 66 assert(e.mods == InputModifier.Control); 67 68 assert(!lastState); 69 } 70 71 72 override void keyReleased(immutable KeyboardEvent e) 73 { 74 assert(e.key == Keycode.Enter); 75 assert(e.mods == InputModifier.None); 76 } 77 78 79 override void mousePressed(immutable MouseButtonEvent e, bool lastState) 80 { 81 assert(e.btn == InputButton.Left); 82 assert(e.mods == InputModifier.NumLock); 83 84 assert(lastState); 85 } 86 87 88 override void mouseReleased(immutable MouseButtonEvent e) 89 { 90 assert(e.btn == InputButton.Right); 91 assert(e.mods == InputModifier.None); 92 } 93 94 95 override void mouseMoved(immutable MouseMotionEvent e) 96 { 97 assert(e.xpos == 1.04); 98 assert(e.ypos == -0.23); 99 } 100 101 102 override void mouseScrolled(immutable MouseScrollEvent e) 103 { 104 assert(e.xoffset == 1.0); 105 assert(e.yoffset == -1.0); 106 } 107 108 109 override void touchMoved(immutable TouchFingerEvent e) 110 { 111 assert(e.dx == 1.32f); 112 assert(e.dy == 0.23f); 113 114 assert(e.x == 2.54f); 115 assert(e.y == -5.27f); 116 117 assert(e.fingerID == 3); 118 } 119 120 121 override void touchPressed(immutable TouchFingerEvent e, bool lastState) 122 { 123 assert(e.dx == 1.32f); 124 assert(e.dy == 0.23f); 125 126 assert(e.x == 2.54f); 127 assert(e.y == -5.27f); 128 129 assert(e.fingerID == 3); 130 131 assert(lastState); 132 } 133 134 135 override void touchReleased(immutable TouchFingerEvent e) 136 { 137 assert(e.dx == 1.32f); 138 assert(e.dy == 0.23f); 139 140 assert(e.x == 2.54f); 141 assert(e.y == -5.27f); 142 143 assert(e.fingerID == 3); 144 } 145 } 146 147 MyInputListener listener = new MyInputListener(); 148 149 listener.keyPressed(KeyboardEvent(Keycode.Enter, InputModifier.Control), false); 150 listener.keyReleased(KeyboardEvent(Keycode.Enter)); 151 listener.mousePressed(MouseButtonEvent(InputButton.Left, InputModifier.NumLock), true); 152 listener.mouseReleased(MouseButtonEvent(InputButton.Right)); 153 listener.mouseMoved(MouseMotionEvent(1.04, -0.23)); 154 listener.mouseScrolled(MouseScrollEvent(1.0, -1.0)); 155 listener.touchMoved(TouchFingerEvent(1.32f, 0.23f, 2.54f, -5.27f, 3)); 156 listener.touchPressed(TouchFingerEvent(1.32f, 0.23f, 2.54f, -5.27f, 3), true); 157 listener.touchReleased(TouchFingerEvent(1.32f, 0.23f, 2.54f, -5.27f, 3)); 158 }