refactored line addition

This commit is contained in:
devZoGok
2024-05-18 20:28:14 +03:00
parent 4dc308c420
commit d998175d8d
2 changed files with 24 additions and 22 deletions
+21 -22
View File
@@ -44,27 +44,19 @@ namespace vb01Gui{
Root *root = Root::getSingleton(); Root *root = Root::getSingleton();
Vector2 mousePos = getCursorPos(); Vector2 mousePos = getCursorPos();
guiNode = Root::getSingleton()->getGuiNode(); guiNode = Root::getSingleton()->getGuiNode();
string texUni = "texturingEnabled", diffColUni = "diffuseColor"; 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++){ if(!lines.empty()){
Text *text = new Text(fontPath, stringToWstring(lines[i])); for(int i = 0; i < lines.size(); i++)
addLine(stringToWstring(lines[i]));
Material *textMat = new Material(root->getLibPath() + "text"); this->lines[0]->getNode()->setVisible(true);
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);
listboxButton = new ListboxButton(this, pos, size, "ListboxButton"); 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"); 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); 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); Vector3 scrollButtonPos = Vector3(pos.x + size.x - 20, pos.y + lineHeight + lineHeight * scrollOffset * (double(maxDisplay - 2) / (maxDisplay + 1)), pos.z - .05);
scrollingButton->setPos(scrollButtonPos); scrollingButton->setPos(scrollButtonPos);
@@ -141,6 +133,8 @@ namespace vb01Gui{
} }
void Listbox::openUp(){ void Listbox::openUp(){
if(lines.empty()) return;
open = true; open = true;
Vector3 selOpPos = pos + Vector3(0, size.y * (selectedOption - scrollOffset + 1), 0) + textOffset; Vector3 selOpPos = pos + Vector3(0, size.y * (selectedOption - scrollOffset + 1), 0) + textOffset;
lines[selectedOption]->getNode()->setPosition(selOpPos); lines[selectedOption]->getNode()->setPosition(selOpPos);
@@ -222,11 +216,16 @@ namespace vb01Gui{
} }
void Listbox::addLine(wstring line){ void Listbox::addLine(wstring line){
Text *t = new Text(fontPath, line); float sc = .2;
Node *node = new Node(pos + Vector3(0, size.y * lines.size(), 0) + textOffset); Node *node = new Node(pos + Vector3(0, size.y * (lines.size() + 1), 0) + textOffset, Quaternion::QUAT_W, Vector3(sc, sc, 1));
node->addText(t); Root::getSingleton()->getGuiNode()->attachChild(node);
guiNode->attachChild(node); node->setVisible(false);
lines.push_back(t);
Text *text = new Text(fontPath, line);
text->setMaterial(textMat);
node->addText(text);
lines.push_back(text);
} }
string Listbox::convert(string str){ string Listbox::convert(string str){
+3
View File
@@ -8,6 +8,7 @@
namespace vb01{ namespace vb01{
class Node; class Node;
class Material;
class Text; class Text;
} }
@@ -40,6 +41,7 @@ namespace vb01Gui{
inline bool isCloseable(){return closeable;} inline bool isCloseable(){return closeable;}
void appendLines(std::vector<std::wstring>&); void appendLines(std::vector<std::wstring>&);
inline int getSelectedOption(){return selectedOption;} inline int getSelectedOption(){return selectedOption;}
inline void setMaxDisplay(int md){this->maxDisplay = md;}
inline int getMaxDisplay(){return maxDisplay;} inline int getMaxDisplay(){return maxDisplay;}
inline int getNumLines(){return lines.size();} inline int getNumLines(){return lines.size();}
std::vector<std::wstring> getContents(); std::vector<std::wstring> getContents();
@@ -65,6 +67,7 @@ namespace vb01Gui{
ScrollingButton *scrollingButton; ScrollingButton *scrollingButton;
vb01::Node *selRectNode, *guiNode; vb01::Node *selRectNode, *guiNode;
std::vector<vb01::Text*> lines; std::vector<vb01::Text*> lines;
vb01::Material *textMat = nullptr;
protected: protected:
int selectedOption = 0; int selectedOption = 0;
public: public: