There is no code here that actually alters "box" so it's not clear as to if there's an issue elsewhere.
Could printf be an issue here?
Consider adding brackets to your bool assignments as it's not perfectly clear the intention of the code.
SFML has in-built rectangle testing:
bool isIn = box.getGlobalBounds().contains(mPos);
I notice that mPos is integers so it's likely that this is a pixel location (mouse, probably?). Remember to convert this position to the view before using in world co-ordinates:
sf::Vector2f position(window.mapPixelToCoords(mPos));
The code the alters the box's position would be that:
void TITLE::addMenu(const char* displayName, MenuType menuType)
{
sf::Font font;
font.loadFromFile(DEFAULT_FONT);
// create and set up new menu
Menu* menu = new Menu();
// set type
menu->type = menuType;
// set up display name
menu->displayName.setString(displayName);
menu->displayName.setFont(font);
menu->displayName.setCharacterSize(12);
menu->displayName.setFillColor(HIGHLIGHT_COLOR);
// set up box to be next to title
menu->box.setFillColor(DEFAULT_COLOR);
menu->box.setSize(sf::Vector2f(150, 75));
menu->box.setPosition(0, 0);
// only set Menu if it doesn't exist
if(!containsMenu(menuType))
{
for(int i = 0; i < MenuTypeCount; i++)
{
if(menus[i] == nullptr)
{
menu->box.move(600, 100 + (110 * (i))); // set box's position + offset
menus[i] = menu;
break;
}
}
}
}
also, i did the changes you pointed out. I tested it and the conversion didn't change the value of the coords.
Thank you tho for pointing out the printf();. I used std::cout and it did correctly report the coords of the boxes,
but for my mouse positions i had:
- Mouse X: 0
- Mouse Y: 2100
with conversion and without.
Also, all this is on a Mac.. i forgot to point that out before.
I'm not sure if there are extra settings for the window i have to set up if i'm on a Mac, but it seems odd to me that it reports the mouse position as (0, 2100) in the up left corner, which normally would be (0, 0)