3D position coordinates

This commit is contained in:
devZoGok
2024-05-18 14:50:45 +03:00
parent 3b3e4c0109
commit 4dc308c420
11 changed files with 97 additions and 117 deletions
+23 -34
View File
@@ -15,18 +15,19 @@ using namespace std;
using namespace vb01; using namespace vb01;
namespace vb01Gui{ namespace vb01Gui{
Button::Button(Vector2 pos, Vector2 size, string name, string fontPath, int trigger, bool separate, string imagePath){ Button::Button(Vector3 p, Vector2 s, string n, string fontPath, int t, bool sep, string ip) :
this->pos = pos; pos(p),
this->size = size; size(s),
this->name = name; name(n),
this->separate = separate; trigger(t),
this->imagePath = imagePath; separate(sep),
this->trigger = trigger; imagePath(ip),
textOffset(Vector3(0, s.y, .1))
{
Root *root = Root::getSingleton(); Root *root = Root::getSingleton();
guiNode = root->getGuiNode(); guiNode = root->getGuiNode();
rect = new Quad(Vector3(size.x, size.y, 0), false); rect = new Quad(Vector3(size.x, size.y, 0), false);
rectNode = new Node(Vector3(pos.x, pos.y, 0)); rectNode = new Node(pos);
Material *mat = new Material(root->getLibPath() + "gui"); Material *mat = new Material(root->getLibPath() + "gui");
if(imagePath == ""){ if(imagePath == ""){
@@ -47,9 +48,9 @@ namespace vb01Gui{
if(separate){ if(separate){
text = new Text(fontPath, stringToWstring(name)); text = new Text(fontPath, stringToWstring(name));
text->setScale(.2);
textNode = new Node(Vector3(pos.x, pos.y + size.y, - .1)); float sc = .2;
textNode = new Node(pos + textOffset, Quaternion::QUAT_W, Vector3(sc, sc, 1));
textNode->addText(text); textNode->addText(text);
Material *textMat = new Material(root->getLibPath() + "text"); Material *textMat = new Material(root->getLibPath() + "text");
@@ -79,14 +80,14 @@ namespace vb01Gui{
GLFWwindow *window = Root::getSingleton()->getWindow(); GLFWwindow *window = Root::getSingleton()->getWindow();
glfwGetWindowSize(window, &width, &height); glfwGetWindowSize(window, &width, &height);
float posRatio[] = {pos.x / initWindowSize[0], pos.y / initWindowSize[1]}; float posRatio[] = {pos.x / initWindowSize[0], pos.y / initWindowSize[1]};
float sizeRatio[] = {size.x / initWindowSize[0], size.y / initWindowSize[1]}; float sizeRatio[] = {size.x / initWindowSize[0], size.y / initWindowSize[1]};
pos = Vector2(width * posRatio[0], height * posRatio[1]); pos = Vector3(width * posRatio[0], height * posRatio[1], pos.z);
size = Vector2(width * sizeRatio[0], height * sizeRatio[1]); size = Vector2(width * sizeRatio[0], height * sizeRatio[1]);
initWindowSize[0] = width; initWindowSize[0] = width;
initWindowSize[1] = height; initWindowSize[1] = height;
if(textNode) if(textNode)
textNode->setVisible(active); textNode->setVisible(active);
@@ -102,15 +103,13 @@ namespace vb01Gui{
mouseOver = false; mouseOver = false;
} }
void Button::setPos(Vector2 pos){ void Button::setPos(Vector3 pos){
this->pos = pos; this->pos = pos;
float z1 = rectNode->getPosition().z;
rectNode->setPosition(Vector3(pos.x, pos.y, z1));
if(textNode){ rectNode->setPosition(pos);
float z2 = textNode->getPosition().z;
textNode->setPosition(Vector3(pos.x, pos.y + size.y, z2)); if(textNode)
} textNode->setPosition(pos + textOffset);
} }
void Button::setSize(Vector2 size){ void Button::setSize(Vector2 size){
@@ -123,16 +122,6 @@ namespace vb01Gui{
((Material::Vector4Uniform*)rect->getMaterial()->getUniform(diffColUni))->value = color; ((Material::Vector4Uniform*)rect->getMaterial()->getUniform(diffColUni))->value = color;
} }
void Button::setZOrder(float zOrder){
Vector3 rectPos = rectNode->getPosition();
rectNode->setPosition(Vector3(rectPos.x, rectPos.y, zOrder));
if(textNode){
Vector3 textPos = textNode->getPosition();
textNode->setPosition(Vector3(textPos.x, textPos.y, zOrder - .1));
}
}
void Button::setImage(string image){ void Button::setImage(string image){
int texId = -1; int texId = -1;
Material *mat = rect->getMaterial(); Material *mat = rect->getMaterial();
+5 -5
View File
@@ -18,14 +18,14 @@ namespace vb01{
namespace vb01Gui{ namespace vb01Gui{
class Button{ class Button{
public: public:
Button(vb01::Vector2, vb01::Vector2, std::string, std::string, int = -1, bool = true, std::string = ""); Button(vb01::Vector3, vb01::Vector2, std::string, std::string, int = -1, bool = true, std::string = "");
virtual ~Button(); virtual ~Button();
virtual void update(); virtual void update();
virtual void onMouseOver(); virtual void onMouseOver();
virtual void onMouseOff(); virtual void onMouseOff();
virtual void onClick(){} virtual void onClick(){}
inline vb01::Vector2 getPos(){return pos;} inline vb01::Vector3 getPos(){return pos;}
void setPos(vb01::Vector2); void setPos(vb01::Vector3);
inline vb01::Vector2 getSize(){return size;} inline vb01::Vector2 getSize(){return size;}
void setSize(vb01::Vector2); void setSize(vb01::Vector2);
inline std::string getName(){return name;} inline std::string getName(){return name;}
@@ -35,14 +35,14 @@ namespace vb01Gui{
inline vb01::Vector4 getColor(){return color;} inline vb01::Vector4 getColor(){return color;}
inline int getTrigger(){return trigger;} inline int getTrigger(){return trigger;}
void setColor(vb01::Vector4); void setColor(vb01::Vector4);
void setZOrder(float);
void setImage(std::string); void setImage(std::string);
protected: protected:
int trigger, initWindowSize[2]; int trigger, initWindowSize[2];
bool separate, active = true, mouseOver = false; bool separate, active = true, mouseOver = false;
vb01::Quad *rect; vb01::Quad *rect;
vb01::Node *rectNode, *textNode = nullptr, *guiNode; vb01::Node *rectNode, *textNode = nullptr, *guiNode;
vb01::Vector2 pos, size; vb01::Vector3 pos, textOffset;
vb01::Vector2 size;
vb01::Text *text = nullptr; vb01::Text *text = nullptr;
std::string name, imagePath, texUni = "texturingEnabled", diffColUni = "diffuseColor"; std::string name, imagePath, texUni = "texturingEnabled", diffColUni = "diffuseColor";
std::vector<vb01::Texture*> textures; std::vector<vb01::Texture*> textures;
+4 -7
View File
@@ -7,18 +7,15 @@ using namespace vb01;
using namespace std; using namespace std;
namespace vb01Gui{ namespace vb01Gui{
Checkbox::CheckboxButton::CheckboxButton(Checkbox *ch, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, "", -1, separate) { Checkbox::CheckboxButton::CheckboxButton(Checkbox *ch, Vector3 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, "", -1, separate), checkbox(ch) {}
checkbox = ch;
}
void Checkbox::CheckboxButton::onClick() { void Checkbox::CheckboxButton::onClick() {
checkbox->check(); checkbox->check();
float col = (checkbox->isChecked() ? .6 : .2); float col = (checkbox->isChecked() ? .6 : .2);
setColor(Vector4(col, col, col, 1)); setColor(Vector4(col, col, col, 1));
} }
Checkbox::Checkbox(Vector2 pos, string fontPath){ Checkbox::Checkbox(Vector3 p, string fontPath) : pos(p){
this->pos = pos;
checkboxButton = new CheckboxButton(this, pos, Vector2(length,length), "CheckboxButton", false); checkboxButton = new CheckboxButton(this, pos, Vector2(length,length), "CheckboxButton", false);
/* /*
+4 -4
View File
@@ -12,7 +12,7 @@ namespace vb01{
namespace vb01Gui{ namespace vb01Gui{
class Checkbox { class Checkbox {
public: public:
Checkbox(vb01::Vector2, std::string); Checkbox(vb01::Vector3, std::string);
~Checkbox(); ~Checkbox();
void update(){} void update(){}
virtual void check(); virtual void check();
@@ -20,7 +20,7 @@ namespace vb01Gui{
private: private:
class CheckboxButton : public Button { class CheckboxButton : public Button {
public: public:
CheckboxButton(Checkbox*, vb01::Vector2, vb01::Vector2, std::string, bool); CheckboxButton(Checkbox*, vb01::Vector3, vb01::Vector2, std::string, bool);
void onClick(); void onClick();
private: private:
Checkbox *checkbox = nullptr; Checkbox *checkbox = nullptr;
@@ -28,9 +28,9 @@ namespace vb01Gui{
const int length = 15; const int length = 15;
bool checked = false; bool checked = false;
vb01::Vector2 pos; vb01::Vector3 pos;
CheckboxButton *checkboxButton; CheckboxButton *checkboxButton;
vb01::Node *checkNode = nullptr; vb01::Node *checkNode = nullptr;
public: public:
inline CheckboxButton* getCheckboxButton(){return checkboxButton;} inline CheckboxButton* getCheckboxButton(){return checkboxButton;}
}; };
+20 -19
View File
@@ -12,7 +12,7 @@ using namespace vb01;
using namespace std; using namespace std;
namespace vb01Gui{ namespace vb01Gui{
Listbox::ListboxButton::ListboxButton(Listbox *l, Vector2 pos, Vector2 size, string name) : Button(pos, size, name, "", -1, false){listbox = l;} Listbox::ListboxButton::ListboxButton(Listbox *l, Vector3 pos, Vector2 size, string name) : Button(pos, size, name, "", -1, false), listbox(l) {}
void Listbox::ListboxButton::onClick(){ void Listbox::ListboxButton::onClick(){
if(!listbox->isOpen()) if(!listbox->isOpen())
@@ -29,18 +29,18 @@ namespace vb01Gui{
} }
} }
Listbox::ScrollingButton::ScrollingButton(Vector2 pos, Vector2 size, string name) : Button(pos, size, name, "", -1, false){} Listbox::ScrollingButton::ScrollingButton(Vector3 pos, Vector2 size, string name) : Button(pos, size, name, "", -1, false){}
void Listbox::ScrollingButton::onClick(){} void Listbox::ScrollingButton::onClick(){}
Listbox::Listbox(Vector2 pos, Vector2 size, std::vector<string> &lines, int maxDisplay, string fontPath, bool closeable){ Listbox::Listbox(Vector3 p, Vector2 s, std::vector<string> &lines, int md, string fp, bool cl) :
this->pos = pos; pos(p),
this->size = size; size(s),
this->maxDisplay = maxDisplay; maxDisplay(md),
this->fontPath = fontPath; fontPath(fp),
this->lineHeight = size.y; closeable(cl),
this->closeable = closeable; textOffset(Vector3(0, 0, .3))
{
Root *root = Root::getSingleton(); Root *root = Root::getSingleton();
Vector2 mousePos = getCursorPos(); Vector2 mousePos = getCursorPos();
guiNode = Root::getSingleton()->getGuiNode(); guiNode = Root::getSingleton()->getGuiNode();
@@ -48,14 +48,14 @@ namespace vb01Gui{
for(int i = 0; i < lines.size(); i++){ for(int i = 0; i < lines.size(); i++){
Text *text = new Text(fontPath, stringToWstring(lines[i])); Text *text = new Text(fontPath, stringToWstring(lines[i]));
text->setScale(.2);
Material *textMat = new Material(root->getLibPath() + "text"); Material *textMat = new Material(root->getLibPath() + "text");
textMat->addBoolUniform(texUni, false); textMat->addBoolUniform(texUni, false);
textMat->addVec4Uniform(diffColUni, Vector4::VEC_IJKL); textMat->addVec4Uniform(diffColUni, Vector4::VEC_IJKL);
text->setMaterial(textMat); text->setMaterial(textMat);
Node *node = new Node(Vector3(pos.x, pos.y + size.y * (i + 1), textZCoord)); 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); node->addText(text);
guiNode->attachChild(node); guiNode->attachChild(node);
node->setVisible(false); node->setVisible(false);
@@ -67,9 +67,8 @@ namespace vb01Gui{
listboxButton = new ListboxButton(this, pos, size, "ListboxButton"); listboxButton = new ListboxButton(this, pos, size, "ListboxButton");
scrollingButton = new ScrollingButton(Vector2(pos.x + size.x - 20, pos.y + lineHeight), 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");
scrollingButton->setColor(Vector4(.2, .2, .2, 1)); scrollingButton->setColor(Vector4(.2, .2, .2, 1));
scrollingButton->setZOrder(-.05);
scrollingButton->setActive(false); scrollingButton->setActive(false);
Quad *selRect = new Quad(Vector3(size.x, size.y, 0), false); Quad *selRect = new Quad(Vector3(size.x, size.y, 0), false);
@@ -99,13 +98,14 @@ namespace vb01Gui{
delete selRectNode; delete selRectNode;
} }
//TODO selection rectangle Z offset
void Listbox::update(){ void Listbox::update(){
scrollingButton->update(); scrollingButton->update();
listboxButton->update(); listboxButton->update();
if(open){ if(open){
Vector2 mousePos = getCursorPos(); Vector2 mousePos = getCursorPos();
Vector2 p = pos; Vector3 p = pos;
if(mousePos.y > pos.y && mousePos.y < pos.y + size.y * maxDisplay){ if(mousePos.y > pos.y && mousePos.y < pos.y + size.y * maxDisplay){
selectedOption = scrollOffset + ((int)(mousePos.y - pos.y) / ((int)size.y)); selectedOption = scrollOffset + ((int)(mousePos.y - pos.y) / ((int)size.y));
@@ -122,7 +122,7 @@ namespace vb01Gui{
selRectNode->setPosition(Vector3(p.x, p.y, -.05)); selRectNode->setPosition(Vector3(p.x, p.y, -.05));
Vector2 scrollButtonPos = Vector2(pos.x + size.x - 20, pos.y + lineHeight + lineHeight * scrollOffset * (double(maxDisplay - 2) / (maxDisplay + 1))); 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);
} }
} }
@@ -142,7 +142,8 @@ namespace vb01Gui{
void Listbox::openUp(){ void Listbox::openUp(){
open = true; open = true;
lines[selectedOption]->getNode()->setPosition(Vector3(pos.x, pos.y + size.y * (selectedOption-scrollOffset + 1), textZCoord)); Vector3 selOpPos = pos + Vector3(0, size.y * (selectedOption - scrollOffset + 1), 0) + textOffset;
lines[selectedOption]->getNode()->setPosition(selOpPos);
lines[selectedOption]->getNode()->setVisible(false); lines[selectedOption]->getNode()->setVisible(false);
Vector2 size = listboxButton->getSize(); Vector2 size = listboxButton->getSize();
size.y *= maxDisplay; size.y *= maxDisplay;
@@ -167,7 +168,7 @@ namespace vb01Gui{
for(int i = scrollOffset; i < scrollOffset + maxDisplay; i++) for(int i = scrollOffset; i < scrollOffset + maxDisplay; i++)
lines[i]->getNode()->setVisible(false); lines[i]->getNode()->setVisible(false);
lines[selectedOption]->getNode()->setPosition(Vector3(pos.x, pos.y + size.y, textZCoord)); lines[selectedOption]->getNode()->setPosition(pos + Vector3(0, size.y, 0) + textOffset);
lines[selectedOption]->getNode()->setVisible(true); lines[selectedOption]->getNode()->setVisible(true);
onClose(); onClose();
@@ -222,7 +223,7 @@ namespace vb01Gui{
void Listbox::addLine(wstring line){ void Listbox::addLine(wstring line){
Text *t = new Text(fontPath, line); Text *t = new Text(fontPath, line);
Node *node = new Node(Vector3(pos.x, pos.y - size.y * lines.size(), textZCoord)); Node *node = new Node(pos + Vector3(0, size.y * lines.size(), 0) + textOffset);
node->addText(t); node->addText(t);
guiNode->attachChild(node); guiNode->attachChild(node);
lines.push_back(t); lines.push_back(t);
+7 -6
View File
@@ -16,13 +16,13 @@ namespace vb01Gui{
public: public:
class ListboxButton : public Button{ class ListboxButton : public Button{
public: public:
ListboxButton(Listbox*, vb01::Vector2, vb01::Vector2, std::string); ListboxButton(Listbox*, vb01::Vector3, vb01::Vector2, std::string);
void onClick(); void onClick();
private: private:
Listbox *listbox = nullptr; Listbox *listbox = nullptr;
}; };
Listbox(vb01::Vector2, vb01::Vector2, std::vector<std::string>&, int, std::string, bool = true); Listbox(vb01::Vector3, vb01::Vector2, std::vector<std::string>&, int, std::string, bool = true);
~Listbox(); ~Listbox();
void update(); void update();
void openUp(); void openUp();
@@ -43,23 +43,24 @@ namespace vb01Gui{
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();
inline vb01::Vector2 getPos(){return pos;} inline vb01::Vector3 getPos(){return pos;}
inline vb01::Vector2 getSize(){return size;} inline vb01::Vector2 getSize(){return size;}
private: private:
class ScrollingButton : public Button{ class ScrollingButton : public Button{
public: public:
ScrollingButton(vb01::Vector2, vb01::Vector2, std::string); ScrollingButton(vb01::Vector3, vb01::Vector2, std::string);
void onClick(); void onClick();
private: private:
}; };
std::string convert(std::string); std::string convert(std::string);
float textZCoord = -.3, lineHeight; float lineHeight;
int maxDisplay, scrollOffset = 0; int maxDisplay, scrollOffset = 0;
bool open = false, closeable = false; bool open = false, closeable = false;
std::string fontPath; std::string fontPath;
vb01::Vector2 pos, size; vb01::Vector3 pos, textOffset;
vb01::Vector2 size;
ListboxButton *listboxButton; ListboxButton *listboxButton;
ScrollingButton *scrollingButton; ScrollingButton *scrollingButton;
vb01::Node *selRectNode, *guiNode; vb01::Node *selRectNode, *guiNode;
+12 -21
View File
@@ -12,9 +12,7 @@ using namespace std;
using namespace vb01; using namespace vb01;
namespace vb01Gui{ namespace vb01Gui{
Slider::MovableSliderButton::MovableSliderButton(Slider *slider, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, "", -1, separate) { Slider::MovableSliderButton::MovableSliderButton(Slider *sl, Vector3 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, "", -1, separate), slider(sl) {}
this->slider = slider;
}
void Slider::MovableSliderButton::onClick() { void Slider::MovableSliderButton::onClick() {
clicked = !clicked; clicked = !clicked;
@@ -33,9 +31,7 @@ namespace vb01Gui{
} }
} }
Slider::StaticSliderButton::StaticSliderButton(Slider *slider, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, "", -1, separate) { Slider::StaticSliderButton::StaticSliderButton(Slider *sl, Vector3 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, "", -1, separate), slider(sl) {}
this->slider = slider;
}
void Slider::StaticSliderButton::onClick() { void Slider::StaticSliderButton::onClick() {
Vector2 cursorPos = getCursorPos(); Vector2 cursorPos = getCursorPos();
@@ -43,20 +39,14 @@ namespace vb01Gui{
slider->setValue(((double) buttonClickPoint / slider->getSize().x) * slider->getMaxValue()); slider->setValue(((double) buttonClickPoint / slider->getSize().x) * slider->getMaxValue());
} }
Slider::Slider(Vector2 pos, Vector2 size, double minValue, double maxValue) { Slider::Slider(Vector3 p, Vector2 s, double min, double max) : pos(p), size(s), minValue(min), maxValue(max) {
this->pos = pos;
this->size = size;
this->minValue = minValue;
this->maxValue = maxValue;
staticSliderButton = new StaticSliderButton(this, pos, size, "StaticSliderButton", false); staticSliderButton = new StaticSliderButton(this, pos, size, "StaticSliderButton", false);
movableSliderButton = new MovableSliderButton(this, Vector2(pos.x + staticSliderButton->getSize().x / 1, pos.y - 15), Vector2(10, 40), "MovableSliderButton", false); movableSliderButton = new MovableSliderButton(this, pos + Vector3(staticSliderButton->getSize().x, -15, 0), Vector2(10, 40), "MovableSliderButton", false);
value = (maxValue - minValue) / 2; value = (maxValue - minValue) / 2;
} }
Slider::~Slider() { Slider::~Slider() {}
}
void Slider::update() { void Slider::update() {
if (value < minValue) if (value < minValue)
@@ -64,15 +54,16 @@ namespace vb01Gui{
else if (value > maxValue) else if (value > maxValue)
value = maxValue; value = maxValue;
Vector2 p = movableSliderButton->getPos(), s = movableSliderButton->getSize(); Vector3 p = movableSliderButton->getPos();
Vector2 s = movableSliderButton->getSize();
p.x = pos.x + (double) size.x / maxValue * value; p.x = pos.x + (double) size.x / maxValue * value;
movableSliderButton->update(); movableSliderButton->update();
movableSliderButton->setPos(p); movableSliderButton->setPos(p);
if(textbox && !textbox->isEnabled()){ if(textbox && !textbox->isEnabled()){
ostringstream ss; ostringstream ss;
ss << value; ss << value;
textbox->setEntry(stringToWstring(ss.str())); textbox->setEntry(stringToWstring(ss.str()));
} }
} }
} }
+6 -5
View File
@@ -8,7 +8,7 @@
namespace vb01Gui{ namespace vb01Gui{
class Slider { class Slider {
public: public:
Slider(vb01::Vector2, vb01::Vector2, double, double); Slider(vb01::Vector3, vb01::Vector2, double, double);
~Slider(); ~Slider();
void update(); void update();
inline void setTextbox(Textbox *t){this->textbox=t;} inline void setTextbox(Textbox *t){this->textbox=t;}
@@ -16,13 +16,13 @@ namespace vb01Gui{
inline double getValue(){return value;} inline double getValue(){return value;}
inline double getMaxValue(){return maxValue;} inline double getMaxValue(){return maxValue;}
inline void setValue(double v){this->value=v;} inline void setValue(double v){this->value=v;}
inline vb01::Vector2 getPos(){return pos;} inline vb01::Vector3 getPos(){return pos;}
inline vb01::Vector2 getSize(){return size;} inline vb01::Vector2 getSize(){return size;}
inline Textbox* getTextbox(){return textbox;} inline Textbox* getTextbox(){return textbox;}
private: private:
class MovableSliderButton : public Button { class MovableSliderButton : public Button {
public: public:
MovableSliderButton(Slider*, vb01::Vector2, vb01::Vector2, std::string, bool); MovableSliderButton(Slider*, vb01::Vector3, vb01::Vector2, std::string, bool);
void onClick(); void onClick();
void update(); void update();
private: private:
@@ -32,7 +32,7 @@ namespace vb01Gui{
class StaticSliderButton : public Button { class StaticSliderButton : public Button {
public: public:
StaticSliderButton(Slider*, vb01::Vector2, vb01::Vector2, std::string, bool); StaticSliderButton(Slider*, vb01::Vector3, vb01::Vector2, std::string, bool);
void onClick(); void onClick();
private: private:
Slider *slider; Slider *slider;
@@ -41,7 +41,8 @@ namespace vb01Gui{
MovableSliderButton *movableSliderButton = nullptr; MovableSliderButton *movableSliderButton = nullptr;
StaticSliderButton *staticSliderButton = nullptr; StaticSliderButton *staticSliderButton = nullptr;
double minValue, value, maxValue; double minValue, value, maxValue;
vb01::Vector2 pos, size; vb01::Vector3 pos;
vb01::Vector2 size;
Textbox *textbox = nullptr; Textbox *textbox = nullptr;
public: public:
inline MovableSliderButton* getMovableSliderButton(){return movableSliderButton;} inline MovableSliderButton* getMovableSliderButton(){return movableSliderButton;}
+5 -3
View File
@@ -80,17 +80,19 @@ namespace vb01{
Vector2 size = glyph.size, bearing = glyph.bearing; Vector2 size = glyph.size, bearing = glyph.bearing;
if(horizontal) if(horizontal)
advanceOffset.x += (size.x + bearing.x); advanceOffset.x += node->getScale().x * (size.x + bearing.x);
else else
advanceOffset.y += size.y; advanceOffset.y += node->getScale().y * size.y;
} }
} }
void Text::prepareGlyphs(Glyph glyph, Vector2 advanceOffset){ void Text::prepareGlyphs(Glyph glyph, Vector2 advanceOffset){
Vector3 nodePos = node->getPosition(); Vector3 nodePos = node->getPosition();
Vector2 origin = Vector2(nodePos.x, nodePos.y) + (advanceOffset * scale); Vector2 origin = Vector2(nodePos.x, nodePos.y) + (advanceOffset * scale);
Vector3 scale = node->getScale();
Vector2 size = glyph.size * scale, bearing = glyph.bearing * scale; Vector2 size = Vector2(glyph.size.x * scale.x, glyph.size.y * scale.y);
Vector2 bearing = Vector2(glyph.bearing.x * scale.x, glyph.bearing.y * scale.y);
float data[] = { float data[] = {
origin.x + bearing.x, origin.y - bearing.y, 0, 0, origin.x + bearing.x, origin.y - bearing.y, 0, 0,
+6 -9
View File
@@ -14,7 +14,7 @@ using namespace vb01;
using namespace std; using namespace std;
namespace vb01Gui{ namespace vb01Gui{
Textbox::TextboxButton::TextboxButton(Textbox *t, Vector2 pos, Vector2 size, string name) : Button(pos, size, name, "", -1, false) {textbox = t;} Textbox::TextboxButton::TextboxButton(Textbox *t, Vector3 pos, Vector2 size, string name) : Button(pos, size, name, "", -1, false), textbox(t) {}
void Textbox::TextboxButton::onClick(){ void Textbox::TextboxButton::onClick(){
if(!textbox->isEnabled()) if(!textbox->isEnabled())
@@ -23,28 +23,25 @@ namespace vb01Gui{
textbox->disable(); textbox->disable();
} }
Textbox::Textbox(Vector2 pos, Vector2 size, string fontPath, wstring entry){ Textbox::Textbox(Vector3 p, Vector2 s, string fp, wstring entry) : pos(p), size(s), fontPath(fp), cursorZCoord(.01){
this->pos = pos;
this->size = size;
this->fontPath = fontPath;
textboxButton = new TextboxButton(this, pos, size, "TextboxButton"); textboxButton = new TextboxButton(this, pos, size, "TextboxButton");
string libPath = Root::getSingleton()->getLibPath(); string libPath = Root::getSingleton()->getLibPath();
guiNode = Root::getSingleton()->getGuiNode(); guiNode = Root::getSingleton()->getGuiNode();
text = new Text(fontPath, entry); text = new Text(fontPath, entry);
text->setScale(.5);
Material *textMat = new Material(libPath + "text"); Material *textMat = new Material(libPath + "text");
textMat->addBoolUniform("texturingEnabled", false); textMat->addBoolUniform("texturingEnabled", false);
textMat->addVec4Uniform("diffuseColor", Vector4(1, 1, 1, 1)); textMat->addVec4Uniform("diffuseColor", Vector4(1, 1, 1, 1));
text->setMaterial(textMat); text->setMaterial(textMat);
textNode = new Node(Vector3(pos.x, pos.y + size.y, -.1));
float sc = .5;
textNode = new Node(Vector3(pos.x, pos.y + size.y, pos.z + cursorZCoord), Quaternion::QUAT_W, Vector3(sc, sc, 1));
textNode->addText(text); textNode->addText(text);
guiNode->attachChild(textNode); guiNode->attachChild(textNode);
cursorPosOffset = entry.length(); cursorPosOffset = entry.length();
cursorRect = new Quad(Vector3(cursorWidth, size.y, 0), false); cursorRect = new Quad(Vector3(cursorWidth, size.y, 0), false);
cursorNode = new Node(Vector3(pos.x + text->getLength(), pos.y, cursorZCoord)); cursorNode = new Node(Vector3(pos.x + text->getLength(), pos.y, pos.z + cursorZCoord));
Material *mat = new Material(libPath + "gui"); Material *mat = new Material(libPath + "gui");
mat->addBoolUniform("texturingEnabled", false); mat->addBoolUniform("texturingEnabled", false);
mat->addVec4Uniform("diffuseColor", Vector4(1, 1, 1, 1)); mat->addVec4Uniform("diffuseColor", Vector4(1, 1, 1, 1));
+5 -4
View File
@@ -15,7 +15,7 @@ namespace vb01Gui{
class Textbox{ class Textbox{
public: public:
Textbox(vb01::Vector2, vb01::Vector2, std::string, std::wstring = L""); Textbox(vb01::Vector3, vb01::Vector2, std::string, std::wstring = L"");
~Textbox(); ~Textbox();
void update(); void update();
void enable(); void enable();
@@ -33,7 +33,7 @@ namespace vb01Gui{
private: private:
class TextboxButton : public Button{ class TextboxButton : public Button{
public: public:
TextboxButton(Textbox*, vb01::Vector2, vb01::Vector2, std::string); TextboxButton(Textbox*, vb01::Vector3, vb01::Vector2, std::string);
void onClick(); void onClick();
private: private:
Textbox *textbox; Textbox *textbox;
@@ -41,9 +41,10 @@ namespace vb01Gui{
inline bool canChangeCursor(){return vb01::getTime() - lastBlinkTime > 250;} inline bool canChangeCursor(){return vb01::getTime() - lastBlinkTime > 250;}
inline bool canDeleteChar(){return vb01::getTime() - lastDeleteTime > 50;} inline bool canDeleteChar(){return vb01::getTime() - lastDeleteTime > 50;}
float cursorZCoord = -.2; float cursorZCoord;
const int cursorWidth = 5; const int cursorWidth = 5;
vb01::Vector2 pos, size; vb01::Vector3 pos;
vb01::Vector2 size;
std::wstring entry = L""; std::wstring entry = L"";
std::string fontPath = ""; std::string fontPath = "";
bool enabled = false, canShowCursor = false, capitalLeters = false, deleteCharacters = false; bool enabled = false, canShowCursor = false, capitalLeters = false, deleteCharacters = false;