Hello,
I am writing a program(in Visual Studio) that creates a function graph. The function graph consists of RectangleShape and CircleShape. I needed to, when changing the window, by shifting the frames of window, the graph was scaled, without changing its ratio (not stretched). For example, let's say the graph and the window are 800x800. If I drag the left frame to the right, then the window becomes, supposably, 500x800, then the graph should become 500x500. I tried to resize objects, reduce points, but nothing came of it ...
Here is a piece of code:
RectangleShape shape3(Vector2f(2, 800)); // axis y
RectangleShape shape4(Vector2f(800, 2)); // axis x
RectangleShape point1(Vector2f(1, 6)); // point x
RectangleShape point2(Vector2f(6, 1)); // point y
shape3.setPosition(h / 2, 0); // axis movement y
shape4.setPosition(0, w / 2); // axis movement x
for (int i = 0; i <= w; i += 4) // x coordinate points
{
point1.setPosition(i, h / 2);
window.draw(point1);
}
for (int i = 0; i <= h; i += 4) // y coordinate points
{
point2.setPosition(w / 2, i);
window.draw(point2);
}
...
// here I tried to do something
if (w < h)
{
//shape3.setScale(w/h, w/h);
//shape4.setScale(w / h, w / h);
shape3.move(0, 30);
h -= (h - w);
shape3.setSize(Vector2f(6.f, h));
//window.setSize(sf::Vector2u(w, h));
}
if (h < w)
{
shape4.move(30, 0);
//shape3.setScale(h / w, h / w);
//shape4.setScale(h / w, h / w);
w -= (w - h);
shape4.setSize(Vector2f(w, 6.f));
//window.setSize(sf::Vector2u(w, h));
}