summaryrefslogtreecommitdiffstats
path: root/tools/globalcode/utility/overlaymarquee.cpp
blob: 7d97b7739b1be831ff09bbfcf7fae4724d24d7ec (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
//-----------------------------------------------------------------------------
// Copyright (C) 2001 Radical Entertainment Ltd.  All rights reserved.
//
// marquee.cpp
//
// Description: 
//
// Modification History:
//  + Created Jun 14, 2001 -- bkusy 
//-----------------------------------------------------------------------------

//----------------------------------------
// System Includes
//----------------------------------------
#include <windows.h>
#include <assert.h>

#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glaux.h>

//----------------------------------------
// Project Includes
//----------------------------------------
#include "overlaymarquee.h"

//----------------------------------------
// Forward References
//----------------------------------------

//----------------------------------------
// Define Owning Namespace
//----------------------------------------
namespace GLObj {

//----------------------------------------
// Constants, Typedefs and Statics
//----------------------------------------

//-----------------------------------------------------------------------------
// M a r q u e e 
//
// Synopsis:    Constructor
//
// Parameters:  NONE
//
// Returns:     NOTHING
//
// Constraints: NONE
//
//-----------------------------------------------------------------------------
OverlayMarquee::OverlayMarquee() :
    m_xStart( 0 ),
    m_yStart( 0 ),
    m_xEnd( 0 ),
    m_yEnd( 0 )
{
}

//-----------------------------------------------------------------------------
// ~ M a r q u e e 
//
// Synopsis:    Destructor
//
// Parameters:  NONE
//
// Returns:     NOTHING
//
// Constraints: NONE
//
//-----------------------------------------------------------------------------
OverlayMarquee::~OverlayMarquee()
{
}

//-----------------------------------------------------------------------------
// B e g i n 
//
// Synopsis:
//
// Parameters:  NONE
//
// Returns:     NOTHING
//
// Constraints: NONE
//
//-----------------------------------------------------------------------------
void OverlayMarquee::Begin( M3dView& view, short xStart, short yStart )
{
    m_View = view;
    m_xStart = xStart;
    m_yStart = yStart;
    m_View.beginGL();
    m_View.beginOverlayDrawing();
}

//-----------------------------------------------------------------------------
// D r a w 
//
// Synopsis:    Draw a marquee with the given coordinates.
//
// Parameters:  NONE
//
// Returns:     NOTHING
//
// Constraints: NONE
//
//-----------------------------------------------------------------------------
void OverlayMarquee::Draw( short xEnd, short yEnd )
{
    glPushAttrib( GL_CURRENT_BIT | GL_LINE_BIT | GL_POLYGON_BIT );
    m_xEnd = xEnd;
    m_yEnd = yEnd;
    
    //
    // Clearing the overlay plane doesn't seem to work, but swapping buffers does
    // so we'll use that instead.  You've gotta luv Maya bugs -- embrace them 
    // don't squash them.
    //
    m_View.clearOverlayPlane();
    SwapBuffers( m_View.deviceContext() );

    // 
    // Setup the orthographic projection matrix.
    //
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    gluOrtho2D( 0.0, (GLdouble)m_View.portWidth(), 0.0, (GLdouble)m_View.portHeight() );
    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();
    glTranslatef( 0.375, 0.375, 0.0 );

    //
    // Retrieve GL State.
    //
    float         lineWidth;
    unsigned char lineSmoothedFlag;
    glGetFloatv( GL_LINE_WIDTH, &lineWidth );
    glGetBooleanv( GL_LINE_SMOOTH, &lineSmoothedFlag );

    //
    // Set line style.
    //
    glLineStipple( 1, 0x5555 );
    glLineWidth( 1.0 );
    glEnable( GL_LINE_STIPPLE );
    glEnable( GL_LINE_SMOOTH );
    glIndexi( 2 );

    //
    // Draw marquee.
    //
    glBegin( GL_LINES );

        glVertex2i( m_xStart, m_yEnd );  // Left Side.
        glVertex2i( m_xStart, m_yStart );

        glVertex2i( m_xStart, m_yStart );// Top 
        glVertex2i( m_xEnd,   m_yStart );

        glVertex2i( m_xEnd, m_yStart );  // Right Side.
        glVertex2i( m_xEnd, m_yEnd );

        glVertex2i( m_xEnd,    m_yEnd ); // Bottom.
        glVertex2i( m_xStart, m_yEnd );

    glEnd();

    //
    // Don't swap the display buffers.  A bug in Maya causes the display to be 
    // cleared -- making the flicker worse.
    //
    //SwapBuffers( m_View.deviceContext() );

    // 
    // Instead just flush the GL buffers.
    //
    glFlush();
    

    // 
    // Restore GL state.
    glLineWidth( lineWidth );
    if ( !lineSmoothedFlag )  glDisable( GL_LINE_SMOOTH );
    glDisable( GL_LINE_STIPPLE );

    glPopAttrib();
}

//-----------------------------------------------------------------------------
// R e d r a w 
//
// Synopsis:    Draw a marquee with the last given coordinates.
//
// Parameters:  NONE
//
// Returns:     NOTHING
//
// Constraints: NONE
//
//-----------------------------------------------------------------------------
void OverlayMarquee::Redraw()
{
    Draw( m_xEnd, m_yEnd );
}

void OverlayMarquee::End()
{
    m_View.endOverlayDrawing();
    m_View.endGL();
    
    //
    // Use the Maya bug to get rid of any drawing we have done.
    //
    SwapBuffers( m_View.deviceContext() );
}

} // namespace GLObj