DirectButton texture-cards still show default button.

Hello!

I am trying to create a custom button. I made the .egg file according to the documentation with:

egg-texture-cards -o button.egg -p 240,240 button.png button_full.png button_full.png button_full.png

And I am getting a button with my texture, but the original button is still in the background, and the texture don’t scale with the button.
http://imgur.com/fAkZdKQ

The code is

   
maps = loader.loadModel('textures/button')
b = DirectButton(text = ("1", ".", ".", "."), 
                    geom = (maps.find('**/button'),
                         maps.find('**/button_full'),
                         maps.find('**/button_full'),
                         maps.find('**/button_full')))

I want a green border when inactive and unselected, and full green otherwise.

Any idea what I am doing wrong?

Thank you!

EDIT: Is there any other way to get mouseover and click on a aspect2d nodePath?
I tried with a mouse CollisionTraverser() , but found in the forum that this way is overkill and is not appropriate for aspect2d.

EDIT_2 : What I am trying to achieve is a custom menu button… Thanks again!

You can use a DirectFrame as a button, you just need to bind the events and set its state as active (state=DGG.NORMAL):

button=DirectFrame(frameSize=Point3(x,0,-y),                           
                  frameTexture='mytex.png',
                  text="This is a button",
                  text_scale=20,  
                  state=DGG.NORMAL, 
                  parent=pixel2d)
button.bind(DGG.B1PRESS, self.onButtonClickFunction, [button, some_value1])
button.bind(DGG.WITHIN, self.onMouseHoverInFunction, [button, some_value1])
button.bind(DGG.WITHOUT, self.onMouseHoverOutFunction, [button, some_value1])

There are some more events that you may use. There’s B1PRESS and B1RELEASE, but there’s also B1CLICK, “B1” stands here for “mouse button 1”, but you can use B2PRESS and B3PRESS as well.
There’s also a ENTER and EXIT event, but from what I remember WITHIN and WITHOUT worked better (for me).

If I remember correctly DGui will glue one more argument to the function you call, an event, so even though in the example code above I put two arguments in the bind function the function should take 3 (4 with ‘self’) -I always give it a default value so I can call the same function not from a button click without extra trouble:

def onMouseHoverOutFunction (self, button, some_value, event=None):
    print button, some_value, event

And last tip - if you’re using textures for gui elements parent them to pixel2d and set their size in pixels, and if the textures are not power-of-two (2,4,8,16,32,64,128,256,512,1024,2048…) set loadPrcFileData("", “textures-power-2 None”)

I think that you should be able to remove the “background button” by passing “relief = None” into the DirectButton constructor, like so:

b = DirectButton(<other parameters, such as your geom...>,
                 relief = None)

Thanks for your help I really appreciate it! I’ll try both solution and see which is the best for me!

I want a old computer vertex look, so I am making the button with lineseg and GeomTristrips :wink:, but I am happy you mentionned pixel2d, since I didn’t knew about that!

Thanks again!

I read the manual, made some test and I think that DirectFrame is more appropriated. I want to make some buttons that will allow multiple states, and I will change the geom according to the next state geom1 -> geom2 -> geom3 -> geom1…

The thing is that I can’t figure any way to change the geom once it has been specified! I tried everything I could think of and nothing worked :frowning:

Lets say I make a button and immediately want to change it’s geom (test purpose)

    button=DirectFrame( 
                        enableEdit=1,                      
                        text=text,
                        geom=firstState,
                        text_scale=0.05,
                        text_fg=(0,1,0,1),
                        borderWidth=(1,1), 
                        relief = None,
                        text_pos=(0,-0.01,0),
                        textMayChange=1,
                        state=DGG.NORMAL,
                        parent=aspect2d
                        )
button["geom"] = secondState

That would seem the obvious way to do it, but that doesn’t work. It looks like the geom gets locked.

Any idea how I can achieve this?

Thanks again!

Got it to work!

If I set -> button[“geom”] = None

before I set the new geom -> button[“geom”] = secondState

It works… Yay!