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
46 ============================================================================
50 ============================================================================
53 static int cursorx, cursory;
60 void Z_MouseDown (int x, int y, int buttons)
62 vec3_t org, dir, vup, vright;
65 Sys_GetCursorPos (&cursorx, &cursory);
67 vup[0] = 0; vup[1] = 0; vup[2] = 1/z.scale;
69 VectorCopy (z.origin, org);
70 org[2] += (y - (z.height/2))/z.scale;
71 org[1] = g_MinWorldCoord;
73 b = selected_brushes.next;
74 if (b != &selected_brushes)
76 org[0] = (b->mins[0] + b->maxs[0])/2;
79 dir[0] = 0; dir[1] = 1; dir[2] = 0;
81 vright[0] = 0; vright[1] = 0; vright[2] = 0;
83 // LBUTTON = manipulate selection
84 // shift-LBUTTON = select
85 // middle button = grab texture
86 // ctrl-middle button = set entire brush to texture
87 // ctrl-shift-middle button = set single face to texture
89 int nMouseButton = g_PrefsDlg.m_nMouseButtons == 2 ? MK_RBUTTON : MK_MBUTTON;
90 if ( (buttons == MK_LBUTTON)
91 || (buttons == (MK_LBUTTON | MK_SHIFT))
92 || (buttons == MK_MBUTTON)
93 // || (buttons == (MK_MBUTTON|MK_CONTROL))
94 || (buttons == (nMouseButton|MK_SHIFT|MK_CONTROL)) )
96 Drag_Begin (x, y, buttons,
102 // control mbutton = move camera
103 if ((buttons == (MK_CONTROL|nMouseButton) ) || (buttons == (MK_CONTROL|MK_LBUTTON)))
105 g_pParentWnd->GetCamWnd()->Camera()->origin[2] = org[2] ;
106 Sys_UpdateWindows (W_CAMERA|W_XY_OVERLAY|W_Z);
117 void Z_MouseUp (int x, int y, int buttons)
127 void Z_MouseMoved (int x, int y, int buttons)
131 if (buttons == MK_LBUTTON)
133 Drag_MouseMoved (x, y, buttons);
134 Sys_UpdateWindows (W_Z|W_CAMERA_IFON|W_XY);
137 // rbutton = drag z origin
138 if (buttons == MK_RBUTTON)
140 Sys_GetCursorPos (&x, &y);
143 z.origin[2] += y-cursory;
144 Sys_SetCursorPos (cursorx, cursory);
145 Sys_UpdateWindows (W_Z);
149 // control mbutton = move camera
150 int nMouseButton = g_PrefsDlg.m_nMouseButtons == 2 ? MK_RBUTTON : MK_MBUTTON;
151 if ((buttons == (MK_CONTROL|nMouseButton) ) || (buttons == (MK_CONTROL|MK_LBUTTON)))
153 g_pParentWnd->GetCamWnd()->Camera()->origin[2] = (y - (z.height/2))/z.scale;
154 Sys_UpdateWindows (W_CAMERA|W_XY_OVERLAY|W_Z);
161 ============================================================================
165 ============================================================================
174 void Z_DrawGrid (void)
180 w = (z.width/2 / z.scale);
181 h = (z.height/2 / z.scale);
183 zb = z.origin[2] - h;
184 if (zb < region_mins[2])
186 zb = 64 * floor (zb/64);
188 ze = z.origin[2] + h;
189 if (ze > region_maxs[2])
191 ze = 64 * ceil (ze/64);
195 qglColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_GRIDMAJOR]);
197 if ( g_qeglobals.d_showgrid )
199 if (g_qeglobals.d_gridsize < 128)
206 for (zz=zb ; zz<ze ; zz+=64)
208 qglVertex2f (-w, zz);
221 for (zz=zb ; zz<ze ; zz+=64)
223 // d_gridsize >= 128 .. it's an int for sure
224 if ( ((int)zz & ((int)g_qeglobals.d_gridsize-1)) != 0 )
227 qglVertex2f (-w, zz);
236 if (g_qeglobals.d_showgrid && g_qeglobals.d_gridsize*z.scale >= 4 &&
237 g_qeglobals.d_savedinfo.colors[COLOR_GRIDMINOR] != g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK])
239 qglColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_GRIDMINOR]);
242 for (zz=zb ; zz<ze ; zz+=g_qeglobals.d_gridsize)
244 if ( ! ((int)zz & 63) )
246 qglVertex2f (-w, zz);
252 // draw coordinate text if needed
254 if ( g_qeglobals.d_savedinfo.show_coordinates)
256 qglColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_GRIDTEXT]);
258 int step = (int)(g_qeglobals.d_gridsize > 64 ? g_qeglobals.d_gridsize : 64);
259 zb = z.origin[2] - h;
260 if (zb < region_mins[2])
262 zb = step * floor (zb/step);
264 for (zz=zb ; zz<ze ; zz+=step)
266 qglRasterPos2f (-w+(1/z.scale), zz);
267 sprintf (text, "%i",(int)zz);
268 gtk_glwidget_print_string(text);
273 void ZDrawCameraIcon (void)
276 float xCam = z.width/4/z.scale, gizmo = 8 / z.scale, height = 48 / z.scale;
279 y = g_pParentWnd->GetCamWnd()->Camera()->origin[2];
281 qglColor3f (0.0, 0.0, 1.0);
282 qglBegin(GL_LINE_STRIP);
283 qglVertex3f (x-xCam,y,0);
284 qglVertex3f (x,y+gizmo,0);
285 qglVertex3f (x+xCam,y,0);
286 qglVertex3f (x,y-gizmo,0);
287 qglVertex3f (x-xCam,y,0);
288 qglVertex3f (x+xCam,y,0);
289 qglVertex3f (x+xCam,y-height,0);
290 qglVertex3f (x-xCam,y-height,0);
291 qglVertex3f (x-xCam,y,0);
296 GLbitfield glbitClear = GL_COLOR_BUFFER_BIT; //HACK
306 CheckWatchit ("Z_Draw");
313 vec3_t org_top, org_bottom, dir_up, dir_down;
314 int xCam = z.width/3;
316 if (!active_brushes.next)
317 return; // not valid yet
320 start = Sys_DoubleTime ();
325 qglViewport(0, 0, z.width, z.height);
328 g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK][0],
329 g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK][1],
330 g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK][2],
334 /* When not using hw acceleration, gl will fault if we clear the depth
335 buffer bit on the first pass. The hack fix is to set the GL_DEPTH_BUFFER_BIT
336 only after Z_Draw() has been called once. Yeah, right. */
337 qglClear(glbitClear);
338 glbitClear |= GL_DEPTH_BUFFER_BIT;
339 qglMatrixMode(GL_PROJECTION);
342 w = z.width/2 / z.scale;
343 h = z.height/2 / z.scale;
344 qglOrtho (-w, w, z.origin[2]-h, z.origin[2]+h, -8, 8);
346 qglDisable(GL_TEXTURE_2D);
347 qglDisable(GL_TEXTURE_1D);
348 qglDisable(GL_DEPTH_TEST);
349 qglDisable(GL_BLEND);
361 qglDisable(GL_CULL_FACE);
363 qglShadeModel (GL_FLAT);
365 qglPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
367 qglDisable(GL_TEXTURE_2D);
368 qglDisable(GL_BLEND);
369 qglDisable(GL_DEPTH_TEST);
372 // draw filled interiors and edges
373 dir_up[0] = 0 ; dir_up[1] = 0; dir_up[2] = 1;
374 dir_down[0] = 0 ; dir_down[1] = 0; dir_down[2] = -1;
375 VectorCopy (z.origin, org_top);
376 org_top[2] = g_MaxWorldCoord;
377 VectorCopy (z.origin, org_bottom);
378 org_bottom[2] = g_MinWorldCoord;
380 for (brush = active_brushes.next ; brush != &active_brushes ; brush=brush->next)
382 if (brush->bFiltered)
385 if (brush->mins[0] >= z.origin[0]
386 || brush->maxs[0] <= z.origin[0]
387 || brush->mins[1] >= z.origin[1]
388 || brush->maxs[1] <= z.origin[1])
391 if (!Brush_Ray (org_top, dir_down, brush, &top))
393 top = org_top[2] - top;
394 if (!Brush_Ray (org_bottom, dir_up, brush, &bottom))
396 bottom = org_bottom[2] + bottom;
398 q = brush->brush_faces->pShader->getTexture();
399 qglColor3f (q->color[0], q->color[1], q->color[2]);
401 qglVertex2f (-xCam, bottom);
402 qglVertex2f (xCam, bottom);
403 qglVertex2f (xCam, top);
404 qglVertex2f (-xCam, top);
408 qglBegin (GL_LINE_LOOP);
409 qglVertex2f (-xCam, bottom);
410 qglVertex2f (xCam, bottom);
411 qglVertex2f (xCam, top);
412 qglVertex2f (-xCam, top);
417 // now draw selected brushes
419 for (brush = selected_brushes.next ; brush != &selected_brushes ; brush=brush->next)
421 if ( !(brush->mins[0] >= z.origin[0]
422 || brush->maxs[0] <= z.origin[0]
423 || brush->mins[1] >= z.origin[1]
424 || brush->maxs[1] <= z.origin[1]) )
426 if (Brush_Ray (org_top, dir_down, brush, &top))
428 top = org_top[2] - top;
429 if (Brush_Ray (org_bottom, dir_up, brush, &bottom))
431 bottom = org_bottom[2] + bottom;
433 q = brush->brush_faces->pShader->getTexture();
434 qglColor3f (q->color[0], q->color[1], q->color[2]);
436 qglVertex2f (-xCam, bottom);
437 qglVertex2f (xCam, bottom);
438 qglVertex2f (xCam, top);
439 qglVertex2f (-xCam, top);
445 qglColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_SELBRUSHES]);
446 qglBegin (GL_LINE_LOOP);
447 qglVertex2f (-xCam, brush->mins[2]);
448 qglVertex2f (xCam, brush->mins[2]);
449 qglVertex2f (xCam, brush->maxs[2]);
450 qglVertex2f (-xCam, brush->maxs[2]);
458 QE_CheckOpenGLForErrors();
462 end = Sys_DoubleTime ();
463 Sys_Printf ("z: %i ms\n", (int)(1000*(end-start)));