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

Author Topic: Keeping objects at the same size, regardless of zoom  (Read 2023 times)

0 Members and 1 Guest are viewing this topic.

Jamin Grey

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Of Stranger Flames
Keeping objects at the same size, regardless of zoom
« on: July 26, 2012, 10:38:47 pm »
What's the best way to keep an object, positioned and moved around in the view, drawn at the same size regardless of that view's size?

What I mean is, I want some sf::Text to be drawn at an easy-to-read size, even when the view is zoomed way out. But I don't want to just reset the view like I do for drawing a GUI, because the text is positioned by the view it's inside of.

The only way I can think of doing this, is by not messing with the view at all and knowing how much the view is zoomed in (say, 500%), zoom in the text by the same amount. Is that the best option?

Note: To 'zoom in' the view, I do this:
worldView.setSize((originalWidth * worldZoom), (originalHeight * worldZoom));

(I'm using SFML 2)
Of Stranger Flames - My work-in-progress para-historical (and classically-inspired) 2D rpg.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10976
    • View Profile
    • development blog
    • Email
Re: Keeping objects at the same size, regardless of zoom
« Reply #1 on: July 26, 2012, 11:45:47 pm »
Since you want to keep the text in the other view, that's the easiest way to do it, but probably not the best.
Another possibility would be to keep track of the displayed view size (you can use convertCoord with (0,0) and (WndWidth, WndHeight) to get the rectangle) and then match the text to the visible view area (you know what you see in the view and you know the size of the window). This can get very tricky for rotate views... ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Jamin Grey

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Of Stranger Flames
Re: Keeping objects at the same size, regardless of zoom
« Reply #2 on: July 27, 2012, 02:41:16 am »
Thankfully, I'm not using rotated views. I think, since I keep track of the scale anyway, I'll just scale it the opposite of what the view is scaling - it's working fine. I decided to actually slightly reduce the size of the text as it scales (because it obscures too much), so it does get somewhat smaller, but not as small as it'd normally get.

Thank you for the help.
Of Stranger Flames - My work-in-progress para-historical (and classically-inspired) 2D rpg.