GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/events/mouseevent.h Lines: 0 10 0.0 %
Date: 2021-03-17 Branches: 0 0 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2011-2019  The ManaPlus Developers
4
 *  Copyright (C) 2019-2021  Andrei Karas
5
 *
6
 *  This file is part of The ManaPlus Client.
7
 *
8
 *  This program is free software; you can redistribute it and/or modify
9
 *  it under the terms of the GNU General Public License as published by
10
 *  the Free Software Foundation; either version 2 of the License, or
11
 *  any later version.
12
 *
13
 *  This program is distributed in the hope that it will be useful,
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 *  GNU General Public License for more details.
17
 *
18
 *  You should have received a copy of the GNU General Public License
19
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
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 EVENTS_MOUSEEVENT_H
66
#define EVENTS_MOUSEEVENT_H
67
68
#include "events/inputguievent.h"
69
70
#include "enums/events/mousebutton.h"
71
#include "enums/events/mouseeventtype.h"
72
73
class Widget;
74
75
/**
76
  * Represents a mouse event.
77
  *
78
  * @author Olof Naessén
79
  */
80
class MouseEvent final : public InputGuiEvent
81
{
82
    public:
83
        /**
84
          * Constructor.
85
          *
86
          * @param source The source widget of the mouse event.
87
          * @param type The type of the mouse event.
88
          * @param button The button of the mouse event.
89
          * @param x The x coordinate of the event relative to the source widget.
90
          * @param y The y coordinate of the event relative the source widget.
91
          * @param clickCount The number of clicks generated with the same button.
92
          *                   It's set to zero if another button is used.
93
          */
94
        MouseEvent(Widget *const source,
95
                   const MouseEventTypeT type,
96
                   const MouseButtonT button,
97
                   const int x,
98
                   const int y,
99
                   const int clickCount) :
100
            InputGuiEvent(source),
101
            mType(type),
102
            mButton(button),
103
            mX(x),
104
            mY(y),
105
            mClickCount(clickCount)
106
        {
107
        }
108
109
        A_DELETE_COPY(MouseEvent)
110
111
        /**
112
          * Gets the button of the mouse event.
113
          *
114
          * @return The button of the mouse event.
115
          */
116
        MouseButtonT getButton() const noexcept2 A_WARN_UNUSED
117
        { return mButton; }
118
119
        /**
120
          * Gets the x coordinate of the mouse event.
121
          * The coordinate relative to widget the mouse listener
122
          * receiving the events have registered to.
123
          *
124
          * @return The x coordinate of the mouse event.
125
          * @see Widget::addMouseListener, Widget::removeMouseListener
126
          */
127
        int getX() const noexcept2 A_WARN_UNUSED
128
        { return mX; }
129
130
        /**
131
          * Gets the y coordinate of the mouse event.
132
          * The coordinate relative to widget the mouse listener
133
          * receiving the events have registered to.
134
          *
135
          * @return The y coordinate of the mouse event.
136
          * @see Widget::addMouseListener, Widget::removeMouseListener
137
          */
138
        int getY() const noexcept2 A_WARN_UNUSED
139
        { return mY; }
140
141
        /**
142
          * Gets the number of clicks generated with the same button.
143
          * It's set to zero if another button is used.
144
          *
145
          * @return The number of clicks generated with the same button.
146
          */
147
        int getClickCount() const noexcept2 A_WARN_UNUSED
148
        { return mClickCount; }
149
150
        /**
151
          * Gets the type of the event.
152
          *
153
          * @return The type of the event.
154
          */
155
        MouseEventTypeT getType() const noexcept2 A_WARN_UNUSED
156
        { return mType; }
157
158
        void setX(int n)
159
        { mX = n; }
160
161
        void setY(int n)
162
        { mY = n; }
163
164
    protected:
165
        /**
166
          * Holds the type of the mouse event.
167
          */
168
        MouseEventTypeT mType;
169
170
        /**
171
          * Holds the button of the mouse event.
172
          */
173
        MouseButtonT mButton;
174
175
        /**
176
          * Holds the x-coordinate of the mouse event.
177
          */
178
        int mX;
179
180
        /**
181
          * Holds the y-coordinate of the mouse event.
182
          */
183
        int mY;
184
185
        /**
186
          * The number of clicks generated with the same button.
187
          * It's set to zero if another button is used.
188
          */
189
        int mClickCount;
190
191
        /**
192
          * Gui is a friend of this class in order to be able to manipulate
193
          * the protected member variables of this class and at the same time
194
          * keep the MouseEvent class as const as possible. Gui needs to
195
          * update the x och y coordinates for the coordinates to be relative
196
          * to widget the mouse listener receiving the events have registered
197
          * to.
198
          */
199
        friend class Gui;
200
};
201
202
#endif  // EVENTS_MOUSEEVENT_H