GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/events/mouseevent.h Lines: 0 10 0.0 %
Date: 2017-11-29 Branches: 0 0 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2011-2017  The ManaPlus Developers
4
 *
5
 *  This file is part of The ManaPlus Client.
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  any later version.
11
 *
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *  GNU General Public License for more details.
16
 *
17
 *  You should have received a copy of the GNU General Public License
18
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
/*      _______   __   __   __   ______   __   __   _______   __   __
22
 *     / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___  /\ /  |\/ /\
23
 *    / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
24
 *   / / /__   / / // / // / // / /    / ___  / // ___  / // /| ' / /
25
 *  / /_// /\ / /_// / // / // /_/_   / / // / // /\_/ / // / |  / /
26
 * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
27
 * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
28
 *
29
 * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
30
 *
31
 *
32
 * Per Larsson a.k.a finalman
33
 * Olof Naessén a.k.a jansem/yakslem
34
 *
35
 * Visit: http://guichan.sourceforge.net
36
 *
37
 * License: (BSD)
38
 * Redistribution and use in source and binary forms, with or without
39
 * modification, are permitted provided that the following conditions
40
 * are met:
41
 * 1. Redistributions of source code must retain the above copyright
42
 *    notice, this list of conditions and the following disclaimer.
43
 * 2. Redistributions in binary form must reproduce the above copyright
44
 *    notice, this list of conditions and the following disclaimer in
45
 *    the documentation and/or other materials provided with the
46
 *    distribution.
47
 * 3. Neither the name of Guichan nor the names of its contributors may
48
 *    be used to endorse or promote products derived from this software
49
 *    without specific prior written permission.
50
 *
51
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
52
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
53
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
54
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
55
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
56
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
57
 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
58
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
59
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
60
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
61
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62
 */
63
64
#ifndef EVENTS_MOUSEEVENT_H
65
#define EVENTS_MOUSEEVENT_H
66
67
#include "events/inputguievent.h"
68
69
#include "enums/events/mousebutton.h"
70
#include "enums/events/mouseeventtype.h"
71
72
class Widget;
73
74
/**
75
  * Represents a mouse event.
76
  *
77
  * @author Olof Naessén
78
  */
79
class MouseEvent: public InputGuiEvent
80
{
81
    public:
82
        /**
83
          * Constructor.
84
          *
85
          * @param source The source widget of the mouse event.
86
          * @param type The type of the mouse event.
87
          * @param button The button of the mouse event.
88
          * @param x The x coordinate of the event relative to the source widget.
89
          * @param y The y coordinate of the event relative the source widget.
90
          * @param clickCount The number of clicks generated with the same button.
91
          *                   It's set to zero if another button is used.
92
          */
93
        MouseEvent(Widget *const source,
94
                   const MouseEventTypeT type,
95
                   const MouseButtonT button,
96
                   const int x,
97
                   const int y,
98
                   const int clickCount) :
99
            InputGuiEvent(source),
100
            mType(type),
101
            mButton(button),
102
            mX(x),
103
            mY(y),
104
            mClickCount(clickCount)
105
        {
106
        }
107
108
        /**
109
          * Gets the button of the mouse event.
110
          *
111
          * @return The button of the mouse event.
112
          */
113
        MouseButtonT getButton() const noexcept2 A_WARN_UNUSED
114
        { return mButton; }
115
116
        /**
117
          * Gets the x coordinate of the mouse event.
118
          * The coordinate relative to widget the mouse listener
119
          * receiving the events have registered to.
120
          *
121
          * @return The x coordinate of the mouse event.
122
          * @see Widget::addMouseListener, Widget::removeMouseListener
123
          */
124
        int getX() const noexcept2 A_WARN_UNUSED
125
        { return mX; }
126
127
        /**
128
          * Gets the y coordinate of the mouse event.
129
          * The coordinate relative to widget the mouse listener
130
          * receiving the events have registered to.
131
          *
132
          * @return The y coordinate of the mouse event.
133
          * @see Widget::addMouseListener, Widget::removeMouseListener
134
          */
135
        int getY() const noexcept2 A_WARN_UNUSED
136
        { return mY; }
137
138
        /**
139
          * Gets the number of clicks generated with the same button.
140
          * It's set to zero if another button is used.
141
          *
142
          * @return The number of clicks generated with the same button.
143
          */
144
        int getClickCount() const noexcept2 A_WARN_UNUSED
145
        { return mClickCount; }
146
147
        /**
148
          * Gets the type of the event.
149
          *
150
          * @return The type of the event.
151
          */
152
        MouseEventTypeT getType() const noexcept2 A_WARN_UNUSED
153
        { return mType; }
154
155
        void setX(int n)
156
        { mX = n; }
157
158
        void setY(int n)
159
        { mY = n; }
160
161
    protected:
162
        /**
163
          * Holds the type of the mouse event.
164
          */
165
        MouseEventTypeT mType;
166
167
        /**
168
          * Holds the button of the mouse event.
169
          */
170
        MouseButtonT mButton;
171
172
        /**
173
          * Holds the x-coordinate of the mouse event.
174
          */
175
        int mX;
176
177
        /**
178
          * Holds the y-coordinate of the mouse event.
179
          */
180
        int mY;
181
182
        /**
183
          * The number of clicks generated with the same button.
184
          * It's set to zero if another button is used.
185
          */
186
        int mClickCount;
187
188
        /**
189
          * Gui is a friend of this class in order to be able to manipulate
190
          * the protected member variables of this class and at the same time
191
          * keep the MouseEvent class as const as possible. Gui needs to
192
          * update the x och y coordinates for the coordinates to be relative
193
          * to widget the mouse listener receiving the events have registered
194
          * to.
195
          */
196
        friend class Gui;
197
};
198
199
#endif  // EVENTS_MOUSEEVENT_H