/
_types_unused.hpp
174 lines (142 loc) · 5.45 KB
/
_types_unused.hpp
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
// This file is distributed under a BSD license. See LICENSE.txt for details.
#ifndef __TYPES_UNUSED_HPP__
#define __TYPES_UNUSED_HPP__
/****************************************************************************/
/*** ***/
/*** Forwards ***/
/*** ***/
/****************************************************************************/
struct sColor;
/****************************************************************************/
struct sDate
{
sU16 Day; // 0..364 / 365 day of year
sU16 Year; // 1..65535 year AD
sU16 Minute; // 0..1439 minute of day
sU16 Millisecond; // 0..59999 millisecond of minute
void RoundDay(); // clear minute and millisecond to zero
void Sub(sDate &a,sDate &b); // get difference of two dates
void Add(sDate &a,sDate &b); // add difference b to date a
sInt DaysOfYear(); // gets days per year.
void SetMonth(sInt m,sInt d); // m=0..11, d=0..27/30 sets by month and day of month
void GetMonth(sInt &m,sInt &d); // m=0..11, d=0..27/30 gets month and day of month
void PrintDate(sChar *); // 2002-dec-31
void Printime(sChar *); // 23:59
void ReadDate(sChar *); // 2002-dec-31
void ReadTime(sChar *); // 23:59
};
/****************************************************************************/
struct sColor
{
union
{
sU32 Color;
struct
{
sU8 b,g,r,a;
};
sU8 bgra[4];
};
__forceinline sColor(sU32 c) { Color = c; }
__forceinline sColor() {}
__forceinline operator unsigned long () { return Color; }
__forceinline void Init(sU8 R,sU8 G,sU8 B) { Color = B|(G<<8)|(R<<16)|0xff000000; };
__forceinline void Init(sU8 R,sU8 G,sU8 B,sU32 A) { Color = B|(G<<8)|(R<<16)|(A<<24); };
void Fade(sF32 fade,sColor c0,sColor c1);
void Fade(sInt fade,sColor c0,sColor c1);
};
/****************************************************************************/
struct sPlacer // places gui elements in a grid
{
sInt XPos; // rect to place the elements in
sInt YPos;
sInt XSize;
sInt YSize;
sInt XDiv; // number of divisions in x-axxis
sInt YDiv; // number of divisions in y-axxis
void Init(sRect &r,sInt xdiv,sInt ydiv);
void Div(sRect &r,sInt x,sInt y,sInt xs=1,sInt ys=1);
};
/****************************************************************************/
/*** ***/
/*** StringSet ***/
/*** ***/
/****************************************************************************/
struct sStringSetEntry
{
sChar *String;
sObject *Object;
};
struct sStringSet
{
private:
sInt FindNr(sChar *string);
public:
sArray<sStringSetEntry> Set;
void Init(); // create
void Exit(); // destroy
void Clear();
sObject *Find(sChar *string); // find object set for string
sBool Add(sChar *string,sObject *); // add object/string pair. return sTRUE if already in list. overwites
};
/****************************************************************************/
/*** ***/
/*** RangeCoder ***/
/*** ***/
/****************************************************************************/
class sRangeCoder
{
sU32 Low;
sU32 Code;
sU32 Range;
sU32 Bytes;
sU8 *Buffer;
public:
void InitEncode(sU8 *buffer);
void FinishEncode();
void Encode(sU32 cumfreq,sU32 freq,sU32 totfreq);
void EncodePlain(sU32 value,sU32 max);
void EncodeGamma(sU32 value);
void InitDecode(sU8 *buffer);
sU32 GetFreq(sU32 totfreq);
void Decode(sU32 cumfreq,sU32 freq);
sU32 DecodePlain(sU32 max);
sU32 DecodeGamma();
sU32 GetBytes() { return Bytes; }
};
/****************************************************************************/
class sRangeModel
{
sInt *Freq;
sInt Symbols;
sInt TotFreq;
void Update(sInt symbol);
public:
void Init(sInt symbols);
void Exit() { delete[] Freq; }
void Encode(sRangeCoder &coder,sInt symbol);
sInt Decode(sRangeCoder &coder);
};
/****************************************************************************/
/****************************************************************************/
/*** ***/
/*** Rectangle Packer ***/
/*** ***/
/****************************************************************************/
class sRectPacker
{
sRect Size;
sArray<sInt> Anchors;
sArray<sInt> *Lines;
sInt AreaUsed,Thresh;
sBool IsFree(sRect &r);
void AddAnchor(sInt x,sInt y);
void AddRect(sRect &r);
public:
void Init(sInt w=128,sInt h=128);
void Exit();
sBool PackRect(sRect &r);
sF32 GetRelativeAreaUsed();
};
/****************************************************************************/
#endif