2011-01-02 01:48:38 +02:00
|
|
|
/*
|
2014-05-25 02:00:14 +03:00
|
|
|
* The ManaPlus Client
|
2011-01-02 01:48:38 +02:00
|
|
|
* Copyright (C) 2008 Douglas Boffey <DougABoffey@netscape.net>
|
|
|
|
|
* Copyright (C) 2008-2009 The Mana World Development Team
|
|
|
|
|
* Copyright (C) 2009-2010 The Mana Developers
|
2024-02-09 13:36:22 +00:00
|
|
|
* Copyright (C) 2011-2020 The ManaPlus Developers
|
|
|
|
|
* Copyright (C) 2020-2023 The ManaVerse Developers
|
2011-01-02 01:48:38 +02:00
|
|
|
*
|
2011-02-19 01:13:26 +02:00
|
|
|
* This file is part of The ManaPlus Client.
|
2011-01-02 01:48:38 +02:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "text.h"
|
|
|
|
|
|
|
|
|
|
#include "configuration.h"
|
|
|
|
|
#include "textmanager.h"
|
|
|
|
|
|
|
|
|
|
#include "gui/gui.h"
|
2012-12-27 15:58:18 +03:00
|
|
|
#include "gui/theme.h"
|
2011-01-02 01:48:38 +02:00
|
|
|
|
2014-05-17 18:31:23 +03:00
|
|
|
#include "gui/fonts/font.h"
|
|
|
|
|
|
2014-05-19 22:50:16 +03:00
|
|
|
#include "resources/imagerect.h"
|
2011-01-02 01:48:38 +02:00
|
|
|
|
2016-06-07 15:41:00 +03:00
|
|
|
#include "resources/image/image.h"
|
|
|
|
|
|
2014-03-28 00:39:12 +03:00
|
|
|
#include "utils/delete2.h"
|
|
|
|
|
|
2011-05-24 00:38:44 +03:00
|
|
|
#include "debug.h"
|
|
|
|
|
|
2011-01-02 01:48:38 +02:00
|
|
|
int Text::mInstances = 0;
|
|
|
|
|
ImageRect Text::mBubble;
|
|
|
|
|
|
2015-05-27 21:29:06 +03:00
|
|
|
Text::Text(const std::string &text,
|
|
|
|
|
const int x, const int y,
|
2014-02-15 20:31:52 +03:00
|
|
|
const Graphics::Alignment alignment,
|
2015-05-27 21:29:06 +03:00
|
|
|
const Color *const color,
|
|
|
|
|
const Speech isSpeech,
|
2014-02-16 22:17:22 +03:00
|
|
|
Font *const font) :
|
2017-06-06 23:34:34 +03:00
|
|
|
mFont(font != nullptr ?
|
|
|
|
|
font : (gui != nullptr ? gui->getFont() : nullptr)),
|
2015-05-26 14:38:25 +03:00
|
|
|
mTextChunk(),
|
2013-04-20 16:40:24 +03:00
|
|
|
mX(x),
|
2012-09-08 00:17:45 +03:00
|
|
|
mY(y),
|
2017-06-06 23:34:34 +03:00
|
|
|
mWidth(mFont != nullptr ? mFont->getWidth(text) : 1),
|
|
|
|
|
mHeight(mFont != nullptr ? mFont->getHeight() : 1),
|
2013-04-20 16:40:24 +03:00
|
|
|
mXOffset(0),
|
2011-01-02 01:48:38 +02:00
|
|
|
mText(text),
|
|
|
|
|
mColor(color),
|
2017-06-06 23:34:34 +03:00
|
|
|
mOutlineColor(color != nullptr ? (isSpeech == Speech_true ?
|
2015-06-26 00:41:35 +03:00
|
|
|
*color : theme->getColor(ThemeColorId::OUTLINE, 255)) : Color()),
|
2015-05-26 14:38:25 +03:00
|
|
|
mIsSpeech(isSpeech),
|
|
|
|
|
mTextChanged(true)
|
2011-01-02 01:48:38 +02:00
|
|
|
{
|
2017-06-06 23:34:34 +03:00
|
|
|
if (textManager == nullptr)
|
2011-01-02 01:48:38 +02:00
|
|
|
{
|
|
|
|
|
textManager = new TextManager;
|
2017-06-06 23:34:34 +03:00
|
|
|
if (theme != nullptr)
|
2011-01-02 01:48:38 +02:00
|
|
|
{
|
2017-12-27 03:30:58 +03:00
|
|
|
theme->loadRect(mBubble,
|
|
|
|
|
"bubble.xml",
|
|
|
|
|
"",
|
|
|
|
|
0,
|
|
|
|
|
8);
|
2011-01-02 01:48:38 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (int f = 0; f < 9; f ++)
|
2011-11-08 00:44:17 +03:00
|
|
|
mBubble.grid[f] = nullptr;
|
2011-01-02 01:48:38 +02:00
|
|
|
}
|
2012-07-15 00:37:34 +03:00
|
|
|
|
2011-01-02 01:48:38 +02:00
|
|
|
const float bubbleAlpha = config.getFloatValue("speechBubbleAlpha");
|
|
|
|
|
for (int i = 0; i < 9; i++)
|
|
|
|
|
{
|
2017-06-06 23:34:34 +03:00
|
|
|
if (mBubble.grid[i] != nullptr)
|
2011-01-02 01:48:38 +02:00
|
|
|
mBubble.grid[i]->setAlpha(bubbleAlpha);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
++mInstances;
|
|
|
|
|
|
|
|
|
|
switch (alignment)
|
|
|
|
|
{
|
2014-02-15 20:31:52 +03:00
|
|
|
case Graphics::LEFT:
|
2011-01-02 01:48:38 +02:00
|
|
|
mXOffset = 0;
|
|
|
|
|
break;
|
2014-02-15 20:31:52 +03:00
|
|
|
case Graphics::CENTER:
|
2011-01-02 01:48:38 +02:00
|
|
|
mXOffset = mWidth / 2;
|
|
|
|
|
break;
|
2014-02-15 20:31:52 +03:00
|
|
|
case Graphics::RIGHT:
|
2011-01-02 01:48:38 +02:00
|
|
|
mXOffset = mWidth;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
mX = x - mXOffset;
|
2017-06-06 23:34:34 +03:00
|
|
|
if (textManager != nullptr)
|
2011-01-02 01:48:38 +02:00
|
|
|
textManager->addText(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Text::~Text()
|
|
|
|
|
{
|
2017-06-06 23:34:34 +03:00
|
|
|
if (textManager != nullptr)
|
2011-01-02 01:48:38 +02:00
|
|
|
textManager->removeText(this);
|
|
|
|
|
if (--mInstances == 0)
|
|
|
|
|
{
|
2018-11-26 00:51:57 +03:00
|
|
|
delete2(textManager)
|
2012-07-15 00:37:34 +03:00
|
|
|
for (int f = 0; f < 9; f ++)
|
|
|
|
|
{
|
2017-06-06 23:34:34 +03:00
|
|
|
if (mBubble.grid[f] != nullptr)
|
2012-07-15 00:37:34 +03:00
|
|
|
{
|
|
|
|
|
mBubble.grid[f]->decRef();
|
|
|
|
|
mBubble.grid[f] = nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-01-02 01:48:38 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-22 14:21:27 +03:00
|
|
|
void Text::setColor(const Color *const color)
|
2011-01-02 01:48:38 +02:00
|
|
|
{
|
2015-05-26 14:38:25 +03:00
|
|
|
mTextChanged = true;
|
2015-05-27 21:29:06 +03:00
|
|
|
if (mIsSpeech == Speech_true)
|
2015-05-26 13:23:21 +03:00
|
|
|
{
|
|
|
|
|
mColor = color;
|
2015-05-26 14:38:25 +03:00
|
|
|
mOutlineColor = *color;
|
2015-05-26 13:23:21 +03:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
mColor = color;
|
|
|
|
|
}
|
2011-01-02 01:48:38 +02:00
|
|
|
}
|
|
|
|
|
|
2015-05-27 21:39:10 +03:00
|
|
|
void Text::adviseXY(const int x, const int y,
|
|
|
|
|
const Move move)
|
2011-01-02 01:48:38 +02:00
|
|
|
{
|
2017-06-06 23:34:34 +03:00
|
|
|
if ((textManager != nullptr) && move == Move_true)
|
2013-03-31 14:18:08 +03:00
|
|
|
{
|
2011-01-02 01:48:38 +02:00
|
|
|
textManager->moveText(this, x - mXOffset, y);
|
2013-03-31 14:18:08 +03:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
mX = x - mXOffset;
|
|
|
|
|
mY = y;
|
|
|
|
|
}
|
2011-01-02 01:48:38 +02:00
|
|
|
}
|
|
|
|
|
|
2012-12-27 15:58:18 +03:00
|
|
|
void Text::draw(Graphics *const graphics, const int xOff, const int yOff)
|
2011-01-02 01:48:38 +02:00
|
|
|
{
|
2012-11-06 21:13:16 +03:00
|
|
|
BLOCK_START("Text::draw")
|
2015-05-27 21:29:06 +03:00
|
|
|
if (mIsSpeech == Speech_true)
|
2011-01-02 01:48:38 +02:00
|
|
|
{
|
2014-02-15 22:21:02 +03:00
|
|
|
graphics->drawImageRect(mX - xOff - 5,
|
|
|
|
|
mY - yOff - 5,
|
|
|
|
|
mWidth + 10,
|
|
|
|
|
mHeight + 10,
|
|
|
|
|
mBubble);
|
2011-01-02 01:48:38 +02:00
|
|
|
}
|
|
|
|
|
|
2015-05-26 14:38:25 +03:00
|
|
|
if (mTextChanged)
|
|
|
|
|
{
|
|
|
|
|
mTextChunk.textFont = mFont;
|
|
|
|
|
mTextChunk.deleteImage();
|
|
|
|
|
mTextChunk.text = mText;
|
|
|
|
|
mTextChunk.color = *mColor;
|
|
|
|
|
mTextChunk.color2 = mOutlineColor;
|
|
|
|
|
mFont->generate(mTextChunk);
|
|
|
|
|
mTextChanged = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const Image *const image = mTextChunk.img;
|
2017-06-06 23:34:34 +03:00
|
|
|
if (image != nullptr)
|
2015-05-26 14:38:25 +03:00
|
|
|
graphics->drawImage(image, mX - xOff, mY - yOff);
|
|
|
|
|
|
2012-11-06 21:13:16 +03:00
|
|
|
BLOCK_END("Text::draw")
|
2011-01-02 01:48:38 +02:00
|
|
|
}
|
|
|
|
|
|
2015-05-26 13:23:21 +03:00
|
|
|
FlashText::FlashText(const std::string &text,
|
|
|
|
|
const int x, const int y,
|
2014-02-15 20:31:52 +03:00
|
|
|
const Graphics::Alignment alignment,
|
2015-05-26 13:23:21 +03:00
|
|
|
const Color *const color,
|
|
|
|
|
Font *const font) :
|
2015-05-27 21:29:06 +03:00
|
|
|
Text(text, x, y, alignment, color, Speech_false, font),
|
2011-01-02 01:48:38 +02:00
|
|
|
mTime(0)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-27 15:58:18 +03:00
|
|
|
void FlashText::draw(Graphics *const graphics, const int xOff, const int yOff)
|
2011-01-02 01:48:38 +02:00
|
|
|
{
|
2012-11-06 21:13:16 +03:00
|
|
|
BLOCK_START("FlashText::draw")
|
2017-06-06 23:34:34 +03:00
|
|
|
if (mTime != 0)
|
2011-01-02 01:48:38 +02:00
|
|
|
{
|
|
|
|
|
if ((--mTime & 4) == 0)
|
2012-11-06 21:13:16 +03:00
|
|
|
{
|
|
|
|
|
BLOCK_END("FlashText::draw")
|
2011-01-02 01:48:38 +02:00
|
|
|
return;
|
2012-11-06 21:13:16 +03:00
|
|
|
}
|
2011-01-02 01:48:38 +02:00
|
|
|
}
|
|
|
|
|
Text::draw(graphics, xOff, yOff);
|
2012-11-06 21:13:16 +03:00
|
|
|
BLOCK_END("FlashText::draw")
|
2011-01-02 01:48:38 +02:00
|
|
|
}
|