We provide a quit action but did not do anything when this was signalled.
Now we emit a signal to the application using builder so that it can decide how quit should be
handled.
Change-Id: I51f24d29f30cbb38b400d346bf3c5d0c7b0d56c2
#include <stdlib.h>
#include <dali-toolkit-test-suite-utils.h>
#include <dali-toolkit/public-api/builder/builder.h>
+#include <dali/integration-api/events/touch-event-integ.h>
using namespace Dali;
using namespace Toolkit;
return s;
}
+struct BuilderFunctor
+{
+ BuilderFunctor( bool& called ) : mCalled( called )
+ {
+ mCalled = false;
+ }
+
+ void operator()()
+ {
+ mCalled = true;
+ }
+
+ bool& mCalled;
+};
+
} // namespace
END_TEST;
}
+
+int UtcDaliBuilderQuitSignal(void)
+{
+ ToolkitTestApplication application;
+
+ // JSON with a quit event when the actor is touched
+ std::string json(
+ "{"
+ "\"stage\":"
+ "[{"
+ "\"type\": \"Actor\","
+ "\"size\": [100,100,1],"
+ "\"parent-origin\": \"TOP_LEFT\","
+ "\"anchor-point\": \"TOP_LEFT\","
+ "\"signals\": [{"
+ "\"name\": \"touched\","
+ "\"action\": \"quit\""
+ "}]"
+ "}]"
+ "}"
+ );
+ Builder builder = Builder::New();
+ builder.LoadFromString( json );
+ builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
+
+ // Connect to builder's quit signal
+ bool functorCalled( false );
+ builder.QuitSignal().Connect( &application, BuilderFunctor( functorCalled ) );
+
+ // Render and notify
+ application.SendNotification();
+ application.Render();
+
+ // Emit touch event and check that our quit method is called
+ Integration::TouchEvent touchEvent;
+ touchEvent.points.push_back( TouchPoint ( 0, TouchPoint::Down, 10.0f, 10.0f ) );
+ application.ProcessEvent( touchEvent );
+ DALI_TEST_CHECK( functorCalled );
+
+ END_TEST;
+}
// EXTERNAL INCLUDES
#include <sys/stat.h>
+#include <boost/function.hpp>
#include <sstream>
// INTERNAL INCLUDES
extern bool SetPropertyFromNode( const TreeNode& node, Property::Value& value, const Replacement& replacements );
extern bool SetPropertyFromNode( const TreeNode& node, Property::Type type, Property::Value& value );
extern bool SetPropertyFromNode( const TreeNode& node, Property::Type type, Property::Value& value, const Replacement& replacements );
-extern Actor SetupSignalAction(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor);
-extern Actor SetupPropertyNotification(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor);
+extern Actor SetupSignalAction(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor, boost::function<void (void)> quitAction);
+extern Actor SetupPropertyNotification(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor, boost::function<void (void)> quitAction);
extern Actor SetupActor( const TreeNode& node, Actor& actor, const Replacement& constant );
#if defined(DEBUG_ENABLED)
}
}
+struct QuitAction
+{
+public:
+ QuitAction( Builder& builder )
+ : mBuilder( builder )
+ {
+ }
+
+ void operator()(void)
+ {
+ mBuilder.EmitQuitSignal();
+ }
+
+private:
+ Builder& mBuilder;
+};
+
} // namespace anon
/*
SetupActor( node, actor, constant );
// add signals
- SetupSignalAction( mSlotDelegate.GetConnectionTracker(), root, node, actor );
-
- SetupPropertyNotification( mSlotDelegate.GetConnectionTracker(), root, node, actor );
+ QuitAction quitAction( *this );
+ SetupSignalAction( mSlotDelegate.GetConnectionTracker(), root, node, actor, quitAction );
+ SetupPropertyNotification( mSlotDelegate.GetConnectionTracker(), root, node, actor, quitAction );
}
}
else
return ret;
}
+Toolkit::Builder::Signal& Builder::QuitSignal()
+{
+ return mQuitSignal;
+}
+
+void Builder::EmitQuitSignal()
+{
+ mQuitSignal.Emit();
+}
+
void Builder::AddActors( Actor toActor )
{
// 'stage' is the default/by convention section to add from
*/
FrameBufferImage GetFrameBufferImage( const std::string &name, const Replacement& constant );
+ /**
+ * @copydoc Toolkit::Builder::QuitSignal
+ */
+ Toolkit::Builder::Signal& QuitSignal();
+
+ /**
+ * Emits the quit signal
+ */
+ void EmitQuitSignal();
+
protected:
virtual ~Builder();
void SetProperties( const TreeNode& node, Handle& handle, const Replacement& constant );
+ Toolkit::Builder::Signal mQuitSignal;
};
} // namespace Internal
// Signal Actions
//
-// Action quit; connected to signals
-// TODO: MOVE TO BUILDER TEMPLATE
-struct ActionQuit
-{
- ActionQuit(void) {};
-
- void operator()(void) {
- // Dali::Application::Get().Quit();
- };
-};
-
// Action on child actor. The child is found by alias so can be 'previous' etc.
struct ChildActorAction
{
/**
* Get an action as boost function callback
*/
-boost::function<void (void)> GetAction(const TreeNode &root, const TreeNode &child, Actor actor)
+boost::function<void (void)> GetAction(const TreeNode &root, const TreeNode &child, Actor actor, boost::function<void (void)> quitAction)
{
OptionalString childActorName(IsString( IsChild(&child, "child-actor")) );
OptionalString actorName(IsString( IsChild(&child, "actor")) );
}
else if("quit" == *actionName)
{
- callback = ActionQuit();
+ callback = quitAction;
}
else if("play" == *actionName)
{
/**
* Setup signals and actions on an actor
*/
-Actor SetupSignalAction(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor)
+Actor SetupSignalAction(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor, boost::function<void (void)> quitAction)
{
DALI_ASSERT_ALWAYS(actor);
OptionalString name( IsString( IsChild( key_child.second, "name")) );
DALI_ASSERT_ALWAYS(name && "Signal must have a name");
- boost::function<void (void)> callback = GetAction(root, key_child.second, actor);
+ boost::function<void (void)> callback = GetAction(root, key_child.second, actor, quitAction);
actor.ConnectSignal(tracker, *name, callback);
}
/**
* Setup Property notifications for an actor
*/
-Actor SetupPropertyNotification(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor)
+Actor SetupPropertyNotification(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor, boost::function<void (void)> quitAction)
{
DALI_ASSERT_ALWAYS(actor);
// Actor actions reference by pointer because of circular reference actor->signal
// So this callback should only go onto the actor maintained list.
- boost::function<void (void)> callback = GetAction(root, key_child.second, actor);
+ boost::function<void (void)> callback = GetAction(root, key_child.second, actor, quitAction);
OptionalString prop(IsString( IsChild(key_child.second, "property")) );
DALI_ASSERT_ALWAYS(prop && "Notification signal must specify a property");
return GetImpl(*this).GetFrameBufferImage( name );
}
+Builder::Signal& Builder::QuitSignal()
+{
+ return GetImpl( *this ).QuitSignal();
+}
+
} // namespace Toolkit
} // namespace Dali
*/
FrameBufferImage GetFrameBufferImage( const std::string &name );
+ // Signals
+
+ /**
+ * @brief Builder signal type
+ */
+ typedef SignalV2< void () > Signal;
+
+ /**
+ * @brief Signal emitted when a quit action is requested by the builder.
+ */
+ Signal& QuitSignal();
+
private:
Builder(Internal::Builder *impl);