]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - contrib/camera/camera.cpp
uncrustify! now the code is only ugly on the *inside*
[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         g_pRadiantWnd = (GtkWidget*)pMainWidget;
63
64         // initialize cams
65         for ( int i = 0; i < MAX_CAMERAS; i++ ) {
66                 if ( i == 0 ) {
67                         firstFreeCam = new CCamera( i );
68                         firstCam = firstFreeCam;
69                 }
70                 else {
71                         firstCam->SetNext( new CCamera( i ) );
72                         firstCam = firstCam->GetNext();
73                 }
74         }
75         firstCam = NULL;
76
77         if ( !Renderer ) {
78                 Renderer = new CRenderer;
79         }
80
81         if ( g_pCameraInspectorWnd == NULL ) {
82                 g_pCameraInspectorWnd = CreateCameraInspectorDialog();
83         }
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         return PLUGIN_NAME;
94 }
95
96 const char* QERPlug_GetCommandList(){
97         return PLUGIN_COMMANDS;
98 }
99
100 void QERPlug_Dispatch( const char* p, float* vMin, float* vMax, bool bSingleBrush ){
101         if ( !strcmp( p, "New Fixed Camera" ) ) {
102                 DoNewFixedCamera();
103         }
104         else if ( !strcmp( p, "New Interpolated Camera" ) ) {
105                 DoNewInterpolatedCamera();
106         }
107         else if ( !strcmp( p, "New Spline Camera" ) ) {
108                 DoNewSplineCamera();
109         }
110         else if ( !strcmp( p, "Camera Inspector..." ) ) {
111                 DoCameraInspector();
112         }
113         else if ( !strcmp( p, "Preview Camera" ) ) {
114                 DoPreviewCamera();
115         }
116         else if ( !strcmp( p, "Load Camera..." ) ) {
117                 DoLoadCamera();
118         }
119         else if ( !strcmp( p, "About..." ) ) {
120                 g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, PLUGIN_ABOUT, "About", MB_OK, NULL );
121         }
122 }
123
124
125 // toolbar
126
127 #include "itoolbar.h"
128
129 unsigned int ToolbarButtonCount(){
130         return 1;
131 }
132
133 class CameraInspectorButton : public IToolbarButton
134 {
135 public:
136 virtual const char* getImage() const {
137         return "camera_insp.bmp";
138 }
139 virtual const char* getText() const {
140         return "Inspector";
141 }
142 virtual const char* getTooltip() const {
143         return "Camera Inspector";
144 }
145 virtual void activate() const {
146         DoCameraInspector();
147 }
148 virtual EType getType() const {
149         return eButton;
150 }
151 };
152
153 CameraInspectorButton g_camerainspectorbutton;
154
155 const IToolbarButton* GetToolbarButton( unsigned int index ){
156         return &g_camerainspectorbutton;
157 }
158
159
160 _QERFuncTable_1 g_FuncTable;
161 _QERQglTable g_QglTable;
162 _QERUITable g_UITable;
163 _QERCameraTable g_CameraTable;
164
165 // =============================================================================
166 // SYNAPSE
167
168 #include "synapse.h"
169
170 class CameraSynapseClient : public CSynapseClient
171 {
172 public:
173 // CSynapseClient API
174 bool RequestAPI( APIDescriptor_t *pAPI );
175 const char* GetInfo();
176
177 CameraSynapseClient() { }
178 virtual ~CameraSynapseClient() { }
179 };
180
181 CSynapseServer* g_pSynapseServer = NULL;
182 CameraSynapseClient g_SynapseClient;
183
184 #if __GNUC__ >= 4
185 #pragma GCC visibility push(default)
186 #endif
187 extern "C" CSynapseClient * SYNAPSE_DLL_EXPORT Synapse_EnumerateInterfaces( const char *version, CSynapseServer *pServer ) {
188 #if __GNUC__ >= 4
189 #pragma GCC visibility pop
190 #endif
191         if ( strcmp( version, SYNAPSE_VERSION ) ) {
192                 Syn_Printf( "ERROR: synapse API version mismatch: should be '" SYNAPSE_VERSION "', got '%s'\n", version );
193                 return NULL;
194         }
195         g_pSynapseServer = pServer;
196         g_pSynapseServer->IncRef();
197         Set_Syn_Printf( g_pSynapseServer->Get_Syn_Printf() );
198
199         g_SynapseClient.AddAPI( TOOLBAR_MAJOR, "camera", sizeof( _QERPlugToolbarTable ) );
200         g_SynapseClient.AddAPI( PLUGIN_MAJOR, "camera", sizeof( _QERPluginTable ) );
201
202         g_SynapseClient.AddAPI( RADIANT_MAJOR, NULL, sizeof( _QERFuncTable_1 ), SYN_REQUIRE, &g_FuncTable );
203         g_SynapseClient.AddAPI( UI_MAJOR, NULL, sizeof( _QERUITable ), SYN_REQUIRE, &g_UITable );
204         g_SynapseClient.AddAPI( QGL_MAJOR, NULL, sizeof( _QERQglTable ), SYN_REQUIRE, &g_QglTable );
205         g_SynapseClient.AddAPI( CAMERA_MAJOR, NULL, sizeof( _QERCameraTable ), SYN_REQUIRE, &g_CameraTable );
206
207         return &g_SynapseClient;
208 }
209
210 bool CameraSynapseClient::RequestAPI( APIDescriptor_t *pAPI ){
211         if ( !strcmp( pAPI->major_name, TOOLBAR_MAJOR ) ) {
212                 _QERPlugToolbarTable* pTable = static_cast<_QERPlugToolbarTable*>( pAPI->mpTable );
213
214                 pTable->m_pfnToolbarButtonCount = &ToolbarButtonCount;
215                 pTable->m_pfnGetToolbarButton = &GetToolbarButton;
216                 return true;
217         }
218         else if ( !strcmp( pAPI->major_name, PLUGIN_MAJOR ) ) {
219                 _QERPluginTable* pTable = static_cast<_QERPluginTable*>( pAPI->mpTable );
220
221                 pTable->m_pfnQERPlug_Init = QERPlug_Init;
222                 pTable->m_pfnQERPlug_GetName = QERPlug_GetName;
223                 pTable->m_pfnQERPlug_GetCommandList = QERPlug_GetCommandList;
224                 pTable->m_pfnQERPlug_Dispatch = QERPlug_Dispatch;
225                 return true;
226         }
227
228         Syn_Printf( "ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo() );
229         return false;
230 }
231
232 #include "version.h"
233
234 const char* CameraSynapseClient::GetInfo(){
235         return "Camera plugin v1.0 - Arnout van Meer - built " __DATE__ " " RADIANT_VERSION;
236 }
237
238
239
240 //
241 // CCamera
242 //
243 CCamera *AllocCam() {
244         if ( !firstFreeCam ) {
245                 return( NULL );
246         }
247
248         CCamera *cam = firstFreeCam;
249         firstFreeCam = firstFreeCam->GetNext();
250         cam->Init();
251         if ( firstCam ) {
252                 cam->SetNext( firstCam );
253                 firstCam->SetPrev( cam );
254         }
255         firstCam = cam;
256
257         return( cam );
258 }
259
260 void FreeCam( CCamera *cam ) {
261         if ( cam->GetPrev() ) {
262                 if ( cam->GetNext() ) {
263                         cam->GetPrev()->SetNext( cam->GetNext() );
264                         cam->GetNext()->SetPrev( cam->GetPrev() );
265                 }
266                 else {
267                         cam->GetPrev()->SetNext( NULL );
268                 }
269         }
270         else if ( cam->GetNext() ) {
271                 cam->GetNext()->SetPrev( NULL );
272                 firstCam = cam->GetNext();
273         }
274         else {
275                 firstCam = NULL;
276         }
277
278         cam->GetCam()->clear();
279         cam->Init();
280
281         if ( firstFreeCam ) {
282                 cam->SetNext( firstFreeCam );
283         }
284         firstFreeCam = cam;
285 }
286
287 void SetCurrentCam( CCamera *cam ) {
288         currentCam = cam;
289 }
290
291 CCamera *GetCurrentCam() {
292         return( currentCam );
293 }