1
/*
2
 *  Support for non-overlapping floating text
3
 *  Copyright (C) 2008  Douglas Boffey <DougABoffey@netscape.net>
4
 *  Copyright (C) 2008  The Mana World Development Team
5
 *
6
 *  This file is part of The Mana World.
7
 *
8
 *  This program is free software; you can redistribute it and/or modify
9
 *  it under the terms of the GNU General Public License as published by
10
 *  the Free Software Foundation; either version 2 of the License, or
11
 *  any later version.
12
 *
13
 *  This program is distributed in the hope that it will be useful,
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 *  GNU General Public License for more details.
17
 *
18
 *  You should have received a copy of the GNU General Public License
19
 *  along with this program; if not, write to the Free Software
20
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21
 */
22
23
#ifndef TEXT_H
24
#define TEXT_H
25
26
#include <guichan/color.hpp>
27
28
#include "graphics.h"
29
#include "guichanfwd.h"
30
31
class TextManager;
32
33
class Text
34
{
35
    friend class TextManager;
36
37
    public:
38
        /**
39
         * Constructor creates a text object to display on the screen.
40
         */
41
        Text(const std::string &text, int x, int y,
42
             gcn::Graphics::Alignment alignment,
43
             const gcn::Color *color, bool isSpeech = false);
44
45
        /**
46
         * Destructor. The text is removed from the screen.
47
         */
48
        virtual ~Text();
49
50
        void setColor(const gcn::Color *color);
51
52
        int getWidth() const { return mWidth; }
53
        int getHeight() const { return mHeight; }
54
55
        /**
56
         * Allows the originator of the text to specify the ideal coordinates.
57
         */
58
        void adviseXY(int x, int y);
59
60
        /**
61
         * Draws the text.
62
         */
63
        virtual void draw(gcn::Graphics *graphics, int xOff, int yOff);
64
65
    private:
66
        int mX;                /**< Actual x-value of left of text written. */
67
        int mY;                /**< Actual y-value of top of text written. */
68
        int mWidth;            /**< The width of the text. */
69
        int mHeight;           /**< The height of the text. */
70
        int mXOffset;          /**< The offset of mX from the desired x. */
71
        static int mInstances; /**< Instances of text. */
72
        std::string mText;     /**< The text to display. */
73
        const gcn::Color *mColor;     /**< The color of the text. */
74
        gcn::Font *mFont;      /**< The font of the text */
75
        bool mIsSpeech;        /**< Is this text a speech bubble? */
76
77
    protected:
78
        static ImageRect mBubble;   /**< Speech bubble graphic */
79
        static Image *mBubbleArrow; /**< Speech bubble arrow graphic */
80
};
81
82
class FlashText : public Text
83
{
84
    public:
85
        FlashText(const std::string &text, int x, int y,
86
                  gcn::Graphics::Alignment alignment,
87
                  const gcn::Color* color);
88
89
        /**
90
         * Remove the text from the screen
91
         */
92
        virtual ~FlashText() {}
93
94
        /**
95
         * Flash the text for so many refreshes.
96
         */
97
        void flash(int time) {mTime = time; }
98
99
        /**
100
         * Draws the text.
101
         */
102
        virtual void draw(gcn::Graphics *graphics, int xOff, int yOff);
103
104
    private:
105
        int mTime;             /**< Time left for flashing */
106
};
107
108
#endif // TEXT_H