2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
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.
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.
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/>.
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.
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.
26 ===========================================================================
29 #include "../../idlib/precompiled.h"
39 =======================================================================================================================
41 =======================================================================================================================
52 static int cursorx, cursory;
55 =======================================================================================================================
57 =======================================================================================================================
59 void Z_MouseDown(int x, int y, int buttons) {
60 idVec3 org, dir, vup, vright;
63 Sys_GetCursorPos(&cursorx, &cursory);
69 VectorCopy(z.origin, org);
70 org[2] += (y - (z.height / 2)) / z.scale;
71 org[1] = MIN_WORLD_COORD;
73 b = selected_brushes.next;
74 if (b != &selected_brushes) {
75 org[0] = (b->mins[0] + b->maxs[0]) / 2;
87 // new mouse code for ZClip, I'll do this stuff before falling through into the standard ZWindow mouse code...
89 if (g_pParentWnd->GetZWnd()->m_pZClip) // should always be the case I think, but this is safer
96 if (g_PrefsDlg.m_nMouseButtons == 2)
100 bToggle = (GetKeyState(VK_F1) & 0x8000) != 0;
101 bSetTop = (GetKeyState(VK_F2) & 0x8000) != 0;
102 bSetBot = (GetKeyState(VK_F3) & 0x8000) != 0;
103 bReset = (GetKeyState(VK_F4) & 0x8000) != 0;
109 bToggle = (buttons == (MK_RBUTTON|MK_SHIFT|MK_CONTROL));
110 bSetTop = (buttons == (MK_RBUTTON|MK_SHIFT));
111 bSetBot = (buttons == (MK_RBUTTON|MK_CONTROL));
112 bReset = (GetKeyState(VK_F4) & 0x8000) != 0;
117 g_pParentWnd->GetZWnd()->m_pZClip->Enable(!(g_pParentWnd->GetZWnd()->m_pZClip->IsEnabled()));
118 Sys_UpdateWindows (W_ALL);
124 g_pParentWnd->GetZWnd()->m_pZClip->SetTop(org[2]);
125 Sys_UpdateWindows (W_ALL);
131 g_pParentWnd->GetZWnd()->m_pZClip->SetBottom(org[2]);
132 Sys_UpdateWindows (W_ALL);
138 g_pParentWnd->GetZWnd()->m_pZClip->Reset();
139 Sys_UpdateWindows (W_ALL);
145 // LBUTTON = manipulate selection shift-LBUTTON = select middle button = grab
146 // texture ctrl-middle button = set entire brush to texture ctrl-shift-middle
147 // button = set single face to texture
150 // see code above for these next 3, I just commented them here as well for clarity...
152 // ctrl-shift-RIGHT button = toggle ZClip on/off
153 // shift-RIGHT button = set ZClip top marker
154 // ctrl-RIGHT button = set ZClip bottom marker
156 int nMouseButton = g_PrefsDlg.m_nMouseButtons == 2 ? MK_RBUTTON : MK_MBUTTON;
159 (buttons == MK_LBUTTON) ||
160 (buttons == (MK_LBUTTON | MK_SHIFT)) ||
161 (buttons == MK_MBUTTON) // || (buttons == (MK_MBUTTON|MK_CONTROL))
163 (buttons == (nMouseButton | MK_SHIFT | MK_CONTROL))
165 Drag_Begin(x, y, buttons, vright, vup, org, dir);
169 // control mbutton = move camera
170 if ((buttons == (MK_CONTROL | nMouseButton)) || (buttons == (MK_CONTROL | MK_LBUTTON))) {
171 g_pParentWnd->GetCamera()->Camera().origin[2] = org[2];
172 Sys_UpdateWindows(W_CAMERA | W_XY_OVERLAY | W_Z);
177 =======================================================================================================================
179 =======================================================================================================================
181 void Z_MouseUp(int x, int y, int buttons) {
186 =======================================================================================================================
188 =======================================================================================================================
190 void Z_MouseMoved(int x, int y, int buttons) {
195 if (buttons == MK_LBUTTON) {
196 Drag_MouseMoved(x, y, buttons);
197 Sys_UpdateWindows(W_Z | W_CAMERA_IFON | W_XY);
201 // rbutton = drag z origin
202 if (buttons == MK_RBUTTON) {
203 Sys_GetCursorPos(&x, &y);
205 z.origin[2] += y - cursory;
206 Sys_SetCursorPos(cursorx, cursory);
207 Sys_UpdateWindows(W_Z);
213 // control mbutton = move camera
214 int nMouseButton = g_PrefsDlg.m_nMouseButtons == 2 ? MK_RBUTTON : MK_MBUTTON;
215 if ((buttons == (MK_CONTROL | nMouseButton)) || (buttons == (MK_CONTROL | MK_LBUTTON))) {
216 g_pParentWnd->GetCamera()->Camera().origin[2] = z.origin[2] + (y - (z.height / 2)) / z.scale;
217 Sys_UpdateWindows(W_CAMERA | W_XY_OVERLAY | W_Z);
222 =======================================================================================================================
225 =======================================================================================================================
227 void Z_DrawGrid(void) {
232 w = z.width / 2 / z.scale;
233 h = z.height / 2 / z.scale;
235 zb = z.origin[2] - h;
236 if (zb < region_mins[2]) {
240 zb = 64 * floor(zb / 64);
242 ze = z.origin[2] + h;
243 if (ze > region_maxs[2]) {
247 ze = 64 * ceil(ze / 64);
250 qglColor3fv( g_qeglobals.d_savedinfo.colors[COLOR_GRIDMAJOR].ToFloatPtr() );
257 for (zz = zb; zz < ze; zz += 64) {
265 if ( g_qeglobals.d_showgrid &&
266 g_qeglobals.d_gridsize * z.scale >= 4 &&
267 !g_qeglobals.d_savedinfo.colors[COLOR_GRIDMINOR].Compare( g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK] ) ) {
269 qglColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_GRIDMINOR].ToFloatPtr());
272 for (zz = zb; zz < ze; zz += g_qeglobals.d_gridsize) {
273 if (!((int)zz & 63)) {
284 // draw coordinate text if needed
285 qglColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_GRIDTEXT].ToFloatPtr());
287 for (zz = zb; zz < ze; zz += 64) {
288 qglRasterPos2f(-w + 1, zz);
289 sprintf(text, "%i", (int)zz);
290 qglCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
294 #define CAM_HEIGHT 48 // height of main part
295 #define CAM_GIZMO 8 // height of the gizmo
298 =======================================================================================================================
299 =======================================================================================================================
301 void ZDrawCameraIcon(void) {
303 int xCam = z.width / 4;
306 y = g_pParentWnd->GetCamera()->Camera().origin[2];
308 qglColor3f(0.0, 0.0, 1.0);
309 qglBegin(GL_LINE_STRIP);
310 qglVertex3f(x - xCam, y, 0);
311 qglVertex3f(x, y + CAM_GIZMO, 0);
312 qglVertex3f(x + xCam, y, 0);
313 qglVertex3f(x, y - CAM_GIZMO, 0);
314 qglVertex3f(x - xCam, y, 0);
315 qglVertex3f(x + xCam, y, 0);
316 qglVertex3f(x + xCam, y - CAM_HEIGHT, 0);
317 qglVertex3f(x - xCam, y - CAM_HEIGHT, 0);
318 qglVertex3f(x - xCam, y, 0);
327 y = g_pParentWnd->GetCamera()->Camera().origin[2];
329 if (g_pParentWnd->GetZWnd()->m_pZClip) // should always be the case I think
330 g_pParentWnd->GetZWnd()->m_pZClip->Paint();
334 GLbitfield glbitClear = GL_COLOR_BUFFER_BIT; // HACK
337 =======================================================================================================================
339 =======================================================================================================================
345 idVec3 org_top, org_bottom, dir_up, dir_down;
346 int xCam = z.width / 3;
348 if (!active_brushes.next) {
349 return; // not valid yet
353 qglViewport(0, 0, z.width, z.height);
354 qglScissor(0, 0, z.width, z.height);
358 g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK][0],
359 g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK][1],
360 g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK][2],
366 * When not using hw acceleration, gl will fault if we clear the depth buffer bit
367 * on the first pass. The hack fix is to set the GL_DEPTH_BUFFER_BIT only after
368 * Z_Draw() has been called once. Yeah, right. £
369 * qglClear(glbitClear);
371 qglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
374 // glbitClear |= GL_DEPTH_BUFFER_BIT;
375 // qglClear(GL_DEPTH_BUFFER_BIT);
377 qglMatrixMode(GL_PROJECTION);
380 w = z.width / 2 / z.scale;
381 h = z.height / 2 / z.scale;
382 qglOrtho(-w, w, z.origin[2] - h, z.origin[2] + h, -8, 8);
384 globalImages->BindNull();
385 qglDisable(GL_DEPTH_TEST);
386 qglDisable(GL_BLEND);
392 qglDisable(GL_CULL_FACE);
394 qglPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
396 globalImages->BindNull();
398 // draw filled interiors and edges
405 VectorCopy(z.origin, org_top);
407 VectorCopy(z.origin, org_bottom);
408 org_bottom[2] = -4096;
410 for (brush = active_brushes.next; brush != &active_brushes; brush = brush->next) {
413 brush->mins[0] >= z.origin[0] ||
414 brush->maxs[0] <= z.origin[0] ||
415 brush->mins[1] >= z.origin[1] ||
416 brush->maxs[1] <= z.origin[1]
421 if (!Brush_Ray(org_top, dir_down, brush, &top)) {
425 top = org_top[2] - top;
426 if (!Brush_Ray(org_bottom, dir_up, brush, &bottom)) {
430 bottom = org_bottom[2] + bottom;
432 //q = declManager->FindMaterial(brush->brush_faces->texdef.name);
433 qglColor3f(brush->owner->eclass->color.x, brush->owner->eclass->color.y, brush->owner->eclass->color.z);
435 qglVertex2f(-xCam, bottom);
436 qglVertex2f(xCam, bottom);
437 qglVertex2f(xCam, top);
438 qglVertex2f(-xCam, top);
442 qglBegin(GL_LINE_LOOP);
443 qglVertex2f(-xCam, bottom);
444 qglVertex2f(xCam, bottom);
445 qglVertex2f(xCam, top);
446 qglVertex2f(-xCam, top);
450 // now draw selected brushes
451 for (brush = selected_brushes.next; brush != &selected_brushes; brush = brush->next) {
455 brush->mins[0] >= z.origin[0] ||
456 brush->maxs[0] <= z.origin[0] ||
457 brush->mins[1] >= z.origin[1] ||
458 brush->maxs[1] <= z.origin[1]
461 if (Brush_Ray(org_top, dir_down, brush, &top)) {
462 top = org_top[2] - top;
463 if (Brush_Ray(org_bottom, dir_up, brush, &bottom)) {
464 bottom = org_bottom[2] + bottom;
466 //q = declManager->FindMaterial(brush->brush_faces->texdef.name);
467 qglColor3f(brush->owner->eclass->color.x, brush->owner->eclass->color.y, brush->owner->eclass->color.z);
469 qglVertex2f(-xCam, bottom);
470 qglVertex2f(xCam, bottom);
471 qglVertex2f(xCam, top);
472 qglVertex2f(-xCam, top);
478 qglColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_SELBRUSHES].ToFloatPtr());
479 qglBegin(GL_LINE_LOOP);
480 qglVertex2f(-xCam, brush->mins[2]);
481 qglVertex2f(xCam, brush->mins[2]);
482 qglVertex2f(xCam, brush->maxs[2]);
483 qglVertex2f(-xCam, brush->maxs[2]);
491 QE_CheckOpenGLForErrors();