[Not needed] DrawString scale parameter

Moderator: Developers

DrawString scale parameter

Postby Matt » Thu Oct 18, 2018 2: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 10: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
the dreamer
 
 
 
Joined: 29 Dec 2017
Location: Siberia
Discord: m8f#0629

Re: DrawString scale parameter

Postby Matt » Thu Oct 18, 2018 6: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 11:57 pm

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

Re: DrawString scale parameter

Postby Matt » Fri Oct 19, 2018 2: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 2: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 2: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 Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: DrawString scale parameter

Postby Matt » Fri Oct 19, 2018 2: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 4: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 11: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
the dreamer
 
 
 
Joined: 29 Dec 2017
Location: Siberia
Discord: m8f#0629

Re: DrawString scale parameter

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

Spoiler: If we're talking status bars...
User avatar
Major Cooke
The road to Hell is paved in the carrion she leaves behind.
 
Joined: 28 Jan 2007
Discord: Major Cooke#0846

Re: DrawString scale parameter

Postby Player701 » Sun Oct 21, 2018 12:05 pm

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
You are now breathing manually.
 
Joined: 13 May 2009
Location: Russian Federation
Discord: Player701#8214

Re: DrawString scale parameter

Postby Matt » Tue Oct 23, 2018 10: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


Return to Closed Feature Suggestions

Who is online

Users browsing this forum: No registered users and 1 guest