Remove ResourceImage usage from demos
[platform/core/uifw/dali-demo.git] / shared / view.h
index 0d29283..a0b528f 100644 (file)
@@ -19,6 +19,8 @@
  */
 
 #include <dali-toolkit/dali-toolkit.h>
+#include <dali-toolkit/devel-api/controls/tool-bar/tool-bar.h>
+
 
 namespace DemoHelper
 {
@@ -45,16 +47,11 @@ const ViewStyle DEFAULT_VIEW_STYLE( 0.1f, 0.7f, 80.f, 4.f );
 
 const char*                   DEFAULT_TEXT_STYLE_FONT_FAMILY("HelveticaNue");
 const char*                   DEFAULT_TEXT_STYLE_FONT_STYLE("Regular");
-const Dali::PointSize         DEFAULT_TEXT_STYLE_POINT_SIZE( 8.0f );
-const Dali::TextStyle::Weight DEFAULT_TEXT_STYLE_WEIGHT(Dali::TextStyle::EXTRALIGHT);
-const Dali::Vector4           DEFAULT_TEXT_STYLE_COLOR(0.0f, 0.0f, 0.0f, 1.0f);
+const float                   DEFAULT_TEXT_STYLE_POINT_SIZE( 8.0f );
 
 const Dali::Toolkit::Alignment::Padding DEFAULT_PLAY_PADDING(12.0f, 12.0f, 12.0f, 12.0f);
 const Dali::Toolkit::Alignment::Padding DEFAULT_MODE_SWITCH_PADDING(8.0f, 8.0f, 8.0f, 8.0f);
 
-static Dali::TextStyle defaultTextStyle;
-static bool textStyleSet=false;
-
 float ScalePointSize(int pointSize)
 {
   Dali::Vector2 dpi = Dali::Stage::GetCurrent().GetDpi();
@@ -62,87 +59,70 @@ float ScalePointSize(int pointSize)
   return pointSize * 220.0f / meanDpi;        // 220 is the default horizontal DPI defined in adaptor Application
 }
 
-Dali::TextStyle& GetDefaultTextStyle()
-{
-  if(!textStyleSet)
-  {
-    defaultTextStyle.SetFontName(DEFAULT_TEXT_STYLE_FONT_FAMILY);
-    defaultTextStyle.SetFontStyle(DEFAULT_TEXT_STYLE_FONT_STYLE);
-    defaultTextStyle.SetFontPointSize(Dali::PointSize(ScalePointSize(DEFAULT_TEXT_STYLE_POINT_SIZE)));
-    defaultTextStyle.SetWeight(DEFAULT_TEXT_STYLE_WEIGHT);
-    defaultTextStyle.SetTextColor(DEFAULT_TEXT_STYLE_COLOR);
-    textStyleSet = true;
-  }
-
-  return defaultTextStyle;
-}
-
 Dali::Layer CreateToolbar( Dali::Toolkit::ToolBar& toolBar,
                            const std::string& toolbarImagePath,
                            const std::string& title,
-                           const ViewStyle& style,
-                           const Dali::TextStyle& textStyle )
+                           const ViewStyle& style )
 {
+  Dali::Stage stage = Dali::Stage::GetCurrent();
+
   Dali::Layer toolBarLayer = Dali::Layer::New();
   toolBarLayer.SetName( "TOOLBAR_LAYER" );
   toolBarLayer.SetAnchorPoint( Dali::AnchorPoint::TOP_CENTER );
   toolBarLayer.SetParentOrigin( Dali::ParentOrigin::TOP_CENTER );
-  toolBarLayer.SetPreferredSize( Dali::Vector2( 0.0f, style.mToolBarHeight ) );
-  toolBarLayer.SetResizePolicy( Dali::FILL_TO_PARENT, Dali::WIDTH );
-  toolBarLayer.SetResizePolicy( Dali::FIXED, Dali::HEIGHT );
+  toolBarLayer.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::WIDTH );
+  toolBarLayer.SetSize( 0.0f, style.mToolBarHeight );
 
   // Raise tool bar layer to the top.
   toolBarLayer.RaiseToTop();
 
   // Tool bar
-  Dali::Image image = Dali::ResourceImage::New( toolbarImagePath );
-  Dali::ImageActor toolBarBackground = Dali::ImageActor::New( image );
-  toolBarBackground.SetName( "TOOLBAR_BACKGROUND" );
-  toolBarBackground.SetResizePolicy( Dali::FILL_TO_PARENT, Dali::ALL_DIMENSIONS );
   toolBar = Dali::Toolkit::ToolBar::New();
   toolBar.SetName( "TOOLBAR" );
-  toolBar.SetBackground( toolBarBackground );
+  Dali::Property::Map background;
+  background["url"] = toolbarImagePath;
+  toolBar.SetProperty( Dali::Toolkit::Control::Property::BACKGROUND, background );
   toolBar.SetParentOrigin( Dali::ParentOrigin::TOP_CENTER );
   toolBar.SetAnchorPoint( Dali::AnchorPoint::TOP_CENTER );
-  toolBar.SetResizePolicy( Dali::FILL_TO_PARENT, Dali::ALL_DIMENSIONS );
-  toolBarBackground.SetSortModifier(1.0f);
+  toolBar.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS );
 
-  // Add the tool bar to the too bar layer.
+  // Add the tool bar to the tool bar layer.
   toolBarLayer.Add( toolBar );
 
