RadioButton.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. GWEN
  3. Copyright (c) 2010 Facepunch Studios
  4. See license in Gwen.h
  5. */
  6. #pragma once
  7. #ifndef GWEN_CONTROLS_RADIOBUTTON_H
  8. #define GWEN_CONTROLS_RADIOBUTTON_H
  9. #include "Gwen/Controls/Base.h"
  10. #include "Gwen/Controls/Label.h"
  11. #include "Gwen/Controls/Button.h"
  12. #include "Gwen/Gwen.h"
  13. #include "Gwen/Skin.h"
  14. #include "Gwen/Controls/CheckBox.h"
  15. #include "Gwen/Controls/LabelClickable.h"
  16. namespace Gwen
  17. {
  18. namespace Controls
  19. {
  20. class GWEN_EXPORT RadioButton : public CheckBox
  21. {
  22. GWEN_CONTROL( RadioButton, CheckBox );
  23. virtual void Render( Skin::Base* skin );
  24. private:
  25. // From CheckBox
  26. virtual bool AllowUncheck(){ return false; }
  27. };
  28. class GWEN_EXPORT LabeledRadioButton : public Base
  29. {
  30. public:
  31. GWEN_CONTROL_INLINE( LabeledRadioButton, Base )
  32. {
  33. SetSize( 200, 19 );
  34. m_RadioButton = new RadioButton( this );
  35. m_RadioButton->Dock( Pos::Left );
  36. m_RadioButton->SetMargin( Margin( 0, 4, 2, 4 ) );
  37. m_RadioButton->SetTabable( false );
  38. m_RadioButton->SetKeyboardInputEnabled( false );
  39. m_Label = new LabelClickable( this );
  40. m_Label->SetAlignment( Pos::CenterV | Pos::Left );
  41. m_Label->SetText( "Radio Button" );
  42. m_Label->Dock( Pos::Fill );
  43. m_Label->onPress.Add( m_RadioButton, &CheckBox::ReceiveEventPress );
  44. m_Label->SetTabable( false );
  45. m_Label->SetKeyboardInputEnabled( false );
  46. }
  47. void RenderFocus( Gwen::Skin::Base* skin )
  48. {
  49. if ( Gwen::KeyboardFocus != this ) return;
  50. if ( !IsTabable() ) return;
  51. skin->DrawKeyboardHighlight( this, GetRenderBounds(), 0 );
  52. }
  53. virtual RadioButton* GetRadioButton() { return m_RadioButton; }
  54. virtual LabelClickable* GetLabel(){ return m_Label; }
  55. virtual bool OnKeySpace(bool bDown) { if ( bDown ) m_RadioButton->SetChecked( !m_RadioButton->IsChecked() ); return true; }
  56. virtual void Select(){ m_RadioButton->SetChecked( true ); }
  57. private:
  58. RadioButton* m_RadioButton;
  59. LabelClickable* m_Label;
  60. };
  61. }
  62. }
  63. #endif