Bläddra i källkod

Added the pressed event to pictures.

David Piuva 4 år sedan
förälder
incheckning
a513bc5947
2 ändrade filer med 17 tillägg och 0 borttagningar
  1. 13 0
      Source/DFPSR/gui/components/Picture.cpp
  2. 4 0
      Source/DFPSR/gui/components/Picture.h

+ 13 - 0
Source/DFPSR/gui/components/Picture.cpp

@@ -71,6 +71,19 @@ bool Picture::pointIsInside(const IVector2D& pixelPosition) {
 	}
 	}
 }
 }
 
 
+void Picture::receiveMouseEvent(const MouseEvent& event) {
+	if (event.mouseEventType == MouseEventType::MouseDown) {
+		this->pressed = true;
+	} else if (this->pressed && event.mouseEventType == MouseEventType::MouseUp) {
+		this->pressed = false;
+		if (this->inside) {
+			this->callback_pressedEvent();
+		}
+	}
+	this->inside = this->pointIsInside(event.position);
+	VisualComponent::receiveMouseEvent(event);
+}
+
 void Picture::generateGraphics() {
 void Picture::generateGraphics() {
 	int width = this->location.width();
 	int width = this->location.width();
 	int height = this->location.height();
 	int height = this->location.height();

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

@@ -39,6 +39,9 @@ public:
 	bool hasImages = false;
 	bool hasImages = false;
 	OrderedImageRgbaU8 finalImage;
 	OrderedImageRgbaU8 finalImage;
 	void generateGraphics();
 	void generateGraphics();
+	// Temporary
+	bool pressed = false;
+	bool inside = false;
 	// Attribute access
 	// Attribute access
 	void declareAttributes(StructureDefinition &target) const override;
 	void declareAttributes(StructureDefinition &target) const override;
 	Persistent* findAttribute(const ReadableString &name) override;
 	Persistent* findAttribute(const ReadableString &name) override;
@@ -47,6 +50,7 @@ public:
 public:
 public:
 	bool isContainer() const override;
 	bool isContainer() const override;
 	void drawSelf(ImageRgbaU8& targetImage, const IRect &relativeLocation) override;
 	void drawSelf(ImageRgbaU8& targetImage, const IRect &relativeLocation) override;
+	void receiveMouseEvent(const MouseEvent& event) override;
 	bool pointIsInside(const IVector2D& pixelPosition) override;
 	bool pointIsInside(const IVector2D& pixelPosition) override;
 	void changedLocation(const IRect &oldLocation, const IRect &newLocation) override;
 	void changedLocation(const IRect &oldLocation, const IRect &newLocation) override;
 	void changedAttribute(const ReadableString &name) override;
 	void changedAttribute(const ReadableString &name) override;