Commit b16077f4097b55414580a5915e85d7b1186d7d07

Authored by Andrew Poor
Committed by Adeel Kazmi
1 parent 6a6a13fc

Mesh visual buttons change.

Change-Id: I32ed8eb68cd099fc329a93fc6c370a4caada32a0
examples/mesh-visual/mesh-visual-example.cpp
@@ -39,11 +39,24 @@ namespace @@ -39,11 +39,24 @@ namespace
39 MeshVisual::ShadingMode::TEXTURELESS_WITH_DIFFUSE_LIGHTING 39 MeshVisual::ShadingMode::TEXTURELESS_WITH_DIFFUSE_LIGHTING
40 }; 40 };
41 41
  42 + //Button labels.
  43 + const char * const PAUSE = " || ";
  44 + const char * const PLAY = " > ";
  45 + const char * const FIXED = "FIXED";
  46 + const char * const MANUAL = "MANUAL";
  47 + const char * const FRONT = "FRONT";
  48 + const char * const BACK = "BACK";
  49 +
  50 + //Image urls for the light.
  51 + const char * const LIGHT_URL_FRONT = DEMO_IMAGE_DIR "light-icon-front.png";
  52 + const char * const LIGHT_URL_BACK = DEMO_IMAGE_DIR "light-icon-back.png";
  53 +
42 const float X_ROTATION_DISPLACEMENT_FACTOR = 60.0f; 54 const float X_ROTATION_DISPLACEMENT_FACTOR = 60.0f;
43 const float Y_ROTATION_DISPLACEMENT_FACTOR = 60.0f; 55 const float Y_ROTATION_DISPLACEMENT_FACTOR = 60.0f;
44 const float MODEL_SCALE = 0.75f; 56 const float MODEL_SCALE = 0.75f;
45 const float LIGHT_SCALE = 0.15f; 57 const float LIGHT_SCALE = 0.15f;
46 - const float BUTTONS_OFFSET_BOTTOM = 0.9f; 58 + const float BUTTONS_OFFSET_BOTTOM = 0.08f;
  59 + const float BUTTONS_OFFSET_SIDE = 0.2f;
47 const int NUM_MESHES = 2; 60 const int NUM_MESHES = 2;
48 61
49 //Used to identify actors. 62 //Used to identify actors.
@@ -60,11 +73,12 @@ public: @@ -60,11 +73,12 @@ public:
60 MeshVisualController( Application& application ) 73 MeshVisualController( Application& application )
61 : mApplication( application ), //Store handle to the application. 74 : mApplication( application ), //Store handle to the application.
62 mModelIndex( 1 ), //Start with metal robot. 75 mModelIndex( 1 ), //Start with metal robot.
63 - mShadingModeIndex( 0 ), //Start with textured with detailed specular lighting. 76 + mShadingModeIndex( 0 ), //Start with texture and detailed specular lighting.
64 mTag( -1 ), //Non-valid default, which will get set to a correct value when used. 77 mTag( -1 ), //Non-valid default, which will get set to a correct value when used.
65 mSelectedModelIndex( -1 ), //Non-valid default, which will get set to a correct value when used. 78 mSelectedModelIndex( -1 ), //Non-valid default, which will get set to a correct value when used.
66 mPaused( false ), //Animations play by default. 79 mPaused( false ), //Animations play by default.
67 - mLightFixed( true ) //The light is fixed by default. 80 + mLightFixed( true ), //The light is fixed by default.
  81 + mLightFront( true ) //The light is in front by default.
