00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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 }