浏览代码

Made a setting for letting Pictures be clickable instead of decorative.

David Piuva 4 年之前
父节点
当前提交
9f7e6776f0
共有 2 个文件被更改,包括 12 次插入1 次删除
  1. 11 1
      Source/DFPSR/gui/components/Picture.cpp
  2. 1 0
      Source/DFPSR/gui/components/Picture.h

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

@@ -39,6 +39,8 @@ Persistent* Picture::findAttribute(const ReadableString &name) {
 		return &(this->image);
 	} else if (string_caseInsensitiveMatch(name, U"Interpolation")) {
 		return &(this->interpolation);
+	} else if (string_caseInsensitiveMatch(name, U"Clickable")) {
+		return &(this->clickable);
 	} else {
 		return VisualComponent::findAttribute(name);
 	}
@@ -58,7 +60,15 @@ void Picture::drawSelf(ImageRgbaU8& targetImage, const IRect &relativeLocation)
 }
 
 bool Picture::pointIsInside(const IVector2D& pixelPosition) {
-	return false;
+	if (this->clickable.value) {
+		this->generateGraphics();
+		// Get the point relative to the component instead of its direct container
+		IVector2D localPoint = pixelPosition - this->location.upperLeft();
+		// Sample opacity at the location
+		return dsr::image_readPixel_border(this->finalImage, localPoint.x, localPoint.y).alpha > 127;
+	} else {
+		return false;
+	}
 }
 
 void Picture::generateGraphics() {

+ 1 - 0
Source/DFPSR/gui/components/Picture.h

@@ -34,6 +34,7 @@ public:
 	// Attributes
 	PersistentImage image;
 	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;