I didn’t find initialisation of PGTop in DirectGuiBase, when it was created ?
The initializations for the PGTop nodes should be in direct/showbase/ShowBase.py
aspect2d it’s a PGTop ?? I created my own PGTop, but if it already is in ShowBase I do not mind ).
zumodrive.com/share/9pGJODcyYW
How to setup active zone of PGItem, i obtained reaction on mouse-click, but not in particular area. Is it works only when geometry attached (setFrame is not enough)?
from direct.showbase import DirectObject
from panda3d.core import *
from direct.showbase.PythonUtil import StackTrace
class btnStyle(PGFrameStyle):
def __init__(self, styName= '_'):
PGFrameStyle.__init__(self)
self.setName=styName
self.frameSize=(-0.15,0.15,-0.1,0.1)
self.setColor(0.7,0,0,1)
styleCollection={}
styleCollection['defaultStyle']=btnStyle()
def eventAny(extraArgs=[]):
print extraArgs
print '*******************'
print StackTrace()
class guiControl(PGItem, DirectObject.DirectObject):
def __init__(self, cntrlName='x', cntrlStyle='defaultStyle',
cntrlText=None): #parent='guiRoot',
PGItem.__init__(self, cntrlName)
DirectObject.DirectObject.__init__(self)
cntrlStyle=styleCollection[cntrlStyle]
self.setFrameStyle(0,cntrlStyle)
self.setFrame(cntrlStyle.frameSize)
self.setId('dd')
pass
def setPosHpr(self,x=0, y=0, z=0, h=0,p=0,r=0,cntr=False):
tmpTrans=self.getTransform()
tmpTrans.setPos((x,y,z))
tmpTrans.setHpr((h,p,r))
self.setTransform(tmpTrans)
def bind(self, event, command, extraArgs = []):
#gEvent = self.getPressEvent(MouseButton.one() + self.getId()
self.accept(event, command, extraArgs = extraArgs)
if __name__ == '__main__':
import direct.directbase.DirectStart
import startPG # creates PGTop, attached it to aspect2d
guiItem1=guiControl()
guiItem1.bind('mouse1', eventAny, [guiItem1.getPressEvent(MouseButton.one())])
# event: 'press-mouse1-dd' --- i don't see reaction,
# event: 'mouse1' - event causes reaction, but don't tracks location of PGItem
guiRoot.addChild(guiItem1)
guiItem1.setPosHpr(h=0,p=0,r=0)
print guiItem1.getClassType()
print aspect2d.find('**/x')
run()