I’m working on some gui widgets and often need to be able to switch between multiple states, which also have a different graphical representation.
Basically, very similar to the DirectButton that has it’s four states (rollover, clicked, etc.) with four different geoms, one for each state.
But since this is not a clickable widget I want to use a DirectFrame instead of a Button.
From reading the docs and looking at the code, I believe that DirectFrame is capable of doing it, but I don’t understand how.
So the idea was that I tell the frame that it should have 2 states and I pass in two geometries.
It created the two components (they show up in myFrame.components()) but the geom never switches.
I’m sorry that I have waisted your time. It DOES work fine. I don’t know how I tested it in the first place and came to the conclusion that it wouldn’t work.
Anyway, maybe it’s beneficial for others, so here my quick test that demonstrates that DirectFrame objects can have multiple states and switch between them:
import direct.directbase.DirectStart
from direct.gui.DirectGui import *
from direct.interval.IntervalGlobal import *
# function to switch the states of DirectGui Widget
def switchState(frame, statenum):
frame.guiItem.setState(statenum)
smiley = loader.loadModel("smiley.egg.pz")
box = loader.loadModel("box.egg.pz")
# add some frames with a single state - I merely display them for reference, to check how my two states will look like..
f1 = DirectFrame(relief = None, geom = smiley, scale = 0.1, pos = (-1,0,0))
f2 = DirectFrame(relief = None, geom = box, scale = 0.1, pos = (1,0,0))
# frame with multiple states
f3 = DirectFrame(relief = None, geom = (box, smiley), numStates = 2, scale = 0.1)
# cerate an interval that switches the state every second
interval = Sequence(Wait(1.0), Func(switchState, f3, 1), Wait(1.0), Func(switchState, f3, 0))
interval.loop()
#run!
run()