Просмотр исходного кода

Labels now have a new rendering mode called Label::ANTIALIAS_LCD, which renders text using subpixel antialiasing. You must initialize them with a foreground and background colors and they cannot be alpha blended

Ivan Safrin 10 лет назад
Родитель
Сommit
f6d40cc8e1

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

@@ -72,7 +72,7 @@ namespace Polycode {
              * @param premultiplyAlpha If set to true, will premultiply alpha in the label image.
              * @see Font
              */
-			Label(Font *font, const String& text, int size, int antiAliasMode, bool premultiplyAlpha = false);
+			Label(Font *font, const String& text, int size, int antiAliasMode, bool premultiplyAlpha = false, const Color &backgroundColor = Color(0.0, 0.0, 0.0, 1.0), const Color &foregroundColor = Color(0.0, 0.0, 0.0, 1.0));
 			virtual ~Label();
         
             /**
@@ -189,6 +189,9 @@ namespace Polycode {
             void setForegroundColor(const Color &color);
             void setColors(const Color &backgroundColor, const Color &foregroundColor);
         
+            Color getBackgroundColor();
+            Color getForegroundColor();
+        
 			bool optionsChanged();
 			
 		protected:

+ 1 - 1
Core/Contents/Include/PolySceneLabel.h

@@ -39,7 +39,7 @@ namespace Polycode {
 		public:
 			
 			
-			SceneLabel(const String& text, int size, const String& fontName = "sans", int amode = 0, Number actualHeight = 0.0, bool premultiplyAlpha = false);
+			SceneLabel(const String& text, int size, const String& fontName = "sans", int amode = 0, Number actualHeight = 0.0, bool premultiplyAlpha = false, const Color &backgroundColor = Color(0.0, 0.0, 0.0, 1.0), const Color &foregroundColor = Color(0.0, 0.0, 0.0, 1.0));
 			
 			String getText();
         

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

@@ -58,7 +58,7 @@ ColorRange::ColorRange(Color color, unsigned int rangeStart, unsigned int rangeE
 }
 
 
-Label::Label(Font *font, const String& text, int size, int antiAliasMode, bool premultiplyAlpha) : Image(), _optionsChanged(false), backgroundColor(0.0 ,0.0, 0.0, 0.0), foregroundColor(1.0, 1.0, 1.0, 1.0) {
+Label::Label(Font *font, const String& text, int size, int antiAliasMode, bool premultiplyAlpha, const Color &backgroundColor, const Color &foregroundColor) : Image(), backgroundColor(backgroundColor), foregroundColor(foregroundColor), _optionsChanged(false) {
 		setPixelType(Image::IMAGE_RGBA);
 		this->font = font;
 		this->size = size;
@@ -303,6 +303,14 @@ void Label::precacheGlyphs(String text, GlyphData *glyphData) {
 	}
 }
 
+Color Label::getBackgroundColor() {
+    return backgroundColor;
+}
+
+Color Label::getForegroundColor() {
+    return foregroundColor;
+}
+
 void Label::setBackgroundColor(const Color &color) {
     backgroundColor = color;
     _optionsChanged = true;

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

@@ -35,9 +35,9 @@ bool SceneLabel::defaultPositionAtBaseline = false;
 bool SceneLabel::defaultSnapToPixels = false;
 bool SceneLabel::createMipmapsForLabels = true;
 
-SceneLabel::SceneLabel(const String& text, int size, const String& fontName, int amode, Number actualHeight, bool premultiplyAlpha) : ScenePrimitive(ScenePrimitive::TYPE_VPLANE, 1, 1){
+SceneLabel::SceneLabel(const String& text, int size, const String& fontName, int amode, Number actualHeight, bool premultiplyAlpha, const Color &backgroundColor, const Color &foregroundColor) : ScenePrimitive(ScenePrimitive::TYPE_VPLANE, 1, 1){
 
-	label = new Label(CoreServices::getInstance()->getFontManager()->getFontByName(fontName), text, size * CoreServices::getInstance()->getRenderer()->getBackingResolutionScaleX(), amode, premultiplyAlpha);
+	label = new Label(CoreServices::getInstance()->getFontManager()->getFontByName(fontName), text, size * CoreServices::getInstance()->getRenderer()->getBackingResolutionScaleX(), amode, premultiplyAlpha, backgroundColor, foregroundColor);
     
 	positionAtBaseline = SceneLabel::defaultPositionAtBaseline;
 	setAnchorPoint(SceneLabel::defaultAnchor);	
@@ -46,7 +46,7 @@ SceneLabel::SceneLabel(const String& text, int size, const String& fontName, int
 }
 
 Entity *SceneLabel::Clone(bool deepClone, bool ignoreEditorOnly) const {
-	SceneLabel *newLabel = new SceneLabel(label->getText(), label->getSize(), label->getFont()->getFontName(), actualHeight, label->getPremultiplyAlpha());
+	SceneLabel *newLabel = new SceneLabel(label->getText(), label->getSize(), label->getFont()->getFontName(), label->getAntialiasMode(), actualHeight, label->getPremultiplyAlpha(), label->getBackgroundColor(), label->getForegroundColor());
     applyClone(newLabel, deepClone, ignoreEditorOnly);
     return newLabel;
 }
@@ -61,6 +61,8 @@ void SceneLabel::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly
     cloneLabel->getLabel()->setFont(label->getFont());
     cloneLabel->getLabel()->setPremultiplyAlpha(label->getPremultiplyAlpha());
     cloneLabel->setLabelActualHeight(actualHeight);
+    cloneLabel->getLabel()->setBackgroundColor(label->getBackgroundColor());
+    cloneLabel->getLabel()->setForegroundColor(label->getForegroundColor());
     cloneLabel->positionAtBaseline = positionAtBaseline;
     cloneLabel->setText(label->getText());