Hello, so i am trying to do "sf::Vector2f getSize();" function. I assign the x and y values in the CPP file, but when I call the function outside of the class it's still zero. I tested out by cout ing the values in class CPP file, it outputs the current values. But cout ing outside is zero.
This the class function cpp file.
Note: When i draw a rectangle shape border around the text, it covers the text. So its sizes are correct. So i pass in those sizes to getSize() value.
void Label::setValues() {
if (firstRun) {
labelText.setPosition(position);
labelText.setCharacterSize(fontSize);
labelText.setString(labelName);
labelText.setFillColor(fontColor);
labelBorder.setPosition(sf::Vector2f(position.x + labelText.getLocalBounds().left, position.y + labelText.getLocalBounds().top));
labelBorder.setSize(sf::Vector2f(labelText.getLocalBounds().width, labelText.getLocalBounds().height));
labelBorder.setOutlineThickness(2);
labelBorder.setOutlineColor(borderColor);
labelBorder.setFillColor(sf::Color::Transparent);
//**** HERE IS THE PROBLEM *****
labelSize = labelBorder.getSize();
cout << labelSize.x << "|" << labelSize.y << endl;
//correct outputs ^ of "74|11"
firstRun = false;
}
}
//for label size its "sf::Vector2f labelSize";
sf::Vector2f Label::getSize() {
return labelSize;
}
This is where i call the function outside the file.
void WindowManager::startUp() {
window.create(sf::VideoMode(windowWidth, windowHeight), "Windows Form");
label.setBorderColor(sf::Color::Magenta);
label.setLabelName("Hello Button");
label.setFontSize(15);
label.setPosition(0, button.getSize().y/2);
//**** HERE IS THE PROBLEM *****
button.setPosition(label.getSize().x + 10, button.getPosition().y);
cout << label.getSize().x << "|" << label.getSize().y << endl;
//wrong outputs ^ its "0|0"
}