]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - contrib/bobtoolz/DTreePlanter.h
ported PrtView plugin
[xonotic/netradiant.git] / contrib / bobtoolz / DTreePlanter.h
1 /*
2 BobToolz plugin for GtkRadiant
3 Copyright (C) 2001 Gordon Biggans
4
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.
9
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.
14
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
18 */
19
20 #ifndef __DTREE_H__
21 #define __DTREE_H__
22
23
24 #define MAX_QPATH 64
25
26 typedef struct treeModel_s {
27         char name[MAX_QPATH];
28 } treeModel_t;
29
30 #define MAX_TP_MODELS 256
31
32 class DTreePlanter : public IWindowListener {
33 public:
34         virtual bool OnMouseMove(guint32 nFlags, gdouble x, gdouble y);
35         virtual bool OnLButtonDown(guint32 nFlags, gdouble x, gdouble y);
36         virtual bool OnMButtonDown(guint32 nFlags, gdouble x, gdouble y);
37         virtual bool OnRButtonDown(guint32 nFlags, gdouble x, gdouble y);
38         virtual bool OnLButtonUp(guint32 nFlags, gdouble x, gdouble y);
39         virtual bool OnMButtonUp(guint32 nFlags, gdouble x, gdouble y);
40         virtual bool OnRButtonUp(guint32 nFlags, gdouble x, gdouble y);
41         virtual bool OnKeyPressed(char *s) { return false; }
42         virtual bool Paint() { return true; }
43         virtual void Close() { }
44         
45         DTreePlanter() {
46                 m_refCount =    1;
47                 m_hooked =              false;
48                 m_XYWrapper =   NULL;
49                 m_numModels =   0;
50                 m_offset =              0;
51                 m_maxPitch =    0;
52                 m_minPitch =    0;
53                 m_maxYaw =              0;
54                 m_minYaw =              0;
55                 m_setAngles =   false;
56                 m_useScale =    false;
57                 m_autoLink =    false;
58                 m_linkNum =             0;
59
60                 Register();
61
62                 m_world.LoadSelectedBrushes();
63
64                 char buffer[256];
65                 GetFilename( buffer, "bt/tp_ent.txt" );
66
67                 FILE* file = fopen( buffer, "rb" );
68                 if(file) {
69                         fseek( file, 0, SEEK_END );
70                         int len = ftell( file );
71                         fseek( file, 0, SEEK_SET );
72
73                         if(len) {
74                                 char* buf = new char[len+1];
75                                 buf[len] = '\0';
76                                 // parser will do the cleanup, dont delete.
77
78                                 fread( buf, len, 1, file );
79
80                                 CScriptParser parser;
81                                 parser.SetScript( buf );
82
83                                 ReadConfig( &parser );
84                         }
85
86                         fclose( file );
87                 }
88         }
89
90 #define MT(t)   !stricmp( pToken, t )
91 #define GT              pToken = pScriptParser->GetToken( true )
92 #define CT              if(!*pToken) { return; }
93
94         void ReadConfig( CScriptParser* pScriptParser ) {
95                 const char* GT;
96                 CT;
97
98                 do {
99                         GT;
100                         if(*pToken == '}') {
101                                 break;
102                         }
103
104                         if(MT("model")) {
105                                 if(m_numModels >= MAX_TP_MODELS) {
106                                         return;
107                                 }
108
109                                 GT; CT;
110
111                                 strncpy( m_trees[m_numModels++].name, pToken, MAX_QPATH );
112                         } else if(MT("link")) {
113                                 GT; CT;
114
115                                 strncpy( m_linkName, pToken, MAX_QPATH );
116
117                                 m_autoLink = true;
118                         } else if(MT("entity")) {
119                                 GT; CT;
120
121                                 strncpy( m_entType, pToken, MAX_QPATH );
122                         } else if(MT("offset")) {
123                                 GT; CT;
124
125                                 m_offset = atoi(pToken);
126                         } else if(MT("pitch")) {
127                                 GT; CT;
128
129                                 m_minPitch = atoi(pToken);
130
131                                 GT; CT;
132
133                                 m_maxPitch = atoi(pToken);
134
135                                 m_setAngles = true;
136                         } else if(MT("yaw")) {
137                                 GT; CT;
138
139                                 m_minYaw = atoi(pToken);
140
141                                 GT; CT;
142
143                                 m_maxYaw = atoi(pToken);
144
145                                 m_setAngles = true;
146                         } else if(MT("scale")) {
147                                 GT; CT;
148
149                                 m_minScale = static_cast<float>(atof(pToken));
150
151                                 GT; CT;
152
153                                 m_maxScale = static_cast<float>(atof(pToken));
154
155                                 m_useScale = true;
156                         } else if(MT("numlinks")) {
157                                 GT; CT;
158
159                                 m_linkNum = atoi( pToken );
160                         }
161                 } while( true );
162         }
163
164         virtual ~DTreePlanter() {
165                 UnRegister();
166         }
167
168         virtual void IncRef() { m_refCount++; }
169         virtual void DecRef() { m_refCount--; if (m_refCount <= 0) delete this; }
170
171         void Register() {
172                 if(!m_hooked) {
173                         g_MessageTable.m_pfnHookWindow( this );
174                         m_XYWrapper = g_MessageTable.m_pfnGetXYWndWrapper();
175                         m_hooked = true;
176                 }
177         }
178
179         void UnRegister() {
180                 if(m_hooked) {
181                         g_MessageTable.m_pfnUnHookWindow( this );
182                         m_XYWrapper = NULL;
183                         m_hooked = false;
184                 }
185         }
186
187         bool FindDropPoint(vec3_t in, vec3_t out);
188         void DropEntsToGround( void );
189         void MakeChain( void );
190         void SelectChain( void );
191
192 private:
193         IXYWndWrapper*  m_XYWrapper;
194         DEntity                 m_world;
195
196         treeModel_t             m_trees[MAX_TP_MODELS];
197
198         int                             m_refCount;
199         int                             m_numModels;
200         int                             m_offset;
201         int                             m_maxPitch;
202         int                             m_minPitch;
203         int                             m_maxYaw;
204         int                             m_minYaw;
205
206         char                    m_entType[MAX_QPATH];
207         char                    m_linkName[MAX_QPATH];
208         int                             m_linkNum;
209
210         float                   m_minScale;
211         float                   m_maxScale;
212
213         bool                    m_hooked;
214         bool                    m_useScale;
215         bool                    m_setAngles;
216         bool                    m_autoLink;
217 };
218
219 #endif