2009-05-20 13:08:56 +03:00
|
|
|
#include "../stdafx.h"
|
2007-06-12 12:33:20 +03:00
|
|
|
#include "CMessage.h"
|
2008-08-02 18:08:03 +03:00
|
|
|
#include "SDL_ttf.h"
|
2010-12-20 23:22:53 +02:00
|
|
|
#include "CDefHandler.h"
|
2010-11-15 17:15:00 +02:00
|
|
|
#include "CAnimation.h"
|
2007-07-11 15:08:42 +03:00
|
|
|
#include "CGameInfo.h"
|
2007-07-12 14:41:31 +03:00
|
|
|
#include "SDL_Extensions.h"
|
2010-12-20 23:22:53 +02:00
|
|
|
#include "../lib/CLodHandler.h"
|
2007-10-13 23:31:50 +03:00
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
#include <boost/algorithm/string/replace.hpp>
|
|
|
|
#include <sstream>
|
2010-12-20 23:22:53 +02:00
|
|
|
#include "../lib/CGeneralTextHandler.h"
|
2009-05-20 13:08:56 +03:00
|
|
|
#include "Graphics.h"
|
|
|
|
#include "GUIClasses.h"
|
2009-05-19 21:23:04 +03:00
|
|
|
#include "AdventureMapButton.h"
|
2009-06-02 05:15:23 +03:00
|
|
|
#include "CConfigHandler.h"
|
2010-08-17 18:16:08 +03:00
|
|
|
#include "CBitmapHandler.h"
|
2009-04-15 17:03:31 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* CMessage.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-08-17 11:50:31 +03:00
|
|
|
SDL_Color tytulowy = {229, 215, 123, 0},
|
|
|
|
tlo = {66, 44, 24, 0},
|
2011-03-03 20:25:48 +02:00
|
|
|
zwykly = {255, 243, 222, 0},
|
2009-10-03 13:51:05 +03:00
|
|
|
darkTitle = {215, 175, 78, 0};
|
2007-06-19 18:25:42 +03:00
|
|
|
|
2008-04-25 12:25:59 +03:00
|
|
|
extern SDL_Surface * screen;
|
2007-07-28 12:44:10 +03:00
|
|
|
|
2007-07-29 02:01:25 +03:00
|
|
|
using namespace NMessage;
|
2009-03-27 01:05:40 +02:00
|
|
|
|
|
|
|
const int COMPONENT_TO_SUBTITLE = 5;
|
|
|
|
const int BETWEEN_COMPS_ROWS = 10;
|
|
|
|
const int BEFORE_COMPONENTS = 30;
|
2009-06-02 05:15:23 +03:00
|
|
|
const int SIDE_MARGIN = 30;
|
2009-03-27 01:05:40 +02:00
|
|
|
|
2007-12-27 02:11:46 +02:00
|
|
|
template <typename T, typename U> std::pair<T,U> max(const std::pair<T,U> &x, const std::pair<T,U> &y)
|
|
|
|
{
|
|
|
|
std::pair<T,U> ret;
|
|
|
|
ret.first = std::max(x.first,y.first);
|
|
|
|
ret.second = std::max(x.second,y.second);
|
|
|
|
return ret;
|
|
|
|
}
|
2007-07-29 02:01:25 +03:00
|
|
|
|
|
|
|
namespace NMessage
|
|
|
|
{
|
2007-11-19 00:58:28 +02:00
|
|
|
CDefHandler * ok, *cancel;
|
2007-07-29 02:01:25 +03:00
|
|
|
std::vector<std::vector<SDL_Surface*> > piecesOfBox; //in colors of all players
|
|
|
|
SDL_Surface * background = NULL;
|
|
|
|
}
|
2007-07-28 12:44:10 +03:00
|
|
|
|
2009-03-27 01:05:40 +02:00
|
|
|
|
2007-07-29 02:01:25 +03:00
|
|
|
void CMessage::init()
|
2007-07-28 12:44:10 +03:00
|
|
|
{
|
2007-07-29 02:01:25 +03:00
|
|
|
{
|
2011-04-23 13:27:44 +03:00
|
|
|
piecesOfBox.resize(PLAYER_LIMIT);
|
2007-07-29 02:01:25 +03:00
|
|
|
for (int i=0;i<PLAYER_LIMIT;i++)
|
|
|
|
{
|
2008-06-12 09:45:51 +03:00
|
|
|
CDefHandler * bluePieces = CDefHandler::giveDef("DIALGBOX.DEF");
|
2007-07-29 02:01:25 +03:00
|
|
|
if (i==1)
|
|
|
|
{
|
2008-12-21 21:17:35 +02:00
|
|
|
for (size_t j=0;j<bluePieces->ourImages.size();++j)
|
2007-07-29 02:01:25 +03:00
|
|
|
{
|
|
|
|
piecesOfBox[i].push_back(bluePieces->ourImages[j].bitmap);
|
2011-04-23 13:27:44 +03:00
|
|
|
bluePieces->ourImages[j].bitmap->refcount++;
|
2007-07-29 02:01:25 +03:00
|
|
|
}
|
|
|
|
}
|
2008-12-21 21:17:35 +02:00
|
|
|
for (size_t j=0;j<bluePieces->ourImages.size();++j)
|
2007-07-29 02:01:25 +03:00
|
|
|
{
|
2008-06-30 03:06:41 +03:00
|
|
|
graphics->blueToPlayersAdv(bluePieces->ourImages[j].bitmap,i);
|
2007-07-29 02:01:25 +03:00
|
|
|
piecesOfBox[i].push_back(bluePieces->ourImages[j].bitmap);
|
2011-04-23 13:27:44 +03:00
|
|
|
bluePieces->ourImages[j].bitmap->refcount++;
|
2007-07-29 02:01:25 +03:00
|
|
|
}
|
2011-04-23 13:27:44 +03:00
|
|
|
delete bluePieces;
|
2007-07-29 02:01:25 +03:00
|
|
|
}
|
2008-06-12 09:45:51 +03:00
|
|
|
NMessage::background = BitmapHandler::loadBitmap("DIBOXBCK.BMP");
|
2007-07-29 02:01:25 +03:00
|
|
|
SDL_SetColorKey(background,SDL_SRCCOLORKEY,SDL_MapRGB(background->format,0,255,255));
|
|
|
|
}
|
2008-06-12 09:45:51 +03:00
|
|
|
ok = CDefHandler::giveDef("IOKAY.DEF");
|
|
|
|
cancel = CDefHandler::giveDef("ICANCEL.DEF");
|
2007-07-29 02:01:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CMessage::dispose()
|
|
|
|
{
|
|
|
|
for (int i=0;i<PLAYER_LIMIT;i++)
|
|
|
|
{
|
2008-12-21 21:17:35 +02:00
|
|
|
for (size_t j=0; j<piecesOfBox[i].size(); ++j)
|
2007-07-29 02:01:25 +03:00
|
|
|
{
|
|
|
|
SDL_FreeSurface(piecesOfBox[i][j]);
|
|
|
|
}
|
|
|
|
}
|
2007-07-28 12:44:10 +03:00
|
|
|
SDL_FreeSurface(background);
|
2007-11-19 00:58:28 +02:00
|
|
|
delete ok;
|
|
|
|
delete cancel;
|
2007-07-28 12:44:10 +03:00
|
|
|
}
|
2008-08-15 15:11:42 +03:00
|
|
|
SDL_Surface * CMessage::drawBox1(int w, int h, int playerColor) //draws box for window
|
2007-06-12 12:33:20 +03:00
|
|
|
{
|
|
|
|
//prepare surface
|
2009-08-22 16:59:15 +03:00
|
|
|
SDL_Surface * ret = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask);
|
2011-01-01 22:26:39 +02:00
|
|
|
for (int i=0; i<w; i+=background->w)//background
|
2007-06-12 12:33:20 +03:00
|
|
|
{
|
2011-01-01 22:26:39 +02:00
|
|
|
for (int j=0; j<h; j+=background->h)
|
2008-12-23 15:59:03 +02:00
|
|
|
{
|
2011-01-01 22:26:39 +02:00
|
|
|
Rect srcR(0,0,background->w, background->h);
|
|
|
|
Rect dstR(i,j,w,h);
|
|
|
|
CSDL_Ext::blitSurface(background, &srcR, ret, &dstR);
|
2008-12-23 15:59:03 +02:00
|
|
|
}
|
2007-07-12 14:41:31 +03:00
|
|
|
}
|
2008-12-08 00:38:04 +02:00
|
|
|
drawBorder(playerColor, ret, w, h);
|
2007-06-12 12:33:20 +03:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-04-16 14:14:13 +03:00
|
|
|
/* The map file contains long texts, with or without line breaks. This
|
|
|
|
* method takes such a text and breaks it into into several lines. */
|
2010-07-06 05:10:26 +03:00
|
|
|
std::vector<std::string> CMessage::breakText( std::string text, size_t maxLineSize/*=30*/, const boost::function<int(char)> &charMetric /*= 0*/, bool allowLeadingWhitespace /*= false*/ )
|
2007-06-12 12:33:20 +03:00
|
|
|
{
|
2010-07-06 05:10:26 +03:00
|
|
|
std::vector<std::string> ret;
|
2009-04-16 14:14:13 +03:00
|
|
|
|
2011-04-23 13:27:44 +03:00
|
|
|
boost::algorithm::trim_right_if(text,boost::algorithm::is_any_of(std::string(" ")));
|
2009-04-16 14:14:13 +03:00
|
|
|
|
2009-04-16 16:32:45 +03:00
|
|
|
while (text.length())
|
|
|
|
{
|
2010-07-06 05:10:26 +03:00
|
|
|
unsigned int lineLength = 0; //in characters or given char metric
|
|
|
|
unsigned int z = 0; //our position in text
|
|
|
|
bool opened = false;//if we have an unclosed brace in current line
|
|
|
|
bool lineManuallyBroken = false;
|
2009-04-16 14:14:13 +03:00
|
|
|
|
2010-07-06 05:10:26 +03:00
|
|
|
while(z < text.length() && text[z] != 0x0a && lineLength < maxLineSize)
|
2009-04-16 16:32:45 +03:00
|
|
|
{
|
2009-04-16 14:14:13 +03:00
|
|
|
/* We don't count braces in string length. */
|
2009-04-16 16:32:45 +03:00
|
|
|
if (text[z] == '{')
|
2009-04-16 14:14:13 +03:00
|
|
|
opened=true;
|
2009-04-16 16:32:45 +03:00
|
|
|
else if (text[z]=='}')
|
2009-04-16 14:14:13 +03:00
|
|
|
opened=false;
|
2010-07-06 05:10:26 +03:00
|
|
|
else if(charMetric)
|
|
|
|
lineLength += charMetric(text[z]);
|
|
|
|
else
|
|
|
|
lineLength++;
|
2009-04-16 14:14:13 +03:00
|
|
|
|
|
|
|
z++;
|
2007-07-28 12:44:10 +03:00
|
|
|
}
|
2009-04-16 14:14:13 +03:00
|
|
|
|
2010-02-20 15:24:38 +02:00
|
|
|
if (z < text.length() && (text[z] != 0x0a))
|
2009-04-16 16:32:45 +03:00
|
|
|
{
|
2009-04-16 14:14:13 +03:00
|
|
|
/* We have a long line. Try to do a nice line break, if
|
|
|
|
* possible. We backtrack on the line until we find a
|
2011-01-17 18:07:08 +02:00
|
|
|
* suitable character.
|
|
|
|
* Note: Cyrillic symbols have indexes 220-255 so we need
|
|
|
|
* to use unsigned char for comparison
|
|
|
|
*/
|
2009-04-16 14:14:13 +03:00
|
|
|
int pos = z-1;
|
2011-01-17 18:07:08 +02:00
|
|
|
while(pos > 0 && ((unsigned char)text[pos]) > ' ' )
|
|
|
|
pos --;
|
2009-04-16 14:14:13 +03:00
|
|
|
|
|
|
|
if (pos > 0)
|
|
|
|
z = pos+1;
|
2007-06-12 12:33:20 +03:00
|
|
|
}
|
2009-04-16 14:14:13 +03:00
|
|
|
|
2009-04-16 16:32:45 +03:00
|
|
|
if(z) //non-blank line
|
|
|
|
{
|
2010-07-06 05:10:26 +03:00
|
|
|
ret.push_back(text.substr(0, z));
|
2009-04-16 14:14:13 +03:00
|
|
|
|
|
|
|
if (opened)
|
|
|
|
/* Close the brace for the current line. */
|
2010-07-06 05:10:26 +03:00
|
|
|
ret.back() += '}';
|
2009-04-16 14:14:13 +03:00
|
|
|
|
|
|
|
text.erase(0, z);
|
2007-10-13 23:31:50 +03:00
|
|
|
}
|
2009-04-16 16:32:45 +03:00
|
|
|
else if(text[z] == 0x0a) //blank line
|
|
|
|
{
|
2010-07-06 05:10:26 +03:00
|
|
|
ret.push_back(""); //add empty string, no extra actions needed
|
2009-04-16 16:32:45 +03:00
|
|
|
}
|
2009-04-16 14:14:13 +03:00
|
|
|
|
2010-02-20 15:24:38 +02:00
|
|
|
if (text.length() && text[0] == 0x0a)
|
2009-04-16 16:32:45 +03:00
|
|
|
{
|
2009-04-16 14:14:13 +03:00
|
|
|
/* Braces do not carry over lines. The map author forgot
|
|
|
|
* to close it. */
|
|
|
|
opened = false;
|
|
|
|
|
|
|
|
/* Remove LF */
|
|
|
|
text.erase(0, 1);
|
2010-07-06 05:10:26 +03:00
|
|
|
|
|
|
|
lineManuallyBroken = true;
|
2009-04-16 14:14:13 +03:00
|
|
|
}
|
|
|
|
|
2010-07-06 05:10:26 +03:00
|
|
|
if(!allowLeadingWhitespace || !lineManuallyBroken)
|
2011-04-23 13:27:44 +03:00
|
|
|
boost::algorithm::trim_left_if(text,boost::algorithm::is_any_of(std::string(" ")));
|
2009-04-16 14:14:13 +03:00
|
|
|
|
2009-04-16 16:32:45 +03:00
|
|
|
if (opened)
|
|
|
|
{
|
2009-04-16 14:14:13 +03:00
|
|
|
/* Add an opening brace for the next line. */
|
|
|
|
if (text.length())
|
|
|
|
text.insert(0, "{");
|
2007-07-28 12:44:10 +03:00
|
|
|
}
|
|
|
|
}
|
2009-04-16 14:14:13 +03:00
|
|
|
|
|
|
|
/* Trim whitespaces of every line. */
|
2010-07-06 05:10:26 +03:00
|
|
|
if(!allowLeadingWhitespace)
|
|
|
|
for (size_t i=0; i<ret.size(); i++)
|
|
|
|
boost::algorithm::trim(ret[i]);
|
2009-04-16 14:14:13 +03:00
|
|
|
|
2007-10-13 23:31:50 +03:00
|
|
|
return ret;
|
|
|
|
}
|
2007-12-27 02:11:46 +02:00
|
|
|
|
2010-07-06 05:10:26 +03:00
|
|
|
std::vector<std::string> CMessage::breakText( std::string text, size_t maxLineWidth, EFonts font )
|
|
|
|
{
|
|
|
|
return breakText(text, maxLineWidth, boost::bind(&Font::getCharWidth, graphics->fonts[font], _1), true);
|
|
|
|
}
|
|
|
|
|
2009-06-01 08:40:54 +03:00
|
|
|
std::pair<int,int> CMessage::getMaxSizes(std::vector<std::vector<SDL_Surface*> > * txtg, int fontHeight)
|
2007-11-19 00:58:28 +02:00
|
|
|
{
|
2008-08-02 18:08:03 +03:00
|
|
|
std::pair<int,int> ret;
|
2007-11-19 00:58:28 +02:00
|
|
|
ret.first = -1;
|
|
|
|
ret.second=0;
|
2009-04-16 14:14:13 +03:00
|
|
|
for (size_t i=0; i<txtg->size();i++) //we are searching widest line and total height
|
2007-11-19 00:58:28 +02:00
|
|
|
{
|
|
|
|
int lw=0;
|
2008-12-21 21:17:35 +02:00
|
|
|
for (size_t j=0;j<(*txtg)[i].size();j++)
|
2007-11-19 00:58:28 +02:00
|
|
|
{
|
|
|
|
lw+=(*txtg)[i][j]->w;
|
|
|
|
ret.second+=(*txtg)[i][j]->h;
|
|
|
|
}
|
2008-08-20 22:02:48 +03:00
|
|
|
if(!(*txtg)[i].size())
|
2009-06-01 08:40:54 +03:00
|
|
|
ret.second+=fontHeight;
|
2007-11-19 00:58:28 +02:00
|
|
|
if (ret.first<lw)
|
|
|
|
ret.first=lw;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2009-06-01 08:40:54 +03:00
|
|
|
|
|
|
|
// Blit the text in txtg onto one surface. txtg contains lines of
|
|
|
|
// text. Each line can be split into pieces. Currently only lines with
|
|
|
|
// the same height are supported (ie. fontHeight).
|
|
|
|
SDL_Surface * CMessage::blitTextOnSur(std::vector<std::vector<SDL_Surface*> > * txtg, int fontHeight, int & curh, SDL_Surface * ret, int xCenterPos)
|
2007-12-01 14:50:33 +02:00
|
|
|
{
|
2009-06-01 08:40:54 +03:00
|
|
|
for (size_t i=0; i<txtg->size(); i++, curh += fontHeight)
|
2007-12-01 14:50:33 +02:00
|
|
|
{
|
2009-03-27 01:05:40 +02:00
|
|
|
int lw=0; //line width
|
2008-12-21 21:17:35 +02:00
|
|
|
for (size_t j=0;j<(*txtg)[i].size();j++)
|
2009-03-27 01:05:40 +02:00
|
|
|
lw+=(*txtg)[i][j]->w;
|
|
|
|
|
|
|
|
int pw = (xCenterPos < 0) ? ret->w/2 : xCenterPos;
|
|
|
|
pw -= lw/2; //x coord for the start of the text
|
2007-10-13 23:31:50 +03:00
|
|
|
|
2007-12-01 14:50:33 +02:00
|
|
|
int tw = pw;
|
2008-12-21 21:17:35 +02:00
|
|
|
for (size_t j=0;j<(*txtg)[i].size();j++) //blit text
|
2008-08-02 18:08:03 +03:00
|
|
|
{
|
2009-06-01 08:40:54 +03:00
|
|
|
SDL_Surface *surf = (*txtg)[i][j];
|
|
|
|
blitAt(surf, tw, curh, ret);
|
|
|
|
tw+=surf->w;
|
|
|
|
SDL_FreeSurface(surf);
|
2009-03-27 01:05:40 +02:00
|
|
|
(*txtg)[i][j] = NULL;
|
2007-12-01 14:50:33 +02:00
|
|
|
}
|
|
|
|
}
|
2009-06-01 08:40:54 +03:00
|
|
|
|
2007-12-01 14:50:33 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2010-02-04 17:50:59 +02:00
|
|
|
|
|
|
|
SDL_Surface * FNT_RenderText (EFonts font, std::string text, SDL_Color kolor= zwykly)
|
|
|
|
{
|
|
|
|
if (graphics->fontsTrueType[font])
|
|
|
|
return TTF_RenderText_Blended(graphics->fontsTrueType[font], text.c_str(), kolor);
|
|
|
|
const Font *f = graphics->fonts[font];
|
|
|
|
int w = f->getWidth(text.c_str()),
|
|
|
|
h = f->height;
|
|
|
|
SDL_Surface * ret = CSDL_Ext::newSurface(w, h, screen);
|
2010-08-23 19:13:30 +03:00
|
|
|
CSDL_Ext::fillRect (ret, NULL, SDL_MapRGB(ret->format,128,128,128));//if use default black - no shadowing
|
2010-02-04 17:50:59 +02:00
|
|
|
SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,128,128,128));
|
|
|
|
CSDL_Ext::printAt(text.c_str(), 0, 0, font, kolor, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::vector<SDL_Surface*> > * CMessage::drawText(std::vector<std::string> * brtext, int &fontHeigh, EFonts font)
|
2007-10-13 23:31:50 +03:00
|
|
|
{
|
2007-11-19 00:58:28 +02:00
|
|
|
std::vector<std::vector<SDL_Surface*> > * txtg = new std::vector<std::vector<SDL_Surface*> >();
|
|
|
|
txtg->resize(brtext->size());
|
2010-02-04 17:50:59 +02:00
|
|
|
if (graphics->fontsTrueType[font])
|
|
|
|
fontHeigh = TTF_FontHeight(graphics->fontsTrueType[font]);
|
|
|
|
else
|
|
|
|
fontHeigh = graphics->fonts[font]->height;
|
2009-06-01 08:40:54 +03:00
|
|
|
|
2008-12-21 21:17:35 +02:00
|
|
|
for (size_t i=0; i<brtext->size();i++) //foreach line
|
2007-10-13 23:31:50 +03:00
|
|
|
{
|
2009-04-16 14:14:13 +03:00
|
|
|
while((*brtext)[i].length()) //if something left
|
2007-10-13 23:31:50 +03:00
|
|
|
{
|
2009-04-16 14:14:13 +03:00
|
|
|
size_t z;
|
|
|
|
|
|
|
|
/* Handle normal text. */
|
|
|
|
z = 0;
|
2010-02-20 15:24:38 +02:00
|
|
|
while(z < (*brtext)[i].length() && (*brtext)[i][z] != ('{'))
|
2007-10-13 23:31:50 +03:00
|
|
|
z++;
|
2009-04-16 14:14:13 +03:00
|
|
|
|
2007-10-13 23:31:50 +03:00
|
|
|
if (z)
|
2010-02-04 17:50:59 +02:00
|
|
|
(*txtg)[i].push_back(FNT_RenderText(font, (*brtext)[i].substr(0,z), zwykly));
|
2007-10-13 23:31:50 +03:00
|
|
|
(*brtext)[i].erase(0,z);
|
2009-04-16 14:14:13 +03:00
|
|
|
|
2010-02-20 15:24:38 +02:00
|
|
|
if ((*brtext)[i].length() && (*brtext)[i][0] == '{')
|
2009-04-16 14:14:13 +03:00
|
|
|
/* Remove '{' */
|
|
|
|
(*brtext)[i].erase(0,1);
|
|
|
|
|
|
|
|
if ((*brtext)[i].length()==0)
|
|
|
|
/* End of line */
|
2007-10-13 23:31:50 +03:00
|
|
|
continue;
|
2009-04-16 14:14:13 +03:00
|
|
|
|
|
|
|
/* This text will be highlighted. */
|
|
|
|
z = 0;
|
2010-02-20 15:24:38 +02:00
|
|
|
while(z < (*brtext)[i].length() && (*brtext)[i][z] != ('}'))
|
2009-04-16 14:14:13 +03:00
|
|
|
z++;
|
|
|
|
|
|
|
|
if (z)
|
2010-02-04 17:50:59 +02:00
|
|
|
(*txtg)[i].push_back(FNT_RenderText(font, (*brtext)[i].substr(0,z), tytulowy));
|
2009-04-16 14:14:13 +03:00
|
|
|
(*brtext)[i].erase(0,z);
|
|
|
|
|
2010-02-20 15:24:38 +02:00
|
|
|
if ((*brtext)[i].length() && (*brtext)[i][0] == '}')
|
2009-04-16 14:14:13 +03:00
|
|
|
/* Remove '}' */
|
|
|
|
(*brtext)[i].erase(0,1);
|
|
|
|
|
2007-10-13 23:31:50 +03:00
|
|
|
} //ends while((*brtext)[i].length())
|
2008-08-02 18:08:03 +03:00
|
|
|
} //ends for(int i=0; i<brtext->size();i++)
|
2007-11-19 00:58:28 +02:00
|
|
|
return txtg;
|
|
|
|
}
|
2011-03-12 23:55:31 +02:00
|
|
|
//CSimpleWindow * CMessage::genWindow(std::string text, int player, bool centerOnMouse, int Lmar, int Rmar, int Tmar, int Bmar)
|
|
|
|
//{
|
|
|
|
// CSimpleWindow * ret = new CSimpleWindow();
|
|
|
|
// int fontHeight;
|
|
|
|
// std::vector<std::string> brtext = breakText(text,32);
|
|
|
|
// std::vector<std::vector<SDL_Surface*> > * txtg = drawText(&brtext, fontHeight);
|
|
|
|
// std::pair<int,int> txts = getMaxSizes(txtg, fontHeight);
|
|
|
|
// ret->bitmap = drawBox1(txts.first+Lmar+Rmar,txts.second+Tmar+Bmar,player);
|
|
|
|
// ret->pos.h = ret->bitmap->h;
|
|
|
|
// ret->pos.w = ret->bitmap->w;
|
|
|
|
// if (centerOnMouse)
|
|
|
|
// {
|
|
|
|
// ret->pos.x = GH.current->motion.x - ret->pos.w/2;
|
|
|
|
// ret->pos.y = GH.current->motion.y - ret->pos.h/2;
|
|
|
|
// // Put the window back on screen if necessary
|
|
|
|
// amax(ret->pos.x, 0);
|
|
|
|
// amax(ret->pos.y, 0);
|
|
|
|
// amin(ret->pos.x, conf.cc.resx - ret->pos.w);
|
|
|
|
// amin(ret->pos.y, conf.cc.resy - ret->pos.h);
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// // Center on screen
|
|
|
|
// ret->pos.x = screen->w/2 - (ret->pos.w/2);
|
|
|
|
// ret->pos.y = screen->h/2 - (ret->pos.h/2);
|
|
|
|
// }
|
|
|
|
// int curh = ret->bitmap->h/2 - (fontHeight*txtg->size())/2;
|
|
|
|
// blitTextOnSur(txtg,fontHeight,curh,ret->bitmap);
|
|
|
|
// delete txtg;
|
|
|
|
// return ret;
|
|
|
|
//}
|
2008-08-20 22:02:48 +03:00
|
|
|
SDL_Surface * CMessage::drawBoxTextBitmapSub( int player, std::string text, SDL_Surface* bitmap, std::string sub, int charperline/*=30*/, int imgToBmp/*=55*/ )
|
2008-03-06 20:54:35 +02:00
|
|
|
{
|
|
|
|
int curh;
|
2009-06-01 08:40:54 +03:00
|
|
|
int fontHeight;
|
2010-07-06 05:10:26 +03:00
|
|
|
std::vector<std::string> tekst = breakText(text,charperline);
|
|
|
|
std::vector<std::vector<SDL_Surface*> > * txtg = drawText(&tekst, fontHeight);
|
2009-06-01 08:40:54 +03:00
|
|
|
std::pair<int,int> txts = getMaxSizes(txtg, fontHeight), boxs;
|
2008-03-06 20:54:35 +02:00
|
|
|
boxs.first = std::max(txts.first,bitmap->w) // text/bitmap max width
|
|
|
|
+ 50; //side margins
|
2008-08-02 18:08:03 +03:00
|
|
|
boxs.second =
|
2008-03-06 20:54:35 +02:00
|
|
|
(curh=45) //top margin
|
|
|
|
+ txts.second //text total height
|
2008-08-20 22:02:48 +03:00
|
|
|
+ imgToBmp //text <=> img
|
2008-03-06 20:54:35 +02:00
|
|
|
+ bitmap->h
|
|
|
|
+ 5 // to sibtitle
|
|
|
|
+ (*txtg)[0][0]->h
|
|
|
|
+ 30;
|
|
|
|
SDL_Surface *ret = drawBox1(boxs.first,boxs.second,player);
|
2009-06-01 08:40:54 +03:00
|
|
|
blitTextOnSur(txtg,fontHeight,curh,ret);
|
2008-08-20 22:02:48 +03:00
|
|
|
curh += imgToBmp;
|
2008-03-06 20:54:35 +02:00
|
|
|
blitAt(bitmap,(ret->w/2)-(bitmap->w/2),curh,ret);
|
|
|
|
curh += bitmap->h + 5;
|
2010-02-02 18:24:53 +02:00
|
|
|
CSDL_Ext::printAtMiddle(sub,ret->w/2,curh+10,FONT_SMALL,zwykly,ret);
|
2008-08-20 22:02:48 +03:00
|
|
|
delete txtg;
|
2008-03-06 20:54:35 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-07-26 18:37:58 +03:00
|
|
|
void CMessage::drawIWindow(CInfoWindow * ret, std::string text, int player)
|
2007-12-27 02:11:46 +02:00
|
|
|
{
|
2009-03-27 01:05:40 +02:00
|
|
|
SDL_Surface * _or = NULL;
|
2010-10-31 00:53:41 +03:00
|
|
|
//const Font &f = *graphics->fonts[FONT_MEDIUM];
|
|
|
|
//int fontHeight = f.height;
|
2010-07-06 05:10:26 +03:00
|
|
|
|
|
|
|
if(dynamic_cast<CSelWindow*>(ret)) //it's selection window, so we'll blit "or" between components
|
|
|
|
_or = FNT_RenderText(FONT_MEDIUM,CGI->generaltexth->allTexts[4],zwykly);
|
2009-06-02 05:15:23 +03:00
|
|
|
|
2011-03-21 10:14:23 +02:00
|
|
|
const int sizes[][2] = {{400, 125}, {500, 150}, {600, 200}, {480, 400}};
|
2010-07-06 05:10:26 +03:00
|
|
|
for(int i = 0;
|
|
|
|
i < ARRAY_COUNT(sizes)
|
|
|
|
&& sizes[i][0] < conf.cc.resx - 150
|
|
|
|
&& sizes[i][1] < conf.cc.resy - 150
|
|
|
|
&& ret->text->slider;
|
|
|
|
i++)
|
2009-07-12 17:07:36 +03:00
|
|
|
{
|
2010-07-06 05:10:26 +03:00
|
|
|
ret->text->setBounds(sizes[i][0], sizes[i][1]);
|
2009-06-02 05:15:23 +03:00
|
|
|
}
|
|
|
|
|
2010-07-06 05:10:26 +03:00
|
|
|
if(ret->text->slider)
|
|
|
|
ret->text->slider->changeUsedEvents(CIntObject::WHEEL | CIntObject::KEYBOARD, true);
|
2009-03-27 01:05:40 +02:00
|
|
|
|
2010-07-06 05:10:26 +03:00
|
|
|
std::pair<int,int> winSize(ret->text->pos.w, ret->text->pos.h); //start with text size
|
2009-03-27 01:05:40 +02:00
|
|
|
|
|
|
|
ComponentsToBlit comps(ret->components,500,_or);
|
2008-08-15 15:11:42 +03:00
|
|
|
if (ret->components.size())
|
2010-07-06 05:10:26 +03:00
|
|
|
winSize.second += 30 + comps.h; //space to first component
|
2009-03-27 01:05:40 +02:00
|
|
|
|
2009-10-24 14:17:10 +03:00
|
|
|
int bw = 0;
|
2009-06-02 05:15:23 +03:00
|
|
|
if (ret->buttons.size())
|
2009-10-24 14:17:10 +03:00
|
|
|
{
|
|
|
|
// Compute total width of buttons
|
|
|
|
bw = 20*(ret->buttons.size()-1); // space between all buttons
|
|
|
|
for(size_t i=0; i<ret->buttons.size(); i++) //and add buttons width
|
2011-02-20 11:24:53 +02:00
|
|
|
bw+=ret->buttons[i]->pos.w;
|
2010-07-06 05:10:26 +03:00
|
|
|
winSize.second += 20 + //before button
|
2009-10-24 14:17:10 +03:00
|
|
|
ok->ourImages[0].bitmap->h; //button
|
|
|
|
}
|
2009-03-27 01:05:40 +02:00
|
|
|
|
2009-06-02 05:15:23 +03:00
|
|
|
// Clip window size
|
2010-07-06 05:10:26 +03:00
|
|
|
amax(winSize.second, 50);
|
|
|
|
amax(winSize.first, 80);
|
|
|
|
amax(winSize.first, comps.w);
|
|
|
|
amax(winSize.first, bw);
|
2009-03-27 01:05:40 +02:00
|
|
|
|
2010-07-06 05:10:26 +03:00
|
|
|
amin(winSize.first, conf.cc.resx - 150);
|
2009-06-02 05:15:23 +03:00
|
|
|
|
2010-07-06 05:10:26 +03:00
|
|
|
ret->bitmap = drawBox1 (winSize.first + 2*SIDE_MARGIN, winSize.second + 2*SIDE_MARGIN, player);
|
2008-08-15 15:11:42 +03:00
|
|
|
ret->pos.h=ret->bitmap->h;
|
|
|
|
ret->pos.w=ret->bitmap->w;
|
2010-07-06 05:10:26 +03:00
|
|
|
ret->center();
|
|
|
|
|
2009-06-02 05:15:23 +03:00
|
|
|
|
|
|
|
int curh = SIDE_MARGIN;
|
2010-07-06 05:10:26 +03:00
|
|
|
int xOffset = (ret->pos.w - ret->text->pos.w)/2;
|
|
|
|
|
2011-05-26 01:44:02 +03:00
|
|
|
if(!ret->buttons.size() && !ret->components.size()) //improvement for very small text only popups -> center text vertically
|
|
|
|
{
|
|
|
|
if(ret->bitmap->h > ret->text->pos.h + 2*SIDE_MARGIN)
|
|
|
|
curh = (ret->bitmap->h - ret->text->pos.h)/2;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret->text->moveBy(Point(xOffset, curh));
|
2010-07-06 05:10:26 +03:00
|
|
|
|
|
|
|
curh += ret->text->pos.h;
|
2009-03-27 01:05:40 +02:00
|
|
|
|
2008-08-15 15:11:42 +03:00
|
|
|
if (ret->components.size())
|
|
|
|
{
|
2009-03-27 01:05:40 +02:00
|
|
|
curh += BEFORE_COMPONENTS;
|
2009-10-28 12:45:45 +02:00
|
|
|
comps.blitCompsOnSur (_or, 10, curh, ret->bitmap);
|
2008-08-15 15:11:42 +03:00
|
|
|
}
|
|
|
|
if(ret->buttons.size())
|
|
|
|
{
|
2009-06-02 05:15:23 +03:00
|
|
|
// Position the buttons at the bottom of the window
|
2008-08-15 15:11:42 +03:00
|
|
|
bw = (ret->bitmap->w/2) - (bw/2);
|
2011-02-20 11:24:53 +02:00
|
|
|
curh = ret->bitmap->h - SIDE_MARGIN - ret->buttons[0]->pos.h;
|
2009-06-02 05:15:23 +03:00
|
|
|
|
2008-12-21 21:17:35 +02:00
|
|
|
for(size_t i=0; i<ret->buttons.size(); i++)
|
2008-08-15 15:11:42 +03:00
|
|
|
{
|
2011-02-20 11:24:53 +02:00
|
|
|
ret->buttons[i]->moveBy(Point(bw, curh));
|
|
|
|
bw += ret->buttons[i]->pos.w + 20;
|
2008-08-15 15:11:42 +03:00
|
|
|
}
|
|
|
|
}
|
2008-12-21 21:17:35 +02:00
|
|
|
for(size_t i=0; i<ret->components.size(); i++)
|
2008-08-15 15:11:42 +03:00
|
|
|
{
|
|
|
|
ret->components[i]->pos.x += ret->pos.x;
|
|
|
|
ret->components[i]->pos.y += ret->pos.y;
|
|
|
|
}
|
2010-07-06 05:10:26 +03:00
|
|
|
|
2009-03-27 01:05:40 +02:00
|
|
|
if(_or)
|
|
|
|
SDL_FreeSurface(_or);
|
2007-11-19 00:58:28 +02:00
|
|
|
}
|
2007-10-13 23:31:50 +03:00
|
|
|
|
2008-12-08 00:38:04 +02:00
|
|
|
void CMessage::drawBorder(int playerColor, SDL_Surface * ret, int w, int h, int x, int y)
|
|
|
|
{
|
2011-01-01 22:26:39 +02:00
|
|
|
std::vector<SDL_Surface *> &box = piecesOfBox[playerColor];
|
2009-04-16 14:14:13 +03:00
|
|
|
//obwodka I-szego rzedu pozioma //border of 1st series, horizontal
|
2011-01-01 22:26:39 +02:00
|
|
|
for (int i=0; i<w-box[6]->w; i+=box[6]->w)
|
2008-12-08 00:38:04 +02:00
|
|
|
{
|
2011-01-01 22:26:39 +02:00
|
|
|
Rect dstR(x+i, y, box[6]->w, box[6]->h);
|
|
|
|
CSDL_Ext::blitSurface(box[6], NULL, ret, &dstR);
|
|
|
|
|
|
|
|
int currY = y+h-box[7]->h+1;
|
|
|
|
dstR=Rect(x+i, currY, box[7]->w, box[7]->h);
|
|
|
|
|
|
|
|
CSDL_Ext::blitSurface(box[7], NULL, ret, &dstR);
|
2008-12-08 00:38:04 +02:00
|
|
|
}
|
2009-04-16 14:14:13 +03:00
|
|
|
//obwodka I-szego rzedu pionowa //border of 1st series, vertical
|
2011-01-01 22:26:39 +02:00
|
|
|
for (int i=0; i<h-box[4]->h; i+=box[4]->h)
|
2008-12-08 00:38:04 +02:00
|
|
|
{
|
2011-01-01 22:26:39 +02:00
|
|
|
Rect dstR(x, y+i, box[4]->w, box[4]->h);
|
|
|
|
CSDL_Ext::blitSurface(box[4], NULL, ret, &dstR);
|
|
|
|
|
|
|
|
int currX = x+w-box[5]->w;
|
|
|
|
dstR=Rect(currX, y+i, box[5]->w, box[5]->h);
|
|
|
|
|
|
|
|
CSDL_Ext::blitSurface(box[5], NULL, ret, &dstR);
|
2008-12-08 00:38:04 +02:00
|
|
|
}
|
|
|
|
//corners
|
2011-01-01 22:26:39 +02:00
|
|
|
Rect dstR(x, y, box[0]->w, box[0]->h);
|
|
|
|
CSDL_Ext::blitSurface(box[0], NULL, ret, &dstR);
|
|
|
|
|
|
|
|
dstR=Rect(x+w-box[1]->w, y, box[1]->w, box[1]->h);
|
|
|
|
CSDL_Ext::blitSurface(box[1], NULL, ret, &dstR);
|
|
|
|
|
|
|
|
dstR=Rect(x, y+h-box[2]->h+1, box[2]->w, box[2]->h);
|
|
|
|
CSDL_Ext::blitSurface(box[2], NULL, ret, &dstR);
|
|
|
|
|
|
|
|
dstR=Rect(x+w-box[3]->w, y+h-box[3]->h+1, box[3]->w, box[3]->h);
|
|
|
|
CSDL_Ext::blitSurface(box[3], NULL, ret, &dstR);
|
2009-03-27 01:05:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ComponentResolved::ComponentResolved()
|
|
|
|
{
|
|
|
|
comp = NULL;
|
|
|
|
img = NULL;
|
|
|
|
txt = NULL;
|
2009-06-01 08:40:54 +03:00
|
|
|
txtFontHeight = 0;
|
2009-03-27 01:05:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ComponentResolved::ComponentResolved( SComponent *Comp )
|
|
|
|
{
|
|
|
|
comp = Comp;
|
|
|
|
img = comp->getImg();
|
2011-03-08 09:53:09 +02:00
|
|
|
std::vector<std::string> brtext = CMessage::breakText(comp->subtitle,14); //text
|
2011-01-01 22:26:39 +02:00
|
|
|
txt = CMessage::drawText(&brtext,txtFontHeight,FONT_SMALL);
|
2009-04-21 01:57:07 +03:00
|
|
|
|
|
|
|
//calculate dimensions
|
2009-06-01 08:40:54 +03:00
|
|
|
std::pair<int,int> textSize = CMessage::getMaxSizes(txt, txtFontHeight);
|
2009-04-21 01:57:07 +03:00
|
|
|
comp->pos.w = std::max(textSize.first, img->w); //bigger of: subtitle width and image width
|
|
|
|
comp->pos.h = img->h + COMPONENT_TO_SUBTITLE + textSize.second;
|
2009-03-27 01:05:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ComponentResolved::~ComponentResolved()
|
|
|
|
{
|
|
|
|
for(size_t i = 0; i < txt->size(); i++)
|
|
|
|
for(size_t j = 0; j < (*txt)[i].size(); j++)
|
|
|
|
if((*txt)[i][j])
|
|
|
|
SDL_FreeSurface((*txt)[i][j]);
|
|
|
|
delete txt;
|
|
|
|
}
|
|
|
|
|
|
|
|
ComponentsToBlit::~ComponentsToBlit()
|
|
|
|
{
|
|
|
|
for(size_t i=0; i<comps.size(); i++)
|
|
|
|
for(size_t j = 0; j < comps[i].size(); j++)
|
|
|
|
delete comps[i][j];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ComponentsToBlit::ComponentsToBlit(std::vector<SComponent*> & SComps, int maxw, SDL_Surface* _or)
|
|
|
|
{
|
|
|
|
w = h = 0;
|
2011-02-06 19:26:27 +02:00
|
|
|
if(SComps.empty())
|
2009-03-27 01:05:40 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
comps.resize(1);
|
|
|
|
int curw = 0;
|
2009-04-21 01:57:07 +03:00
|
|
|
int curr = 0; //current row
|
2009-03-27 01:05:40 +02:00
|
|
|
|
|
|
|
for(size_t i=0;i<SComps.size();i++)
|
|
|
|
{
|
2009-04-21 01:57:07 +03:00
|
|
|
ComponentResolved *cur = new ComponentResolved(SComps[i]);
|
|
|
|
|
|
|
|
int toadd = (cur->comp->pos.w + 12 + (_or ? _or->w : 0));
|
2009-03-27 01:05:40 +02:00
|
|
|
if (curw + toadd > maxw)
|
|
|
|
{
|
2009-04-16 14:14:13 +03:00
|
|
|
curr++;
|
2009-03-27 01:05:40 +02:00
|
|
|
amax(w,curw);
|
2009-04-21 01:57:07 +03:00
|
|
|
curw = cur->comp->pos.w;
|
2009-03-27 01:05:40 +02:00
|
|
|
comps.resize(curr+1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
curw += toadd;
|
2009-05-02 01:08:03 +03:00
|
|
|
amax(w,curw);
|
2009-03-27 01:05:40 +02:00
|
|
|
}
|
|
|
|
|
2009-04-21 01:57:07 +03:00
|
|
|
comps[curr].push_back(cur);
|
2009-03-27 01:05:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for(size_t i=0;i<comps.size();i++)
|
|
|
|
{
|
|
|
|
int maxh = 0;
|
2009-04-21 01:57:07 +03:00
|
|
|
for(size_t j=0;j<comps[i].size();j++)
|
2009-03-27 01:05:40 +02:00
|
|
|
amax(maxh,comps[i][j]->comp->pos.h);
|
|
|
|
h += maxh + BETWEEN_COMPS_ROWS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ComponentsToBlit::blitCompsOnSur( SDL_Surface * _or, int inter, int &curh, SDL_Surface *ret )
|
|
|
|
{
|
2010-08-25 17:57:58 +03:00
|
|
|
for (size_t i=0;i<comps.size();i++)//for each row
|
2009-03-27 01:05:40 +02:00
|
|
|
{
|
|
|
|
int totalw=0, maxh=0;
|
2010-08-25 17:57:58 +03:00
|
|
|
for(size_t j=0;j<(comps)[i].size();j++)//find max height & total width in this row
|
2009-03-27 01:05:40 +02:00
|
|
|
{
|
|
|
|
ComponentResolved *cur = (comps)[i][j];
|
|
|
|
totalw += cur->comp->pos.w;
|
2010-08-25 17:57:58 +03:00
|
|
|
amax(maxh,cur->comp->getImg()->h);//subtitles height will added later
|
2009-03-27 01:05:40 +02:00
|
|
|
}
|
|
|
|
if(_or)
|
|
|
|
{
|
|
|
|
totalw += (inter*2+_or->w) * ((comps)[i].size() - 1);
|
|
|
|
}
|
2010-08-25 17:57:58 +03:00
|
|
|
else//add space between comps in this row
|
2009-03-27 01:05:40 +02:00
|
|
|
{
|
|
|
|
totalw += (inter) * ((comps)[i].size() - 1);
|
|
|
|
}
|
2011-03-20 00:27:05 +02:00
|
|
|
|
|
|
|
int startHeight = curh;
|
2011-01-01 22:26:39 +02:00
|
|
|
int middleh = curh + maxh/2;//axis for image aligment
|
2009-03-27 01:05:40 +02:00
|
|
|
int curw = (ret->w/2)-(totalw/2);
|
2011-01-01 22:26:39 +02:00
|
|
|
|
2009-03-27 01:05:40 +02:00
|
|
|
for(size_t j=0;j<(comps)[i].size();j++)
|
|
|
|
{
|
|
|
|
ComponentResolved *cur = (comps)[i][j];
|
|
|
|
|
|
|
|
//blit img
|
2011-01-01 22:26:39 +02:00
|
|
|
int imgX = curw + ( cur->comp->pos.w - cur->comp->getImg()->w ) / 2;
|
2011-03-20 00:27:05 +02:00
|
|
|
int imgY = startHeight;
|
2011-01-01 22:26:39 +02:00
|
|
|
blitAt(cur->img, imgX, imgY, ret);
|
|
|
|
cur->comp->pos.x = imgX;
|
|
|
|
cur->comp->pos.y = imgY;
|
2009-03-27 01:05:40 +02:00
|
|
|
|
|
|
|
//blit subtitle
|
2011-01-01 22:26:39 +02:00
|
|
|
int textX = imgX + cur->comp->getImg()->w/2;
|
2011-03-20 00:27:05 +02:00
|
|
|
int textY = startHeight + cur->comp->getImg()->h + COMPONENT_TO_SUBTITLE;
|
2011-01-01 22:26:39 +02:00
|
|
|
CMessage::blitTextOnSur(cur->txt, cur->txtFontHeight, textY, ret, textX );
|
2009-03-27 01:05:40 +02:00
|
|
|
|
|
|
|
//if there is subsequent component blit "or"
|
2009-04-21 01:57:07 +03:00
|
|
|
curw += cur->comp->pos.w;
|
2009-03-27 01:05:40 +02:00
|
|
|
if(j<((comps)[i].size()-1))
|
|
|
|
{
|
|
|
|
if(_or)
|
|
|
|
{
|
|
|
|
curw+=inter;
|
2011-01-01 22:26:39 +02:00
|
|
|
blitAt(_or,curw,middleh-(_or->h/2),ret);
|
2009-03-27 01:05:40 +02:00
|
|
|
curw+=_or->w;
|
|
|
|
}
|
|
|
|
curw+=inter;
|
|
|
|
}
|
2011-01-01 22:26:39 +02:00
|
|
|
amax(curh, textY);
|
2009-03-27 01:05:40 +02:00
|
|
|
}
|
2011-01-01 22:26:39 +02:00
|
|
|
curh += BETWEEN_COMPS_ROWS;
|
2009-03-27 01:05:40 +02:00
|
|
|
}
|
2009-06-01 08:40:54 +03:00
|
|
|
}
|