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: 2022-06-14 00:41:00 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /* Copyright (C) 2017 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             : #include "Globals.h"
      20             : 
      21             : #include "network/NetClient.h"
      22             : #include "ps/GameSetup/Config.h"
      23             : #include "soundmanager/ISoundManager.h"
      24             : 
      25             : bool g_app_minimized = false;
      26             : bool g_app_has_focus = true;
      27             : 
      28             : std::unordered_map<int32_t, bool> g_scancodes;
      29             : 
      30             : int g_mouse_x = 50, g_mouse_y = 50;
      31             : bool g_mouse_active = true;
      32             : 
      33             : // g_mouse_buttons[0] is unused. The order of entries is as in KeyName.h for MOUSE_*
      34             : bool g_mouse_buttons[MOUSE_LAST - MOUSE_BASE] = {0};
      35             : 
      36             : PIFrequencyFilter g_frequencyFilter;
      37             : 
      38             : // updates the state of the above; never swallows messages.
      39          44 : InReaction GlobalsInputHandler(const SDL_Event_* ev)
      40             : {
      41          44 :     size_t c;
      42             : 
      43          44 :     switch(ev->ev.type)
      44             :     {
      45           0 :     case SDL_WINDOWEVENT:
      46           0 :         switch(ev->ev.window.event)
      47             :         {
      48           0 :         case SDL_WINDOWEVENT_MINIMIZED:
      49           0 :             g_app_minimized = true;
      50           0 :             break;
      51           0 :         case SDL_WINDOWEVENT_EXPOSED:
      52           0 :         case SDL_WINDOWEVENT_RESTORED:
      53           0 :             g_app_minimized = false;
      54           0 :             break;
      55           0 :         case SDL_WINDOWEVENT_FOCUS_GAINED:
      56           0 :             g_app_has_focus = true;
      57           0 :             break;
      58           0 :         case SDL_WINDOWEVENT_FOCUS_LOST:
      59           0 :             g_app_has_focus = false;
      60           0 :             break;
      61           0 :         case SDL_WINDOWEVENT_ENTER:
      62           0 :             g_mouse_active = true;
      63           0 :             break;
      64           0 :         case SDL_WINDOWEVENT_LEAVE:
      65           0 :             g_mouse_active = false;
      66           0 :             break;
      67             :         }
      68             :         return IN_PASS;
      69             : 
      70           0 :     case SDL_MOUSEMOTION:
      71           0 :         g_mouse_x = ev->ev.motion.x;
      72           0 :         g_mouse_y = ev->ev.motion.y;
      73           0 :         return IN_PASS;
      74             : 
      75           0 :     case SDL_MOUSEBUTTONDOWN:
      76           0 :     case SDL_MOUSEBUTTONUP:
      77           0 :         c = ev->ev.button.button;
      78           0 :         if(c < ARRAY_SIZE(g_mouse_buttons))
      79           0 :             g_mouse_buttons[c] = (ev->ev.type == SDL_MOUSEBUTTONDOWN);
      80             :         else
      81             :         {
      82             :             // don't complain: just ignore people with too many mouse buttons
      83             :             //debug_warn(L"invalid mouse button");
      84             :         }
      85             :         return IN_PASS;
      86             : 
      87          40 :     case SDL_KEYDOWN:
      88          40 :     case SDL_KEYUP:
      89          40 :         g_scancodes[ev->ev.key.keysym.scancode] = (ev->ev.type == SDL_KEYDOWN);
      90          40 :         return IN_PASS;
      91             : 
      92             :     default:
      93             :         return IN_PASS;
      94             :     }
      95             : 
      96             :     UNREACHABLE;
      97             : }

Generated by: LCOV version 1.13