FIFE
2008.0
|
00001 /*************************************************************************** 00002 * Copyright (C) 2005-2010 by the FIFE team * 00003 * http://www.fifengine.net * 00004 * This file is part of FIFE. * 00005 * * 00006 * FIFE is free software; you can redistribute it and/or * 00007 * modify it under the terms of the GNU Lesser General Public * 00008 * License as published by the Free Software Foundation; either * 00009 * version 2.1 of the License, or (at your option) any later version. * 00010 * * 00011 * This library is distributed in the hope that it will be useful, * 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00014 * Lesser General Public License for more details. * 00015 * * 00016 * You should have received a copy of the GNU Lesser General Public * 00017 * License along with this library; if not, write to the * 00018 * Free Software Foundation, Inc., * 00019 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * 00020 ***************************************************************************/ 00021 00022 /* 00023 * For comments regarding functions please see the header file. 00024 */ 00025 00026 // Standard C++ library includes 00027 00028 // 3rd party library includes 00029 #include <guichan/rectangle.hpp> 00030 #include <guichan/graphics.hpp> 00031 00032 // FIFE includes 00033 // These includes are split up in two parts, separated by one empty line 00034 // First block: files included from the FIFE root src directory 00035 // Second block: files included from the same folder 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 }