Browse Source

The Color attribute is now an alias for the most dominant color of the component.

David Piuva 3 years ago
parent
commit
c0ab330279

+ 9 - 6
Source/DFPSR/gui/components/Button.cpp

@@ -35,8 +35,11 @@ void Button::declareAttributes(StructureDefinition &target) const {
 }
 }
 
 
 Persistent* Button::findAttribute(const ReadableString &name) {
 Persistent* Button::findAttribute(const ReadableString &name) {
-	if (string_caseInsensitiveMatch(name, U"Color")) {
-		return &(this->color);
+	if (string_caseInsensitiveMatch(name, U"Color") || string_caseInsensitiveMatch(name, U"BackColor")) {
+		// The short Color alias refers to the back color in Buttons, because most buttons use black text.
+		return &(this->backColor);
+	} else if (string_caseInsensitiveMatch(name, U"ForeColor")) {
+		return &(this->foreColor);
 	} else if (string_caseInsensitiveMatch(name, U"Text")) {
 	} else if (string_caseInsensitiveMatch(name, U"Text")) {
 		return &(this->text);
 		return &(this->text);
 	} else {
 	} else {
@@ -50,7 +53,7 @@ bool Button::isContainer() const {
 	return false;
 	return false;
 }
 }
 
 
-static OrderedImageRgbaU8 generateButtonImage(Button &button, MediaMethod imageGenerator, int pressed, int width, int height, ColorRgbI32 backColor, String text, RasterFont font) {
+static OrderedImageRgbaU8 generateButtonImage(Button &button, MediaMethod imageGenerator, int pressed, int width, int height, ColorRgbI32 backColor, ColorRgbI32 foreColor, String text, RasterFont font) {
 	// Create a scaled image
 	// Create a scaled image
 	OrderedImageRgbaU8 result;
 	OrderedImageRgbaU8 result;
  	button.generateImage(imageGenerator, width, height, backColor.red, backColor.green, backColor.blue, pressed)(result);
  	button.generateImage(imageGenerator, width, height, backColor.red, backColor.green, backColor.blue, pressed)(result);
@@ -60,7 +63,7 @@ static OrderedImageRgbaU8 generateButtonImage(Button &button, MediaMethod imageG
 		if (pressed) {
 		if (pressed) {
 			top += 1;
 			top += 1;
 		}
 		}
-		font_printLine(result, font, text, IVector2D(left, top), ColorRgbaI32(0, 0, 0, 255));
+		font_printLine(result, font, text, IVector2D(left, top), ColorRgbaI32(foreColor, 255));
 	}
 	}
 	return result;
 	return result;
 }
 }
@@ -72,8 +75,8 @@ void Button::generateGraphics() {
 	if (height < 1) { height = 1; }
 	if (height < 1) { height = 1; }
 	if (!this->hasImages) {
 	if (!this->hasImages) {
 		completeAssets();
 		completeAssets();
-		this->imageUp = generateButtonImage(*this, this->button, 0, width, height, this->color.value, this->text.value, this->font);
-		this->imageDown = generateButtonImage(*this, this->button, 1, width, height, this->color.value, this->text.value, this->font);
+		this->imageUp = generateButtonImage(*this, this->button, 0, width, height, this->backColor.value, this->foreColor.value, this->text.value, this->font);
+		this->imageDown = generateButtonImage(*this, this->button, 1, width, height, this->backColor.value, this->foreColor.value, this->text.value, this->font);
 		this->hasImages = true;
 		this->hasImages = true;
 	}
 	}
 }
 }

+ 2 - 1
Source/DFPSR/gui/components/Button.h

@@ -33,7 +33,8 @@ class Button : public VisualComponent {
 PERSISTENT_DECLARATION(Button)
 PERSISTENT_DECLARATION(Button)
 public:
 public:
 	// Attributes
 	// Attributes
-	PersistentColor color;
+	PersistentColor backColor;
+	PersistentColor foreColor;
 	PersistentString text;
 	PersistentString text;
 	void declareAttributes(StructureDefinition &target) const override;
 	void declareAttributes(StructureDefinition &target) const override;
 	Persistent* findAttribute(const ReadableString &name) override;
 	Persistent* findAttribute(const ReadableString &name) override;

+ 2 - 1
Source/DFPSR/gui/components/Label.cpp

@@ -36,7 +36,8 @@ void Label::declareAttributes(StructureDefinition &target) const {
 }
 }
 
 
 Persistent* Label::findAttribute(const ReadableString &name) {
 Persistent* Label::findAttribute(const ReadableString &name) {
-	if (string_caseInsensitiveMatch(name, U"Color")) {
+	if (string_caseInsensitiveMatch(name, U"Color") || string_caseInsensitiveMatch(name, U"ForeColor")) {
+		// Both color and forecolor is accepted as names for the text color, because labels have no background.
 		return &(this->color);
 		return &(this->color);
 	} else if (string_caseInsensitiveMatch(name, U"Opacity")) {
 	} else if (string_caseInsensitiveMatch(name, U"Opacity")) {
 		return &(this->opacity);
 		return &(this->opacity);

+ 2 - 1
Source/DFPSR/gui/components/Panel.cpp

@@ -36,7 +36,8 @@ void Panel::declareAttributes(StructureDefinition &target) const {
 Persistent* Panel::findAttribute(const ReadableString &name) {
 Persistent* Panel::findAttribute(const ReadableString &name) {
 	if (string_caseInsensitiveMatch(name, U"Solid")) {
 	if (string_caseInsensitiveMatch(name, U"Solid")) {
 		return &(this->solid);
 		return &(this->solid);
-	} else if (string_caseInsensitiveMatch(name, U"Color")) {
+	} else if (string_caseInsensitiveMatch(name, U"Color") || string_caseInsensitiveMatch(name, U"BackColor")) {
+		// Both color and backcolor is accepted as names for the only color.
 		return &(this->color);
 		return &(this->color);
 	} else {
 	} else {
 		return VisualComponent::findAttribute(name);
 		return VisualComponent::findAttribute(name);

+ 4 - 2
Source/SDK/guiExample/media/interface.lof

@@ -12,7 +12,8 @@
 			Right = 100%-105
 			Right = 100%-105
 			Top = +5
 			Top = +5
 			Bottom = +45
 			Bottom = +45
-			Color = 200,200,200
+			BackColor = 200,200,200
+			ForeColor = 0,0,0
 			Text = "Element"
 			Text = "Element"
 		End
 		End
 		Begin : Button
 		Begin : Button
@@ -21,7 +22,8 @@
 			Right = 100%-5
 			Right = 100%-5
 			Top = +5
 			Top = +5
 			Bottom = +45
 			Bottom = +45
-			Color = 150,160,150
+			BackColor = 150,160,150
+			ForeColor = 0,100,0
 			Text = "Add"
 			Text = "Add"
 		End
 		End
 	End
 	End