]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - contrib/camera/camera.cpp
cmake: drop useless version.h
[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 ui::Window g_pRadiantWnd{ui::null};
43 ui::Window g_pCameraInspectorWnd{ui::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 =
53                         PLUGIN_NAME " " PLUGIN_VERSION " for "
54                         RADIANT_NAME " " RADIANT_VERSION "\n\n"
55                         "Written by Arnout van Meer <rr2do2@splashdamage.com)\n\n"
56                         "Written by Geoffrey DeWan <gdewan@prairienet.org>\n\n"
57                         "This product contains software technology\n"
58                         "from id Software, Inc. ('id Technology').\n"
59                         "id Technology (c) 2001, 2002 id Software, Inc.\n\n";
60                         "Built against "
61                         RADIANT_NAME " " RADIANT_VERSION "\n"
62                         __DATE__;
63
64 #include "iplugin.h"
65
66 const char* QERPlug_Init( void* hApp, void* pMainWidget ){
67         g_pRadiantWnd = (GtkWidget*)pMainWidget;
68
69         // initialize cams
70         for ( int i = 0; i < MAX_CAMERAS; i++ ) {
71                 if ( i == 0 ) {
72                         firstFreeCam = new CCamera( i );
73                         firstCam = firstFreeCam;
74                 }
75                 else {
76                         firstCam->SetNext( new CCamera( i ) );
77                         firstCam = firstCam->GetNext();
78                 }
79         }
80         firstCam = NULL;
81
82         if ( !Renderer ) {
83                 Renderer = new CRenderer;
84         }
85
86         if ( g_pCameraInspectorWnd == NULL ) {
87                 g_pCameraInspectorWnd = CreateCameraInspectorDialog();
88         }
89
90         GetFileTypeRegistry()->addType( "camera", "", filetype_t( "Camera file", "*.camera" ) );
91
92         return "Camera for " RADIANT_NAME;
93 }
94
95 const char* QERPlug_GetName(){
96         return PLUGIN_NAME;
97 }
98
99 const char* QERPlug_GetCommandList(){
100         return PLUGIN_COMMANDS;
101 }
102
103 void QERPlug_Dispatch( const char* p, float* vMin, float* vMax, bool bSingleBrush ){
104         if ( !strcmp( p, "New Fixed Camera" ) ) {
105                 DoNewFixedCamera();
106         }
107         else if ( !strcmp( p, "New Interpolated Camera" ) ) {
108                 DoNewInterpolatedCamera();
109         }
110         else if ( !strcmp( p, "New Spline Camera" ) ) {
111                 DoNewSplineCamera();
112         }
113         else if ( !strcmp( p, "Camera Inspector..." ) ) {
114                 DoCameraInspector();
115         }
116         else if ( !strcmp( p, "Preview Camera" ) ) {
117                 DoPreviewCamera();
118         }
119         else if ( !strcmp( p, "Load Camera..." ) ) {
120                 DoLoadCamera();
121         }
122         else if ( !strcmp( p, "About..." ) ) {
123                 g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, PLUGIN_ABOUT, "About", eMB_OK );
124         }
125 }
126
127
128 // toolbar
129
130 #include "itoolbar.h"
131
132 unsigned int ToolbarButtonCount(){
133         return 1;
134 }
135
136 class CameraInspectorButton : public IToolbarButton
137 {
138 public:
139 virtual const char* getImage() const {
140         return "camera_insp.jpg";
141 }
142 virtual const char* getText() const {
143         return "Inspector";
144 }
145 virtual const char* getTooltip() const {
146         return "Camera Inspector";
147 }
148 virtual void activate() const {
149         DoCameraInspector();
150 }
151 virtual EType getType() const {
152         return eButton;
153 }
154 };
155
156 CameraInspectorButton g_camerainspectorbutton;
157
158 const IToolbarButton* GetToolbarButton( unsigned int index ){
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 extern "C" CSynapseClient * SYNAPSE_DLL_EXPORT Synapse_EnumerateInterfaces( const char *version, CSynapseServer *pServer ){
188         if ( strcmp( version, SYNAPSE_VERSION ) ) {
189                 Syn_Printf( "ERROR: synapse API version mismatch: should be '" SYNAPSE_VERSION "', got '%s'\n", version );
190                 return NULL;
191         }
192         g_pSynapseServer = pServer;
193         g_pSynapseServer->IncRef();
194         Set_Syn_Printf( g_pSynapseServer->Get_Syn_Printf() );
195
196         g_SynapseClient.AddAPI( TOOLBAR_MAJOR, "camera", sizeof( _QERPlugToolbarTable ) );
197         g_SynapseClient.AddAPI( PLUGIN_MAJOR, "camera", sizeof( _QERPluginTable ) );
198
199         g_SynapseClient.AddAPI( RADIANT_MAJOR, NULL, sizeof( _QERFuncTable_1 ), SYN_REQUIRE, &g_FuncTable );
200         g_SynapseClient.AddAPI( UI_MAJOR, NULL, sizeof( _QERUITable ), SYN_REQUIRE, &g_UITable );
201         g_SynapseClient.AddAPI( QGL_MAJOR, NULL, sizeof( _QERQglTable ), SYN_REQUIRE, &g_QglTable );
202         g_SynapseClient.AddAPI( CAMERA_MAJOR, NULL, sizeof( _QERCameraTable ), SYN_REQUIRE, &g_CameraTable );
203
204         return &g_SynapseClient;
205 }
206
207 bool CameraSynapseClient::RequestAPI( APIDescriptor_t *pAPI ){
208         if ( !strcmp( pAPI->major_name, TOOLBAR_MAJOR ) ) {
209                 _QERPlugToolbarTable* pTable = static_cast<_QERPlugToolbarTable*>( pAPI->mpTable );
210
211                 pTable->m_pfnToolbarButtonCount = &ToolbarButtonCount;
212                 pTable->m_pfnGetToolbarButton = &GetToolbarButton;
213                 return true;
214         }
215         else if ( !strcmp( pAPI->major_name, PLUGIN_MAJOR ) ) {
216                 _QERPluginTable* pTable = static_cast<_QERPluginTable*>( pAPI->mpTable );
217
218                 pTable->m_pfnQERPlug_Init = QERPlug_Init;
219                 pTable->m_pfnQERPlug_GetName = QERPlug_GetName;
220                 pTable->m_pfnQERPlug_GetCommandList = QERPlug_GetCommandList;
221                 pTable->m_pfnQERPlug_Dispatch = QERPlug_Dispatch;
222                 return true;
223         }
224
225         Syn_Printf( "ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo() );
226         return false;
227 }
228
229 const char* CameraSynapseClient::GetInfo(){
230         return "Camera plugin v1.0 - Arnout van Meer - built " __DATE__ " " RADIANT_VERSION;
231 }
232
233
234
235 //
236 // CCamera
237 //
238 CCamera *AllocCam() {
239         if ( !firstFreeCam ) {
240                 return( NULL );
241         }
242
243         CCamera *cam = firstFreeCam;
244         firstFreeCam = firstFreeCam->GetNext();
245         cam->Init();
246         if ( firstCam ) {
247                 cam->SetNext( firstCam );
248                 firstCam->SetPrev( cam );
249         }
250         firstCam = cam;
251
252         return( cam );
253 }
254
255 void FreeCam( CCamera *cam ) {
256         if ( cam->GetPrev() ) {
257                 if ( cam->GetNext() ) {
258                         cam->GetPrev()->SetNext( cam->GetNext() );
259                         cam->GetNext()->SetPrev( cam->GetPrev() );
260                 }
261                 else {
262                         cam->GetPrev()->SetNext( NULL );
263                 }
264         }
265         else if ( cam->GetNext() ) {
266                 cam->GetNext()->SetPrev( NULL );
267                 firstCam = cam->GetNext();
268         }
269         else {
270                 firstCam = NULL;
271         }
272
273         cam->GetCam()->clear();
274         cam->Init();
275
276         if ( firstFreeCam ) {
277                 cam->SetNext( firstFreeCam );
278         }
279         firstFreeCam = cam;
280 }
281
282 void SetCurrentCam( CCamera *cam ) {
283         currentCam = cam;
284 }
285
286 CCamera *GetCurrentCam() {
287         return( currentCam );
288 }