GLWDropDownColor.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D 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
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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 }

Generated on Mon Feb 16 15:14:45 2009 for Scorched3D by  doxygen 1.5.3