Browse Source

Created a destroy event for visual components.

David Piuva 2 years ago
parent
commit
c7d9108825

+ 4 - 0
Source/DFPSR/api/guiAPI.cpp

@@ -225,6 +225,10 @@ void dsr::component_setPressedEvent(const Component& component, const EmptyCallb
 	MUST_EXIST(component, component_setPressedEvent);
 	MUST_EXIST(component, component_setPressedEvent);
 	component->pressedEvent() = event;
 	component->pressedEvent() = event;
 }
 }
+void dsr::component_setDestroyEvent(const Component& component, const EmptyCallback& event) {
+	MUST_EXIST(component, component_setDestroyEvent);
+	component->destroyEvent() = event;
+}
 void dsr::component_setMouseDownEvent(const Component& component, const MouseCallback& mouseEvent) {
 void dsr::component_setMouseDownEvent(const Component& component, const MouseCallback& mouseEvent) {
 	MUST_EXIST(component, component_setMouseDownEvent);
 	MUST_EXIST(component, component_setMouseDownEvent);
 	component->mouseDownEvent() = mouseEvent;
 	component->mouseDownEvent() = mouseEvent;

+ 4 - 0
Source/DFPSR/api/guiAPI.h

@@ -276,6 +276,10 @@ namespace dsr {
 	// The main activation of clickable components.
 	// The main activation of clickable components.
 	//   The pressed callback doesn't take any arguments, because it should be possible to generate from multiple input methods.
 	//   The pressed callback doesn't take any arguments, because it should be possible to generate from multiple input methods.
 	void component_setPressedEvent(const Component& component, const EmptyCallback& event);
 	void component_setPressedEvent(const Component& component, const EmptyCallback& event);
+	// Called before the component and it's child components are destructed.
+	// The event is called when there are no more handles to component.
+	//   Be careful not to forget any extra handles to the component if a memory leak would significantly change the behavior.
+	void component_setDestroyEvent(const Component& component, const EmptyCallback& event);
 	// Mouse-down activates when any mouse button is pressed down within the component
 	// Mouse-down activates when any mouse button is pressed down within the component
 	//   Raises an exception if component doesn't exist.
 	//   Raises an exception if component doesn't exist.
 	//   The component itself decides if the mouse is inside, which allow rounded components to act as their true shape.
 	//   The component itself decides if the mouse is inside, which allow rounded components to act as their true shape.

+ 1 - 0
Source/DFPSR/gui/VisualComponent.cpp

@@ -32,6 +32,7 @@ PERSISTENT_DEFINITION(VisualComponent)
 VisualComponent::VisualComponent() {}
 VisualComponent::VisualComponent() {}
 
 
 VisualComponent::~VisualComponent() {
 VisualComponent::~VisualComponent() {
+	this->callback_destroyEvent();
 	// Let the children know that the parent component no longer exists.
 	// Let the children know that the parent component no longer exists.
 	for (int i = 0; i < this->getChildCount(); i++) {
 	for (int i = 0; i < this->getChildCount(); i++) {
 		this->children[i]->parent = nullptr;
 		this->children[i]->parent = nullptr;

+ 1 - 0
Source/DFPSR/gui/VisualComponent.h

@@ -119,6 +119,7 @@ public:
 public:
 public:
 	// Callbacks
 	// Callbacks
 	DECLARE_CALLBACK(pressedEvent, emptyCallback);
 	DECLARE_CALLBACK(pressedEvent, emptyCallback);
+	DECLARE_CALLBACK(destroyEvent, emptyCallback);
 	DECLARE_CALLBACK(mouseDownEvent, mouseCallback);
 	DECLARE_CALLBACK(mouseDownEvent, mouseCallback);
 	DECLARE_CALLBACK(mouseUpEvent, mouseCallback);
 	DECLARE_CALLBACK(mouseUpEvent, mouseCallback);
 	DECLARE_CALLBACK(mouseMoveEvent, mouseCallback);
 	DECLARE_CALLBACK(mouseMoveEvent, mouseCallback);