Hello All ,
I’m figthing with GUI stuff actually. all my components (Entry, label…) are set into one DirectFrame. However i’m lost when trying to position this components on the frame. What i would like to do is an handy function:
user tells coordinate of the components inside Directframe on a 0-1 scale (0,0,0 to 1,1,1 or 0,0 to 1,1) (like a screen coordinate)
and the function convert this coordinates in real coordinates in DirectFrame coordinates system.
Before working on it , i would like to know if it exists somewhere in panda?
(i’m asking before i often discovered good idea are already implemented in panda …)
Do you mean convert screen-relative coordinates into frame-relative coordinates? That’s easily answered using Panda’s relative scene graph operations.
framePos = frame.getRelativePoint(render2d, screenPos)
Note that screen coordinates, by convention, range from (-1, -1) to (1, 1).
But I can do you one better. When you are laying out your DirectGui elements, put the following in your Config.pp file:
With this in effect, you can drag your gui elements around onscreen with the middle mouse button. If you hold down the control key and the middle mouse button together, you can also rescale them. When you get your gui elements positioned where you want them, break into your Python process and print out their position and scale, e.g.:
and then hard-code those numbers into your program.
Man asked a question, God provided a miracle …
I’m afraid I haven’t been able to get the direct-edit functionality to work. I placed the ‘direct-gui-edit’ line in my Config.prc and made sure ‘enableEdit’ was set to 1 on my gui objects.
(I wasn’t sure if the line was actually intended for Config.pp. I’m currently using the pre-packaged Panda and couldn’t find it there. I did find Config.pp under ‘/dtools’ in my full-source version, but I was hoping not to rebuild Panda just to activate this feature.)
The game loads fine, but I’m unable to move or resize things with the middle mouse button. Do anyone know what I might be doing wrong? Thanks.
You might want to check to make sure that you are editing the correct Config.prc file. Maybe the game is loading a different one.
You can run this command:
to list all of the Config.prc files that are loaded. You can also type this:
to confirm that the variable is, indeed, being set to true.