Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Globals.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2012 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 
22 #include "network/NetClient.h"
23 #include "ps/GameSetup/Config.h"
25 
26 bool g_app_minimized = false;
27 bool g_app_has_focus = true;
28 
29 std::map<int32_t, bool> g_keys;
30 int g_mouse_x = 50, g_mouse_y = 50;
31 bool g_mouse_active = true;
32 
33 // unused, left, right, middle, wheel up, wheel down
34 // (order is given by SDL_BUTTON_* constants).
35 bool g_mouse_buttons[6] = {0};
36 
38 
39 // updates the state of the above; never swallows messages.
41 {
42  size_t c;
43 
44  switch(ev->ev.type)
45  {
46 #if SDL_VERSION_ATLEAST(2, 0, 0)
47  case SDL_WINDOWEVENT:
48  switch(ev->ev.window.event)
49  {
50  case SDL_WINDOWEVENT_MINIMIZED:
51  g_app_minimized = true;
52  break;
53  case SDL_WINDOWEVENT_RESTORED:
54  g_app_minimized = false;
55  break;
56  case SDL_WINDOWEVENT_FOCUS_GAINED:
57  g_app_has_focus = true;
58  break;
59  case SDL_WINDOWEVENT_FOCUS_LOST:
60  g_app_has_focus = false;
61  break;
62  case SDL_WINDOWEVENT_ENTER:
63  g_mouse_active = true;
64  break;
65  case SDL_WINDOWEVENT_LEAVE:
66  g_mouse_active = false;
67  break;
68  }
69  return IN_PASS;
70 #else
71  case SDL_ACTIVEEVENT:
72  if(ev->ev.active.state & SDL_APPACTIVE)
73  {
74  g_app_minimized = (ev->ev.active.gain == 0); // negated
75 
76  if ( g_SoundManager )
78  }
80  {
81  g_app_has_focus = (ev->ev.active.gain != 0);
82 
83  if ( g_SoundManager )
85  }
87  g_mouse_active = (ev->ev.active.gain != 0);
88  return IN_PASS;
89 #endif
90 
91  case SDL_MOUSEMOTION:
92  g_mouse_x = ev->ev.motion.x;
93  g_mouse_y = ev->ev.motion.y;
94  return IN_PASS;
95 
97  case SDL_MOUSEBUTTONUP:
98  c = ev->ev.button.button;
101  else
102  {
103  // don't complain: just ignore people with too many mouse buttons
104  //debug_warn(L"invalid mouse button");
105  }
106  return IN_PASS;
107 
108  case SDL_KEYDOWN:
109  case SDL_KEYUP:
110  g_keys[ev->ev.key.keysym.sym] = (ev->ev.type == SDL_KEYDOWN);
111  return IN_PASS;
112 
113  default:
114  return IN_PASS;
115  }
116 
117  UNREACHABLE;
118 }
CNetClient * g_NetClient
Global network client for the standard game.
Definition: NetClient.cpp:37
virtual void Pause(bool pauseIt)=0
SDL_KeyboardEvent key
Definition: wsdl.h:305
ISoundManager * g_SoundManager
bool g_mouse_active
Indicates whether the mouse is focused on the game window (mouse positions should usually be consider...
Definition: Globals.cpp:31
#define ARRAY_SIZE(name)
SDL_MouseMotionEvent motion
Definition: wsdl.h:307
shared_ptr< IFrequencyFilter > PIFrequencyFilter
SDL_Event ev
Definition: libsdl.h:56
Uint8 type
Definition: wsdl.h:302
SDL_MouseButtonEvent button
Definition: wsdl.h:308
SDL_ActiveEvent active
Definition: wsdl.h:303
bool g_app_has_focus
Definition: Globals.cpp:27
InReaction
Definition: input.h:34
Definition: input.h:40
#define UNREACHABLE
&quot;unreachable code&quot; helpers
InReaction GlobalsInputHandler(const SDL_Event_ *ev)
Definition: Globals.cpp:40
bool g_mouse_buttons[6]
g_mouse_buttons: Mouse buttons states, indexed by SDL_BUTTON_* constants.
Definition: Globals.cpp:35
PIFrequencyFilter g_frequencyFilter
Definition: Globals.cpp:37
bool g_PauseOnFocusLoss
Definition: Config.cpp:37
bool g_app_minimized
Definition: Globals.cpp:26
int g_mouse_x
Definition: Globals.cpp:30
SDL_keysym keysym
Definition: wsdl.h:196
int g_mouse_y
Definition: Globals.cpp:30
SDLKey sym
Definition: wsdl.h:188
std::map< int32_t, bool > g_keys
g_keys: Key states, indexed by SDLK* constants.
Definition: Globals.cpp:29