Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Scaling a window with objects(Shape)  (Read 963 times)

0 Members and 1 Guest are viewing this topic.

Kirill_Amber

  • Newbie
  • *
  • Posts: 3
    • View Profile
Scaling a window with objects(Shape)
« 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 ...


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));
                        }

 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: Scaling a window with objects(Shape)
« Reply #1 on: August 08, 2019, 07:34:25 am »
Handle the resize event and adjust the view accordingly. See the tutorial for more details.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Kirill_Amber

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Scaling a window with objects(Shape)
« Reply #2 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?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: Scaling a window with objects(Shape)
« Reply #3 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Kirill_Amber

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Scaling a window with objects(Shape)
« Reply #4 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

 

anything