Explorar o código

Made labels not re-render if text and color are the same

Ivan Safrin %!s(int64=12) %!d(string=hai) anos
pai
achega
b548bbaf1e

+ 3 - 1
Core/Contents/Include/PolyLabel.h

@@ -90,6 +90,8 @@ namespace Polycode {
 			
 			
 			int getAntialiasMode() const;			
 			int getAntialiasMode() const;			
 			void setAntialiasMode(int newMode);
 			void setAntialiasMode(int newMode);
+			
+			bool colorsChanged();
 					
 					
 			static const int ANTIALIAS_FULL = 0;
 			static const int ANTIALIAS_FULL = 0;
 			static const int ANTIALIAS_NONE = 1;
 			static const int ANTIALIAS_NONE = 1;
@@ -99,7 +101,7 @@ namespace Polycode {
 			
 			
 		protected:
 		protected:
 		
 		
-			
+			bool _colorsChanged;
 			GlyphData labelData;
 			GlyphData labelData;
 	
 	
 			std::vector<ColorRange> colorRanges;
 			std::vector<ColorRange> colorRanges;

+ 9 - 3
Core/Contents/Source/PolyLabel.cpp

@@ -58,9 +58,8 @@ ColorRange::ColorRange(Color color, unsigned int rangeStart, unsigned int rangeE
 }
 }
 
 
 
 
-Label::Label(Font *font, const String& text, int size, int antiAliasMode, bool premultiplyAlpha) : Image() {
+Label::Label(Font *font, const String& text, int size, int antiAliasMode, bool premultiplyAlpha) : Image(), _colorsChanged(false) {
 		setPixelType(Image::IMAGE_RGBA);
 		setPixelType(Image::IMAGE_RGBA);
-		
 		this->font = font;
 		this->font = font;
 		this->size = size;
 		this->size = size;
 		this->premultiplyAlpha = premultiplyAlpha;
 		this->premultiplyAlpha = premultiplyAlpha;
@@ -194,10 +193,12 @@ const String& Label::getText() const {
 
 
 void Label::clearColors() {
 void Label::clearColors() {
 	colorRanges.clear();
 	colorRanges.clear();
+	_colorsChanged = true;
 }
 }
 
 
 void Label::setColorForRange(Color color, unsigned int rangeStart, unsigned int rangeEnd) {
 void Label::setColorForRange(Color color, unsigned int rangeStart, unsigned int rangeEnd) {
 	colorRanges.push_back(ColorRange(color, rangeStart, rangeEnd));
 	colorRanges.push_back(ColorRange(color, rangeStart, rangeEnd));
+	_colorsChanged = true;	
 }
 }
 
 
 Color Label::getColorForIndex(unsigned int index) {
 Color Label::getColorForIndex(unsigned int index) {
@@ -395,8 +396,12 @@ void Label::renderGlyphs(GlyphData *glyphData) {
 	}
 	}
 }
 }
 
 
-void Label::setText(const String& text) {
+bool Label::colorsChanged() {
+	return _colorsChanged;
+}
 
 
+void Label::setText(const String& text) {
+	
 	if(!font)
 	if(!font)
 		return;
 		return;
 	if(!font->isValid())
 	if(!font->isValid())
@@ -418,4 +423,5 @@ void Label::setText(const String& text) {
 	
 	
 	createEmpty(textWidth,textHeight);	
 	createEmpty(textWidth,textHeight);	
 	renderGlyphs(&labelData);
 	renderGlyphs(&labelData);
+	_colorsChanged = false;	
 }
 }

+ 5 - 0
Core/Contents/Source/PolySceneLabel.cpp

@@ -46,6 +46,11 @@ Label *SceneLabel::getLabel() {
 }
 }
 
 
 void SceneLabel::setText(const String& newText) {
 void SceneLabel::setText(const String& newText) {
+	
+	if(newText == label->getText() && !label->colorsChanged()) {
+		return;
+	}
+
 	if(texture)
 	if(texture)
 		CoreServices::getInstance()->getMaterialManager()->deleteTexture(texture);
 		CoreServices::getInstance()->getMaterialManager()->deleteTexture(texture);
 		
 		

+ 4 - 2
Core/Contents/Source/PolyScreenLabel.cpp

@@ -93,6 +93,8 @@ void ScreenLabel::Render() {
 }
 }
 
 
 void ScreenLabel::setText(const String& newText) {
 void ScreenLabel::setText(const String& newText) {
-	label->setText(newText);	
-	updateTexture();
+	if(newText != label->getText() || label->colorsChanged()) {
+		label->setText(newText);	
+		updateTexture();
+	}
 }
 }