1 /***************************************************************************
2  *   Copyright (c) 2017-2019 by the fifechan team                               *
3  *   https://github.com/fifengine/fifechan                                 *
4  *   This file is part of fifechan.                                        *
5  *                                                                         *
6  *   fifechan is free software; you can redistribute it and/or             *
7  *   modify it under the terms of the GNU Lesser General Public            *
8  *   License as published by the Free Software Foundation; either          *
9  *   version 2.1 of the License, or (at your option) any later version.    *
10  *                                                                         *
11  *   This library is distributed in the hope that it will be useful,       *
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
14  *   Lesser General Public License for more details.                       *
15  *                                                                         *
16  *   You should have received a copy of the GNU Lesser General Public      *
17  *   License along with this library; if not, write to the                 *
18  *   Free Software Foundation, Inc.,                                       *
19  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
20  ***************************************************************************/
21 
22 /*      _______   __   __   __   ______   __   __   _______   __   __
23  *     / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___  /\ /  |\/ /\
24  *    / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
25  *   / / /__   / / // / // / // / /    / ___  / // ___  / // /| ' / /
26  *  / /_// /\ / /_// / // / // /_/_   / / // / // /\_/ / // / |  / /
27  * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
28  * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
29  *
30  * Copyright (c) 2004 - 2008 Olof Naess�n and Per Larsson
31  *
32  *
33  * Per Larsson a.k.a finalman
34  * Olof Naess�n a.k.a jansem/yakslem
35  *
36  * Visit: http://guichan.sourceforge.net
37  *
38  * License: (BSD)
39  * Redistribution and use in source and binary forms, with or without
40  * modification, are permitted provided that the following conditions
41  * are met:
42  * 1. Redistributions of source code must retain the above copyright
43  *    notice, this list of conditions and the following disclaimer.
44  * 2. Redistributions in binary form must reproduce the above copyright
45  *    notice, this list of conditions and the following disclaimer in
46  *    the documentation and/or other materials provided with the
47  *    distribution.
48  * 3. Neither the name of Guichan nor the names of its contributors may
49  *    be used to endorse or promote products derived from this software
50  *    without specific prior written permission.
51  *
52  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
53  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
54  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
55  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
56  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
57  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
58  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
59  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
60  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
61  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
62  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63  */
64 
65 #ifndef FCN_MOUSEINPUT_HPP
66 #define FCN_MOUSEINPUT_HPP
67 
68 #include "fifechan/platform.hpp"
69 
70 namespace fcn
71 {
72 
73     /**
74      * Internal class that represents mouse input. Generally you won't have to
75      * bother using this class unless you implement an Input class for
76      * a back end.
77      *
78      * @author Olof Naess�n
79      * @author Per Larsson
80      */
81     class FCN_CORE_DECLSPEC MouseInput
82     {
83     public:
84 
85         /**
86          * Constructor.
87          */
MouseInput()88         MouseInput() { };
89 
90         /**
91          * Constructor.
92          *
93          * @param button The button pressed.
94          * @param type The type of mouse input.
95          * @param x The mouse x coordinate.
96          * @param y The mouse y coordinate.
97          * @param timeStamp The timestamp of the mouse input. Used to
98          *                  check for double clicks.
99          */
100         MouseInput(unsigned int button,
101                    unsigned int type,
102                    int x,
103                    int y,
104                    int timeStamp);
105 
106         /**
107          * Sets the type of the mouse input.
108          *
109          * @param type The type of the mouse input. Should be a value from the
110          *             mouse event type enum
111          * @see getType
112          */
113         void setType(unsigned int type);
114 
115         /**
116          * Gets the type of the mouse input.
117          *
118          * @return The type of the mouse input. A value from the mouse event
119          *         type enum.
120          * @see setType
121          */
122         unsigned int getType() const;
123 
124         /**
125          * Sets the button pressed.
126          *
127          * @param button The button pressed. Should be one of the values
128          *               in the mouse event button enum.
129          * @see getButton.
130          */
131         void setButton(unsigned int button);
132 
133         /**
134          * Gets the button pressed.
135          *
136          * @return The button pressed. A value from the mouse event
137          *         button enum.
138          * @see setButton
139          */
140         unsigned int getButton() const;
141 
142         /**
143          * Sets the timestamp for the mouse input.
144          * Used to check for double clicks.
145          *
146          * @param timeStamp The timestamp of the mouse input.
147          * @see getTimeStamp
148          */
149         void setTimeStamp(int timeStamp);
150 
151         /**
152          * Gets the time stamp of the input.
153          * Used to check for double clicks.
154          *
155          * @return The time stamp of the mouse input.
156          * @see setTimeStamp
157          */
158         int getTimeStamp() const;
159 
160         /**
161          * Sets the x coordinate of the mouse input.
162          *
163          * @param x The x coordinate of the mouse input.
164          * @see getX
165          */
166         void setX(int x);
167 
168         /**
169          * Gets the x coordinate of the mouse input.
170          *
171          * @return The x coordinate of the mouse input.
172          * @see setX
173          */
174         int getX() const;
175 
176         /**
177          * Sets the y coordinate of the mouse input.
178          *
179          * @param y The y coordinate of the mouse input.
180          * @see getY
181          */
182         void setY(int y);
183 
184         /**
185          * Gets the y coordinate of the mouse input.
186          *
187          * @return The y coordinate of the mouse input.
188          * @see setY
189          */
190         int getY() const;
191 
192         /**
193          * Mouse input event types. This enum partially corresponds
194          * to the enum with event types in MouseEvent for easy mapping.
195          */
196         enum
197         {
198             Moved = 0,
199             Pressed,
200             Released,
201             WheelMovedDown,
202             WheelMovedUp,
203             WheelMovedRight,
204             WheelMovedLeft
205         };
206 
207         /**
208          * Mouse button types.
209          */
210         enum {
211             Empty = 0,
212             Left,
213             Right,
214             Middle,
215             X1,
216             X2
217         };
218 
219     protected:
220         /**
221          * Holds the type of the mouse input.
222          */
223         unsigned int mType;
224 
225         /**
226          * Holds the button of the mouse input.
227          */
228         unsigned int mButton;
229 
230         /**
231          * Holds the timestamp of the mouse input. Used to
232          * check for double clicks.
233          */
234         int mTimeStamp;
235 
236         /**
237          * Holds the x coordinate of the mouse input.
238          */
239         int mX;
240 
241         /**
242          * Holds the y coordinate of the mouse input.
243          */
244         int mY;
245     };
246 }
247 
248 #endif // end FCN_MOUSEINPUT_HPP
249