Parcourir la source

CLabel: add methods getWidth, setColor, setAutoRedraw

For somethign like map list we need to change CLabel data without redrawing it.
Arseniy Shestakov il y a 7 ans
Parent
commit
ab2b9086d3
2 fichiers modifiés avec 25 ajouts et 0 suppressions
  1. 22 0
      client/widgets/TextControls.cpp
  2. 3 0
      client/widgets/TextControls.h

+ 22 - 0
client/widgets/TextControls.cpp

@@ -63,6 +63,11 @@ std::string CLabel::getText()
 	return text;
 	return text;
 }
 }
 
 
+void CLabel::setAutoRedraw(bool value)
+{
+	autoRedraw = value;
+}
+
 void CLabel::setText(const std::string &Txt)
 void CLabel::setText(const std::string &Txt)
 {
 {
 	text = Txt;
 	text = Txt;
@@ -75,6 +80,23 @@ void CLabel::setText(const std::string &Txt)
 	}
 	}
 }
 }
 
 
+void CLabel::setColor(const SDL_Color & Color)
+{
+	color = Color;
+	if(autoRedraw)
+	{
+		if(bg || !parent)
+			redraw();
+		else
+			parent->redraw();
+	}
+}
+
+size_t CLabel::getWidth()
+{
+	return graphics->fonts[font]->getStringWidth(visibleText());;
+}
+
 CMultiLineLabel::CMultiLineLabel(Rect position, EFonts Font, EAlignment Align, const SDL_Color &Color, const std::string &Text):
 CMultiLineLabel::CMultiLineLabel(Rect position, EFonts Font, EAlignment Align, const SDL_Color &Color, const std::string &Text):
 	CLabel(position.x, position.y, Font, Align, Color, Text),
 	CLabel(position.x, position.y, Font, Align, Color, Text),
 	visibleSize(0, 0, position.w, position.h)
 	visibleSize(0, 0, position.w, position.h)

+ 3 - 0
client/widgets/TextControls.h

@@ -47,7 +47,10 @@ public:
 	bool autoRedraw;  //whether control will redraw itself on setTxt
 	bool autoRedraw;  //whether control will redraw itself on setTxt
 
 
 	std::string getText();
 	std::string getText();
+	virtual void setAutoRedraw(bool option);
 	virtual void setText(const std::string &Txt);
 	virtual void setText(const std::string &Txt);
+	virtual void setColor(const SDL_Color & Color);
+	size_t getWidth();
 
 
 	CLabel(int x=0, int y=0, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT,
 	CLabel(int x=0, int y=0, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT,
 	       const SDL_Color &Color = Colors::WHITE, const std::string &Text =  "");
 	       const SDL_Color &Color = Colors::WHITE, const std::string &Text =  "");