Commit bc208134da08d558201015e2f36efa50e718ed4a
Merge remote-tracking branch 'origin/tizen' into new_text
Change-Id: Id953da32620c4a3c57519cf9f5ecd74eb765a430
Showing
6 changed files
with
402 additions
and
39 deletions
com.samsung.dali-demo.xml
| ... | ... | @@ -88,4 +88,7 @@ |
| 88 | 88 | <ui-application appid="path-animation.example" exec="/usr/apps/com.samsung.dali-demo/bin/path-animation.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true"> |
| 89 | 89 | <label>Path Animation</label> |
| 90 | 90 | </ui-application> |
| 91 | + <ui-application appid="atlas.example" exec="/usr/apps/com.samsung.dali-demo/bin/atlas.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true"> | |
| 92 | + <label>Atlas</label> | |
| 93 | + </ui-application> | |
| 91 | 94 | </manifest> | ... | ... |
demo/dali-table-view.cpp
| ... | ... | @@ -168,11 +168,36 @@ bool CompareByTitle( const Example& lhs, const Example& rhs ) |
| 168 | 168 | } // namespace |
| 169 | 169 | |
| 170 | 170 | DaliTableView::DaliTableView( Application& application ) |
| 171 | - : mApplication( application ), | |
| 172 | - mScrolling( false ), | |
| 173 | - mBackgroundImagePath( DEFAULT_BACKGROUND_IMAGE_PATH ), | |
| 174 | - mSortAlphabetically( false ), | |
| 175 | - mBackgroundAnimsPlaying( false ) | |
| 171 | +: mApplication( application ), | |
| 172 | + mBackgroundLayer(), | |
| 173 | + mRootActor(), | |
| 174 | + mRotateAnimation(), | |
| 175 | + mBackground(), | |
| 176 | + mLogo(), | |
| 177 | + mPressedAnimation(), | |
| 178 | + mScrollViewLayer(), | |
| 179 | + mScrollView(), | |
| 180 | + mScrollViewEffect(), | |
| 181 | + mScrollRulerX(), | |
| 182 | + mScrollRulerY(), | |
| 183 | + mButtons(), | |
| 184 | + mPressedActor(), | |
| 185 | + mAnimationTimer(), | |
| 186 | + mLogoTapDetector(), | |
| 187 | + mVersionPopup(), | |
| 188 | + mButtonsPageRelativeSize(), | |
| 189 | + mPages(), | |
| 190 | + mTableViewImages(), | |
| 191 | + mBackgroundActors(), | |
| 192 | + mBackgroundAnimations(), | |
| 193 | + mExampleList(), | |
| 194 | + mExampleMap(), | |
| 195 | + mBackgroundImagePath( DEFAULT_BACKGROUND_IMAGE_PATH ), | |
| 196 | + mTotalPages(), | |
| 197 | + mScrolling( false ), | |
| 198 | + mSortAlphabetically( false ), | |
| 199 | + mBackgroundAnimsPlaying( false ), | |
| 200 | + mVersionPopupShown( false ) | |
| 176 | 201 | { |
| 177 | 202 | application.InitSignal().Connect( this, &DaliTableView::Initialize ); |
| 178 | 203 | } |
| ... | ... | @@ -233,6 +258,11 @@ void DaliTableView::Initialize( Application& application ) |
| 233 | 258 | const float logoHeight = mLogo.GetImage().GetHeight() + logoMargin; |
| 234 | 259 | mRootActor.SetFixedHeight( 1, logoHeight ); |
| 235 | 260 | |
| 261 | + // Show version in a popup when log is tapped | |
| 262 | + mLogoTapDetector = TapGestureDetector::New(); | |
| 263 | + mLogoTapDetector.Attach( mLogo ); | |
| 264 | + mLogoTapDetector.DetectedSignal().Connect( this, &DaliTableView::OnLogoTapped ); | |
| 265 | + | |
| 236 | 266 | const float bottomMargin = paddingHeight * BOTTOM_PADDING_RATIO; |
| 237 | 267 | mButtonsPageRelativeSize = Vector3( TABLE_RELATIVE_SIZE.x, 1.f - ( toolbarHeight + logoHeight + bottomMargin) / stageSize.height, TABLE_RELATIVE_SIZE.z ); |
| 238 | 268 | mRootActor.SetFixedHeight( 2, mButtonsPageRelativeSize.y * stageSize.height ); |
| ... | ... | @@ -661,7 +691,14 @@ void DaliTableView::OnKeyEvent( const KeyEvent& event ) |
| 661 | 691 | { |
| 662 | 692 | if ( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) |
| 663 | 693 | { |
| 664 | - mApplication.Quit(); | |
| 694 | + if ( mVersionPopup && mVersionPopupShown ) | |
| 695 | + { | |
| 696 | + HideVersionPopup(); | |
| 697 | + } | |
| 698 | + else | |
| 699 | + { | |
| 700 | + mApplication.Quit(); | |
| 701 | + } | |
| 665 | 702 | } |
| 666 | 703 | } |
| 667 | 704 | } |
| ... | ... | @@ -926,3 +963,46 @@ bool DaliTableView::OnTileHovered( Actor actor, const HoverEvent& event ) |
| 926 | 963 | KeyboardFocusManager::Get().SetCurrentFocusActor( actor ); |
| 927 | 964 | return true; |
| 928 | 965 | } |
| 966 | + | |
| 967 | +void DaliTableView::OnLogoTapped( Dali::Actor actor, const Dali::TapGesture& tap ) | |
| 968 | +{ | |
| 969 | + if ( !mVersionPopupShown ) | |
| 970 | + { | |
| 971 | + if ( !mVersionPopup ) | |
| 972 | + { | |
| 973 | + std::ostringstream stream; | |
| 974 | + stream << "DALi Core: " << CORE_MAJOR_VERSION << "." << CORE_MINOR_VERSION << "." << CORE_MICRO_VERSION << std::endl << "(" << CORE_BUILD_DATE << ")" << std::endl << std::endl; | |
| 975 | + stream << "DALi Adaptor: " << ADAPTOR_MAJOR_VERSION << "." << ADAPTOR_MINOR_VERSION << "." << ADAPTOR_MICRO_VERSION << std::endl << "(" << ADAPTOR_BUILD_DATE << ")" << std::endl << std::endl; | |
| 976 | + stream << "DALi Toolkit: " << TOOLKIT_MAJOR_VERSION << "." << TOOLKIT_MINOR_VERSION << "." << TOOLKIT_MICRO_VERSION << std::endl << "(" << TOOLKIT_BUILD_DATE << ")"; | |
| 977 | + | |
| 978 | + mVersionPopup = Dali::Toolkit::Popup::New(); | |
| 979 | + mVersionPopup.SetTitle( stream.str() ); | |
| 980 | + mVersionPopup.SetParentOrigin( ParentOrigin::CENTER ); | |
| 981 | + mVersionPopup.SetAnchorPoint( AnchorPoint::CENTER ); | |
| 982 | + mVersionPopup.HideTail(); | |
| 983 | + mVersionPopup.OutsideTouchedSignal().Connect( this, &DaliTableView::HideVersionPopup ); | |
| 984 | + mVersionPopup.HiddenSignal().Connect( this, &DaliTableView::PopupHidden ); | |
| 985 | + | |
| 986 | + Dali::Stage::GetCurrent().Add( mVersionPopup ); | |
| 987 | + } | |
| 988 | + | |
| 989 | + mVersionPopup.Show(); | |
| 990 | + mVersionPopupShown = true; | |
| 991 | + } | |
| 992 | +} | |
| 993 | + | |
| 994 | +void DaliTableView::HideVersionPopup() | |
| 995 | +{ | |
| 996 | + if ( mVersionPopup ) | |
| 997 | + { | |
| 998 | + mVersionPopup.Hide(); | |
| 999 | + } | |
| 1000 | +} | |
| 1001 | + | |
| 1002 | +void DaliTableView::PopupHidden() | |
| 1003 | +{ | |
| 1004 | + if ( mVersionPopup ) | |
| 1005 | + { | |
| 1006 | + mVersionPopupShown = false; | |
| 1007 | + } | |
| 1008 | +} | ... | ... |
demo/dali-table-view.h
| ... | ... | @@ -360,38 +360,59 @@ private: // Application callbacks & implementation |
| 360 | 360 | */ |
| 361 | 361 | void OnFocusedActorActivated( Dali::Actor activatedActor ); |
| 362 | 362 | |
| 363 | + /** | |
| 364 | + * Called when the logo is tapped | |
| 365 | + * | |
| 366 | + * @param[in] actor The tapped actor | |
| 367 | + * @param[in] tap The tap information. | |
| 368 | + */ | |
| 369 | + void OnLogoTapped( Dali::Actor actor, const Dali::TapGesture& tap ); | |
| 370 | + | |
| 371 | + /** | |
| 372 | + * Hides the popup | |
| 373 | + */ | |
| 374 | + void HideVersionPopup(); | |
| 375 | + | |
| 376 | + /** | |
| 377 | + * Called when the popup is completely hidden | |
| 378 | + */ | |
| 379 | + void PopupHidden(); | |
| 380 | + | |
| 363 | 381 | private: |
| 364 | 382 | |
| 365 | - Dali::Application& mApplication; ///< Application instance. | |
| 366 | - Dali::Layer mBackgroundLayer; ///< Background resides on a separate layer. | |
| 367 | - Dali::Toolkit::TableView mRootActor; ///< All content (excluding background is anchored to this Actor) | |
| 368 | - Dali::Animation mRotateAnimation; ///< Animation to rotate and resize mRootActor. | |
| 369 | - Dali::ImageActor mBackground; ///< Background's static image. | |
| 370 | - Dali::ImageActor mLogo; ///< Logo's static image. | |
| 371 | - Dali::Animation mPressedAnimation; ///< Button press scaling animation. | |
| 372 | - Dali::Layer mScrollViewLayer; ///< ScrollView resides on a separate layer. | |
| 373 | - Dali::Toolkit::ScrollView mScrollView; ///< ScrollView container (for all Examples) | |
| 374 | - Dali::Toolkit::ScrollViewEffect mScrollViewEffect; ///< Effect to be applied to the scroll view | |
| 375 | - bool mScrolling; ///< Flag indicating whether view is currently being scrolled | |
| 376 | - Dali::Toolkit::RulerPtr mScrollRulerX; ///< ScrollView X (horizontal) ruler | |
| 377 | - Dali::Toolkit::RulerPtr mScrollRulerY; ///< ScrollView Y (vertical) ruler | |
| 378 | - Dali::Toolkit::TableView mButtons; ///< Navigation buttons | |
| 379 | - ExampleList mExampleList; ///< List of examples. | |
| 380 | - ExampleMap mExampleMap; ///< Map LUT for examples. | |
| 381 | - Dali::ActorContainer mPages; ///< List of pages. | |
| 382 | - Dali::Actor mPressedActor; ///< The currently pressed actor. | |
| 383 | - int mTotalPages; ///< Total pages within scrollview. | |
| 384 | - std::string mBackgroundImagePath; ///< The path to the background image. | |
| 385 | - bool mSortAlphabetically; ///< Sort examples alphabetically. | |
| 386 | - | |
| 387 | - Dali::ActorContainer mTableViewImages; ///< Offscreen render of tableview | |
| 388 | - Dali::ActorContainer mBackgroundActors; ///< List of background actors used in the effect | |
| 389 | - | |
| 390 | - AnimationList mBackgroundAnimations;///< List of background bubble animations | |
| 391 | - Dali::Timer mAnimationTimer; ///< Timer used to turn off animation after a specific time period | |
| 392 | - bool mBackgroundAnimsPlaying; ///< Are background animations playing | |
| 393 | - | |
| 394 | - Dali::Vector3 mButtonsPageRelativeSize; ///< Size of a buttons page relative to the stage size | |
| 383 | + Dali::Application& mApplication; ///< Application instance. | |
| 384 | + Dali::Layer mBackgroundLayer; ///< Background resides on a separate layer. | |
| 385 | + Dali::Toolkit::TableView mRootActor; ///< All content (excluding background is anchored to this Actor) | |
| 386 | + Dali::Animation mRotateAnimation; ///< Animation to rotate and resize mRootActor. | |
| 387 | + Dali::ImageActor mBackground; ///< Background's static image. | |
| 388 | + Dali::ImageActor mLogo; ///< Logo's static image. | |
| 389 | + Dali::Animation mPressedAnimation; ///< Button press scaling animation. | |
| 390 | + Dali::Layer mScrollViewLayer; ///< ScrollView resides on a separate layer. | |
| 391 | + Dali::Toolkit::ScrollView mScrollView; ///< ScrollView container (for all Examples) | |
| 392 | + Dali::Toolkit::ScrollViewEffect mScrollViewEffect; ///< Effect to be applied to the scroll view | |
| 393 | + Dali::Toolkit::RulerPtr mScrollRulerX; ///< ScrollView X (horizontal) ruler | |
| 394 | + Dali::Toolkit::RulerPtr mScrollRulerY; ///< ScrollView Y (vertical) ruler | |
| 395 | + Dali::Toolkit::TableView mButtons; ///< Navigation buttons | |
| 396 | + Dali::Actor mPressedActor; ///< The currently pressed actor. | |
| 397 | + Dali::Timer mAnimationTimer; ///< Timer used to turn off animation after a specific time period | |
| 398 | + Dali::TapGestureDetector mLogoTapDetector; ///< To detect taps on the logo | |
| 399 | + Dali::Toolkit::Popup mVersionPopup; ///< Displays DALi library version information | |
| 400 | + Dali::Vector3 mButtonsPageRelativeSize; ///< Size of a buttons page relative to the stage size | |
| 401 | + | |
| 402 | + Dali::ActorContainer mPages; ///< List of pages. | |
| 403 | + Dali::ActorContainer mTableViewImages; ///< Offscreen render of tableview | |
| 404 | + Dali::ActorContainer mBackgroundActors; ///< List of background actors used in the effect | |
| 405 | + AnimationList mBackgroundAnimations; ///< List of background bubble animations | |
| 406 | + ExampleList mExampleList; ///< List of examples. | |
| 407 | + ExampleMap mExampleMap; ///< Map LUT for examples. | |
| 408 | + | |
| 409 | + std::string mBackgroundImagePath; ///< The path to the background image. | |
| 410 | + int mTotalPages; ///< Total pages within scrollview. | |
| 411 | + | |
| 412 | + bool mScrolling:1; ///< Flag indicating whether view is currently being scrolled | |
| 413 | + bool mSortAlphabetically:1; ///< Sort examples alphabetically. | |
| 414 | + bool mBackgroundAnimsPlaying:1; ///< Are background animations playing | |
| 415 | + bool mVersionPopupShown:1; ///< Whehter the version popup is shown or not | |
| 395 | 416 | }; |
| 396 | 417 | |
| 397 | 418 | #endif // __DALI_DEMO_H__ | ... | ... |
examples/atlas/atlas-example.cpp
0 โ 100644
| 1 | +/* | |
| 2 | + * Copyright (c) 2015 Samsung Electronics Co., Ltd. | |
| 3 | + * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | + * you may not use this file except in compliance with the License. | |
| 6 | + * You may obtain a copy of the License at | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | + * See the License for the specific language governing permissions and | |
| 14 | + * limitations under the License. | |
| 15 | + * | |
| 16 | + */ | |
| 17 | + | |
| 18 | +#include <dali/dali.h> | |
| 19 | +#include "shared/view.h" | |
| 20 | +#include <iostream> | |
| 21 | +#include <cstdio> | |
| 22 | + | |
| 23 | +using namespace Dali; | |
| 24 | + | |
| 25 | +class AtlasController; | |
| 26 | + | |
| 27 | +namespace | |
| 28 | +{ | |
| 29 | +const char * const BACKGROUND_IMAGE( DALI_IMAGE_DIR "background-gradient.jpg" ); | |
| 30 | +const char * const TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" ); | |
| 31 | +const char * const LOSE_CONTEXT_IMAGE( DALI_IMAGE_DIR "icon-cluster-wobble.png" ); | |
| 32 | + | |
| 33 | +Application gApplication; | |
| 34 | +AtlasController* gAtlasController(NULL); | |
| 35 | +} | |
| 36 | + | |
| 37 | +class AtlasController : public ConnectionTracker | |
| 38 | +{ | |
| 39 | +public: | |
| 40 | + | |
| 41 | + AtlasController( Application& application ) | |
| 42 | + : mApplication( application ) | |
| 43 | + { | |
| 44 | + // Connect to the Application's Init signal | |
| 45 | + mApplication.InitSignal().Connect( this, &AtlasController::Create ); | |
| 46 | + } | |
| 47 | + | |
| 48 | + ~AtlasController() | |
| 49 | + { | |
| 50 | + // Nothing to do here; | |
| 51 | + } | |
| 52 | + | |
| 53 | + void Create( Application& application ) | |
| 54 | + { | |
| 55 | + // Get a handle to the stage | |
| 56 | + Stage stage = Stage::GetCurrent(); | |
| 57 | + stage.SetBackgroundColor(Color::YELLOW); | |
| 58 | + | |
| 59 | + // Respond to a click anywhere on the stage | |
| 60 | + stage.KeyEventSignal().Connect(this, &AtlasController::OnKeyEvent); | |
| 61 | + | |
| 62 | + mApplication.GetWindow().ShowIndicator( Dali::Window::INVISIBLE ); | |
| 63 | + | |
| 64 | + mContentLayer = DemoHelper::CreateView( mApplication, | |
| 65 | + mView, | |
| 66 | + mToolBar, | |
| 67 | + BACKGROUND_IMAGE, | |
| 68 | + TOOLBAR_IMAGE, | |
| 69 | + "Atlas" ); | |
| 70 | + | |
| 71 | + mLoseContextButton = Toolkit::PushButton::New(); | |
| 72 | + mLoseContextButton.SetBackgroundImage( ResourceImage::New( LOSE_CONTEXT_IMAGE ) ); | |
| 73 | + mLoseContextButton.ClickedSignal().Connect( this, &AtlasController::OnLoseContextButtonClicked ); | |
| 74 | + mToolBar.AddControl( mLoseContextButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); | |
| 75 | + | |
| 76 | + mAtlas = Atlas::New( 400,300, Pixel::RGBA8888); | |
| 77 | + mAtlas.Clear(Vector4(0.f,0.5f,0.5f,0.5f)); | |
| 78 | + mAtlas.Upload( DALI_IMAGE_DIR "icon-change.png", 50, 30 ); | |
| 79 | + mAtlas.Upload( DALI_IMAGE_DIR "icon-cluster-carousel.png", 100, 30 ); | |
| 80 | + mAtlas.Upload( DALI_IMAGE_DIR "icon-effects-on.png", 150, 30 ); | |
| 81 | + mAtlas.Upload( DALI_IMAGE_DIR "icon-effect-cross.png", 100, 80 ); | |
| 82 | + mAtlas.Upload( DALI_IMAGE_DIR "icon-effect-fold.png", 150, 80 ); | |
| 83 | + mAtlas.Upload( DALI_IMAGE_DIR "icon-effect-wave.png", 200, 80 ); | |
| 84 | + mAtlas.Upload( DALI_IMAGE_DIR "icon-item-view-layout-depth.png", 150, 130 ); | |
| 85 | + mAtlas.Upload( DALI_IMAGE_DIR "icon-item-view-layout-grid.png", 200, 130 ); | |
| 86 | + mAtlas.Upload( DALI_IMAGE_DIR "icon-item-view-layout-spiral.png", 250, 130 ); | |
| 87 | + UploadBufferImages(); | |
| 88 | + | |
| 89 | + ImageActor imageActor1 = ImageActor::New( mAtlas ); | |
| 90 | + imageActor1.SetY(-170.f); | |
| 91 | + imageActor1.SetParentOrigin(ParentOrigin::CENTER); | |
| 92 | + mContentLayer.Add( imageActor1 ); | |
| 93 | + | |
| 94 | + Atlas atlas2 = Atlas::New( 400,400, Pixel::RGB888); | |
| 95 | + atlas2.Clear( Color::RED ); | |
| 96 | + atlas2.Upload( DALI_IMAGE_DIR "gallery-small-1.jpg", 4, 4 ); | |
| 97 | + atlas2.Clear( Color::BLUE ); | |
| 98 | + atlas2.Upload( DALI_IMAGE_DIR "gallery-small-2.jpg", 136, 4 ); | |
| 99 | + atlas2.Upload( DALI_IMAGE_DIR "gallery-small-3.jpg", 268, 4 ); | |
| 100 | + atlas2.Upload( DALI_IMAGE_DIR "gallery-small-4.jpg", 4, 136 ); | |
| 101 | + atlas2.Upload( DALI_IMAGE_DIR "gallery-small-5.jpg", 136, 136 ); | |
| 102 | + atlas2.Upload( DALI_IMAGE_DIR "gallery-small-6.jpg", 268, 135 ); | |
| 103 | + atlas2.Upload( DALI_IMAGE_DIR "gallery-small-7.jpg", 4, 268 ); | |
| 104 | + atlas2.Upload( DALI_IMAGE_DIR "gallery-small-7.jpg", 136, 268 ); | |
| 105 | + atlas2.Upload( DALI_IMAGE_DIR "gallery-small-7.jpg", 268, 268 ); | |
| 106 | + | |
| 107 | + | |
| 108 | + ImageActor imageActor2 = ImageActor::New( atlas2 ); | |
| 109 | + imageActor2.SetY(200.f); | |
| 110 | + imageActor2.SetZ(-1.f); | |
| 111 | + imageActor2.SetParentOrigin(ParentOrigin::CENTER); | |
| 112 | + mContentLayer.Add( imageActor2 ); | |
| 113 | + | |
| 114 | + mPanGestureDetector = PanGestureDetector::New(); | |
| 115 | + mPanGestureDetector.DetectedSignal().Connect(this, &AtlasController::OnPanGesture); | |
| 116 | + mPanGestureDetector.Attach(imageActor1); | |
| 117 | + mPanGestureDetector.Attach(imageActor2); | |
| 118 | + | |
| 119 | + stage.ContextLostSignal().Connect(this, &AtlasController::OnContextLost); | |
| 120 | + stage.ContextRegainedSignal().Connect(this, &AtlasController::OnContextRegained); | |
| 121 | + } | |
| 122 | + | |
| 123 | + void UploadBufferImages() | |
| 124 | + { | |
| 125 | + mAtlas.Upload( CreateBufferImage( Vector4(1.f, 1.f, 1.f, 0.5f ), 80, 90 ), 0, 210 ); | |
| 126 | + mAtlas.Upload( CreateBufferImage( Vector4(1.f, 1.f, 0.75f, 0.5f ), 80, 80 ), 40, 210 ); | |
| 127 | + mAtlas.Upload( CreateBufferImage( Vector4(1.f, 1.f, 0.5f, 0.5f ), 80, 70 ), 80, 210 ); | |
| 128 | + mAtlas.Upload( CreateBufferImage( Vector4(1.f, 1.f, 0.25f, 0.5f ), 80, 60 ), 120, 210 ); | |
| 129 | + mAtlas.Upload( CreateBufferImage( Vector4(1.f, 1.f, 0.f, 0.5f ), 80, 50 ), 160, 210 ); | |
| 130 | + mAtlas.Upload( CreateBufferImage( Vector4(0.75f, 0.75f, 0.f, 0.5f ), 80, 40 ), 200, 210 ); | |
| 131 | + mAtlas.Upload( CreateBufferImage( Vector4(0.5f, 0.5f, 0.f, 0.5f ), 80, 30 ), 240, 210 ); | |
| 132 | + mAtlas.Upload( CreateBufferImage( Vector4(0.25f, 0.25f, 0.f, 0.5f ), 80, 20 ), 280, 210 ); | |
| 133 | + mAtlas.Upload( CreateBufferImage( Vector4(0.1f, 0.1f, 0.f, 0.5f ), 80, 10 ), 320, 210 ); | |
| 134 | + BufferImage redBlock = CreateBufferImage( Color::RED, 40, 40 ); | |
| 135 | + mAtlas.Upload(redBlock, 320, 30); | |
| 136 | + mAtlas.Upload(redBlock, 320, 80); | |
| 137 | + mAtlas.Upload(redBlock, 320, 130); | |
| 138 | + } | |
| 139 | + | |
| 140 | + static void NewWindow(void) | |
| 141 | + { | |
| 142 | + PositionSize posSize(0, 0, 720, 1280); | |
| 143 | + gApplication.ReplaceWindow(posSize, "NewWindow"); // Generates a new window | |
| 144 | + } | |
| 145 | + | |
| 146 | + bool OnLoseContextButtonClicked( Toolkit::Button button ) | |
| 147 | + { | |
| 148 | + // Add as an idle callback to avoid ProcessEvents being recursively called. | |
| 149 | + mApplication.AddIdle(MakeCallback( AtlasController::NewWindow )); | |
| 150 | + return true; | |
| 151 | + } | |
| 152 | + | |
| 153 | + void OnKeyEvent( const KeyEvent& event ) | |
| 154 | + { | |
| 155 | + if(event.state == KeyEvent::Down) | |
| 156 | + { | |
| 157 | + if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) | |
| 158 | + { | |
| 159 | + mApplication.Quit(); | |
| 160 | + } | |
| 161 | + } | |
| 162 | + } | |
| 163 | + | |
| 164 | + void OnPanGesture( Actor actor, const PanGesture& gesture ) | |
| 165 | + { | |
| 166 | + if( gesture.state == Gesture::Continuing ) | |
| 167 | + { | |
| 168 | + actor.MoveBy( Vector3( gesture.displacement ) ); | |
| 169 | + } | |
| 170 | + } | |
| 171 | + | |
| 172 | + void OnContextLost() | |
| 173 | + { | |
| 174 | + printf("Stage reporting context loss\n"); | |
| 175 | + } | |
| 176 | + | |
| 177 | + void OnContextRegained() | |
| 178 | + { | |
| 179 | + printf("Stage reporting context regain\n"); | |
| 180 | + UploadBufferImages(); | |
| 181 | + } | |
| 182 | + | |
| 183 | +private: | |
| 184 | + | |
| 185 | + BufferImage CreateBufferImage( const Vector4& color, const unsigned int width, const unsigned int height ) | |
| 186 | + { | |
| 187 | + BufferImage imageData = BufferImage::New( width, height, Pixel::RGBA8888 ); | |
| 188 | + | |
| 189 | + // Create the image | |
| 190 | + PixelBuffer* pixbuf = imageData.GetBuffer(); | |
| 191 | + const unsigned int bitmapSize = width * height; | |
| 192 | + for( size_t i = 0; i < bitmapSize; ++i ) | |
| 193 | + { | |
| 194 | + pixbuf[i*4+0] = 0xFF * color.r; | |
| 195 | + pixbuf[i*4+1] = 0xFF * color.g; | |
| 196 | + pixbuf[i*4+2] = 0xFF * color.b; | |
| 197 | + pixbuf[i*4+3] = 0xFF * color.a; | |
| 198 | + } | |
| 199 | + | |
| 200 | + imageData.Update(); | |
| 201 | + | |
| 202 | + return imageData; | |
| 203 | + } | |
| 204 | + | |
| 205 | + | |
| 206 | +private: | |
| 207 | + Application& mApplication; | |
| 208 | + PanGestureDetector mPanGestureDetector; | |
| 209 | + | |
| 210 | + Toolkit::View mView; ///< The View instance. | |
| 211 | + Toolkit::ToolBar mToolBar; ///< The View's Toolbar. | |
| 212 | + Layer mContentLayer; ///< Content layer (scrolling cluster content) | |
| 213 | + Toolkit::PushButton mLoseContextButton; | |
| 214 | + Atlas mAtlas; | |
| 215 | +}; | |
| 216 | + | |
| 217 | +void RunTest( Application& application ) | |
| 218 | +{ | |
| 219 | + gAtlasController = new AtlasController(application); | |
| 220 | + application.MainLoop(Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS); | |
| 221 | +} | |
| 222 | + | |
| 223 | +// Entry point for Linux & SLP applications | |
| 224 | +// | |
| 225 | +int main( int argc, char **argv ) | |
| 226 | +{ | |
| 227 | + gApplication = Application::New( &argc, &argv ); | |
| 228 | + | |
| 229 | + RunTest( gApplication ); | |
| 230 | + | |
| 231 | + return 0; | |
| 232 | +} | ... | ... |
examples/item-view/item-view-example.cpp
| ... | ... | @@ -99,6 +99,10 @@ const char* IMAGE_PATHS[] = { |
| 99 | 99 | |
| 100 | 100 | const unsigned int NUM_IMAGES = sizeof(IMAGE_PATHS) / sizeof(char*); |
| 101 | 101 | |
| 102 | +const unsigned int IMAGE_WIDTH = 256; | |
| 103 | +const unsigned int IMAGE_HEIGHT = 256; | |
| 104 | +const unsigned int NUM_IMAGE_PER_ROW_IN_ATLAS = 8; | |
| 105 | + | |
| 102 | 106 | AlphaFunction ALPHA_FUNCTIONS[] = { AlphaFunctions::Linear, |
| 103 | 107 | AlphaFunctions::EaseIn, |
| 104 | 108 | AlphaFunctions::EaseOut }; |
| ... | ... | @@ -310,6 +314,7 @@ public: |
| 310 | 314 | stage.Add( mReplaceButton ); |
| 311 | 315 | |
| 312 | 316 | // Create the item view actor |
| 317 | + mImageAtlas = CreateImageAtlas(); | |
| 313 | 318 | mItemView = ItemView::New(*this); |
| 314 | 319 | mItemView.SetParentOrigin(ParentOrigin::CENTER); |
| 315 | 320 | mItemView.SetAnchorPoint(AnchorPoint::CENTER); |
| ... | ... | @@ -874,8 +879,12 @@ public: // From ItemFactory |
| 874 | 879 | virtual Actor NewItem(unsigned int itemId) |
| 875 | 880 | { |
| 876 | 881 | // Create an image actor for this item |
| 877 | - Image image = ResourceImage::New( IMAGE_PATHS[itemId % NUM_IMAGES] ); | |
| 878 | - Actor actor = ImageActor::New(image); | |
| 882 | + unsigned int imageId = itemId % NUM_IMAGES; | |
| 883 | + ImageActor::PixelArea pixelArea( (imageId%NUM_IMAGE_PER_ROW_IN_ATLAS)*IMAGE_WIDTH, | |
| 884 | + (imageId/NUM_IMAGE_PER_ROW_IN_ATLAS)*IMAGE_HEIGHT, | |
| 885 | + IMAGE_WIDTH, | |
| 886 | + IMAGE_HEIGHT ); | |
| 887 | + Actor actor = ImageActor::New(mImageAtlas, pixelArea); | |
| 879 | 888 | actor.SetPosition( INITIAL_OFFSCREEN_POSITION ); |
| 880 | 889 | |
| 881 | 890 | // Add a border image child actor |
| ... | ... | @@ -934,6 +943,23 @@ public: // From ItemFactory |
| 934 | 943 | private: |
| 935 | 944 | |
| 936 | 945 | /** |
| 946 | + * Create an Atlas to tile the images inside. | |
| 947 | + */ | |
| 948 | + Atlas CreateImageAtlas() | |
| 949 | + { | |
| 950 | + const unsigned int atlas_width = IMAGE_WIDTH*NUM_IMAGE_PER_ROW_IN_ATLAS; | |
| 951 | + const unsigned int atlas_height = IMAGE_HEIGHT*ceil( static_cast<float>(NUM_IMAGES)/ static_cast<float>(NUM_IMAGE_PER_ROW_IN_ATLAS)); | |
| 952 | + Atlas atlas = Atlas::New(atlas_width, atlas_height, Pixel::RGB888); | |
| 953 | + | |
| 954 | + for( unsigned int i = 0; i < NUM_IMAGES; i++ ) | |
| 955 | + { | |
| 956 | + atlas.Upload( IMAGE_PATHS[i], (i%NUM_IMAGE_PER_ROW_IN_ATLAS)*IMAGE_WIDTH, (i/NUM_IMAGE_PER_ROW_IN_ATLAS)*IMAGE_HEIGHT ); | |
| 957 | + } | |
| 958 | + | |
| 959 | + return atlas; | |
| 960 | + } | |
| 961 | + | |
| 962 | + /** | |
| 937 | 963 | * Sets/Updates the title of the View |
| 938 | 964 | * @param[in] title The new title for the view. |
| 939 | 965 | */ |
| ... | ... | @@ -1050,6 +1076,7 @@ private: |
| 1050 | 1076 | |
| 1051 | 1077 | ItemView mItemView; |
| 1052 | 1078 | Image mBorderImage; |
| 1079 | + Atlas mImageAtlas; | |
| 1053 | 1080 | unsigned int mCurrentLayout; |
| 1054 | 1081 | float mDurationSeconds; |
| 1055 | 1082 | ... | ... |