diff --git a/listbox.cpp b/listbox.cpp index 5beec7e..29caa16 100644 --- a/listbox.cpp +++ b/listbox.cpp @@ -44,27 +44,19 @@ namespace vb01Gui{ Root *root = Root::getSingleton(); Vector2 mousePos = getCursorPos(); guiNode = Root::getSingleton()->getGuiNode(); + string texUni = "texturingEnabled", diffColUni = "diffuseColor"; + textMat = new Material(root->getLibPath() + "text"); + textMat->addBoolUniform(texUni, false); + textMat->addVec4Uniform(diffColUni, Vector4::VEC_IJKL); - for(int i = 0; i < lines.size(); i++){ - Text *text = new Text(fontPath, stringToWstring(lines[i])); + if(!lines.empty()){ + for(int i = 0; i < lines.size(); i++) + addLine(stringToWstring(lines[i])); - Material *textMat = new Material(root->getLibPath() + "text"); - textMat->addBoolUniform(texUni, false); - textMat->addVec4Uniform(diffColUni, Vector4::VEC_IJKL); - text->setMaterial(textMat); - - float sc = .2; - Node *node = new Node(pos + Vector3(0, size.y * (i + 1), 0) + textOffset, Quaternion::QUAT_W, Vector3(sc, sc, 1)); - node->addText(text); - guiNode->attachChild(node); - node->setVisible(false); - - this->lines.push_back(text); + this->lines[0]->getNode()->setVisible(true); } - this->lines[0]->getNode()->setVisible(true); - listboxButton = new ListboxButton(this, pos, size, "ListboxButton"); scrollingButton = new ScrollingButton(Vector3(pos.x + size.x - 20, pos.y + lineHeight, pos.z - .05), Vector2(20, lineHeight * (maxDisplay - 2) / (maxDisplay + 1)), "scrollingButton"); @@ -120,7 +112,7 @@ namespace vb01Gui{ p.y = pos.y + size.y * (maxDisplay - 1); } - selRectNode->setPosition(Vector3(p.x, p.y, -.05)); + selRectNode->setPosition(Vector3(p.x, p.y, p.z + .05)); Vector3 scrollButtonPos = Vector3(pos.x + size.x - 20, pos.y + lineHeight + lineHeight * scrollOffset * (double(maxDisplay - 2) / (maxDisplay + 1)), pos.z - .05); scrollingButton->setPos(scrollButtonPos); @@ -141,6 +133,8 @@ namespace vb01Gui{ } void Listbox::openUp(){ + if(lines.empty()) return; + open = true; Vector3 selOpPos = pos + Vector3(0, size.y * (selectedOption - scrollOffset + 1), 0) + textOffset; lines[selectedOption]->getNode()->setPosition(selOpPos); @@ -222,11 +216,16 @@ namespace vb01Gui{ } void Listbox::addLine(wstring line){ - Text *t = new Text(fontPath, line); - Node *node = new Node(pos + Vector3(0, size.y * lines.size(), 0) + textOffset); - node->addText(t); - guiNode->attachChild(node); - lines.push_back(t); + float sc = .2; + Node *node = new Node(pos + Vector3(0, size.y * (lines.size() + 1), 0) + textOffset, Quaternion::QUAT_W, Vector3(sc, sc, 1)); + Root::getSingleton()->getGuiNode()->attachChild(node); + node->setVisible(false); + + Text *text = new Text(fontPath, line); + text->setMaterial(textMat); + node->addText(text); + + lines.push_back(text); } string Listbox::convert(string str){ diff --git a/listbox.h b/listbox.h index eda2879..33fb7aa 100644 --- a/listbox.h +++ b/listbox.h @@ -8,6 +8,7 @@ namespace vb01{ class Node; + class Material; class Text; } @@ -40,6 +41,7 @@ namespace vb01Gui{ inline bool isCloseable(){return closeable;} void appendLines(std::vector&); inline int getSelectedOption(){return selectedOption;} + inline void setMaxDisplay(int md){this->maxDisplay = md;} inline int getMaxDisplay(){return maxDisplay;} inline int getNumLines(){return lines.size();} std::vector getContents(); @@ -65,6 +67,7 @@ namespace vb01Gui{ ScrollingButton *scrollingButton; vb01::Node *selRectNode, *guiNode; std::vector lines; + vb01::Material *textMat = nullptr; protected: int selectedOption = 0; public: