GLWidget.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/GLWidget.h>
00022 #include <GLW/GLWPanel.h>
00023 #include <GLW/GLWToolTip.h>
00024 #include <GLW/GLWTranslate.h>
00025 #include <GLEXT/GLState.h>
00026 #include <XML/XMLParser.h>
00027 #include <common/Defines.h>
00028 #include <math.h>
00029 
00030 unsigned int GLWidget::nextId_ = 0;
00031 static GLuint listNo = 0;
00032 
00033 GLWidget::GLWidget(float x, float y, float w, float h) : 
00034         id_(++nextId_), parent_(0), userData_(0), visible_(true),
00035         x_(x), y_(y), w_(w), h_(h), tooltip_(0), tooltipTransparent_(false)
00036 {
00037 }
00038 
00039 GLWidget::~GLWidget()
00040 {
00041 }
00042 
00043 void GLWidget::draw()
00044 {
00045         if (listNo == 0)
00046         {
00047                 listNo = glGenLists(1);
00048                 glNewList(listNo, GL_COMPILE);
00049                         for (float a=360.0f; a>0.0f; a-=360.0f / 36.0f)
00050                         {
00051                                 glVertex2f(sinf(a/180.0f * PI), 
00052                                         cosf(a/180.0f * PI));
00053                         }
00054                 glEndList();
00055         }
00056 
00057         if (tooltipTransparent_)
00058         {
00059         }
00060         else if (tooltip_)
00061         {
00062                 GLWToolTip::instance()->addToolTip(tooltip_, 
00063                         GLWTranslate::getPosX() + x_, 
00064                         GLWTranslate::getPosY() + y_, 
00065                         w_, h_);
00066         }
00067         else
00068         {
00069                 GLWToolTip::instance()->clearToolTip(
00070                         GLWTranslate::getPosX() + x_, 
00071                         GLWTranslate::getPosY() + y_, 
00072                         w_, h_);
00073         }
00074 }
00075 
00076 void GLWidget::layout()
00077 {
00078 
00079 }
00080 
00081 void GLWidget::simulate(float frameTime)
00082 {
00083 
00084 }
00085 
00086 void GLWidget::setParent(GLWPanel *parent)
00087 {
00088         parent_ = parent;
00089 }
00090 
00091 void GLWidget::mouseDown(int button, float x, float y, bool &skipRest)
00092 {
00093 
00094 }
00095 
00096 void GLWidget::mouseUp(int button, float x, float y, bool &skipRest)
00097 {
00098 
00099 }
00100 
00101 void GLWidget::mouseDrag(int button, float mx, float my, float x, float y, bool &skipRest)
00102 {
00103 
00104 }
00105 
00106 void GLWidget::keyDown(char *buffer, unsigned int keyState, 
00107                 KeyboardHistory::HistoryElement *history, int hisCount, 
00108                 bool &skipRest)
00109 {
00110 
00111 }
00112 
00113 void GLWidget::mouseWheel(float x, float y, float z, bool &skipRest)
00114 {
00115 
00116 }
00117 
00118 void GLWidget::display()
00119 {
00120 
00121 }
00122 
00123 void GLWidget::hide()
00124 {
00125 
00126 }
00127 
00128 bool GLWidget::initFromXML(XMLNode *node)
00129 {
00130         node->getNamedChild("name", name_, false);
00131         node->getNamedChild("visible", visible_, false);
00132         node->getNamedChild("tooltiptransparent", tooltipTransparent_, false);
00133 
00134         float x, y, w, h;
00135         if (!node->getNamedChild("x", x)) return false;
00136         if (!node->getNamedChild("y", y)) return false;
00137         if (!node->getNamedChild("w", w)) return false;
00138         if (!node->getNamedChild("h", h)) return false; 
00139         setX(x);
00140         setY(y);
00141         setW(w);
00142         setH(h);
00143 
00144         return true;
00145 }
00146 
00147 void GLWidget::drawWholeCircle(bool cap)
00148 {
00149         glCallList(listNo);
00150         if (cap) glVertex2f(0.0f, 1.0f);
00151 }
00152 
00153 void GLWidget::drawCircle(int startA, int endA, float posX, float posY, float size)
00154 {
00155         static Vector positions[16];
00156         static bool init = false;
00157         if (!init)
00158         {
00159                 init = true;
00160                 for (int i=0; i<16; i++)
00161                 {
00162                         const float angDeg = 22.5f;
00163                         float ang = i * angDeg;
00164                         positions[i][0] = sinf(ang / 180.0f * PI);
00165                         positions[i][1] = cosf(ang / 180.0f * PI);
00166                 }
00167         }
00168 
00169         if (startA < endA)
00170         {
00171                 for (int b=startA; b<=endA; b++)
00172                 {
00173                         int a=b; if (a>15) a=a-16;
00174                         glVertex2f(posX + positions[a][0] * size, posY + positions[a][1] * size);
00175                 }
00176         }
00177         else
00178         {
00179                 for (int b=startA; b>=endA; b--)
00180                 {
00181                         int a=b; if (a<0) a=16+a;
00182                         glVertex2f(posX + positions[a][0] * size, posY + positions[a][1] * size);
00183                 }
00184         }
00185 }
00186 
00187 void GLWidget::drawRoundBox(float x, float y, float w, float h, float size)
00188 {
00189         drawCircle(8, 4, x + w - size, y + size, size);
00190         drawCircle(4, 0, x + w - size, y + h - size, size);
00191         drawCircle(0, -4, x + size, y + h - size, size);
00192         drawCircle(-4, -8, x + size, y + size, size);
00193 }
00194 
00195 void GLWidget::drawShadedRoundBox(float x, float y, float w, float h, float size, bool depressed)
00196 {
00197         if (depressed) glColor3f(0.4f, 0.4f, 0.6f);
00198         else glColor3f(1.0f, 1.0f, 1.0f);
00199 
00200         drawCircle(-6, -8, x + size, y + size, size);
00201         drawCircle(8, 4, x + w - size, y + size, size);
00202         drawCircle(4, 3, x + w - size, y + h - size, size);
00203 
00204         if (depressed) glColor3f(1.0f, 1.0f, 1.0f); 
00205         else glColor3f(0.4f, 0.4f, 0.6f);
00206 
00207         drawCircle(2, 0, x + w - size, y + h - size, size);
00208         drawCircle(0, -4, x + size, y + h - size, size);
00209         drawCircle(-4, -5, x + size, y + size, size);
00210 
00211         if (depressed) glColor3f(0.4f, 0.4f, 0.6f);
00212         else glColor3f(1.0f, 1.0f, 1.0f);
00213         drawCircle(-6, -6, x + size, y + size, size);
00214 }
00215 
00216 void GLWidget::drawBox(float x, float y, float w, float h, bool depressed)
00217 {
00218         if (depressed) glColor3f(0.4f, 0.4f, 0.6f);
00219         else glColor3f(1.0f, 1.0f, 1.0f);
00220 
00221         glVertex2f(x , y);
00222         glVertex2f(x + w, y);
00223 
00224         glVertex2f(x + w, y);
00225         glVertex2f(x + w, y + h);
00226 
00227         if (depressed) glColor3f(1.0f, 1.0f, 1.0f);
00228         else glColor3f(0.4f, 0.4f, 0.6f);
00229         glVertex2f(x + w, y + h);
00230         glVertex2f(x, y + h);
00231 
00232         glVertex2f(x, y + h);
00233         glVertex2f(x, y);
00234 }
00235 
00236 bool GLWidget::inBox(float posX, float posY, float x, float y, float w, float h)
00237 {
00238         if ((posX >= x) && (posX <= x + w) &&
00239                 (posY >= y) && (posY <= y + h))
00240         {
00241                 return true;
00242         }
00243 
00244         return false;
00245 }
00246 
00247 GLWCondition::GLWCondition()
00248 {
00249 }
00250 
00251 GLWCondition::~GLWCondition()
00252 {
00253 }
00254 
00255 bool GLWCondition::initFromXML(XMLNode *node)
00256 {
00257         return true;
00258 }
00259 

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