Way to get value of the #CENTER

Feature requests for future versions of Hollywood can be voiced here
Bugala
Posts: 1221
Joined: Sun Feb 14, 2010 7:11 pm

Re: Way to get value of the #CENTER

Post by Bugala »

airsoftsoftwair wrote: Sat Sep 28, 2024 10:41 pm
Flinx wrote: Thu Sep 26, 2024 2:58 pm But you know that this is syntactically not correct? #CENTER is a constant with the value -100000 and this magic number triggers Hollywood's center arithmetic. You can't add numbers to it.
Actually, you can ;) It is possible to add and subtract values to those special constants in order to do some fine-tuning. It's documented here. Of course there are some limits, I think the maximum that can added or subtracted is 5000 pixels or so because then the range of the next special constant is hit ;) But adding/subtracting a few pixels is definitely possible and quite a handy feature IMHO which is why it has been supported for a long time.
Thats good. Didnt know that was possible either. Thought I had even tried and failed at some point.

But so anyway, the wishlist that I had was that in case I want to use one specific things #CENTER value as the base point for the rest, there would need to then be a way to get the result of the #CENTER value.

With layers on I think it is doable with GetAttribute, but without Layers on, I guess only way to get it is through TextObject, as JPV suggested, but that doesn't always solve the problem.

To give new example of the problem I am wishlisting for:

Code: Select all

Box(#CENTER, #CENTER, 1000, 1000)
DisplayBrush(1, BoxCenterX + 20, BOxCenterY + 20)
DisplayBrush(2, BoxCenterX + 20, BoxCenterY + 70)
DisplayBrush(3, BoxCenterX + 20, BoxCenterY + 120)
I run into this kind of situation quite often, and instead of using #CENTER, I revert to using hardcoded numbers instead, since I want the Brushes to be displayed inside that Box.

But having a way to get the Box-commands #CENTER value stored to BoxCenterX and BoxCenterY, would give me a possibility to do it like the example code.
Flinx
Posts: 238
Joined: Sun Feb 14, 2021 9:54 am
Location: Germany

Re: Way to get value of the #CENTER

Post by Flinx »

But you have the values already. If you know the size of your objects, you can calculate the needed positions using the display size. You even could use the calculated positions (BoxPositionX and Y) instead of using #CENTER.
Here is a mix of your examples (I've put the values into variables for better reading):

Code: Select all

; example 1:
boxwidth=500
boxheight=200
Box(#CENTER, #CENTER, boxwidth, boxheight, #YELLOW)
displaywidth= GetAttribute(#DISPLAY, 1, #ATTRWIDTH)
displayheight=GetAttribute(#DISPLAY, 1, #ATTRHEIGHT)
BoxPositionX=(displaywidth-boxwidth)/2
BoxPositionY=(displayheight-boxheight)/2
TextOut(BoxPositionX + 20, BoxPositionY+20, "first line of text")
TextOut(BoxPositionX + 20, BoxPositionY+70, "second line of text")
TextOut(BoxPositionX + 20, BoxPositionY+120, "third line of text")

; example 2:
boxwidth=150
boxheight=100
Box(#CENTER, #CENTER, boxwidth, boxwidth, #WHITE)
CreateBrush(1, 100, 50, #BLUE)
CreateBrush(2, 100, 50, #YELLOW)
BoxPositionX=(displaywidth-boxwidth)/2
BoxPositionY=(displayheight-boxheight)/2
DisplayBrush(1, BoxPositionX + 20, BoxPositionY + 20)
DisplayBrush(2, BoxPositionX + 20, BoxPositionY + 70)

Wait(15,#SECONDS)
Flinx
Posts: 238
Joined: Sun Feb 14, 2021 9:54 am
Location: Germany

Re: Way to get value of the #CENTER

Post by Flinx »

Bug in example 2. Should be

Code: Select all

Box(#CENTER, #CENTER, boxwidth, boxheight, #WHITE)
Bugala
Posts: 1221
Joined: Sun Feb 14, 2010 7:11 pm

Re: Way to get value of the #CENTER

Post by Bugala »

Flinx wrote: Sun Sep 29, 2024 11:28 am But you have the values already. If you know the size of your objects, you can calculate the needed positions using the display size. You even could use the calculated positions (BoxPositionX and Y) instead of using #CENTER.
Here is a mix of your examples (I've put the values into variables for better reading):
Its not a matter of not being able to do it at all, just looking for easier/handier way to do it, which would be by simply getting the value of #CENTER somehow stored somewhere accessible.

For example, I don't necessarily want to know what is the resolution being used, or if I am having graphic for background, I might not want to know that brushes size, although it can be got, but would simply like to use #CENTER, and then just keep using that value as the basis for the other ones.

That to actually demonstrate this, is to point out that when I run into this situation, instead of taking screenwidth etc. I have just calculated the numbers myself in my head and used hard number.

However, now that you mentioned, I could actually make a function that does all that calculation, that way needing to do it only once.
Flinx
Posts: 238
Joined: Sun Feb 14, 2021 9:54 am
Location: Germany

Re: Way to get value of the #CENTER

Post by Flinx »

Understand. But why not make it handy by yourself?

Code: Select all

Function p_CenterBox(w, h, ...)
	Box(#CENTER, #CENTER, w, h, Unpack(arg))
	Local x=(GetAttribute(#DISPLAY, 1, #ATTRWIDTH) -w)/2
	Local y=(GetAttribute(#DISPLAY, 1, #ATTRHEIGHT)-h)/2
	Return(x, y)
EndFunction

cx,cy= p_CenterBox(500, 200, #YELLOW)
TextOut(cx+20, cy+20, "first line of text")
Edit: Did you add the last sentence? I didn't read it before I posted.
Bugala
Posts: 1221
Joined: Sun Feb 14, 2010 7:11 pm

Re: Way to get value of the #CENTER

Post by Bugala »

At least I think I wrote the last sentence along with the rest.

But thanks for the code, can use this for the box version (which is the most usual case) instead of having to do it myself.
Post Reply