This is all about directGUI, so button means DirectButton etc…
I create a frame, then i make button and parent it to frame.
when i do
print button.getParent()
i get Frame,
but when i want to get bounds via button.getParent().getBounds(), i get
bsphere, c <0.7,0,0>,r 1.42
Is that collision sphere or what???
I need to get bounds of parent because i want to make system in which i can place widgets relatively in corner based manner.
I placed object to fit in exact bottom left corner (frame is a2dbottomleft, and button is in corner of frame after frame changes position)
i tried couple of thing like calling node() and whatnot, but cant really get it right…
here is code
from direct.gui.OnscreenText import OnscreenText
from direct.gui.DirectGui import *
from direct.showbase.DirectObject import DirectObject
from pandac.PandaModules import *
class MainMenu(DirectObject):
def __init__(self):
self.accept("a", self.posDownLeft)
self.accept("s", self.posDownRight)
self.accept("d", self.posTopLeft)
self.accept("f", self.posTopRight)
self.text = OnscreenText(text = 'my text string', pos = (-0.9, -0.9), scale = 0.147)
self.Frame = DirectFrame(frameColor=(0,0,0,1) , frameSize=(0,1.41,0,1.123 ) )
self.Frame.reparentTo(base.a2dBottomLeft)
self.Frame.setPos(self.Frame, 0.5,0,0.5)
#Add button
self.b = DirectButton(text = ("T", "click!", "rolling over", "disabled"), scale=.4)
self.b.reparentTo(self.Frame)
def posDownLeft(self):
x = self.b.getBounds()
scale = self.b['scale']
posX = x[0]*scale*-1
posy = x[2]*scale*-1
self.b.setPos(posX,0,posy)
def posTopLeft(self):
bounds = self.b.getBounds()
scale = self.b['scale']
parent = self.b.getParent()
ph = parent.node().getBounds()
print ph
posX = bounds[0]*scale*-1
posy = bounds[2] * scale *-1
self.b.setPos(posX,0,posy)
and of course, this is just prototype to get it working, i will write fair wrappers later, that is reason why i dont simply call self.Frame instead of getParent()…