]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/tools/radiant/ZClip.cpp
hello world
[icculus/iodoom3.git] / neo / tools / radiant / ZClip.cpp
1 /*
2 ===========================================================================
3
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. 
6
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).  
8
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.
13
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.
18
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/>.
21
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.
23
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.
25
26 ===========================================================================
27 */
28
29 #include "../../idlib/precompiled.h"
30 #pragma hdrstop
31
32 #include "qe3.h"
33 #include "Radiant.h"
34
35 #include "zclip.h"
36
37
38 CZClip::CZClip()
39 {       
40         LONG 
41         lSize = sizeof(m_bEnabled);
42         if (!LoadRegistryInfo("radiant_ZClipEnabled",   &m_bEnabled, &lSize))
43                 m_bEnabled = false;
44
45         lSize = sizeof(m_iZClipTop);
46         if (!LoadRegistryInfo("radiant_ZClipTop",               &m_iZClipTop, &lSize))
47                 m_iZClipTop = 64;
48
49         lSize = sizeof(m_iZClipBottom);
50         if (!LoadRegistryInfo("radiant_ZClipBottom",    &m_iZClipBottom, &lSize))
51                 m_iZClipBottom = -64;
52
53         Legalise();
54 }
55
56 CZClip::~CZClip()
57 {
58         // TODO: registry save
59
60         SaveRegistryInfo("radiant_ZClipEnabled", &m_bEnabled,           sizeof(m_bEnabled));
61         SaveRegistryInfo("radiant_ZClipTop",     &m_iZClipTop,          sizeof(m_iZClipTop));
62         SaveRegistryInfo("radiant_ZClipBottom",  &m_iZClipBottom,       sizeof(m_iZClipBottom));
63 }
64
65 void CZClip::Reset(void)
66 {
67         m_iZClipTop             = 64;           // arb. starting values, but must be at least 64 apart
68         m_iZClipBottom  = -64;
69         m_bEnabled              = false;
70
71         Legalise();
72 }
73
74
75 int     CZClip::GetTop(void)
76 {
77         return m_iZClipTop;
78 }
79
80 int CZClip::GetBottom(void)
81 {
82         return m_iZClipBottom;
83 }
84
85 void CZClip::Legalise(void)
86 {
87         // need swapping?
88         //
89         if (m_iZClipTop < m_iZClipBottom)
90         {
91                 int iTemp = m_iZClipTop;
92                                         m_iZClipTop = m_iZClipBottom;
93                                                                   m_iZClipBottom = iTemp;
94         }
95
96         // too close together?
97         //
98 #define ZCLIP_MIN_SPACING 64
99
100         if (abs(m_iZClipTop - m_iZClipBottom) < ZCLIP_MIN_SPACING)
101                 m_iZClipBottom = m_iZClipTop - ZCLIP_MIN_SPACING;
102 }
103
104
105 void CZClip::SetTop(int iNewZ)
106 {
107         m_iZClipTop = iNewZ;
108
109         Legalise();             
110 }
111
112 void CZClip::SetBottom(int iNewZ)
113 {
114         m_iZClipBottom = iNewZ;
115
116         Legalise();
117 }
118
119 bool CZClip::IsEnabled(void)
120 {
121         return m_bEnabled;
122 }
123
124
125 bool CZClip::Enable(bool bOnOff)
126 {
127         m_bEnabled = !m_bEnabled;
128         return IsEnabled();
129 }
130
131 #define ZCLIP_BAR_THICKNESS 8
132 #define ZCLIP_ARROWHEIGHT (ZCLIP_BAR_THICKNESS*8)
133
134 void CZClip::Paint(void)
135 {
136         float   x, y;
137         int     xCam = z.width/4;       // hmmm, a rather unpleasant and obscure global name, but it was already called that so...
138
139         qglColor3f (ZCLIP_COLOUR);//1.0, 0.0, 1.0);
140
141         // draw TOP marker...
142         //
143         x = 0;
144         y = m_iZClipTop;
145
146         if (m_bEnabled) 
147                 qglBegin(GL_QUADS);
148         else
149                 qglBegin(GL_LINE_LOOP);
150
151         qglVertex3f (x-xCam,y,0);
152         qglVertex3f (x-xCam,y+ZCLIP_BAR_THICKNESS,0);
153         qglVertex3f (x+xCam,y+ZCLIP_BAR_THICKNESS,0);
154         qglVertex3f (x+xCam,y,0);
155         qglEnd ();
156
157         qglColor3f (ZCLIP_COLOUR_DIM);//0.8, 0.0, 0.8);
158
159         if (m_bEnabled)
160                 qglBegin(GL_TRIANGLES);
161         else
162                 qglBegin(GL_LINE_LOOP); 
163         qglVertex3f (x,(y+ZCLIP_BAR_THICKNESS),0);
164         qglVertex3f (x-xCam,(y+ZCLIP_BAR_THICKNESS)+(ZCLIP_ARROWHEIGHT/2),0);
165         qglVertex3f (x+xCam,(y+ZCLIP_BAR_THICKNESS)+(ZCLIP_ARROWHEIGHT/2),0);
166         qglEnd ();
167
168         // draw bottom marker...
169         //
170         qglColor3f (ZCLIP_COLOUR);//1.0, 0.0, 1.0);
171         x = 0;
172         y = m_iZClipBottom;
173
174         if (m_bEnabled) 
175                 qglBegin(GL_QUADS);
176         else
177                 qglBegin(GL_LINE_LOOP);
178         qglVertex3f (x-xCam,y,0);
179         qglVertex3f (x-xCam,y-ZCLIP_BAR_THICKNESS,0);
180         qglVertex3f (x+xCam,y-ZCLIP_BAR_THICKNESS,0);
181         qglVertex3f (x+xCam,y,0);
182         qglEnd ();
183
184         qglColor3f (ZCLIP_COLOUR_DIM);//0.8, 0.0, 0.8);
185
186         if (m_bEnabled)
187                 qglBegin(GL_TRIANGLES);
188         else
189                 qglBegin(GL_LINE_LOOP); 
190         qglVertex3f (x,(y-ZCLIP_BAR_THICKNESS),0);
191         qglVertex3f (x-xCam,(y-ZCLIP_BAR_THICKNESS)-(ZCLIP_ARROWHEIGHT/2),0);
192         qglVertex3f (x+xCam,(y-ZCLIP_BAR_THICKNESS)-(ZCLIP_ARROWHEIGHT/2),0);
193         qglEnd ();
194 }
195
196
197 ///////////////// eof ///////////////////
198
199