2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
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.
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.
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
23 Camera plugin for GtkRadiant
24 Copyright (C) 2002 Splash Damage Ltd.
30 CRenderer *Renderer = NULL;
33 CListener *Listener = NULL;
36 static const char *PLUGIN_NAME = "Camera";
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";
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
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.";
61 const char *QERPlug_Init(void *hApp, void *pMainWidget)
63 g_pRadiantWnd = (GtkWidget *) pMainWidget;
66 for (int i = 0; i < MAX_CAMERAS; i++) {
68 firstFreeCam = new CCamera(i);
69 firstCam = firstFreeCam;
71 firstCam->SetNext(new CCamera(i));
72 firstCam = firstCam->GetNext();
78 Renderer = new CRenderer;
81 if (g_pCameraInspectorWnd == NULL) {
82 g_pCameraInspectorWnd = CreateCameraInspectorDialog();
85 GetFileTypeRegistry()->addType("camera", "", filetype_t("Camera file", "*.camera"));
87 return "Camera for NetRadiant";
90 const char *QERPlug_GetName()
95 const char *QERPlug_GetCommandList()
97 return PLUGIN_COMMANDS;
100 void QERPlug_Dispatch(const char *p, float *vMin, float *vMax, bool bSingleBrush)
102 if (!strcmp(p, "New Fixed Camera")) {
104 } else if (!strcmp(p, "New Interpolated Camera")) {
105 DoNewInterpolatedCamera();
106 } else if (!strcmp(p, "New Spline Camera")) {
108 } else if (!strcmp(p, "Camera Inspector...")) {
110 } else if (!strcmp(p, "Preview Camera")) {
112 } else if (!strcmp(p, "Load Camera...")) {
114 } else if (!strcmp(p, "About...")) {
115 g_FuncTable.m_pfnMessageBox((GtkWidget *) g_pRadiantWnd, PLUGIN_ABOUT, "About", eMB_OK);
122 #include "itoolbar.h"
124 unsigned int ToolbarButtonCount()
129 class CameraInspectorButton : public IToolbarButton {
131 virtual const char *getImage() const
133 return "camera_insp.jpg";
136 virtual const char *getText() const
141 virtual const char *getTooltip() const
143 return "Camera Inspector";
146 virtual void activate() const
151 virtual EType getType() const
157 CameraInspectorButton g_camerainspectorbutton;
159 const IToolbarButton *GetToolbarButton(unsigned int index)
161 return &g_camerainspectorbutton;
165 _QERFuncTable_1 g_FuncTable;
166 _QERQglTable g_QglTable;
167 _QERUITable g_UITable;
168 _QERCameraTable g_CameraTable;
170 // =============================================================================
175 class CameraSynapseClient : public CSynapseClient {
177 // CSynapseClient API
178 bool RequestAPI(APIDescriptor_t *pAPI);
180 const char *GetInfo();
182 CameraSynapseClient()
185 virtual ~CameraSynapseClient()
189 CSynapseServer *g_pSynapseServer = NULL;
190 CameraSynapseClient g_SynapseClient;
192 extern "C" CSynapseClient *SYNAPSE_DLL_EXPORT
194 Synapse_EnumerateInterfaces(const char *version, CSynapseServer *pServer)
196 if (strcmp(version, SYNAPSE_VERSION)) {
197 Syn_Printf("ERROR: synapse API version mismatch: should be '"
199 "', got '%s'\n", version );
202 g_pSynapseServer = pServer;
203 g_pSynapseServer->IncRef();
204 Set_Syn_Printf(g_pSynapseServer->Get_Syn_Printf());
206 g_SynapseClient.AddAPI(TOOLBAR_MAJOR, "camera", sizeof(_QERPlugToolbarTable));
207 g_SynapseClient.AddAPI(PLUGIN_MAJOR, "camera", sizeof(_QERPluginTable));
209 g_SynapseClient.AddAPI(RADIANT_MAJOR, NULL, sizeof(_QERFuncTable_1), SYN_REQUIRE, &g_FuncTable);
210 g_SynapseClient.AddAPI(UI_MAJOR, NULL, sizeof(_QERUITable), SYN_REQUIRE, &g_UITable);
211 g_SynapseClient.AddAPI(QGL_MAJOR, NULL, sizeof(_QERQglTable), SYN_REQUIRE, &g_QglTable);
212 g_SynapseClient.AddAPI(CAMERA_MAJOR, NULL, sizeof(_QERCameraTable), SYN_REQUIRE, &g_CameraTable);
214 return &g_SynapseClient;
217 bool CameraSynapseClient::RequestAPI(APIDescriptor_t *pAPI)
219 if (!strcmp(pAPI->major_name, TOOLBAR_MAJOR)) {
220 _QERPlugToolbarTable *pTable = static_cast<_QERPlugToolbarTable *>( pAPI->mpTable );
222 pTable->m_pfnToolbarButtonCount = &ToolbarButtonCount;
223 pTable->m_pfnGetToolbarButton = &GetToolbarButton;
225 } else if (!strcmp(pAPI->major_name, PLUGIN_MAJOR)) {
226 _QERPluginTable *pTable = static_cast<_QERPluginTable *>( pAPI->mpTable );
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;
235 Syn_Printf("ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo());
241 const char *CameraSynapseClient::GetInfo()
243 return "Camera plugin v1.0 - Arnout van Meer - built " __DATE__ " "
257 CCamera *cam = firstFreeCam;
258 firstFreeCam = firstFreeCam->GetNext();
261 cam->SetNext(firstCam);
262 firstCam->SetPrev(cam);
269 void FreeCam(CCamera *cam)
271 if (cam->GetPrev()) {
272 if (cam->GetNext()) {
273 cam->GetPrev()->SetNext(cam->GetNext());
274 cam->GetNext()->SetPrev(cam->GetPrev());
276 cam->GetPrev()->SetNext(NULL);
278 } else if (cam->GetNext()) {
279 cam->GetNext()->SetPrev(NULL);
280 firstCam = cam->GetNext();
285 cam->GetCam()->clear();
289 cam->SetNext(firstFreeCam);
294 void SetCurrentCam(CCamera *cam)
299 CCamera *GetCurrentCam()