1#include "skin.h"
2
3#include <base/math.h>
4#include <base/system.h>
5
6#include <limits>
7
8void CSkin::CSkinTextures::Reset()
9{
10 m_Body = IGraphics::CTextureHandle();
11 m_BodyOutline = IGraphics::CTextureHandle();
12 m_Feet = IGraphics::CTextureHandle();
13 m_FeetOutline = IGraphics::CTextureHandle();
14 m_Hands = IGraphics::CTextureHandle();
15 m_HandsOutline = IGraphics::CTextureHandle();
16 for(auto &Eye : m_aEyes)
17 {
18 Eye = IGraphics::CTextureHandle();
19 }
20}
21
22void CSkin::CSkinTextures::Unload(IGraphics *pGraphics)
23{
24 pGraphics->UnloadTexture(pIndex: &m_Body);
25 pGraphics->UnloadTexture(pIndex: &m_BodyOutline);
26 pGraphics->UnloadTexture(pIndex: &m_Feet);
27 pGraphics->UnloadTexture(pIndex: &m_FeetOutline);
28 pGraphics->UnloadTexture(pIndex: &m_Hands);
29 pGraphics->UnloadTexture(pIndex: &m_HandsOutline);
30 for(auto &Eye : m_aEyes)
31 {
32 pGraphics->UnloadTexture(pIndex: &Eye);
33 }
34}
35
36CSkin::CSkinMetricVariableInt::operator int() const
37{
38 return m_Value;
39}
40
41CSkin::CSkinMetricVariableInt &CSkin::CSkinMetricVariableInt::operator=(int NewVal)
42{
43 m_Value = minimum(a: m_Value, b: NewVal);
44 return *this;
45}
46
47CSkin::CSkinMetricVariableInt::CSkinMetricVariableInt()
48{
49 Reset();
50}
51
52void CSkin::CSkinMetricVariableInt::Reset()
53{
54 m_Value = std::numeric_limits<int>::max();
55}
56
57CSkin::CSkinMetricVariableSize::operator int() const
58{
59 return m_Value;
60}
61
62CSkin::CSkinMetricVariableSize &CSkin::CSkinMetricVariableSize::operator=(int NewVal)
63{
64 m_Value = maximum(a: m_Value, b: NewVal);
65 return *this;
66}
67
68CSkin::CSkinMetricVariableSize::CSkinMetricVariableSize()
69{
70 Reset();
71}
72
73void CSkin::CSkinMetricVariableSize::Reset()
74{
75 m_Value = std::numeric_limits<int>::lowest();
76}
77
78float CSkin::CSkinMetricVariable::WidthNormalized() const
79{
80 return (float)m_Width / (float)m_MaxWidth;
81}
82
83float CSkin::CSkinMetricVariable::HeightNormalized() const
84{
85 return (float)m_Height / (float)m_MaxHeight;
86}
87
88float CSkin::CSkinMetricVariable::OffsetXNormalized() const
89{
90 return (float)m_OffsetX / (float)m_MaxWidth;
91}
92
93float CSkin::CSkinMetricVariable::OffsetYNormalized() const
94{
95 return (float)m_OffsetY / (float)m_MaxHeight;
96}
97
98void CSkin::CSkinMetricVariable::Reset()
99{
100 m_Width.Reset();
101 m_Height.Reset();
102 m_OffsetX.Reset();
103 m_OffsetY.Reset();
104 m_MaxWidth.Reset();
105 m_MaxHeight.Reset();
106}
107
108CSkin::CSkinMetrics::CSkinMetrics()
109{
110 Reset();
111}
112
113void CSkin::CSkinMetrics::Reset()
114{
115 m_Body.Reset();
116 m_Feet.Reset();
117}
118
119bool CSkin::operator<(const CSkin &Other) const
120{
121 return str_comp(a: m_aName, b: Other.m_aName) < 0;
122}
123
124bool CSkin::operator==(const CSkin &Other) const
125{
126 return !str_comp(a: m_aName, b: Other.m_aName);
127}
128
129CSkin::CSkin(const char *pName)
130{
131 str_copy(dst&: m_aName, src: pName);
132}
133
134// has to be kept in sync with m_aSkinNameRestrictions
135bool CSkin::IsValidName(const char *pName)
136{
137 if(str_length(str: pName) >= (int)sizeof(CSkin("").m_aName))
138 {
139 return false;
140 }
141
142 return str_valid_filename(str: pName);
143}
144
145const char CSkin::m_aSkinNameRestrictions[] = "Skin names must be valid filenames shorter than 24 characters.";
146