FIFE  be64c707dea6b3250bd4355bf5c825d25920087d
percentagebar.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2019 by the FIFE team *
3  * http://www.fifengine.net *
4  * This file is part of FIFE. *
5  * *
6  * FIFE is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20  ***************************************************************************/
21 
22 /*
23  * For comments regarding functions please see the header file.
24  */
25 
26 // Standard C++ library includes
27 
28 // 3rd party library includes
29 #include <fifechan/rectangle.hpp>
30 #include <fifechan/graphics.hpp>
31 
32 // FIFE includes
33 // These includes are split up in two parts, separated by one empty line
34 // First block: files included from the FIFE root src directory
35 // Second block: files included from the same folder
36 #include "percentagebar.h"
37 
38 namespace fcn
39 {
40 
42  {
43  mImage = 0;
44 
46  setValue(0);
47  }
48 
49  void PercentageBar::draw(Graphics* graphics)
50  {
51  graphics->setColor(getForegroundColor());
52 
53  if (getOrientation() == HORIZONTAL)
54  {
55  graphics->fillRectangle(fcn::Rectangle(0,0,getWidth() * mValue/100,getHeight()));
56  }
57  else
58  {
59  graphics->fillRectangle(fcn::Rectangle(0,getHeight()-getHeight() * mValue/100,getWidth(),getHeight() * mValue/100));
60  }
61 
62 
63  if ( mImage )
64  graphics->drawImage(mImage, 0, 0);
65 
66  }
67 
69  {
70  mImage = image;
71  if( mImage ) {
72  setHeight(image->getHeight());
73  setWidth(image->getWidth());
74  }
75  }
76 
77  void PercentageBar::setValue(int32_t value)
78  {
79  if (value > 100)
80  {
81  mValue = 100;
82  return;
83  }
84 
85  if (value < 0)
86  {
87  mValue = 0;
88  return;
89  }
90 
91  mValue = value;
92  }
93 
94  int32_t PercentageBar::getValue() const
95  {
96  return mValue;
97  }
98 
100  {
101  mOrientation = orientation;
102  }
103 
105  {
106  return mOrientation;
107  }
108 }
void setForegroundImage(Image *image)
void setOrientation(Orientation orientation)
Sets the orientation of the percentage bar.
virtual void draw(Graphics *graphics)
double mValue
Holds the current value of the percentage bar.
Orientation mOrientation
Holds the orientation of the percentage bar.
PercentageBar()
Constructor.
void setValue(int32_t value)
Sets the value of the percentage bar.
Orientation getOrientation() const
Gets the orientation of the percentage bar.
int32_t getValue() const
Gets the value of the percentage bar.