Image parameter of DirectFrame()

Hello,

I have a question regarding how images are displayed in DirectFrames.

I am using many DirectFrames as buttons to create a menu and submenus. Everything works perfectly, but I want to add icons on each DirectFrames, and that’s the moment were things get a little spicy! :smile:

Everything is triggered by DGG.WITHIN and DGG.WITHOUT:

    def set_button_mouseover_style(self, button, _):

        self.close_all_submenus()
        button.frame.setColor(Base.WHITE)
        button.frame["text_fg"] = Base.GREY
        button.frame["image"] = "content/images/ui/icon_cars_mouseover.png"

    @staticmethod
    def set_button_mouseout_style(button, _):

        # button.frame.setColor(Base.RED)
        button.frame.setColor((0, 1, 0, 1))
        button.frame["text_fg"] = Base.WHITE
        button.frame["image"] = "content/images/ui/icon_cars_mouseout.png"

Here is my problem:

image190

  • Case #1 : button was active but DGG.WITHOUT has been triggered
  • Case #2 : button is active because DGG.WITHIN has been triggered
  • Case #3 : button is inactive and never been triggered

My problem is the case #1: I cannot get the image back as for untriggered buttons.

@Thaumaturge made an interesting post explaining that frameColor has an impact on the image color of the DirectFrame:

So I checked: I set the frameColor to green, I can see the icon:

So my question is, is there a way to just display the image without depending on the frameColor?

Thanks for your help! :pray:

Before I get to the main question, may I ask: Why is it that you’re not using DirectButtons? Is there some functionality that doesn’t work with them…?

In any case, returning to the actual question, this seemed at first odd.

You see, testing quickly on my end, I find that the “frameColor” value tints images added via the “frameTexture” keyword-parameter, but not images added via the “image” keyword-parameter.

However, looking closer at your code, it seems to me that you’re not actually using the “frameColor” value! You’re instead calling the “setColor” method, which is a method available to NodePaths in general (not just DirectGUI widgets).

And indeed, using “setColor” does result in an image applied via the “image” keyword-parameter being tinted!

(I would guess as a result of the internal structure of the DirectGUI widget and where, precisely, the colours set by “frameTexture” and “setColor” are respectively applied.)

So, the answer, I think, may be to simply switch to using the “frameColor” keyword-parameter rather than calling “setColor”!

1 Like

Thanks for pointing out my mistake, I had read my code again and again without finding the problem! :pray:

Now, it works the way I want it to work, thanks to your help:

    def set_button_mouseover_style(self, _):

        self.frame["frameColor"] = Base.WHITE
        self.frame["text_fg"] = Base.GREY
        self.frame["image"] = "content/images/ui/icon_cars_mouseover.png"

    def set_button_mouseout_style(self, _):

        self.frame["frameColor"] = Base.RED
        self.frame["text_fg"] = Base.WHITE
        self.frame["image"] = "content/images/ui/icon_cars_mouseout.png"

To answer your question: in my menu, some buttons need to be clicked and others need to be mouse overed to be activated. So a simple Frame does the trick. Moreover, my buttons’ style is very simple: a square which changes color, so I didn’t wanted to deal with unnecessary buttons options like relief, animations, …

1 Like

Ah, I’m glad that it works! :slight_smile:

Ah, I see! That does make sense!

Thank you for answering! :slight_smile: