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