DirectButton in a new window

I don’t know what I must have been thinking when I made that earlier post. In addition to creating a render2d and setting up a camera for it, if you want to use DirectGui, you also need two additional things: (1) an aspect2d node, which is a node of type PGTop, critical for DirectGui objects; and (2) a MouseWatcher, to monitor the mouse motion in your second window, and active your DirectGui objects when the mouse rolls over them.

Here are the relevant lines from your example, extended to create the new structures:

        #create new window for the gui
        wp = WindowProperties()
        wp.setSize(400, 300)
        wp.setOrigin(879, 200)
        aspectRatio = 1.33
        controlwin = base.openWindow(props = wp, aspectRatio = aspectRatio)

        # 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)

        aspect2d = render2d.attachNewNode(PGTop("aspect2d"))
        aspect2d.setScale(1.0 / aspectRatio, 1.0, 1.0)

        # Set up a MouseWatcher to monitor the DirectGui.
        name = controlwin.getInputDeviceName(0)
        mk = base.dataRoot.attachNewNode(MouseAndKeyboard(controlwin, 0, name))
        mw = mk.attachNewNode(MouseWatcher(name))
        aspect2d.node().setMouseWatcher(mw.node())

Now you can parent your DirectGui objects to aspect2d, rather than render2d, and they should work. Note that there is a keyword parameter named parent, available to every DirectGui object; in lieu of reparenting it afterwards, you could simply say “DirectButton(parent = aspect2d, …)”. But reparenting it does the same thing. I don’t know why this convenience parameter isn’t documented.

The red dot you are referring to is the selection dot you get when you have the DirectTools loaded. You must have “want-directtools 1” in your Config.prc file.

David