DirectGUI: Framesize DirectButton and Aspect2D coordinates

Hello,

I´m trying to code a level editor for my current Arkanoid/Breakout-Clone using DirectGUI.
As far as I know, DirectGUI objects are rendered by Aspect2D. So the X-Coordinates go from -1 to 1 and the Z-Coordinates go from -1 to 1.
But when I try to resize my buttons through framesize:

self.Editor_button['frameSize'] = -1, 1, -0.5, 0.5

It doesnt match the Aspect2D coordinates, which makes positioning difficult.
So I´m looking either for a function that translates from framesize coordinates to aspect2D coordinates or a conversion factor.
I hope I made the problem clear enough.

Sorry, I don’t understand. If you set the framesize to a height of -0.5 to 0.5, then the height will be -0.5 to 0.5 in aspect2d coordinates. Do you want it to still be -1 to 1, even though it’s now only half as tall? If that’s what you want, you could try adjusting the scale instead of the frameSize.

David

as far as I know, this would be the (proper) way to set the frameSize:

self.Editor_button['frameSize'] = (-1, 1, -0.5, 0.5)

I only say that as I’ve never seen it done your way without the tuple brackets “()”, I forgot how python manages tuples though, so your way may work fine. :wink: (in other words I could be very wrong and you may be right)

as far as aspect2d, you’d think that the very far left of the window would be x=-1, that’s indeed wrong. Aspect2d has the bounds of the “aspect” of the window, hence the name aspect2d, in other words a standard 800/600px window will have an spect ratio of 1.3^, (800.0 / 600.0 = 1.3^, my math may be wrong to calculate this however) in any case, aspect2d scales to the window size, so if your window is square, it should have x=(-1, 1) y=(-1, 1), however, if the window is non-square, the bounds of aspect2d change. I found this uber hard to work with (from my limited understanding of aspect2d) and settled for something more simple.

Do something like this before opening the window (import DirectStart, etc)
(aka, before ANY of your own code, or put “aspect-ratio 1.0” inside your Config.prc)

from pandac.PandaModules import loadPrcFileData
loadPrcFileData('', 'aspect-ratio 1.0')
from direct.directbase import DirectStart

<do stuff..>

run()

Just for the record, the parentheses don’t really matter:

>>> a = 1, 2
>>> type(a)
<type 'tuple'>
>>> a == (1, 2)
True

Ah, the wonderful python, thank you rdb for clearing that up (it’s rather cool how python can do that :smiley:)

The problem is: One frameSize Unit is not one aspect2d unit. So I dont know what size my button is in apsect2d units. maybe it gets a lil clearer.

Okay, I´m officially dumb. I didn´t recognize that I scaled the Buttons before setting the frameSize. :blush:
But thank you for your quick responses.