00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <GLW/GLWDropDownColor.h>
00022 #include <image/ImageFactory.h>
00023 #include <client/ScorchedClient.h>
00024
00025 REGISTER_CLASS_SOURCE(GLWDropDownColor);
00026
00027 GLWDropDownColor::GLWDropDownColor(float x, float y, float w) :
00028 GLWDropDown(x, y, w), createdTexture_(false)
00029 {
00030 }
00031
00032 GLWDropDownColor::~GLWDropDownColor()
00033 {
00034 }
00035
00036 void GLWDropDownColor::addColor(Vector &color)
00037 {
00038 if (!createdTexture_)
00039 {
00040 createdTexture_ = true;
00041 ImageHandle map = ImageFactory::loadImageHandle(
00042 S3D::getDataFile("data/windows/white.bmp"));
00043 colorTexture_.create(map);
00044 }
00045
00046 GLWSelectorEntry entry(LANG_STRING(""), 0, false, &colorTexture_, 0);
00047 entry.getColor() = color;
00048 entry.getTextureWidth() = 32;
00049 addEntry(entry);
00050 }
00051
00052 Vector &GLWDropDownColor::getCurrentColor()
00053 {
00054 if (!getCurrentEntry()) return Vector::getNullVector();
00055 return getCurrentEntry()->getColor();
00056 }
00057
00058 void GLWDropDownColor::setCurrentColor(Vector &color)
00059 {
00060 int position = 0;
00061 std::list<GLWSelectorEntry>::iterator itor;
00062 for (itor = texts_.begin();
00063 itor != texts_.end();
00064 itor++)
00065 {
00066 GLWSelectorEntry &entry = *itor;
00067 if (color == entry.getColor())
00068 {
00069 current_ = &entry;
00070 break;
00071 }
00072
00073 position++;
00074 }
00075
00076 if (handler_)
00077 {
00078 handler_->select(id_, position, *current_);
00079 }
00080 }
00081
00082 void GLWDropDownColor::draw()
00083 {
00084 GLWDropDown::draw();
00085
00086 if (getCurrentEntry())
00087 {
00088 GLState state(GLState::TEXTURE_OFF);
00089
00090 Vector color = getCurrentColor();
00091 glColor3f(color[0], color[1], color[2]);
00092
00093 float x = x_ + 12.0f;
00094 float y = y_ + 6.0f;
00095 glBegin(GL_QUADS);
00096 glTexCoord2f(0.0f, 0.0f);
00097 glVertex2f(x, y);
00098 glTexCoord2f(1.0f, 0.0f);
00099 glVertex2f(x + w_ - 44.0f, y);
00100 glTexCoord2f(1.0f, 1.0f);
00101 glVertex2f(x + w_ - 44.0f, y + 14.0f);
00102 glTexCoord2f(0.0f, 1.0f);
00103 glVertex2f(x, y + 14.0f);
00104 glEnd();
00105 }
00106 }