GLWIcon.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/GLWIcon.h>
00022 #include <GLEXT/GLState.h>
00023 #include <XML/XMLParser.h>
00024 #include <graph/TextureStore.h>
00025 #include <common/Defines.h>
00026 
00027 REGISTER_CLASS_SOURCE(GLWIcon);
00028 
00029 GLWIcon::GLWIcon(float x, float y, float w, float h, GLTexture *texture) : 
00030         GLWidget(x, y, w, h),
00031         texture_(texture)
00032 {
00033         tooltipTransparent_ = true;
00034 }
00035 
00036 GLWIcon::~GLWIcon()
00037 {
00038 }
00039 
00040 void GLWIcon::draw()
00041 {
00042         if (texture_)
00043         {
00044                 GLState state(GLState::TEXTURE_ON | GLState::BLEND_ON);
00045                 glColor3f(1.0f, 1.0f, 1.0f);
00046                 texture_->draw();
00047 
00048                 glBegin(GL_QUADS);
00049                         glTexCoord2f(0.0f, 0.0f);
00050                         glVertex2f(x_, y_);
00051                         glTexCoord2f(1.0f, 0.0f);
00052                         glVertex2f(x_ + w_, y_);
00053                         glTexCoord2f(1.0f, 1.0f);
00054                         glVertex2f(x_ + w_, y_ + h_);
00055                         glTexCoord2f(0.0f, 1.0f);
00056                         glVertex2f(x_, y_ + h_);
00057                 glEnd();
00058         }
00059 
00060         GLWidget::draw();
00061 }
00062 
00063 bool GLWIcon::initFromXML(XMLNode *node)
00064 {
00065         if (!GLWidget::initFromXML(node)) return false;
00066 
00067         XMLNode *bitmapNode, *bitmapANode, *invertNode;
00068         if (!node->getNamedChild("bitmap", bitmapNode)) return false;
00069         if (!node->getNamedChild("bitmapa", bitmapANode)) return false;
00070         if (!node->getNamedChild("invert", invertNode)) return false;
00071 
00072         bool invert = (0 == strcmp(invertNode->getContent(), "true"));
00073         if (bitmapNode && bitmapANode)
00074         {
00075                 std::string bitmapName = 
00076                         S3D::getDataFile(bitmapNode->getContent());
00077                 std::string bitmapAName = 
00078                         S3D::getDataFile(bitmapANode->getContent());
00079 
00080                 texture_ = TextureStore::instance()->loadTexture(
00081                         bitmapName.c_str(), bitmapAName.c_str(), invert);
00082                 if (!texture_) return false;
00083 
00084                 texture_->draw();
00085                 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
00086                 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
00087         }
00088         return true;
00089 }

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