[ZScript] [BaseStatusBar] - Vertical-Center with DrawString?

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!)
Post Reply
violgamba
Posts: 41
Joined: Wed Apr 10, 2024 4:53 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10

[ZScript] [BaseStatusBar] - Vertical-Center with DrawString?

Post by violgamba »

Hi. I'm struggling to find a way to have BaseStatusBar.DrawString() draw some text to the center of the screen when that text is large enough to wrap multiple times. When I use the flag DI_SCREEN_VCENTER, the origin is at screen center, but then the lines of text are drawn below that. It seems like BaseStatusBar.DrawString() is a lower level function than HudMessage(), so perhaps it doesn't provide a way to calculate the height of the text and center based on it?

I tried reviewing hudmessages.cpp, but I don't think it relies on BaseStatusBar.DrawString(). Not 100% sure about that, though, as it was hard to follow.

Does anyone know how this could be done?
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: [ZScript] [BaseStatusBar] - Vertical-Center with DrawString?

Post by Jarewill »

You should also use item-relative positioning flags such as DI_ITEM_VCENTER alongside the screen-relative one.
violgamba
Posts: 41
Joined: Wed Apr 10, 2024 4:53 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10

Re: [ZScript] [BaseStatusBar] - Vertical-Center with DrawString?

Post by violgamba »

I should have mentioned that I did try DI_ITEM_VCENTER. It didn't seem to have any effect on the text positioning. Perhaps it needs to be used in conjunction with some other setting? Here's my code, in case it helps:

Code: Select all

myHud.DrawString(MyFont, MessageText, (scaledScreenSize.x * .025, scaledScreenSize.y * .025), myHud.DI_SCREEN_VCENTER | myHud.DI_ITEM_VCENTER, Font.CR_UNTRANSLATED, 1, scaledScreenSize.x * .95, -5);
(There's a bit of indirection with my code design, thus the "myHud" prefixes.)
violgamba
Posts: 41
Joined: Wed Apr 10, 2024 4:53 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10

Re: [ZScript] [BaseStatusBar] - Vertical-Center with DrawString?

Post by violgamba »

I'm attaching a demo PK3 showing the effect of vertical alignment of the screen, and vertical alignment of the item when using StringDraw. Perhaps this will help clarify the issue. Note, in the attached mod, that the vertical alignment of the item doesn't seem to affect on how StringDraw renders.
Attachments
DrawStringExample.pk3
(12.21 KiB) Downloaded 11 times
User avatar
metalx1000
Posts: 21
Joined: Tue Apr 23, 2024 5:56 pm
Operating System Version (Optional): Debian SID
Graphics Processor: Not Listed
Contact:

Re: [ZScript] [BaseStatusBar] - Vertical-Center with DrawString?

Post by metalx1000 »

Thank you for sharing the pk3, I wish more people did that. It makes things much easier to trouble shoot.
I've played around with it some, and I'm not 100% sure what you are going for, but I think this might get you close.

Code: Select all

DrawString(MyFont, CurrentMessage, (0,-scaledScreenSize.y*.5), DI_SCREEN_CENTER|DI_TEXT_ALIGN_CENTER , Font.CR_UNTRANSLATED, 1, scaledScreenSize.x * .95);
DI_SCREEN_CENTER|DI_TEXT_ALIGN_CENTER might be part of what you need and then I played with the y position a bit "-scaledScreenSize.y*.5"

I have sound this site useful.
https://jekyllgrim.github.io/ZScript_Ba ... usbar.html
violgamba
Posts: 41
Joined: Wed Apr 10, 2024 4:53 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10

Re: [ZScript] [BaseStatusBar] - Vertical-Center with DrawString?

Post by violgamba »

Thanks for the reply @metalx1000! The thing I'm going for is to vertically center text on the screen. You addressed my problem when you said that you played with the y position a bit "-scaledScreenSize.y*.5". Unfortunately, manually determining the vertical position like this is unfeasable for two reasons, (1) I have quite a few texts throughout my work, so manually positioning each is cumbersome (2) when the screen size changes, it affects the relative size of text, causing it to wrap at different positions and take up different amounts of vertical space. The attached pictures show this (note: I had to scale down to meet the file-size limit).

Ideally, it'd be possible to dynamically calculate the height of a text and vertically position it based on that. But given the dearth of solutions, this may not be possible. I'll keep looking, though. If I find a solution I'll post it here.
Attachments
demo_drawString2.png
demo_drawString2.png (31.61 KiB) Viewed 185 times
demo_drawString1.png
demo_drawString1.png (43.1 KiB) Viewed 185 times
Post Reply

Return to “Scripting”