diff --git a/com.samsung.dali-demo.xml b/com.samsung.dali-demo.xml index cf4763d..dea3e21 100644 --- a/com.samsung.dali-demo.xml +++ b/com.samsung.dali-demo.xml @@ -88,4 +88,7 @@ + + + diff --git a/demo/dali-table-view.cpp b/demo/dali-table-view.cpp index 2856f9a..1b7711c 100644 --- a/demo/dali-table-view.cpp +++ b/demo/dali-table-view.cpp @@ -168,11 +168,36 @@ bool CompareByTitle( const Example& lhs, const Example& rhs ) } // namespace DaliTableView::DaliTableView( Application& application ) - : mApplication( application ), - mScrolling( false ), - mBackgroundImagePath( DEFAULT_BACKGROUND_IMAGE_PATH ), - mSortAlphabetically( false ), - mBackgroundAnimsPlaying( false ) +: mApplication( application ), + mBackgroundLayer(), + mRootActor(), + mRotateAnimation(), + mBackground(), + mLogo(), + mPressedAnimation(), + mScrollViewLayer(), + mScrollView(), + mScrollViewEffect(), + mScrollRulerX(), + mScrollRulerY(), + mButtons(), + mPressedActor(), + mAnimationTimer(), + mLogoTapDetector(), + mVersionPopup(), + mButtonsPageRelativeSize(), + mPages(), + mTableViewImages(), + mBackgroundActors(), + mBackgroundAnimations(), + mExampleList(), + mExampleMap(), + mBackgroundImagePath( DEFAULT_BACKGROUND_IMAGE_PATH ), + mTotalPages(), + mScrolling( false ), + mSortAlphabetically( false ), + mBackgroundAnimsPlaying( false ), + mVersionPopupShown( false ) { application.InitSignal().Connect( this, &DaliTableView::Initialize ); } @@ -233,6 +258,11 @@ void DaliTableView::Initialize( Application& application ) const float logoHeight = mLogo.GetImage().GetHeight() + logoMargin; mRootActor.SetFixedHeight( 1, logoHeight ); + // Show version in a popup when log is tapped + mLogoTapDetector = TapGestureDetector::New(); + mLogoTapDetector.Attach( mLogo ); + mLogoTapDetector.DetectedSignal().Connect( this, &DaliTableView::OnLogoTapped ); + const float bottomMargin = paddingHeight * BOTTOM_PADDING_RATIO; mButtonsPageRelativeSize = Vector3( TABLE_RELATIVE_SIZE.x, 1.f - ( toolbarHeight + logoHeight + bottomMargin) / stageSize.height, TABLE_RELATIVE_SIZE.z ); mRootActor.SetFixedHeight( 2, mButtonsPageRelativeSize.y * stageSize.height ); @@ -661,7 +691,14 @@ void DaliTableView::OnKeyEvent( const KeyEvent& event ) { if ( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) { - mApplication.Quit(); + if ( mVersionPopup && mVersionPopupShown ) + { + HideVersionPopup(); + } + else + { + mApplication.Quit(); + } } } } @@ -926,3 +963,46 @@ bool DaliTableView::OnTileHovered( Actor actor, const HoverEvent& event ) KeyboardFocusManager::Get().SetCurrentFocusActor( actor ); return true; } + +void DaliTableView::OnLogoTapped( Dali::Actor actor, const Dali::TapGesture& tap ) +{ + if ( !mVersionPopupShown ) + { + if ( !mVersionPopup ) + { + std::ostringstream stream; + stream << "DALi Core: " << CORE_MAJOR_VERSION << "." << CORE_MINOR_VERSION << "." << CORE_MICRO_VERSION << std::endl << "(" << CORE_BUILD_DATE << ")" << std::endl << std::endl; + stream << "DALi Adaptor: " << ADAPTOR_MAJOR_VERSION << "." << ADAPTOR_MINOR_VERSION << "." << ADAPTOR_MICRO_VERSION << std::endl << "(" << ADAPTOR_BUILD_DATE << ")" << std::endl << std::endl; + stream << "DALi Toolkit: " << TOOLKIT_MAJOR_VERSION << "." << TOOLKIT_MINOR_VERSION << "." << TOOLKIT_MICRO_VERSION << std::endl << "(" << TOOLKIT_BUILD_DATE << ")"; + + mVersionPopup = Dali::Toolkit::Popup::New(); + mVersionPopup.SetTitle( stream.str() ); + mVersionPopup.SetParentOrigin( ParentOrigin::CENTER ); + mVersionPopup.SetAnchorPoint( AnchorPoint::CENTER ); + mVersionPopup.HideTail(); + mVersionPopup.OutsideTouchedSignal().Connect( this, &DaliTableView::HideVersionPopup ); + mVersionPopup.HiddenSignal().Connect( this, &DaliTableView::PopupHidden ); + + Dali::Stage::GetCurrent().Add( mVersionPopup ); + } + + mVersionPopup.Show(); + mVersionPopupShown = true; + } +} + +void DaliTableView::HideVersionPopup() +{ + if ( mVersionPopup ) + { + mVersionPopup.Hide(); + } +} + +void DaliTableView::PopupHidden() +{ + if ( mVersionPopup ) + { + mVersionPopupShown = false; + } +} diff --git a/demo/dali-table-view.h b/demo/dali-table-view.h index bc77fba..fbaa2ea 100644 --- a/demo/dali-table-view.h +++ b/demo/dali-table-view.h @@ -360,38 +360,59 @@ private: // Application callbacks & implementation */ void OnFocusedActorActivated( Dali::Actor activatedActor ); + /** + * Called when the logo is tapped + * + * @param[in] actor The tapped actor + * @param[in] tap The tap information. + */ + void OnLogoTapped( Dali::Actor actor, const Dali::TapGesture& tap ); + + /** + * Hides the popup + */ + void HideVersionPopup(); + + /** + * Called when the popup is completely hidden + */ + void PopupHidden(); + private: - Dali::Application& mApplication; ///< Application instance. - Dali::Layer mBackgroundLayer; ///< Background resides on a separate layer. - Dali::Toolkit::TableView mRootActor; ///< All content (excluding background is anchored to this Actor) - Dali::Animation mRotateAnimation; ///< Animation to rotate and resize mRootActor. - Dali::ImageActor mBackground; ///< Background's static image. - Dali::ImageActor mLogo; ///< Logo's static image. - Dali::Animation mPressedAnimation; ///< Button press scaling animation. - Dali::Layer mScrollViewLayer; ///< ScrollView resides on a separate layer. - Dali::Toolkit::ScrollView mScrollView; ///< ScrollView container (for all Examples) - Dali::Toolkit::ScrollViewEffect mScrollViewEffect; ///< Effect to be applied to the scroll view - bool mScrolling; ///< Flag indicating whether view is currently being scrolled - Dali::Toolkit::RulerPtr mScrollRulerX; ///< ScrollView X (horizontal) ruler - Dali::Toolkit::RulerPtr mScrollRulerY; ///< ScrollView Y (vertical) ruler - Dali::Toolkit::TableView mButtons; ///< Navigation buttons - ExampleList mExampleList; ///< List of examples. - ExampleMap mExampleMap; ///< Map LUT for examples. - Dali::ActorContainer mPages; ///< List of pages. - Dali::Actor mPressedActor; ///< The currently pressed actor. - int mTotalPages; ///< Total pages within scrollview. - std::string mBackgroundImagePath; ///< The path to the background image. - bool mSortAlphabetically; ///< Sort examples alphabetically. - - Dali::ActorContainer mTableViewImages; ///< Offscreen render of tableview - Dali::ActorContainer mBackgroundActors; ///< List of background actors used in the effect - - AnimationList mBackgroundAnimations;///< List of background bubble animations - Dali::Timer mAnimationTimer; ///< Timer used to turn off animation after a specific time period - bool mBackgroundAnimsPlaying; ///< Are background animations playing - - Dali::Vector3 mButtonsPageRelativeSize; ///< Size of a buttons page relative to the stage size + Dali::Application& mApplication; ///< Application instance. + Dali::Layer mBackgroundLayer; ///< Background resides on a separate layer. + Dali::Toolkit::TableView mRootActor; ///< All content (excluding background is anchored to this Actor) + Dali::Animation mRotateAnimation; ///< Animation to rotate and resize mRootActor. + Dali::ImageActor mBackground; ///< Background's static image. + Dali::ImageActor mLogo; ///< Logo's static image. + Dali::Animation mPressedAnimation; ///< Button press scaling animation. + Dali::Layer mScrollViewLayer; ///< ScrollView resides on a separate layer. + Dali::Toolkit::ScrollView mScrollView; ///< ScrollView container (for all Examples) + Dali::Toolkit::ScrollViewEffect mScrollViewEffect; ///< Effect to be applied to the scroll view + Dali::Toolkit::RulerPtr mScrollRulerX; ///< ScrollView X (horizontal) ruler + Dali::Toolkit::RulerPtr mScrollRulerY; ///< ScrollView Y (vertical) ruler + Dali::Toolkit::TableView mButtons; ///< Navigation buttons + Dali::Actor mPressedActor; ///< The currently pressed actor. + Dali::Timer mAnimationTimer; ///< Timer used to turn off animation after a specific time period + Dali::TapGestureDetector mLogoTapDetector; ///< To detect taps on the logo + Dali::Toolkit::Popup mVersionPopup; ///< Displays DALi library version information + Dali::Vector3 mButtonsPageRelativeSize; ///< Size of a buttons page relative to the stage size + + Dali::ActorContainer mPages; ///< List of pages. + Dali::ActorContainer mTableViewImages; ///< Offscreen render of tableview + Dali::ActorContainer mBackgroundActors; ///< List of background actors used in the effect + AnimationList mBackgroundAnimations; ///< List of background bubble animations + ExampleList mExampleList; ///< List of examples. + ExampleMap mExampleMap; ///< Map LUT for examples. + + std::string mBackgroundImagePath; ///< The path to the background image. + int mTotalPages; ///< Total pages within scrollview. + + bool mScrolling:1; ///< Flag indicating whether view is currently being scrolled + bool mSortAlphabetically:1; ///< Sort examples alphabetically. + bool mBackgroundAnimsPlaying:1; ///< Are background animations playing + bool mVersionPopupShown:1; ///< Whehter the version popup is shown or not }; #endif // __DALI_DEMO_H__ diff --git a/examples/atlas/atlas-example.cpp b/examples/atlas/atlas-example.cpp new file mode 100644 index 0000000..70a9aa9 --- /dev/null +++ b/examples/atlas/atlas-example.cpp @@ -0,0 +1,232 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include "shared/view.h" +#include +#include + +using namespace Dali; + +class AtlasController; + +namespace +{ +const char * const BACKGROUND_IMAGE( DALI_IMAGE_DIR "background-gradient.jpg" ); +const char * const TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" ); +const char * const LOSE_CONTEXT_IMAGE( DALI_IMAGE_DIR "icon-cluster-wobble.png" ); + +Application gApplication; +AtlasController* gAtlasController(NULL); +} + +class AtlasController : public ConnectionTracker +{ +public: + + AtlasController( Application& application ) + : mApplication( application ) + { + // Connect to the Application's Init signal + mApplication.InitSignal().Connect( this, &AtlasController::Create ); + } + + ~AtlasController() + { + // Nothing to do here; + } + + void Create( Application& application ) + { + // Get a handle to the stage + Stage stage = Stage::GetCurrent(); + stage.SetBackgroundColor(Color::YELLOW); + + // Respond to a click anywhere on the stage + stage.KeyEventSignal().Connect(this, &AtlasController::OnKeyEvent); + + mApplication.GetWindow().ShowIndicator( Dali::Window::INVISIBLE ); + + mContentLayer = DemoHelper::CreateView( mApplication, + mView, + mToolBar, + BACKGROUND_IMAGE, + TOOLBAR_IMAGE, + "Atlas" ); + + mLoseContextButton = Toolkit::PushButton::New(); + mLoseContextButton.SetBackgroundImage( ResourceImage::New( LOSE_CONTEXT_IMAGE ) ); + mLoseContextButton.ClickedSignal().Connect( this, &AtlasController::OnLoseContextButtonClicked ); + mToolBar.AddControl( mLoseContextButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + + mAtlas = Atlas::New( 400,300, Pixel::RGBA8888); + mAtlas.Clear(Vector4(0.f,0.5f,0.5f,0.5f)); + mAtlas.Upload( DALI_IMAGE_DIR "icon-change.png", 50, 30 ); + mAtlas.Upload( DALI_IMAGE_DIR "icon-cluster-carousel.png", 100, 30 ); + mAtlas.Upload( DALI_IMAGE_DIR "icon-effects-on.png", 150, 30 ); + mAtlas.Upload( DALI_IMAGE_DIR "icon-effect-cross.png", 100, 80 ); + mAtlas.Upload( DALI_IMAGE_DIR "icon-effect-fold.png", 150, 80 ); + mAtlas.Upload( DALI_IMAGE_DIR "icon-effect-wave.png", 200, 80 ); + mAtlas.Upload( DALI_IMAGE_DIR "icon-item-view-layout-depth.png", 150, 130 ); + mAtlas.Upload( DALI_IMAGE_DIR "icon-item-view-layout-grid.png", 200, 130 ); + mAtlas.Upload( DALI_IMAGE_DIR "icon-item-view-layout-spiral.png", 250, 130 ); + UploadBufferImages(); + + ImageActor imageActor1 = ImageActor::New( mAtlas ); + imageActor1.SetY(-170.f); + imageActor1.SetParentOrigin(ParentOrigin::CENTER); + mContentLayer.Add( imageActor1 ); + + Atlas atlas2 = Atlas::New( 400,400, Pixel::RGB888); + atlas2.Clear( Color::RED ); + atlas2.Upload( DALI_IMAGE_DIR "gallery-small-1.jpg", 4, 4 ); + atlas2.Clear( Color::BLUE ); + atlas2.Upload( DALI_IMAGE_DIR "gallery-small-2.jpg", 136, 4 ); + atlas2.Upload( DALI_IMAGE_DIR "gallery-small-3.jpg", 268, 4 ); + atlas2.Upload( DALI_IMAGE_DIR "gallery-small-4.jpg", 4, 136 ); + atlas2.Upload( DALI_IMAGE_DIR "gallery-small-5.jpg", 136, 136 ); + atlas2.Upload( DALI_IMAGE_DIR "gallery-small-6.jpg", 268, 135 ); + atlas2.Upload( DALI_IMAGE_DIR "gallery-small-7.jpg", 4, 268 ); + atlas2.Upload( DALI_IMAGE_DIR "gallery-small-7.jpg", 136, 268 ); + atlas2.Upload( DALI_IMAGE_DIR "gallery-small-7.jpg", 268, 268 ); + + + ImageActor imageActor2 = ImageActor::New( atlas2 ); + imageActor2.SetY(200.f); + imageActor2.SetZ(-1.f); + imageActor2.SetParentOrigin(ParentOrigin::CENTER); + mContentLayer.Add( imageActor2 ); + + mPanGestureDetector = PanGestureDetector::New(); + mPanGestureDetector.DetectedSignal().Connect(this, &AtlasController::OnPanGesture); + mPanGestureDetector.Attach(imageActor1); + mPanGestureDetector.Attach(imageActor2); + + stage.ContextLostSignal().Connect(this, &AtlasController::OnContextLost); + stage.ContextRegainedSignal().Connect(this, &AtlasController::OnContextRegained); + } + + void UploadBufferImages() + { + mAtlas.Upload( CreateBufferImage( Vector4(1.f, 1.f, 1.f, 0.5f ), 80, 90 ), 0, 210 ); + mAtlas.Upload( CreateBufferImage( Vector4(1.f, 1.f, 0.75f, 0.5f ), 80, 80 ), 40, 210 ); + mAtlas.Upload( CreateBufferImage( Vector4(1.f, 1.f, 0.5f, 0.5f ), 80, 70 ), 80, 210 ); + mAtlas.Upload( CreateBufferImage( Vector4(1.f, 1.f, 0.25f, 0.5f ), 80, 60 ), 120, 210 ); + mAtlas.Upload( CreateBufferImage( Vector4(1.f, 1.f, 0.f, 0.5f ), 80, 50 ), 160, 210 ); + mAtlas.Upload( CreateBufferImage( Vector4(0.75f, 0.75f, 0.f, 0.5f ), 80, 40 ), 200, 210 ); + mAtlas.Upload( CreateBufferImage( Vector4(0.5f, 0.5f, 0.f, 0.5f ), 80, 30 ), 240, 210 ); + mAtlas.Upload( CreateBufferImage( Vector4(0.25f, 0.25f, 0.f, 0.5f ), 80, 20 ), 280, 210 ); + mAtlas.Upload( CreateBufferImage( Vector4(0.1f, 0.1f, 0.f, 0.5f ), 80, 10 ), 320, 210 ); + BufferImage redBlock = CreateBufferImage( Color::RED, 40, 40 ); + mAtlas.Upload(redBlock, 320, 30); + mAtlas.Upload(redBlock, 320, 80); + mAtlas.Upload(redBlock, 320, 130); + } + + static void NewWindow(void) + { + PositionSize posSize(0, 0, 720, 1280); + gApplication.ReplaceWindow(posSize, "NewWindow"); // Generates a new window + } + + bool OnLoseContextButtonClicked( Toolkit::Button button ) + { + // Add as an idle callback to avoid ProcessEvents being recursively called. + mApplication.AddIdle(MakeCallback( AtlasController::NewWindow )); + return true; + } + + void OnKeyEvent( const KeyEvent& event ) + { + if(event.state == KeyEvent::Down) + { + if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + { + mApplication.Quit(); + } + } + } + + void OnPanGesture( Actor actor, const PanGesture& gesture ) + { + if( gesture.state == Gesture::Continuing ) + { + actor.MoveBy( Vector3( gesture.displacement ) ); + } + } + + void OnContextLost() + { + printf("Stage reporting context loss\n"); + } + + void OnContextRegained() + { + printf("Stage reporting context regain\n"); + UploadBufferImages(); + } + +private: + + BufferImage CreateBufferImage( const Vector4& color, const unsigned int width, const unsigned int height ) + { + BufferImage imageData = BufferImage::New( width, height, Pixel::RGBA8888 ); + + // Create the image + PixelBuffer* pixbuf = imageData.GetBuffer(); + const unsigned int bitmapSize = width * height; + for( size_t i = 0; i < bitmapSize; ++i ) + { + pixbuf[i*4+0] = 0xFF * color.r; + pixbuf[i*4+1] = 0xFF * color.g; + pixbuf[i*4+2] = 0xFF * color.b; + pixbuf[i*4+3] = 0xFF * color.a; + } + + imageData.Update(); + + return imageData; + } + + +private: + Application& mApplication; + PanGestureDetector mPanGestureDetector; + + Toolkit::View mView; ///< The View instance. + Toolkit::ToolBar mToolBar; ///< The View's Toolbar. + Layer mContentLayer; ///< Content layer (scrolling cluster content) + Toolkit::PushButton mLoseContextButton; + Atlas mAtlas; +}; + +void RunTest( Application& application ) +{ + gAtlasController = new AtlasController(application); + application.MainLoop(Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS); +} + +// Entry point for Linux & SLP applications +// +int main( int argc, char **argv ) +{ + gApplication = Application::New( &argc, &argv ); + + RunTest( gApplication ); + + return 0; +} diff --git a/examples/item-view/item-view-example.cpp b/examples/item-view/item-view-example.cpp index 4a69d44..40fb073 100644 --- a/examples/item-view/item-view-example.cpp +++ b/examples/item-view/item-view-example.cpp @@ -99,6 +99,10 @@ const char* IMAGE_PATHS[] = { const unsigned int NUM_IMAGES = sizeof(IMAGE_PATHS) / sizeof(char*); +const unsigned int IMAGE_WIDTH = 256; +const unsigned int IMAGE_HEIGHT = 256; +const unsigned int NUM_IMAGE_PER_ROW_IN_ATLAS = 8; + AlphaFunction ALPHA_FUNCTIONS[] = { AlphaFunctions::Linear, AlphaFunctions::EaseIn, AlphaFunctions::EaseOut }; @@ -310,6 +314,7 @@ public: stage.Add( mReplaceButton ); // Create the item view actor + mImageAtlas = CreateImageAtlas(); mItemView = ItemView::New(*this); mItemView.SetParentOrigin(ParentOrigin::CENTER); mItemView.SetAnchorPoint(AnchorPoint::CENTER); @@ -874,8 +879,12 @@ public: // From ItemFactory virtual Actor NewItem(unsigned int itemId) { // Create an image actor for this item - Image image = ResourceImage::New( IMAGE_PATHS[itemId % NUM_IMAGES] ); - Actor actor = ImageActor::New(image); + unsigned int imageId = itemId % NUM_IMAGES; + ImageActor::PixelArea pixelArea( (imageId%NUM_IMAGE_PER_ROW_IN_ATLAS)*IMAGE_WIDTH, + (imageId/NUM_IMAGE_PER_ROW_IN_ATLAS)*IMAGE_HEIGHT, + IMAGE_WIDTH, + IMAGE_HEIGHT ); + Actor actor = ImageActor::New(mImageAtlas, pixelArea); actor.SetPosition( INITIAL_OFFSCREEN_POSITION ); // Add a border image child actor @@ -934,6 +943,23 @@ public: // From ItemFactory private: /** + * Create an Atlas to tile the images inside. + */ + Atlas CreateImageAtlas() + { + const unsigned int atlas_width = IMAGE_WIDTH*NUM_IMAGE_PER_ROW_IN_ATLAS; + const unsigned int atlas_height = IMAGE_HEIGHT*ceil( static_cast(NUM_IMAGES)/ static_cast(NUM_IMAGE_PER_ROW_IN_ATLAS)); + Atlas atlas = Atlas::New(atlas_width, atlas_height, Pixel::RGB888); + + for( unsigned int i = 0; i < NUM_IMAGES; i++ ) + { + atlas.Upload( IMAGE_PATHS[i], (i%NUM_IMAGE_PER_ROW_IN_ATLAS)*IMAGE_WIDTH, (i/NUM_IMAGE_PER_ROW_IN_ATLAS)*IMAGE_HEIGHT ); + } + + return atlas; + } + + /** * Sets/Updates the title of the View * @param[in] title The new title for the view. */ @@ -1050,6 +1076,7 @@ private: ItemView mItemView; Image mBorderImage; + Atlas mImageAtlas; unsigned int mCurrentLayout; float mDurationSeconds; diff --git a/packaging/com.samsung.dali-demo.spec b/packaging/com.samsung.dali-demo.spec index 8115a00..59480fe 100755 --- a/packaging/com.samsung.dali-demo.spec +++ b/packaging/com.samsung.dali-demo.spec @@ -2,7 +2,7 @@ Name: com.samsung.dali-demo Summary: The OpenGLES Canvas Core Demo -Version: 1.0.32 +Version: 1.0.33 Release: 1 Group: System/Libraries License: Apache-2.0