DirectButton that ignores the mouse

Is there a way to get the state-based functionality of a DirectButton without having its state transitions directly tied to mouse input? I am working with a touch-screen interface and information about fingers on the surface are being fed into Panda via events. I want to take advantage of all the functionality that DirectButton has to offer, but drive it’s state changes via explicit calls based on my touch screen input. Does anyone know of a way to do this, preferably without having to make any C-level changes.

Sounds like you’d be interested in this thread.

But the short answer is, no, it will require some C-level changes. But maybe you can contact the other person who has already walked down this path.

David

I am in a prototype environment, so I am looking for a short term solution. One approach that might work is creating DirectLabels with multiple states. Along those lines I delved into explicitly changing the state of a DirectLabel, with the result shown below.


# Panda Imports
import direct.directbase.DirectStart
from direct.gui.DirectGui import DirectLabel
from pandac.PandaModules import TextNode

# create a direct label with multiple states
label = DirectLabel(
	parent = aspect2d,
	text = ("State 0", "State 1", "State 2"),
	text_align = TextNode.ACenter,
	text_pos = (0.0, 0.0),
	text_scale = 0.1,
	numStates = 3,
)

def setLabelState(state):
	global label
	label["activeState"] = state
	label.setActiveState()
	

taskMgr.doMethodLater( 1.0, setLabelState, "setLabelState", extraArgs=[1] )
taskMgr.doMethodLater( 2.0, setLabelState, "setLabelState", extraArgs=[2] )
taskMgr.doMethodLater( 3.0, setLabelState, "setLabelState", extraArgs=[0] )

run()

Is this the correct way to change a DirectLabel’s state? Is there an easier way?

I don’t think it’s necessary to make the second call to label.setActiveState()–this call is made implicitly when you assign something to label[‘activeState’].

Other perfectly valid approaches would be to use a SwitchNode, which allows you to select one particular child at a time to be visible, or even to simply hide and show the labels (or whatever items you have) explicitly.

David

You are correct. The call to setActiveState() is not necessary.