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