Browse Source

Gave Picture pressed images for custom buttons.

David Piuva 4 years ago
parent
commit
a946ada883
2 changed files with 8 additions and 3 deletions
  1. 5 1
      Source/DFPSR/gui/components/Picture.cpp
  2. 3 2
      Source/DFPSR/gui/components/Picture.h

+ 5 - 1
Source/DFPSR/gui/components/Picture.cpp

@@ -31,12 +31,15 @@ PERSISTENT_DEFINITION(Picture)
 void Picture::declareAttributes(StructureDefinition &target) const {
 	VisualComponent::declareAttributes(target);
 	target.declareAttribute(U"Image");
+	target.declareAttribute(U"ImagePressed");
 	target.declareAttribute(U"Interpolation");
 }
 
 Persistent* Picture::findAttribute(const ReadableString &name) {
 	if (string_caseInsensitiveMatch(name, U"Image")) {
 		return &(this->image);
+	} else if (string_caseInsensitiveMatch(name, U"ImagePressed")) {
+		return &(this->imagePressed);
 	} else if (string_caseInsensitiveMatch(name, U"Interpolation")) {
 		return &(this->interpolation);
 	} else if (string_caseInsensitiveMatch(name, U"Clickable")) {
@@ -55,7 +58,7 @@ bool Picture::isContainer() const {
 void Picture::drawSelf(ImageRgbaU8& targetImage, const IRect &relativeLocation) {
 	if (image_exists(this->image.value)) {
 		this->generateGraphics();
-		draw_alphaFilter(targetImage, this->finalImage, relativeLocation.left(), relativeLocation.top());
+		draw_alphaFilter(targetImage, (this->pressed && this->inside) ? this->finalImagePressed : this->finalImage, relativeLocation.left(), relativeLocation.top());
 	}
 }
 
@@ -91,6 +94,7 @@ void Picture::generateGraphics() {
 	if (height < 1) { height = 1; }
 	if (!this->hasImages) {
 		this->finalImage = filter_resize(this->image.value, this->interpolation.value ? Sampler::Linear : Sampler::Nearest, width, height);
+		this->finalImagePressed = filter_resize(this->imagePressed.value, this->interpolation.value ? Sampler::Linear : Sampler::Nearest, width, height);
 		this->hasImages = true;
 	}
 }

+ 3 - 2
Source/DFPSR/gui/components/Picture.h

@@ -32,12 +32,13 @@ class Picture : public VisualComponent {
 PERSISTENT_DECLARATION(Picture)
 public:
 	// Attributes
-	PersistentImage image;
+	PersistentImage image; // The default image
+	PersistentImage imagePressed; // Only visible when pressing like a button (Requires clickable)
 	PersistentBoolean interpolation; // False (0) for nearest neighbor, True (1) for bi-linear
 	PersistentBoolean clickable; // Allow catching mouse events (false by default)
 	// Generated
 	bool hasImages = false;
-	OrderedImageRgbaU8 finalImage;
+	OrderedImageRgbaU8 finalImage, finalImagePressed;
 	void generateGraphics();
 	// Temporary
 	bool pressed = false;