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: 2023-01-19 00:18:29 Functions: 0 7 0.0 %

          Line data    Source code
       1             : /* Copyright (C) 2021 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/CGUI.h"
      22             : #include "gui/ObjectBases/IGUIObject.h"
      23             : #include "lib/external_libraries/libsdl.h"
      24             : #include "ps/CStr.h"
      25             : 
      26             : #include <vector>
      27             : 
      28             : /**
      29             :  * When in focus, returns all currently pressed keys.
      30             :  * After a set time without changes, it will trigger a "combination" event.
      31             :  *
      32             :  * Used to create new hotkey combinations in-game. Mostly custom.
      33             :  * This object does not draw anything.
      34             :  */
      35             : class CHotkeyPicker : public IGUIObject
      36             : {
      37           0 :     GUI_OBJECT(CHotkeyPicker)
      38             : 
      39             : public:
      40             :     CHotkeyPicker(CGUI& pGUI);
      41             :     virtual ~CHotkeyPicker();
      42             : 
      43             :     // Do nothing.
      44           0 :     virtual void Draw(CCanvas2D& UNUSED(canvas)) {};
      45             : 
      46             :     // Checks if the timer has passed and we need to fire a "combination" event.
      47             :     virtual void Tick();
      48             : 
      49             :     // React to blur/focus.
      50             :     virtual void HandleMessage(SGUIMessage& Message);
      51             : 
      52             :     // Pre-empt events: this is our sole purpose.
      53             :     virtual InReaction PreemptEvent(const SDL_Event_* ev);
      54             : 
      55           0 :     struct Key
      56             :     {
      57             :         // The scancode is used for fast comparisons.
      58             :         SDL_Scancode code;
      59             :         // This is the name ultimately stored in the config file.
      60             :         CStr scancodeName;
      61             :     };
      62             : protected:
      63             :     // Fire an event with m_KeysPressed as argument.
      64             :     void FireEvent(const CStr& event);
      65             : 
      66             :     // Time without changes until a "combination" event is sent.
      67             :     CGUISimpleSetting<float> m_TimeToCombination;
      68             :     // Time of the last registered key change.
      69             :     double m_LastKeyChange;
      70             : 
      71             :     // Keep track of which keys we are pressing, and precompute their name for JS code.
      72             :     std::vector<Key> m_KeysPressed;
      73             : 
      74             :     static const CStr EventNameCombination;
      75             :     static const CStr EventNameKeyChange;
      76             : };
      77             : 
      78             : #endif // INCLUDED_CHOTKEYPICKER

Generated by: LCOV version 1.13