2011-12-14 00:23:17 +03:00
|
|
|
#include "StdInc.h"
|
2007-06-12 12:33:20 +03:00
|
|
|
#include "CMessage.h"
|
2011-12-14 00:23:17 +03:00
|
|
|
|
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"
|
2013-04-07 14:52:07 +03:00
|
|
|
#include "gui/SDL_Extensions.h"
|
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"
|
2012-09-29 13:59:43 +03:00
|
|
|
#include "../lib/CConfigHandler.h"
|
2010-08-17 18:16:08 +03:00
|
|
|
#include "CBitmapHandler.h"
|
2013-04-07 14:52:07 +03:00
|
|
|
#include "gui/CIntObjectClasses.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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-05-13 18:04:21 +03:00
|
|
|
const int COMPONENT_TO_SUBTITLE = 17;
|
2009-03-27 01:05:40 +02:00
|
|
|
const int BETWEEN_COMPS_ROWS = 10;
|
|
|
|
const int BEFORE_COMPONENTS = 30;
|
2012-09-29 22:18:35 +03:00
|
|
|
const int BETWEEN_COMPS = 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
|
|
|
|
2012-05-13 18:04:21 +03:00
|
|
|
//One image component + subtitles below it
|
|
|
|
class ComponentResolved : public CIntObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CComponent *comp;
|
|
|
|
|
|
|
|
//blit component with image centered at this position
|
|
|
|
void showAll(SDL_Surface * to);
|
|
|
|
|
|
|
|
//ComponentResolved(); //c-tor
|
|
|
|
ComponentResolved(CComponent *Comp); //c-tor
|
|
|
|
~ComponentResolved(); //d-tor
|
|
|
|
};
|
|
|
|
// Full set of components for blitting on dialog box
|
|
|
|
struct ComponentsToBlit
|
|
|
|
{
|
|
|
|
std::vector< std::vector<ComponentResolved*> > comps;
|
|
|
|
int w, h;
|
|
|
|
|
2012-12-19 20:24:53 +03:00
|
|
|
void blitCompsOnSur(bool blitOr, int inter, int &curh, SDL_Surface *ret);
|
|
|
|
ComponentsToBlit(std::vector<CComponent*> & SComps, int maxw, bool blitOr); //c-tor
|
2012-05-13 18:04:21 +03:00
|
|
|
~ComponentsToBlit(); //d-tor
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace
|
2007-07-29 02:01:25 +03:00
|
|
|
{
|
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
|
2013-06-26 14:18:27 +03:00
|
|
|
SDL_Surface * background = nullptr;
|
2007-07-29 02:01:25 +03:00
|
|
|
}
|
2007-07-28 12:44:10 +03: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
|
|
|
{
|
2013-03-03 20:06:03 +03:00
|
|
|
piecesOfBox.resize(PlayerColor::PLAYER_LIMIT_I);
|
|
|
|
for (int i=0; i<PlayerColor::PLAYER_LIMIT_I; i++)
|
2007-07-29 02:01:25 +03:00
|
|
|
{
|
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)
|
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
for (auto & elem : bluePieces->ourImages)
|
2007-07-29 02:01:25 +03:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
piecesOfBox[i].push_back(elem.bitmap);
|
|
|
|
elem.bitmap->refcount++;
|
2007-07-29 02:01:25 +03:00
|
|
|
}
|
|
|
|
}
|
2013-06-29 16:05:48 +03:00
|
|
|
for (auto & elem : bluePieces->ourImages)
|
2007-07-29 02:01:25 +03:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
graphics->blueToPlayersAdv(elem.bitmap, PlayerColor(i));
|
|
|
|
piecesOfBox[i].push_back(elem.bitmap);
|
|
|
|
elem.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
|
|
|
}
|
2012-05-13 18:04:21 +03:00
|
|
|
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()
|
|
|
|
{
|
2013-03-03 20:06:03 +03:00
|
|
|
for (int i=0; i<PlayerColor::PLAYER_LIMIT_I; i++)
|
2007-07-29 02:01:25 +03:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
for (auto & elem : piecesOfBox[i])
|
2007-07-29 02:01:25 +03:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
SDL_FreeSurface(elem);
|
2007-07-29 02:01:25 +03:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
2012-05-13 18:04:21 +03:00
|
|
|
|
2013-03-03 20:06:03 +03:00
|
|
|
SDL_Surface * CMessage::drawDialogBox(int w, int h, PlayerColor playerColor)
|
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-12-22 16:05:19 +03:00
|
|
|
Rect srcR(0,0,background->w, background->h);
|
|
|
|
Rect dstR(i,j,w,h);
|
2011-01-01 22:26:39 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-12-19 20:24:53 +03:00
|
|
|
std::vector<std::string> CMessage::breakText( std::string text, size_t maxLineSize, EFonts font )
|
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())
|
|
|
|
{
|
2011-12-14 00:23:17 +03:00
|
|
|
ui32 lineLength = 0; //in characters or given char metric
|
|
|
|
ui32 z = 0; //our position in text
|
2010-07-06 05:10:26 +03:00
|
|
|
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
|
2012-12-19 20:24:53 +03:00
|
|
|
lineLength += graphics->fonts[font]->getSymbolWidth(text[z]);
|
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
|
2011-12-14 00:23:17 +03:00
|
|
|
* to use ui8 for comparison
|
2011-01-17 18:07:08 +02:00
|
|
|
*/
|
2009-04-16 14:14:13 +03:00
|
|
|
int pos = z-1;
|
2011-12-14 00:23:17 +03:00
|
|
|
while(pos > 0 && ((ui8)text[pos]) > ' ' )
|
2011-01-17 18:07:08 +02:00
|
|
|
pos --;
|
2009-04-16 14:14:13 +03:00
|
|
|
|
|
|
|
if (pos > 0)
|
|
|
|
z = pos+1;
|
2007-06-12 12:33:20 +03:00
|
|
|
}
|
2012-12-19 20:24:53 +03:00
|
|
|
|
|
|
|
if(z) //non-blank line
|
2009-04-16 16:32:45 +03:00
|
|
|
{
|
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
|
|
|
}
|
2012-12-19 20:24:53 +03:00
|
|
|
else if(text[z] == 0x0a) //blank line
|
2009-04-16 16:32:45 +03:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2012-12-19 20:24:53 +03:00
|
|
|
//if(!allowLeadingWhitespace || !lineManuallyBroken)
|
|
|
|
if(!lineManuallyBroken)
|
|
|
|
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. */
|
2012-12-19 20:24:53 +03:00
|
|
|
//if(!allowLeadingWhitespace)
|
2013-06-29 16:05:48 +03:00
|
|
|
for (auto & elem : ret)
|
|
|
|
boost::algorithm::trim(elem);
|
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
|
|
|
|
2013-03-03 20:06:03 +03:00
|
|
|
void CMessage::drawIWindow(CInfoWindow * ret, std::string text, PlayerColor player)
|
2007-12-27 02:11:46 +02:00
|
|
|
{
|
2012-12-19 20:24:53 +03:00
|
|
|
bool blitOr = false;
|
2010-07-06 05:10:26 +03:00
|
|
|
if(dynamic_cast<CSelWindow*>(ret)) //it's selection window, so we'll blit "or" between components
|
2012-12-19 20:24:53 +03:00
|
|
|
blitOr = true;
|
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}};
|
2011-12-14 00:23:17 +03:00
|
|
|
|
2010-07-06 05:10:26 +03:00
|
|
|
for(int i = 0;
|
|
|
|
i < ARRAY_COUNT(sizes)
|
2012-01-12 18:23:00 +03:00
|
|
|
&& sizes[i][0] < screen->w - 150
|
|
|
|
&& sizes[i][1] < screen->h - 150
|
2010-07-06 05:10:26 +03:00
|
|
|
&& 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)
|
2012-06-02 18:16:54 +03:00
|
|
|
ret->text->slider->addUsedEvents(CIntObject::WHEEL | CIntObject::KEYBOARD);
|
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
|
|
|
|
2012-12-19 20:24:53 +03:00
|
|
|
ComponentsToBlit comps(ret->components,500, blitOr);
|
2008-08-15 15:11:42 +03:00
|
|
|
if (ret->components.size())
|
2012-05-13 18:04:21 +03:00
|
|
|
winSize.second += 10 + 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
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & elem : ret->buttons) //and add buttons width
|
|
|
|
bw+=elem->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
|
2011-12-14 00:23:17 +03:00
|
|
|
vstd::amax(winSize.second, 50);
|
|
|
|
vstd::amax(winSize.first, 80);
|
|
|
|
vstd::amax(winSize.first, comps.w);
|
|
|
|
vstd::amax(winSize.first, bw);
|
2009-03-27 01:05:40 +02:00
|
|
|
|
2012-01-12 18:23:00 +03:00
|
|
|
vstd::amin(winSize.first, screen->w - 150);
|
2009-06-02 05:15:23 +03:00
|
|
|
|
2012-05-13 18:04:21 +03:00
|
|
|
ret->bitmap = drawDialogBox (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;
|
|
|
|
}
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
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;
|
2012-12-19 20:24:53 +03:00
|
|
|
comps.blitCompsOnSur (blitOr, BETWEEN_COMPS, 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
|
|
|
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & elem : ret->buttons)
|
2008-08-15 15:11:42 +03:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
elem->moveBy(Point(bw, curh));
|
|
|
|
bw += elem->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++)
|
2012-05-13 18:04:21 +03:00
|
|
|
ret->components[i]->moveBy(Point(ret->pos.x, ret->pos.y));
|
2007-11-19 00:58:28 +02:00
|
|
|
}
|
2007-10-13 23:31:50 +03:00
|
|
|
|
2013-03-03 20:06:03 +03:00
|
|
|
void CMessage::drawBorder(PlayerColor playerColor, SDL_Surface * ret, int w, int h, int x, int y)
|
2008-12-08 00:38:04 +02:00
|
|
|
{
|
2013-03-03 20:06:03 +03:00
|
|
|
std::vector<SDL_Surface *> &box = piecesOfBox[playerColor.getNum()];
|
2011-09-25 21:44:13 +03:00
|
|
|
|
|
|
|
// Note: this code assumes that the corner dimensions are all the same.
|
|
|
|
|
|
|
|
// Horizontal borders
|
|
|
|
int start_x = x + box[0]->w;
|
|
|
|
const int stop_x = x + w - box[1]->w;
|
|
|
|
const int bottom_y = y+h-box[7]->h+1;
|
|
|
|
while (start_x < stop_x) {
|
|
|
|
int cur_w = stop_x - start_x;
|
|
|
|
if (cur_w > box[6]->w)
|
|
|
|
cur_w = box[6]->w;
|
|
|
|
|
|
|
|
// Top border
|
2011-12-22 16:05:19 +03:00
|
|
|
Rect srcR(0, 0, cur_w, box[6]->h);
|
|
|
|
Rect dstR(start_x, y, 0, 0);
|
2011-09-25 21:44:13 +03:00
|
|
|
CSDL_Ext::blitSurface(box[6], &srcR, ret, &dstR);
|
2011-01-01 22:26:39 +02:00
|
|
|
|
2011-09-25 21:44:13 +03:00
|
|
|
// Bottom border
|
|
|
|
dstR.y = bottom_y;
|
|
|
|
CSDL_Ext::blitSurface(box[7], &srcR, ret, &dstR);
|
2011-01-01 22:26:39 +02:00
|
|
|
|
2011-09-25 21:44:13 +03:00
|
|
|
start_x += cur_w;
|
2008-12-08 00:38:04 +02:00
|
|
|
}
|
2011-01-01 22:26:39 +02:00
|
|
|
|
2011-09-25 21:44:13 +03:00
|
|
|
// Vertical borders
|
|
|
|
int start_y = y + box[0]->h;
|
|
|
|
const int stop_y = y + h - box[2]->h+1;
|
|
|
|
const int right_x = x+w-box[5]->w;
|
|
|
|
while (start_y < stop_y) {
|
|
|
|
int cur_h = stop_y - start_y;
|
|
|
|
if (cur_h > box[4]->h)
|
|
|
|
cur_h = box[4]->h;
|
|
|
|
|
|
|
|
// Left border
|
2011-12-22 16:05:19 +03:00
|
|
|
Rect srcR(0, 0, box[4]->w, cur_h);
|
|
|
|
Rect dstR(x, start_y, 0, 0);
|
2011-09-25 21:44:13 +03:00
|
|
|
CSDL_Ext::blitSurface(box[4], &srcR, ret, &dstR);
|
|
|
|
|
|
|
|
// Right border
|
|
|
|
dstR.x = right_x;
|
|
|
|
CSDL_Ext::blitSurface(box[5], &srcR, ret, &dstR);
|
|
|
|
|
|
|
|
start_y += cur_h;
|
2008-12-08 00:38:04 +02:00
|
|
|
}
|
2011-09-25 21:44:13 +03:00
|
|
|
|
2008-12-08 00:38:04 +02:00
|
|
|
//corners
|
2011-12-22 16:05:19 +03:00
|
|
|
Rect dstR(x, y, box[0]->w, box[0]->h);
|
2013-06-26 14:18:27 +03:00
|
|
|
CSDL_Ext::blitSurface(box[0], nullptr, ret, &dstR);
|
2011-01-01 22:26:39 +02:00
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
dstR=Rect(x+w-box[1]->w, y, box[1]->w, box[1]->h);
|
2013-06-26 14:18:27 +03:00
|
|
|
CSDL_Ext::blitSurface(box[1], nullptr, ret, &dstR);
|
2011-01-01 22:26:39 +02:00
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
dstR=Rect(x, y+h-box[2]->h+1, box[2]->w, box[2]->h);
|
2013-06-26 14:18:27 +03:00
|
|
|
CSDL_Ext::blitSurface(box[2], nullptr, ret, &dstR);
|
2011-01-01 22:26:39 +02:00
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
dstR=Rect(x+w-box[3]->w, y+h-box[3]->h+1, box[3]->w, box[3]->h);
|
2013-06-26 14:18:27 +03:00
|
|
|
CSDL_Ext::blitSurface(box[3], nullptr, ret, &dstR);
|
2009-03-27 01:05:40 +02:00
|
|
|
}
|
|
|
|
|
2012-05-13 18:04:21 +03:00
|
|
|
ComponentResolved::ComponentResolved( CComponent *Comp ):
|
|
|
|
comp(Comp)
|
2009-03-27 01:05:40 +02:00
|
|
|
{
|
2012-05-13 18:04:21 +03:00
|
|
|
//Temporary assign ownership on comp
|
|
|
|
if (parent)
|
|
|
|
parent->removeChild(this);
|
|
|
|
if (comp->parent)
|
|
|
|
{
|
|
|
|
comp->parent->addChild(this);
|
|
|
|
comp->parent->removeChild(comp);
|
|
|
|
}
|
2009-03-27 01:05:40 +02:00
|
|
|
|
2012-05-13 18:04:21 +03:00
|
|
|
addChild(comp);
|
|
|
|
defActions = 255 - DISPOSE;
|
|
|
|
pos.x = pos.y = 0;
|
|
|
|
|
2012-07-03 00:51:48 +03:00
|
|
|
pos.w = comp->pos.w;
|
|
|
|
pos.h = comp->pos.h;
|
2009-03-27 01:05:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ComponentResolved::~ComponentResolved()
|
|
|
|
{
|
2012-05-13 18:04:21 +03:00
|
|
|
if (parent)
|
|
|
|
{
|
|
|
|
removeChild(comp);
|
|
|
|
parent->addChild(comp);
|
|
|
|
}
|
2009-03-27 01:05:40 +02:00
|
|
|
}
|
|
|
|
|
2012-05-13 18:04:21 +03:00
|
|
|
void ComponentResolved::showAll(SDL_Surface *to)
|
|
|
|
{
|
|
|
|
CIntObject::showAll(to);
|
|
|
|
comp->showAll(to);
|
|
|
|
}
|
|
|
|
|
2009-03-27 01:05:40 +02:00
|
|
|
ComponentsToBlit::~ComponentsToBlit()
|
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & elem : comps)
|
|
|
|
for(size_t j = 0; j < elem.size(); j++)
|
|
|
|
delete elem[j];
|
2009-03-27 01:05:40 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-12-19 20:24:53 +03:00
|
|
|
ComponentsToBlit::ComponentsToBlit(std::vector<CComponent*> & SComps, int maxw, bool blitOr)
|
2009-03-27 01:05:40 +02:00
|
|
|
{
|
2012-12-19 20:24:53 +03:00
|
|
|
int orWidth = graphics->fonts[FONT_MEDIUM]->getStringWidth(CGI->generaltexth->allTexts[4]);
|
|
|
|
|
2009-03-27 01:05:40 +02:00
|
|
|
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
|
|
|
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & SComp : SComps)
|
2009-03-27 01:05:40 +02:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
auto cur = new ComponentResolved(SComp);
|
2009-04-21 01:57:07 +03:00
|
|
|
|
2012-12-19 20:24:53 +03:00
|
|
|
int toadd = (cur->pos.w + BETWEEN_COMPS + (blitOr ? orWidth : 0));
|
2009-03-27 01:05:40 +02:00
|
|
|
if (curw + toadd > maxw)
|
|
|
|
{
|
2009-04-16 14:14:13 +03:00
|
|
|
curr++;
|
2011-12-14 00:23:17 +03:00
|
|
|
vstd::amax(w,curw);
|
2012-05-13 18:04:21 +03:00
|
|
|
curw = cur->pos.w;
|
2009-03-27 01:05:40 +02:00
|
|
|
comps.resize(curr+1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
curw += toadd;
|
2011-12-14 00:23:17 +03:00
|
|
|
vstd::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
|
|
|
}
|
|
|
|
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & elem : comps)
|
2009-03-27 01:05:40 +02:00
|
|
|
{
|
2012-05-13 18:04:21 +03:00
|
|
|
int maxHeight = 0;
|
2013-06-29 16:05:48 +03:00
|
|
|
for(size_t j=0;j<elem.size();j++)
|
|
|
|
vstd::amax(maxHeight, elem[j]->pos.h);
|
2012-05-13 18:04:21 +03:00
|
|
|
|
|
|
|
h += maxHeight + BETWEEN_COMPS_ROWS;
|
2009-03-27 01:05:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-19 20:24:53 +03:00
|
|
|
void ComponentsToBlit::blitCompsOnSur( bool blitOr, int inter, int &curh, SDL_Surface *ret )
|
2009-03-27 01:05:40 +02:00
|
|
|
{
|
2012-12-19 20:24:53 +03:00
|
|
|
int orWidth = graphics->fonts[FONT_MEDIUM]->getStringWidth(CGI->generaltexth->allTexts[4]);
|
|
|
|
|
2013-06-29 16:05:48 +03:00
|
|
|
for (auto & elem : comps)//for each row
|
2009-03-27 01:05:40 +02:00
|
|
|
{
|
2012-05-13 18:04:21 +03:00
|
|
|
int totalw=0, maxHeight=0;
|
2013-06-29 16:05:48 +03:00
|
|
|
for(size_t j=0;j<elem.size();j++)//find max height & total width in this row
|
2009-03-27 01:05:40 +02:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
ComponentResolved *cur = elem[j];
|
2012-05-13 18:04:21 +03:00
|
|
|
totalw += cur->pos.w;
|
|
|
|
vstd::amax(maxHeight, cur->pos.h);
|
2009-03-27 01:05:40 +02:00
|
|
|
}
|
2012-05-13 18:04:21 +03:00
|
|
|
|
|
|
|
//add space between comps in this row
|
2012-12-19 20:24:53 +03:00
|
|
|
if(blitOr)
|
2013-06-29 16:05:48 +03:00
|
|
|
totalw += (inter*2+orWidth) * (elem.size() - 1);
|
2012-05-13 18:04:21 +03:00
|
|
|
else
|
2013-06-29 16:05:48 +03:00
|
|
|
totalw += (inter) * (elem.size() - 1);
|
2011-03-20 00:27:05 +02:00
|
|
|
|
2012-05-13 18:04:21 +03:00
|
|
|
int middleh = curh + maxHeight/2;//axis for image aligment
|
|
|
|
int curw = ret->w/2 - totalw/2;
|
2011-01-01 22:26:39 +02:00
|
|
|
|
2013-06-29 16:05:48 +03:00
|
|
|
for(size_t j=0;j<elem.size();j++)
|
2009-03-27 01:05:40 +02:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
ComponentResolved *cur = elem[j];
|
2012-05-13 18:04:21 +03:00
|
|
|
cur->moveTo(Point(curw, curh));
|
2009-03-27 01:05:40 +02:00
|
|
|
|
2012-05-13 18:04:21 +03:00
|
|
|
//blit component
|
|
|
|
cur->showAll(ret);
|
|
|
|
curw += cur->pos.w;
|
2009-03-27 01:05:40 +02:00
|
|
|
|
|
|
|
//if there is subsequent component blit "or"
|
2013-06-29 16:05:48 +03:00
|
|
|
if(j<(elem.size()-1))
|
2009-03-27 01:05:40 +02:00
|
|
|
{
|
2012-12-19 20:24:53 +03:00
|
|
|
if(blitOr)
|
2009-03-27 01:05:40 +02:00
|
|
|
{
|
|
|
|
curw+=inter;
|
2012-12-19 20:24:53 +03:00
|
|
|
|
|
|
|
graphics->fonts[FONT_MEDIUM]->renderTextLeft(ret, CGI->generaltexth->allTexts[4], Colors::WHITE,
|
|
|
|
Point(curw,middleh-(graphics->fonts[FONT_MEDIUM]->getLineHeight()/2)));
|
|
|
|
|
|
|
|
curw+=orWidth;
|
2009-03-27 01:05:40 +02:00
|
|
|
}
|
|
|
|
curw+=inter;
|
|
|
|
}
|
|
|
|
}
|
2012-05-13 18:04:21 +03:00
|
|
|
curh += maxHeight + BETWEEN_COMPS_ROWS;
|
2009-03-27 01:05:40 +02:00
|
|
|
}
|
2009-06-01 08:40:54 +03:00
|
|
|
}
|