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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
|
//=========== Copyright Valve Corporation, All rights reserved. ===============//
//
// Purpose:
//=============================================================================//
#ifndef BACKGROUNDIMAGE_H
#define BACKGROUNDIMAGE_H
#ifdef _WIN32
#pragma once
#endif
#include "csshelpers.h"
#include "../data/panoramavideoplayer.h"
#include "utlstring.h"
#include "uilength.h"
namespace panorama
{
class IImageSource;
class CMovie;
class CPanel2D;
//-----------------------------------------------------------------------------
// Purpose: Background position for background image
//-----------------------------------------------------------------------------
class CBackgroundPosition
{
public:
CBackgroundPosition();
~CBackgroundPosition() {}
EHorizontalAlignment GetHorizontalAlignment() const { return m_eHorizontalAlignment; }
CUILength GetHorizontalLength() const { return m_horizontal; }
EVerticalAlignment GetVeriticalAlignment() const { return m_eVerticalAlignment; }
CUILength GetVerticalLength() const { return m_vertical; }
bool IsHorizontalSet() const
{
return ( m_eHorizontalAlignment != k_EHorizontalAlignmentUnset && m_horizontal.IsSet() );
}
bool IsVerticalSet() const
{
return ( m_eVerticalAlignment != k_EVerticalAlignmentUnset && m_vertical.IsSet() );
}
bool IsSet() const
{
return ( IsHorizontalSet() && IsVerticalSet() );
}
void Set( EHorizontalAlignment eHorizontal, const CUILength &horizontal, EVerticalAlignment eVertical, const CUILength &vertical );
void ResolveDefaultValues();
void ToString( CFmtStr1024 *pfmtBuffer );
void ScaleLengthValues( float flScaleFactor )
{
m_horizontal.ScaleLengthValue( flScaleFactor );
m_vertical.ScaleLengthValue( flScaleFactor );
}
bool operator==( const CBackgroundPosition &rhs ) const
{
return ( m_eHorizontalAlignment == rhs.m_eHorizontalAlignment && m_horizontal == rhs.m_horizontal && m_eVerticalAlignment == rhs.m_eVerticalAlignment && m_vertical == rhs.m_vertical );
}
bool operator!=( const CBackgroundPosition &rhs ) const
{
return !( *this == rhs );
}
private:
EHorizontalAlignment m_eHorizontalAlignment;
CUILength m_horizontal;
EVerticalAlignment m_eVerticalAlignment;
CUILength m_vertical;
};
//-----------------------------------------------------------------------------
// Purpose: Background images have a repeat in the x & y directions
//-----------------------------------------------------------------------------
class CBackgroundRepeat
{
public:
CBackgroundRepeat() { Set( k_EBackgroundRepeatUnset, k_EBackgroundRepeatUnset ); }
~CBackgroundRepeat() {}
bool IsSet() const { return (m_eHorizontal != k_EBackgroundRepeatUnset && m_eVertical != k_EBackgroundRepeatUnset); }
void Set( EBackgroundRepeat eHorizontal, EBackgroundRepeat eVertical )
{
m_eHorizontal = eHorizontal;
m_eVertical = eVertical;
}
void ResolveDefaultValues()
{
if ( m_eHorizontal == k_EBackgroundRepeatUnset )
m_eHorizontal = k_EBackgroundRepeatRepeat;
if ( m_eVertical == k_EBackgroundRepeatUnset )
m_eVertical = k_EBackgroundRepeatRepeat;
}
EBackgroundRepeat GetHorizontal() const { return m_eHorizontal; }
EBackgroundRepeat GetVertical() const { return m_eVertical; }
bool operator==( const CBackgroundRepeat &rhs ) const
{
return ( m_eHorizontal == rhs.m_eHorizontal && m_eVertical == rhs.m_eVertical );
}
bool operator!=( const CBackgroundRepeat &rhs ) const
{
return !( *this == rhs );
}
private:
EBackgroundRepeat m_eHorizontal;
EBackgroundRepeat m_eVertical;
};
//-----------------------------------------------------------------------------
// Purpose: Can have multiple background image layers, each contains the following
//-----------------------------------------------------------------------------
class CBackgroundImageLayer
{
private:
enum EImagePath
{
k_EImagePathUnset,
k_EImagePathNone,
k_EImagePathSet
};
public:
CBackgroundImageLayer();
~CBackgroundImageLayer();
void SetPathUnset()
{
m_eImagePath = k_EImagePathUnset;
m_sURLPath.Clear();
}
void SetPathToNone()
{
m_eImagePath = m_eImagePath;
m_sURLPath.Clear();
}
void SetPath( const char *pchPath )
{
m_eImagePath = k_EImagePathSet;
m_sURLPath = pchPath;
}
bool IsPathSet() { return (m_eImagePath != k_EImagePathUnset); }
bool IsPathNone() { return (m_eImagePath == k_EImagePathNone); }
const char *GetPath() { return m_sURLPath.String(); }
// from background-position
const CBackgroundPosition &GetPosition() { return m_position; }
void SetPosition( const CBackgroundPosition &position ) { m_position = position; }
const CUILength &GetWidth() { return m_width; }
const CUILength &GetHeight() { return m_height; }
void SetBackgroundSize( const CUILength &width, const CUILength &height )
{
m_width = width;
m_height = height;
m_eBackgroundSizeConstant = k_EBackgroundSizeConstantNone;
}
EBackgroundSizeConstant GetBackgroundSizeConstant() { return m_eBackgroundSizeConstant; }
void SetBackgroundSize( EBackgroundSizeConstant eConstant )
{
Assert( eConstant != k_EBackgroundSizeConstantNone );
m_eBackgroundSizeConstant = eConstant;
m_width.SetLength( k_flFloatAuto );
m_height.SetLength( k_flFloatAuto );
}
CBackgroundRepeat GetRepeat() { return m_repeat; }
void SetRepeat( const CBackgroundRepeat &repeat ) { m_repeat = repeat; }
IImageSource *GetImage() { return m_pImage; }
CVideoPlayerPtr GetMovie() { return m_pVideoPlayer; }
bool IsCompletelyUnset()
{
return (m_eImagePath == k_EImagePathUnset && !m_position.IsSet() && !m_width.IsSet() && !m_height.IsSet() && !m_repeat.IsSet() );
}
bool IsSet()
{
return (m_eImagePath != k_EImagePathUnset && m_position.IsSet() && m_width.IsSet() && m_height.IsSet() && m_repeat.IsSet() );
}
void ResolveDefaultValues();
void ApplyUIScaleFactor( float flScaleFactor );
void OnAppliedToPanel( IUIPanel *pPanel );
void MergeTo( CBackgroundImageLayer *pTarget );
void ToString( CFmtStr1024 *pfmtBuffer );
// comparison operators
bool operator==( const CBackgroundImageLayer &rhs ) const
{
return ( m_eImagePath == rhs.m_eImagePath && m_sURLPath == rhs.m_sURLPath && m_position == rhs.m_position &&
m_width == rhs.m_width&& m_height == rhs.m_height && m_repeat == rhs.m_repeat && m_eBackgroundSizeConstant == rhs.m_eBackgroundSizeConstant );
}
bool operator!=( const CBackgroundImageLayer &rhs ) const
{
return !( *this == rhs );
}
// helpers for drawing
void CalculateFinalDimensions( float *pflWidth, float *pflHeight, float flPanelWidth, float flPanelHeight, float flScaleFactor );
void CalculateFinalPosition( float *px, float *py, float flWidthPanel, float flHeightPanel, float flWidthImage, float flHeightImage );
void CalculateFinalSpacing( float *px, float *py, float flWidthPanel, float flHeightPanel, float flWidthImage, float flHeightImage );
void Set( const CBackgroundImageLayer &rhs );
#ifdef DBGFLAG_VALIDATE
virtual void Validate( CValidator &validator, const tchar *pchName );
#endif
private:
CBackgroundImageLayer( const CBackgroundImageLayer &rhs );
CBackgroundImageLayer& operator=( const CBackgroundImageLayer &rhs ) const;
// from background-image
CUtlString m_sURLPath;
EImagePath m_eImagePath;
// from background-position
CBackgroundPosition m_position;
// from background-size
EBackgroundSizeConstant m_eBackgroundSizeConstant;
CUILength m_width;
CUILength m_height;
// from background-repeat
CBackgroundRepeat m_repeat;
// loaded when applied to a panel
IImageSource *m_pImage;
CVideoPlayerPtr m_pVideoPlayer;
};
} // namespace panorama
#endif //BACKGROUNDIMAGE_H
|