-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a UI element which able to render raw pygame surface #662
Comments
I believe what you want is https://github.com/MyreMylar/pygame_gui/blob/main/pygame_gui/elements/ui_image.py Just draw your surface however you like and then pass it into Let me know if this is not what you were thinking of. |
Thanks for the fast reply. Now I'm trying to make work with the The plot has a few features like when you hover one of the point, it's display the number and also a range can be selected. Like what google plots have. I will write here if I found a solution for this. |
I've found out if I use my plot inside the class it will draws enierly different. New values always renders at the top of the surface and the plot animation didn't even play. It doesn't matter where is the plot surface which has to be updated, because while the plot manager is in the UI class it will not draws the plot in the way it has to. Updating the plot surface requires to call a It's kinda wierd why it's not working inside a UI class, but this would do for a while. I will only use a plot in one UI in my game, so that's not a big deal. The hovering event works by calculating the mouse cursor relative to the |
Here is an example program of a custom, animated, surface being updated on a UIImage: import pygame
import pygame_gui
import random
pygame.init()
pygame.display.set_caption("Quick Start")
window_surface = pygame.display.set_mode((800, 600))
background = pygame.Surface((800, 600))
background.fill(pygame.Color("#000000"))
plot_surface = pygame.Surface((100, 100))
plot_surface.fill(pygame.Color("#909060"))
manager = pygame_gui.UIManager((800, 600))
test_window = pygame_gui.elements.UIWindow((50, 50, 300, 300), manager, "Test Window")
plot_ui_image = pygame_gui.elements.UIImage(
relative_rect=pygame.Rect((50, 50), (100, 100)),
image_surface=plot_surface,
manager=manager,
container=test_window,
)
colour_change_timer = 0.0
clock = pygame.time.Clock()
is_running = True
while is_running:
time_delta = clock.tick(60) / 1000.0
for event in pygame.event.get():
if event.type == pygame.QUIT:
is_running = False
manager.process_events(event)
colour_change_timer += time_delta
if colour_change_timer >= 1.0:
colour_change_timer = 0.0
plot_surface.fill(
(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
)
plot_ui_image.set_image(plot_surface)
manager.update(time_delta)
window_surface.blit(background, (0, 0))
manager.draw_ui(window_surface)
pygame.display.update() |
Thanks for the code, but I want to create a custom Here is two code. (The code is not yet optimized) This is code contains what I want to achive. I want to implement the Github didn't allowed me to upload python files, so I uploaded as txt files. |
Yeah I still have this issue. For some reason it always adds 25 no matter what value I add, even if I add a constant 5 it still adds 25 instead. Also new values didn't got added to the plot. |
I've found out the If I replace the Anyway, thanks for the help, the suffering now ends for a while I hope. By the way, happy new year 🥳🎉. |
Is your feature request related to a problem? Please describe.
Currently pygame_gui doesn't have plots, so I made a simple class which draws a plot surface, but I couldn't find a way to add it to the base
UIElement
class. I would simply use the rendered plot surface, inside theUIElement
to render the plot, but as far as I know I can't.Describe the solution you'd like
A simple
UISurfaceElement
which can render raw pygame surface would be cool. I didn't dig into the code too much, so I don't know if this is even possible.Describe alternatives you've considered
None
Additional context
A simple code example that I came up with:
The text was updated successfully, but these errors were encountered: