]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/zwindow.cpp
propagate from internal tree
[xonotic/netradiant.git] / radiant / zwindow.cpp
1 /*
2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
4
5 This file is part of GtkRadiant.
6
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.
11
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.
16
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
20 */
21
22 //
23 // Z Window
24 //
25 // Leonardo Zide (leo@lokigames.com)
26 //
27
28 #include "stdafx.h"
29 #include "zwindow.h"
30
31 // =============================================================================
32 // ZWnd class
33
34 ZWnd::ZWnd ()
35   : GLWindow (FALSE)
36 {
37 }
38
39 ZWnd::~ZWnd()
40 {
41 }
42
43 void ZWnd::OnCreate () 
44 {
45   g_qeglobals_gui.d_z = m_pWidget;
46
47   if (!MakeCurrent())
48     Error ("wglMakeCurrent in CZWnd::OnCreate failed");
49 }
50
51 void ZWnd::OnLButtonDown(guint32 nFlags, int pointx, int pointy) 
52 {
53   SetFocus();
54   SetCapture();
55   Z_MouseDown (pointx, m_pWidget->allocation.height - 1 - pointy , nFlags);
56 }
57
58 void ZWnd::OnMButtonDown(guint32 nFlags, int pointx, int pointy) 
59 {
60   SetFocus();
61   SetCapture();
62   Z_MouseDown (pointx, m_pWidget->allocation.height - 1 - pointy , nFlags);
63 }
64
65 void ZWnd::OnRButtonDown(guint32 nFlags, int pointx, int pointy) 
66 {
67   SetFocus();
68   SetCapture();
69   Z_MouseDown (pointx, m_pWidget->allocation.height - 1 - pointy , nFlags);
70 }
71
72 void ZWnd::OnLButtonUp(guint32 nFlags, int pointx, int pointy) 
73 {
74   Z_MouseUp (pointx, m_pWidget->allocation.height - 1 - pointy, nFlags);
75   ReleaseCapture ();
76 }
77
78 void ZWnd::OnMButtonUp(guint32 nFlags, int pointx, int pointy) 
79 {
80   Z_MouseUp (pointx, m_pWidget->allocation.height - 1 - pointy, nFlags);
81   ReleaseCapture ();
82 }
83
84 void ZWnd::OnRButtonUp(guint32 nFlags, int pointx, int pointy) 
85 {
86   Z_MouseUp (pointx, m_pWidget->allocation.height - 1 - pointy, nFlags);
87   ReleaseCapture ();
88 }
89
90 void ZWnd::OnMouseMove(guint32 nFlags, int pointx, int pointy) 
91 {
92   float fz = z.origin[2] + ((m_pWidget->allocation.height - 1 - pointy) - (z.height/2)) / z.scale;
93         fz = floor(fz / g_qeglobals.d_gridsize + 0.5) * g_qeglobals.d_gridsize;
94   CString strStatus;
95   strStatus.Format("Z:: %.1f", fz);
96   g_pParentWnd->SetStatusText(1, strStatus);
97   Z_MouseMoved (pointx, m_pWidget->allocation.height - 1 - pointy, nFlags);
98 }
99
100 void ZWnd::OnExpose() 
101 {
102   if (!MakeCurrent ())
103   {
104     Sys_Printf("ERROR: wglMakeCurrent failed..\n ");
105     Sys_Printf("Please restart Radiant if the Z view is not working\n");
106   }
107   else
108   {
109     QE_CheckOpenGLForErrors();
110     Z_Draw ();
111     QE_CheckOpenGLForErrors();
112     SwapBuffers();
113   }
114 }
115
116 void ZWnd::OnSize(int cx, int cy) 
117 {
118   z.width = cx;
119   z.height = cy;
120   if (z.width < 10)
121     z.width = 10;
122   if (z.height < 10)
123     z.height = 10;
124   RedrawWindow ();
125 }