68 { 82 {
69 // Connect to the Application's Init signal 83 // Connect to the Application's Init signal
70 mApplication.InitSignal().Connect( this, &MeshVisualController::Create ); 84 mApplication.InitSignal().Connect( this, &MeshVisualController::Create );
@@ -163,57 +177,78 @@ public: @@ -163,57 +177,78 @@ public:
163 //Place the various buttons on the bottom of the screen, with title labels where necessary. 177 //Place the various buttons on the bottom of the screen, with title labels where necessary.
164 void SetupButtons( Layer layer ) 178 void SetupButtons( Layer layer )
165 { 179 {
166 - //Text label title for changing model or shader.  
167 - TextLabel changeTitleLabel = TextLabel::New( "Switch" );  
168 - changeTitleLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );  
169 - changeTitleLabel.SetProperty( TextLabel::Property::UNDERLINE, "{\"thickness\":\"2.0\"}" );  
170 - changeTitleLabel.SetParentOrigin( Vector3( 0.2, BUTTONS_OFFSET_BOTTOM, 0.5 ) );  
171 - changeTitleLabel.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );  
172 - layer.Add( changeTitleLabel ); 180 + //Actor for positioning model and shading mode buttons.
  181 + Actor positionActorModel = Actor::New();
  182 + positionActorModel.SetParentOrigin( Vector3( BUTTONS_OFFSET_SIDE, 1.0 - BUTTONS_OFFSET_BOTTOM, 0.5 ) );
  183 + positionActorModel.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
  184 + layer.Add( positionActorModel );
173 185
174 - //Create button for model changing 186 + //Create button for model changing.
175 PushButton modelButton = Toolkit::PushButton::New(); 187 PushButton modelButton = Toolkit::PushButton::New();
176 modelButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); 188 modelButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
177 modelButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeModelClicked ); 189 modelButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeModelClicked );
178 - modelButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );  
179 - modelButton.SetAnchorPoint( AnchorPoint::TOP_RIGHT ); 190 + modelButton.SetParentOrigin( ParentOrigin::TOP_CENTER );
  191 + modelButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
180 modelButton.SetLabelText( "Model" ); 192 modelButton.SetLabelText( "Model" );
181 - changeTitleLabel.Add( modelButton );  
182 -  
183 - //Create button for shader changing  
184 - PushButton shaderButton = Toolkit::PushButton::New();  
185 - shaderButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );  
186 - shaderButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeShaderClicked );  
187 - shaderButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );  
188 - shaderButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );  
189 - shaderButton.SetLabelText( "Shader" );  
190 - changeTitleLabel.Add( shaderButton );  
191 -  
192 - //Create button for pausing animations 193 + positionActorModel.Add( modelButton );
  194 +
  195 + //Create button for shading mode changing.
  196 + PushButton shadingModeButton = Toolkit::PushButton::New();
  197 + shadingModeButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
  198 + shadingModeButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeShadingModeClicked );
  199 + shadingModeButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
  200 + shadingModeButton.SetAnchorPoint( AnchorPoint::TOP_CENTER );
  201 + shadingModeButton.SetLabelText( "Shading Mode" );
  202 + positionActorModel.Add( shadingModeButton );
  203 +
  204 + //Text label title for changing model or shading mode.
  205 + TextLabel changeTitleLabel = TextLabel::New( "Change" );
  206 + changeTitleLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
  207 + changeTitleLabel.SetProperty( TextLabel::Property::UNDERLINE, "{\"thickness\":\"2.0\"}" );
  208 + changeTitleLabel.SetParentOrigin( ParentOrigin::TOP_CENTER );
  209 + changeTitleLabel.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
  210 + modelButton.Add( changeTitleLabel );
  211 +
  212 + //Create button for pausing animations.
193 PushButton pauseButton = Toolkit::PushButton::New(); 213 PushButton pauseButton = Toolkit::PushButton::New();
194 pauseButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); 214 pauseButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
195 pauseButton.ClickedSignal().Connect( this, &MeshVisualController::OnPauseClicked ); 215 pauseButton.ClickedSignal().Connect( this, &MeshVisualController::OnPauseClicked );
196 - pauseButton.SetParentOrigin( Vector3( 0.5, BUTTONS_OFFSET_BOTTOM, 0.5 ) );  
197 - pauseButton.SetAnchorPoint( AnchorPoint::TOP_CENTER );  
198 - pauseButton.SetLabelText( " || " ); 216 + pauseButton.SetParentOrigin( Vector3( 0.5, 1.0 - BUTTONS_OFFSET_BOTTOM, 0.5 ) );
  217 + pauseButton.SetAnchorPoint( AnchorPoint::CENTER );
  218 + pauseButton.SetLabelText( PAUSE );
