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/radiobutton.h"
00023
00024 #include "configuration.h"
00025 #include "graphics.h"
00026
00027 #include "resources/image.h"
00028 #include "resources/resourcemanager.h"
00029
00030 int RadioButton::instances = 0;
00031 float RadioButton::mAlpha = 1.0;
00032 Image *RadioButton::radioNormal;
00033 Image *RadioButton::radioChecked;
00034 Image *RadioButton::radioDisabled;
00035 Image *RadioButton::radioDisabledChecked;
00036
00037 RadioButton::RadioButton(const std::string &caption, const std::string &group,
00038 bool marked):
00039 gcn::RadioButton(caption, group, marked)
00040 {
00041 if (instances == 0)
00042 {
00043 ResourceManager *resman = ResourceManager::getInstance();
00044 radioNormal = resman->getImage("graphics/gui/radioout.png");
00045 radioChecked = resman->getImage("graphics/gui/radioin.png");
00046 radioDisabled = resman->getImage("graphics/gui/radioout.png");
00047 radioDisabledChecked = resman->getImage("graphics/gui/radioin.png");
00048 radioNormal->setAlpha(mAlpha);
00049 radioChecked->setAlpha(mAlpha);
00050 radioDisabled->setAlpha(mAlpha);
00051 radioDisabledChecked->setAlpha(mAlpha);
00052 }
00053
00054 instances++;
00055 }
00056
00057 RadioButton::~RadioButton()
00058 {
00059 instances--;
00060
00061 if (instances == 0)
00062 {
00063 radioNormal->decRef();
00064 radioChecked->decRef();
00065 radioDisabled->decRef();
00066 radioDisabledChecked->decRef();
00067 }
00068 }
00069
00070 void RadioButton::drawBox(gcn::Graphics* graphics)
00071 {
00072 if (config.getValue("guialpha", 0.8) != mAlpha)
00073 {
00074 mAlpha = config.getValue("guialpha", 0.8);
00075 radioNormal->setAlpha(mAlpha);
00076 radioChecked->setAlpha(mAlpha);
00077 radioDisabled->setAlpha(mAlpha);
00078 radioDisabledChecked->setAlpha(mAlpha);
00079 }
00080
00081 Image *box = NULL;
00082
00083 if (isSelected())
00084 {
00085 if (isEnabled())
00086 box = radioChecked;
00087 else
00088 box = radioDisabledChecked;
00089 }
00090 else if (isEnabled())
00091 box = radioNormal;
00092 else
00093 box = radioDisabled;
00094
00095 if (box)
00096 static_cast<Graphics*>(graphics)->drawImage(box, 2, 2);
00097 }
00098
00099 void RadioButton::draw(gcn::Graphics* graphics)
00100 {
00101 graphics->pushClipArea(gcn::Rectangle(1, 1, getWidth() - 1,
00102 getHeight() - 1));
00103
00104 drawBox(graphics);
00105
00106 graphics->popClipArea();
00107
00108 graphics->setFont(getFont());
00109 graphics->setColor(getForegroundColor());
00110
00111 int h = getHeight() + getHeight() / 2;
00112 graphics->drawText(getCaption(), h - 2, 0);
00113 }