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