SFML community forums

Help => General => Topic started by: Kirill_Amber on August 08, 2019, 04:12:51 am

Title: Scaling a window with objects(Shape)
Post by: Kirill_Amber on August 08, 2019, 04:12:51 am
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 ...
(http://www.cyberforum.ru/attachments/1059557d1565181582t)
(http://www.cyberforum.ru/attachments/1059558d1565181582)
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));
                        }

 
Title: Re: Scaling a window with objects(Shape)
Post by: eXpl0it3r on August 08, 2019, 07:34:25 am
Handle the resize event and adjust the view accordingly. See the tutorial for more details.
Title: Re: Scaling a window with objects(Shape)
Post by: Kirill_Amber on August 08, 2019, 03:14:26 pm
Handle the resize event and adjust the view accordingly. See the tutorial for more details.
What tutorials can you, pls, recommend?
Title: Re: Scaling a window with objects(Shape)
Post by: eXpl0it3r on August 08, 2019, 03:17:58 pm
The official view tutorial is recommended to understand how the view works: https://www.sfml-dev.org/tutorials/2.5/graphics-view.php#showing-more-when-the-window-is-resized

For letter boxing there's also some code on the GitHub SFML Wiki.
Title: Re: Scaling a window with objects(Shape)
Post by: Kirill_Amber on August 08, 2019, 03:35:42 pm
The official view tutorial is recommended to understand how the view works: https://www.sfml-dev.org/tutorials/2.5/graphics-view.php#showing-more-when-the-window-is-resized

For letter boxing there's also some code on the GitHub SFML Wiki.
Thank, brah