How to you use values from other function in the same class?
Code:
#include "Shapes.h"
#include "Global.h"
#include <iostream>
#include <SFML/Graphics.hpp>
Shapes::Shapes()
{
//ctor
}
Shapes::~Shapes()
{
//dtor
}
void Shapes::setShapes()
{
MainButton1.setSize(sf::Vector2f(100,80));
MainButton1.setPosition(sf::Vector2f( ScreenWidth/ 10 , ScreenHeight / 4 ));
MainButton1.scale(2,1);
MainButton1.setFillColor(sf::Color::White);
MainButton1.setOutlineColor(sf::Color::Black);
MainButton1.setOutlineThickness(3);
MainButton2.setSize(sf::Vector2f(100,80));
MainButton2.setPosition(sf::Vector2f( ScreenWidth/ 10 , ScreenHeight / 2.5 ));
MainButton2.scale(2,1);
MainButton2.setFillColor(sf::Color::White);
MainButton2.setOutlineColor(sf::Color::Black);
MainButton2.setOutlineThickness(3);
MainButton1RED.setSize(sf::Vector2f(100,80));
MainButton1RED.setPosition(sf::Vector2f( ScreenWidth/ 10 , ScreenHeight / 4 ));
MainButton1RED.scale(2,1);
MainButton1RED.setFillColor(sf::Color::Yellow);
MainButton1RED.setOutlineColor(sf::Color::Black);
MainButton1RED.setOutlineThickness(3);
MainButton2RED.setSize(sf::Vector2f(100,80));
MainButton2RED.setPosition(sf::Vector2f( ScreenWidth/ 10 , ScreenHeight / 2.5 ));
MainButton2RED.scale(2,1);
MainButton2RED.setFillColor(sf::Color::Yellow);
MainButton2RED.setOutlineColor(sf::Color::Black);
MainButton2RED.setOutlineThickness(3);
}
void Shapes::ChangeButtonColor( int buttonNum )
{
if( buttonNum == 1) // this in main
{
buttonCOLOR = 1;
setButtonColor(buttonCOLOR);
}
else if ( buttonNum == 2) // this in main
{
buttonCOLOR = 2;
setButtonColor(buttonCOLOR);
}
else if ( buttonNum == 0) // this in main
{
buttonCOLOR = 0;
setButtonColor(buttonCOLOR);
}
}
int Shapes::setButtonColor(int buttonColor)
{
this->buttonCOLOR = buttonCOLOR;
return buttonCOLOR;
}
void Shapes::Draw(sf::RenderWindow &VoteApp)
{
if( 0 == buttonCOLOR )
{
VoteApp.draw(MainButton1);
VoteApp.draw(MainButton2);
std::cout << "should paint the two buttons white" << std::endl;
}
else if( 1 == buttonCOLOR)
{
VoteApp.draw(MainButton1RED);
VoteApp.draw(MainButton2);
std::cout << "should paint the button 1 yellow" << std::endl;
}
else if( 2 == buttonCOLOR )
{
VoteApp.draw(MainButton2RED);
VoteApp.draw(MainButton1);
std::cout << "should paint the button 2 yellow" << std::endl;
}
std::cout << "buttonColor: " << buttonCOLOR << std::endl;
}
I don't understand why it print out buttonColor : 72, instead of the value from the Shapes::setButtonColor(int buttonCOLOR) function. How do I make the buttonCOLOR from Shapes::ChangeButtonColor(int buttonNum) to have the same value in the Shapes:::Draw(sf::RenderWindow &VoteApp) function?