Small refactor and note updates
This commit is contained in:
@@ -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):
|
class DrawArea(Gtk.DrawingArea):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(DrawArea, self).__init__()
|
super(DrawArea, self).__init__()
|
||||||
@@ -205,13 +206,14 @@ class DrawArea(Gtk.DrawingArea):
|
|||||||
if self.is_drawing:
|
if self.is_drawing:
|
||||||
for surface in self.surface_manager:
|
for surface in self.surface_manager:
|
||||||
brush.set_source_surface(surface.area, 0.0, 0.0)
|
brush.set_source_surface(surface.area, 0.0, 0.0)
|
||||||
brush.paint()
|
|
||||||
|
|
||||||
|
brush.paint()
|
||||||
return
|
return
|
||||||
|
|
||||||
for surface in self.surface_manager:
|
for surface in self.surface_manager:
|
||||||
brush.set_source_surface(surface.area, 0.0, 0.0)
|
brush.set_source_surface(surface.area, 0.0, 0.0)
|
||||||
surface.draw()
|
surface.draw()
|
||||||
|
|
||||||
brush.paint()
|
brush.paint()
|
||||||
|
|
||||||
def _draw_overlay(self, area, brush: cairo.Context):
|
def _draw_overlay(self, area, brush: cairo.Context):
|
||||||
|
@@ -9,6 +9,7 @@ from libs.history_manager import HistoryManager
|
|||||||
from data.events.event import Event
|
from data.events.event import Event
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Surface:
|
class Surface:
|
||||||
def __init__(self, w = 1, h = 1):
|
def __init__(self, w = 1, h = 1):
|
||||||
super(Surface, self).__init__()
|
super(Surface, self).__init__()
|
||||||
@@ -19,7 +20,6 @@ class Surface:
|
|||||||
self.create_new_area(None, w, h)
|
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):
|
def create_new_area(self, surface: cairo.ImageSurface = None, w: int = None, h: int = None):
|
||||||
if surface:
|
if surface:
|
||||||
self.area = surface
|
self.area = surface
|
||||||
@@ -36,11 +36,13 @@ class Surface:
|
|||||||
self.history_manager.append(event)
|
self.history_manager.append(event)
|
||||||
|
|
||||||
def draw(self):
|
def draw(self):
|
||||||
if not self.image_data:
|
if self.image_data:
|
||||||
self.clear_surface()
|
# Note: dest_data here is accessing directly the raw pixil buffer
|
||||||
elif self.image_data:
|
# so writes here get directly applied without needing to call 'paint'.
|
||||||
dest_data = self.area.get_data()
|
dest_data = self.area.get_data()
|
||||||
dest_data[:len(self.image_data)] = self.image_data[:]
|
dest_data[:len(self.image_data)] = self.image_data[:]
|
||||||
|
else:
|
||||||
|
self.clear_surface()
|
||||||
|
|
||||||
for event in self.history_manager:
|
for event in self.history_manager:
|
||||||
if not event.is_valid: continue
|
if not event.is_valid: continue
|
||||||
|
Reference in New Issue
Block a user