Skip to content

Commit

Permalink
[SUTK] Container is now Activatable and Optimized input event handler…
Browse files Browse the repository at this point in the history
… objects
  • Loading branch information
ravi688 committed Sep 3, 2024
1 parent 47f16f3 commit 5486c03
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion sutk/include/sutk/Container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <sutk/IDebuggable.hpp> // for SUTK::IDebuggable class
#include <sutk/AnchorRect.hpp> // for SUTK::AnchorRect class
#include <sutk/Activatable.hpp> // for SUTK::Activatable class

namespace SUTK
{
Expand All @@ -24,7 +25,7 @@ namespace SUTK
class RenderRectOutline;
class RenderableContainer;

class Container : public UIDriverObject, public IDebuggable
class Container : public UIDriverObject, public IDebuggable, public Activatable
{
private:
std::vector<Container*> m_containers;
Expand Down
17 changes: 16 additions & 1 deletion sutk/include/sutk/InputEventHandlerObject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,22 @@ namespace SUTK

protected:
TInputEventHandlerContainerObject(InputEventType& event) noexcept : TInputEventHandlerObject<InputEventType>(event), m_container(NULL) { }
TInputEventHandlerContainerObject(InputEventType& event, Container* container) noexcept : TInputEventHandlerObject<InputEventType>(event), m_container(container) { }
TInputEventHandlerContainerObject(InputEventType& event, Container* container) noexcept : TInputEventHandlerObject<InputEventType>(event), m_container(container)
{
if(m_container != NULL)
{
// If the container has been deactivated then sleep the subscription,
// Or if the container has been activated then awake the subscription
// This saves CPU cycles
m_container->getOnActiveEvent().subscribe([this](Activatable* _, bool isActive)
{
if(isActive)
this->awake();
else
this->sleep();
});
}
}
bool isInside(Vec2Df point) const noexcept
{
return (m_container != NULL) ? m_container->containsGlobalCoords(point) : true;
Expand Down

0 comments on commit 5486c03

Please sign in to comment.