199 layer.Add( pauseButton ); 219 layer.Add( pauseButton );
200 220
  221 + //Actor for positioning light position buttons.
  222 + Actor positionActorLight = Actor::New();
  223 + positionActorLight.SetParentOrigin( Vector3( 1.0 - BUTTONS_OFFSET_SIDE, 1.0 - BUTTONS_OFFSET_BOTTOM, 0.5 ) );
  224 + positionActorLight.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
  225 + layer.Add( positionActorLight );
  226 +
  227 + //Create button for switching between manual and fixed light position.
  228 + PushButton lightModeButton = Toolkit::PushButton::New();
  229 + lightModeButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
  230 + lightModeButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeLightModeClicked );
  231 + lightModeButton.SetParentOrigin( ParentOrigin::TOP_CENTER );
  232 + lightModeButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
  233 + lightModeButton.SetLabelText( FIXED );
  234 + positionActorLight.Add( lightModeButton );
  235 +
  236 + //Create button for switching between front and back light position.
  237 + PushButton lightSideButton = Toolkit::PushButton::New();
  238 + lightSideButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
  239 + lightSideButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeLightSideClicked );
  240 + lightSideButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
  241 + lightSideButton.SetAnchorPoint( AnchorPoint::TOP_CENTER );
  242 + lightSideButton.SetLabelText( FRONT );
  243 + positionActorLight.Add( lightSideButton );
  244 +
201 //Text label title for light position mode. 245 //Text label title for light position mode.
202 TextLabel lightTitleLabel = TextLabel::New( "Light Position" ); 246 TextLabel lightTitleLabel = TextLabel::New( "Light Position" );
203 lightTitleLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); 247 lightTitleLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
204 lightTitleLabel.SetProperty( TextLabel::Property::UNDERLINE, "{\"thickness\":\"2.0\"}" ); 248 lightTitleLabel.SetProperty( TextLabel::Property::UNDERLINE, "{\"thickness\":\"2.0\"}" );
205 - lightTitleLabel.SetParentOrigin( Vector3( 0.8, BUTTONS_OFFSET_BOTTOM, 0.5 ) ); 249 + lightTitleLabel.SetParentOrigin( ParentOrigin::TOP_CENTER );
206 lightTitleLabel.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); 250 lightTitleLabel.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
207 - layer.Add( lightTitleLabel );  
208 -  
209 - //Create button for switching between manual and fixed light position.  
210 - PushButton lightButton = Toolkit::PushButton::New();  
211 - lightButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );  
212 - lightButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeLightModeClicked );  
213 - lightButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );  
214 - lightButton.SetAnchorPoint( AnchorPoint::TOP_CENTER );  
215 - lightButton.SetLabelText( "FIXED" );  
216 - lightTitleLabel.Add( lightButton ); 251 + lightModeButton.Add( lightTitleLabel );
217 } 252 }
218 253
219 //Add a point light source the the scene, on a layer above the first. 254 //Add a point light source the the scene, on a layer above the first.
@@ -246,10 +281,7 @@ public: @@ -246,10 +281,7 @@ public:
246 mLightSource.SetPosition( Stage::GetCurrent().GetSize().x * 0.85f, Stage::GetCurrent().GetSize().y * 0.125 ); 281 mLightSource.SetPosition( Stage::GetCurrent().GetSize().x * 0.85f, Stage::GetCurrent().GetSize().y * 0.125 );
247 282
248 //Supply an image to represent the light. 283 //Supply an image to represent the light.
249 - Property::Map lightMap;  
250 - lightMap.Insert( Visual::Property::TYPE, Visual::IMAGE );  
251 - lightMap.Insert( ImageVisual::Property::URL, DEMO_IMAGE_DIR "light-icon.png" );  
252 - mLightSource.SetProperty( Control::Property::BACKGROUND, Property::Value( lightMap ) ); 284 + SetLightImage();
253 285
254 //Connect to touch signal for dragging. 286 //Connect to touch signal for dragging.
255 mLightSource.TouchedSignal().Connect( this, &MeshVisualController::OnTouch ); 287 mLightSource.TouchedSignal().Connect( this, &MeshVisualController::OnTouch );
@@ -264,14 +296,27 @@ public: @@ -264,14 +296,27 @@ public:
264 upperLayer.Add( mLightSource ); 296 upperLayer.Add( mLightSource );
265 297
266 //Decide which light to use to begin with. 298 //Decide which light to use to begin with.
267 - if( mLightFixed ) 299 + SetLightMode();
  300 + }
  301 +
  302 + //Sets the image to use for the light source depending on whether the light is in front or behind.
  303 + void SetLightImage()
  304 + {
  305 + std::string imageUrl;
  306 +
  307 + if( mLightFront )
268 { 308 {
269 - UseFixedLight(); 309 + imageUrl = LIGHT_URL_FRONT;
270 } 310 }
271 else 311 else
272 { 312 {
273 - UseManualLight(); 313 + imageUrl = LIGHT_URL_BACK;
274 } 314 }
  315 +
  316 + Property::Map lightMap;
  317 + lightMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
  318 + lightMap.Insert( ImageVisual::Property::URL, imageUrl );
  319 + mLightSource.SetProperty( Control::Property::BACKGROUND, Property::Value( lightMap ) );
275 } 320 }
276 321
277 //Updates the displayed models to account for parameter changes. 322 //Updates the displayed models to account for parameter changes.
@@ -292,16 +337,31 @@ public: @@ -292,16 +337,31 @@ public:
292 } 337 }
293 } 338 }
294 339
  340 + //Set the mode used to light the models.
  341 + void SetLightMode()
  342 + {
  343 + if( mLightFixed )
  344 + {
  345 + UseFixedLight();
  346 + }
  347 + else
  348 + {
  349 + UseManualLight();
  350 + }
  351 + }
  352 +
  353 + //Make the models use a fixed, invisible light above the center of the stage.
