1 /*
2  Copyright (c) 2016 yvt
3 
4  This file is part of OpenSpades.
5 
6  OpenSpades is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  OpenSpades is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with OpenSpades.  If not, see <http://www.gnu.org/licenses/>.
18 
19  */
20 
21 #include "ScriptManager.h"
22 #include <Client/Fonts.h>
23 
24 namespace spades{
25 	namespace client {
26 
27 		class FontManagerRegistrar : public ScriptObjectRegistrar {
GetGuiFont(FontManager * self)28 			static IFont *GetGuiFont(FontManager *self) {
29 				IFont *font = self->GetGuiFont();
30 				font->AddRef();
31 				return font;
32 			}
GetHeadingFont(FontManager * self)33 			static IFont *GetHeadingFont(FontManager *self) {
34 				IFont *font = self->GetHeadingFont();
35 				font->AddRef();
36 				return font;
37 			}
GetLargeFont(FontManager * self)38 			static IFont *GetLargeFont(FontManager *self) {
39 				IFont *font = self->GetLargeFont();
40 				font->AddRef();
41 				return font;
42 			}
GetSquareDesignFont(FontManager * self)43 			static IFont *GetSquareDesignFont(FontManager *self) {
44 				IFont *font = self->GetSquareDesignFont();
45 				font->AddRef();
46 				return font;
47 			}
48 
49 		public:
FontManagerRegistrar()50 			FontManagerRegistrar() : ScriptObjectRegistrar("FontManager") {}
Register(ScriptManager * manager,Phase phase)51 			virtual void Register(ScriptManager *manager, Phase phase) {
52 				asIScriptEngine *eng = manager->GetEngine();
53 				int r;
54 				eng->SetDefaultNamespace("spades");
55 				switch(phase){
56 					case PhaseObjectType:
57 						r = eng->RegisterObjectType("FontManager",
58 													0, asOBJ_REF);
59 						manager->CheckError(r);
60 						r = eng->RegisterObjectBehaviour("FontManager",
61 														 asBEHAVE_ADDREF, "void f()",
62 														 asMETHOD(FontManager, AddRef),
63 														 asCALL_THISCALL);
64 						manager->CheckError(r);
65 						r = eng->RegisterObjectBehaviour("FontManager",
66 														 asBEHAVE_RELEASE, "void f()",
67 														 asMETHOD(FontManager, Release),
68 														 asCALL_THISCALL);
69 						manager->CheckError(r);
70 						r = eng->RegisterObjectMethod("FontManager",
71 													  "Font@ get_GuiFont()",
72 													  asFUNCTION(GetGuiFont),
73 													  asCALL_CDECL_OBJLAST);
74 						manager->CheckError(r);
75 						r = eng->RegisterObjectMethod("FontManager",
76 													  "Font@ get_HeadingFont()",
77 													  asFUNCTION(GetHeadingFont),
78 													  asCALL_CDECL_OBJLAST);
79 						manager->CheckError(r);
80 						r = eng->RegisterObjectMethod("FontManager",
81 													  "Font@ get_LargeFont()",
82 													  asFUNCTION(GetLargeFont),
83 													  asCALL_CDECL_OBJLAST);
84 						manager->CheckError(r);
85 						r = eng->RegisterObjectMethod("FontManager",
86 													  "Font@ get_SquareDesignFont()",
87 													  asFUNCTION(GetSquareDesignFont),
88 													  asCALL_CDECL_OBJLAST);
89 						manager->CheckError(r);
90 
91 						break;
92 					case PhaseObjectMember:
93 						break;
94 					default:
95 
96 						break;
97 				}
98 			}
99 		};
100 
101 		static FontManagerRegistrar registrar;
102 	}
103 }
104