code_uieditfield.cpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // UIEditField application source code
  2. #include <Atomic/Resource/ResourceCache.h>
  3. #include <Atomic/UI/UIEditField.h>
  4. #include "PeriodicApp.h"
  5. void PeriodicApp::setup_uieditfield( UIWidget *layout )
  6. {
  7. PODVector<UIWidget*> dest;
  8. layout->SearchWidgetClass( "TBButton", dest );
  9. for (unsigned ii = 0; ii < dest.Size(); ii++)
  10. SubscribeToEvent(dest[ii], E_WIDGETEVENT, ATOMIC_HANDLER(PeriodicApp, HandleUieditfieldEvent ));
  11. UIWidget *ed1 = layout->GetWidget("editfieldsingle");
  12. if ( ed1)
  13. SubscribeToEvent(ed1, E_WIDGETEVENT, ATOMIC_HANDLER(PeriodicApp, HandleUieditfieldEvent ));
  14. UIWidget *ed2 = layout->GetWidget("editfieldmulti");
  15. if ( ed2)
  16. SubscribeToEvent(ed2, E_WIDGETEVENT, ATOMIC_HANDLER(PeriodicApp, HandleUieditfieldEvent ));
  17. }
  18. void PeriodicApp::HandleUieditfieldEvent(StringHash eventType, VariantMap& eventData)
  19. {
  20. using namespace WidgetEvent;
  21. UIWidget* widget = static_cast<UIWidget*>(eventData[P_TARGET].GetPtr());
  22. if ( widget == NULL ) return;
  23. if (eventData[P_TYPE] == UI_EVENT_TYPE_CLICK)
  24. {
  25. if (widget->GetId() == "uieditfieldcode" )
  26. {
  27. AppLog( "UIEditField support : " + widget->GetId() + " was pressed " );
  28. ViewCode ( "Components/code_uieditfield.cpp", widget->GetParent() );
  29. }
  30. if (widget->GetId() == "uieditfieldlayout" )
  31. {
  32. AppLog( "UIEditField support : " + widget->GetId() + " was pressed ");
  33. ViewCode ( "Scenes/layout_uieditfield.ui.txt", widget->GetParent() );
  34. }
  35. if (widget->GetId() == "editfieldadd" )
  36. {
  37. AppLog( "UIEditField action : " + widget->GetId() + " was pressed ");
  38. UIEditField *ef1 = static_cast<UIEditField*>(widget->FindWidget("editfieldmulti"));
  39. if(ef1)
  40. {
  41. ResourceCache* cache = GetSubsystem<ResourceCache>();
  42. SharedPtr<File> filex = cache->GetFile("Scenes/layout_uieditfield.ui.txt");
  43. String textx = filex->ReadText();
  44. filex->Close();
  45. ef1->SetText(textx);
  46. }
  47. }
  48. if (widget->GetId() == "editfieldclr" )
  49. {
  50. AppLog( "UIEditField action : " + widget->GetId() + " was pressed ");
  51. UIEditField *ef2 = static_cast<UIEditField*>(widget->FindWidget("editfieldmulti"));
  52. if(ef2)
  53. ef2->SetText("");
  54. }
  55. }
  56. else
  57. {
  58. if ( widget->GetId() == "editfieldsingle" )
  59. {
  60. UIEditField *efx = static_cast<UIEditField*>(widget);
  61. AppLog( "UIEditField event : " + widget->GetId() + " text = `" + efx->GetText() + "` event type = " + EventReport(eventData[P_TYPE].GetInt()));
  62. }
  63. if ( widget->GetId() == "editfieldmulti" )
  64. {
  65. UIEditField *efx = static_cast<UIEditField*>(widget);
  66. AppLog( "UIEditField event : " + widget->GetId() + " text = `" + efx->GetText() + "` event type = " + EventReport(eventData[P_TYPE].GetInt()));
  67. }
  68. }
  69. }