295 void UseFixedLight() 354 void UseFixedLight()
296 { 355 {
297 //Hide draggable source 356 //Hide draggable source
298 mLightSource.SetVisible( false ); 357 mLightSource.SetVisible( false );
299 358
300 - //Use stage dimensions to place light at center, offset outwards in z axis. 359 + //Use stage dimensions to place light at center, offset in z axis.
301 Stage stage = Stage::GetCurrent(); 360 Stage stage = Stage::GetCurrent();
302 float width = stage.GetSize().width; 361 float width = stage.GetSize().width;
303 float height = stage.GetSize().height; 362 float height = stage.GetSize().height;
304 - Vector3 lightPosition = Vector3( width / 2.0f, height / 2.0f, std::max( width, height ) * 5.0f ); 363 + Vector3 lightPosition = Vector3( width / 2.0f, height / 2.0f,
  364 + ( mLightFront ? 1 : -1 ) * std::max( width, height ) * 5.0f );
305 365
306 //Set global light position 366 //Set global light position
307 for( int i = 0; i < NUM_MESHES; ++i ) 367 for( int i = 0; i < NUM_MESHES; ++i )
@@ -310,21 +370,23 @@ public: @@ -310,21 +370,23 @@ public:
310 } 370 }
311 } 371 }
312 372
  373 + //Make the models use a light source that the user can drag around.
