percentagebar.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <guichan/rectangle.hpp>
00030 #include <guichan/graphics.hpp>
00031
00032
00033
00034
00035
00036 #include "percentagebar.hpp"
00037
00038 namespace gcn
00039 {
00040
00041 PercentageBar::PercentageBar()
00042 {
00043 mImage = 0;
00044
00045 setOrientation(HORIZONTAL);
00046 setValue(0);
00047 }
00048
00049 void PercentageBar::draw(Graphics* graphics)
00050 {
00051 graphics->setColor(getForegroundColor());
00052
00053 if (getOrientation() == HORIZONTAL)
00054 {
00055 graphics->fillRectangle(gcn::Rectangle(0,0,getWidth() * mValue/100,getHeight()));
00056 }
00057 else
00058 {
00059 graphics->fillRectangle(gcn::Rectangle(0,getHeight()-getHeight() * mValue/100,getWidth(),getHeight() * mValue/100));
00060 }
00061
00062
00063 if ( mImage )
00064 graphics->drawImage(mImage, 0, 0);
00065
00066 }
00067
00068 void PercentageBar::setForegroundImage(Image* image)
00069 {
00070 mImage = image;
00071 if( mImage ) {
00072 setHeight(image->getHeight());
00073 setWidth(image->getWidth());
00074 }
00075 }
00076
00077 void PercentageBar::setValue(int value)
00078 {
00079 if (value > 100)
00080 {
00081 mValue = 100;
00082 return;
00083 }
00084
00085 if (value < 0)
00086 {
00087 mValue = 0;
00088 return;
00089 }
00090
00091 mValue = value;
00092 }
00093
00094 int PercentageBar::getValue() const
00095 {
00096 return mValue;
00097 }
00098
00099 void PercentageBar::setOrientation(PercentageBar::Orientation orientation)
00100 {
00101 mOrientation = orientation;
00102 }
00103
00104 PercentageBar::Orientation PercentageBar::getOrientation() const
00105 {
00106 return mOrientation;
00107 }
00108 }