2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <dali/dali.h>
19 #include "shared/view.h"
25 class AtlasController;
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" );
33 Application gApplication;
34 AtlasController* gAtlasController(NULL);
37 class AtlasController : public ConnectionTracker
41 AtlasController( Application& application )
42 : mApplication( application )
44 // Connect to the Application's Init signal
45 mApplication.InitSignal().Connect( this, &AtlasController::Create );
50 // Nothing to do here;
53 void Create( Application& application )
55 // Get a handle to the stage
56 Stage stage = Stage::GetCurrent();
57 stage.SetBackgroundColor(Color::YELLOW);
59 // Respond to a click anywhere on the stage
60 stage.KeyEventSignal().Connect(this, &AtlasController::OnKeyEvent);
62 mApplication.GetWindow().ShowIndicator( Dali::Window::INVISIBLE );
64 mContentLayer = DemoHelper::CreateView( mApplication,
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 );
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 );
89 ImageActor imageActor1 = ImageActor::New( mAtlas );
90 imageActor1.SetY(-170.f);
91 imageActor1.SetParentOrigin(ParentOrigin::CENTER);
92 mContentLayer.Add( imageActor1 );
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 );
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 );
114 mPanGestureDetector = PanGestureDetector::New();
115 mPanGestureDetector.DetectedSignal().Connect(this, &AtlasController::OnPanGesture);
116 mPanGestureDetector.Attach(imageActor1);
117 mPanGestureDetector.Attach(imageActor2);
119 stage.ContextLostSignal().Connect(this, &AtlasController::OnContextLost);
120 stage.ContextRegainedSignal().Connect(this, &AtlasController::OnContextRegained);
123 void UploadBufferImages()
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);
140 static void NewWindow(void)
142 PositionSize posSize(0, 0, 720, 1280);
143 gApplication.ReplaceWindow(posSize, "NewWindow"); // Generates a new window
146 bool OnLoseContextButtonClicked( Toolkit::Button button )
148 // Add as an idle callback to avoid ProcessEvents being recursively called.
149 mApplication.AddIdle(MakeCallback( AtlasController::NewWindow ));
153 void OnKeyEvent( const KeyEvent& event )
155 if(event.state == KeyEvent::Down)
157 if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
164 void OnPanGesture( Actor actor, const PanGesture& gesture )
166 if( gesture.state == Gesture::Continuing )
168 actor.TranslateBy( Vector3( gesture.displacement ) );
174 printf("Stage reporting context loss\n");
177 void OnContextRegained()
179 printf("Stage reporting context regain\n");
180 UploadBufferImages();
185 BufferImage CreateBufferImage( const Vector4& color, const unsigned int width, const unsigned int height )
187 BufferImage imageData = BufferImage::New( width, height, Pixel::RGBA8888 );
190 PixelBuffer* pixbuf = imageData.GetBuffer();
191 const unsigned int bitmapSize = width * height;
192 for( size_t i = 0; i < bitmapSize; ++i )
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;
207 Application& mApplication;
208 PanGestureDetector mPanGestureDetector;
210 Toolkit::View mView; ///< The View instance.
211 Toolkit::ToolBar mToolBar; ///< The View's Toolbar.
212 Toolkit::TextView mTitleActor; ///< The Toolbar's Title.
213 Layer mContentLayer; ///< Content layer (scrolling cluster content)
214 Toolkit::PushButton mLoseContextButton;
218 void RunTest( Application& application )
220 gAtlasController = new AtlasController(application);
221 application.MainLoop(Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS);
224 // Entry point for Linux & Tizen applications
226 int main( int argc, char **argv )
228 gApplication = Application::New( &argc, &argv );
230 RunTest( gApplication );