1 /* GemRB - Infinity Engine Emulator
2 * Copyright (C) 2003-2020 The GemRB Project
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 *
18 *
19 */
20
21 #include "DPadSoftKeyboard.h"
22
23 using namespace GemRB;
24
StartInput()25 void DPadSoftKeyboard::StartInput()
26 {
27 inputActive = true;
28 emptyInput = true;
29 currentUpper = true;
30 currentCharIndex = 0;
31 inputIndexes.clear();
32 }
33
StopInput()34 void DPadSoftKeyboard::StopInput()
35 {
36 inputActive = false;
37 }
38
IsInputActive() const39 bool DPadSoftKeyboard::IsInputActive() const
40 {
41 return inputActive;
42 }
43
GetTextEvent() const44 Event DPadSoftKeyboard::GetTextEvent() const
45 {
46 char modKeyValue = dpadKeys[currentCharIndex];
47
48 if (currentUpper && dpadKeys[currentCharIndex] >= 97 && dpadKeys[currentCharIndex] <= 122) {
49 modKeyValue -= 32;
50 }
51
52 char string[2] = { modKeyValue, '\0' };
53 return EventMgr::CreateTextEvent(string);
54 }
55
ToggleUppercase()56 void DPadSoftKeyboard::ToggleUppercase()
57 {
58 if (emptyInput) {
59 emptyInput = false;
60 }
61
62 if (dpadKeys[currentCharIndex] >= 97 && dpadKeys[currentCharIndex] <= 122) {
63 currentUpper = !currentUpper;
64 }
65 }
66
RemoveCharacter()67 void DPadSoftKeyboard::RemoveCharacter()
68 {
69 if (inputIndexes.empty()) {
70 emptyInput = true;
71 currentUpper = true;
72 currentCharIndex = 0;
73 } else {
74 currentCharIndex = inputIndexes.back();
75 inputIndexes.pop_back();
76 if (inputIndexes.empty()) {
77 currentUpper = true;
78 }
79 }
80 }
81
AddCharacter()82 void DPadSoftKeyboard::AddCharacter()
83 {
84 if (emptyInput) {
85 emptyInput = false;
86 } else {
87 currentUpper = false;
88 inputIndexes.push_back(currentCharIndex);
89 currentCharIndex = 0;
90 }
91 }
92
NextCharacter()93 void DPadSoftKeyboard::NextCharacter()
94 {
95 if (emptyInput) {
96 emptyInput = false;
97 } else {
98 ++currentCharIndex;
99 if (currentCharIndex >= TOTAL_CHARACTERS_DPAD) {
100 currentCharIndex = 0;
101 }
102 }
103 }
104
PreviousCharacter()105 void DPadSoftKeyboard::PreviousCharacter()
106 {
107 if (emptyInput) {
108 emptyInput = false;
109 } else {
110 --currentCharIndex;
111 if (currentCharIndex < 0) {
112 currentCharIndex = TOTAL_CHARACTERS_DPAD - 1;
113 }
114 }
115 }
116