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 { 45 ~this() 46 { 47 } 48 49 void keyPressed(immutable KeyboardEvent e, bool lastState) 50 { 51 } 52 53 void keyReleased(immutable KeyboardEvent e) 54 { 55 } 56 57 void mousePressed(immutable MouseButtonEvent e, bool lastState) 58 { 59 } 60 61 void mouseReleased(immutable MouseButtonEvent e) 62 { 63 } 64 65 void mouseMoved(immutable MouseMotionEvent e) 66 { 67 } 68 69 void mouseScrolled(immutable MouseScrollEvent e) 70 { 71 } 72 73 void touchMoved(immutable TouchFingerEvent e) 74 { 75 } 76 77 void touchPressed(immutable TouchFingerEvent e, bool lastState) 78 { 79 } 80 81 void touchReleased(immutable TouchFingerEvent e) 82 { 83 } 84 } 85 86 @safe pure 87 @("Input: raw listener") 88 unittest 89 { 90 class MyInputListener : RawInputListener 91 { 92 93 override void keyPressed(immutable KeyboardEvent e, bool lastState) 94 { 95 assert(e.key == Keycode.Enter); 96 assert(e.mods == InputModifier.Control); 97 98 assert(!lastState); 99 } 100 101 override void keyReleased(immutable KeyboardEvent e) 102 { 103 assert(e.key == Keycode.Enter); 104 assert(e.mods == InputModifier.None); 105 } 106 107 override void mousePressed(immutable MouseButtonEvent e, bool lastState) 108 { 109 assert(e.btn == InputButton.Left); 110 assert(e.mods == InputModifier.NumLock); 111 112 assert(lastState); 113 } 114 115 override void mouseReleased(immutable MouseButtonEvent e) 116 { 117 assert(e.btn == InputButton.Right); 118 assert(e.mods == InputModifier.None); 119 } 120 121 override void mouseMoved(immutable MouseMotionEvent e) 122 { 123 assert(e.xpos == 1.04); 124 assert(e.ypos == -0.23); 125 } 126 127 override void mouseScrolled(immutable MouseScrollEvent e) 128 { 129 assert(e.xoffset == 1.0); 130 assert(e.yoffset == -1.0); 131 } 132 133 override void touchMoved(immutable TouchFingerEvent e) 134 { 135 assert(e.dx == 1.32f); 136 assert(e.dy == 0.23f); 137 138 assert(e.x == 2.54f); 139 assert(e.y == -5.27f); 140 141 assert(e.fingerID == 3); 142 } 143 144 override void touchPressed(immutable TouchFingerEvent e, bool lastState) 145 { 146 assert(e.dx == 1.32f); 147 assert(e.dy == 0.23f); 148 149 assert(e.x == 2.54f); 150 assert(e.y == -5.27f); 151 152 assert(e.fingerID == 3); 153 154 assert(lastState); 155 } 156 157 override void touchReleased(immutable TouchFingerEvent e) 158 { 159 assert(e.dx == 1.32f); 160 assert(e.dy == 0.23f); 161 162 assert(e.x == 2.54f); 163 assert(e.y == -5.27f); 164 165 assert(e.fingerID == 3); 166 } 167 } 168 169 MyInputListener listener = new MyInputListener(); 170 171 listener.keyPressed(KeyboardEvent(Keycode.Enter, InputModifier.Control), false); 172 listener.keyReleased(KeyboardEvent(Keycode.Enter)); 173 listener.mousePressed(MouseButtonEvent(InputButton.Left, InputModifier.NumLock), true); 174 listener.mouseReleased(MouseButtonEvent(InputButton.Right)); 175 listener.mouseMoved(MouseMotionEvent(1.04, -0.23)); 176 listener.mouseScrolled(MouseScrollEvent(1.0, -1.0)); 177 listener.touchMoved(TouchFingerEvent(1.32f, 0.23f, 2.54f, -5.27f, 3)); 178 listener.touchPressed(TouchFingerEvent(1.32f, 0.23f, 2.54f, -5.27f, 3), true); 179 listener.touchReleased(TouchFingerEvent(1.32f, 0.23f, 2.54f, -5.27f, 3)); 180 }