Permalink
Browse files

lib: Make the C++ part of TiledSurface a member, not base class

Will make it easier to swap out the underlying C++ class (for GEGL)<
  • Loading branch information...
1 parent a3c0492 commit 5057a067865b3aba1c4147bc4e652838c00b2031 @jonnor jonnor committed Jun 21, 2013
Showing with 39 additions and 10 deletions.
  1. +1 −1 lib/layer.py
  2. +34 −5 lib/tiledsurface.py
  3. +2 −2 mypaint-gegl.py
  4. +1 −1 tests/test_mypaintlib.py
  5. +1 −1 tests/test_performance.py
View
@@ -115,7 +115,7 @@ def save_as_png(self, filename, *args, **kwargs):
def stroke_to(self, brush, x, y, pressure, xtilt, ytilt, dtime):
"""Render a part of a stroke."""
self._surface.begin_atomic()
- split = brush.stroke_to(self._surface, x, y,
+ split = brush.stroke_to(self._surface.backend, x, y,
pressure, xtilt, ytilt, dtime)
self._surface.end_atomic()
return split
View
@@ -88,11 +88,24 @@ class SurfaceSnapshot:
if use_gegl:
- class GeglSurface(mypaintlib.GeglBackedSurface):
+ class GeglSurface():
- def __init__(self, mipmap_level=0):
- mypaintlib.GeglBackedSurface.__init__(self, self)
+ def __init__(self, mipmap_level=0, looped=False, looped_size=(0,0)):
self.observers = []
+ self._backend = mypaintlib.GeglBackedSurface(self)
+
+ # Forwarding API
+ self.begin_atomic = self._backend.begin_atomic
+ self.end_atomic = self._backend.end_atomic
+ self.get_color = self._backend.get_color
+ self.get_alpha = self._backend.get_alpha
+ self.draw_dab = self._backend.draw_dab
+# self.set_symmetry_state = self._backend.set_symmetry_state
+ self.get_node = self._backend.get_node
+
+ @property
+ def backend(self):
+ return self._backend
def notify_observers(self, *args):
for f in self.observers:
@@ -141,10 +154,14 @@ def get_tiles(self):
def set_symmetry_state(self, enabled, center_axis):
pass
-class MyPaintSurface(mypaintlib.TiledSurface):
+# TODO:
+# - move the tile storage from MyPaintSurface to a separate class
+class MyPaintSurface():
# the C++ half of this class is in tiledsurface.hpp
def __init__(self, mipmap_level=0, looped=False, looped_size=(0,0)):
- mypaintlib.TiledSurface.__init__(self, self)
+
+ # TODO: pass just what it needs access to, not all of self
+ self._backend = mypaintlib.TiledSurface(self)
self.tiledict = {}
self.observers = []
@@ -162,6 +179,18 @@ def __init__(self, mipmap_level=0, looped=False, looped_size=(0,0)):
self.mipmap = Surface(mipmap_level+1)
self.mipmap.parent = self
+ # Forwarding API
+ self.set_symmetry_state = self._backend.set_symmetry_state
+ self.begin_atomic = self._backend.begin_atomic
+ self.end_atomic = self._backend.end_atomic
+ self.get_color = self._backend.get_color
+ self.get_alpha = self._backend.get_alpha
+ self.draw_dab = self._backend.draw_dab
+
+ @property
+ def backend(self):
+ return self._backend
+
def notify_observers(self, *args):
for f in self.observers:
f(*args)
View
@@ -22,7 +22,7 @@ def draw_test_data(surface, brush):
for t, x, y, pressure in events:
dtime = t - t_old
t_old = t
- b.stroke_to (s, x, y, pressure, 0.0, 0.0, dtime)
+ b.stroke_to (s.backend, x, y, pressure, 0.0, 0.0, dtime)
s.end_atomic()
def find_widgets(widget, predicate):
@@ -128,7 +128,7 @@ def motion_to(self, widget, event):
dtime = (time - self.last_event[2])/1000.0
if self.button_pressed:
self.surface.begin_atomic()
- self.brush.stroke_to(self.surface, x, y, pressure, 0.0, 0.0, dtime)
+ self.brush.stroke_to(self.surface.backend, x, y, pressure, 0.0, 0.0, dtime)
self.surface.end_atomic()
self.last_event = (x, y, time)
View
@@ -113,7 +113,7 @@ def brushPaint():
dtime = t - t_old
t_old = t
s.begin_atomic()
- b.stroke_to (s, x*4, y*4, pressure, 0.0, 0.0, dtime)
+ b.stroke_to(s.backend, x*4, y*4, pressure, 0.0, 0.0, dtime)
s.end_atomic()
print 'Brushpaint time:', time()-t0
print s.get_bbox(), b.get_total_stroke_painting_time() # FIXME: why is this time so different each run?
@@ -191,7 +191,7 @@ def brushengine_paint_hires():
for t, x, y, pressure in events:
dtime = t - t_old
t_old = t
- b.stroke_to (s, x*5, y*5, pressure, 0.0, 0.0, dtime)
+ b.stroke_to(s.backend, x*5, y*5, pressure, 0.0, 0.0, dtime)
trans_time += dtime
if trans_time > 0.05:

0 comments on commit 5057a06

Please sign in to comment.