Page 1 of 2
Way to get value of the #CENTER
Posted: Thu Sep 26, 2024 11:06 am
by Bugala
Quite often I tend to run to a situation where I would need the value of the #CENTERs result.
as example:
Code: Select all
Box(#CENTER, #CENTER, 500, 200)
TextOut(#CENTER + 20, #CENTER+20, "first line of text")
TextOut(#CENTER + 20, #CENTER+70, "second line of text")
TextOut("#CENTER + 20, #CENTER+120, "third line of text")
In these situations, while using #CENTER, would be very handy, problem is You cant use "#CENTER + 20" as example, to which reason I have to figure out the center value myself and use that instead of using the otherwise very handy #CENTER, not to mention that the values of that boxes #CENTER, are different than Textout #CENTERs, so in this example case I would want to get the values of Box commands #CENTERs and then use them for the TextOuts to have those textouts inside the box.
Re: Way to get value of the #CENTER
Posted: Thu Sep 26, 2024 2:14 pm
by Flinx
Bugala wrote: ↑Thu Sep 26, 2024 11:06 am
not to mention that the values of that boxes #CENTER, are different than Textout #CENTERs
Are you sure? I have never seen that before.
Code: Select all
DebugPrint(GetAttribute(#DISPLAY, 1, #ATTRWIDTH)/2, GetAttribute(#DISPLAY, 1, #ATTRHEIGHT)/2)
But knowing the #CENTER values doesn't help, because when centering, the X position for
TextOut() depends on the text width. You can use layers to get around this, because there you can query the layer width, but without layers, a center value isn't much help, I think.
Maybe return values for position and size would help.
Re: Way to get value of the #CENTER
Posted: Thu Sep 26, 2024 2:38 pm
by Bugala
@flinx
Was bit unclear in my explanation.
What I meant with #CENTER values being different is that:
#CENTER values in "Box(#CENTER, #CENTER, 500, 200)" are different than in "TextOut(#CENTER, #CENTER, "line of text")"
Point being with this since in my code I was using:
Box(#CENTER, #CENTER)
TextOut(#CENTER + 20, #CENTER + 20)
When in reality it should be something like:
Code: Select all
Box(#CENTER, #CENTER)
BOX_X = GetBoxCenterValueX()
BOX_Y = GetBoxCenterValueY()
TextOut(BOX_X + 20, BOX_Y + 20)
Since this is a wishlist request, was just demonstrating to Andreas to what kind of situation that being able to get the #CENTER value would be useful by using some sort of example code.
GetAttribute could work in many situations, but I guess it requires you to have layers on. So without layers on, it cant be used at least in Boxes case.
Re: Way to get value of the #CENTER
Posted: Thu Sep 26, 2024 2:58 pm
by Flinx
Bugala wrote: ↑Thu Sep 26, 2024 2:38 pm
Code: Select all
TextOut(#CENTER + 20, #CENTER + 20)
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.
When in reality it should be something like ...
Yes, that would need the return values for TextOut or Box. Or for all functions using #CENTER. Andreas will be thrilled...
Re: Way to get value of the #CENTER
Posted: Fri Sep 27, 2024 8:01 am
by Bugala
Yes, the #CENTER + 20 was just to demonstrate what I am trying to do sometimes, but which currently is not possible.
And I don't know how that #CENTER value should be got even, maybe something like:
Code: Select all
ReturnTable = Box(#CENTER, #CENTER, width, height)
and then the ReturnTable could contain the actual X and Y positions?
In which case I could continue with:
Code: Select all
TextOut(ReturnTable.x + 20, ReturnTable.y + 20, "first line of text")
TextOut(ReturnTable.x + 20, ReturnTable.y + 70, "second line of text")
Re: Way to get value of the #CENTER
Posted: Fri Sep 27, 2024 8:24 am
by jPV
Why don't you use TextObjects if you need information about sizes and positions? Or use TextExtent/TextWidth/TextHeight to get dimensions before actually drawing them with TextOut. You can then draw a box according the text dimensions.. if you're first doing the box there's a risk that text don't fit in it anyway.
Re: Way to get value of the #CENTER
Posted: Fri Sep 27, 2024 11:58 am
by Bugala
@jpv Havent thought that before. Might solve the example problem, but wont work when there are other stuff too, like I could be using displaybrush there too with the text and boxes.
For example right now I have this situation where I drew a box, wrote a line of text, and after that text I displayed a brush.
"Choose hotkey for:" displaybrush
Had been handy to do it with:
Code: Select all
Box(#CENTER, #CENTER, width, height)
TextOut(Box.X + 20, Box.Y+10, "Choose hotkey for:")
DisplayBrush(1, Box.X + 300, Box.Y+10)
Re: Way to get value of the #CENTER
Posted: Fri Sep 27, 2024 12:25 pm
by Bugala
Actually, that would work in this specific case too now that I think of it better.
But main point being that if there is mixture of different things, then having option to get #CENTER value of any object might be necessary, that while TextObject already solves a lot of those problems (thanks from that!) it doesn't solve all the cases.
Re: Way to get value of the #CENTER
Posted: Sat Sep 28, 2024 10:41 pm
by airsoftsoftwair
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.
Re: Way to get value of the #CENTER
Posted: Sat Sep 28, 2024 11:25 pm
by Flinx
Ah, very interesting. Thanks!