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

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2012-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 INPUT_KEYINPUT_H
65
#define INPUT_KEYINPUT_H
66
67
#include "enums/events/keyeventtype.h"
68
69
#include "enums/input/inputaction.h"
70
71
#include "input/key.h"
72
73
#ifdef USE_SDL2
74
#include <string>
75
#endif  // USE_SDL2
76
77
#include "localconsts.h"
78
79
class KeyInput final
80
{
81
    public:
82
        KeyInput() :
83
            mKey(0),
84
            mType(KeyEventType::PRESSED),
85
#ifdef USE_SDL2
86
            mText(),
87
#endif  // USE_SDL2
88
            mActionId(InputAction::UNDEFINED_VALUE)
89
        { }
90
91
        KeyInput(const KeyInput &k) :
92
            mKey(k.mKey),
93
            mType(k.mType),
94
#ifdef USE_SDL2
95
            mText(k.mText),
96
#endif  // USE_SDL2
97
            mActionId(k.mActionId)
98
        {
99
        }
100
101
        A_DEFAULT_COPY(KeyInput)
102
103
        KeyInput &operator=(const KeyInput &k) noexcept2
104
        {
105
            mKey = k.mKey;
106
            mType = k.mType;
107
#ifdef USE_SDL2
108
            mText = k.mText;
109
#endif  // USE_SDL2
110
            mActionId = k.mActionId;
111
            return *this;
112
        }
113
114
        ~KeyInput()
115
        { }
116
117
        void setType(KeyEventTypeT type) noexcept2
118
        {
119
            mType = type;
120
        }
121
122
        KeyEventTypeT getType() const noexcept2 A_WARN_UNUSED
123
        {
124
            return mType;
125
        }
126
127
        void setKey(const Key& key) noexcept2
128
        {
129
            mKey = key;
130
        }
131
132
        const Key& getKey() const noexcept2
133
        {
134
            return mKey;
135
        }
136
137
        void setActionId(const InputActionT n) noexcept2
138
        {
139
            mActionId = n;
140
        }
141
142
        InputActionT getActionId() const noexcept2 A_WARN_UNUSED
143
        {
144
            return mActionId;
145
        }
146
147
#ifdef USE_SDL2
148
        void setText(const std::string &text) noexcept2
149
        {
150
            mText = text;
151
        }
152
153
        std::string getText() const noexcept2
154
        {
155
            return mText;
156
        }
157
#endif  // USE_SDL2
158
159
    protected:
160
        /**
161
         * Holds the key of the key input.
162
         */
163
        Key mKey;
164
165
        /**
166
         * Holds the type of the key input.
167
         */
168
        KeyEventTypeT mType;
169
170
#ifdef USE_SDL2
171
        std::string mText;
172
#endif  // USE_SDL2
173
174
        InputActionT mActionId;
175
};
176
177
#endif  // INPUT_KEYINPUT_H