X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Fbuilder%2Fexamples.cpp;h=e80c88b4a6332f1a2f61a274471f7e3427f1ec7b;hb=28946d814d1f11fddcc23a887a0e318133147549;hp=d3c7f05edb7aa920c09a0c834ada08e340c0f806;hpb=b7bf4aba325e2325680747d2b3d898c7d41a86aa;p=platform%2Fcore%2Fuifw%2Fdali-demo.git diff --git a/examples/builder/examples.cpp b/examples/builder/examples.cpp index d3c7f05..e80c88b 100644 --- a/examples/builder/examples.cpp +++ b/examples/builder/examples.cpp @@ -20,26 +20,27 @@ // //------------------------------------------------------------------------------ -#include "dali.h" +#include #include -#include -#include -#include +#include +#include +#include +#include #include #include #include #include #include -#include #include #include +#include -//#include #include "sys/stat.h" #include +#include #include -#include "../shared/view.h" +#include "shared/view.h" #define TOKEN_STRING(x) #x @@ -50,8 +51,9 @@ namespace { const char* BACKGROUND_IMAGE( "" ); -const char* TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" ); -const char* EDIT_IMAGE( DALI_IMAGE_DIR "icon-change.png" ); +const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" ); +const char* EDIT_IMAGE( DEMO_IMAGE_DIR "icon-change.png" ); +const char* EDIT_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-change-selected.png" ); std::string USER_DIRECTORY; @@ -60,9 +62,9 @@ std::string JSON_BROKEN(" \ 'stage': \ [ \ { \ - 'type':'TextView', \ + 'type':'TextLabel', \ 'size': [50,50,1], \ - 'parent-origin': 'CENTER', \ + 'parentOrigin': 'CENTER', \ 'text':'COULD NOT LOAD JSON FILE' \ } \ ] \ @@ -142,11 +144,6 @@ const std::string ShortName( const std::string& name ) } } -static Vector3 SetItemSize(unsigned int numberOfColumns, float layoutWidth, float sideMargin, float columnSpacing) -{ - return Vector3(layoutWidth, 50, 1); -} - //------------------------------------------------------------------------------ // // @@ -244,15 +241,12 @@ public: { if(!mTitleActor) { - mTitleActor = TextView::New(); + mTitleActor = DemoHelper::CreateToolBarLabel( "" ); // Add title to the tool bar. mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Alignment::HorizontalCenter ); } - Font font = Font::New(); - mTitleActor.SetText( title ); - mTitleActor.SetSize( font.MeasureText( title ) ); - mTitleActor.SetStyleToCurrentText(DemoHelper::GetDefaultTextStyle()); + mTitleActor.SetProperty( TextLabel::Property::TEXT, title ); } bool OnToolSelectLayout( Toolkit::Button button ) @@ -279,6 +273,10 @@ public: void EnterSelection() { Stage stage = Stage::GetCurrent(); + stage.SetBackgroundColor( Color::WHITE ); + + mTapDetector = TapGestureDetector::New(); + mTapDetector.DetectedSignal().Connect( this, &ExampleApp::OnTap ); if( mItemView ) { @@ -291,17 +289,12 @@ public: stage.Add( mItemView ); mItemView.SetParentOrigin(ParentOrigin::CENTER); mItemView.SetAnchorPoint(AnchorPoint::CENTER); - mGridLayout = GridLayout::New(); - mGridLayout->SetNumberOfColumns(1); - - mGridLayout->SetItemSizeFunction(SetItemSize); + mLayout = DefaultItemLayout::New( DefaultItemLayout::LIST ); - mGridLayout->SetTopMargin(DemoHelper::DEFAULT_VIEW_STYLE.mToolBarHeight); + mLayout->SetItemSize( Vector3( stage.GetSize().width, 50, 1 ) ); - mItemView.AddLayout(*mGridLayout); + mItemView.AddLayout( *mLayout ); - Vector3 size(stage.GetSize()); - mItemView.ActivateLayout(0, size, 0.0f/*immediate*/); mItemView.SetKeyboardFocusable( true ); mFiles.clear(); @@ -313,7 +306,7 @@ public: } else { - DirectoryFilesByType( DALI_SCRIPT_DIR, "json", files ); + DirectoryFilesByType( DEMO_SCRIPT_DIR, "json", files ); } std::sort(files.begin(), files.end()); @@ -361,15 +354,6 @@ public: } } - mTapDetector = TapGestureDetector::New(); - - for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i ) - { - mTapDetector.Attach( mItemView.GetChildAt(i) ); - } - - mTapDetector.DetectedSignal().Connect( this, &ExampleApp::OnTap ); - // Display item view on the stage stage.Add( mItemView ); @@ -378,9 +362,9 @@ public: SetTitle("Select"); - // Itemview renderes the previous items unless its scrolled. Not sure why at the moment so we force a scroll - mItemView.ScrollToItem(0, 0); - + // Activate the layout + Vector3 size(stage.GetSize()); + mItemView.ActivateLayout(0, size, 0.0f/*immediate*/); } void ExitSelection() @@ -393,7 +377,7 @@ public: SetTitle("View"); } - void OnTap( Actor actor, TapGesture tap ) + void OnTap( Actor actor, const TapGesture& tap ) { ItemId id = mItemView.GetItemId( actor ); @@ -402,11 +386,14 @@ public: Actor MenuItem(const std::string& text) { - TextView t = TextView::New(); - t.SetMarkupProcessingEnabled(true); - t.SetText( std::string("") + ShortName( text ) + std::string("") ); - t.SetTextAlignment( Alignment::HorizontalLeft ); - return t; + TextLabel label = TextLabel::New( ShortName( text ) ); + label.SetProperty( Dali::Toolkit::Control::Property::STYLE_NAME, "builderlabel" ); + label.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); + + // Hook up tap detector + mTapDetector.Attach( label ); + + return label; } bool OnTimer() @@ -424,11 +411,12 @@ public: Stage stage = Stage::GetCurrent(); builder = Builder::New(); + builder.QuitSignal().Connect( this, &ExampleApp::OnBuilderQuit ); - PropertyValueMap defaultDirs; - defaultDirs[ TOKEN_STRING(DALI_IMAGE_DIR) ] = DALI_IMAGE_DIR; - defaultDirs[ TOKEN_STRING(DALI_MODEL_DIR) ] = DALI_MODEL_DIR; - defaultDirs[ TOKEN_STRING(DALI_SCRIPT_DIR) ] = DALI_SCRIPT_DIR; + Property::Map defaultDirs; + defaultDirs[ TOKEN_STRING(DEMO_IMAGE_DIR) ] = DEMO_IMAGE_DIR; + defaultDirs[ TOKEN_STRING(DEMO_MODEL_DIR) ] = DEMO_MODEL_DIR; + defaultDirs[ TOKEN_STRING(DEMO_SCRIPT_DIR) ] = DEMO_SCRIPT_DIR; builder.AddConstants( defaultDirs ); @@ -474,7 +462,6 @@ public: } builder.AddActors( layer ); - } @@ -492,9 +479,8 @@ public: { ReloadJsonFile( name, mBuilder, mBuilderLayer ); - // do this here as GetCurrentSize() - mBuilderLayer.SetParentOrigin(ParentOrigin::CENTER); - mBuilderLayer.SetAnchorPoint(AnchorPoint::CENTER); + mBuilderLayer.SetParentOrigin(ParentOrigin::BOTTOM_CENTER); + mBuilderLayer.SetAnchorPoint(AnchorPoint::BOTTOM_CENTER); Dali::Vector3 size = Stage::GetCurrent().GetRootLayer().GetCurrentSize(); size.y -= DemoHelper::DEFAULT_VIEW_STYLE.mToolBarHeight; mBuilderLayer.SetSize( size ); @@ -526,7 +512,8 @@ public: // Create an edit mode button. (left of toolbar) Toolkit::PushButton editButton = Toolkit::PushButton::New(); - editButton.SetBackgroundImage( Image::New( EDIT_IMAGE ) ); + editButton.SetUnselectedImage( EDIT_IMAGE ); + editButton.SetSelectedImage( EDIT_IMAGE_SELECTED ); editButton.ClickedSignal().Connect( this, &ExampleApp::OnToolSelectLayout); editButton.SetLeaveRequired( true ); mToolBar.AddControl( editButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalLeft, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); @@ -559,22 +546,44 @@ public: { if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) { - mApp.Quit(); + if ( mItemView.IsVisible() ) + { + mApp.Quit(); + } + else + { + EnterSelection(); + } } } } + /** + * Event handler when Builder wants to quit (we only want to close the shown json unless we're at the top-level) + */ + void OnBuilderQuit() + { + if ( mItemView.IsVisible() ) + { + mApp.Quit(); + } + else + { + EnterSelection(); + } + } + private: Application& mApp; - GridLayoutPtr mGridLayout; + ItemLayoutPtr mLayout; ItemView mItemView; - Toolkit::View mView; + Toolkit::Control mView; unsigned int mOrientation; Toolkit::ToolBar mToolBar; - TextView mTitleActor; ///< The Toolbar's Title. + TextLabel mTitleActor; ///< The Toolbar's Title. Layer mBuilderLayer; @@ -598,14 +607,17 @@ private: // // //------------------------------------------------------------------------------ -int main(int argc, char **argv) +int DALI_EXPORT_API main(int argc, char **argv) { - if(argc > 1) + if(argc > 2) { - USER_DIRECTORY = argv[1]; + if(strcmp(argv[1], "-f") == 0) + { + USER_DIRECTORY = argv[2]; + } } - Application app = Application::New(&argc, &argv); + Application app = Application::New(&argc, &argv, DEMO_THEME_PATH); ExampleApp dali_app(app);