drawing: add a stroke.seal() functionality
Makes end-of-stroke handling easier, we can call seal() on the current stroke and it'll make drawing.current_stroke() None, which is something we can deal with.pull/94/head
parent
155a11104c
commit
23e18cea67
|
@ -41,8 +41,18 @@ class Stroke(GObject.Object):
|
||||||
self.points = []
|
self.points = []
|
||||||
self._position = (0, 0)
|
self._position = (0, 0)
|
||||||
self._pressure = 0
|
self._pressure = 0
|
||||||
|
self._is_sealed = False
|
||||||
|
|
||||||
|
@GObject.property
|
||||||
|
def sealed(self):
|
||||||
|
return self._is_sealed
|
||||||
|
|
||||||
|
def seal(self):
|
||||||
|
self._is_sealed = True
|
||||||
|
|
||||||
def new_rel(self, position=None, pressure=None):
|
def new_rel(self, position=None, pressure=None):
|
||||||
|
assert not self._is_sealed
|
||||||
|
|
||||||
p = Point(self)
|
p = Point(self)
|
||||||
if position is not None:
|
if position is not None:
|
||||||
x, y = self._position
|
x, y = self._position
|
||||||
|
@ -55,6 +65,8 @@ class Stroke(GObject.Object):
|
||||||
self.points.append(p)
|
self.points.append(p)
|
||||||
|
|
||||||
def new_abs(self, position=None, pressure=None):
|
def new_abs(self, position=None, pressure=None):
|
||||||
|
assert not self._is_sealed
|
||||||
|
|
||||||
p = Point(self)
|
p = Point(self)
|
||||||
if position is not None:
|
if position is not None:
|
||||||
self._position = position
|
self._position = position
|
||||||
|
@ -88,18 +100,27 @@ class Drawing(GObject.Object):
|
||||||
|
|
||||||
def seal(self):
|
def seal(self):
|
||||||
# Drop empty strokes
|
# Drop empty strokes
|
||||||
|
for s in self.strokes:
|
||||||
|
s.seal()
|
||||||
self.strokes = [s for s in self.strokes if s.points]
|
self.strokes = [s for s in self.strokes if s.points]
|
||||||
|
|
||||||
# The way we're building drawings, we don't need to change the current
|
# The way we're building drawings, we don't need to change the current
|
||||||
# stroke at runtime, so this is read-ony
|
# stroke at runtime, so this is read-ony
|
||||||
@GObject.Property
|
@GObject.Property
|
||||||
def current_stroke(self):
|
def current_stroke(self):
|
||||||
return self.strokes[self._current_stroke]
|
if self._current_stroke < 0:
|
||||||
|
return None
|
||||||
|
|
||||||
|
s = self.strokes[self._current_stroke]
|
||||||
|
return s if not s.sealed else None
|
||||||
|
|
||||||
def new_stroke(self):
|
def new_stroke(self):
|
||||||
'''
|
'''
|
||||||
Create a new stroke and make it the current stroke
|
Create a new stroke and make it the current stroke
|
||||||
'''
|
'''
|
||||||
|
if self.current_stroke is not None:
|
||||||
|
self.current_stroke.seal()
|
||||||
|
|
||||||
s = Stroke(self)
|
s = Stroke(self)
|
||||||
self.strokes.append(s)
|
self.strokes.append(s)
|
||||||
self._current_stroke += 1
|
self._current_stroke += 1
|
||||||
|
|
|
@ -636,9 +636,10 @@ class WacomProtocolBase(WacomProtocolLowLevelComm):
|
||||||
continue
|
continue
|
||||||
if bytes(args) == b'\x00\x00\xff\xff\xff\xff\xff\xff':
|
if bytes(args) == b'\x00\x00\xff\xff\xff\xff\xff\xff':
|
||||||
logger.info(f'end of stroke')
|
logger.info(f'end of stroke')
|
||||||
stroke = None
|
stroke.seal()
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
stroke = drawing.current_stroke
|
||||||
if stroke is None:
|
if stroke is None:
|
||||||
stroke = drawing.new_stroke()
|
stroke = drawing.new_stroke()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue