[Added] DrawString scale parameter

Moderator: GZDoom Developers

DrawString scale parameter

Postby Matt » Thu Oct 18, 2018 1:35 am

Would be nice to be able to get different font sizes without either defining whole new fonts or changing the screen size just to draw a particular string.
User avatar
Matt
Putting the XD into *xdeath since 2007
 
Joined: 04 Jan 2004
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: DrawString scale parameter

Postby m8f » Thu Oct 18, 2018 9:14 am

Another way to draw scaled strings is to use Screen.DrawText with the proper parameters.
Matt, you most probably know about this already, I'm posting the code just to show that this way is not nice either.

Code: Select allExpand view
  ui void drawTextCenter(string text, int color, double scale, double relativeY,
                         Font font, int xAdjustment = 0)
  {
    int width    = int(scale * Screen.GetWidth());
    int height   = int(scale * (Screen.GetHeight() - font.GetHeight()));
    int position = width - font.StringWidth(text);

    double x = position * 0.5 + xAdjustment;
    double y = height   * relativeY;

    Screen.DrawText(font, color, x, y, text,
                    DTA_KeepRatio,     true,
                    DTA_VirtualWidth,  width,
                    DTA_VirtualHeight, height);
  }
User avatar
m8f
dreamer
 
 
 
Joined: 29 Dec 2017
Location: Siberia (UTC+7)
Discord: m8f#0629
Github ID: mmaulwurff
Operating System: Debian-like Linux (Debian, Ubuntu, Kali, Mint, etc) 64-bit

Re: DrawString scale parameter

Postby Matt » Thu Oct 18, 2018 5:32 pm

I did not :shock: and might need to spend a couple days studying that code snippet since about 90% of it is code I haven't even touched since ZScript started!
User avatar
Matt
Putting the XD into *xdeath since 2007
 
Joined: 04 Jan 2004
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: DrawString scale parameter

Postby Nash » Thu Oct 18, 2018 10:57 pm

m8f - what are "xAdjustment" and "relativeY" supposed to mean?
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: DrawString scale parameter

Postby Matt » Fri Oct 19, 2018 1:02 am

Can we reopen this feature suggestion? I've been trying to get m8f's suggested alternative to work for 2 hours and it's a horrible mess. I'm sure many other modders would have an even worse time with it. [Okay, the single biggest problem was that I was trying to create a function and call that function in 2 different places, so I couldn't see immediately that I'd defined one of the function's parameters differently than what I had assumed. It got a lot better though I am still relying on a function and a function call elsewhere rather than a single, easily debugged inline parameter.]

Also HUDfonts don't work with this, and scale is inversed so that bigger numbers mean smaller display output.

And the scale will throw off the position of the text.

And it doesn't clamp to the HUD size, so there needs to be an additional 2-3 lines to deal with that.

I'm just slowly hammering away at this one glitch and oversight at a time until I get something that can work like my feature suggestion. It might take me a day or two.

It really shouldn't be this painful to scale a font in comparison to an image.
Last edited by Matt on Fri Oct 19, 2018 1:36 am, edited 1 time in total.
User avatar
Matt
Putting the XD into *xdeath since 2007
 
Joined: 04 Jan 2004
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: DrawString scale parameter

Postby Graf Zahl » Fri Oct 19, 2018 1:26 am

Matt wrote:Can we reopen this feature suggestion?


Why? All this boils down to is "I cannot deal with how the function needs to be called and need an easier interface."

I think stuff like this is far better suited for some external utility library.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: DrawString scale parameter

Postby Matt » Fri Oct 19, 2018 1:37 am

We're talking about something approaching 30 lines of code in the VM to deal with something that is dealt natively with a similar function elsewhere, that's why.

I mean, unless you want a bunch of randos coding horrible gruesome hacks involve giant hundred-line if blocks and DrawImage, because I've half a mind to start doing that at this point...



EDIT: Right after going to bed at around 2 it finally occurred to me to stop trying to mess with Screen.DrawText and go back to depending on SetSize. If having to recalculate all the positioning so that it doesn't run with the scale is totally unavoidable, this is the simplest solution from the user point of view. Number of additional lines is closer to 4-8 depending on what other changes are required.
Last edited by Matt on Fri Oct 19, 2018 3:23 pm, edited 1 time in total.
User avatar
Matt
Putting the XD into *xdeath since 2007
 
Joined: 04 Jan 2004
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: DrawString scale parameter

Postby m8f » Fri Oct 19, 2018 10:20 am

Nash wrote:m8f - what are "xAdjustment" and "relativeY" supposed to mean?


Sorry for giving this snippet out of context - it was just to illustrate the use of Screen.DrawText().
This function is used, among other things, to draw scalable crosshair for Target Spy mod. There, relativeY means vertical position on the screen relative to the screen size. This parameter should be in range [0.0, 1.0], 0.0 for the top of the screen, and 1.0 for the bottom. xAdjustment is used to move text to the left or to the right, so it is properly centered. It is read from user settings, and is set by the user if they find the selected crosshair symbol to be off-center.
User avatar
m8f
dreamer
 
 
 
Joined: 29 Dec 2017
Location: Siberia (UTC+7)
Discord: m8f#0629
Github ID: mmaulwurff
Operating System: Debian-like Linux (Debian, Ubuntu, Kali, Mint, etc) 64-bit

Re: DrawString scale parameter

Postby Major Cooke » Sun Oct 21, 2018 10:17 am

Spoiler: If we're talking status bars...
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: DrawString scale parameter

Postby Player701 » Sun Oct 21, 2018 11:05 am

Major Cooke wrote:It's set up where scaling works as a multiplier so 2 is twice as big and so on.

Bigger, yes, but making strings smaller using your code doesn't work for me. Although I don't need this so badly, it might come in useful later on.

The method with Screen.DrawText looks fine as long as the HUD scale is not relevant, but unfortunately, most of the time it is. And while BaseStatusBar functions (DrawString, DrawImage and so on) abstract the HUD scale away, Screen.DrawText does not. Being a programmer myself, I don't like breaking the abstraction unless really necessary, so I kind of wonder why DrawString shouldn't have a scale parameter when DrawImage and co. already have it.
User avatar
Player701
 
 
 
Joined: 13 May 2009
Location: Russia
Discord: Player701#8214
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: DrawString scale parameter

Postby Matt » Tue Oct 23, 2018 9:48 am

I don't like breaking the abstraction unless really necessary, so I kind of wonder why DrawString shouldn't have a scale parameter when DrawImage and co. already have it.

^^^this. But from the discussion so far I take it this would be a much more complicated thing to add than it might look.

I've been noticing another problem, though: when I try to scale things with SetSize, it seems to "snap" between a few thresholds of sizes, instead of progressing smoothly at all points. Is there any way around that?
User avatar
Matt
Putting the XD into *xdeath since 2007
 
Joined: 04 Jan 2004
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: DrawString scale parameter

Postby phantombeta » Fri Jul 26, 2019 3:08 am

Bumping/revisiting this. The lack of a scale parameter forces us to use Screen.DrawText instead of BaseStatusbar.DrawString, which is a pain in the ass. We have to manually handle shadows, spacing, the HUD scaling settings, and much more, just so we can have scaled text in our HUDs. There's really no reason for DrawString to not have a scale parameter.
User avatar
phantombeta
In the meadow of sinful thoughts, every flower's a perfect one
 
Joined: 02 May 2013
Location: Brazil, South America, Earth, Orion-Cygnus Arm, Milky Way
Discord: phantombeta#2461
Twitch ID: phantombeta_
Github ID: Doom2fan
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: DrawString scale parameter

Postby Major Cooke » Fri Jul 26, 2019 12:40 pm

I have to agree here. The longer I look at this stuff, the more I feel like something official should be done.
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: DrawString scale parameter

Postby Player701 » Thu Nov 14, 2019 6:35 am

I'm really sorry for bumping this, but why was this closed as "Not needed"? As far as I'm aware, there is still no robust solution to this problem. In the context of a HUD, using Screen::DrawText is not an option (the reasons are explained in phantombeta's post above).

Upd: Unless I'm missing something here, I can provide a PR to implement this feature. However, If there really exists a non-hacky way to achieve HUD string scaling in the current GZDoom version, I'd appreciate if someone could tell me about it.
User avatar
Player701
 
 
 
Joined: 13 May 2009
Location: Russia
Discord: Player701#8214
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: DrawString scale parameter

Postby Player701 » Sun Nov 24, 2019 4:36 am

Sorry for double-posting, but I decided to take the initiative and went ahead with my PR. It just got merged, so this can be reclassified as "added". I hope this message will help other people who are interested in this feature, and they can finally stop using questionable hacks.
User avatar
Player701
 
 
 
Joined: 13 May 2009
Location: Russia
Discord: Player701#8214
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Next

Return to Closed Feature Suggestions

Who is online

Users browsing this forum: No registered users and 0 guests