GLWFileView.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/GLWFileView.h>
00022 #include <GLW/GLWFont.h>
00023 #include <common/DefinesString.h>
00024 
00025 REGISTER_CLASS_SOURCE(GLWFileView);
00026 
00027 GLWFileView::GLWFileView(char *fileName, float x, float y, float w, float h) :
00028         GLWidget(x, y, w, h), 
00029         scroll_(x + w - 17, y, h, 0, 1)
00030 {
00031         if (fileName[0])
00032         {
00033                 lines_.readFile(fileName);
00034                 scroll_.setMax((int) lines_.getLines().size());
00035                 scroll_.setSee((int) (h_ / 9));
00036                 scroll_.setCurrent(scroll_.getMax());
00037         }
00038 }
00039 
00040 GLWFileView::~GLWFileView()
00041 {
00042 }
00043 
00044 void GLWFileView::simulate(float frameTime)
00045 {
00046         scroll_.simulate(frameTime);
00047 }
00048 
00049 void GLWFileView::draw()
00050 {
00051         glBegin(GL_LINE_LOOP);
00052                 drawShadedRoundBox(x_, y_, w_, h_, 6.0f, false);
00053         glEnd();
00054 
00055         float posY = y_ + h_ - 10.0f;
00056         for (int i=scroll_.getMax() - scroll_.getCurrent(); i<(int) lines_.getLines().size(); i++)
00057         {
00058                 GLWFont::instance()->getGameFont()->drawWidth(
00059                         w_,
00060                         GLWFont::widgetFontColor, 8,
00061                         x_ + 5.0f, posY, 0.0f, 
00062                         S3D::formatStringBuffer("%s", lines_.getLines()[i].c_str()));
00063                 posY -= 9.0f;
00064 
00065                 if (posY < y_) break;
00066         }
00067 
00068         scroll_.draw();
00069 }
00070 
00071 void GLWFileView::mouseDown(int button, float x, float y, bool &skipRest)
00072 {
00073         scroll_.mouseDown(button, x, y, skipRest);
00074 }
00075 
00076 void GLWFileView::mouseUp(int button, float x, float y, bool &skipRest)
00077 {
00078         scroll_.mouseUp(button, x, y, skipRest);
00079 }
00080 
00081 void GLWFileView::mouseDrag(int button, float mx, float my, float x, float y, bool &skipRest)
00082 {
00083         scroll_.mouseDrag(button, mx, my, x, y, skipRest);
00084 }
00085 
00086 void GLWFileView::mouseWheel(float x, float y, float z, bool &skipRest)
00087 {
00088         if (inBox(x, y, x_, y_, w_, h_))
00089         {
00090                 skipRest = true;
00091 
00092                 if (z < 0.0f) scroll_.setCurrent(scroll_.getCurrent() + 1);
00093                 else scroll_.setCurrent(scroll_.getCurrent() - 1);
00094         }
00095 }

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