Bubba-3D  0.9.0
Awesome game engine!
Dimension.cpp
1 /*
2  * This file is part of Bubba-3D.
3  *
4  * Bubba-3D is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Bubba-3D is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with Bubba-3D. If not, see http://www.gnu.org/licenses/.
16  */
17 //
18 // Created by simon on 2016-02-06.
19 //
20 
21 #include "Dimension.h"
22 
23 float Dimension::getSize(float room){
24  if(unit == PIXELS)
25  return (float)pixels;
26  if(unit == PERCENTAGE)
27  return room*percentage/100.0f;
28  if(unit == PERCENTAGE_PLUS_PIXELS)
29  return room*percentage/100.0f + (float)pixels;
30  throw "undecidable";
31 }
32 
34  Dimension dim = Dimension(PERCENTAGE);
35  dim.percentage = percentage;
36  return dim;
37 }
38 
40  Dimension dim = Dimension(PIXELS);
41  dim.pixels = pixels;
42  return dim;
43 }
44 
45 Dimension Dimension::fromPercentagePlusPixels(float percentage, int pixels) {
46  Dimension dim = Dimension(PERCENTAGE_PLUS_PIXELS);
47  dim.percentage = percentage;
48  dim.pixels = pixels;
49  return dim;
50 }
51 
53  return fill(1);
54 }
55 
56 Dimension Dimension::fill(unsigned int weight){
57  Dimension dim = Dimension(FILL);
58  dim.weight = weight;
59  return dim;
60 }
61 
63  return Dimension(WRAP);
64 }
65 
66 Dimension::DimensionUnit Dimension::getUnit() {
67  return unit;
68 }
69 
71  return weight;
72 }
73 
75  return pixels;
76 }
77 
79  return percentage;
80 }
81 
82 Dimension::Dimension(DimensionUnit unit) {
83  this->unit = unit;
84 }
85 
87  pixels = 0;
88 }
float getPercentage()
Definition: Dimension.cpp:78
int getWeight()
Definition: Dimension.cpp:70
float getSize(float room)
Definition: Dimension.cpp:23
static Dimension fromPixels(int pixels)
Definition: Dimension.cpp:39
static Dimension wrap()
Definition: Dimension.cpp:62
static Dimension fill()
Definition: Dimension.cpp:52
static Dimension fromPercentagePlusPixels(float percentage, int pixels)
Definition: Dimension.cpp:45
DimensionUnit getUnit()
Definition: Dimension.cpp:66
int getPixels()
Definition: Dimension.cpp:74
static Dimension fromPercentage(float percentage)
Definition: Dimension.cpp:33