[ZScript] Status Bar elements regardless of scaling

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)

[ZScript] Status Bar elements regardless of scaling

Postby Virathas » Fri Nov 12, 2021 2:39 pm

Hey everyone!

I have lately been trying to improve my status bars, to have them support actual scaling. Problem is, I can't get it to work. Manipulating "SetSize" to actual resolution, and then setting postion via "XResolution" multiplied by a percentage value sometimes works. And it is exactly that, sometimes it works perfectly, for example "XResolution * 0.5" would display at the X center of the screen, but otherwise it will not display (actually displaying way away from the screen) or having the point (0,0) be somewhere to the left-center of the screen.

What is it that I am missing?

Things i want to do, is to have certain bars, like health bars, or image in specific relative location. Currently, since status bars scale in a way that the entire status bar is significantly shrunk, and it siimply look bad. Example in attachment 1.

What I would like to have is those icons to the top left of the status bar to be drawn at the top left of the actual screen.

Scenarios that this should work is:
- Various resolutions, i.e. 800x600, 1024x768, 1600x900
- Various scaling options, especially the "Use default scale"

Note, i do not use fullscreen status bar for this.

Also a side note, i use GZDoom 3.7.1 for this
You do not have the required permissions to view the files attached to this post.
User avatar
Virathas
 
Joined: 10 Aug 2017

Re: [ZScript] Status Bar elements regardless of scaling

Postby Player701 » Tue Nov 23, 2021 7:11 am

IIRC, you should call BeginHUD() before drawing the non-status bar elements of your HUD on the screen.
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: [ZScript] Status Bar elements regardless of scaling

Postby Virathas » Wed Nov 24, 2021 3:11 am

Over the last two weeks i've been working around this and finally got it work mostly as I want. UI elements that i want to stay at the same place, ignore any scale factors in the options, do some nearly perfectly. The only thing that slightly changes is if the "force aspect ratio" setting is changed, but that is acceptable.

Generally what i have done is:

Code: Select allExpand view
      vector2 Scale = GetHUDScale();

// The main bool that allows drawing outside of the status bar, also causes scaling from "fullscreenhud"
      FullScreenOffsets = true;
// Virtual UI sizes.
      int VSizeX = 160;
      int VSizeY = 100;
      SetSize(0, 160, 100);
      // Rescaling, so this part of UI is always the same size      
         VSizeX = 80 * Scale.X;
         VSizeY = 50 * Scale.X;
// Oddly enough, omitting this one "if" caused erroneaus behavior
      if (Scale.X == 2)
      {
         Scale = (2,2);
         SetSize(0, 160, 100);      
      }
      if (Scale.X == 1)
      {
         Scale = (2,2);
         SetSize(0, 80, 50);
      }
      if (Scale.X == 3)
      {
         Scale = (2,2);
         SetSize(0, 240, 150);      
      }
      if (Scale.X == 4)
      {
         Scale = (2,2);
         SetSize(0, 320, 200);      
      }
      if (Scale.X == 5)
      {
         Scale = (2,2);
         SetSize(0, 400, 250);      
      }
      if (Scale.X == 6)
      {
         Scale = (2,2);
         SetSize(0, 480, 300);      
      }
// the / 2 is simply a result of tests, and looks good that way
      int SizeX = Screen.GetWidth() / Scale.X / 2;
      int SizeY = Screen.GetHeight() / Scale.Y / 2;

// All the top most functions are setting up

// Generally, drawing depends on which part of the UI you want to anchor the object. If it is to the left/top, you can use flat values:
   DrawImage("Backico", (10, 30), DI_ITEM_OFFSETS, 1, (8,8));
// if you want to anchor to the right/bottom you can use SizeX/SizeY multiplied by "percentage" place of the screen. With some math, a flat value could also be used.
   DrawImage("Backico", (SizeX * (0.98), SizeY * (0.6) + (SkillYMOD * 10) -50), DI_ITEM_RIGHT, 1, (8,8));   

// Scaling images is simple, as simply changing the box size gets the result wanted.


// For texts, since 3.7.1 does not support scaling, i use the classic hackery of changing screen size. Note that it DOES NOT work 1:1, in this case i had to multiply screen size by 3 and the position of text by 4 to have it in the same place.
   SetSize(0, VSizeX * 3, VSizeY * 3);   
   DrawString(val1 .. "/" .. val2, (4 * SizeX * (0.98), (4*  SizeY * 0.6)), DI_TEXT_ALIGN_RIGHT | DI_NOSHADOW, Font.CR_GREEN);
   SetSize(0, VSizeX, VSizeY);      


// Below function returns to normal status bar

      FullScreenOffsets = false;
      SetSize(0, 320, 200);



I am not actually sure what BeginHUD() directly does, but i am sure it uses some of the functions/variable changes that i used above.

EDIT: Added an example of the HUD elements outside of the statusbar
You do not have the required permissions to view the files attached to this post.
User avatar
Virathas
 
Joined: 10 Aug 2017

Re: [ZScript] Status Bar elements regardless of scaling

Postby Player701 » Wed Nov 24, 2021 7:40 am

BeginHUD() is used before drawing the elements of the fullscreen HUD, subject to the fullscreen HUD scaling factors. You can have both the status bar and the fullscreen HUD elements on the screen (e.g. icons in the top left/right corners of the screen etc). I would not recommend creating a HUD containing elements not subject to any scale factors because it can become a frustrating experience for the end user (especially if they are using a non-conventional screen resolution).
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: [ZScript] Status Bar elements regardless of scaling

Postby Enjay » Wed Nov 24, 2021 1:41 pm

Seconding that. I have run several mods recently that seem to side-step or otherwise have problems with HUD scaling. I don't have a particularly unusual monitor resolution (1920x1200) but I have set my scaling values to ones that I like for general use and several mods simply don't "play nice" with them. End result: I quit and don't play the mod because I'm not messing up my settings for it.
User avatar
Enjay
Everyone is a moon, and has a dark side which he never shows to anybody. Twain
 
 
 
Joined: 15 Jul 2003
Location: Scotland

Re: [ZScript] Status Bar elements regardless of scaling

Postby Virathas » Wed Nov 24, 2021 1:56 pm

I will actually consider this. The main three problems I had with scalings were:

1) Doom Scalings tend to be extreme, from extremely large fonts to extremely small ones, giving a feeling of "inconsitency"
2) General overlapping or extreme spaces between elements once scaling comes in
3) Inconsitent scaling. Some elements scale on their own with particular scaling settings while others dont. As an example, the right side icons are not aligned with the green values, despite both having the same sttings

Code fragment:
Code: Select allExpand view

      SetSize(60, 640, 400);
   DrawImage("Backico", (620, 180), DI_ITEM_OFFSETS, 1, (15,15));   
      SetSize(120, 1280, 800);
      DrawString(SmallHUDFont, Skill1 .. "/" .. MMData.MMIntData[CurrentMobType][2], (1270, 382), DI_TEXT_ALIGN_RIGHT | DI_NOSHADOW, Font.CR_GREEN);


And visual aid of inconsitency:
You do not have the required permissions to view the files attached to this post.
User avatar
Virathas
 
Joined: 10 Aug 2017


Return to Scripting

Who is online

Users browsing this forum: Kzer-Za, yum13241 and 1 guest