00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <GLW/GLWIconTable.h>
00022 #include <GLEXT/GLState.h>
00023 #include <common/DefinesString.h>
00024
00025 GLWIconTable::GLWIconTable(
00026 float x, float y, float w, float h,
00027 std::list<Column> *columns,
00028 float rowHeight) :
00029 GLWidget(x, y, w, h),
00030 rowHeight_(rowHeight),
00031 scrollBar_(x + w_ - 17.0f, y + 2.0f, h_ - 4.0f, 0, 0, int((h - 25.0f) / rowHeight)),
00032 selected_(-1), handler_(0), itemCount_(0)
00033 {
00034 if (columns)
00035 {
00036 float colx = x + 1;
00037 std::list<Column>::iterator itor;
00038 for (itor = columns->begin();
00039 itor != columns->end();
00040 itor++)
00041 {
00042 Column &col = *itor;
00043 GLWTextButton *button = new
00044 GLWTextButton(
00045 col.name,
00046 colx, y_ + h_ - 20.0f,
00047 col.width, this,
00048 GLWButton::ButtonFlagCenterX, 10);
00049 columns_.push_back(button);
00050
00051 colx += col.width + 2.0f;
00052 }
00053 }
00054 }
00055
00056 GLWIconTable::~GLWIconTable()
00057 {
00058 }
00059
00060 void GLWIconTable::setItemCount(int items)
00061 {
00062 if (selected_ > items) selected_ = -1;
00063
00064 scrollBar_.setMax(items);
00065 scrollBar_.setCurrent(0);
00066 itemCount_ = items;
00067 }
00068
00069 void GLWIconTable::simulate(float frameTime)
00070 {
00071 scrollBar_.simulate(frameTime);
00072 }
00073
00074 void GLWIconTable::draw()
00075 {
00076 GLWidget::draw();
00077
00078
00079 scrollBar_.draw();
00080
00081
00082 glBegin(GL_LINE_LOOP);
00083 drawShadedRoundBox(x_, y_, w_, h_, 5.0f, false);
00084 glEnd();
00085
00086
00087 for (int j=0; j<(int) columns_.size(); j++)
00088 {
00089 GLWTextButton *column = columns_[j];
00090 if (!column->getEmpty()) column->draw();
00091 }
00092
00093
00094 int min = MIN(itemCount_, scrollBar_.getCurrent());
00095 int max = MIN(itemCount_, scrollBar_.getCurrent() + scrollBar_.getSee());
00096
00097 float x = x_ + 5.0f;
00098 float y = y_ + h_ - 25.0f;
00099
00100
00101 for (int i=min; i<max; i++)
00102 {
00103 y -= rowHeight_;
00104
00105
00106 if (selected_ != i)
00107 {
00108 glEnable(GL_LINE_STIPPLE);
00109 glLineStipple(1, 0x0F0F);
00110 glColor3f(0.4f, 0.4f, 0.6f);
00111 }
00112 else
00113 {
00114 glLineWidth(2.0f);
00115 glColor3f(0.1f, 0.1f, 0.3f);
00116 }
00117 glBegin(GL_LINES);
00118 for (int j=1; j<(int) columns_.size(); j++)
00119 {
00120 GLWTextButton *column = columns_[j];
00121 glVertex2f(column->getX(), y);
00122 glVertex2f(column->getX(), y + rowHeight_);
00123 }
00124 glVertex2f(x_, y);
00125 glVertex2f(x_ + w_ - 18.0f, y);
00126 if (i == min || selected_ == i)
00127 {
00128 glVertex2f(x_, y + rowHeight_);
00129 glVertex2f(x_ + w_ - 18.0f, y + rowHeight_);
00130 }
00131 glEnd();
00132 glDisable(GL_LINE_STIPPLE);
00133 glLineWidth(1.0f);
00134
00135
00136 for (int j=0; j<(int) columns_.size(); j++)
00137 {
00138 GLWTextButton *column = columns_[j];
00139 if (handler_) handler_->drawColumn(id_, i, j,
00140 column->getX(), y, column->getW());
00141 }
00142 }
00143 }
00144
00145 void GLWIconTable::buttonDown(unsigned int id)
00146 {
00147 for (int j=0; j<(int) columns_.size(); j++)
00148 {
00149 GLWTextButton *column = columns_[j];
00150 if (column->getId() == id && handler_)
00151 {
00152 handler_->columnSelected(id_, j);
00153 }
00154 }
00155 }
00156
00157 void GLWIconTable::mouseDown(int button, float x, float y, bool &skipRest)
00158 {
00159 scrollBar_.mouseDown(button, x, y, skipRest);
00160 if (!skipRest)
00161 {
00162 if (inBox(x, y, x_, y_, w_ - 20.0f, h_ - 20.0f))
00163 {
00164 skipRest = true;
00165
00166 int pos = int((y_ + h_ - 25.0f - y) / rowHeight_) + scrollBar_.getCurrent();
00167 if (pos >=0 && pos < itemCount_)
00168 {
00169 selected_ = pos;
00170
00171 if (handler_) handler_->rowSelected(getId(), selected_);
00172
00173 if (button == GameState::MouseButtonLeftDoubleClick)
00174 {
00175 if (handler_) handler_->rowChosen(getId(), selected_);
00176 }
00177 }
00178 }
00179 }
00180
00181 if (!skipRest)
00182 {
00183 std::vector<GLWTextButton *>::iterator itor;
00184 for (itor = columns_.begin();
00185 itor != columns_.end();
00186 itor++)
00187 {
00188 GLWTextButton *column = (*itor);
00189 column->mouseDown(button, x, y, skipRest);
00190 }
00191 }
00192 }
00193
00194 void GLWIconTable::mouseDrag(int button, float mx, float my, float x, float y, bool &skipRest)
00195 {
00196 scrollBar_.mouseDrag(button, mx, my, x, y, skipRest);
00197
00198 if (!skipRest)
00199 {
00200 std::vector<GLWTextButton *>::iterator itor;
00201 for (itor = columns_.begin();
00202 itor != columns_.end();
00203 itor++)
00204 {
00205 GLWTextButton *column = (*itor);
00206 column->mouseDrag(button, mx, my, x, y, skipRest);
00207 }
00208 }
00209 }
00210
00211 void GLWIconTable::mouseUp(int button, float x, float y, bool &skipRest)
00212 {
00213 scrollBar_.mouseUp(button, x, y, skipRest);
00214
00215 if (!skipRest)
00216 {
00217 std::vector<GLWTextButton *>::iterator itor;
00218 for (itor = columns_.begin();
00219 itor != columns_.end();
00220 itor++)
00221 {
00222 GLWTextButton *column = (*itor);
00223 column->mouseUp(button, x, y, skipRest);
00224 }
00225 }
00226 }
00227
00228 void GLWIconTable::mouseWheel(float x, float y, float z, bool &skipRest)
00229 {
00230 if (inBox(x, y, x_, y_, w_, h_))
00231 {
00232 skipRest = true;
00233 scrollBar_.mouseWheel(scrollBar_.getX() + 1, scrollBar_.getY() + 1, z, skipRest);
00234 }
00235 }