| 
									
										
										
										
											2017-07-13 11:26:03 +03:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * TextControls.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 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | #include "StdInc.h"
 | 
					
						
							|  |  |  | #include "TextControls.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-30 17:31:45 +03:00
										 |  |  | #include "Slider.h"
 | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | #include "Images.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-19 22:53:31 +02:00
										 |  |  | #include "../CPlayerInterface.h"
 | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | #include "../gui/CGuiHandler.h"
 | 
					
						
							| 
									
										
										
										
											2023-02-01 20:42:06 +02:00
										 |  |  | #include "../windows/CMessage.h"
 | 
					
						
							| 
									
										
										
										
											2023-08-26 14:01:19 +04:00
										 |  |  | #include "../windows/InfoWindows.h"
 | 
					
						
							| 
									
										
										
										
											2023-02-01 20:42:06 +02:00
										 |  |  | #include "../adventureMap/CInGameConsole.h"
 | 
					
						
							| 
									
										
										
										
											2023-02-02 21:15:13 +02:00
										 |  |  | #include "../renderSDL/SDL_Extensions.h"
 | 
					
						
							| 
									
										
										
										
											2023-06-02 16:42:18 +03:00
										 |  |  | #include "../render/Canvas.h"
 | 
					
						
							| 
									
										
										
										
											2023-07-31 19:50:55 +03:00
										 |  |  | #include "../render/Graphics.h"
 | 
					
						
							|  |  |  | #include "../render/IFont.h"
 | 
					
						
							| 
									
										
										
										
											2024-09-23 15:43:11 +00:00
										 |  |  | #include "../render/IRenderHandler.h"
 | 
					
						
							| 
									
										
										
										
											2023-02-02 21:15:13 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-20 12:55:17 +00:00
										 |  |  | #include "../../lib/texts/TextOperations.h"
 | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-23 19:23:48 +02:00
										 |  |  | #ifdef VCMI_ANDROID
 | 
					
						
							|  |  |  | #include "lib/CAndroidVMHelper.h"
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | std::string CLabel::visibleText() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return text; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-02 16:42:18 +03:00
										 |  |  | void CLabel::showAll(Canvas & to) | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | { | 
					
						
							|  |  |  | 	CIntObject::showAll(to); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(!visibleText().empty()) | 
					
						
							|  |  |  | 		blitLine(to, pos, visibleText()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-07 23:42:48 +01:00
										 |  |  | CLabel::CLabel(int x, int y, EFonts Font, ETextAlignment Align, const ColorRGBA & Color, const std::string & Text, int maxWidth) | 
					
						
							|  |  |  | 	: CTextContainer(Align, Font, Color), text(Text), maxWidth(maxWidth) | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-07-03 19:24:12 +03:00
										 |  |  | 	setRedrawParent(true); | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 	autoRedraw = true; | 
					
						
							|  |  |  | 	pos.x += x; | 
					
						
							|  |  |  | 	pos.y += y; | 
					
						
							|  |  |  | 	pos.w = pos.h = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-07 23:42:48 +01:00
										 |  |  | 	trimText(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-26 23:12:20 +02:00
										 |  |  | 	if(alignment == ETextAlignment::TOPLEFT) // causes issues for MIDDLE
 | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2024-09-23 15:43:11 +00:00
										 |  |  | 		const auto & fontPtr = GH.renderHandler().loadFont(font); | 
					
						
							|  |  |  | 		pos.w = fontPtr->getStringWidth(visibleText().c_str()); | 
					
						
							|  |  |  | 		pos.h = fontPtr->getLineHeight(); | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Point CLabel::getBorderSize() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return Point(0, 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | std::string CLabel::getText() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return text; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-20 15:19:33 +07:00
										 |  |  | void CLabel::setAutoRedraw(bool value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	autoRedraw = value; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-07 12:56:34 +03:00
										 |  |  | void CLabel::setText(const std::string & Txt) | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-03-21 18:00:05 +02:00
										 |  |  | 	assert(TextOperations::isValidUnicodeString(Txt)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 	text = Txt; | 
					
						
							| 
									
										
										
										
											2024-01-07 23:42:48 +01:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	trimText(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 	if(autoRedraw) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-04-07 14:34:11 +03:00
										 |  |  | 		if(background || !parent) | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 			redraw(); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			parent->redraw(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-27 13:39:50 +02:00
										 |  |  | void CLabel::clear() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	text.clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(autoRedraw) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if(background || !parent) | 
					
						
							|  |  |  | 			redraw(); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			parent->redraw(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-08 00:08:05 +01:00
										 |  |  | void CLabel::setMaxWidth(int width) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	maxWidth = width; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-07 23:42:48 +01:00
										 |  |  | void CLabel::trimText() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if(maxWidth > 0) | 
					
						
							| 
									
										
										
										
											2024-09-23 15:43:11 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		const auto & fontPtr = GH.renderHandler().loadFont(font); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		while (fontPtr->getStringWidth(visibleText().c_str()) > maxWidth) | 
					
						
							| 
									
										
										
										
											2024-01-07 23:42:48 +01:00
										 |  |  | 			TextOperations::trimRightUnicode(text); | 
					
						
							| 
									
										
										
										
											2024-09-23 15:43:11 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-01-07 23:42:48 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-31 19:50:55 +03:00
										 |  |  | void CLabel::setColor(const ColorRGBA & Color) | 
					
						
							| 
									
										
										
										
											2018-03-20 15:19:33 +07:00
										 |  |  | { | 
					
						
							|  |  |  | 	color = Color; | 
					
						
							|  |  |  | 	if(autoRedraw) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-04-07 14:34:11 +03:00
										 |  |  | 		if(background || !parent) | 
					
						
							| 
									
										
										
										
											2018-03-20 15:19:33 +07:00
										 |  |  | 			redraw(); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			parent->redraw(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | size_t CLabel::getWidth() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-09-23 15:43:11 +00:00
										 |  |  | 	const auto & fontPtr = GH.renderHandler().loadFont(font); | 
					
						
							|  |  |  | 	return fontPtr->getStringWidth(visibleText()); | 
					
						
							| 
									
										
										
										
											2018-03-20 15:19:33 +07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-31 19:50:55 +03:00
										 |  |  | CMultiLineLabel::CMultiLineLabel(Rect position, EFonts Font, ETextAlignment Align, const ColorRGBA & Color, const std::string & Text) : | 
					
						
							| 
									
										
										
										
											2016-03-12 04:41:27 +03:00
										 |  |  | 	CLabel(position.x, position.y, Font, Align, Color, Text), | 
					
						
							|  |  |  | 	visibleSize(0, 0, position.w, position.h) | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | { | 
					
						
							|  |  |  | 	pos.w = position.w; | 
					
						
							|  |  |  | 	pos.h = position.h; | 
					
						
							| 
									
										
										
										
											2019-04-20 18:26:54 +02:00
										 |  |  | 	splitText(Text, true); | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-20 18:26:54 +02:00
										 |  |  | void CMultiLineLabel::setVisibleSize(Rect visibleSize, bool redrawElement) | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | { | 
					
						
							|  |  |  | 	this->visibleSize = visibleSize; | 
					
						
							| 
									
										
										
										
											2019-04-20 18:26:54 +02:00
										 |  |  | 	if(redrawElement) | 
					
						
							|  |  |  | 		redraw(); | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CMultiLineLabel::scrollTextBy(int distance) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	scrollTextTo(visibleSize.y + distance); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-20 18:26:54 +02:00
										 |  |  | void CMultiLineLabel::scrollTextTo(int distance, bool redrawAfterScroll) | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | { | 
					
						
							|  |  |  | 	Rect size = visibleSize; | 
					
						
							|  |  |  | 	size.y = distance; | 
					
						
							| 
									
										
										
										
											2019-04-20 18:26:54 +02:00
										 |  |  | 	setVisibleSize(size, redrawAfterScroll); | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-07 12:56:34 +03:00
										 |  |  | void CMultiLineLabel::setText(const std::string & Txt) | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-20 18:26:54 +02:00
										 |  |  | 	splitText(Txt, false); //setText used below can handle redraw
 | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 	CLabel::setText(Txt); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-14 23:26:24 +02:00
										 |  |  | std::vector<std::string> CMultiLineLabel::getLines() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return lines; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-02 16:42:18 +03:00
										 |  |  | void CTextContainer::blitLine(Canvas & to, Rect destRect, std::string what) | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-09-23 15:43:11 +00:00
										 |  |  | 	const auto f = GH.renderHandler().loadFont(font); | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 	Point where = destRect.topLeft(); | 
					
						
							| 
									
										
										
										
											2024-06-24 03:23:26 +02:00
										 |  |  | 	const std::string delimiters = "{}"; | 
					
						
							|  |  |  | 	auto delimitersCount = std::count_if(what.cbegin(), what.cend(), [&delimiters](char c) | 
					
						
							| 
									
										
										
										
											2023-03-15 14:35:55 +03:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2024-06-24 03:23:26 +02:00
										 |  |  | 		return delimiters.find(c) != std::string::npos; | 
					
						
							| 
									
										
										
										
											2023-03-15 14:35:55 +03:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 	//We should count delimiters length from string to correct centering later.
 | 
					
						
							| 
									
										
										
										
											2024-06-24 03:23:26 +02:00
										 |  |  | 	delimitersCount *= f->getStringWidth(delimiters)/2; | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-12 15:28:09 +02:00
										 |  |  | 	std::smatch match; | 
					
						
							| 
									
										
										
										
											2023-09-13 02:04:59 +02:00
										 |  |  | 	std::regex expr("\\{(.*?)\\|"); | 
					
						
							| 
									
										
										
										
											2023-09-12 15:28:09 +02:00
										 |  |  | 	std::string::const_iterator searchStart( what.cbegin() ); | 
					
						
							|  |  |  | 	while(std::regex_search(searchStart, what.cend(), match, expr)) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2023-09-13 02:04:59 +02:00
										 |  |  | 		std::string colorText = match[1].str(); | 
					
						
							| 
									
										
										
										
											2023-09-13 16:02:54 +02:00
										 |  |  | 		if(auto c = Colors::parseColor(colorText)) | 
					
						
							| 
									
										
										
										
											2023-09-13 02:04:59 +02:00
										 |  |  | 			delimitersCount += f->getStringWidth(colorText + "|"); | 
					
						
							| 
									
										
										
										
											2023-09-12 15:28:09 +02:00
										 |  |  | 		searchStart = match.suffix().first; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 	// input is rect in which given text should be placed
 | 
					
						
							|  |  |  | 	// calculate proper position for top-left corner of the text
 | 
					
						
							| 
									
										
										
										
											2024-03-13 23:02:45 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if(alignment == ETextAlignment::TOPLEFT || alignment == ETextAlignment::CENTERLEFT  || alignment == ETextAlignment::BOTTOMLEFT) | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 		where.x += getBorderSize().x; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-13 23:02:45 +02:00
										 |  |  | 	if(alignment == ETextAlignment::CENTER || alignment == ETextAlignment::TOPCENTER || alignment == ETextAlignment::BOTTOMCENTER) | 
					
						
							|  |  |  | 		where.x += (destRect.w - (static_cast<int>(f->getStringWidth(what)) - delimitersCount)) / 2; | 
					
						
							| 
									
										
										
										
											2024-03-12 19:52:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-13 23:02:45 +02:00
										 |  |  | 	if(alignment == ETextAlignment::TOPRIGHT || alignment == ETextAlignment::BOTTOMRIGHT || alignment == ETextAlignment::CENTERRIGHT) | 
					
						
							|  |  |  | 		where.x += getBorderSize().x + destRect.w - (static_cast<int>(f->getStringWidth(what)) - delimitersCount); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(alignment == ETextAlignment::TOPLEFT || alignment == ETextAlignment::TOPCENTER || alignment == ETextAlignment::TOPRIGHT) | 
					
						
							| 
									
										
										
										
											2024-03-12 19:52:42 +02:00
										 |  |  | 		where.y += getBorderSize().y; | 
					
						
							| 
									
										
										
										
											2023-08-30 00:35:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-13 23:02:45 +02:00
										 |  |  | 	if(alignment == ETextAlignment::CENTERLEFT || alignment == ETextAlignment::CENTER || alignment == ETextAlignment::CENTERRIGHT) | 
					
						
							|  |  |  | 		where.y += (destRect.h - static_cast<int>(f->getLineHeight())) / 2; | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-13 23:02:45 +02:00
										 |  |  | 	if(alignment == ETextAlignment::BOTTOMLEFT || alignment == ETextAlignment::BOTTOMCENTER || alignment == ETextAlignment::BOTTOMRIGHT) | 
					
						
							|  |  |  | 		where.y += getBorderSize().y + destRect.h - static_cast<int>(f->getLineHeight()); | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	size_t begin = 0; | 
					
						
							| 
									
										
										
										
											2024-06-24 03:23:26 +02:00
										 |  |  | 	size_t currDelimiter = 0; | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	do | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2024-06-24 03:23:26 +02:00
										 |  |  | 		size_t end = what.find_first_of(delimiters[currDelimiter % 2], begin); | 
					
						
							| 
									
										
										
										
											2022-05-07 12:56:34 +03:00
										 |  |  | 		if(begin != end) | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			std::string toPrint = what.substr(begin, end - begin); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-24 03:23:26 +02:00
										 |  |  | 			if(currDelimiter % 2) // Enclosed in {} text - set to yellow or defined color
 | 
					
						
							| 
									
										
										
										
											2023-09-12 15:28:09 +02:00
										 |  |  | 			{ | 
					
						
							|  |  |  | 				std::smatch match; | 
					
						
							| 
									
										
										
										
											2023-09-13 02:04:59 +02:00
										 |  |  |    				std::regex expr("^(.*?)\\|"); | 
					
						
							| 
									
										
										
										
											2023-09-12 15:28:09 +02:00
										 |  |  | 				if(std::regex_search(toPrint, match, expr)) | 
					
						
							|  |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2023-09-13 02:04:59 +02:00
										 |  |  | 					std::string colorText = match[1].str(); | 
					
						
							|  |  |  | 					 | 
					
						
							| 
									
										
										
										
											2023-09-13 16:02:54 +02:00
										 |  |  | 					if(auto color = Colors::parseColor(colorText)) | 
					
						
							| 
									
										
										
										
											2023-09-13 02:04:59 +02:00
										 |  |  | 					{ | 
					
						
							|  |  |  | 						toPrint = toPrint.substr(colorText.length() + 1, toPrint.length() - colorText.length()); | 
					
						
							| 
									
										
										
										
											2023-09-13 16:02:54 +02:00
										 |  |  | 						to.drawText(where, font, *color, ETextAlignment::TOPLEFT, toPrint); | 
					
						
							| 
									
										
										
										
											2023-09-13 02:04:59 +02:00
										 |  |  | 					} | 
					
						
							|  |  |  | 					else | 
					
						
							|  |  |  | 						to.drawText(where, font, Colors::YELLOW, ETextAlignment::TOPLEFT, toPrint); | 
					
						
							| 
									
										
										
										
											2023-09-12 15:28:09 +02:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				else | 
					
						
							|  |  |  | 					to.drawText(where, font, Colors::YELLOW, ETextAlignment::TOPLEFT, toPrint); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 			else // Non-enclosed text, use default color
 | 
					
						
							| 
									
										
										
										
											2023-06-02 16:42:18 +03:00
										 |  |  | 				to.drawText(where, font, color, ETextAlignment::TOPLEFT, toPrint); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 			begin = end; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-01 01:38:06 -07:00
										 |  |  | 			where.x += (int)f->getStringWidth(toPrint); | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2024-06-24 03:23:26 +02:00
										 |  |  | 		currDelimiter++; | 
					
						
							| 
									
										
										
										
											2022-05-07 12:56:34 +03:00
										 |  |  | 	} while(begin++ != std::string::npos); | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-31 19:50:55 +03:00
										 |  |  | CTextContainer::CTextContainer(ETextAlignment alignment, EFonts font, ColorRGBA color) : | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 	alignment(alignment), | 
					
						
							|  |  |  | 	font(font), | 
					
						
							|  |  |  | 	color(color) | 
					
						
							| 
									
										
										
										
											2022-05-07 12:56:34 +03:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-02 16:42:18 +03:00
										 |  |  | void CMultiLineLabel::showAll(Canvas & to) | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | { | 
					
						
							|  |  |  | 	CIntObject::showAll(to); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-23 15:43:11 +00:00
										 |  |  | 	const auto & fontPtr = GH.renderHandler().loadFont(font); | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// calculate which lines should be visible
 | 
					
						
							| 
									
										
										
										
											2020-10-01 01:38:06 -07:00
										 |  |  | 	int totalLines = static_cast<int>(lines.size()); | 
					
						
							| 
									
										
										
										
											2022-05-07 12:56:34 +03:00
										 |  |  | 	int beginLine = visibleSize.y; | 
					
						
							|  |  |  | 	int endLine = getTextLocation().h + visibleSize.y; | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-07 12:56:34 +03:00
										 |  |  | 	if(beginLine < 0) | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 		beginLine = 0; | 
					
						
							|  |  |  | 	else | 
					
						
							| 
									
										
										
										
											2024-09-23 15:43:11 +00:00
										 |  |  | 		beginLine /= fontPtr->getLineHeight(); | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-07 12:56:34 +03:00
										 |  |  | 	if(endLine < 0) | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 		endLine = 0; | 
					
						
							|  |  |  | 	else | 
					
						
							| 
									
										
										
										
											2024-09-23 15:43:11 +00:00
										 |  |  | 		endLine /= fontPtr->getLineHeight(); | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 	endLine++; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// and where they should be displayed
 | 
					
						
							| 
									
										
										
										
											2024-09-23 15:43:11 +00:00
										 |  |  | 	Point lineStart = getTextLocation().topLeft() - visibleSize + Point(0, beginLine * fontPtr->getLineHeight()); | 
					
						
							|  |  |  | 	Point lineSize = Point(getTextLocation().w, fontPtr->getLineHeight()); | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-02 16:42:18 +03:00
										 |  |  | 	CSDL_Ext::CClipRectGuard guard(to.getInternalSurface(), getTextLocation()); // to properly trim text that is too big to fit
 | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-07 12:56:34 +03:00
										 |  |  | 	for(int i = beginLine; i < std::min(totalLines, endLine); i++) | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2022-05-07 12:56:34 +03:00
										 |  |  | 		if(!lines[i].empty()) //non-empty line
 | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 			blitLine(to, Rect(lineStart, lineSize), lines[i]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-23 15:43:11 +00:00
										 |  |  | 		lineStart.y += fontPtr->getLineHeight(); | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-07 12:56:34 +03:00
										 |  |  | void CMultiLineLabel::splitText(const std::string & Txt, bool redrawAfter) | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | { | 
					
						
							|  |  |  | 	lines.clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-23 15:43:11 +00:00
										 |  |  | 	const auto & fontPtr = GH.renderHandler().loadFont(font); | 
					
						
							| 
									
										
										
										
											2024-10-10 20:31:11 +00:00
										 |  |  | 	int lineHeight = fontPtr->getLineHeight(); | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	lines = CMessage::breakText(Txt, pos.w, font); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-07 12:56:34 +03:00
										 |  |  | 	textSize.y = lineHeight * (int)lines.size(); | 
					
						
							|  |  |  | 	textSize.x = 0; | 
					
						
							|  |  |  | 	for(const std::string & line : lines) | 
					
						
							| 
									
										
										
										
											2024-09-23 15:43:11 +00:00
										 |  |  | 		vstd::amax(textSize.x, fontPtr->getStringWidth(line.c_str())); | 
					
						
							| 
									
										
										
										
											2019-04-20 18:26:54 +02:00
										 |  |  | 	if(redrawAfter) | 
					
						
							|  |  |  | 		redraw(); | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Rect CMultiLineLabel::getTextLocation() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// this method is needed for vertical alignment alignment of text
 | 
					
						
							|  |  |  | 	// when height of available text is smaller than height of widget
 | 
					
						
							|  |  |  | 	// in this case - we should add proper offset to display text at required position
 | 
					
						
							| 
									
										
										
										
											2022-05-07 12:56:34 +03:00
										 |  |  | 	if(pos.h <= textSize.y) | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 		return pos; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-23 15:43:11 +00:00
										 |  |  | 	const auto & fontPtr = GH.renderHandler().loadFont(font); | 
					
						
							| 
									
										
										
										
											2024-10-10 20:31:11 +00:00
										 |  |  | 	Point textSizeComputed(pos.w, fontPtr->getLineHeight() * lines.size()); //FIXME: how is this different from textSize member?
 | 
					
						
							|  |  |  | 	Point textOffset(pos.w - textSizeComputed.x, pos.h - textSizeComputed.y); | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	switch(alignment) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2024-10-10 20:31:11 +00:00
										 |  |  | 	case ETextAlignment::TOPLEFT:     return Rect(pos.topLeft(), textSizeComputed); | 
					
						
							|  |  |  | 	case ETextAlignment::TOPCENTER:   return Rect(pos.topLeft(), textSizeComputed); | 
					
						
							|  |  |  | 	case ETextAlignment::CENTER:      return Rect(pos.topLeft() + textOffset / 2, textSizeComputed); | 
					
						
							|  |  |  | 	case ETextAlignment::CENTERRIGHT: return Rect(pos.topLeft() + Point(textOffset.x, textOffset.y / 2), textSizeComputed); | 
					
						
							|  |  |  | 	case ETextAlignment::BOTTOMRIGHT: return Rect(pos.topLeft() + textOffset, textSizeComputed); | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	assert(0); | 
					
						
							|  |  |  | 	return Rect(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-31 19:50:55 +03:00
										 |  |  | CLabelGroup::CLabelGroup(EFonts Font, ETextAlignment Align, const ColorRGBA & Color) | 
					
						
							| 
									
										
										
										
											2018-04-07 14:34:11 +03:00
										 |  |  | 	: font(Font), align(Align), color(Color) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-07 12:56:34 +03:00
										 |  |  | void CLabelGroup::add(int x, int y, const std::string & text) | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-08-09 15:30:04 +00:00
										 |  |  | 	OBJECT_CONSTRUCTION; | 
					
						
							| 
									
										
										
										
											2018-04-07 14:34:11 +03:00
										 |  |  | 	labels.push_back(std::make_shared<CLabel>(x, y, font, align, color, text)); | 
					
						
							| 
									
										
										
										
											2018-03-23 01:23:18 +07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | size_t CLabelGroup::currentSize() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return labels.size(); | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-31 19:50:55 +03:00
										 |  |  | CTextBox::CTextBox(std::string Text, const Rect & rect, int SliderStyle, EFonts Font, ETextAlignment Align, const ColorRGBA & Color) : | 
					
						
							| 
									
										
										
										
											2016-03-12 04:41:27 +03:00
										 |  |  | 	sliderStyle(SliderStyle), | 
					
						
							|  |  |  | 	slider(nullptr) | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-08-09 15:30:04 +00:00
										 |  |  | 	OBJECT_CONSTRUCTION; | 
					
						
							| 
									
										
										
										
											2018-04-07 14:34:11 +03:00
										 |  |  | 	label = std::make_shared<CMultiLineLabel>(rect, Font, Align, Color); | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-03 19:24:12 +03:00
										 |  |  | 	setRedrawParent(true); | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 	pos.x += rect.x; | 
					
						
							|  |  |  | 	pos.y += rect.y; | 
					
						
							|  |  |  | 	pos.h = rect.h; | 
					
						
							|  |  |  | 	pos.w = rect.w; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	assert(pos.w >= 40); //we need some space
 | 
					
						
							|  |  |  | 	setText(Text); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CTextBox::sliderMoved(int to) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	label->scrollTextTo(to); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2024-02-26 18:32:15 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | void CTextBox::trimToFit() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (slider) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	pos.w = label->textSize.x; | 
					
						
							|  |  |  | 	pos.h = label->textSize.y; | 
					
						
							|  |  |  | 	label->pos.w = label->textSize.x; | 
					
						
							|  |  |  | 	label->pos.h = label->textSize.y; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | void CTextBox::resize(Point newSize) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	pos.w = newSize.x; | 
					
						
							|  |  |  | 	pos.h = newSize.y; | 
					
						
							|  |  |  | 	label->pos.w = pos.w; | 
					
						
							|  |  |  | 	label->pos.h = pos.h; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-07 14:34:11 +03:00
										 |  |  | 	slider.reset(); | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 	setText(label->getText()); // force refresh
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-07 12:56:34 +03:00
										 |  |  | void CTextBox::setText(const std::string & text) | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-11-24 16:18:10 +03:00
										 |  |  | 	label->pos.w = pos.w; // reset to default before textSize.y check
 | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 	label->setText(text); | 
					
						
							| 
									
										
										
										
											2014-11-24 16:18:10 +03:00
										 |  |  | 	if(label->textSize.y <= label->pos.h && slider) | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		// slider is no longer needed
 | 
					
						
							| 
									
										
										
										
											2018-04-07 14:34:11 +03:00
										 |  |  | 		slider.reset(); | 
					
						
							| 
									
										
										
										
											2024-05-11 20:53:39 +00:00
										 |  |  | 		label->scrollTextTo(0); | 
					
						
							| 
									
										
										
										
											2014-11-24 16:18:10 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else if(slider) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		// decrease width again if slider still used
 | 
					
						
							| 
									
										
										
										
											2023-12-23 18:12:55 +02:00
										 |  |  | 		label->pos.w = pos.w - 16; | 
					
						
							| 
									
										
										
										
											2023-11-26 18:55:50 +02:00
										 |  |  | 		assert(label->pos.w > 0); | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 		label->setText(text); | 
					
						
							| 
									
										
										
										
											2015-03-13 18:45:07 +03:00
										 |  |  | 		slider->setAmount(label->textSize.y); | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-11-24 16:18:10 +03:00
										 |  |  | 	else if(label->textSize.y > label->pos.h) | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		// create slider and update widget
 | 
					
						
							| 
									
										
										
										
											2023-12-23 18:12:55 +02:00
										 |  |  | 		label->pos.w = pos.w - 16; | 
					
						
							| 
									
										
										
										
											2023-11-26 18:55:50 +02:00
										 |  |  | 		assert(label->pos.w > 0); | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 		label->setText(text); | 
					
						
							| 
									
										
										
										
											2024-09-23 15:43:11 +00:00
										 |  |  | 		const auto & fontPtr = GH.renderHandler().loadFont(label->font); | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-09 15:30:04 +00:00
										 |  |  | 		OBJECT_CONSTRUCTION; | 
					
						
							| 
									
										
										
										
											2023-12-23 18:12:55 +02:00
										 |  |  | 		slider = std::make_shared<CSlider>(Point(pos.w - 16, 0), pos.h, std::bind(&CTextBox::sliderMoved, this, _1), | 
					
						
							| 
									
										
										
										
											2023-06-22 23:49:38 +03:00
										 |  |  | 			label->pos.h, label->textSize.y, 0, Orientation::VERTICAL, CSlider::EStyle(sliderStyle)); | 
					
						
							| 
									
										
										
										
											2024-09-23 15:43:11 +00:00
										 |  |  | 		slider->setScrollStep(fontPtr->getLineHeight()); | 
					
						
							| 
									
										
										
										
											2023-06-22 23:49:38 +03:00
										 |  |  | 		slider->setPanningStep(1); | 
					
						
							|  |  |  | 		slider->setScrollBounds(pos - slider->pos.topLeft()); | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-12 18:23:41 +02:00
										 |  |  | void CGStatusBar::setEnteringMode(bool on) | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-12-12 18:23:41 +02:00
										 |  |  | 	consoleText.clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (on) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2023-04-06 22:49:38 +04:00
										 |  |  | 		//assert(enteringText == false);
 | 
					
						
							| 
									
										
										
										
											2022-12-12 18:23:41 +02:00
										 |  |  | 		alignment = ETextAlignment::TOPLEFT; | 
					
						
							| 
									
										
										
										
											2023-02-02 16:15:39 +02:00
										 |  |  | 		GH.startTextInput(pos); | 
					
						
							| 
									
										
										
										
											2022-12-12 18:23:41 +02:00
										 |  |  | 		setText(consoleText); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2023-04-06 22:49:38 +04:00
										 |  |  | 		//assert(enteringText == true);
 | 
					
						
							| 
									
										
										
										
											2022-12-12 18:23:41 +02:00
										 |  |  | 		alignment = ETextAlignment::CENTER; | 
					
						
							| 
									
										
										
										
											2023-02-02 16:15:39 +02:00
										 |  |  | 		GH.stopTextInput(); | 
					
						
							| 
									
										
										
										
											2022-12-12 18:23:41 +02:00
										 |  |  | 		setText(hoverText); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	enteringText = on; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CGStatusBar::setEnteredText(const std::string & text) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	assert(enteringText == true); | 
					
						
							|  |  |  | 	consoleText = text; | 
					
						
							|  |  |  | 	setText(text); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-18 17:54:10 +02:00
										 |  |  | void CGStatusBar::write(const std::string & Text) | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-12-12 18:23:41 +02:00
										 |  |  | 	hoverText = Text; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (enteringText == false) | 
					
						
							|  |  |  | 		setText(hoverText); | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-11 23:43:43 +02:00
										 |  |  | void CGStatusBar::clearIfMatching(const std::string & Text) | 
					
						
							| 
									
										
										
										
											2022-11-18 17:54:10 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-12-12 18:23:41 +02:00
										 |  |  | 	if (hoverText == Text) | 
					
						
							| 
									
										
										
										
											2022-11-18 17:54:10 +02:00
										 |  |  | 		clear(); | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CGStatusBar::clear() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2022-12-12 18:23:41 +02:00
										 |  |  | 	write({}); | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-31 19:50:55 +03:00
										 |  |  | CGStatusBar::CGStatusBar(std::shared_ptr<CIntObject> background_, EFonts Font, ETextAlignment Align, const ColorRGBA & Color) | 
					
						
							| 
									
										
										
										
											2024-01-07 23:42:48 +01:00
										 |  |  | 	: CLabel(background_->pos.x, background_->pos.y, Font, Align, Color, "", background_->pos.w) | 
					
						
							| 
									
										
										
										
											2022-12-12 18:23:41 +02:00
										 |  |  | 	, enteringText(false) | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-01-19 19:00:18 +02:00
										 |  |  | 	addUsedEvents(LCLICK); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-07 14:34:11 +03:00
										 |  |  | 	background = background_; | 
					
						
							|  |  |  | 	addChild(background.get()); | 
					
						
							|  |  |  | 	pos = background->pos; | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 	getBorderSize(); | 
					
						
							| 
									
										
										
										
											2019-05-19 16:19:16 +02:00
										 |  |  | 	autoRedraw = false; | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-26 15:53:44 +02:00
										 |  |  | CGStatusBar::CGStatusBar(int x, int y) | 
					
						
							|  |  |  | 	: CLabel(x, y, FONT_SMALL, ETextAlignment::CENTER) | 
					
						
							|  |  |  | 	, enteringText(false) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2023-09-26 15:56:39 +02:00
										 |  |  | 	 // without background
 | 
					
						
							| 
									
										
										
										
											2023-09-26 15:53:44 +02:00
										 |  |  | 	addUsedEvents(LCLICK); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-23 15:07:50 +03:00
										 |  |  | CGStatusBar::CGStatusBar(int x, int y, const ImagePath & name, int maxw) | 
					
						
							| 
									
										
										
										
											2022-11-26 23:12:20 +02:00
										 |  |  | 	: CLabel(x, y, FONT_SMALL, ETextAlignment::CENTER) | 
					
						
							| 
									
										
										
										
											2022-12-12 18:23:41 +02:00
										 |  |  | 	, enteringText(false) | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-01-19 19:00:18 +02:00
										 |  |  | 	addUsedEvents(LCLICK); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-09 15:30:04 +00:00
										 |  |  | 	OBJECT_CONSTRUCTION; | 
					
						
							| 
									
										
										
										
											2023-09-25 01:04:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-26 15:44:10 +03:00
										 |  |  | 	auto backgroundImage = std::make_shared<CPicture>(name); | 
					
						
							|  |  |  | 	background = backgroundImage; | 
					
						
							| 
									
										
										
										
											2018-04-07 14:34:11 +03:00
										 |  |  | 	pos = background->pos; | 
					
						
							| 
									
										
										
										
											2020-10-16 06:08:59 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if((unsigned)maxw < (unsigned)pos.w) //(insigned)-1 > than any correct value of pos.w
 | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2020-10-16 06:08:59 +03:00
										 |  |  | 		//execution of this block when maxw is incorrect breaks text centralization (issue #3151)
 | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 		vstd::amin(pos.w, maxw); | 
					
						
							| 
									
										
										
										
											2023-04-26 15:44:10 +03:00
										 |  |  | 		backgroundImage->srcRect = Rect(0, 0, maxw, pos.h); | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-05-19 16:19:16 +02:00
										 |  |  | 	autoRedraw = false; | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-05 23:36:33 +03:00
										 |  |  | CGStatusBar::~CGStatusBar() | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-05-16 18:34:23 +03:00
										 |  |  | 	assert(GH.statusbar().get() != this); | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-02 16:42:18 +03:00
										 |  |  | void CGStatusBar::show(Canvas & to) | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-05-05 23:36:33 +03:00
										 |  |  | 	showAll(to); | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-09 17:48:25 +03:00
										 |  |  | void CGStatusBar::clickPressed(const Point & cursorPosition) | 
					
						
							| 
									
										
										
										
											2022-11-20 11:53:46 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-07-08 14:33:04 +03:00
										 |  |  | 	if(LOCPLINT && LOCPLINT->cingconsole->isActive()) | 
					
						
							|  |  |  | 		LOCPLINT->cingconsole->startEnteringText(); | 
					
						
							| 
									
										
										
										
											2022-11-20 11:53:46 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-05 23:36:33 +03:00
										 |  |  | void CGStatusBar::activate() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2023-05-16 18:34:23 +03:00
										 |  |  | 	GH.setStatusbar(shared_from_this()); | 
					
						
							| 
									
										
										
										
											2023-05-13 17:59:59 +03:00
										 |  |  | 	CIntObject::activate(); | 
					
						
							| 
									
										
										
										
											2023-05-05 23:36:33 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-19 22:06:01 +02:00
										 |  |  | void CGStatusBar::deactivate() | 
					
						
							| 
									
										
										
										
											2022-11-20 11:53:46 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-05-16 18:34:23 +03:00
										 |  |  | 	GH.setStatusbar(nullptr); | 
					
						
							| 
									
										
										
										
											2023-05-05 23:36:33 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-19 22:06:01 +02:00
										 |  |  | 	if (enteringText) | 
					
						
							| 
									
										
										
										
											2022-12-19 22:53:31 +02:00
										 |  |  | 		LOCPLINT->cingconsole->endEnteringText(false); | 
					
						
							| 
									
										
										
										
											2022-12-19 22:06:01 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	CIntObject::deactivate(); | 
					
						
							| 
									
										
										
										
											2022-11-20 11:53:46 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | Point CGStatusBar::getBorderSize() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	//Width of borders where text should not be printed
 | 
					
						
							| 
									
										
										
										
											2022-05-07 12:56:34 +03:00
										 |  |  | 	static const Point borderSize(5, 1); | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	switch(alignment) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2022-11-26 23:12:20 +02:00
										 |  |  | 	case ETextAlignment::TOPLEFT:     return Point(borderSize.x, borderSize.y); | 
					
						
							| 
									
										
										
										
											2023-08-30 00:35:31 +02:00
										 |  |  | 	case ETextAlignment::TOPCENTER:   return Point(pos.w / 2, borderSize.y); | 
					
						
							| 
									
										
										
										
											2022-11-26 23:12:20 +02:00
										 |  |  | 	case ETextAlignment::CENTER:      return Point(pos.w / 2, pos.h / 2); | 
					
						
							|  |  |  | 	case ETextAlignment::BOTTOMRIGHT: return Point(pos.w - borderSize.x, pos.h - borderSize.y); | 
					
						
							| 
									
										
										
										
											2014-07-15 10:14:49 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	assert(0); | 
					
						
							|  |  |  | 	return Point(); | 
					
						
							|  |  |  | } |