Debian Codegraph @

source/code/TextManager.hpp

raw symbols SCIP
1 /*
2 ===========================================================================
3 blockattack - Block Attack - Rise of the Blocks
4 Copyright (C) 2005-2017 Poul Sander
5
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 2 of the License, or
9 (at your option) any later version.
10
11 This program 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
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see http://www.gnu.org/licenses/
18
19 Source information and contacts persons can be found at
20 https://blockattack.net
21 ===========================================================================
22 */
23
24 #ifndef TEXTMANAGER_HPP
25 #define TEXTMANAGER_HPP
26
27 #include <string>
28 #include <array>
29
30 class TextMessage {
31 private:
32 int x = 0;
33 int y = 0;
34 unsigned int textt = 0;
35 unsigned long int time = 0;
36 unsigned long int placeTime = 0; //Then the text was placed
37 public:
38 bool inUse = false;
39
40 TextMessage() {
41 }
42
43 //constructor:
44 TextMessage(int X, int Y,unsigned int Text,unsigned int Time) {
45 placeTime = SDL_GetTicks();
46 x = X;
47 y = Y;
48 textt = Text;
49 time = Time;
50 } //constructor
51
52 //true if the text has expired
53 bool removeMe() {
54 return SDL_GetTicks()-placeTime>time;
55 }
56
57 int getX() {
58 return x;
59 }
60
61 int getY() {
62 return y;
63 }
64
65 unsigned int getText() {
66 return textt;
67 }
68 }; //text popup
69
70 class TextManager {
71 static const int maxNumberOfTexts = 6*12*2*2;
72 public:
73 std::array<TextMessage, maxNumberOfTexts> textArray;
74
75 TextManager() {
76 }
77
78 int addText(int x, int y, unsigned int Text, unsigned int Time) {
79 size_t textNumber = 0;
80 while (textNumber<textArray.size() && textArray[textNumber].inUse) {
81 textNumber++;
82 }
83 if (textNumber==textArray.size()) {
84 return -1;
85 }
86 textArray[textNumber] = TextMessage(x,y,Text,Time);
87 textArray[textNumber].inUse = true;
88 return 1;
89 } //addText
90
91 void update() {
92 for (size_t i = 0; i<textArray.size(); i++) {
93
94 if (textArray[i].inUse) {
95 if (textArray[i].removeMe()) {
96 textArray[i].inUse = false;
97 }
98 }
99 }
100 } //update
101
102
103 }; //textManager
104
105 #endif /* TEXTMANAGER_HPP */
106