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.manager;
37 
38 import aurorafw.core.input.state;
39 import aurorafw.core.input.rawlistener;
40 import aurorafw.core.input.events;
41 
42 struct InputManager
43 {
44 	public void addRawListener(RawInputListener listener)
45 	{
46 		_rawlisteneres ~= listener;
47 	}
48 
49 	public void removeRawListener(int index)
50 	{
51 		import std.algorithm : remove;
52 
53 		_rawlisteneres.remove(index);
54 	}
55 
56 	public void keyPressed(immutable KeyboardEvent e)
57 	{
58 		foreach (listener; _rawlisteneres)
59 			listener.keyPressed(e, _keyboardState.isKeyPressed(e.key));
60 		_keyboardState.pressKey(e.key);
61 	}
62 
63 	public void keyReleased(immutable KeyboardEvent e)
64 	{
65 		foreach (listener; _rawlisteneres)
66 			listener.keyReleased(e);
67 		_keyboardState.releaseKey(e.key);
68 	}
69 
70 	public void mousePressed(immutable MouseButtonEvent e)
71 	{
72 		foreach (listener; _rawlisteneres)
73 			listener.mousePressed(e, _mouseState.isButtonPressed(e.btn));
74 		_mouseState.pressButton(e.btn);
75 	}
76 
77 	public void mouseReleased(immutable MouseButtonEvent e)
78 	{
79 		foreach (listener; _rawlisteneres)
80 			listener.mouseReleased(e);
81 		_mouseState.releaseButton(e.btn);
82 	}
83 
84 	public void mouseMoved(immutable MouseMotionEvent e)
85 	{
86 		foreach (listener; _rawlisteneres)
87 			listener.mouseMoved(e);
88 
89 		_mouseState.x = e.xpos;
90 		_mouseState.y = e.ypos;
91 	}
92 
93 	public void mouseScrolled(immutable MouseScrollEvent e)
94 	{
95 		foreach (listener; _rawlisteneres)
96 			listener.mouseScrolled(e);
97 	}
98 
99 	public void touchMoved(immutable TouchFingerEvent e)
100 	{
101 		foreach (listener; _rawlisteneres)
102 			listener.touchMoved(e);
103 	}
104 
105 	public void touchPressed(immutable TouchFingerEvent e)
106 	{
107 		foreach (listener; _rawlisteneres)
108 			listener.touchPressed(e, _touchState.isTouchPressed(e.fingerID));
109 		_touchState.touchPress(e.fingerID);
110 	}
111 
112 	public void touchReleased(immutable TouchFingerEvent e)
113 	{
114 		foreach (listener; _rawlisteneres)
115 			listener.touchReleased(e);
116 		_touchState.touchRelease(e.fingerID);
117 	}
118 
119 	private RawInputListener[] _rawlisteneres;
120 	private MouseState _mouseState;
121 	private KeyboardState _keyboardState;
122 	private TouchState _touchState;
123 }