Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JSInterface_GameView.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2013 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 "JSInterface_GameView.h"
21 #include "graphics/GameView.h"
22 #include "ps/Game.h"
23 #include "ps/CLogger.h"
25 
26 #define IMPLEMENT_BOOLEAN_SCRIPT_SETTING(NAME) \
27 bool JSI_GameView::Get##NAME##Enabled(void* UNUSED(cbdata)) \
28 { \
29  if (!g_Game || !g_Game->GetView()) \
30  { \
31  LOGERROR(L"Trying to get a setting from GameView when it's not initialized!"); \
32  return false; \
33  } \
34  return g_Game->GetView()->Get##NAME##Enabled(); \
35 } \
36 \
37 void JSI_GameView::Set##NAME##Enabled(void* UNUSED(cbdata), bool Enabled) \
38 { \
39  if (!g_Game || !g_Game->GetView()) \
40  { \
41  LOGERROR(L"Trying to set a setting of GameView when it's not initialized!"); \
42  return; \
43  } \
44  g_Game->GetView()->Set##NAME##Enabled(Enabled); \
45 }
46 
48 IMPLEMENT_BOOLEAN_SCRIPT_SETTING(LockCullCamera);
49 IMPLEMENT_BOOLEAN_SCRIPT_SETTING(ConstrainCamera);
50 
51 #undef IMPLEMENT_BOOLEAN_SCRIPT_SETTING
52 
53 
54 #define REGISTER_BOOLEAN_SCRIPT_SETTING(NAME) \
55 scriptInterface.RegisterFunction<bool, &JSI_GameView::Get##NAME##Enabled>("GameView_Get" #NAME "Enabled"); \
56 scriptInterface.RegisterFunction<void, bool, &JSI_GameView::Set##NAME##Enabled>("GameView_Set" #NAME "Enabled");
57 
59 {
61  REGISTER_BOOLEAN_SCRIPT_SETTING(LockCullCamera);
62  REGISTER_BOOLEAN_SCRIPT_SETTING(ConstrainCamera);
63 }
64 
65 #undef REGISTER_BOOLEAN_SCRIPT_SETTING
66 
67 
68 
#define IMPLEMENT_BOOLEAN_SCRIPT_SETTING(NAME)
#define REGISTER_BOOLEAN_SCRIPT_SETTING(NAME)
void RegisterScriptFunctions(ScriptInterface &ScriptInterface)
Abstraction around a SpiderMonkey JSContext.