2 Copyright (C) 1999-2007 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
45 ============================================================================
49 ============================================================================
52 static int cursorx, cursory;
59 void Z_MouseDown( int x, int y, int buttons ){
60 vec3_t org, dir, vup, vright;
63 Sys_GetCursorPos( &cursorx, &cursory );
65 vup[0] = 0; vup[1] = 0; vup[2] = 1 / z.scale;
67 VectorCopy( z.origin, org );
68 org[2] += ( y - ( z.height / 2 ) ) / z.scale;
69 org[1] = g_MinWorldCoord;
71 b = selected_brushes.next;
72 if ( b != &selected_brushes ) {
73 org[0] = ( b->mins[0] + b->maxs[0] ) / 2;
76 dir[0] = 0; dir[1] = 1; dir[2] = 0;
78 vright[0] = 0; vright[1] = 0; vright[2] = 0;
80 // LBUTTON = manipulate selection
81 // shift-LBUTTON = select
82 // middle button = grab texture
83 // ctrl-middle button = set entire brush to texture
84 // ctrl-shift-middle button = set single face to texture
86 int nMouseButton = g_PrefsDlg.m_nMouseButtons == 2 ? MK_RBUTTON : MK_MBUTTON;
87 if ( ( buttons == MK_LBUTTON )
88 || ( buttons == ( MK_LBUTTON | MK_SHIFT ) )
89 || ( buttons == MK_MBUTTON )
90 // || (buttons == (MK_MBUTTON|MK_CONTROL))
91 || ( buttons == ( nMouseButton | MK_SHIFT | MK_CONTROL ) ) ) {
92 Drag_Begin( x, y, buttons,
98 // control mbutton = move camera
99 if ( ( buttons == ( MK_CONTROL | nMouseButton ) ) || ( buttons == ( MK_CONTROL | MK_LBUTTON ) ) ) {
100 g_pParentWnd->GetCamWnd()->Camera()->origin[2] = org[2] ;
101 Sys_UpdateWindows( W_CAMERA | W_XY_OVERLAY | W_Z );
112 void Z_MouseUp( int x, int y, int buttons ){
121 void Z_MouseMoved( int x, int y, int buttons ){
125 if ( buttons == MK_LBUTTON ) {
126 Drag_MouseMoved( x, y, buttons );
127 Sys_UpdateWindows( W_Z | W_CAMERA_IFON | W_XY );
130 // rbutton = drag z origin
131 if ( buttons == MK_RBUTTON ) {
132 Sys_GetCursorPos( &x, &y );
133 if ( y != cursory ) {
134 z.origin[2] += y - cursory;
135 Sys_SetCursorPos( cursorx, cursory );
136 Sys_UpdateWindows( W_Z );
140 // control mbutton = move camera
141 int nMouseButton = g_PrefsDlg.m_nMouseButtons == 2 ? MK_RBUTTON : MK_MBUTTON;
142 if ( ( buttons == ( MK_CONTROL | nMouseButton ) ) || ( buttons == ( MK_CONTROL | MK_LBUTTON ) ) ) {
143 g_pParentWnd->GetCamWnd()->Camera()->origin[2] = ( y - ( z.height / 2 ) ) / z.scale;
144 Sys_UpdateWindows( W_CAMERA | W_XY_OVERLAY | W_Z );
151 ============================================================================
155 ============================================================================
164 void Z_DrawGrid( void ){
169 w = ( z.width / 2 / z.scale );
170 h = ( z.height / 2 / z.scale );
172 zb = z.origin[2] - h;
173 if ( zb < region_mins[2] ) {
176 zb = 64 * floor( zb / 64 );
178 ze = z.origin[2] + h;
179 if ( ze > region_maxs[2] ) {
182 ze = 64 * ceil( ze / 64 );
186 qglColor3fv( g_qeglobals.d_savedinfo.colors[COLOR_GRIDMAJOR] );
188 if ( g_qeglobals.d_showgrid ) {
189 if ( g_qeglobals.d_gridsize < 128 ) {
190 qglBegin( GL_LINES );
192 qglVertex2f( 0, zb );
193 qglVertex2f( 0, ze );
195 for ( zz = zb ; zz < ze ; zz += 64 )
197 qglVertex2f( -w, zz );
198 qglVertex2f( w, zz );
205 qglBegin( GL_LINES );
207 qglVertex2f( 0, zb );
208 qglVertex2f( 0, ze );
210 for ( zz = zb ; zz < ze ; zz += 64 )
212 // d_gridsize >= 128 .. it's an int for sure
213 if ( ( (int)zz & ( (int)g_qeglobals.d_gridsize - 1 ) ) != 0 ) {
217 qglVertex2f( -w, zz );
218 qglVertex2f( w, zz );
226 if ( g_qeglobals.d_showgrid && g_qeglobals.d_gridsize * z.scale >= 4 &&
227 g_qeglobals.d_savedinfo.colors[COLOR_GRIDMINOR] != g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK] ) {
228 qglColor3fv( g_qeglobals.d_savedinfo.colors[COLOR_GRIDMINOR] );
230 qglBegin( GL_LINES );
231 for ( zz = zb ; zz < ze ; zz += g_qeglobals.d_gridsize )
233 if ( !( (int)zz & 63 ) ) {
236 qglVertex2f( -w, zz );
237 qglVertex2f( w, zz );
242 // draw coordinate text if needed
244 if ( g_qeglobals.d_savedinfo.show_coordinates ) {
245 qglColor3fv( g_qeglobals.d_savedinfo.colors[COLOR_GRIDTEXT] );
247 int step = (int)( g_qeglobals.d_gridsize > 64 ? g_qeglobals.d_gridsize : 64 );
248 zb = z.origin[2] - h;
249 if ( zb < region_mins[2] ) {
252 zb = step * floor( zb / step );
254 for ( zz = zb ; zz < ze ; zz += step )
256 qglRasterPos2f( -w + ( 1 / z.scale ), zz );
257 sprintf( text, "%i",(int)zz );
258 gtk_glwidget_print_string( text );
263 void ZDrawCameraIcon( void ){
265 float xCam = z.width / 4 / z.scale, gizmo = 8 / z.scale, height = 48 / z.scale;
268 y = g_pParentWnd->GetCamWnd()->Camera()->origin[2];
270 qglColor3f( 0.0, 0.0, 1.0 );
271 qglBegin( GL_LINE_STRIP );
272 qglVertex3f( x - xCam,y,0 );
273 qglVertex3f( x,y + gizmo,0 );
274 qglVertex3f( x + xCam,y,0 );
275 qglVertex3f( x,y - gizmo,0 );
276 qglVertex3f( x - xCam,y,0 );
277 qglVertex3f( x + xCam,y,0 );
278 qglVertex3f( x + xCam,y - height,0 );
279 qglVertex3f( x - xCam,y - height,0 );
280 qglVertex3f( x - xCam,y,0 );
285 GLbitfield glbitClear = GL_COLOR_BUFFER_BIT; //HACK
294 CheckWatchit( "Z_Draw" );
301 vec3_t org_top, org_bottom, dir_up, dir_down;
302 int xCam = z.width / 3;
304 if ( !active_brushes.next ) {
305 return; // not valid yet
309 start = Sys_DoubleTime();
315 qglViewport( 0, 0, z.width, z.height );
318 g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK][0],
319 g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK][1],
320 g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK][2],
324 /* When not using hw acceleration, gl will fault if we clear the depth
325 buffer bit on the first pass. The hack fix is to set the GL_DEPTH_BUFFER_BIT
326 only after Z_Draw() has been called once. Yeah, right. */
327 qglClear( glbitClear );
328 glbitClear |= GL_DEPTH_BUFFER_BIT;
329 qglMatrixMode( GL_PROJECTION );
332 w = z.width / 2 / z.scale;
333 h = z.height / 2 / z.scale;
334 qglOrtho( -w, w, z.origin[2] - h, z.origin[2] + h, -8, 8 );
336 qglDisable( GL_TEXTURE_2D );
337 qglDisable( GL_TEXTURE_1D );
338 qglDisable( GL_DEPTH_TEST );
339 qglDisable( GL_BLEND );
351 qglDisable( GL_CULL_FACE );
353 qglShadeModel( GL_FLAT );
355 qglPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
357 qglDisable( GL_TEXTURE_2D );
358 qglDisable( GL_BLEND );
359 qglDisable( GL_DEPTH_TEST );
362 // draw filled interiors and edges
363 dir_up[0] = 0 ; dir_up[1] = 0; dir_up[2] = 1;
364 dir_down[0] = 0 ; dir_down[1] = 0; dir_down[2] = -1;
365 VectorCopy( z.origin, org_top );
366 org_top[2] = g_MaxWorldCoord;
367 VectorCopy( z.origin, org_bottom );
368 org_bottom[2] = g_MinWorldCoord;
370 for ( brush = active_brushes.next ; brush != &active_brushes ; brush = brush->next )
372 if ( brush->bFiltered ) {
376 if ( brush->mins[0] >= z.origin[0]
377 || brush->maxs[0] <= z.origin[0]
378 || brush->mins[1] >= z.origin[1]
379 || brush->maxs[1] <= z.origin[1] ) {
383 if ( !Brush_Ray( org_top, dir_down, brush, &top ) ) {
386 top = org_top[2] - top;
387 if ( !Brush_Ray( org_bottom, dir_up, brush, &bottom ) ) {
390 bottom = org_bottom[2] + bottom;
392 q = brush->brush_faces->pShader->getTexture();
393 qglColor3f( q->color[0], q->color[1], q->color[2] );
394 qglBegin( GL_QUADS );
395 qglVertex2f( -xCam, bottom );
396 qglVertex2f( xCam, bottom );
397 qglVertex2f( xCam, top );
398 qglVertex2f( -xCam, top );
402 qglBegin( GL_LINE_LOOP );
403 qglVertex2f( -xCam, bottom );
404 qglVertex2f( xCam, bottom );
405 qglVertex2f( xCam, top );
406 qglVertex2f( -xCam, top );
411 // now draw selected brushes
413 for ( brush = selected_brushes.next ; brush != &selected_brushes ; brush = brush->next )
415 if ( !( brush->mins[0] >= z.origin[0]
416 || brush->maxs[0] <= z.origin[0]
417 || brush->mins[1] >= z.origin[1]
418 || brush->maxs[1] <= z.origin[1] ) ) {
419 if ( Brush_Ray( org_top, dir_down, brush, &top ) ) {
420 top = org_top[2] - top;
421 if ( Brush_Ray( org_bottom, dir_up, brush, &bottom ) ) {
422 bottom = org_bottom[2] + bottom;
424 q = brush->brush_faces->pShader->getTexture();
425 qglColor3f( q->color[0], q->color[1], q->color[2] );
426 qglBegin( GL_QUADS );
427 qglVertex2f( -xCam, bottom );
428 qglVertex2f( xCam, bottom );
429 qglVertex2f( xCam, top );
430 qglVertex2f( -xCam, top );
436 qglColor3fv( g_qeglobals.d_savedinfo.colors[COLOR_SELBRUSHES] );
437 qglBegin( GL_LINE_LOOP );
438 qglVertex2f( -xCam, brush->mins[2] );
439 qglVertex2f( xCam, brush->mins[2] );
440 qglVertex2f( xCam, brush->maxs[2] );
441 qglVertex2f( -xCam, brush->maxs[2] );
449 QE_CheckOpenGLForErrors();
452 end = Sys_DoubleTime();
453 Sys_Printf( "z: %i ms\n", (int)( 1000 * ( end - start ) ) );