Small refactor and note updates

This commit is contained in:
2025-09-19 00:18:23 -05:00
parent 5c72847864
commit f34cf69b8c
2 changed files with 10 additions and 6 deletions

View File

@@ -20,6 +20,7 @@ from .surface import Surface
# Note: https://martimm.github.io/gnome-gtk3/content-docs/tutorial/Cairo/drawing-model.html
class DrawArea(Gtk.DrawingArea):
def __init__(self):
super(DrawArea, self).__init__()
@@ -205,13 +206,14 @@ class DrawArea(Gtk.DrawingArea):
if self.is_drawing:
for surface in self.surface_manager:
brush.set_source_surface(surface.area, 0.0, 0.0)
brush.paint()
brush.paint()
return
for surface in self.surface_manager:
brush.set_source_surface(surface.area, 0.0, 0.0)
surface.draw()
brush.paint()
def _draw_overlay(self, area, brush: cairo.Context):

View File

@@ -9,6 +9,7 @@ from libs.history_manager import HistoryManager
from data.events.event import Event
class Surface:
def __init__(self, w = 1, h = 1):
super(Surface, self).__init__()
@@ -19,7 +20,6 @@ class Surface:
self.create_new_area(None, w, h)
# Note: https://martimm.github.io/gnome-gtk3/content-docs/tutorial/Cairo/drawing-model.html
def create_new_area(self, surface: cairo.ImageSurface = None, w: int = None, h: int = None):
if surface:
self.area = surface
@@ -36,11 +36,13 @@ class Surface:
self.history_manager.append(event)
def draw(self):
if not self.image_data:
self.clear_surface()
elif self.image_data:
if self.image_data:
# Note: dest_data here is accessing directly the raw pixil buffer
# so writes here get directly applied without needing to call 'paint'.
dest_data = self.area.get_data()
dest_data[:len(self.image_data)] = self.image_data[:]
else:
self.clear_surface()
for event in self.history_manager:
if not event.is_valid: continue