Starshatter_Open
Open source Starshatter engine
Main Page
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
DisplayView.cpp
Go to the documentation of this file.
1
/* Project Starshatter 4.5
2
Destroyer Studios LLC
3
Copyright © 1997-2004. All Rights Reserved.
4
5
SUBSYSTEM: Stars.exe
6
FILE: DisplayView.cpp
7
AUTHOR: John DiCamillo
8
9
10
OVERVIEW
11
========
12
View class for Quantum Destination HUD Overlay
13
*/
14
15
#include "
MemDebug.h
"
16
#include "
DisplayView.h
"
17
#include "
QuantumDrive.h
"
18
#include "
HUDView.h
"
19
#include "
Ship.h
"
20
#include "
Element.h
"
21
#include "
Sim.h
"
22
#include "
StarSystem.h
"
23
#include "
FormatUtil.h
"
24
25
#include "
Color.h
"
26
#include "
Window.h
"
27
#include "
Video.h
"
28
#include "
Screen.h
"
29
#include "
DataLoader.h
"
30
#include "
Scene.h
"
31
#include "
Font.h
"
32
#include "
FontMgr.h
"
33
#include "
Keyboard.h
"
34
#include "
Mouse.h
"
35
#include "
Game.h
"
36
#include "
Menu.h
"
37
38
// +====================================================================+
39
40
class
DisplayElement
41
{
42
public
:
43
static
const
char
*
TYPENAME
() {
return
"DisplayElement"
; }
44
45
DisplayElement
() :
image
(0),
font
(0),
blend
(0),
hold
(0),
fade_in
(0),
fade_out
(0) { }
46
47
Text
text
;
48
Bitmap
*
image
;
49
Font
*
font
;
50
Color
color
;
51
Rect
rect
;
52
int
blend
;
53
double
hold
;
54
double
fade_in
;
55
double
fade_out
;
56
};
57
58
// +====================================================================+
59
60
DisplayView
*
display_view
= 0;
61
62
DisplayView::DisplayView
(
Window
* c)
63
:
View
(c), width(0), height(0), xcenter(0), ycenter(0)
64
{
65
display_view =
this
;
66
DisplayView::OnWindowMove
();
67
}
68
69
DisplayView::~DisplayView
()
70
{
71
if
(display_view ==
this
)
72
display_view = 0;
73
74
elements
.
destroy
();
75
}
76
77
DisplayView
*
78
DisplayView::GetInstance
()
79
{
80
if
(display_view == 0)
81
display_view =
new
DisplayView
(0);
82
83
return
display_view
;
84
}
85
86
void
87
DisplayView::OnWindowMove
()
88
{
89
if
(
window
) {
90
width
=
window
->
Width
();
91
height
=
window
->
Height
();
92
xcenter
= (
width
/ 2.0) - 0.5;
93
ycenter
= (
height
/ 2.0) + 0.5;
94
}
95
}
96
97
// +--------------------------------------------------------------------+
98
99
void
100
DisplayView::Refresh
()
101
{
102
ListIter<DisplayElement>
iter =
elements
;
103
while
(++iter) {
104
DisplayElement
* elem = iter.
value
();
105
106
// convert relative rect to window rect:
107
Rect
elem_rect = elem->
rect
;
108
if
(elem_rect.
x
== 0 && elem_rect.
y
== 0 && elem_rect.
w
== 0 && elem_rect.
h
== 0) {
109
// stretch to fit
110
elem_rect.
w
=
width
;
111
elem_rect.
h
=
height
;
112
}
113
else
if
(elem_rect.
w
< 0 && elem_rect.
h
< 0) {
114
// center image in window
115
elem_rect.
w
*= -1;
116
elem_rect.
h
*= -1;
117
118
elem_rect.
x
= (
width
- elem_rect.
w
)/2;
119
elem_rect.
y
= (
height
- elem_rect.
h
)/2;
120
}
121
else
{
122
// offset from right or bottom
123
if
(elem_rect.
x
< 0) elem_rect.
x
+=
width
;
124
if
(elem_rect.
y
< 0) elem_rect.
y
+=
height
;
125
}
126
127
// compute current fade,
128
// assumes fades are 1 second or less:
129
double
fade = 0;
130
if
(elem->
fade_in
> 0) fade = 1 - elem->
fade_in
;
131
else
if
(elem->
hold
> 0) fade = 1;
132
else
if
(elem->
fade_out
> 0) fade = elem->
fade_out
;
133
134
// draw text:
135
if
(elem->
text
.
length
() && elem->
font
) {
136
elem->
font
->
SetColor
(elem->
color
);
137
elem->
font
->
SetAlpha
(fade);
138
window
->
SetFont
(elem->
font
);
139
window
->
DrawText
(elem->
text
, elem->
text
.
length
(), elem_rect, DT_WORDBREAK);
140
}
141
142
// draw image:
143
else
if
(elem->
image
) {
144
window
->
FadeBitmap
( elem_rect.
x
,
145
elem_rect.
y
,
146
elem_rect.
x
+ elem_rect.
w
,
147
elem_rect.
y
+ elem_rect.
h
,
148
elem->
image
,
149
elem->
color
* fade,
150
elem->
blend
);
151
152
}
153
}
154
}
155
156
// +--------------------------------------------------------------------+
157
158
void
159
DisplayView::ExecFrame
()
160
{
161
double
seconds =
Game::GUITime
();
162
163
ListIter<DisplayElement>
iter =
elements
;
164
while
(++iter) {
165
DisplayElement
* elem = iter.
value
();
166
167
if
(elem->
fade_in
> 0)
168
elem->
fade_in
-= seconds;
169
170
else
if
(elem->
hold
> 0)
171
elem->
hold
-= seconds;
172
173
else
if
(elem->
fade_out
> 0)
174
elem->
fade_out
-= seconds;
175
176
else
177
delete
iter.
removeItem
();
178
}
179
}
180
181
// +--------------------------------------------------------------------+
182
183
void
184
DisplayView::ClearDisplay
()
185
{
186
elements
.
destroy
();
187
}
188
189
// +--------------------------------------------------------------------+
190
191
void
192
DisplayView::AddText
(
const
char
* text,
193
Font
* font,
194
Color
color,
195
const
Rect
& rect,
196
double
hold,
197
double
fade_in,
198
double
fade_out)
199
{
200
DisplayElement
* elem =
new
(__FILE__,__LINE__)
DisplayElement
;
201
202
if
(fade_in == 0 && fade_out == 0 && hold == 0)
203
hold = 300;
204
205
elem->
text
= text;
206
elem->
font
= font;
207
elem->
color
= color;
208
elem->
rect
= rect;
209
elem->
hold
= hold;
210
elem->
fade_in
= fade_in;
211
elem->
fade_out
= fade_out;
212
213
elements
.
append
(elem);
214
}
215
216
void
217
DisplayView::AddImage
(
Bitmap
* bmp,
218
Color
color,
219
int
blend,
220
const
Rect
& rect,
221
double
hold,
222
double
fade_in,
223
double
fade_out)
224
{
225
DisplayElement
* elem =
new
(__FILE__,__LINE__)
DisplayElement
;
226
227
if
(fade_in == 0 && fade_out == 0 && hold == 0)
228
hold = 300;
229
230
elem->
image
= bmp;
231
elem->
rect
= rect;
232
elem->
color
= color;
233
elem->
blend
= blend;
234
elem->
hold
= hold;
235
elem->
fade_in
= fade_in;
236
elem->
fade_out
= fade_out;
237
238
elements
.
append
(elem);
239
}
Stars45
DisplayView.cpp
Generated on Tue Jun 5 2012 20:46:51 for Starshatter_Open by
1.8.1