-  Dali::Font font = Dali::Font::New();
-
   // Tool bar text.
   if( !title.empty() )
   {
-    Dali::Toolkit::TextView titleActor = Dali::Toolkit::TextView::New();
-    titleActor.SetName( "TOOLBAR_TITLE" );
-    titleActor.SetText( title );
-    titleActor.SetSize( font.MeasureText( title ) );
-    titleActor.SetStyleToCurrentText(textStyle);
+    Dali::Toolkit::TextLabel label = Dali::Toolkit::TextLabel::New();
+    label.SetAnchorPoint( Dali::AnchorPoint::TOP_LEFT );
+    label.SetProperty( Dali::Toolkit::Control::Property::STYLE_NAME, "toolbarlabel" );
+    label.SetProperty( Dali::Toolkit::TextLabel::Property::TEXT, title );
+    label.SetProperty( Dali::Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
+    label.SetProperty( Dali::Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
+    label.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::HEIGHT );
 
     // Add title to the tool bar.
     const float padding( style.mToolBarPadding );
-    toolBar.AddControl( titleActor, style.mToolBarTitlePercentage, Dali::Toolkit::Alignment::HorizontalCenter, Dali::Toolkit::Alignment::Padding( padding, padding, padding, padding ) );
+    toolBar.AddControl( label, style.mToolBarTitlePercentage, Dali::Toolkit::Alignment::HorizontalCenter, Dali::Toolkit::Alignment::Padding( padding, padding, padding, padding ) );
   }
 
   return toolBarLayer;
 }
 
 Dali::Layer CreateView( Dali::Application& application,
-                        Dali::Toolkit::View& view,
+                        Dali::Toolkit::Control& view,
                         Dali::Toolkit::ToolBar& toolBar,
                         const std::string& backgroundImagePath,
                         const std::string& toolbarImagePath,
                         const std::string& title,
-                        const ViewStyle& style,
-                        const Dali::TextStyle& textStyle )
+                        const ViewStyle& style = DEFAULT_VIEW_STYLE )
 {
   Dali::Stage stage = Dali::Stage::GetCurrent();
 
   // Create default View.
-  view = Dali::Toolkit::View::New();
-  view.SetResizePolicy( Dali::FILL_TO_PARENT, Dali::ALL_DIMENSIONS );
+  view = Dali::Toolkit::Control::New();
+  view.SetAnchorPoint( Dali::AnchorPoint::CENTER );
+  view.SetParentOrigin( Dali::ParentOrigin::CENTER );
+  view.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS );
 
   // Add the view to the stage before setting the background.
   stage.Add( view );
@@ -150,13 +130,15 @@ Dali::Layer CreateView( Dali::Application& application,
   // Set background image, loading it at screen resolution:
   if ( !backgroundImagePath.empty() )
   {
-    Dali::ImageAttributes backgroundAttributes;
-    backgroundAttributes.SetSize( stage.GetSize() );
-    backgroundAttributes.SetFilterMode( Dali::ImageAttributes::BoxThenLinear );
-    backgroundAttributes.SetScalingMode( Dali::ImageAttributes::ScaleToFill );
-    Dali::Image backgroundImage = Dali::ResourceImage::New( backgroundImagePath, backgroundAttributes );
-    Dali::ImageActor backgroundImageActor = Dali::ImageActor::New( backgroundImage );
-    view.SetBackground( backgroundImageActor );
+    Dali::Property::Map map;
+    map["rendererType"] = "image";
+    map["url"] = backgroundImagePath;
+    map["desiredWidth"] = stage.GetSize().x;
+    map["desiredHeight"] = stage.GetSize().y;
+    map["fittingMode"] = "SCALE_TO_FILL";
+    map["samplingMode"] = "BOX_THEN_LINEAR";
+    map["synchronousLoading"] = true;
+    view.SetProperty( Dali::Toolkit::Control::Property::BACKGROUND, map );
   }
 
   // FIXME
@@ -164,34 +146,32 @@ Dali::Layer CreateView( Dali::Application& application,
   //application.GetOrientation().ChangedSignal().Connect( &view, &Dali::Toolkit::View::OrientationChanged );
 
   // Create default ToolBar
-  Dali::Layer toolBarLayer = CreateToolbar( toolBar, toolbarImagePath, title, style, textStyle );
+  Dali::Layer toolBarLayer = CreateToolbar( toolBar, toolbarImagePath, title, style );
 
   // Add tool bar layer to the view.
-  view.AddContentLayer( toolBarLayer );
+  view.Add( toolBarLayer );
 
   // Create a content layer.
   Dali::Layer contentLayer = Dali::Layer::New();
   contentLayer.SetAnchorPoint( Dali::AnchorPoint::CENTER );
   contentLayer.SetParentOrigin( Dali::ParentOrigin::CENTER );
-  contentLayer.SetResizePolicy( Dali::FILL_TO_PARENT, Dali::ALL_DIMENSIONS );
-  view.AddContentLayer( contentLayer );
+  contentLayer.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS );
+  view.Add( contentLayer );
   contentLayer.LowerBelow( toolBarLayer );
 
   return contentLayer;
 }
 
-Dali::Layer CreateView( Dali::Application& application,
-                        Dali::Toolkit::View& view,
-                        Dali::Toolkit::ToolBar& toolBar,
-                        const std::string& backgroundImagePath,
-                        const std::string& toolbarImagePath,
-                        const std::string& title,
-                        const ViewStyle& style  = DEFAULT_VIEW_STYLE )
+Dali::Toolkit::TextLabel CreateToolBarLabel( const std::string& text )
 {
-  return CreateView( application, view, toolBar, backgroundImagePath, toolbarImagePath, title, style,
-                     GetDefaultTextStyle() );
-}
+  Dali::Toolkit::TextLabel label = Dali::Toolkit::TextLabel::New( text );
+  label.SetProperty( Dali::Toolkit::Control::Property::STYLE_NAME, "toolbarlabel" );
+  label.SetProperty( Dali::Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
+  label.SetProperty( Dali::Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
+  label.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::HEIGHT );
 
+  return label;
+}
 
 } // DemoHelper