Button.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include "UnitTest.h"
  2. using namespace Gwen;
  3. class Button : public GUnit
  4. {
  5. public:
  6. GWEN_CONTROL_INLINE( Button, GUnit )
  7. {
  8. // Normal button
  9. Controls::Button* pButtonA = new Controls::Button( this );
  10. pButtonA->SetText( L"Event Tester" );
  11. pButtonA->onPress.Add( this, &Button::onButtonA );
  12. {
  13. Controls::Button* pButtonA = new Controls::Button( this );
  14. pButtonA->SetBounds( 200, 30, 300, 200 );
  15. pButtonA->SetText( L"Event Tester" );
  16. pButtonA->onPress.Add( this, &Button::onButtonA );
  17. }
  18. // Unicode test
  19. Controls::Button* pButtonB = new Controls::Button( this );
  20. pButtonB->SetText( L"\u0417\u0430\u043C\u0435\u0436\u043D\u0430\u044F \u043C\u043E\u0432\u0430" );
  21. Gwen::Align::PlaceBelow( pButtonB, pButtonA, 10 );
  22. // Image with text
  23. Controls::Button* pButtonC = new Controls::Button( this );
  24. pButtonC->SetText( L"Image Button" );
  25. pButtonC->SetImage( L"test16.png" );
  26. Gwen::Align::PlaceBelow( pButtonC, pButtonB, 10 );
  27. // Just image
  28. Controls::Button* pButtonD = new Controls::Button( this );
  29. pButtonD->SetText( L"" );
  30. pButtonD->SetImage( L"test16.png" );
  31. pButtonD->SetSize( 20, 20 );
  32. Gwen::Align::PlaceBelow( pButtonD, pButtonC, 10 );
  33. // Toggle button
  34. Controls::Button* pButtonE = new Controls::Button( this );
  35. pButtonE->SetText( L"Toggle Me" );
  36. pButtonE->SetIsToggle( true );
  37. pButtonE->onToggle.Add( this, &Button::OnToggle );
  38. pButtonE->onToggleOn.Add( this, &Button::OnToggleOn );
  39. pButtonE->onToggleOff.Add( this, &Button::OnToggleOff );
  40. Gwen::Align::PlaceBelow( pButtonE, pButtonD, 10 );
  41. }
  42. void onButtonA( Controls::Base* pControl )
  43. {
  44. UnitPrint( L"Button Pressed (using 'OnPress' event)" );
  45. }
  46. void OnToggle( Controls::Base* pControl )
  47. {
  48. UnitPrint( L"Button Toggled (using 'OnToggle' event)" );
  49. }
  50. void OnToggleOn( Controls::Base* pControl )
  51. {
  52. UnitPrint( L"Button Toggled ON (using 'OnToggleOn' event)" );
  53. }
  54. void OnToggleOff( Controls::Base* pControl )
  55. {
  56. UnitPrint( L"Button Toggled Off (using 'OnToggleOff' event)" );
  57. }
  58. };
  59. DEFINE_UNIT_TEST( Button, L"Button" );