GLWSlider.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/GLWSlider.h>
00022 #include <GLW/GLWFont.h>
00023 #include <GLEXT/GLState.h>
00024 #include <common/Keyboard.h>
00025 #include <common/ToolTip.h>
00026 #include <client/ScorchedClient.h>
00027 #include <tank/TankContainer.h>
00028 #include <tank/TankState.h>
00029 #include <tank/TankPosition.h>
00030 
00031 REGISTER_CLASS_SOURCE(GLWSlider);
00032 
00033 GLWSlider::GLWSlider(float x, float y, float w, 
00034         float min, float max, int marks) :
00035         GLWidget(x, y, w, 20.0f), 
00036         min_(min), max_(max),
00037         marks_(marks),
00038         handler_(0)
00039 {
00040         setCurrent(min_);
00041 }
00042 
00043 GLWSlider::~GLWSlider()
00044 {
00045 
00046 }
00047 
00048 void GLWSlider::draw()
00049 {
00050         glBegin(GL_LINE_LOOP);
00051                 drawBox(x_ - 4.0f, y_ + 8.0f, w_ + 12.0f, 4.0f, false);
00052         glEnd();
00053 
00054         glColor3f(0.0f, 0.0f, 0.0f);
00055         glBegin(GL_LINES);
00056         for (int i=0; i<=marks_; i++)
00057         {
00058                 float dist = float(i) / float(marks_);
00059                 glVertex2f(x_ + w_ * dist, y_ + 12.0f);
00060                 glVertex2f(x_ + w_ * dist, y_ + 18.0f);
00061 
00062                 glVertex2f(x_ + w_ * dist, y_ + 2.0f);
00063                 glVertex2f(x_ + w_ * dist, y_ + 8.0f);
00064         }
00065         glEnd();
00066 
00067         float dist = (current_ - min_) / max_;
00068         glColor3f(0.8f, 0.8f, 1.0f);
00069         glBegin(GL_QUADS);
00070                 glVertex2f(x_ + w_ * dist , y_);
00071                 glVertex2f(x_ + w_ * dist + 4.0f, y_);
00072                 glVertex2f(x_ + w_ * dist + 4.0f, y_ + 20.0f);
00073                 glVertex2f(x_ + w_ * dist, y_ + 20.0f);
00074         glEnd();
00075         glBegin(GL_LINE_LOOP);
00076                 drawBox(x_ + w_ * dist, y_, 4.0f, 20.0f, true);
00077         glEnd();
00078 }
00079 
00080 void GLWSlider::setCurrent(float current)
00081 { 
00082         current_ = current; 
00083         if (handler_) handler_->currentChanged(getId(), current_);
00084 }
00085 
00086 void GLWSlider::mouseDown(int button, float x, float y, bool &skipRest)
00087 {
00088         if (inBox(x, y, x_, y_, w_, h_))
00089         {
00090                 skipRest = true;
00091 
00092                 float dist = (x - x_) / w_;
00093                 if (dist >= 0.0f && dist <= 1.0f)
00094                 {
00095                         setCurrent(((max_ - min_) * dist) + min_);
00096                 }
00097         }
00098 }
00099 
00100 void GLWSlider::mouseUp(int button, float x, float y, bool &skipRest)
00101 {
00102 }
00103 
00104 void GLWSlider::mouseDrag(int button, float mx, float my, float x, float y, bool &skipRest)
00105 {
00106         mouseDown(button, mx, my, skipRest);
00107 }

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