2 * Copyright (c) 2014 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 <dali-toolkit/dali-toolkit.h>
20 #include <dali-toolkit/devel-api/controls/popup/popup.h>
21 #include "shared/view.h"
25 using Toolkit::TextLabel;
30 const char* BACKGROUND_IMAGE( DALI_IMAGE_DIR "background-gradient.jpg" );
31 const Vector4 BACKGROUND_COLOUR( 1.0f, 1.0f, 1.0f, 0.15f );
33 const int MARGIN_SIZE = 10;
35 const char* const NEXT_BUTTON_ID = "NEXT_BUTTON";
36 const char* const PREVIOUS_BUTTON_ID = "PREVIOUS_BUTTON";
37 const char * const DALI_ICON_PLAY = DALI_IMAGE_DIR "icon-play.png";
39 const char* const FITTING_BUTTON_ID = "FITTING_BUTTON";
40 const char* const SAMPLING_BUTTON_ID = "SAMPLING_BUTTON";
41 const char* const FITTING_BUTTON_TEXT = "Fitting";
42 const char* const SAMPLING_BUTTON_TEXT = "Sampling";
44 const char* const STYLE_LABEL_TEXT = "grouplabel";
45 const char* const STYLE_BUTTON_TEXT = "buttonlabel";
49 const char* IMAGE_PATHS[] =
51 // Worst case for aliasing in downscaling, 2k x 2k 1 bit per pixel dithered
52 // black and white image:
53 DALI_IMAGE_DIR "gallery-large-14.wbmp",
54 // Variety of sizes, shapes and formats:
55 DALI_IMAGE_DIR "animation-list.png",
56 DALI_IMAGE_DIR "layer1.png",
57 DALI_IMAGE_DIR "layer2.png",
58 DALI_IMAGE_DIR "music-libray-main-screen.png",
59 DALI_IMAGE_DIR "music-libray-record-cover.png",
60 DALI_IMAGE_DIR "contacts-background.png",
61 DALI_IMAGE_DIR "portrait_screen_primitive_shapes.gif",
62 DALI_IMAGE_DIR "landscape_screen_primitive_shapes.gif",
63 DALI_IMAGE_DIR "square_primitive_shapes.bmp",
64 DALI_IMAGE_DIR "dali-logo.png",
65 DALI_IMAGE_DIR "com.samsung.dali-demo.ico",
66 DALI_IMAGE_DIR "gallery-large-14.jpg",
67 DALI_IMAGE_DIR "book-landscape-cover.jpg",
68 DALI_IMAGE_DIR "book-portrait-p1.jpg",
69 DALI_IMAGE_DIR "book-landscape-cover-back.jpg",
70 DALI_IMAGE_DIR "background-1.jpg",
71 DALI_IMAGE_DIR "background-blocks.jpg",
72 DALI_IMAGE_DIR "background-magnifier.jpg",
73 DALI_IMAGE_DIR "gallery-large-14.jpg",
76 const int NUM_IMAGE_PATHS = sizeof(IMAGE_PATHS) / sizeof(IMAGE_PATHS[0]) - 1u;
78 /** Cycle the scaling mode options. */
79 FittingMode::Type NextScalingMode( FittingMode::Type oldMode )
81 FittingMode::Type newMode = FittingMode::SHRINK_TO_FIT;
84 case FittingMode::SHRINK_TO_FIT:
85 newMode = FittingMode::SCALE_TO_FILL;
87 case FittingMode::SCALE_TO_FILL:
88 newMode = FittingMode::FIT_WIDTH;
90 case FittingMode::FIT_WIDTH:
91 newMode = FittingMode::FIT_HEIGHT;
93 case FittingMode::FIT_HEIGHT:
94 newMode = FittingMode::SHRINK_TO_FIT;
100 /** Cycle through filter mode options. */
101 SamplingMode::Type NextFilterMode( SamplingMode::Type oldMode )
103 SamplingMode::Type newMode = SamplingMode::BOX;
107 case SamplingMode::BOX:
108 newMode = SamplingMode::NEAREST;
110 case SamplingMode::NEAREST:
111 newMode = SamplingMode::LINEAR;
113 case SamplingMode::LINEAR:
114 newMode = SamplingMode::BOX_THEN_NEAREST;
116 case SamplingMode::BOX_THEN_NEAREST:
117 newMode = SamplingMode::BOX_THEN_LINEAR;
119 case SamplingMode::BOX_THEN_LINEAR:
120 newMode = SamplingMode::NO_FILTER;
122 case SamplingMode::NO_FILTER:
123 newMode = SamplingMode::BOX;
125 case SamplingMode::DONT_CARE:
126 newMode = SamplingMode::BOX;
132 const char* StringFromScalingMode( FittingMode::Type scalingMode )
134 return scalingMode == FittingMode::SCALE_TO_FILL ? "SCALE_TO_FILL" : scalingMode == FittingMode::SHRINK_TO_FIT ? "SHRINK_TO_FIT" : scalingMode == FittingMode::FIT_WIDTH ? "FIT_WIDTH" : scalingMode == FittingMode::FIT_HEIGHT ? "FIT_HEIGHT" : "UnknownScalingMode";
137 const char* StringFromFilterMode( SamplingMode::Type filterMode )
139 return filterMode == SamplingMode::BOX ? "BOX" : filterMode == SamplingMode::BOX_THEN_NEAREST ? "BOX_THEN_NEAREST" : filterMode == SamplingMode::BOX_THEN_LINEAR ? "BOX_THEN_LINEAR" : filterMode == SamplingMode::NEAREST ? "NEAREST" : filterMode == SamplingMode::LINEAR ? "LINEAR" : filterMode == SamplingMode::NO_FILTER ? "NO_FILTER" : filterMode == SamplingMode::DONT_CARE ? "DONT_CARE" : "UnknownFilterMode";
144 // This example shows the load-time image scaling and filtering features.
146 class ImageScalingAndFilteringController : public ConnectionTracker
150 ImageScalingAndFilteringController( Application& application )
151 : mApplication( application ),
152 mImageStageScale( 0.5f, 0.5f ),
154 mFittingMode( FittingMode::SCALE_TO_FILL ),
155 mSamplingMode( SamplingMode::BOX_THEN_LINEAR)
157 // Connect to the Application's Init signal
158 mApplication.InitSignal().Connect( this, &ImageScalingAndFilteringController::Create );
161 ~ImageScalingAndFilteringController()
163 // Nothing to do here;
166 // The Init signal is received once (only) during the Application lifetime
167 void Create( Application& application )
169 // Get a handle to the stage
170 Stage stage = Stage::GetCurrent();
173 Dali::Property::Map backgroundImage;
174 backgroundImage.Insert( "renderer-type", "image-renderer" );
175 backgroundImage.Insert( "image-url", BACKGROUND_IMAGE );
176 backgroundImage.Insert( "image-desired-width", stage.GetSize().width );
177 backgroundImage.Insert( "image-desired-height", stage.GetSize().height );
178 backgroundImage.Insert( "image-fitting-mode", "scale-to-fill" );
179 backgroundImage.Insert( "image-sampling-mode", "box-then-nearest" );
181 Toolkit::ImageView background = Toolkit::ImageView::New();
182 background.SetProperty( Toolkit::ImageView::Property::IMAGE, backgroundImage );
183 background.SetAnchorPoint( AnchorPoint::TOP_LEFT );
184 background.SetSize( stage.GetSize() );
185 stage.Add( background );
187 // Make grey pixels for the desired box, the desired height the desired width:
188 BufferImage desiredBackground = BufferImage::WHITE();
190 BufferImage heightBackground = BufferImage::WHITE();
191 PixelBuffer* const heightPixel = heightBackground.GetBuffer();
192 heightPixel[0] = 0x8f;
193 heightPixel[1] = 0x8f;
194 heightPixel[2] = 0x8f;
196 BufferImage widthBackground = BufferImage::WHITE();
197 PixelBuffer* const widthPixel = widthBackground.GetBuffer();
198 widthPixel[0] = 0x4f;
199 widthPixel[1] = 0x4f;
200 widthPixel[2] = 0x4f;
202 mHeightBox = Toolkit::ImageView::New( heightBackground );
203 mHeightBox.SetOpacity( 0.2f );
204 background.Add( mHeightBox );
206 mWidthBox = Toolkit::ImageView::New( widthBackground );
207 mWidthBox.SetOpacity( 0.2f );
208 background.Add( mWidthBox );
210 mDesiredBox = Toolkit::ImageView::New( desiredBackground );
211 background.Add( mDesiredBox );
213 mDesiredBox.SetSize( stage.GetSize() * mImageStageScale );
214 mDesiredBox.SetParentOrigin( ParentOrigin::CENTER );
215 mDesiredBox.SetAnchorPoint( AnchorPoint::CENTER );
217 mHeightBox.SetSize( stage.GetSize().width, (stage.GetSize() * mImageStageScale).height );
218 mHeightBox.SetParentOrigin( ParentOrigin::CENTER );
219 mHeightBox.SetAnchorPoint( AnchorPoint::CENTER );
221 mWidthBox.SetSize( (stage.GetSize() * mImageStageScale).width, stage.GetSize().height );
222 mWidthBox.SetParentOrigin( ParentOrigin::CENTER );
223 mWidthBox.SetAnchorPoint( AnchorPoint::CENTER );
225 // Initialize the actor
226 mImageView = Toolkit::ImageView::New( IMAGE_PATHS[ 0 ] );
228 // Reposition the actor
229 mImageView.SetParentOrigin( ParentOrigin::CENTER );
230 mImageView.SetAnchorPoint( AnchorPoint::CENTER );
232 // Display the actor on the stage
233 mDesiredBox.Add( mImageView );
235 mImageView.SetSize( stage.GetSize() * mImageStageScale );
237 // Setup the pinch detector for scaling the desired image load dimensions:
238 mPinchDetector = PinchGestureDetector::New();
239 mPinchDetector.Attach( mImageView );
240 mPinchDetector.DetectedSignal().Connect( this, &ImageScalingAndFilteringController::OnPinch );
242 // Make a grab-handle for resizing the image:
243 mGrabCorner = Toolkit::PushButton::New();
244 mGrabCorner.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::WIDTH );
245 mGrabCorner.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
246 mGrabCorner.SetName( "GrabCorner" );
247 mGrabCorner.SetAnchorPoint( AnchorPoint::BOTTOM_RIGHT );
248 mGrabCorner.SetParentOrigin( ParentOrigin::BOTTOM_RIGHT );
249 mGrabCorner.SetSize( Vector2( stage.GetSize().width*0.08f, stage.GetSize().width*0.08f ) );
250 mGrabCorner.SetOpacity( 0.6f );
252 Layer grabCornerLayer = Layer::New();
253 grabCornerLayer.SetAnchorPoint( AnchorPoint::BOTTOM_RIGHT );
254 grabCornerLayer.SetParentOrigin( ParentOrigin::BOTTOM_RIGHT );
256 grabCornerLayer.Add( mGrabCorner );
257 mImageView.Add( grabCornerLayer );
258 mPanGestureDetector = PanGestureDetector::New();
259 mPanGestureDetector.Attach( mGrabCorner );
260 mPanGestureDetector.DetectedSignal().Connect( this, &ImageScalingAndFilteringController::OnPan );
263 // Tie-in input event handlers:
264 stage.KeyEventSignal().Connect( this, &ImageScalingAndFilteringController::OnKeyEvent );
272 * Create the GUI controls which float above the scene
274 void CreateControls()
276 Stage stage = Stage::GetCurrent();
278 Dali::Layer controlsLayer = Dali::Layer::New();
279 controlsLayer.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
280 controlsLayer.SetSizeModeFactor( Vector3( 1.0f, 1.0f, 1.0f ) );
281 controlsLayer.SetAnchorPoint( AnchorPoint::TOP_LEFT);
282 controlsLayer.SetParentOrigin( ParentOrigin::TOP_LEFT);
283 stage.Add( controlsLayer );
285 // Back and next image buttons in corners of stage:
286 unsigned int playWidth = std::min( stage.GetSize().x * (1 / 5.0f), 58.0f );
287 Image playImage = ResourceImage::New( DALI_ICON_PLAY, ImageDimensions( playWidth, playWidth ), FittingMode::SHRINK_TO_FIT, SamplingMode::BOX_THEN_LINEAR );
288 Toolkit::ImageView imagePrevious = Toolkit::ImageView::New( playImage );
290 // Last image button:
291 imagePrevious.SetAnchorPoint( AnchorPoint::TOP_LEFT );
292 imagePrevious.RotateBy( Radian(3.14159265358979323846f), Vector3( 0, 1.0f, 0 ) );
293 imagePrevious.SetY( playWidth * 0.5f );
294 imagePrevious.SetX( playWidth + playWidth * 0.5f );
295 imagePrevious.SetOpacity( 0.6f );
296 controlsLayer.Add( imagePrevious );
297 imagePrevious.SetName( PREVIOUS_BUTTON_ID );
298 imagePrevious.TouchedSignal().Connect( this, &ImageScalingAndFilteringController::OnControlTouched );
300 // Next image button:
301 Toolkit::ImageView imageNext = Toolkit::ImageView::New( playImage );
302 imageNext.SetAnchorPoint( AnchorPoint::TOP_RIGHT );
303 imageNext.SetY( playWidth * 0.5f );
304 imageNext.SetX( stage.GetSize().x - playWidth * 0.5f );
305 imageNext.SetOpacity( 0.6f );
306 controlsLayer.Add( imageNext );
307 imageNext.SetName( NEXT_BUTTON_ID );
308 imageNext.TouchedSignal().Connect( this, &ImageScalingAndFilteringController::OnControlTouched );
310 // Buttons to popup selectors for fitting and sampling modes:
312 // Wrapper table to hold two buttons side by side:
313 Toolkit::TableView modesGroupBackground = Toolkit::TableView::New( 1, 2 );
314 modesGroupBackground.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
315 modesGroupBackground.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
316 modesGroupBackground.SetBackgroundColor( BACKGROUND_COLOUR );
317 modesGroupBackground.SetCellPadding( Size( MARGIN_SIZE * 0.5f, MARGIN_SIZE ) );
318 modesGroupBackground.SetFitHeight( 0 );
320 modesGroupBackground.SetAnchorPoint( AnchorPoint::BOTTOM_LEFT );
321 modesGroupBackground.SetParentOrigin( ParentOrigin::BOTTOM_LEFT );
322 modesGroupBackground.SetPosition( 0.0f, 0.0f );
324 controlsLayer.Add( modesGroupBackground );
327 // Vertical table to hold label and button:
328 Toolkit::TableView fittingModeGroup = Toolkit::TableView::New( 2, 1 );
329 fittingModeGroup.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
330 fittingModeGroup.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
331 fittingModeGroup.SetBackgroundColor( BACKGROUND_COLOUR );
332 fittingModeGroup.SetCellPadding( Size( MARGIN_SIZE * 0.5f, MARGIN_SIZE * 0.5f ) );
333 fittingModeGroup.SetFitHeight( 0 );
334 fittingModeGroup.SetFitHeight( 1 );
336 TextLabel label = TextLabel::New( "Image fitting mode:" );
337 label.SetProperty( Toolkit::Control::Property::STYLE_NAME, STYLE_LABEL_TEXT );
338 fittingModeGroup.Add( label );
340 Toolkit::PushButton button = CreateButton( FITTING_BUTTON_ID, StringFromScalingMode( mFittingMode ) );
341 fittingModeGroup.Add( button );
342 mFittingModeButton = button;
344 modesGroupBackground.Add( fittingModeGroup );
348 // Vertical table to hold label and button:
349 Toolkit::TableView samplingModeGroup = Toolkit::TableView::New( 2, 1 );
350 samplingModeGroup.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
351 samplingModeGroup.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
352 samplingModeGroup.SetBackgroundColor( BACKGROUND_COLOUR );
353 samplingModeGroup.SetCellPadding( Size( MARGIN_SIZE * 0.5f, MARGIN_SIZE * 0.5f ) );
354 samplingModeGroup.SetFitHeight( 0 );
355 samplingModeGroup.SetFitHeight( 1 );
357 TextLabel label = TextLabel::New( "Image sampling mode:" );
358 label.SetProperty( Toolkit::Control::Property::STYLE_NAME, STYLE_LABEL_TEXT );
359 samplingModeGroup.Add( label );
361 Toolkit::PushButton button = CreateButton( SAMPLING_BUTTON_ID, StringFromFilterMode( mSamplingMode ) );
362 samplingModeGroup.Add( button );
363 mSamplingModeButton = button;
365 modesGroupBackground.Add( samplingModeGroup );
369 Toolkit::PushButton CreateButton( const char * id, const char * label )
371 Toolkit::PushButton button = Toolkit::PushButton::New();
372 button.SetProperty( Toolkit::Control::Property::STYLE_NAME, STYLE_BUTTON_TEXT );
373 button.SetName( id );
374 button.SetLabelText( label );
375 button.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
376 button.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
377 button.ClickedSignal().Connect( this, &ImageScalingAndFilteringController::OnButtonClicked );
381 Toolkit::Popup CreatePopup()
383 Stage stage = Stage::GetCurrent();
384 const float POPUP_WIDTH_DP = stage.GetSize().width * 0.75f;
386 Toolkit::Popup popup = Toolkit::Popup::New();
387 popup.SetName( "POPUP" );
388 popup.SetParentOrigin( ParentOrigin::CENTER );
389 popup.SetAnchorPoint( AnchorPoint::CENTER );
390 popup.SetSize( POPUP_WIDTH_DP, 0.0f );
392 popup.OutsideTouchedSignal().Connect( this, &ImageScalingAndFilteringController::OnPopupOutsideTouched );
397 //void CreatePopupButton( Toolkit::Popup popup, const char* id )
398 Toolkit::PushButton CreatePopupButton( Actor parent, const char* id )
400 Toolkit::PushButton button = Toolkit::PushButton::New();
401 button.SetName( id );
402 button.SetLabelText( id );
404 button.SetAnchorPoint( AnchorPoint::TOP_LEFT );
405 button.SetParentOrigin( ParentOrigin::BOTTOM_LEFT );
406 button.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
407 button.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
409 button.ClickedSignal().Connect( this, &ImageScalingAndFilteringController::OnButtonClicked );
411 parent.Add( button );
415 bool OnButtonClicked( Toolkit::Button button )
417 if( button.GetName() == FITTING_BUTTON_ID )
419 mPopup = CreatePopup();
421 // Four-row table to hold buttons:
422 Toolkit::TableView fittingModes = Toolkit::TableView::New( 4, 1 );
423 fittingModes.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
424 fittingModes.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
425 fittingModes.SetCellPadding( Size( MARGIN_SIZE, MARGIN_SIZE * 0.5 ) );
426 fittingModes.SetFitHeight( 0 );
427 fittingModes.SetFitHeight( 1 );
428 fittingModes.SetFitHeight( 2 );
429 fittingModes.SetFitHeight( 3 );
431 CreatePopupButton( fittingModes, StringFromScalingMode( FittingMode::SCALE_TO_FILL ) );
432 CreatePopupButton( fittingModes, StringFromScalingMode( FittingMode::SHRINK_TO_FIT ) );
433 CreatePopupButton( fittingModes, StringFromScalingMode( FittingMode::FIT_WIDTH ) );
434 CreatePopupButton( fittingModes, StringFromScalingMode( FittingMode::FIT_HEIGHT ) );
436 mPopup.SetContent( fittingModes );
437 Stage::GetCurrent().Add( mPopup );
438 mPopup.SetDisplayState( Toolkit::Popup::SHOWN );
440 else if( button.GetName() == SAMPLING_BUTTON_ID )
442 mPopup = CreatePopup();
444 // Table to hold buttons for each sampling mode:
445 Toolkit::TableView samplingModes = Toolkit::TableView::New( 6, 1 );
446 samplingModes.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
447 samplingModes.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
448 samplingModes.SetCellPadding( Size( MARGIN_SIZE, MARGIN_SIZE * 0.5 ) );
449 samplingModes.SetFitHeight( 0 );
450 samplingModes.SetFitHeight( 1 );
451 samplingModes.SetFitHeight( 2 );
452 samplingModes.SetFitHeight( 3 );
453 samplingModes.SetFitHeight( 4 );
454 samplingModes.SetFitHeight( 5 );
456 CreatePopupButton( samplingModes, StringFromFilterMode( SamplingMode::NEAREST ) );
457 CreatePopupButton( samplingModes, StringFromFilterMode( SamplingMode::LINEAR ) );
458 CreatePopupButton( samplingModes, StringFromFilterMode( SamplingMode::BOX ) );
459 CreatePopupButton( samplingModes, StringFromFilterMode( SamplingMode::BOX_THEN_NEAREST ) );
460 CreatePopupButton( samplingModes, StringFromFilterMode( SamplingMode::BOX_THEN_LINEAR ) );
461 CreatePopupButton( samplingModes, StringFromFilterMode( SamplingMode::NO_FILTER ) );
463 mPopup.SetContent( samplingModes );
464 Stage::GetCurrent().Add( mPopup );
465 mPopup.SetDisplayState( Toolkit::Popup::SHOWN );
467 else if( CheckFittingModeButton( button, FittingMode::SCALE_TO_FILL) ||
468 CheckFittingModeButton( button, FittingMode::SHRINK_TO_FIT) ||
469 CheckFittingModeButton( button, FittingMode::FIT_WIDTH) ||
470 CheckFittingModeButton( button, FittingMode::FIT_HEIGHT) )
473 else if( CheckSamplingModeButton( button, SamplingMode::NEAREST ) ||
474 CheckSamplingModeButton( button, SamplingMode::LINEAR ) ||
475 CheckSamplingModeButton( button, SamplingMode::BOX ) ||
476 CheckSamplingModeButton( button, SamplingMode::LINEAR ) ||
477 CheckSamplingModeButton( button, SamplingMode::BOX_THEN_NEAREST ) ||
478 CheckSamplingModeButton( button, SamplingMode::BOX_THEN_LINEAR ) ||
479 CheckSamplingModeButton( button, SamplingMode::NO_FILTER ) )
485 bool CheckFittingModeButton( Actor &button, FittingMode::Type mode )
487 const char * const modeName = StringFromScalingMode( mode );
488 if( button.GetName() == modeName )
491 mFittingModeButton.SetLabelText( modeName );
493 mPopup.SetDisplayState( Toolkit::Popup::HIDDEN );
500 bool CheckSamplingModeButton( Actor &button, SamplingMode::Type mode )
502 const char * const modeName = StringFromFilterMode( mode );
503 if( button.GetName() == modeName )
505 mSamplingMode = mode;
506 mSamplingModeButton.SetLabelText( modeName );
508 mPopup.SetDisplayState( Toolkit::Popup::HIDDEN );
515 void OnPopupOutsideTouched()
519 mPopup.SetDisplayState( Toolkit::Popup::HIDDEN );
524 void OnImageLoaded( ResourceImage image )
526 DALI_ASSERT_DEBUG( image == mNextImage );
527 mImageView.SetImage( image );
528 mImageView.SetSize( Size( image.GetWidth(), image.GetHeight() ) );
531 bool OnControlTouched( Actor actor, const TouchEvent& event )
533 if(event.GetPointCount() > 0)
535 const TouchPoint& point = event.GetPoint(0);
540 const std::string & name = actor.GetName();
541 if( name == NEXT_BUTTON_ID )
543 mCurrentPath = mCurrentPath + 1;
544 mCurrentPath = mCurrentPath < NUM_IMAGE_PATHS ? mCurrentPath : 0;
547 else if( name == PREVIOUS_BUTTON_ID )
549 mCurrentPath = mCurrentPath - 1;
550 mCurrentPath = mCurrentPath >= 0 ? mCurrentPath : NUM_IMAGE_PATHS - 1;
565 void OnPinch( Actor actor, const PinchGesture& pinch )
567 if( pinch.state == Gesture::Started )
569 mLastPinchScale = pinch.scale;
571 const float scale = pinch.scale;
573 if( scale != mLastPinchScale )
575 if ( scale < mLastPinchScale )
577 mImageStageScale.x = std::max( 0.05f, mImageStageScale.x * 0.9f );
578 mImageStageScale.y = std::max( 0.05f, mImageStageScale.y * 0.9f );
582 mImageStageScale.x = std::max( 0.05f, std::min( 1.0f, mImageStageScale.x * 1.1f ) );
583 mImageStageScale.y = std::max( 0.05f, std::min( 1.0f, mImageStageScale.y * 1.1f ) );
587 mLastPinchScale = scale;
590 void OnPan( Actor actor, const PanGesture& gesture )
592 Stage stage = Stage::GetCurrent();
593 mImageStageScale.x = std::max( 0.05f, std::min( 1.0f, mImageStageScale.x + (gesture.displacement.x * 2.0f / stage.GetSize().width ) ) );
594 mImageStageScale.y = std::max( 0.05f, std::min( 1.0f, mImageStageScale.y + (gesture.displacement.y * 2.0f / stage.GetSize().height ) ) );
598 void OnKeyEvent(const KeyEvent& event)
600 if( event.state == KeyEvent::Down )
602 if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) )
604 if( mPopup && mPopup.IsVisible() )
606 mPopup.SetDisplayState( Toolkit::Popup::HIDDEN );
614 else if ( event.keyPressedName == "Right" )
616 mImageStageScale.x = std::max( 0.05f, std::min( 1.0f, mImageStageScale.x * 1.1f ) );
618 else if ( event.keyPressedName == "Left" )
620 mImageStageScale.x = std::max( 0.05f, mImageStageScale.x * 0.9f );
622 else if ( event.keyPressedName == "Up" )
624 mImageStageScale.y = std::max( 0.05f, std::min( 1.0f, mImageStageScale.y * 1.1f ) );
626 else if ( event.keyPressedName == "Down" )
628 mImageStageScale.y = std::max( 0.05f, mImageStageScale.y * 0.9f );
630 else if ( event.keyPressedName == "o" )
632 mImageStageScale.x = std::max( 0.05f, mImageStageScale.x * 0.9f );
633 mImageStageScale.y = std::max( 0.05f, mImageStageScale.y * 0.9f );
635 else if ( event.keyPressedName == "p" )
637 mImageStageScale.x = std::max( 0.05f, std::min( 1.0f, mImageStageScale.x * 1.1f ) );
638 mImageStageScale.y = std::max( 0.05f, std::min( 1.0f, mImageStageScale.y * 1.1f ) );
640 else if ( event.keyPressedName == "n" )
642 mCurrentPath = mCurrentPath + 1;
643 mCurrentPath = mCurrentPath < NUM_IMAGE_PATHS ? mCurrentPath : 0;
645 else if ( event.keyPressedName == "b" )
647 mCurrentPath = mCurrentPath - 1;
648 mCurrentPath = mCurrentPath >= 0 ? mCurrentPath : NUM_IMAGE_PATHS - 1;
650 // Cycle filter and scaling modes:
651 else if ( event.keyPressedName == "f" )
653 mSamplingMode = NextFilterMode( mSamplingMode );
654 mSamplingModeButton.SetLabelText( StringFromFilterMode( mSamplingMode ) );
656 // Cycle filter and scaling modes:
657 else if ( event.keyPressedName == "s" )
659 mFittingMode = NextScalingMode( mFittingMode );
660 mFittingModeButton.SetLabelText( StringFromScalingMode( mFittingMode ) );
674 const char * const path = IMAGE_PATHS[mCurrentPath];
676 Stage stage = Stage::GetCurrent();
677 Size imageSize = stage.GetSize() * mImageStageScale;
678 const ImageDimensions imageSizeInt = ImageDimensions::FromFloatArray( &imageSize.x );
680 ResourceImage image = ResourceImage::New( path, imageSizeInt, mFittingMode, mSamplingMode );
681 image.LoadingFinishedSignal().Connect( this, &ImageScalingAndFilteringController::OnImageLoaded );
685 mDesiredBox.SetSize( stage.GetSize() * mImageStageScale );
686 mHeightBox.SetSize( stage.GetSize().width, (stage.GetSize() * mImageStageScale).height );
687 mWidthBox.SetSize( (stage.GetSize() * mImageStageScale).width, stage.GetSize().height );
691 Application& mApplication;
692 Toolkit::ImageView mDesiredBox; //< Background rectangle to show requested image size.
693 Toolkit::ImageView mHeightBox; //< Background horizontal stripe to show requested image height.
694 Toolkit::ImageView mWidthBox; //< Background vertical stripe to show requested image width.
695 Toolkit::PushButton mFittingModeButton;
696 Toolkit::PushButton mSamplingModeButton;
697 Toolkit::Popup mPopup;
698 PinchGestureDetector mPinchDetector;
699 float mLastPinchScale;
700 Toolkit::PushButton mGrabCorner;
701 PanGestureDetector mPanGestureDetector;
702 Toolkit::ImageView mImageView;
703 ResourceImage mNextImage; //< Currently-loading image
704 Vector2 mImageStageScale;
706 FittingMode::Type mFittingMode;
707 SamplingMode::Type mSamplingMode;
710 void RunTest( Application& application )
712 ImageScalingAndFilteringController test( application );
714 application.MainLoop();
717 // Entry point for Linux & Tizen applications
718 int main( int argc, char **argv )
720 Application application = Application::New( &argc, &argv, DALI_DEMO_THEME_PATH );
722 RunTest( application );