mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	A patch from Gernsworth that fixes #166. CGStatusBar is extended to support alignment, old CStatusBar class is removed.
This commit is contained in:
		| @@ -109,7 +109,7 @@ public: | ||||
| 	SDL_Surface * bg; | ||||
| 	std::vector<CDefHandler *> gems; | ||||
| 	CMinimap minimap; | ||||
| 	CStatusBar statusbar; | ||||
| 	CGStatusBar statusbar; | ||||
|  | ||||
| 	CAdventureMapButton kingOverview,//- kingdom overview | ||||
| 		underground,//- underground switch | ||||
|   | ||||
| @@ -54,7 +54,6 @@ class CInGameConsole; | ||||
| class CGarrisonInt; | ||||
| class CInGameConsole; | ||||
| union SDL_Event; | ||||
| class IStatusBar; | ||||
| class CInfoWindow; | ||||
| class IShowActivatable; | ||||
| class ClickableL; | ||||
|   | ||||
| @@ -158,31 +158,31 @@ CSpellWindow::CSpellWindow(const SDL_Rect &, const CGHeroInstance * _myHero, CPl | ||||
|  | ||||
|  | ||||
|  | ||||
| 	statusBar = new CStatusBar(7 + pos.x, 569 + pos.y, "Spelroll.bmp"); | ||||
| 	statusBar = new CGStatusBar(7 + pos.x, 569 + pos.y, "Spelroll.bmp"); | ||||
| 	SDL_Rect temp_rect = genRect(45, 35, 479 + pos.x, 405 + pos.y); | ||||
| 	exitBtn = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fexitb, this), CGI->generaltexth->zelp[460].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[460].first)), boost::bind(&CStatusBar::clear, statusBar), myInt); | ||||
| 	exitBtn = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fexitb, this), CGI->generaltexth->zelp[460].second, boost::bind(&CGStatusBar::print, statusBar, (CGI->generaltexth->zelp[460].first)), boost::bind(&CGStatusBar::clear, statusBar), myInt); | ||||
| 	temp_rect = genRect(45, 35, 221 + pos.x, 405 + pos.y); | ||||
| 	battleSpells = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fbattleSpellsb, this), CGI->generaltexth->zelp[453].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[453].first)), boost::bind(&CStatusBar::clear, statusBar), myInt); | ||||
| 	battleSpells = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fbattleSpellsb, this), CGI->generaltexth->zelp[453].second, boost::bind(&CGStatusBar::print, statusBar, (CGI->generaltexth->zelp[453].first)), boost::bind(&CGStatusBar::clear, statusBar), myInt); | ||||
| 	temp_rect = genRect(45, 35, 355 + pos.x, 405 + pos.y); | ||||
| 	adventureSpells = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fadvSpellsb, this), CGI->generaltexth->zelp[452].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[452].first)), boost::bind(&CStatusBar::clear, statusBar), myInt); | ||||
| 	adventureSpells = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fadvSpellsb, this), CGI->generaltexth->zelp[452].second, boost::bind(&CGStatusBar::print, statusBar, (CGI->generaltexth->zelp[452].first)), boost::bind(&CGStatusBar::clear, statusBar), myInt); | ||||
| 	temp_rect = genRect(45, 35, 418 + pos.x, 405 + pos.y); | ||||
| 	manaPoints = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fmanaPtsb, this), CGI->generaltexth->zelp[459].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[459].first)), boost::bind(&CStatusBar::clear, statusBar), myInt); | ||||
| 	manaPoints = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fmanaPtsb, this), CGI->generaltexth->zelp[459].second, boost::bind(&CGStatusBar::print, statusBar, (CGI->generaltexth->zelp[459].first)), boost::bind(&CGStatusBar::clear, statusBar), myInt); | ||||
|  | ||||
| 	temp_rect = genRect(36, 56, 549 + pos.x, 94 + pos.y); | ||||
| 	selectSpellsA = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::selectSchool, this, 0), CGI->generaltexth->zelp[454].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[454].first)), boost::bind(&CStatusBar::clear, statusBar), myInt); | ||||
| 	selectSpellsA = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::selectSchool, this, 0), CGI->generaltexth->zelp[454].second, boost::bind(&CGStatusBar::print, statusBar, (CGI->generaltexth->zelp[454].first)), boost::bind(&CGStatusBar::clear, statusBar), myInt); | ||||
| 	temp_rect = genRect(36, 56, 549 + pos.x, 151 + pos.y); | ||||
| 	selectSpellsE = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::selectSchool, this, 3), CGI->generaltexth->zelp[457].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[457].first)), boost::bind(&CStatusBar::clear, statusBar), myInt); | ||||
| 	selectSpellsE = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::selectSchool, this, 3), CGI->generaltexth->zelp[457].second, boost::bind(&CGStatusBar::print, statusBar, (CGI->generaltexth->zelp[457].first)), boost::bind(&CGStatusBar::clear, statusBar), myInt); | ||||
| 	temp_rect = genRect(36, 56, 549 + pos.x, 210 + pos.y); | ||||
| 	selectSpellsF = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::selectSchool, this, 1), CGI->generaltexth->zelp[455].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[455].first)), boost::bind(&CStatusBar::clear, statusBar), myInt); | ||||
| 	selectSpellsF = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::selectSchool, this, 1), CGI->generaltexth->zelp[455].second, boost::bind(&CGStatusBar::print, statusBar, (CGI->generaltexth->zelp[455].first)), boost::bind(&CGStatusBar::clear, statusBar), myInt); | ||||
| 	temp_rect = genRect(36, 56, 549 + pos.x, 270 + pos.y); | ||||
| 	selectSpellsW = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::selectSchool, this, 2), CGI->generaltexth->zelp[456].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[456].first)), boost::bind(&CStatusBar::clear, statusBar), myInt); | ||||
| 	selectSpellsW = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::selectSchool, this, 2), CGI->generaltexth->zelp[456].second, boost::bind(&CGStatusBar::print, statusBar, (CGI->generaltexth->zelp[456].first)), boost::bind(&CGStatusBar::clear, statusBar), myInt); | ||||
| 	temp_rect = genRect(36, 56, 549 + pos.x, 330 + pos.y); | ||||
| 	selectSpellsAll = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::selectSchool, this, 4), CGI->generaltexth->zelp[458].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[458].first)), boost::bind(&CStatusBar::clear, statusBar), myInt); | ||||
| 	selectSpellsAll = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::selectSchool, this, 4), CGI->generaltexth->zelp[458].second, boost::bind(&CGStatusBar::print, statusBar, (CGI->generaltexth->zelp[458].first)), boost::bind(&CGStatusBar::clear, statusBar), myInt); | ||||
|  | ||||
| 	temp_rect = genRect(leftCorner->h, leftCorner->w, 97 + pos.x, 77 + pos.y); | ||||
| 	lCorner = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fLcornerb, this), CGI->generaltexth->zelp[450].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[450].first)), boost::bind(&CStatusBar::clear, statusBar), myInt); | ||||
| 	lCorner = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fLcornerb, this), CGI->generaltexth->zelp[450].second, boost::bind(&CGStatusBar::print, statusBar, (CGI->generaltexth->zelp[450].first)), boost::bind(&CGStatusBar::clear, statusBar), myInt); | ||||
| 	temp_rect = genRect(rightCorner->h, rightCorner->w, 487 + pos.x, 72 + pos.y); | ||||
| 	rCorner = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fRcornerb, this), CGI->generaltexth->zelp[451].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[451].first)), boost::bind(&CStatusBar::clear, statusBar), myInt); | ||||
| 	rCorner = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fRcornerb, this), CGI->generaltexth->zelp[451].second, boost::bind(&CGStatusBar::print, statusBar, (CGI->generaltexth->zelp[451].first)), boost::bind(&CGStatusBar::clear, statusBar), myInt); | ||||
|  | ||||
| 	//areas for spells | ||||
| 	int xpos = 117 + pos.x, ypos = 90 + pos.y; | ||||
|   | ||||
| @@ -17,7 +17,7 @@ struct SDL_Surface; | ||||
| class CDefHandler; | ||||
| struct SDL_Rect; | ||||
| class CGHeroInstance; | ||||
| class CStatusBar; | ||||
| class CGStatusBar; | ||||
| class CPlayerInterface; | ||||
|  | ||||
| /// Spellbook button is used by the spell window class | ||||
| @@ -71,7 +71,7 @@ private: | ||||
| 	SpellbookInteractiveArea * selectSpellsA, * selectSpellsE, * selectSpellsF, * selectSpellsW, * selectSpellsAll; | ||||
| 	SpellbookInteractiveArea * lCorner, * rCorner; | ||||
| 	SpellArea * spellAreas[12]; | ||||
| 	CStatusBar * statusBar; | ||||
| 	CGStatusBar * statusBar; | ||||
|  | ||||
| 	Uint8 sitesPerTabAdv[5]; | ||||
| 	Uint8 sitesPerTabBattle[5]; | ||||
|   | ||||
| @@ -3939,7 +3939,12 @@ void CInGameConsole::startEnteringText() | ||||
| 	enteredText = "_"; | ||||
| 	if(GH.topInt() == adventureInt) | ||||
| 	{ | ||||
|         GH.statusbar->alignment = TOPLEFT; | ||||
|         GH.statusbar->calcOffset(); | ||||
| 		GH.statusbar->print(enteredText); | ||||
|  | ||||
|         //Prevent changes to the text from mouse interaction with the adventure map | ||||
|         GH.statusbar->lock(true); | ||||
| 	} | ||||
| 	else if(LOCPLINT->battleInt) | ||||
| 	{ | ||||
| @@ -3960,7 +3965,10 @@ void CInGameConsole::endEnteringText(bool printEnteredText) | ||||
| 	enteredText = ""; | ||||
| 	if(GH.topInt() == adventureInt) | ||||
| 	{ | ||||
| 		GH.statusbar->clear(); | ||||
|         GH.statusbar->alignment = CENTER; | ||||
|         GH.statusbar->calcOffset(); | ||||
|         GH.statusbar->lock(false); | ||||
|         GH.statusbar->clear(); | ||||
| 	} | ||||
| 	else if(LOCPLINT->battleInt) | ||||
| 	{ | ||||
| @@ -3972,7 +3980,10 @@ void CInGameConsole::refreshEnteredText() | ||||
| { | ||||
| 	if(GH.topInt() == adventureInt) | ||||
| 	{ | ||||
|         GH.statusbar->lock(false); | ||||
|         GH.statusbar->clear(); | ||||
| 		GH.statusbar->print(enteredText); | ||||
|         GH.statusbar->lock(true); | ||||
| 	} | ||||
| 	else if(LOCPLINT->battleInt) | ||||
| 	{ | ||||
|   | ||||
| @@ -4,7 +4,7 @@ | ||||
| #include "Geometries.h" | ||||
|  | ||||
| class CFramerateManager; | ||||
| class IStatusBar; | ||||
| class CGStatusBar; | ||||
| class CIntObject; | ||||
| class IUpdateable; | ||||
| class IShowActivatable; | ||||
| @@ -43,7 +43,7 @@ class CGuiHandler | ||||
| public: | ||||
| 	CFramerateManager * mainFPSmng; //to keep const framerate | ||||
| 	std::list<IShowActivatable *> listInt; //list of interfaces - front=foreground; back = background (includes adventure map, window interfaces, all kind of active dialogs, and so on) | ||||
| 	IStatusBar * statusbar; | ||||
| 	CGStatusBar * statusbar; | ||||
|  | ||||
| private: | ||||
| 	typedef std::list<CIntObject*> CIntObjectList; | ||||
|   | ||||
| @@ -59,16 +59,6 @@ public: | ||||
| 	virtual ~IShowActivatable(){}; //d-tor | ||||
| }; | ||||
|  | ||||
| // Status bar interface | ||||
| class IStatusBar | ||||
| { | ||||
| public: | ||||
| 	virtual ~IStatusBar(){}; //d-tor | ||||
| 	virtual void print(const std::string & text)=0; //prints text and refreshes statusbar | ||||
| 	virtual void clear()=0;//clears statusbar and refreshes | ||||
| 	virtual std::string getCurrent()=0; //returns currently displayed text | ||||
| }; | ||||
|  | ||||
| //typedef ui16 ActivityFlag; | ||||
|  | ||||
| // Base UI element | ||||
|   | ||||
| @@ -1099,63 +1099,6 @@ CSimpleWindow::~CSimpleWindow() | ||||
| 	} | ||||
| } | ||||
|  | ||||
| CStatusBar::CStatusBar(int x, int y, std::string name, int maxw) | ||||
| { | ||||
| 	bg=BitmapHandler::loadBitmap(name); | ||||
| 	SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255)); | ||||
| 	pos.x += x; | ||||
| 	pos.y += y; | ||||
| 	if(maxw >= 0) | ||||
| 		pos.w = std::min(bg->w,maxw); | ||||
| 	else | ||||
| 		pos.w=bg->w; | ||||
| 	pos.h=bg->h; | ||||
| 	middlex=(pos.w/2)+pos.x; | ||||
| 	middley=(bg->h/2)+pos.y; | ||||
| } | ||||
|  | ||||
| CStatusBar::~CStatusBar() | ||||
| { | ||||
| 	SDL_FreeSurface(bg); | ||||
| } | ||||
|  | ||||
| void CStatusBar::clear() | ||||
| { | ||||
| 	if(LOCPLINT->cingconsole->enteredText == "") //for appropriate support for in-game console | ||||
| 	{ | ||||
| 		current=""; | ||||
| 		redraw(); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void CStatusBar::print(const std::string & text) | ||||
| { | ||||
| 	if(LOCPLINT->cingconsole->enteredText == "" || text == LOCPLINT->cingconsole->enteredText) //for appropriate support for in-game console | ||||
| 	{ | ||||
| 		current=text; | ||||
| 		redraw(); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void CStatusBar::showAll(SDL_Surface * to) | ||||
| { | ||||
| 	show(to); | ||||
| } | ||||
|  | ||||
| void CStatusBar::show(SDL_Surface * to) | ||||
| { | ||||
| 	SDL_Rect srcRect = genRect(pos.h,pos.w,0,0); | ||||
| 	SDL_Rect dstRect = genRect(pos.h,pos.w,pos.x,pos.y); | ||||
| 	CSDL_Ext::blitSurface(bg,&srcRect,to,&dstRect); | ||||
|  | ||||
| 	graphics->fonts[FONT_SMALL]->renderTextCenter(to, current, Colors::WHITE, Point(middlex, middley)); | ||||
| } | ||||
|  | ||||
| std::string CStatusBar::getCurrent() | ||||
| { | ||||
| 	return current; | ||||
| } | ||||
|  | ||||
| void CHoverableArea::hover (bool on) | ||||
| { | ||||
| 	if (on) | ||||
| @@ -1215,7 +1158,8 @@ void CLabel::showAll(SDL_Surface * to) | ||||
| 	if(!toPrint.length()) | ||||
| 		return; | ||||
|  | ||||
| 	blitLine(to, pos.topLeft()/2 + pos.bottomRight()/2, toPrint); | ||||
| 	//blitLine(to, pos.topLeft()/2 + pos.bottomRight()/2, toPrint); | ||||
|     blitLine(to, pos.topLeft() + textOffset, toPrint); | ||||
|  | ||||
| } | ||||
|  | ||||
| @@ -1439,14 +1383,18 @@ void CTextBox::sliderMoved(int to) | ||||
| 	redraw(); | ||||
| } | ||||
|  | ||||
| const Point CGStatusBar::edgeOffset = Point(5, 1); | ||||
|  | ||||
| void CGStatusBar::print(const std::string & Text) | ||||
| { | ||||
| 	setTxt(Text); | ||||
|     if(!textLock) | ||||
| 	    setTxt(Text); | ||||
| } | ||||
|  | ||||
| void CGStatusBar::clear() | ||||
| { | ||||
| 	setTxt(""); | ||||
|     if(!textLock) | ||||
| 	    setTxt(""); | ||||
| } | ||||
|  | ||||
| std::string CGStatusBar::getCurrent() | ||||
| @@ -1468,6 +1416,7 @@ CGStatusBar::CGStatusBar(CPicture *BG, EFonts Font /*= FONT_SMALL*/, EAlignment | ||||
| 	addChild(bg); | ||||
| 	pos = bg->pos; | ||||
| 	calcOffset(); | ||||
|     textLock = false; | ||||
| } | ||||
|  | ||||
| CGStatusBar::CGStatusBar(int x, int y, std::string name/*="ADROLLVR.bmp"*/, int maxw/*=-1*/) | ||||
| @@ -1477,12 +1426,13 @@ CGStatusBar::CGStatusBar(int x, int y, std::string name/*="ADROLLVR.bmp"*/, int | ||||
| 	init(); | ||||
| 	bg = new CPicture(name); | ||||
| 	pos = bg->pos; | ||||
| 	if(maxw < pos.w) | ||||
| 	if((unsigned int)maxw < pos.w) | ||||
| 	{ | ||||
| 		vstd::amin(pos.w, maxw); | ||||
| 		bg->srcRect = new Rect(0, 0, maxw, pos.h); | ||||
| 	} | ||||
| 	calcOffset(); | ||||
|     textLock = false; | ||||
| } | ||||
|  | ||||
| CGStatusBar::~CGStatusBar() | ||||
| @@ -1492,7 +1442,7 @@ CGStatusBar::~CGStatusBar() | ||||
|  | ||||
| void CGStatusBar::show(SDL_Surface * to) | ||||
| { | ||||
|  | ||||
|     showAll(to); | ||||
| } | ||||
|  | ||||
| void CGStatusBar::init() | ||||
| @@ -1505,15 +1455,23 @@ void CGStatusBar::calcOffset() | ||||
| { | ||||
| 	switch(alignment) | ||||
| 	{ | ||||
| 	case TOPLEFT: | ||||
| 		textOffset = Point(edgeOffset.x, edgeOffset.y); | ||||
| 		break; | ||||
| 	case CENTER: | ||||
| 		textOffset = Point(pos.w/2, pos.h/2); | ||||
| 		break; | ||||
| 	case BOTTOMRIGHT: | ||||
| 		textOffset = Point(pos.w, pos.h); | ||||
| 		textOffset = Point(pos.w - edgeOffset.x, pos.h - edgeOffset.y); | ||||
| 		break; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void CGStatusBar::lock(bool shouldLock) | ||||
| { | ||||
|     textLock = shouldLock; | ||||
| } | ||||
|  | ||||
| CTextInput::CTextInput(const Rect &Pos, EFonts font, const CFunctionList<void(const std::string &)> &CB): | ||||
|     CLabel(Pos.x, Pos.y, font, CENTER), | ||||
|     cb(CB) | ||||
|   | ||||
| @@ -312,23 +312,6 @@ public: | ||||
| 	size_t getPos(); | ||||
| }; | ||||
|  | ||||
| /// Status bar which is shown at the bottom of the in-game screens | ||||
| class CStatusBar : public CIntObject, public IStatusBar | ||||
| { | ||||
| public: | ||||
| 	SDL_Surface * bg; //background | ||||
| 	int middlex, middley; //middle of statusbar | ||||
| 	std::string current; //text currently printed | ||||
|  | ||||
| 	CStatusBar(int x, int y, std::string name="ADROLLVR.bmp", int maxw=-1); //c-tor | ||||
| 	~CStatusBar(); //d-tor | ||||
| 	void print(const std::string & text); //prints text and refreshes statusbar | ||||
| 	void clear();//clears statusbar and refreshes | ||||
| 	void showAll(SDL_Surface * to); //shows statusbar (with current text) | ||||
| 	void show(SDL_Surface * to); | ||||
| 	std::string getCurrent(); //getter for current | ||||
| }; | ||||
|  | ||||
| class CTextContainer : public virtual CIntObject | ||||
| { | ||||
| protected: | ||||
| @@ -409,11 +392,12 @@ public: | ||||
| }; | ||||
|  | ||||
| /// Status bar which is shown at the bottom of the in-game screens | ||||
| class CGStatusBar : public CLabel, public IStatusBar | ||||
| class CGStatusBar : public CLabel | ||||
| { | ||||
|     bool textLock; //Used for blocking changes to the text | ||||
| 	void init(); | ||||
| public: | ||||
| 	IStatusBar *oldStatusBar; | ||||
| 	CGStatusBar *oldStatusBar; | ||||
|  | ||||
| 	//statusbar interface overloads | ||||
| 	void print(const std::string & Text); //prints text and refreshes statusbar | ||||
| @@ -427,6 +411,10 @@ public: | ||||
|  | ||||
| 	~CGStatusBar(); | ||||
| 	void calcOffset(); | ||||
|  | ||||
|     void lock(bool shouldLock); //If true, current text cannot be changed until lock(false) is called | ||||
|  | ||||
|     const static Point edgeOffset; //Amount to move text from side when alignment is left or right | ||||
| }; | ||||
|  | ||||
| /// UIElement which can get input focus | ||||
|   | ||||
		Reference in New Issue
	
	Block a user