]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/zwindow.cpp
create a branch for AB sync
[xonotic/netradiant.git] / radiant / zwindow.cpp
1 /*\r
2 Copyright (C) 1999-2007 id Software, Inc. and contributors.\r
3 For a list of contributors, see the accompanying CONTRIBUTORS file.\r
4 \r
5 This file is part of GtkRadiant.\r
6 \r
7 GtkRadiant is free software; you can redistribute it and/or modify\r
8 it under the terms of the GNU General Public License as published by\r
9 the Free Software Foundation; either version 2 of the License, or\r
10 (at your option) any later version.\r
11 \r
12 GtkRadiant is distributed in the hope that it will be useful,\r
13 but WITHOUT ANY WARRANTY; without even the implied warranty of\r
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
15 GNU General Public License for more details.\r
16 \r
17 You should have received a copy of the GNU General Public License\r
18 along with GtkRadiant; if not, write to the Free Software\r
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\r
20 */\r
21 \r
22 //\r
23 // Z Window\r
24 //\r
25 // Leonardo Zide (leo@lokigames.com)\r
26 //\r
27 \r
28 #include "stdafx.h"\r
29 #include "zwindow.h"\r
30 \r
31 // =============================================================================\r
32 // ZWnd class\r
33 \r
34 ZWnd::ZWnd ()\r
35   : GLWindow (FALSE)\r
36 {\r
37 }\r
38 \r
39 ZWnd::~ZWnd()\r
40 {\r
41 }\r
42 \r
43 void ZWnd::OnCreate () \r
44 {\r
45   g_qeglobals_gui.d_z = m_pWidget;\r
46 \r
47   if (!MakeCurrent())\r
48     Error ("wglMakeCurrent in CZWnd::OnCreate failed");\r
49 }\r
50 \r
51 void ZWnd::OnLButtonDown(guint32 nFlags, int pointx, int pointy) \r
52 {\r
53   SetFocus();\r
54   SetCapture();\r
55   Z_MouseDown (pointx, m_pWidget->allocation.height - 1 - pointy , nFlags);\r
56 }\r
57 \r
58 void ZWnd::OnMButtonDown(guint32 nFlags, int pointx, int pointy) \r
59 {\r
60   SetFocus();\r
61   SetCapture();\r
62   Z_MouseDown (pointx, m_pWidget->allocation.height - 1 - pointy , nFlags);\r
63 }\r
64 \r
65 void ZWnd::OnRButtonDown(guint32 nFlags, int pointx, int pointy) \r
66 {\r
67   SetFocus();\r
68   SetCapture();\r
69   Z_MouseDown (pointx, m_pWidget->allocation.height - 1 - pointy , nFlags);\r
70 }\r
71 \r
72 void ZWnd::OnLButtonUp(guint32 nFlags, int pointx, int pointy) \r
73 {\r
74   Z_MouseUp (pointx, m_pWidget->allocation.height - 1 - pointy, nFlags);\r
75   ReleaseCapture ();\r
76 }\r
77 \r
78 void ZWnd::OnMButtonUp(guint32 nFlags, int pointx, int pointy) \r
79 {\r
80   Z_MouseUp (pointx, m_pWidget->allocation.height - 1 - pointy, nFlags);\r
81   ReleaseCapture ();\r
82 }\r
83 \r
84 void ZWnd::OnRButtonUp(guint32 nFlags, int pointx, int pointy) \r
85 {\r
86   Z_MouseUp (pointx, m_pWidget->allocation.height - 1 - pointy, nFlags);\r
87   ReleaseCapture ();\r
88 }\r
89 \r
90 void ZWnd::OnMouseMove(guint32 nFlags, int pointx, int pointy) \r
91 {\r
92   float fz = z.origin[2] + ((m_pWidget->allocation.height - 1 - pointy) - (z.height/2)) / z.scale;\r
93         fz = floor(fz / g_qeglobals.d_gridsize + 0.5) * g_qeglobals.d_gridsize;\r
94   CString strStatus;\r
95   strStatus.Format("Z:: %.1f", fz);\r
96   g_pParentWnd->SetStatusText(1, strStatus);\r
97   Z_MouseMoved (pointx, m_pWidget->allocation.height - 1 - pointy, nFlags);\r
98 }\r
99 \r
100 void ZWnd::OnExpose() \r
101 {\r
102   if (!MakeCurrent ())\r
103   {\r
104     Sys_Printf("ERROR: wglMakeCurrent failed..\n ");\r
105     Sys_Printf("Please restart Radiant if the Z view is not working\n");\r
106   }\r
107   else\r
108   {\r
109     QE_CheckOpenGLForErrors();\r
110     Z_Draw ();\r
111     QE_CheckOpenGLForErrors();\r
112     SwapBuffers();\r
113   }\r
114 }\r
115 \r
116 void ZWnd::OnSize(int cx, int cy) \r
117 {\r
118   z.width = cx;\r
119   z.height = cy;\r
120   if (z.width < 10)\r
121     z.width = 10;\r
122   if (z.height < 10)\r
123     z.height = 10;\r
124   RedrawWindow ();\r
125 }\r