313 void UseManualLight() 374 void UseManualLight()
314 { 375 {
315 //Show draggable source 376 //Show draggable source
316 mLightSource.SetVisible( true ); 377 mLightSource.SetVisible( true );
317 378
318 - //Update to switch light position to that off the source. 379 + //Update to switch light position of models to that of the source.
319 UpdateLight(); 380 UpdateLight();
320 } 381 }
321 382
322 //Updates the light position for each model to account for changes in the source on screen. 383 //Updates the light position for each model to account for changes in the source on screen.
323 void UpdateLight() 384 void UpdateLight()
324 { 385 {
325 - //Set light position to the x and y of the light control, offset out of the screen. 386 + //Set light position to the x and y of the light control, offset into/out of the screen.
326 Vector3 controlPosition = mLightSource.GetCurrentPosition(); 387 Vector3 controlPosition = mLightSource.GetCurrentPosition();
327 - Vector3 lightPosition = Vector3( controlPosition.x, controlPosition.y, Stage::GetCurrent().GetSize().x / 2.0f ); 388 + Vector3 lightPosition = Vector3( controlPosition.x, controlPosition.y,
  389 + ( mLightFront ? 1 : -1 ) * Stage::GetCurrent().GetSize().x / 2.0f );
328 390
329 for( int i = 0; i < NUM_MESHES; ++i ) 391 for( int i = 0; i < NUM_MESHES; ++i )
330 { 392 {
@@ -426,8 +488,8 @@ public: @@ -426,8 +488,8 @@ public:
426 return true; 488 return true;
427 } 489 }
428 490
429 - //Cycle through the list of shaders.  
430 - bool OnChangeShaderClicked( Toolkit::Button button ) 491 + //Cycle through the list of shading modes.
  492 + bool OnChangeShadingModeClicked( Toolkit::Button button )
431 { 493 {
432 ++mShadingModeIndex %= 3; 494 ++mShadingModeIndex %= 3;
433 495
@@ -451,7 +513,7 @@ public: @@ -451,7 +513,7 @@ public:
451 mModels[i].rotationAnimation.Pause(); 513 mModels[i].rotationAnimation.Pause();
452 } 514 }
453 515
454 - button.SetLabelText( " > " ); 516 + button.SetLabelText( PLAY );
455 } 517 }
456 else //Unpause all animations again. 518 else //Unpause all animations again.
457 { 519 {
@@ -460,14 +522,14 @@ public: @@ -460,14 +522,14 @@ public:
460 mModels[i].rotationAnimation.Play(); 522 mModels[i].rotationAnimation.Play();
461 } 523 }
462 524
463 - button.SetLabelText( " || " ); 525 + button.SetLabelText( PAUSE );
464 } 526 }
465 527
466 return true; 528 return true;
467 } 529 }
468 530
469 531
470 - //Switch between a fixed light source in front of the screen, and a light source the user can drag around. 532 + //Switch between a fixed light source above/behind the screen, and a light source the user can drag around.
471 bool OnChangeLightModeClicked( Toolkit::Button button ) 533 bool OnChangeLightModeClicked( Toolkit::Button button )
472 { 534 {
473 //Toggle state. 535 //Toggle state.
@@ -475,17 +537,39 @@ public: @@ -475,17 +537,39 @@ public:
475 537
476 if( mLightFixed ) 538 if( mLightFixed )
477 { 539 {
478 - UseFixedLight();  
479 -  
480 - button.SetLabelText( "FIXED" ); 540 + button.SetLabelText( FIXED );
481 } 541 }
482 else 542 else
483 { 543 {
484 - UseManualLight(); 544 + button.SetLabelText( MANUAL );
  545 + }
485 546
486 - button.SetLabelText( "MANUAL" ); 547 + SetLightMode();
  548 +
  549 + return true;
  550 + }
  551 +
  552 + //Switch between the light being in front of and behind the models.
  553 + bool OnChangeLightSideClicked( Toolkit::Button button )
  554 + {
  555 + //Toggle state.
  556 + mLightFront = !mLightFront;
  557 +
  558 + if( mLightFront )
  559 + {
  560 + button.SetLabelText( FRONT );
  561 + }
  562 + else
  563 + {
  564 + button.SetLabelText( BACK );
487 } 565 }
488 566
  567 + //Change light image.
  568 + SetLightImage();
  569 +
  570 + //Update light to account for the change.
  571 + SetLightMode();
  572 +
489 return true; 573 return true;
490 } 574 }
491 575
@@ -516,11 +600,12 @@ private: @@ -516,11 +600,12 @@ private:
516 Vector2 mRotationStart; 600 Vector2 mRotationStart;
517 601
518 int mModelIndex; //Index of model to load. 602 int mModelIndex; //Index of model to load.
519 - int mShadingModeIndex; //Index of shader type to use. 603 + int mShadingModeIndex; //Index of shading mode to use.
520 int mTag; //Identifies what kind of actor has been selected in OnTouch. 604 int mTag; //Identifies what kind of actor has been selected in OnTouch.
521 int mSelectedModelIndex; //Index of model selected on screen. 605 int mSelectedModelIndex; //Index of model selected on screen.
522 bool mPaused; //If true, all animations are paused and should stay so. 606 bool mPaused; //If true, all animations are paused and should stay so.
523 bool mLightFixed; //If false, the light is in manual. 607 bool mLightFixed; //If false, the light is in manual.
  608 + bool mLightFront; //Bool for light being in front or behind the models.
524 }; 609 };
525 610
526 // Entry point for Linux & Tizen applications 611 // Entry point for Linux & Tizen applications
resources/images/light-icon-back.png 0 โ†’ 100644

129 KB

resources/images/light-icon.png renamed to resources/images/light-icon-front.png

115 KB