2 PrtView plugin for GtkRadiant
3 Copyright (C) 2001 Geoffrey Dewan, Loki software and qeradiant.com
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <uilib/uilib.h>
27 #include "profile/profile.h"
29 #include "qerplugin.h"
30 #include "iscenegraph.h"
31 #include "iglrender.h"
33 #include "stream/stringstream.h"
36 #include "AboutDialog.h"
37 #include "ConfigDialog.h"
38 #include "LoadPortalFileDialog.h"
40 #define Q3R_CMD_SPLITTER "-"
41 #define Q3R_CMD_ABOUT "About Portal Viewer"
42 #define Q3R_CMD_LOAD "Load .prt file"
43 #define Q3R_CMD_RELEASE "Unload .prt file"
44 #define Q3R_CMD_SHOW_3D "Toggle portals (3D)"
45 #define Q3R_CMD_SHOW_2D "Toggle portals (2D)"
46 #define Q3R_CMD_OPTIONS "Configure Portal Viewer"
50 /////////////////////////////////////////////////////////////////////////////
51 // CPrtViewApp construction
53 const char *RENDER_2D = "Render2D";
54 const char *WIDTH_2D = "Width2D";
55 const char *AA_2D = "AntiAlias2D";
56 const char *COLOR_2D = "Color2D";
58 const char *RENDER_3D = "Render3D";
59 const char *WIDTH_3D = "Width3D";
60 const char *AA_3D = "AntiAlias3D";
61 const char *COLOR_3D = "Color3D";
62 const char *COLOR_FOG = "ColorFog";
63 const char *FOG = "Fog";
64 const char *ZBUFFER = "ZBuffer";
65 const char *POLYGON = "Polygons";
66 const char *LINE = "Lines";
67 const char *TRANS_3D = "Transparency";
68 const char *CLIP_RANGE = "ClipRange";
69 const char *CLIP = "Clip";
72 void PrtView_construct(){
73 StringOutputStream tmp( 64 );
74 tmp << GlobalRadiant().getSettingsPath() << "prtview.ini";
77 portals.show_2d = INIGetInt( RENDER_2D, FALSE ) ? true : false;
78 portals.aa_2d = INIGetInt( AA_2D, FALSE ) ? true : false;
79 portals.width_2d = (float)INIGetInt( WIDTH_2D, 10 );
80 portals.color_2d = (PackedColour)INIGetInt( COLOR_2D, RGB( 0, 0, 255 ) ) & 0xFFFFFF;
82 if ( portals.width_2d > 40.0f ) {
83 portals.width_2d = 40.0f;
85 else if ( portals.width_2d < 2.0f ) {
86 portals.width_2d = 2.0f;
89 portals.show_3d = INIGetInt( RENDER_3D, TRUE ) ? true : false;
91 portals.zbuffer = INIGetInt( ZBUFFER, 1 );
92 portals.fog = INIGetInt( FOG, FALSE ) ? true : false;
93 portals.polygons = INIGetInt( POLYGON, TRUE );
94 portals.lines = INIGetInt( LINE, TRUE );
95 portals.aa_3d = INIGetInt( AA_3D, FALSE ) ? true : false;
96 portals.width_3d = (float)INIGetInt( WIDTH_3D, 4 );
97 portals.color_3d = (PackedColour)INIGetInt( COLOR_3D, RGB( 255, 255, 0 ) ) & 0xFFFFFF;
98 portals.color_fog = (PackedColour)INIGetInt( COLOR_FOG, RGB( 127, 127, 127 ) ) & 0xFFFFFF;
99 portals.trans_3d = (float)INIGetInt( TRANS_3D, 50 );
100 portals.clip = INIGetInt( CLIP, FALSE ) ? true : false;
101 portals.clip_range = (float)INIGetInt( CLIP_RANGE, 16 );
103 if ( portals.clip_range < 1 ) {
104 portals.clip_range = 1;
106 else if ( portals.clip_range > 128 ) {
107 portals.clip_range = 128;
110 if ( portals.zbuffer < 0 ) {
113 else if ( portals.zbuffer > 2 ) {
117 if ( portals.width_3d > 40.0f ) {
118 portals.width_3d = 40.0f;
120 else if ( portals.width_3d < 2.0f ) {
121 portals.width_3d = 2.0f;
124 if ( portals.trans_3d > 100.0f ) {
125 portals.trans_3d = 100.0f;
127 else if ( portals.trans_3d < 0.0f ) {
128 portals.trans_3d = 0.0f;
135 Portals_constructShaders();
136 GlobalShaderCache().attachRenderable( render );
139 void PrtView_destroy(){
140 GlobalShaderCache().detachRenderable( render );
141 Portals_destroyShaders();
145 INISetInt( RENDER_2D, portals.show_2d, "Draw in 2D windows" );
146 INISetInt( WIDTH_2D, (int)portals.width_2d, "Width of lines in 2D windows (in units of 1/2)" );
147 INISetInt( COLOR_2D, (int)portals.color_2d, "Color of lines in 2D windows" );
148 INISetInt( AA_2D, portals.aa_2d, "Draw lines in 2D window anti-aliased" );
150 INISetInt( ZBUFFER, portals.zbuffer, "ZBuffer level in 3D window" );
151 INISetInt( FOG, portals.fog, "Use depth cueing in 3D window" );
152 INISetInt( POLYGON, portals.polygons, "Render using polygons polygons in 3D window" );
153 INISetInt( LINE, portals.polygons, "Render using lines in 3D window" );
154 INISetInt( RENDER_3D, portals.show_3d, "Draw in 3D windows" );
155 INISetInt( WIDTH_3D, (int)portals.width_3d, "Width of lines in 3D window (in units of 1/2)" );
156 INISetInt( COLOR_3D, (int)portals.color_3d, "Color of lines/polygons in 3D window" );
157 INISetInt( COLOR_FOG, (int)portals.color_fog, "Color of distant lines/polygons in 3D window" );
158 INISetInt( AA_3D, portals.aa_3d, "Draw lines in 3D window anti-aliased" );
159 INISetInt( TRANS_3D, (int)portals.trans_3d, "Transparency in 3d view (0 = solid, 100 = invisible)" );
160 INISetInt( CLIP, portals.clip, "Cubic clipper active for portal viewer" );
161 INISetInt( CLIP_RANGE, (int)portals.clip_range, "Portal viewer cubic clip distance (in units of 64)" );
165 const char *CONFIG_SECTION = "Configuration";
167 int INIGetInt( const char *key, int def ){
170 if ( read_var( INIfn.c_str(), CONFIG_SECTION, key, value ) ) {
171 return atoi( value );
178 void INISetInt( const char *key, int val, const char *comment /* = NULL */ ){
182 sprintf( s, "%d ; %s", val, comment );
185 sprintf( s, "%d", val );
187 save_var( INIfn.c_str(), CONFIG_SECTION, key, s );
192 static const char *PLUGIN_NAME = "Portal Viewer";
193 // commands in the menu
194 static const char *PLUGIN_COMMANDS =
206 ui::Widget g_pRadiantWnd{ui::null};
208 const char* QERPlug_Init( void *hApp, void* pMainWidget ){
209 g_pRadiantWnd = ui::Window::from(pMainWidget);
210 return "Portal Viewer for Q3Radiant";
213 const char* QERPlug_GetName(){
217 const char* QERPlug_GetCommandList(){
218 return PLUGIN_COMMANDS;
222 const char* QERPlug_GetCommandTitleList(){
227 void QERPlug_Dispatch( const char* p, float* vMin, float* vMax, bool bSingleBrush ){
228 globalOutputStream() << MSG_PREFIX "Command \"" << p << "\"\n";
230 if ( !strcmp( p,Q3R_CMD_ABOUT ) ) {
233 else if ( !strcmp( p,Q3R_CMD_LOAD ) ) {
234 if ( DoLoadPortalFileDialog() == IDOK ) {
240 globalOutputStream() << MSG_PREFIX "Portal file load aborted.\n";
243 else if ( !strcmp( p,Q3R_CMD_RELEASE ) ) {
248 globalOutputStream() << MSG_PREFIX "Portals unloaded.\n";
250 else if ( !strcmp( p,Q3R_CMD_SHOW_2D ) ) {
251 portals.show_2d = !portals.show_2d;
256 if ( portals.show_2d ) {
257 globalOutputStream() << MSG_PREFIX "Portals will be rendered in 2D view.\n";
260 globalOutputStream() << MSG_PREFIX "Portals will NOT be rendered in 2D view.\n";
263 else if ( !strcmp( p,Q3R_CMD_SHOW_3D ) ) {
264 portals.show_3d = !portals.show_3d;
269 if ( portals.show_3d ) {
270 globalOutputStream() << MSG_PREFIX "Portals will be rendered in 3D view.\n";
273 globalOutputStream() << MSG_PREFIX "Portals will NOT be rendered in 3D view.\n";
276 else if ( !strcmp( p,Q3R_CMD_OPTIONS ) ) {
285 #include "modulesystem/singletonmodule.h"
287 class PrtViewPluginDependencies :
288 public GlobalSceneGraphModuleRef,
289 public GlobalRadiantModuleRef,
290 public GlobalShaderCacheModuleRef,
291 public GlobalOpenGLModuleRef,
292 public GlobalOpenGLStateLibraryModuleRef
296 class PrtViewPluginModule
298 _QERPluginTable m_plugin;
300 typedef _QERPluginTable Type;
301 STRING_CONSTANT( Name, "prtview" );
303 PrtViewPluginModule(){
304 m_plugin.m_pfnQERPlug_Init = QERPlug_Init;
305 m_plugin.m_pfnQERPlug_GetName = QERPlug_GetName;
306 m_plugin.m_pfnQERPlug_GetCommandList = QERPlug_GetCommandList;
307 m_plugin.m_pfnQERPlug_GetCommandTitleList = QERPlug_GetCommandTitleList;
308 m_plugin.m_pfnQERPlug_Dispatch = QERPlug_Dispatch;
312 ~PrtViewPluginModule(){
315 _QERPluginTable* getTable(){
320 typedef SingletonModule<PrtViewPluginModule, PrtViewPluginDependencies> SingletonPrtViewPluginModule;
322 SingletonPrtViewPluginModule g_PrtViewPluginModule;
325 extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules( ModuleServer& server ){
326 initialiseModule( server );
328 g_PrtViewPluginModule.selfRegister();