For example
sf::FloatRect area1(50, 400, 250, 200);
// 50 and 400 are the x and y, 250 and 200 are the width and height, approximately, I don't know your real values
sf::FloatRect area2(300, 400, 250, 200);
// etc.
then (using loc_x and loc_y like in your
other thread)
if (area1.contains(loc_x, loc_y)) {
std::cout << "1 clicked" << endl;
}
if (area2.contains(loc_x, loc_y)) {
std::cout << "2 clicked" << endl;
}
//etc.
(and then you could possibly modify it to use an sf::Vector or array and not use 9 if, and maybe use an sf::Event)
I don't understand, is there any reason why you would absolutely want to do it "without defining all the 9 cells one by one"? Because your 3 rectangles thing is weird as hell.
Alternatively, if you really don't want to define the 9 cells there is a way to compute what cells you're on.
Get the mouse position relative to the big rectangle surrounding all 9 cells.
Divide mouse x position by (big rectangle width / 3) and floor it to get the x position of the cell
Divide mouse y position by (big rectangle height / 3) and floor it to get the y position of the cell
Then if you want, do y * 3 + x + 1 to get the cell number