GLWScrollPanel.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/GLWScrollPanel.h>
00022 #include <GLW/GLWTranslate.h>
00023 #include <GLEXT/GLState.h>
00024 #include <float.h>
00025 
00026 REGISTER_CLASS_SOURCE(GLWScrollPanel);
00027 
00028 GLWScrollPanel::GLWScrollPanel(float x, float y, float w, float h) : 
00029         GLWPanel(x, y, w, h), scrollW_(x + w - 19, y + 4, h - 10, 0, 0),
00030         drawScrollBar_(true), maxSee_(0), widgetHeight_(0.0f)
00031 {
00032         scrollW_.setHandler(this);
00033 }
00034 
00035 GLWScrollPanel::~GLWScrollPanel()
00036 {
00037 
00038 }
00039 
00040 void GLWScrollPanel::setH(float h)
00041 {
00042         GLWidget::setH(h);
00043 
00044         scrollW_.setH(h_ - 10);
00045 }
00046 
00047 void GLWScrollPanel::simulate(float frameTime)
00048 {
00049         scrollW_.simulate(frameTime);
00050 }
00051 
00052 void GLWScrollPanel::calculateVisible()
00053 {
00054         drawScrollBar_ = false;
00055         int canSee = 0;
00056         float widgetMinY = FLT_MAX;
00057         float widgetMaxY = FLT_MIN;
00058         {
00059                 std::list<GLWPanel::GLWPanelEntry>::iterator itor;
00060                 for (itor = getWidgets().begin();
00061                         itor != getWidgets().end();
00062                         itor++)
00063                 {
00064                                 GLWidget *vw = (GLWidget *) (*itor).widget;
00065                                 if (vw->getY() < 0.0f || vw->getY() + vw->getH() > h_)
00066                                 {
00067                                         drawScrollBar_ = true;
00068                                 }
00069                                 else
00070                                 {
00071                                         canSee++;
00072                                 }
00073 
00074                                 if (vw->getY() < widgetMinY) widgetMinY = vw->getY();
00075                                 if (vw->getY() + vw->getH() > widgetMaxY) widgetMaxY = vw->getY() + vw->getH();
00076                 }
00077         }
00078 
00079         widgetHeight_ = widgetMaxY - widgetMinY;
00080 
00081         // Draw scroll bar if not
00082         if (drawScrollBar_)
00083         {
00084                 if (canSee > maxSee_) maxSee_ = canSee;
00085                 scrollW_.setSee(maxSee_);
00086                 scrollW_.setMax((int) getWidgets().size());
00087         }
00088 }
00089 
00090 void GLWScrollPanel::draw()
00091 {
00092         calculateVisible();
00093 
00094         glPushMatrix();
00095         {
00096                 GLWTranslate trans(x_, y_);
00097                 glTranslatef(x_, y_, 0.0f);
00098 
00099                 GLState currentState(GLState::DEPTH_OFF | GLState::TEXTURE_OFF);
00100 
00101                 std::list<GLWPanel::GLWPanelEntry>::iterator itor;
00102                 for (itor = getWidgets().begin();
00103                         itor != getWidgets().end();
00104                         itor++)
00105                 {
00106                         glPushMatrix();
00107                                 GLWidget *vw = (GLWidget *) (*itor).widget;
00108                                 if (vw->getY() >= 0.0f && vw->getY() + vw->getH() <= h_)
00109                                 {
00110                                         vw->draw();
00111                                 }
00112                         glPopMatrix();
00113                 }
00114         }
00115         glPopMatrix();
00116 
00117         if (drawScrollBar_) scrollW_.draw();
00118 }
00119 
00120 void GLWScrollPanel::mouseUp(int button, float x, float y, bool &skipRest)
00121 {
00122         if (drawScrollBar_)
00123         {
00124                 scrollW_.mouseUp(button, x, y, skipRest);
00125         }
00126         if (!skipRest)
00127         {
00128                 x -= x_;
00129                 y -= y_;
00130 
00131                 std::list<GLWPanel::GLWPanelEntry>::iterator itor;
00132                 for (itor = getWidgets().begin();
00133                         itor != getWidgets().end();
00134                         itor++)
00135                 {
00136                         GLWidget *vw =
00137                                 (GLWidget *) (*itor).widget;
00138                         if (vw->getY() < 0.0f || vw->getY() + vw->getH() > h_)
00139                         {
00140                         
00141                         }
00142                         else
00143                         {
00144                                 vw->mouseUp(button, x, y, skipRest);
00145                         }
00146                         if (skipRest) break;
00147                 }
00148         }
00149 }
00150 
00151 void GLWScrollPanel::mouseDown(int button, float x, float y, bool &skipRest)
00152 {
00153         if (drawScrollBar_)
00154         {
00155                 scrollW_.mouseDown(button, x, y, skipRest);
00156         }
00157         if (!skipRest)
00158         {
00159                 x -= x_;
00160                 y -= y_;
00161 
00162                 std::list<GLWPanel::GLWPanelEntry>::iterator itor;
00163                 for (itor = getWidgets().begin();
00164                         itor != getWidgets().end();
00165                         itor++)
00166                 {
00167                         GLWidget *vw =
00168                                 (GLWidget *) (*itor).widget;
00169                         if (vw->getY() < 0.0f || vw->getY() + vw->getH() > h_)
00170                         {
00171                         
00172                         }
00173                         else
00174                         {
00175                                 vw->mouseDown(button, x, y, skipRest);
00176                         }
00177                         if (skipRest) break;
00178                 }
00179         }
00180 }
00181 
00182 void GLWScrollPanel::mouseDrag(int button, float mx, float my, float x, float y, bool &skipRest)
00183 {
00184         if (drawScrollBar_)
00185         {
00186                 scrollW_.mouseDrag(button, mx, my, x, y, skipRest);
00187         }
00188         if (!skipRest)
00189         {
00190                 mx -= x_;
00191                 my -= y_;
00192 
00193                 std::list<GLWPanel::GLWPanelEntry>::iterator itor;
00194                 for (itor = getWidgets().begin();
00195                         itor != getWidgets().end();
00196                         itor++)
00197                 {
00198                         GLWidget *vw =
00199                                 (GLWidget *) (*itor).widget;
00200                         if (vw->getY() < 0.0f || vw->getY() + vw->getH() > h_)
00201                         {
00202                         
00203                         }
00204                         else
00205                         {
00206                                 vw->mouseDrag(button, mx, my, x, y, skipRest);
00207                         }
00208                         if (skipRest) break;
00209                 }
00210         }
00211 }
00212 
00213 void GLWScrollPanel::mouseWheel(float x, float y, float z, bool &skipRest)
00214 {
00215         if (inBox(x, y, x_, y_, w_, h_))
00216         {
00217                 skipRest = true;
00218 
00219                 if (drawScrollBar_)
00220                 {
00221                         if (z < 0.0f) scrollW_.setCurrent(scrollW_.getCurrent() + 2);
00222                         else scrollW_.setCurrent(scrollW_.getCurrent() - 2);
00223                 }
00224                 else 
00225                 {
00226                         GLWPanel::mouseWheel(x, y, z, skipRest);
00227                 }
00228         }
00229 }
00230 
00231 void GLWScrollPanel::positionChange(unsigned int id, int current, int movement)
00232 {
00233         float move = ((widgetHeight_ + 2.0f) / float(getWidgets().size())) * float(movement);
00234 
00235         std::list<GLWPanel::GLWPanelEntry>::iterator itor;
00236         for (itor = getWidgets().begin();
00237                 itor != getWidgets().end();
00238                 itor++)
00239         {
00240                 GLWidget *vw =
00241                         (GLWidget *) (*itor).widget;
00242                 vw->setY(vw->getY() - move);
00243         }
00244 }
00245 
00246 void GLWScrollPanel::clear()
00247 {
00248         scrollW_.setCurrent(0);
00249         GLWPanel::clear();
00250 }

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