00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "gui/widgets/checkbox.h"
00023
00024 #include "gui/palette.h"
00025
00026 #include "configuration.h"
00027 #include "graphics.h"
00028
00029 #include "resources/image.h"
00030 #include "resources/resourcemanager.h"
00031
00032 int CheckBox::instances = 0;
00033 float CheckBox::mAlpha = 1.0;
00034 Image *CheckBox::checkBoxNormal;
00035 Image *CheckBox::checkBoxChecked;
00036 Image *CheckBox::checkBoxDisabled;
00037 Image *CheckBox::checkBoxDisabledChecked;
00038
00039 CheckBox::CheckBox(const std::string &caption, bool selected):
00040 gcn::CheckBox(caption, selected)
00041 {
00042 if (instances == 0)
00043 {
00044 ResourceManager *resman = ResourceManager::getInstance();
00045 Image *checkBox = resman->getImage("graphics/gui/checkbox.png");
00046 checkBoxNormal = checkBox->getSubImage(0, 0, 9, 10);
00047 checkBoxChecked = checkBox->getSubImage(9, 0, 9, 10);
00048 checkBoxDisabled = checkBox->getSubImage(18, 0, 9, 10);
00049 checkBoxDisabledChecked = checkBox->getSubImage(27, 0, 9, 10);
00050 checkBoxNormal->setAlpha(mAlpha);
00051 checkBoxChecked->setAlpha(mAlpha);
00052 checkBoxDisabled->setAlpha(mAlpha);
00053 checkBoxDisabledChecked->setAlpha(mAlpha);
00054 checkBox->decRef();
00055 }
00056
00057 instances++;
00058 }
00059
00060 CheckBox::~CheckBox()
00061 {
00062 instances--;
00063
00064 if (instances == 0)
00065 {
00066 delete checkBoxNormal;
00067 delete checkBoxChecked;
00068 delete checkBoxDisabled;
00069 delete checkBoxDisabledChecked;
00070 }
00071 }
00072
00073 void CheckBox::draw(gcn::Graphics* graphics)
00074 {
00075 drawBox(graphics);
00076
00077 graphics->setFont(getFont());
00078 graphics->setColor(guiPalette->getColor(Palette::TEXT));
00079
00080 const int h = getHeight() + getHeight() / 2;
00081
00082 graphics->drawText(getCaption(), h - 2, 0);
00083 }
00084
00085 void CheckBox::drawBox(gcn::Graphics* graphics)
00086 {
00087 Image *box;
00088
00089 if (isSelected())
00090 {
00091 if (isEnabled())
00092 box = checkBoxChecked;
00093 else
00094 box = checkBoxDisabledChecked;
00095 }
00096 else if (isEnabled())
00097 box = checkBoxNormal;
00098 else
00099 box = checkBoxDisabled;
00100
00101 if (config.getValue("guialpha", 0.8) != mAlpha)
00102 {
00103 mAlpha = config.getValue("guialpha", 0.8);
00104 checkBoxNormal->setAlpha(mAlpha);
00105 checkBoxChecked->setAlpha(mAlpha);
00106 checkBoxDisabled->setAlpha(mAlpha);
00107 checkBoxDisabledChecked->setAlpha(mAlpha);
00108 }
00109
00110 static_cast<Graphics*>(graphics)->drawImage(box, 2, 2);
00111 }