Browse Source

Merge pull request #508 from fodinabor/UIMultilineLabelFixes

Ui multiline label fixes
Ivan Safrin 11 years ago
parent
commit
a69be0dc5c

+ 24 - 0
Modules/Contents/UI/Include/PolyUIElement.h

@@ -125,6 +125,30 @@ namespace Polycode {
         void setText(const String& text);
         String getText();
         
+		/**
+		* Sets the color of the Labels as normalized floating point values.
+		* @param r Red value as a 0-1 floating point number.
+		* @param g Green value as a 0-1 floating point number.
+		* @param b Blue value as a 0-1 floating point number.
+		* @param a Alpha value as a 0-1 floating point number.
+		*/
+		void setColor(Number r, Number g, Number b, Number a);
+
+		/**
+		* Sets the color of the entity as 0-255 integers.
+		* @param r Red value as a 0-255 integer.
+		* @param g Green value as a 0-255 integer.
+		* @param b Blue value as a 0-255 integer.
+		* @param a Alpha value as a 0-255 integer.
+		*/
+		void setColorInt(int r, int g, int b, int a);
+
+		/**
+		* Sets the color of the entity.
+		* @param color Color to set the entity color to.
+		*/
+		void setColor(Color color);
+
         ~UIMultilineLabel();
     protected:
         

+ 19 - 1
Modules/Contents/UI/Source/PolyUIElement.cpp

@@ -51,10 +51,10 @@ void UIMultilineLabel::setText(const String& text) {
         } else {
             UILabel *label = new UILabel(lines[i], labelSize, labelFontName, labelAAMode);
             lineSize = label->getHeight();
-            addChild(label);
             label->setPositionY(yPos);
             yPos += label->getHeight() + spacing;
             addChild(label);
+			labels.push_back(label);
         }
     }
 }
@@ -70,6 +70,24 @@ String UIMultilineLabel::getText() {
     return text;
 }
 
+void UIMultilineLabel::setColor(Color color) {
+	for (int i = 0; i < labels.size(); i++) {
+		labels[i]->color.setColor(&color);
+	}
+}
+
+void UIMultilineLabel::setColorInt(int r, int g, int b, int a) {
+	for (int i = 0; i < labels.size(); i++) {
+		labels[i]->color.setColorRGBA(r, g, b, a);
+	}
+}
+
+void UIMultilineLabel::setColor(Number r, Number g, Number b, Number a) {
+	for (int i = 0; i < labels.size(); i++) {
+		labels[i]->color.setColor(r, g, b, a);
+	}
+}
+
 void UIMultilineLabel::clearLabels() {
     for(int i=0; i < labels.size(); i++) {
         removeChild(labels[i]);