LCOV - code coverage report
Current view: top level - source/gui/ObjectTypes - CHotkeyPicker.h (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 0 3 0.0 %
Date: 2026-12-03 01:19:39 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /* Copyright (C) 2026 Wildfire Games.
       2             :  * This file is part of 0 A.D.
       3             :  *
       4             :  * 0 A.D. is free software: you can redistribute it and/or modify
       5             :  * it under the terms of the GNU General Public License as published by
       6             :  * the Free Software Foundation, either version 2 of the License, or
       7             :  * (at your option) any later version.
       8             :  *
       9             :  * 0 A.D. is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12             :  * GNU General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU General Public License
      15             :  * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
      16             :  */
      17             : 
      18             : #ifndef INCLUDED_CHOTKEYPICKER
      19             : #define INCLUDED_CHOTKEYPICKER
      20             : 
      21             : #include "gui/CGUISetting.h"
      22             : #include "gui/ObjectBases/IGUIObject.h"
      23             : #include "ps/CStr.h"
      24             : #include "ps/Input.h"
      25             : 
      26             : #include <SDL_scancode.h>
      27             : #include <vector>
      28             : 
      29             : class CGUI;
      30             : union SDL_Event;
      31             : 
      32             : /**
      33             :  * When in focus, returns all currently pressed keys.
      34             :  * After a set time without changes, it will trigger a "combination" event.
      35             :  *
      36             :  * Used to create new hotkey combinations in-game. Mostly custom.
      37             :  * This object does not draw anything.
      38             :  */
      39             : class CHotkeyPicker : public IGUIObject
      40             : {
      41           0 :     GUI_OBJECT(CHotkeyPicker)
      42             : 
      43             : public:
      44             :     CHotkeyPicker(CGUI& pGUI);
      45             : 
      46             :     // Do nothing.
      47           0 :     virtual void Draw(CCanvas2D&) {};
      48             : 
      49             :     // Checks if the timer has passed and we need to fire a "combination" event.
      50             :     virtual void Tick();
      51             : 
      52             :     // React to blur/focus.
      53             :     virtual void HandleMessage(SGUIMessage& Message);
      54             : 
      55             :     // Pre-empt events: this is our sole purpose.
      56             :     virtual Input::Reaction PreemptEvent(const SDL_Event& ev);
      57             : 
      58           0 :     struct Key
      59             :     {
      60             :         // The scancode is used for fast comparisons.
      61             :         SDL_Scancode code;
      62             :         // This is the name ultimately stored in the config file.
      63             :         CStr scancodeName;
      64             :     };
      65             : protected:
      66             :     // Fire an event with m_KeysPressed as argument.
      67             :     void FireEvent(const CStr& event);
      68             : 
      69             :     // Time without changes until a "combination" event is sent.
      70             :     CGUISimpleSetting<float> m_TimeToCombination;
      71             :     // Time of the last registered key change.
      72             :     double m_LastKeyChange;
      73             : 
      74             :     // Keep track of which keys we are pressing, and precompute their name for JS code.
      75             :     std::vector<Key> m_KeysPressed;
      76             : 
      77             :     static const CStr EventNameCombination;
      78             :     static const CStr EventNameKeyChange;
      79             : };
      80             : 
      81             : #endif // INCLUDED_CHOTKEYPICKER

Generated by: LCOV version 1.16