GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/text.h Lines: 2 6 33.3 %
Date: 2021-03-17 Branches: 0 0 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2008  Douglas Boffey <[email protected]>
4
 *  Copyright (C) 2008-2009  The Mana World Development Team
5
 *  Copyright (C) 2009-2010  The Mana Developers
6
 *  Copyright (C) 2011-2019  The ManaPlus Developers
7
 *  Copyright (C) 2019-2021  Andrei Karas
8
 *
9
 *  This file is part of The ManaPlus Client.
10
 *
11
 *  This program is free software; you can redistribute it and/or modify
12
 *  it under the terms of the GNU General Public License as published by
13
 *  the Free Software Foundation; either version 2 of the License, or
14
 *  any later version.
15
 *
16
 *  This program is distributed in the hope that it will be useful,
17
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 *  GNU General Public License for more details.
20
 *
21
 *  You should have received a copy of the GNU General Public License
22
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 */
24
25
#ifndef TEXT_H
26
#define TEXT_H
27
28
#include "enums/simpletypes/move.h"
29
#include "enums/simpletypes/speech.h"
30
31
#include "gui/fonts/textchunk.h"
32
33
#include "render/graphics.h"
34
35
#include "localconsts.h"
36
37
class Font;
38
39
class Text notfinal
40
{
41
    friend class TextManager;
42
43
    public:
44
        /**
45
         * Constructor creates a text object to display on the screen.
46
         */
47
        Text(const std::string &text,
48
             const int x, const int y,
49
             const Graphics::Alignment alignment,
50
             const Color *const color,
51
             const Speech isSpeech,
52
             Font *const font);
53
54
        A_DELETE_COPY(Text)
55
56
        /**
57
         * Destructor. The text is removed from the screen.
58
         */
59
        virtual ~Text();
60
61
        void setColor(const Color *const color);
62
63
        int getWidth() const noexcept2 A_WARN_UNUSED
64
        { return mWidth; }
65
66
        int getHeight() const noexcept2 A_WARN_UNUSED
67
1
        { return mHeight; }
68
69
        /**
70
         * Allows the originator of the text to specify the ideal coordinates.
71
         */
72
        void adviseXY(const int x, const int y, const Move move);
73
74
        /**
75
         * Draws the text.
76
         */
77
        virtual void draw(Graphics *const graphics,
78
                          const int xOff, const int yOff) A_NONNULL(2);
79
80
//        int getWidth() A_WARN_UNUSED;
81
82
        int getX() const noexcept2 A_WARN_UNUSED
83
        { return mX; }
84
85
        int getY() const noexcept2 A_WARN_UNUSED
86
        { return mY; }
87
88
    private:
89
        Font *mFont;           /**< The font of the text */
90
        TextChunk mTextChunk;
91
        int mX;                /**< Actual x-value of left of text written. */
92
        int mY;                /**< Actual y-value of top of text written. */
93
        int mWidth;            /**< The width of the text. */
94
        int mHeight;           /**< The height of the text. */
95
        int mXOffset;          /**< The offset of mX from the desired x. */
96
        static int mInstances; /**< Instances of text. */
97
        std::string mText;     /**< The text to display. */
98
        const Color *mColor;   /**< The color of the text. */
99
        Color mOutlineColor;
100
        Speech mIsSpeech;      /**< Is this text a speech bubble? */
101
        bool mTextChanged;
102
103
    protected:
104
        static ImageRect mBubble;   /**< Speech bubble graphic */
105
};
106
107
9
class FlashText final : public Text
108
{
109
    public:
110
        FlashText(const std::string &text, const int x, const int y,
111
                  const Graphics::Alignment alignment,
112
                  const Color *const color,
113
                  Font *const font);
114
115
        A_DELETE_COPY(FlashText)
116
117
        /**
118
         * Flash the text for so many refreshes.
119
         */
120
        void flash(const int time)
121
        { mTime = time; }
122
123
        /**
124
         * Draws the text.
125
         */
126
        void draw(Graphics *const graphics,
127
                  const int xOff,
128
                  const int yOff) override final A_NONNULL(2);
129
130
    private:
131
        int mTime;             /**< Time left for flashing */
132
};
133
134
#endif  // TEXT_H