Mana
Loading...
Searching...
No Matches
text.h
Go to the documentation of this file.
1/*
2 * Support for non-overlapping floating text
3 * Copyright (C) 2008 Douglas Boffey <DougABoffey@netscape.net>
4 * Copyright (C) 2008-2009 The Mana World Development Team
5 * Copyright (C) 2009-2012 The Mana Developers
6 *
7 * This file is part of The Mana Client.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23#pragma once
24
25#include "utils/time.h"
26
27#include <guichan/color.hpp>
28#include <guichan/font.hpp>
29#include <guichan/graphics.hpp>
30
31class TextManager;
32
33class Text
34{
35 friend class TextManager;
36
37 public:
41 Text(const std::string &text, int x, int y,
42 gcn::Graphics::Alignment alignment,
43 const gcn::Color *color, bool isSpeech = false,
44 gcn::Font *font = nullptr);
45
49 virtual ~Text();
50
51 void setColor(const gcn::Color *color);
52
53 int getWidth() const { return mWidth; }
54 int getHeight() const { return mHeight; }
55
59 void adviseXY(int x, int y);
60
64 virtual void draw(gcn::Graphics *graphics, int xOff, int yOff);
65
66 private:
67 int mX;
68 int mY;
69 int mWidth;
70 int mHeight;
72 static int mInstances;
73 std::string mText;
74 const gcn::Color *mColor;
75 gcn::Font *mFont;
76 bool mIsSpeech;
77};
78
79class FlashText : public Text
80{
81 public:
82 using Text::Text;
83
87 void flash(int time) { mTimer.set(time); }
88
92 void draw(gcn::Graphics *graphics, int xOff, int yOff) override;
93
94 private:
96};
void flash(int time)
Flash the text for so many milliseconds.
Definition text.h:87
Timer mTimer
Time left for flashing.
Definition text.h:95
void draw(gcn::Graphics *graphics, int xOff, int yOff) override
Draws the text.
Definition text.cpp:124
Definition text.h:34
Text(const std::string &text, int x, int y, gcn::Graphics::Alignment alignment, const gcn::Color *color, bool isSpeech=false, gcn::Font *font=nullptr)
Constructor creates a text object to display on the screen.
Definition text.cpp:35
int getHeight() const
Definition text.h:54
int mXOffset
The offset of mX from the desired x.
Definition text.h:71
std::string mText
The text to display.
Definition text.h:73
const gcn::Color * mColor
The color of the text.
Definition text.h:74
virtual ~Text()
Destructor.
Definition text.cpp:74
static int mInstances
Instances of text.
Definition text.h:72
bool mIsSpeech
Is this text a speech bubble?
Definition text.h:76
gcn::Font * mFont
The font of the text.
Definition text.h:75
int mX
Actual x-value of left of text written.
Definition text.h:67
void setColor(const gcn::Color *color)
Definition text.cpp:84
int mWidth
The width of the text.
Definition text.h:69
int mHeight
The height of the text.
Definition text.h:70
int getWidth() const
Definition text.h:53
void adviseXY(int x, int y)
Allows the originator of the text to specify the ideal coordinates.
Definition text.cpp:89
int mY
Actual y-value of top of text written.
Definition text.h:68
virtual void draw(gcn::Graphics *graphics, int xOff, int yOff)
Draws the text.
Definition text.cpp:94
Simple timer that can be used to check if a certain amount of time has passed.
Definition time.h:62
void set(uint32_t ms=0)
Sets the timer with an optional duration in milliseconds.
Definition time.h:69
Graphics * graphics
Definition client.cpp:104