doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
guied.cpp
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 
29 #include "../../idlib/precompiled.h"
30 #pragma hdrstop
31 
32 #include "../../renderer/tr_local.h"
33 #include "../../sys/win32/win_local.h"
34 #include <io.h>
35 
36 #include "../../ui/DeviceContext.h"
37 #include "../../sys/win32/rc/guied_resource.h"
38 
39 #include "GEApp.h"
40 
42 
43 /*
44 ================
45 GUIEditorInit
46 
47 Start the gui editor
48 ================
49 */
50 void GUIEditorInit( void )
51 {
52  gApp.Initialize();
53 }
54 
55 /*
56 ================
57 GUIEditorShutdown
58 ================
59 */
60 void GUIEditorShutdown( void ) {
61 }
62 
63 /*
64 ================
65 GUIEditorHandleMessage
66 
67 Handle translator messages
68 ================
69 */
70 bool GUIEditorHandleMessage ( void *msg )
71 {
72  if ( !gApp.IsActive ( ) )
73  {
74  return false;
75  }
76 
77  return gApp.TranslateAccelerator( reinterpret_cast<LPMSG>(msg) );
78 }
79 
80 /*
81 ================
82 GUIEditorRun
83 
84 Run a frame
85 ================
86 */
87 void GUIEditorRun()
88 {
89  MSG msg;
90 
91  // pump the message loop
92  while (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
93  {
94  if ( !GetMessage (&msg, NULL, 0, 0) )
95  {
96  common->Quit();
97  }
98 
99  // save the msg time, because wndprocs don't have access to the timestamp
100  if ( win32.sysMsgTime && win32.sysMsgTime > (int)msg.time )
101  {
102  }
103  else
104  {
105  win32.sysMsgTime = msg.time;
106  }
107 
108  if ( gApp.TranslateAccelerator ( &msg ) )
109  {
110  continue;
111  }
112 
113  TranslateMessage (&msg);
114  DispatchMessage (&msg);
115  }
116 
117  gApp.RunFrame ( );
118 
119  // The GUI editor runs too hot so we need to slow it down a bit.
120  Sleep ( 1 );
121 }
122 
123 /*
124 ================
125 StringFromVec4
126 
127 Returns a clean string version of the given vec4
128 ================
129 */
130 const char *StringFromVec4 ( idVec4& v )
131 {
132  return va( "%s,%s,%s,%s",
133  idStr::FloatArrayToString( &v[0], 1, 8 ),
134  idStr::FloatArrayToString( &v[1], 1, 8 ),
135  idStr::FloatArrayToString( &v[2], 1, 8 ),
136  idStr::FloatArrayToString( &v[3], 1, 8 ) );
137 }
138 
139 /*
140 ================
141 IsExpression
142 
143 Returns true if the given string is an expression
144 ================
145 */
146 bool IsExpression ( const char* s )
147 {
148  idParser src( s, strlen ( s ), "",
153 
154  idToken token;
155  bool needComma = false;
156  bool needNumber = false;
157  while ( src.ReadToken ( &token ) )
158  {
159  switch ( token.type )
160  {
161  case TT_NUMBER:
162  needComma = true;
163  needNumber = false;
164  break;
165 
166  case TT_PUNCTUATION:
167  if ( needNumber )
168  {
169  return true;
170  }
171  if ( token[0] == ',' )
172  {
173  if ( !needComma )
174  {
175  return true;
176  }
177 
178  needComma = false;
179  break;
180  }
181 
182  if ( needComma )
183  {
184  return true;
185  }
186 
187  if ( token[0] == '-' )
188  {
189  needNumber = true;
190  }
191  break;
192 
193  default:
194  return true;
195  }
196  }
197 
198  return false;
199 }
int type
Definition: Token.h:77
Definition: GEApp.h:73
void GUIEditorInit(void)
Definition: guied.cpp:50
const GLdouble * v
Definition: glext.h:2936
rvGEApp gApp
Definition: guied.cpp:41
static const char * FloatArrayToString(const float *array, const int length, const int precision)
Definition: Str.cpp:418
bool IsExpression(const char *s)
Definition: guied.cpp:146
bool IsActive(void)
Definition: GEApp.h:143
bool TranslateAccelerator(LPMSG msg)
Definition: GEApp.cpp:196
Definition: Token.h:71
GLdouble s
Definition: glext.h:2935
GLuint src
Definition: glext.h:5390
void RunFrame(void)
Definition: GEApp.cpp:238
void Sleep(const int time)
#define TT_NUMBER
Definition: Token.h:43
int sysMsgTime
Definition: win_local.h:115
void GUIEditorRun()
Definition: guied.cpp:87
bool Initialize(void)
Definition: GEApp.cpp:78
int ReadToken(idToken *token)
Definition: Parser.cpp:2338
Definition: Vector.h:808
idCommon * common
Definition: Common.cpp:206
const char * StringFromVec4(idVec4 &v)
Definition: guied.cpp:130
#define NULL
Definition: Lib.h:88
#define TT_PUNCTUATION
Definition: Token.h:45
bool GUIEditorHandleMessage(void *msg)
Definition: guied.cpp:70
virtual void Quit(void)=0
char * va(const char *fmt,...)
Definition: Str.cpp:1568
Win32Vars_t win32
Definition: win_main.cpp:65
void GUIEditorShutdown(void)
Definition: guied.cpp:60