menu - items scale

hi all,

i am creating a GUI using the code below

      wp = WindowProperties()
      wp.setSize(1024, 768)
      wp.setOrigin(700, 200)
        
        controlwin =base.openWindow(props = wp, aspectRatio = 1, makeCamera = 0 )

        # Setup a render2d and aspect2d for the new window.
        render2d = NodePath('render2d')
        render2d.setDepthTest(0)
        render2d.setDepthWrite(0)
        camera2d = base.makeCamera2d(controlwin)
        camera2d.reparentTo(render2d) 
       
        self.aspect2d = render2d.attachNewNode(PGTop("aspect2d"))
        self.aspect2d.setScale(1.0, 1.0, 1.0)

and I insert some items in the GUI like the one below:

button1 = DirectButton( scale=(0.5), pos = (0,0,0.12), image = ("models/up.png"), relief = None, pressEffect = 0, rolloverSound = None,clickSound = None, state = 1)

button1.reparentTo(self.aspect2d)

the problem is that when i load the GUI or resize it the items are using the aspect radio of the main Window. e.g I load a button as a square but it is scaled according to the apsect radio of the GUI .

How can I set a fixed size of all the items in the menu independent from the size or aspect radio of theGUI.

I am not a Panda3D expert, so don’t take my word for it.

But the way you set aspect2d up looks weird, you don’t have to create a node for it, you just reparent buttons to aspect2d. Actually that reparenting happens automatically upon creation of the DirectButtons. I guess in your case aspect2d has it’s own aspect ration that propagates down to nodes reparented to it.
To create your behaviour on purpose, one would do something like:

aspectr = base.getAspectRatio()
button1 = DirectButton( scale=(aspectr,1,1), pos = (0,0,0.12))

aspectr for a 16:10 screen is 1.6 here, so this works for screens that are wider then they are tall.

To set up the size of a DirectButton you can use pseudo-absolute values like:

DirectFrame(frameSize=(-156*0.8/480,156*0.8/480,-117*0.45/270,117*0.45/270)

for a 312x234 in a 16:9 960x540 pixels window.

I see that you are creating a separate window from the main window automatically created by Panda, and you are creating your own render2d and aspect2d to go along with it. That’s all fine, but you should understand that one of the purposes of aspect2d is to include the appropriate scale to counter-scale for the window’s aspect ratio (hence its name).

Panda does this automatically when it creates the global aspect2d for the main window. Since you are creating your own aspect2d, you will have to do it yourself. At the moment, you are explicitly setting the scale on your own aspect2d to (1, 1, 1), which is no scale at all. You should set it to something like (1.333, 1, 1) to counter-scale a 4:3 window.

David