Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Values are still zero after "changing".  (Read 1007 times)

0 Members and 1 Guest are viewing this topic.

Hey

  • Newbie
  • *
  • Posts: 5
    • View Profile
Values are still zero after "changing".
« on: June 21, 2018, 08:47:11 pm »
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"
}
 

Rosme

  • Full Member
  • ***
  • Posts: 169
  • Proud member of the shoe club
    • View Profile
    • Code-Concept
Re: Values are still zero after "changing".
« Reply #1 on: June 22, 2018, 02:15:08 pm »
Well where do you call setValues? There's nothing here showing us that.

You should use a debugger to see what is going.
GitHub
Code Concept
Twitter
Rosme on IRC/Discord

 

anything