LCOV - code coverage report
Current view: top level - source/ps - Globals.cpp (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 7 37 18.9 %
Date: 2026-12-03 01:19:39 Functions: 1 1 100.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             : #include "precompiled.h"
      19             : 
      20             : #include "Globals.h"
      21             : 
      22             : #include "lib/code_annotation.h"
      23             : #include "lib/external_libraries/libsdl.h"
      24             : 
      25             : #include <SDL_events.h>
      26             : #include <SDL_video.h>
      27             : #include <cstddef>
      28             : #include "network/NetClient.h"
      29             : #include "ps/GameSetup/Config.h"
      30             : #include "ps/Input.h"
      31             : #include "soundmanager/ISoundManager.h"
      32             : 
      33             : bool g_app_minimized = false;
      34             : bool g_app_has_focus = true;
      35             : 
      36             : std::unordered_map<int32_t, bool> g_scancodes;
      37             : 
      38             : int g_mouse_x = 50, g_mouse_y = 50;
      39             : bool g_mouse_active = true;
      40             : 
      41             : // g_mouse_buttons[0] is unused. The order of entries is as in KeyName.h for MOUSE_*
      42             : bool g_mouse_buttons[MOUSE_LAST - MOUSE_BASE] = {0};
      43             : 
      44             : PIFrequencyFilter g_frequencyFilter;
      45             : 
      46             : // updates the state of the above; never swallows messages.
      47          44 : Input::Reaction GlobalsInputHandler(const SDL_Event& ev)
      48             : {
      49          44 :     size_t c;
      50             : 
      51          44 :     switch(ev.type)
      52             :     {
      53           0 :     case SDL_WINDOWEVENT:
      54           0 :         switch(ev.window.event)
      55             :         {
      56           0 :         case SDL_WINDOWEVENT_MINIMIZED:
      57           0 :             g_app_minimized = true;
      58           0 :             break;
      59           0 :         case SDL_WINDOWEVENT_EXPOSED:
      60           0 :         case SDL_WINDOWEVENT_RESTORED:
      61           0 :             g_app_minimized = false;
      62           0 :             break;
      63           0 :         case SDL_WINDOWEVENT_FOCUS_GAINED:
      64           0 :             g_app_has_focus = true;
      65           0 :             break;
      66           0 :         case SDL_WINDOWEVENT_FOCUS_LOST:
      67           0 :             g_app_has_focus = false;
      68           0 :             break;
      69           0 :         case SDL_WINDOWEVENT_ENTER:
      70           0 :             g_mouse_active = true;
      71           0 :             break;
      72           0 :         case SDL_WINDOWEVENT_LEAVE:
      73           0 :             g_mouse_active = false;
      74           0 :             break;
      75             :         }
      76             :         return Input::Reaction::PASS;
      77             : 
      78           0 :     case SDL_MOUSEMOTION:
      79           0 :         g_mouse_x = ev.motion.x;
      80           0 :         g_mouse_y = ev.motion.y;
      81           0 :         return Input::Reaction::PASS;
      82             : 
      83           0 :     case SDL_MOUSEBUTTONDOWN:
      84           0 :     case SDL_MOUSEBUTTONUP:
      85           0 :         c = ev.button.button;
      86           0 :         if(c < ARRAY_SIZE(g_mouse_buttons))
      87           0 :             g_mouse_buttons[c] = (ev.type == SDL_MOUSEBUTTONDOWN);
      88             :         else
      89             :         {
      90             :             // don't complain: just ignore people with too many mouse buttons
      91             :             //debug_warn(L"invalid mouse button");
      92             :         }
      93             :         return Input::Reaction::PASS;
      94             : 
      95          40 :     case SDL_KEYDOWN:
      96          40 :     case SDL_KEYUP:
      97          40 :         g_scancodes[ev.key.keysym.scancode] = (ev.type == SDL_KEYDOWN);
      98          40 :         return Input::Reaction::PASS;
      99             : 
     100             :     default:
     101             :         return Input::Reaction::PASS;
     102             :     }
     103             : 
     104             :     UNREACHABLE;
     105             : }

Generated by: LCOV version 1.16