17 #include <linmath/float2.h> 18 #include <linmath/float3.h> 19 #include <linmath/float4.h> 21 #include <Dimension.h> 22 #include "HUDGraphic.h" 30 texture(texture), textureElseColor(true) {}
34 float3 HUDGraphic::getCenterOffset(
float width,
float height) {
35 return make_vector(offsetX.
getSize(width), offsetY.
getSize(height), 0.0f);
39 this->offsetX = offsetX;
40 this->offsetY = offsetY;
45 this->texturePosition = texturePosition;
54 float width = 1.0f, height = 1.0f;
56 width = texture->getWidth();
57 height = texture->getHeight();
60 (float) tp.topRightX / width, (
float) tp.topRightY / height);
71 throw std::runtime_error(
"This graphic doesn't have a texture.");
76 return textureElseColor;
81 throw std::runtime_error(
"This graphic doesn't have a solid color.");
86 return setBorder(pixels, pixels, borderColor);
89 HUDGraphic* HUDGraphic::setBorder(
int botAndTop,
int leftAndRight,
Color borderColor) {
90 return setBorder(botAndTop, leftAndRight, botAndTop, leftAndRight, borderColor);
93 HUDGraphic* HUDGraphic::setBorder(
int top,
int right,
int bot,
int left,
Color borderColor) {
94 this->borderColor = borderColor.
getColor();
110 HUDGraphic* HUDGraphic::setRoundedCorners(
int pixels){
111 return setRoundedCorners(pixels, pixels, pixels, pixels);
114 HUDGraphic* HUDGraphic::setRoundedCorners(
int topLeft,
int topRight,
int botRight,
int botLeft) {
115 roundedCorners[0] = topLeft;
116 roundedCorners[1] = topRight;
117 roundedCorners[2] = botLeft;
118 roundedCorners[3] = botRight;
123 return roundedCorners;
126 HUDGraphic* HUDGraphic::setBorderSize(
int top,
int right,
int bot,
int left) {
128 this->borders[0] = top;
130 this->borders[1] = right;
132 this->borders[2] = bot;
134 this->borders[3] = left;
139 this->borderColor = borderColor.
getColor();
144 textureElseColor =
false;
150 textureElseColor =
true;
151 this->texture = texture;
156 :
Color(make_vector((float)red / 255.0f,
157 (float)green / 255.0f,
158 (float)blue / 255.0f, opacity))
173 if(hexString.length() == 0) {
174 throw std::invalid_argument(
"The color hexString can't be empty in HUDGraphic::Color::Color().");
177 if(hexString[0] ==
'#') {
178 hexString = hexString.substr(1,hexString.length()-1);
181 if (hexString.find_first_not_of(
"0123456789abcdefABCDEF", 0) != std::string::npos) {
182 throw std::invalid_argument(
"The color hexString can only contain: 0-9, a-f or A-F.");
187 if (hexString.length() == 3) {
190 }
else if (hexString.length() == 6) {
194 throw std::invalid_argument(
"The color hexString has to be of length 3 or 6 in HUDGraphic::Color::Color().");
197 hexStringToFloat(hexString, 0, valLen, &color.x);
198 hexStringToFloat(hexString, valLen*1, valLen, &color.y);
199 hexStringToFloat(hexString, valLen*2, valLen, &color.z);
205 void HUDGraphic::Color::hexStringToFloat(std::string hexString,
unsigned int pos,
unsigned int len,
float* target){
207 std::stringstream(hexString.substr(pos,len)) >> std::hex >> temp;
208 *target = (float)temp;
float getSize(float room)
HUDGraphic * setCenterOffset(Dimension offsetX, Dimension offsetY)
Color(std::string hexString)
chag::float4 getBorderColor()
bool isTextureElseColor()
HUDGraphic * setTexturePosition(TexturePosition< int > texturePosition)
HUDGraphic(Texture *texture)
int * getRoundedCorners()