Vegastrike 0.5.1 rc1
1.0
Original sources for Vegastrike Evolved
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
Vegastrike 0.5.1 rc1
Todo List
Modules
Namespaces
Classes
Files
File List
src
aldrv
audio
cmd
common
gfx
gldrv
gui
button.cpp
button.h
control.cpp
control.h
eventmanager.cpp
eventmanager.h
eventresponder.cpp
eventresponder.h
font.cpp
font.h
glut_support.cpp
glut_support.h
groupcontrol.cpp
groupcontrol.h
guidefs.cpp
guidefs.h
guitexture.cpp
guitexture.h
modaldialog.cpp
modaldialog.h
newbutton.cpp
newbutton.h
painttext.cpp
painttext.h
picker.cpp
picker.h
scroller.cpp
scroller.h
simplepicker.cpp
simplepicker.h
slider.cpp
slider.h
staticdisplay.cpp
staticdisplay.h
text_area.cpp
text_area.h
textinputdisplay.cpp
textinputdisplay.h
window.cpp
window.h
windowcontroller.cpp
windowcontroller.h
networking
python
accountserver.cpp
audiolib.h
cg_global.cpp
cg_global.h
command.cpp
command.h
config_xml.cpp
config_xml.h
configxml.cpp
configxml.h
cs_boostpython.h
cs_boostpythonclass.h
cs_boostpythonobj.h
cs_python.h
debug_vs.cpp
debug_vs.h
easydom.cpp
easydom.h
endianness.cpp
endianness.h
faction_generic.cpp
faction_generic.h
faction_util.cpp
faction_util_generic.cpp
faction_util_server.cpp
fastmath.cpp
ffmpeg_init.cpp
ffmpeg_init.h
file_main.h
force_feedback.cpp
force_feedback.h
force_feedback_server.cpp
functors.h
galaxy.cpp
galaxy_gen.cpp
galaxy_gen.h
galaxy_xml.cpp
galaxy_xml.h
gamemenu.cpp
gamemenu.h
gfxlib.h
gfxlib_struct.cpp
gfxlib_struct.h
gfxlib_struct_server.cpp
gnuhash.h
hashtable.cpp
hashtable.h
in.h
in_handler.h
in_joystick.cpp
in_joystick.h
in_kb.cpp
in_kb.h
in_kb_data.h
in_main.cpp
in_main.h
in_mouse.cpp
in_mouse.h
in_sdl.cpp
junk.c
libaudioserver.cpp
libserver.cpp
lin_time.cpp
lin_time.h
linecollide.h
load_mission.cpp
load_mission.h
macosx_math.cpp
macosx_math.h
macquartz.cpp
main.cpp
main_loop.cpp
main_loop.h
mmorpgclient.cpp
mmorpgclient.h
options.cpp
options.h
physics.cpp
physics.h
pk3.cpp
pk3.h
posh.cpp
posh.h
precompiled.h
profile.h
rendertext.cpp
rendertext.h
replaceall.py
resizable.h
save_util.h
savegame.cpp
savegame.h
SharedPool.cpp
SharedPool.h
ship_commands.cpp
ship_commands.h
Singleton.h
star_system.cpp
star_system.h
star_system_generic.cpp
star_system_generic.h
star_system_jump.cpp
star_system_xml.cpp
stardate.cpp
stardate.h
universe.cpp
universe.h
universe_generic.cpp
universe_generic.h
universe_util.cpp
universe_util.h
universe_util_generic.cpp
universe_util_server.cpp
vegaserver.cpp
vegastrike.h
vs_globals.cpp
vs_globals.h
vs_math.h
vs_random.h
vsfilesystem.cpp
vsfilesystem.h
VSFileXMLSerializer.cpp
VSFileXMLSerializer.h
xml_serializer.cpp
xml_serializer.h
xml_support.cpp
xml_support.h
XMLDocument.cpp
XMLDocument.h
File Members
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
window.cpp
Go to the documentation of this file.
1
/*
2
* Vega Strike
3
* Copyright (C) 2003 Mike Byron
4
*
5
* http://vegastrike.sourceforge.net/
6
*
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; either version 2
10
* of the License, or (at your option) any later version.
11
*
12
* This program 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 this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
*/
21
22
#include "
vegastrike.h
"
23
24
#include "
window.h
"
25
26
#include "
eventmanager.h
"
27
#include "
groupcontrol.h
"
28
#include "
windowcontroller.h
"
29
30
#include "
eventmanager.h
"
31
32
//For drawing the cursor.
33
#include "
gfx/aux_texture.h
"
34
#include "
gfx/sprite.h
"
35
36
//The outside boundaries of the window.
37
void
Window::setRect
(
const
Rect
&r )
38
{
39
m_rect
= r;
40
}
41
void
Window::setFullScreen
(
void
)
42
{
43
setRect
(
FULL_SCREEN_RECT
);
44
}
45
void
Window::setSizeAndCenter
(
const
Size
&
size
)
46
{
47
setRect
(
Rect
( -size.
width
/2.0, -size.
height
/2.0, size.
width
, size.
height
) );
48
}
49
50
//Initially display the window.
51
//Call this when all the properties and controls of the window are set.
52
void
Window::open
(
void
)
53
{
54
globalWindowManager
().
openWindow
(
this
);
55
}
56
57
//Done with the window.
58
void
Window::close
(
void
)
59
{
60
processCommand
(
"Window::Close"
, NULL );
61
}
62
63
//Manage controls.
64
void
Window::addControl
(
Control
*
c
)
65
{
66
m_controls
->
addChild
( c );
67
}
68
void
Window::deleteControl
(
Control
*
c
)
69
{
70
m_controls
->
deleteControl
( c );
71
}
72
73
//Take a control away from this window and save it elsewhere.
74
Control
*
Window::removeControlFromWindow
(
Control
*
c
)
75
{
76
return
m_controls
->
removeControlFromGroup
( c );
77
}
78
79
//Find a control using its id. NULL returned if none found.
80
//Note that the control may be hidden.
81
Control
*
Window::findControlById
(
const
std::string &
id
)
82
{
83
return
m_controls
->
findControlById
(
id
);
84
}
85
86
//Draw/redraw the whole window.
87
void
Window::draw
(
void
)
88
{
89
drawBackground
();
90
m_controls
->
draw
();
91
}
92
93
//Draw window background.
94
void
Window::drawBackground
(
void
)
95
{
96
m_texture
.
draw
(
m_rect
);
97
if
( !
isClear
(
m_color
) )
98
drawRect
(
m_rect
,
m_color
);
99
if
( !
isClear
(
m_outlineColor
) )
100
drawRectOutline
(
m_rect
,
m_outlineColor
,
m_outlineWidth
);
101
}
102
103
//Read window properties and controls from an XML file.
104
void
Window::readFromXml
(
const
std::string &fileName ) {}
105
106
//OVERRIDES
107
bool
Window::processMouseDown
(
const
InputEvent
&event )
108
{
109
if
(
m_controls
->
processMouseDown
( event ) )
110
return
true
;
111
return
EventResponder::processMouseDown
( event );
112
}
113
114
bool
Window::processMouseUp
(
const
InputEvent
&event )
115
{
116
if
(
m_controls
->
processMouseUp
( event ) )
117
return
true
;
118
return
EventResponder::processMouseUp
( event );
119
}
120
121
bool
Window::processMouseMove
(
const
InputEvent
&event )
122
{
123
if
(
m_controls
->
processMouseMove
( event ) )
124
return
true
;
125
return
EventResponder::processMouseMove
( event );
126
}
127
128
bool
Window::processMouseDrag
(
const
InputEvent
&event )
129
{
130
if
(
m_controls
->
processMouseDrag
( event ) )
131
return
true
;
132
return
EventResponder::processMouseDrag
( event );
133
}
134
135
bool
Window::processCommand
(
const
EventCommandId
&command,
Control
*control )
136
{
137
//The controller should see the command first.
138
if
(
m_controller
!= NULL)
139
if
(
m_controller
->
processWindowCommand
( command, control ) )
140
return
true
;
141
//Default command responders.
142
if
(command ==
"Window::Close"
) {
143
//Close the window!
144
//CAREFUL! This may delete this object! Should be the last line in the function.
145
globalWindowManager
().
closeWindow
(
this
,
m_deleteOnClose
);
146
return
true
;
147
}
148
return
EventResponder::processCommand
( command, control );
149
}
150
151
//CONSTRUCTION
152
Window::Window
(
void
) :
153
m_rect( 0.0, 0.0, 0.0, 0.0 )
154
, m_color(
GUI_OPAQUE_BLACK
() )
155
, m_outlineColor(
GUI_CLEAR
)
156
, m_outlineWidth( 1.0 )
157
, m_deleteOnClose( true )
158
, m_controls( NULL )
159
, m_controller( NULL )
160
{
161
m_controls
=
new
GroupControl
();
162
}
163
164
Window::~Window
(
void
)
165
{
166
EventManager::addToDeleteQueue
(
m_controls
);
167
}
168
170
171
extern
void
ConditionalCursorDraw
(
bool
);
172
//Draw all visible windows.
173
void
WindowManager::draw
()
174
{
175
GFXHudMode
(
true
);
//Load identity matrices.
176
GFXColorf
(
GUI_OPAQUE_WHITE
() );
177
178
GFXDisable
(
DEPTHTEST
);
179
GFXEnable
(
DEPTHWRITE
);
180
GFXDisable
(
LIGHTING
);
181
GFXDisable
(
CULLFACE
);
182
GFXClear
(
GFXTRUE
);
183
GFXDisable
(
DEPTHWRITE
);
184
GFXBlendMode
(
SRCALPHA
,
INVSRCALPHA
);
185
GFXDisable
(
TEXTURE1
);
186
GFXEnable
(
TEXTURE0
);
187
//Just loop through all the windows, and remember if anything gets drawn.
188
//Since the first window in the list is drawn first, z-order is
189
//maintained. First entry is the bottom window, last is the top window.
190
//FIXME mbyron -- I think the event manager needs to get involved with window z-order.
191
//(Mouse events should go to windows in zorder, shouldn't they?)
192
for
(
size_t
i
= 0;
i
<
m_windows
.size();
i
++) {
193
if
(
m_windows
[
i
]->controller() )
194
m_windows
[
i
]->controller()->draw();
195
if
(
i
<
m_windows
.size() )
m_windows
[
i
]->
draw
();
196
}
197
//Emulate EndGUIFrame.
198
static
VSSprite
MouseVSSprite(
"mouse.spr"
,
BILINEAR
,
GFXTRUE
);
199
static
Texture
dummy(
"white.bmp"
, 0,
NEAREST
,
TEXTURE2D
,
TEXTURE_2D
,
GFXTRUE
);
200
GFXDisable
(
CULLFACE
);
201
ConditionalCursorDraw
(
true
);
202
//Figure position of cursor sprite.
203
float
sizex = 0.0, sizey = 0.0;
204
const
Point
loc =
globalEventManager
().
mouseLoc
();
205
MouseVSSprite.
GetSize
( sizex, sizey );
206
float
tempx = 0.0, tempy = 0.0;
207
MouseVSSprite.
GetPosition
( tempx, tempy );
208
MouseVSSprite.
SetPosition
( tempx+loc.
x
+sizex/2, tempy+loc.
y
+sizey/2 );
209
210
dummy.
MakeActive
();
211
GFXBlendMode
(
SRCALPHA
,
INVSRCALPHA
);
212
GFXColorf
(
GUI_OPAQUE_WHITE
() );
213
214
//Draw the cursor sprite.
215
GFXEnable
(
TEXTURE0
);
216
GFXDisable
(
DEPTHTEST
);
217
GFXDisable
(
TEXTURE1
);
218
MouseVSSprite.
Draw
();
219
220
GFXHudMode
(
false
);
221
GFXEnable
(
CULLFACE
);
222
MouseVSSprite.
SetPosition
( tempx, tempy );
223
}
224
225
//A new window has been created and is ready to be drawn.
226
void
WindowManager::openWindow
(
Window
*w )
227
{
228
m_windows
.push_back( w );
229
globalEventManager
().
pushResponder
( w );
230
}
231
232
//A window has been closed.
233
void
WindowManager::closeWindow
(
Window
*w,
//Old window.
234
bool
deleteWindow
//True = delete window.
235
)
236
{
237
vector< Window* >::iterator iter;
238
for
(iter =
m_windows
.begin(); iter !=
m_windows
.end(); iter++)
239
if
( (*iter) == w ) {
240
m_windows
.erase( iter );
241
globalEventManager
().
removeResponder
( w );
//Have to do this now.
242
if
(deleteWindow)
243
EventManager::addToDeleteQueue
( w );
244
break
;
245
}
246
}
247
248
//Close all windows.
249
void
WindowManager::shutDown
(
void
)
250
{
251
while
(
m_windows
.size() > 0)
252
m_windows
.back()->close();
253
//m_windows.erase(m_windows.begin());
254
}
255
256
//Pointer to the one, global window manager.
257
WindowManager
*
globalWindowManagerPtr
= NULL;
258
259
//Get the one window manager.
260
WindowManager
&
globalWindowManager
(
void
)
261
{
262
if
(globalWindowManagerPtr == NULL)
263
globalWindowManagerPtr =
new
WindowManager
;
264
return
*
globalWindowManagerPtr
;
265
}
266
src
gui
window.cpp
Generated on Fri May 29 2015 23:07:33 for Vegastrike 0.5.1 rc1 by
1.8.4