Skip to content

Commit

Permalink
support for cairo
Browse files Browse the repository at this point in the history
  • Loading branch information
misko committed Oct 8, 2024
1 parent 2aacdce commit 958a91e
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions hudes/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
update_grid_vbo,
)

backend = "Agg"
# backend='cairo'
matplotlib.use(backend)
# backend = "Agg"
# backend = "cairo"
# matplotlib.use(backend)
plt_backend = matplotlib.get_backend()


def surface_to_npim(surface):
Expand Down Expand Up @@ -173,7 +174,7 @@ def __init__(self, use_midi=False):
# self.fig = plt.figure(
# figsize=(self.window_size[0] / dpi, self.window_size[1] / dpi), dpi=dpi
# )
self.fig = plt.figure(figsize=(12, 8))
self.fig = plt.figure(figsize=(12, 8), facecolor="white")

# if self.fig.dpi != dpi:
# logging.warning(
Expand Down Expand Up @@ -332,9 +333,22 @@ def draw_or_restore(self):
def draw(self):

logging.debug("hudes_client: redraw")
if True: # backend.lower()=='agg':
# cairo
# np.frombuffer(self.canvas._get_printed_image_surface().get_data(),np.uint8)
# https://www.pygame.org/wiki/CairoPygame
if "cairo" in plt_backend.lower():
self.canvas.draw()
surf = pg.image.frombuffer(
# self.renderer.tostring_rgb(),
self.canvas._get_printed_image_surface().get_data(),
self.window_size,
"RGBA",
)
self.screen.blit(surf, (0, 0))
else: # backend.lower()=='agg':
# self.canvas.draw()
# self.canvas.update()
# breakpoint()
self.renderer.clear()
self.draw_or_restore()
# if self.redraw_train_and_val:
Expand All @@ -348,11 +362,17 @@ def draw(self):
# else:
# self.fig.canvas.restore_region(self.axd["B"].cache)
# self.fig.canvas.restore_region(self.axd["D"].cache)
# TODO TRY FORM BUFFER AND USE THE TOSTRING BUFFER!!!
surf = pg.image.frombytes(
self.renderer.tostring_rgb(),
self.window_size,
"RGB",
)
# surf = pg.image.frombuffer(
# self.renderer.buffer_rgba(),
# self.window_size,
# "RGBA",
# )
self.screen.blit(surf, (0, 0))
# else:

Expand Down

0 comments on commit 958a91e

Please sign in to comment.