Debian Codegraph @

src/game/messageoverlay.hpp

raw symbols SCIP
1 // This file is part of Dust Racing 2D.
2 // Copyright (C) 2012 Jussi Lind <[email protected]>
3 //
4 // Dust Racing 2D is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 // Dust Racing 2D is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with Dust Racing 2D. If not, see <http://www.gnu.org/licenses/>.
15
16 #ifndef MESSAGEOVERLAY_HPP
17 #define MESSAGEOVERLAY_HPP
18
19 #include "overlaybase.hpp"
20
21 #include <MCTextureText>
22 #include <QObject>
23 #include <QString>
24 #include <list>
25
26 class MCTextureFontManager;
27 class MCTextureFont;
28
29 //! A class that draws the radar, texts and displays messages.
30 class MessageOverlay : public QObject, public OverlayBase
31 {
32 Q_OBJECT
33
34 public:
35 //! Alignment of the MessageOverlay messages.
36 enum class Alignment
37 {
38 Top,
39 Bottom
40 };
41
42 //! Constructor.
43 MessageOverlay(Alignment align = Alignment::Bottom, size_t messageMaxTime = 180);
44
45 //! \reimp
46 virtual void render() override;
47
48 //! \reimp
49 virtual bool update() override;
50
51 public slots:
52
53 //! Add a message to the MessageOverlay.
54 void addMessage(const std::wstring & msg);
55
56 //! Add a message to the MessageOverlay.
57 void addMessage(QString msg);
58
59 //! Add a message to the MessageOverlay.
60 void addMessage(const wchar_t * msg);
61
62 private:
63 //! Render messages.
64 void renderMessages();
65
66 //! MessageOverlay message struct.
67 struct Message
68 {
69 //! Time the message has been shown
70 size_t timeShown = 0;
71
72 //! The time after which message will be deleted
73 size_t maxTime = 0;
74
75 //! Current y
76 float y = 0;
77
78 //! Target y
79 float targetY = 0;
80
81 //! Message
82 std::wstring text;
83
84 //! True, if y is initialized
85 bool isYInitialized = false;
86
87 bool isRemoving = false;
88 };
89
90 MCTextureFontManager & m_fontManager;
91
92 MCTextureFont & m_font;
93
94 MCTextureText m_text;
95
96 size_t m_messageMaxTime;
97
98 Alignment m_align;
99
100 std::list<Message> m_listMessages;
101 };
102
103 #endif // MESSAGEOVERLAY_HPP