DirectScrolledFrame, aspect2d, render2d

I’m actually trying to use in my code the directgui directscrolledframe object and at first I was supposed, wrongly, to parent it to render2d and in fact it won’t work. Then I parented to aspect2d and it worked out but not as I was expecting, as is I was supposed that aspect2D was working in a virtual XZ range -1.0,1.0 matching the whole visible screen area (the frustum) but I’d found this is not because, if I got it, looks like it matches the 3D XZ coords ignoring the Z that is fixed. So then I would ask: how can I place my object for example in XZ -1,1 coordinate matching the uppermost left corner of the frustum? I’m aware this could be an obvious question for the most of you but I think that a clear reply cold be useful for starters.

Aspect2d X range is -aspectratio to aspectratio. You can get aspect ratio with base.getAspectRatio().
If you want to use -1 to 1, you have to set the coordinates relative to render2d.

ok thanks ynjh_jo
so using this:


now I’m able to place correctly my directscroll object, not much elegant but works good

What’s that calculation for ?
Aspect ratio is window size x/y, so that calc result is obviously 1.

You can place it after it’s created :

dsf.setPos(render2d, -1,0,1)

ah that’s what you meant!
I was using those x,y calc to put the dsf in aspect2d with a plain setPos(x,0,y)
I wasn’t aware that I could use render2d in the setPos().

tankyou again dude!

ok this is code that explain what we was talking above - it makes 2 DirectScrolledFrame and try to keep’em glued to the left and the right corners.


he got an issue though, even if to me is pretty unimportant, but if I try to resize the panda window very thin, expecially by width, it happens that the rightmost frame loose his stucked position and moves off the corner.

Note that a much easier way to keep stuff glued to the corners is simply to parent it to base.a2dTopLeft and base.a2dTopRight. Then Panda will manage its placement automatically, even when the window changes sizes.


shiny! this thread is going better and better thank to you amazing guys.

so then here the code results of all of this talk:

4 DirectScrolledFrames are placed around each corner of the frustum and it will be stuck there nomatter how you resize your panda window.
Of course this code will be good for other directgui objects as well.
import direct.directbase.DirectStart
from direct.gui.DirectGui import *
import direct.gui.DirectGuiGlobals as DGG
from pandac.PandaModules import *
def mkdsf(parent):
  bgcol=(.2, .2, .2, .5)
  return DirectScrolledFrame(
    frameSize=(0, size[0], -size[1], 0),
    canvasSize=(0, size[0]-borderw[0]-scrollbarw, -5., 0),
if __name__ == '__main__':
  #top right corner will be 0,0
  #and so goes here for the bottom right corner...
  t1=OnscreenText(text='upleft', parent=dsf1.getCanvas(), pos=(.2,-.2))
  t2=OnscreenText(text='upright', parent=dsf2.getCanvas(), pos=(.2,-.2))
  t3=OnscreenText(text='downright', parent=dsf3.getCanvas(), pos=(.2,-.2))
  t4=OnscreenText(text='downleft', parent=dsf4.getCanvas(), pos=(.2,-.2))

now’s pretty good and the confusion has gone! :wink: