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/slider.h"
00023
00024 #include "configuration.h"
00025 #include "graphics.h"
00026
00027 #include "resources/image.h"
00028 #include "resources/resourcemanager.h"
00029
00030 Image *Slider::hStart, *Slider::hMid, *Slider::hEnd, *Slider::hGrip;
00031 Image *Slider::vStart, *Slider::vMid, *Slider::vEnd, *Slider::vGrip;
00032 float Slider::mAlpha = 1.0;
00033 int Slider::mInstances = 0;
00034
00035 Slider::Slider(double scaleEnd):
00036 gcn::Slider(scaleEnd)
00037 {
00038 init();
00039 }
00040
00041 Slider::Slider(double scaleStart, double scaleEnd):
00042 gcn::Slider(scaleStart, scaleEnd)
00043 {
00044 init();
00045 }
00046
00047 Slider::~Slider()
00048 {
00049 mInstances--;
00050
00051 if (mInstances == 0)
00052 {
00053 delete hStart;
00054 delete hMid;
00055 delete hEnd;
00056 delete hGrip;
00057 delete vStart;
00058 delete vMid;
00059 delete vEnd;
00060 delete vGrip;
00061 }
00062 }
00063
00064 void Slider::init()
00065 {
00066 int x, y, w, h,o1,o2;
00067 setFrameSize(0);
00068
00069
00070 if (mInstances == 0)
00071 {
00072 ResourceManager *resman = ResourceManager::getInstance();
00073 Image *slider = resman->getImage("graphics/gui/slider.png");
00074
00075 x = 0; y = 0;
00076 w = 15; h = 6;
00077 o1 = 4; o2 = 11;
00078 hStart = slider->getSubImage(x, y, o1 - x, h);
00079 hMid = slider->getSubImage(o1, y, o2 - o1, h);
00080 hEnd = slider->getSubImage(o2, y, w - o2 + x, h);
00081
00082 x = 6; y = 8;
00083 w = 9; h = 10;
00084 hGrip = slider->getSubImage(x, y, w, h);
00085
00086 x = 0; y = 6;
00087 w = 6; h = 21;
00088 o1 = 10; o2 = 18;
00089 vStart = slider->getSubImage(x, y, w, o1 - y);
00090 vMid = slider->getSubImage(x, o1, w, o2 - o1);
00091 vEnd = slider->getSubImage(x, o2, w, h - o2 + y);
00092
00093 x = 6; y = 8;
00094 w = 9; h = 10;
00095 vGrip = slider->getSubImage(x, y, w, h);
00096
00097 slider->decRef();
00098
00099 hStart->setAlpha(mAlpha);
00100 hMid->setAlpha(mAlpha);
00101 hEnd->setAlpha(mAlpha);
00102 hGrip->setAlpha(mAlpha);
00103
00104 vStart->setAlpha(mAlpha);
00105 vMid->setAlpha(mAlpha);
00106 vEnd->setAlpha(mAlpha);
00107 vGrip->setAlpha(mAlpha);
00108 }
00109
00110 mInstances++;
00111
00112 setMarkerLength(hGrip->getWidth());
00113 }
00114
00115 void Slider::draw(gcn::Graphics *graphics)
00116 {
00117 int w = getWidth();
00118 int h = getHeight();
00119 int x = 0;
00120 int y = (h - hStart->getHeight()) / 2;
00121
00122 if (config.getValue("guialpha", 0.8) != mAlpha)
00123 {
00124 mAlpha = config.getValue("guialpha", 0.8);
00125 hStart->setAlpha(mAlpha);
00126 hMid->setAlpha(mAlpha);
00127 hEnd->setAlpha(mAlpha);
00128 hGrip->setAlpha(mAlpha);
00129
00130 vStart->setAlpha(mAlpha);
00131 vMid->setAlpha(mAlpha);
00132 vEnd->setAlpha(mAlpha);
00133 vGrip->setAlpha(mAlpha);
00134 }
00135
00136 static_cast<Graphics*>(graphics)->drawImage(hStart, x, y);
00137
00138 w -= hStart->getWidth() + hEnd->getWidth();
00139 x += hStart->getWidth();
00140
00141 static_cast<Graphics*>(graphics)->
00142 drawImagePattern(hMid, x, y, w, hMid->getHeight());
00143
00144 x += w;
00145 static_cast<Graphics*>(graphics)->drawImage(hEnd, x, y);
00146
00147 drawMarker(graphics);
00148 }
00149
00150 void Slider::drawMarker(gcn::Graphics *graphics)
00151 {
00152 static_cast<Graphics*>(graphics)->
00153 drawImage(hGrip, getMarkerPosition(), (getHeight() - hGrip->getHeight()) / 2);
00154 }