kxgames / glooey

An object-oriented GUI library for pyglet.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Transparency for multiple drawing sources

UplinkPhobia opened this issue · comments

I am trying a few things with glooey, and one of my attemps was to use glooey and arcade (https://github.com/pvcraven/arcade) at the same time.
While it technically works by forcing arcade to draw on a restricted area of the window, it requires to draw the arcade elements after the glooey GUI, because glooey will always clear/fill with black its background, even if there are no widgets drawn over it.

While it is possible to find workarounds, I was wondering if a sort of transparent background would be possible, so that glooey would only replace the part of the window that it is actually using for widgets?

I understand that it may be an unnecessary feature, but if it is easy to add/already there (I may have missed it), it could be practical in situations such as mine.

This sounds like something pretty easy to implement. Maybe an option to Gui to not clear the background. I'll try to do this the next time I get a chance.

I added an option to Gui to not clear the background when it redraws:

win = pyglet.window.Window()
gui = glooey.Gui(win, clear_before_draw=False)

Let me know if this addresses the issue for you. I think I need to think about a more elegant way to do this, but in the meantime this should provide a reasonably painless way to keep glooey from screwing things up.

Another thought is that you could probably solve the problem by creating a custom widget that uses arcade to render your game. In other words, rather than having glooey and arcade working side-by-side, have arcade work within glooey. This would get glooey to redraw your game whenever it clears the screen. Some pseudo-code for this might look like:

class MyGame(glooey.Widget):
    ...
    # You'd probably want to call `draw()` on this widget frequently, e.g. every frame.
    # You could set this up using `pyglet.clock.schedule()` or similar.
    def do_draw(self):
        # Draw the game state here, e.g. using arcade.
        ...
    ...

win = plyget.window.Window()
gui = glooey.Gui()
game = MyGame()

gui.add(game)

Thanks for the quick add, it seems to work as intended in the previous programs I had.

I thought about putting arcade in a widget, but since I'm just starting to use both arcade and glooey, I'm not sure how easy or difficult it would be, considering that arcade overwrites the pyglet window (in your example, it would be win = arcade.Window(). So while it would probably be a better solution, I'm not sure that it is the easiest one. But once again, I have yet to try it.

In any case, thank you again for adding this feature.

Ah, I didn't realize that arcade has its own window. I'm sure that would complicate things. Anyways, glad this quick-fix helped.