Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
3.3 KiB

  1. #ifndef _INCLUDED_JOYPAD_FOCUS_H
  2. #define _INCLUDED_JOYPAD_FOCUS_H
  3. #ifdef _WIN32
  4. #pragma once
  5. #endif
  6. #include <vgui_controls/Panel.h>
  7. #include <vgui_controls/PHandle.h>
  8. // This class provides a way of using VGUI panels with a joypad. Instead of specific joypad responses being coded
  9. // into every control and panel, this class allows the joypad to manipulate any set of panels that respond to
  10. // IsCursorOver and OnMousePressed/Released events. Panels that want to allow joypad manipulation simply have to
  11. // register themselves with this on creation and remove themselves from this on destruction.
  12. // holds a list of vgui panels that can have joypad cursor focus
  13. // along with the currently focused one
  14. // responds to joypad codes to move this focus about and cause mouseclicks when a confirm button is pressed
  15. #define NUM_JF_KEYS 6
  16. #define JF_KEY_REPEAT_DELAY 500
  17. #define JF_KEY_REPEAT_INTERVAL 250
  18. namespace vgui
  19. {
  20. class ImagePanelColored;
  21. };
  22. class CJoypadOutline;
  23. class CJoypadFocus
  24. {
  25. public:
  26. enum JoypadFocusKey
  27. {
  28. JF_KEY_UP = 0,
  29. JF_KEY_DOWN,
  30. JF_KEY_LEFT,
  31. JF_KEY_RIGHT,
  32. JF_KEY_CONFIRM,
  33. JF_KEY_CANCEL,
  34. };
  35. struct FocusArea
  36. {
  37. vgui::PHandle hPanel;
  38. bool bClickOnFocus;
  39. bool bModal;
  40. };
  41. CJoypadFocus();
  42. // registering for focus
  43. void AddToFocusList(vgui::Panel* pPanel, bool bClickOnFocus=false, bool bModal=false);
  44. void RemoveFromFocusList(vgui::Panel* pPanel);
  45. // changing focus
  46. void SetFocusPanel(int index);
  47. void SetFocusPanel(vgui::Panel* pPanel, bool bClickOnFocus=false);
  48. vgui::Panel* GetFocusPanel();
  49. int FindNextPanel(vgui::Panel *pSource, float angle);
  50. // clicking
  51. bool OnJoypadButtonPressed(int keynum);
  52. bool OnJoypadButtonReleased(int keynum);
  53. void CheckKeyRepeats();
  54. void ClickFocusPanel(bool bDown, bool bRightMouse);
  55. void DoubleClickFocusPanel(bool bRightMouse);
  56. void SetJoypadCodes(int iUpCode, int iDownCode, int iLeftCode, int iRightCode, int iConfirmCode, int iCancelCode);
  57. void SetJoypadMode(bool b) { m_bJoypadMode = b; }
  58. bool IsJoypadMode() { return m_bJoypadMode; }
  59. // checks a panel and all its parents are visible
  60. static bool IsPanelReallyVisible(vgui::Panel *pPanel);
  61. // KF_ numbers for the joypad buttons
  62. int m_KeyNum[NUM_JF_KEYS];
  63. // status of the joypad buttons
  64. bool m_bKeyDown[NUM_JF_KEYS];
  65. float m_fNextKeyRepeatTime[NUM_JF_KEYS];
  66. // list of panels that have registered themselves for joypad focus
  67. CUtlVector<FocusArea> m_FocusAreas;
  68. FocusArea m_CurrentFocus;
  69. vgui::DHANDLE<CJoypadOutline> m_hOutline;
  70. int m_iModal; // how many modal-type focus panels we have. If there are more than 1, all non-modal panels will be ignored when moving around
  71. bool m_bJoypadMode;
  72. bool m_bDebugOutput;
  73. };
  74. CJoypadFocus* GetJoypadFocus();
  75. // graphical representaion of joypad cursor focus - attaches to the focus' parent and puts itself
  76. // in front of the focus, sized to match
  77. class CJoypadOutline : public vgui::Panel
  78. {
  79. DECLARE_CLASS_SIMPLE( CJoypadOutline, vgui::Panel );
  80. public:
  81. CJoypadOutline(vgui::Panel *parent, const char *name);
  82. void ApplySchemeSettings(vgui::IScheme* pScheme);
  83. virtual void OnThink();
  84. virtual void Paint();
  85. void SizeTo(int x, int y, int w, int t);
  86. virtual void GetCornerTextureSize( int& w, int& h );
  87. vgui::ImagePanelColored* m_pImagePanel;
  88. vgui::PHandle m_hLastFocusPanel;
  89. };
  90. #endif // _INCLUDED_JOYPAD_FOCUS_H