]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - contrib/camera/camera.cpp
Fixing Linux SCons build.
[xonotic/netradiant.git] / contrib / camera / camera.cpp
1 /*
2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
4
5 This file is part of GtkRadiant.
6
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 */
21
22 /*
23 Camera plugin for GtkRadiant
24 Copyright (C) 2002 Splash Damage Ltd.
25 */
26
27 #include "camera.h"
28
29 // Render view
30 CRenderer         *Renderer = NULL;
31
32 // Interaction
33 CListener         *Listener = NULL;
34
35 // plugin name
36 static const char *PLUGIN_NAME = "Camera";
37
38 // commands in the menu
39 static const char *PLUGIN_COMMANDS = "About...,-,Load Camera...,-,Preview Camera,-,Camera Inspector...,-,New Spline Camera,New Interpolated Camera,New Fixed Camera";
40
41 // globals
42 GtkWidget *g_pRadiantWnd = NULL;
43 GtkWidget *g_pCameraInspectorWnd = NULL;
44 CCamera   *firstCam = NULL;       // double linked list
45 CCamera   *firstFreeCam = NULL;   // single linked list
46 CCamera   *currentCam = NULL;     // single item
47 bool                    g_bEditOn = false;
48 int       g_iEditMode = 0;                              // 0: editting points 1: adding points
49 int       g_iActiveTarget = -1;
50 int                             g_iPreviewRunning = 0;  // 0: no preview 1: start preview 2: preview in progress
51
52 static const char *PLUGIN_ABOUT = "Camera v1.0 for GtkRadiant\n"
53                                   "by Arnout van Meer (rr2do2@splashdamage.com)\n\n"
54                                   "This product contains software technology\n"
55                                   "from id Software, Inc. ('id Technology').\n"
56                                   "id Technology (c) 2001, 2002 id Software, Inc.";
57
58
59 #include "iplugin.h"
60
61 const char* QERPlug_Init(void* hApp, void* pMainWidget)
62 {
63   g_pRadiantWnd = (GtkWidget*)pMainWidget;
64
65   // initialize cams
66   for( int i = 0; i < MAX_CAMERAS; i++ ) {
67     if( i == 0 ) {  
68       firstFreeCam = new CCamera( i );
69       firstCam = firstFreeCam;
70     } else {
71       firstCam->SetNext( new CCamera( i ) );
72       firstCam = firstCam->GetNext();
73       }
74   }
75   firstCam = NULL;
76
77   if( !Renderer )
78   {
79     Renderer = new CRenderer;
80   }
81
82   if( g_pCameraInspectorWnd == NULL )
83     g_pCameraInspectorWnd = CreateCameraInspectorDialog();
84
85   InitIglToQgl(&g_QglTable);
86
87   GetFileTypeRegistry()->addType("camera", filetype_t("Camera file", "*.camera"));
88
89   return "Camera for GtkRadiant";
90 }
91
92 const char* QERPlug_GetName()
93 {
94   return PLUGIN_NAME;
95 }
96
97 const char* QERPlug_GetCommandList()
98 {
99   return PLUGIN_COMMANDS;
100 }
101
102 void QERPlug_Dispatch (const char* p, float* vMin, float* vMax, bool bSingleBrush)
103 {
104   if( !strcmp( p, "New Fixed Camera" ) )
105     DoNewFixedCamera();
106   else if( !strcmp( p, "New Interpolated Camera" ) )
107     DoNewInterpolatedCamera();
108   else if( !strcmp( p, "New Spline Camera" ) )
109     DoNewSplineCamera();
110   else if( !strcmp( p, "Camera Inspector..." ) )
111     DoCameraInspector();
112   else if( !strcmp( p, "Preview Camera" ) )
113     DoPreviewCamera();
114   else if( !strcmp( p, "Load Camera..." ) )
115     DoLoadCamera();
116   else if( !strcmp( p, "About..." ) )
117     g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, PLUGIN_ABOUT, "About", MB_OK, NULL );
118 }
119
120
121 // toolbar
122
123 #include "itoolbar.h"
124
125 unsigned int ToolbarButtonCount()
126 {
127   return 1;
128 }
129
130 class CameraInspectorButton : public IToolbarButton
131 {
132 public:
133   virtual const char* getImage() const
134   {
135     return "camera_insp.bmp";
136   }
137   virtual const char* getText() const
138   {
139     return "Inspector";
140   }
141   virtual const char* getTooltip() const
142   {
143     return "Camera Inspector";
144   }
145   virtual void activate() const
146   {
147     DoCameraInspector();
148   }
149   virtual EType getType() const
150   {
151     return eButton;
152   }
153 };
154
155 CameraInspectorButton g_camerainspectorbutton;
156
157 const IToolbarButton* GetToolbarButton(unsigned int index)
158 {
159   return &g_camerainspectorbutton;
160 }
161
162
163 _QERFuncTable_1   g_FuncTable;
164 _QERQglTable      g_QglTable;
165 _QERUITable       g_UITable;
166 _QERCameraTable         g_CameraTable;
167
168 // =============================================================================
169 // SYNAPSE
170
171 #include "synapse.h"
172
173 class CameraSynapseClient : public CSynapseClient
174 {
175 public:
176   // CSynapseClient API
177   bool RequestAPI(APIDescriptor_t *pAPI);
178   const char* GetInfo();
179   
180   CameraSynapseClient() { }
181   virtual ~CameraSynapseClient() { }
182 };
183
184 CSynapseServer* g_pSynapseServer = NULL;
185 CameraSynapseClient g_SynapseClient;
186
187 #if __GNUC__ >= 4
188 #pragma GCC visibility push(default)
189 #endif
190 extern "C" CSynapseClient* SYNAPSE_DLL_EXPORT Synapse_EnumerateInterfaces( const char *version, CSynapseServer *pServer ) {
191 #if __GNUC__ >= 4
192 #pragma GCC visibility pop
193 #endif
194   if (strcmp(version, SYNAPSE_VERSION))
195   {
196     Syn_Printf("ERROR: synapse API version mismatch: should be '" SYNAPSE_VERSION "', got '%s'\n", version);
197     return NULL;
198   }
199   g_pSynapseServer = pServer;
200   g_pSynapseServer->IncRef();
201   Set_Syn_Printf(g_pSynapseServer->Get_Syn_Printf());
202
203   g_SynapseClient.AddAPI(TOOLBAR_MAJOR, "camera", sizeof(_QERPlugToolbarTable));
204   g_SynapseClient.AddAPI(PLUGIN_MAJOR, "camera", sizeof(_QERPluginTable));
205
206   g_SynapseClient.AddAPI(RADIANT_MAJOR, NULL, sizeof(_QERFuncTable_1), SYN_REQUIRE, &g_FuncTable);
207   g_SynapseClient.AddAPI(UI_MAJOR, NULL, sizeof(_QERUITable), SYN_REQUIRE, &g_UITable);
208   g_SynapseClient.AddAPI(QGL_MAJOR, NULL, sizeof(_QERQglTable), SYN_REQUIRE, &g_QglTable);
209   g_SynapseClient.AddAPI(CAMERA_MAJOR, NULL, sizeof(_QERCameraTable), SYN_REQUIRE, &g_CameraTable);
210
211   return &g_SynapseClient;
212 }
213
214 bool CameraSynapseClient::RequestAPI(APIDescriptor_t *pAPI)
215 {
216   if (!strcmp(pAPI->major_name, TOOLBAR_MAJOR))
217   {
218     _QERPlugToolbarTable* pTable= static_cast<_QERPlugToolbarTable*>(pAPI->mpTable);
219
220     pTable->m_pfnToolbarButtonCount = &ToolbarButtonCount;
221     pTable->m_pfnGetToolbarButton = &GetToolbarButton;
222     return true;
223   }
224   else if (!strcmp(pAPI->major_name, PLUGIN_MAJOR))
225   {
226     _QERPluginTable* pTable= static_cast<_QERPluginTable*>(pAPI->mpTable);
227
228     pTable->m_pfnQERPlug_Init = QERPlug_Init;
229     pTable->m_pfnQERPlug_GetName = QERPlug_GetName;
230     pTable->m_pfnQERPlug_GetCommandList = QERPlug_GetCommandList;
231     pTable->m_pfnQERPlug_Dispatch = QERPlug_Dispatch;
232     return true;
233   }
234
235   Syn_Printf("ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo());
236   return false;
237 }
238
239 #include "version.h"
240
241 const char* CameraSynapseClient::GetInfo()
242 {
243   return "Camera plugin v1.0 - Arnout van Meer - built " __DATE__ " " RADIANT_VERSION;
244 }
245
246
247
248 //
249 // CCamera
250 //
251 CCamera *AllocCam() {
252   if( !firstFreeCam )
253     return( NULL );
254
255   CCamera *cam = firstFreeCam;
256   firstFreeCam = firstFreeCam->GetNext();
257   cam->Init();
258   if( firstCam ) {
259     cam->SetNext( firstCam );
260     firstCam->SetPrev( cam );
261   }
262   firstCam = cam;
263
264   return( cam );
265 }
266
267 void FreeCam( CCamera *cam ) {
268   if( cam->GetPrev() ) {
269     if( cam->GetNext() ) {
270       cam->GetPrev()->SetNext( cam->GetNext() );
271       cam->GetNext()->SetPrev( cam->GetPrev() );
272     } else {
273       cam->GetPrev()->SetNext( NULL );
274     }
275   } else if( cam->GetNext() ) {
276     cam->GetNext()->SetPrev( NULL );
277     firstCam = cam->GetNext();
278   } else {
279     firstCam = NULL;
280   }
281
282   cam->GetCam()->clear();
283   cam->Init();
284
285   if( firstFreeCam ) {
286     cam->SetNext( firstFreeCam );
287   }
288   firstFreeCam = cam;
289 }
290
291 void SetCurrentCam( CCamera *cam ) {
292   currentCam = cam;
293 }
294
295 CCamera *GetCurrentCam() {
296   return( currentCam );
297 }