code_uisceneview.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // UISceneView application source code
  2. // some code from UISceneview2D sample program
  3. #include <Atomic/UI/UISceneView.h>
  4. #include <Atomic/UI/UILayout.h>
  5. #include <Atomic/Scene/Scene.h>
  6. #include <Atomic/Graphics/Camera.h>
  7. #include <Atomic/Resource/ResourceCache.h>
  8. #include "PeriodicApp.h"
  9. #include "Spinner.h"
  10. void PeriodicApp::setup_uisceneview( UIWidget *layout)
  11. {
  12. PODVector<UIWidget*> dest;
  13. layout->SearchWidgetClass( "TBButton", dest );
  14. for (unsigned ii = 0; ii < dest.Size(); ii++)
  15. SubscribeToEvent(dest[ii], E_WIDGETEVENT, ATOMIC_HANDLER(PeriodicApp, HandleUisceneviewEvent ));
  16. UISceneView * mysceneview = new UISceneView(context_); // make a scene...view
  17. mysceneview->SetId( "UISceneViewDemo"); // tag it, in case we want to get it again later
  18. SubscribeToEvent(mysceneview, E_WIDGETEVENT, ATOMIC_HANDLER(PeriodicApp, HandleUisceneviewEvent ));
  19. /*
  20. Scene *myscene = GetSubsystem<AtomicPlayer::Player>()->LoadScene("Scenes/sceneview.scene");
  21. DONT DO IT THIS WAY for C++! Make a scene, then LoadXML!
  22. */
  23. ResourceCache* cache = GetSubsystem<ResourceCache>();
  24. Scene *myscene = new Scene(context_);
  25. if ( myscene )
  26. {
  27. if ( myscene->LoadXML(*(cache->GetFile("Scenes/sceneview.scene"))))
  28. {
  29. Node *cameraNode = myscene->GetChild("Camera", true);
  30. Camera* mycamera = cameraNode->GetComponent<Camera>();
  31. Node* planetNode = myscene->GetChild("TheWorld", true);
  32. if(planetNode) // spin-o-rama, c++ style
  33. {
  34. Rotator* rotator = planetNode->CreateComponent<Rotator>();
  35. rotator->SetRotationSpeed(Vector3(0.0f, 20.0f, 1.0f));
  36. }
  37. mysceneview->SetView(myscene, mycamera);
  38. mysceneview->SetAutoUpdate(true);
  39. }
  40. }
  41. UILayoutParams *lpx = new UILayoutParams(context_);
  42. lpx->SetWidth (640);
  43. lpx->SetHeight(320);
  44. lpx->SetMinWidth(640);
  45. lpx->SetMinHeight(320);
  46. lpx->SetMaxWidth (640);
  47. lpx->SetMaxHeight(320);
  48. mysceneview->SetLayoutParams(lpx);
  49. UIWidget* lower = layout->GetWidget("uisceneviewlower");
  50. UIWidget* mysvc = layout->GetWidget("sceneviewcontainer");
  51. mysvc->AddChildBefore(mysceneview, lower);
  52. }
  53. void PeriodicApp::HandleUisceneviewEvent(StringHash eventType, VariantMap& eventData)
  54. {
  55. using namespace WidgetEvent;
  56. UIWidget* widget = static_cast<UIWidget*>(eventData[P_TARGET].GetPtr());
  57. if ( widget == NULL ) return;
  58. if (eventData[P_TYPE] == UI_EVENT_TYPE_CLICK)
  59. {
  60. if (widget->GetId() == "uisceneviewcode" )
  61. {
  62. AppLog( "UISceneView support : " + widget->GetId() + " was pressed " );
  63. ViewCode ( "Components/code_uisceneview.cpp", widget->GetParent() );
  64. }
  65. if (widget->GetId() == "uisceneviewlayout" )
  66. {
  67. AppLog( "UISceneView support : " + widget->GetId() + " was pressed ");
  68. ViewCode ( "Scenes/layout_uisceneview.ui.txt", widget->GetParent() );
  69. }
  70. }
  71. if ( widget->GetId() == "UISceneViewDemo" )
  72. {
  73. AppLog( "UISceneView event : " + widget->GetId() + " got event= "+ EventReport(eventData[P_TYPE].GetInt()) );
  74. }
  75. }