code_uifontdescription.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // UIFontdescription application source code
  2. #include <Atomic/UI/UISlider.h>
  3. #include <Atomic/UI/UIFontDescription.h>
  4. #include <Atomic/UI/UITextField.h>
  5. #include "PeriodicApp.h"
  6. void PeriodicApp::setup_uifontdescription( UIWidget *layout )
  7. {
  8. PODVector<UIWidget*> dest;
  9. layout->SearchWidgetClass( "TBButton", dest );
  10. for (unsigned ii = 0; ii < dest.Size(); ii++)
  11. SubscribeToEvent(dest[ii], E_WIDGETEVENT, ATOMIC_HANDLER(PeriodicApp, HandleUifontdescriptionEvent ));
  12. UISlider *steps = static_cast<UISlider*>(layout->GetWidget("fontstep"));
  13. if(steps)
  14. SubscribeToEvent(steps, E_WIDGETEVENT, ATOMIC_HANDLER(PeriodicApp, HandleUifontdescriptionEvent ));
  15. }
  16. void PeriodicApp::HandleUifontdescriptionEvent(StringHash eventType, VariantMap& eventData)
  17. {
  18. using namespace WidgetEvent;
  19. UIWidget* widget = static_cast<UIWidget*>(eventData[P_TARGET].GetPtr());
  20. if ( widget == NULL ) return;
  21. if (eventData[P_TYPE] == UI_EVENT_TYPE_CLICK)
  22. {
  23. if (widget->GetId() == "uifontdescriptioncode" )
  24. {
  25. AppLog( "UIFontdescription support : " + widget->GetId() + " was pressed " );
  26. ViewCode ( "Components/code_uifontdescription.cpp", widget->GetParent() );
  27. }
  28. if (widget->GetId() == "uifontdescriptionlayout" )
  29. {
  30. AppLog( "UIFontdescription support : " + widget->GetId() + " was pressed ");
  31. ViewCode ( "Scenes/layout_uifontdescription.ui.txt", widget->GetParent() );
  32. }
  33. }
  34. else if (eventData[P_TYPE] == UI_EVENT_TYPE_CHANGED )
  35. {
  36. if ( widget->GetId() == "fontstep" )
  37. {
  38. UISlider *uis = static_cast<UISlider*>(widget);
  39. if (uis)
  40. {
  41. UITextField *mytext = static_cast<UITextField*>(widget->FindWidget("changetext"));
  42. UIFontDescription *myfont = new UIFontDescription(context_);
  43. myfont->SetSize(int(uis->GetValue()));
  44. myfont->SetId("Vera");
  45. mytext->SetFontDescription (myfont);
  46. mytext->SetText ( "Size " + String (int (uis->GetValue())));
  47. AppLog( "UIFontdescription action : " + widget->GetId() + " step size changed to " + String (uis->GetValue()));
  48. }
  49. }
  50. }
  51. }