00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <GLEXT/GLState.h>
00022 #include <GLW/GLWTab.h>
00023
00024 static const float tabRoundSize = 10.0f;
00025 static const float tabHeight = 20.0f;
00026 static const float tabSpacing = 10.0f;
00027
00028 REGISTER_CLASS_SOURCE(GLWTab);
00029
00030 GLWTabI::~GLWTabI()
00031 {
00032
00033 }
00034
00035 GLWTab::GLWTab(const std::string &tabName,
00036 const LangString &tabLabel,
00037 float x, float y, float w, float h) :
00038 GLWScrollPanel(x, y, w, h), index_(-1.0f),
00039 label_(x + 5.0f + -1.0f, y + h - 3.0f, tabLabel),
00040 name_(tabName),
00041 handler_(0), depressed_(true)
00042 {
00043 label_.setSize(12.0f);
00044 }
00045
00046 GLWTab::~GLWTab()
00047 {
00048 }
00049
00050 void GLWTab::setH(float h)
00051 {
00052 GLWScrollPanel::setH(h);
00053 label_.setY(y_ + h_ - 3.0f);
00054 }
00055
00056 float GLWTab::getTw()
00057 {
00058 return label_.getW() + tabSpacing;
00059 }
00060
00061 void GLWTab::mouseDown(int button, float x, float y, bool &skipRest)
00062 {
00063 float tw = getTw();
00064 if (x > x_ + index_ &&
00065 x < x_ + index_ + tw &&
00066 y < y_ + h_ + tabHeight &&
00067 y > y_ + h_)
00068 {
00069 setDepressed();
00070 skipRest = true;
00071 }
00072
00073 if (!skipRest && depressed_)
00074 {
00075 GLWScrollPanel::mouseDown(button, x, y, skipRest);
00076 }
00077 }
00078
00079 void GLWTab::mouseWheel(float x, float y, float z, bool &skipRest)
00080 {
00081 if (!skipRest && depressed_)
00082 {
00083 GLWScrollPanel::mouseWheel(x, y, z, skipRest);
00084 }
00085 }
00086
00087 void GLWTab::setDepressed()
00088 {
00089 std::list<GLWPanel::GLWPanelEntry>::iterator itor;
00090 for (itor = parent_->getWidgets().begin();
00091 itor != parent_->getWidgets().end();
00092 itor++)
00093 {
00094 GLWPanel::GLWPanelEntry &entry = (*itor);
00095 if (entry.widget->getMetaClassId() == getMetaClassId())
00096 {
00097 GLWTab *tab = (GLWTab *) entry.widget;
00098 tab->depressed_ = false;
00099 }
00100 }
00101
00102 depressed_ = true;
00103 if (handler_) handler_->tabDown(getId());
00104 }
00105
00106 void GLWTab::setParent(GLWPanel *parent)
00107 {
00108 GLWScrollPanel::setParent(parent);
00109
00110 setDepressed();
00111 }
00112
00113 void GLWTab::draw()
00114 {
00115 GLState currentState(GLState::DEPTH_OFF | GLState::TEXTURE_OFF);
00116
00117 if (index_ == -1.0f)
00118 {
00119 index_ = 0.0f;
00120 std::list<GLWPanel::GLWPanelEntry>::iterator itor;
00121 for (itor = parent_->getWidgets().begin();
00122 itor != parent_->getWidgets().end();
00123 itor++)
00124 {
00125 GLWPanel::GLWPanelEntry &entry = (*itor);
00126 if (entry.widget->getMetaClassId() == getMetaClassId())
00127 {
00128 GLWTab *tab = (GLWTab *) entry.widget;
00129 if (tab == this) break;
00130 index_ += tab->getTw() + 2.0f;
00131 }
00132 }
00133 }
00134
00135 label_.setX(x_ + 5.0f + index_);
00136 if (depressed_) drawSurround();
00137 else drawNonSurround();
00138 }
00139
00140 void GLWTab::drawNonSurround()
00141 {
00142 float tw = getTw();
00143 glBegin(GL_LINE_STRIP);
00144 glColor3f(0.4f, 0.4f, 0.6f);
00145 glVertex2f(x_ + index_, y_ + h_);
00146 drawCircle(12, 16, x_ + index_ + tabRoundSize,
00147 y_ + h_ + tabHeight - tabRoundSize, tabRoundSize);
00148 drawCircle(0, 2, x_ + index_ + tw - tabRoundSize,
00149 y_ + h_ + tabHeight - tabRoundSize, tabRoundSize);
00150
00151 glColor3f(1.0f, 1.0f, 1.0f);
00152 drawCircle(2, 4, x_ + index_ + tw - tabRoundSize,
00153 y_ + h_ + tabHeight - tabRoundSize, tabRoundSize);
00154 glVertex2f(x_ + index_ + tw, y_ + h_);
00155 glEnd();
00156
00157 label_.draw();
00158 }
00159
00160 void GLWTab::drawSurround()
00161 {
00162 float tw = getTw();
00163
00164 glBegin(GL_LINE_STRIP);
00165 glColor3f(1.0f, 1.0f, 1.0f);
00166 glVertex2f(x_, y_);
00167 glVertex2f(x_, y_ + h_);
00168 glVertex2f(x_ + index_, y_ + h_);
00169 drawCircle(12, 16, x_ + index_ + tabRoundSize,
00170 y_ + h_ + tabHeight - tabRoundSize, tabRoundSize);
00171 drawCircle(0, 2, x_ + index_ + tw - tabRoundSize,
00172 y_ + h_ + tabHeight - tabRoundSize, tabRoundSize);
00173
00174 glColor3f(0.4f, 0.4f, 0.6f);
00175 drawCircle(2, 4, x_ + index_ + tw - tabRoundSize,
00176 y_ + h_ + tabHeight - tabRoundSize, tabRoundSize);
00177 glVertex2f(x_ + index_ + tw, y_ + h_);
00178
00179 glColor3f(1.0f, 1.0f, 1.0f);
00180 glVertex2f(x_ + index_ + tw, y_ + h_);
00181 glVertex2f(x_ + w_, y_ + h_);
00182
00183 glColor3f(0.4f, 0.4f, 0.6f);
00184 glVertex2f(x_ + w_, y_ + h_);
00185 glVertex2f(x_ + w_, y_);
00186 glVertex2f(x_, y_);
00187 glEnd();
00188
00189 GLWScrollPanel::draw();
00190
00191 label_.draw();
00192 }