mirror of
https://github.com/lalbornoz/roar.git
synced 2024-11-22 23:36:36 +00:00
Implements {un,re}doing resizing.
libcanvas/Canvas.py:_dispatchDeltaPatches(): handle `resize' delta patches. libcanvas/Canvas.py:_dispatchPatch(): only commit to journal given commitUndo. libcanvas/Canvas.py:resize(): commit `resize' & {deleted,added} cell deltas to journal. libcanvas/Canvas.py: minor cleanup. libcanvas/Canvas{Backend,{Export,Import}Store,Journal}.py: minor cleanup. assets/text/arab-puke.txt: added from mircart/pack2/. assets/text/TODO: updated.
This commit is contained in:
parent
0aa80899ff
commit
c81275bf2f
@ -1,12 +1,12 @@
|
|||||||
1) Scrollbar
|
1) General {cleanup,refactor}
|
||||||
2) Allow {un,re}doing resizing
|
2) Incremental auto{load,save} & {backup,restore}
|
||||||
3) Incremental auto{load,save} & {backup,restore}
|
3) Open and toggle a reference image in the background
|
||||||
4) Open and toggle a reference image in the background
|
4) Client-Server or Peer-to-Peer realtime collaboration
|
||||||
5) Client-Server or Peer-to-Peer realtime collaboration
|
5) Arbitrary {format,palette}s ({4,8} bit ANSI/mIRC, etc.)
|
||||||
6) Arbitrary {format,palette}s ({4,8} bit ANSI/mIRC, etc.)
|
6) Hotkey & graphical interfaces to {composed,parametrised} tools
|
||||||
7) Hotkey & graphical interfaces to {composed,parametrised} tools
|
7) Layer, layout (e.g. for comics, zines, etc.) & {re,un}do canvas traits
|
||||||
8) Layer, layout (e.g. for comics, zines, etc.) & {re,un}do canvas traits
|
8) {Insert,{ex,im}port}ing from/to ANSI, Blender, GIF, HTML, mIRC, printer, SAUCE, WEBM, etc. {clipboard,file}
|
||||||
9) Im- and exporting from/to ANSI, Blender, GIF, HTML, mIRC, Pastebin/..., PNG, printer, SAUCE, WEBM, etc.
|
9) GUI: a) rightmost alignment of Help menu b) scrollbar c) switch from wxPython to GTK d) toolbar tooltips
|
||||||
10) Asset management (e.g. kade, lion, etc.) & traits w/ simple linking & synchronised editing respecting layers
|
10) Asset management (e.g. kade, lion, etc.) & traits w/ simple linking & synchronised editing respecting layers
|
||||||
11) Sprites & scripted (Python?) animation on the basis of asset traits and {composable,parametrised} patterns (metric flow, particle system, rigging, ...)
|
11) Sprites & scripted (Python?) animation on the basis of asset traits and {composable,parametrised} patterns (metric flow, particle system, rigging, ...)
|
||||||
12) Composition and parametrisation of tools from higher-order operators (brushes, filters, outlines, patterns & shaders) and unit tools; unit tools:
|
12) Composition and parametrisation of tools from higher-order operators (brushes, filters, outlines, patterns & shaders) and unit tools; unit tools:
|
||||||
|
36
assets/text/arab-puke.txt
Normal file
36
assets/text/arab-puke.txt
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
0,1 3,3 0,1 9,9 0,1 9,9 0,1 9,9 0,1 9,9 0,1 9,9 0,1 9,9 0,1 9,9 0,1 3,3 0,1 0,0 1,1 0,1 0,0 0,1 9,9 0,1 9,9 0,1 9,9 0,1 9,9 0,1 9,9 0,1 9,9 0,1 9,9 0,1 9,9 0,1 9,9 0,1 9,9 1,1 9,9 1,1 9,9 1,1 0,1 9,9 0,1 9,9 0,1 9,9 0,1 9,9 0,1 9,9 0,1
|
||||||
|
3,3 0,1 3,3 0,1 9,9 0,1 9,9 1,1 9,9 0,1 9,9 0,1 9,9 0,1 9,9 0,1 9,9 0,1 9,9 0,1 0,0 0,1 0,0 0,1 0,0 0,1 9,9 0,1 9,9 0,1 9,9 0,1 9,9 0,1 9,9 0,1 9,9 0,1 1,1 9,9 0,1 9,9 1,1 0,1 9,9 0,1 9,9 0,1 9,9 0,1 9,9 0,1
|
||||||
|
0,1 3,3 0,1 9,9 0,1 11,11 10,10 11,11 0,1 9,9 0,1 9,9 0,1 3,3 0,1 3,3 0,1 0,0 0,1 0,0 0,1 0,0 0,1 9,9 0,1 9,9 0,1 9,9 0,1 1,1 9,9 0,1 1,1 0,1 9,9 0,1 9,9 0,1
|
||||||
|
0,1 3,3 0,1 3,3 0,1 10,10 11,11 10,10 11,11 10,10 0,1 3,3 0,1 3,3 0,1 0,0 0,1 3,3 0,1 3,3 0,1 1,1 3,3 1,1 3,3 1,1 9,9 1,1 9,9 1,1 3,3 1,1 3,3 1,1 0,1 3,3 0,1 3,3 0,1
|
||||||
|
9,9 1,1 3,3 1,1 10,10 11,11 10,10 11,11 10,10 1,1 0,0 1,1 11,11 1,10 1,1 11,11 1,1 3,3 1,1 9,9 1,1 3,3 1,1 11,11 1,1 1,10 11,11 0,1 9,9
|
||||||
|
9,9 1,1 10,10 11,11 10,10 11,11 10,10 11,11 1,1 3,3 1,1 11,11 1,10 1,1 11,11 1,1 3,3 1,1 3,3 1,1 11,11 1,1 1,10 11,11 0,1 9,9
|
||||||
|
9,9 1,1 10,10 11,11 10,10 11,11 10,10 1,1 8,8 1,1 11,11 1,10 1,1 11,11 1,1 3,3 1,1 11,11 1,1 1,10 11,11 1,1 0,1 9,9
|
||||||
|
9,9 1,1 11,11 10,10 11,11 10,10 11,11 10,10 11,11 10,10 1,1 8,8 1,1 8,8 1,1 11,11 1,10 1,1 11,11 1,1 1,10 11,11 1,1 0,1 9,9
|
||||||
|
9,9 1,1 11,11 10,10 11,11 10,10 11,10 10,10 11,11 10,10 1,1 8,8 1,1 8,8 1,1 11,11 1,10 1,1 1,10 11,11 1,1 0,1 9,9
|
||||||
|
9,9 1,1 11,11 10,10 11,11 10,10 11,11 10,10 1,1 8,8 1,1 8,8 1,1 8,8 1,1 0,0 1,1 8,8 1,1 8,8 1,1 8,8 1,1 11,11 1,10 11,11 1,10 11,11 1,1 0,1 9,9
|
||||||
|
1,3 9,9 1,1 11,11 10,10 11,11 10,10 11,11 1,1 8,8 1,1 8,8 1,1 8,8 1,1 0,0 1,1 0,0 1,1 8,8 1,1 8,8 1,1 8,8 1,1 11,11 10,10 11,11 1,1 0,1 9,9 1,3
|
||||||
|
3,3 9,9 1,1 3,3 1,1 3,3 1,1 11,11 10,10 1,1 8,8 1,1 8,8 1,1 8,8 1,1 0,0 1,1 8,8 1,1 8,8 1,1 8,8 1,1 3,3 9,9 3,3 1,1 0,1 9,9 1,3
|
||||||
|
3,3 9,9 1,1 3,3 1,1 3,3 1,1 3,3 1,1 3,3 1,1 8,8 1,1 8,8 1,1 8,8 1,1 0,0 1,1 8,8 1,1 8,8 1,1 0,0 1,1 8,8 1,1 8,8 1,1 8,8 1,1 3,3 9,9 1,1 0,1 9,9 1,3
|
||||||
|
3,3 9,9 1,1 3,3 1,1 3,3 1,1 3,3 1,1 3,3 1,1 8,8 1,1 8,8 1,1 8,8 1,1 0,0 1,1 0,0 1,1 8,8 1,1 8,8 1,1 0,0 1,1 0,0 1,1 8,8 1,1 8,8 1,1 8,8 1,1 3,3 9,9 3,3 1,1 0,1 9,9 1,3
|
||||||
|
3,3 9,9 1,1 9,9 1,1 9,9 1,1 9,9 1,1 7,7 8,8 1,1 8,8 1,1 8,8 1,1 0,0 1,1 8,8 1,1 0,0 1,1 8,8 1,1 8,8 1,1 8,8 1,1 9,9 3,3 1,1 0,1 9,9 1,3
|
||||||
|
1,3 3,3 9,9 1,1 9,9 1,1 9,9 1,1 9,9 1,1 9,9 1,1 9,9 1,1 9,9 1,1 7,7 8,8 1,1 8,8 1,1 8,8 1,1 3,3 9,9 3,3 1,1 0,1 9,9 1,3
|
||||||
|
11,11 3,3 9,9 1,1 7,7 8,8 1,1 8,8 1,1 8,8 1,1 8,8 1,1 3,3 9,9 1,1 0,1 9,9 1,3 11,11
|
||||||
|
11,11 3,3 9,9 1,1 3,3 1,1 3,3 1,1 3,3 1,1 3,3 1,1 3,3 1,1 3,3 1,1 7,7 8,8 1,1 0,0 1,1 8,8 1,1 3,3 9,9 3,3 1,1 0,1 9,9 1,3 11,11
|
||||||
|
11,11 1,3 3,3 9,9 1,1 9,9 1,1 9,9 1,1 9,9 1,1 9,9 1,1 9,9 1,1 7,7 8,8 1,1 8,8 1,1 9,9 3,3 1,1 0,1 9,9 1,3 11,11
|
||||||
|
10,10 3,11 1,3 3,3 9,9 1,1 3,3 1,1 3,3 1,1 7,7 8,8 1,1 0,0 1,1 0,0 1,1 0,0 1,1 8,8 1,1 3,3 1,1 9,9 1,3 3,11 10,10
|
||||||
|
10,10 3,11 1,3 3,3 9,9 1,1 3,3 1,1 3,3 1,1 3,3 1,1 3,3 1,1 3,3 1,1 7,7 8,8 8,1 1,1 8,1 8,8 1,1 9,9 3,3 1,1 9,9 1,3 3,11 10,10
|
||||||
|
10,10 3,11 1,3 3,3 9,9 1,1 9,9 1,1 9,9 1,1 9,9 1,1 9,9 1,1 7,7 8,8 8,1 0,0 1,1 0,0 1,1 0,0 8,1 8,8 1,1 3,3 9,9 1,3 3,11 10,10
|
||||||
|
10,10 3,11 3,3 9,9 7,7 8,8 8,1 1,1 8,1 8,8 7,7 9,9 3,3 1,3 3,11 10,10
|
||||||
|
10,10 11,11 3,3 7,7 8,8 8,1 0,0 8,1 8,8 7,7 3,3 11,11 10,10
|
||||||
|
10,10 11,11 3,3 9,9 7,7 8,8 8,1 8,8 7,7 9,9 3,3 11,11 10,10
|
||||||
|
10,10 11,11 3,3 9,9 3,3 7,7 3,3 9,9 3,3 11,11 10,10
|
||||||
|
10,10 11,11 3,3 9,9 3,3 11,11 3,3 9,9 3,3 11,11 10,10
|
||||||
|
11,11 3,3 9,9 3,3 11,11 10,10 11,11 3,3 9,9 3,3 11,11
|
||||||
|
11,11 3,3 9,9 3,3 11,11 10,10 11,11 10,10 11,11 3,3 9,9 3,3 11,11
|
||||||
|
11,11 3,3 9,9 3,3 11,11 10,10 11,11 10,10 11,11 10,10 11,11 3,3 9,9 3,3 11,11
|
||||||
|
11,11 3,3 9,9 3,3 11,11 10,10 11,11 10,10 11,11 3,3 9,9 3,3 11,11
|
||||||
|
10,10 11,11 3,3 9,9 3,3 11,11 10,10 11,11 3,3 9,9 3,3 11,11 10,10
|
||||||
|
10,10 11,11 3,3 9,9 3,3 11,11 3,3 9,9 3,3 11,11 10,10
|
||||||
|
10,10 11,11 3,3 9,9 3,3 9,9 3,3 11,11 10,10
|
||||||
|
10,10 11,11 3,3 9,9 3,3 11,11 10,10
|
||||||
|
10,10 11,11 3,3 11,11 10,10
|
@ -13,7 +13,6 @@ import wx
|
|||||||
|
|
||||||
class Canvas(wx.Panel):
|
class Canvas(wx.Panel):
|
||||||
"""XXX"""
|
"""XXX"""
|
||||||
imgurApiKey = ImgurApiKey.imgurApiKey
|
|
||||||
|
|
||||||
# {{{ _commitPatch(self, patch): XXX
|
# {{{ _commitPatch(self, patch): XXX
|
||||||
def _commitPatch(self, patch):
|
def _commitPatch(self, patch):
|
||||||
@ -23,25 +22,28 @@ class Canvas(wx.Panel):
|
|||||||
def _dispatchDeltaPatches(self, deltaPatches):
|
def _dispatchDeltaPatches(self, deltaPatches):
|
||||||
eventDc = self.canvasBackend.getDeviceContext(self)
|
eventDc = self.canvasBackend.getDeviceContext(self)
|
||||||
for patch in deltaPatches:
|
for patch in deltaPatches:
|
||||||
if self.canvasBackend.drawPatch(eventDc, patch):
|
if patch[0] == "resize":
|
||||||
|
del eventDc
|
||||||
|
self.resize(patch[1:], False)
|
||||||
|
eventDc = self.canvasBackend.getDeviceContext(self)
|
||||||
|
elif self.canvasBackend.drawPatch(eventDc, patch):
|
||||||
self._commitPatch(patch)
|
self._commitPatch(patch)
|
||||||
self.parentFrame.onCanvasUpdate(undoLevel=self.canvasJournal.patchesUndoLevel)
|
self.parentFrame.onCanvasUpdate(undoLevel=self.canvasJournal.patchesUndoLevel)
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ _dispatchPatch(self, eventDc, isCursor, patch): XXX
|
# {{{ _dispatchPatch(self, eventDc, isCursor, patch, commitUndo=True): XXX
|
||||||
def _dispatchPatch(self, eventDc, isCursor, patch):
|
def _dispatchPatch(self, eventDc, isCursor, patch, commitUndo=True):
|
||||||
if not self._canvasDirtyCursor:
|
if not self._canvasDirtyCursor:
|
||||||
self.canvasBackend.drawCursorMaskWithJournal( \
|
self.canvasBackend.drawCursorMaskWithJournal(self.canvasJournal, eventDc)
|
||||||
self.canvasJournal, eventDc)
|
|
||||||
self._canvasDirtyCursor = True
|
self._canvasDirtyCursor = True
|
||||||
if self.canvasBackend.drawPatch(eventDc, patch):
|
if self.canvasBackend.drawPatch(eventDc, patch):
|
||||||
patchDeltaCell = self.canvasMap[patch[1]][patch[0]]
|
patchDeltaCell = self.canvasMap[patch[1]][patch[0]]
|
||||||
patchDelta = [*patch[0:2], *patchDeltaCell]
|
patchDelta = [*patch[0:2], *patchDeltaCell]
|
||||||
if isCursor:
|
if isCursor and commitUndo:
|
||||||
self.canvasJournal.pushCursor(patchDelta)
|
self.canvasJournal.pushCursor(patchDelta)
|
||||||
else:
|
else:
|
||||||
|
if commitUndo:
|
||||||
if not self._canvasDirty:
|
if not self._canvasDirty:
|
||||||
self.canvasJournal.pushDeltas([], [])
|
self.canvasJournal.pushDeltas([], []); self._canvasDirty = True;
|
||||||
self._canvasDirty = True
|
|
||||||
self.canvasJournal.updateCurrentDeltas(patchDelta, patch)
|
self.canvasJournal.updateCurrentDeltas(patchDelta, patch)
|
||||||
self._commitPatch(patch)
|
self._commitPatch(patch)
|
||||||
# }}}
|
# }}}
|
||||||
@ -78,16 +80,14 @@ class Canvas(wx.Panel):
|
|||||||
event.Dragging(), event.LeftIsDown(), event.RightIsDown(), \
|
event.Dragging(), event.LeftIsDown(), event.RightIsDown(), \
|
||||||
self._dispatchPatch, eventDc)
|
self._dispatchPatch, eventDc)
|
||||||
if self._canvasDirty:
|
if self._canvasDirty:
|
||||||
self.parentFrame.onCanvasUpdate(cellPos=self.brushPos, \
|
self.parentFrame.onCanvasUpdate(cellPos=self.brushPos, undoLevel=self.canvasJournal.patchesUndoLevel)
|
||||||
undoLevel=self.canvasJournal.patchesUndoLevel)
|
|
||||||
if eventType == wx.wxEVT_MOTION:
|
if eventType == wx.wxEVT_MOTION:
|
||||||
self.parentFrame.onCanvasUpdate(cellPos=mapPoint)
|
self.parentFrame.onCanvasUpdate(cellPos=mapPoint)
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ onPanelLeaveWindow(self, event): XXX
|
# {{{ onPanelLeaveWindow(self, event): XXX
|
||||||
def onPanelLeaveWindow(self, event):
|
def onPanelLeaveWindow(self, event):
|
||||||
eventDc = self.canvasBackend.getDeviceContext(self)
|
eventDc = self.canvasBackend.getDeviceContext(self)
|
||||||
self.canvasBackend.drawCursorMaskWithJournal( \
|
self.canvasBackend.drawCursorMaskWithJournal(self.canvasJournal, eventDc)
|
||||||
self.canvasJournal, eventDc)
|
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ onPanelPaint(self, event): XXX
|
# {{{ onPanelPaint(self, event): XXX
|
||||||
def onPanelPaint(self, event):
|
def onPanelPaint(self, event):
|
||||||
@ -95,66 +95,71 @@ class Canvas(wx.Panel):
|
|||||||
# }}}
|
# }}}
|
||||||
# {{{ onStoreUpdate(self, newCanvasSize, newCanvas=None): XXX
|
# {{{ onStoreUpdate(self, newCanvasSize, newCanvas=None): XXX
|
||||||
def onStoreUpdate(self, newCanvasSize, newCanvas=None):
|
def onStoreUpdate(self, newCanvasSize, newCanvas=None):
|
||||||
self.resize(newCanvasSize=newCanvasSize)
|
self.resize(newCanvasSize=newCanvasSize, commitUndo=False)
|
||||||
eventDc = self.canvasBackend.getDeviceContext(self)
|
eventDc = self.canvasBackend.getDeviceContext(self)
|
||||||
for numRow in range(self.canvasSize[1]):
|
for numRow in range(self.canvasSize[1]):
|
||||||
for numCol in range(self.canvasSize[0]):
|
for numCol in range(self.canvasSize[0]):
|
||||||
if newCanvas != None \
|
if newCanvas != None \
|
||||||
and numRow < len(newCanvas) \
|
and numRow < len(newCanvas) \
|
||||||
and numCol < len(newCanvas[numRow]):
|
and numCol < len(newCanvas[numRow]):
|
||||||
self._commitPatch([ \
|
self._commitPatch([numCol, numRow, *newCanvas[numRow][numCol]])
|
||||||
numCol, numRow, *newCanvas[numRow][numCol]])
|
self.canvasBackend.drawPatch(eventDc, [numCol, numRow, *self.canvasMap[numRow][numCol]])
|
||||||
self.canvasBackend.drawPatch(eventDc, \
|
|
||||||
[numCol, numRow, \
|
|
||||||
*self.canvasMap[numRow][numCol]])
|
|
||||||
wx.SafeYield()
|
wx.SafeYield()
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ resize(self, newCanvasSize): XXX
|
# {{{ resize(self, newCanvasSize, commitUndo=True): XXX
|
||||||
def resize(self, newCanvasSize):
|
def resize(self, newCanvasSize, commitUndo=True):
|
||||||
if newCanvasSize != self.canvasSize:
|
if newCanvasSize != self.canvasSize:
|
||||||
|
self._canvasDirty, self._canvasDirtyCursor = False, False
|
||||||
if self.canvasMap == None:
|
if self.canvasMap == None:
|
||||||
self.canvasMap = []; oldCanvasSize = [0, 0];
|
self.canvasMap, oldCanvasSize = [], [0, 0]
|
||||||
else:
|
else:
|
||||||
oldCanvasSize = self.canvasSize
|
oldCanvasSize = self.canvasSize
|
||||||
deltaCanvasSize = [b - a for a, b in zip(oldCanvasSize, newCanvasSize)]
|
deltaCanvasSize = [b - a for a, b in zip(oldCanvasSize, newCanvasSize)]
|
||||||
|
|
||||||
newWinSize = [a * b for a, b in zip(newCanvasSize, self.canvasBackend.cellSize)]
|
newWinSize = [a * b for a, b in zip(newCanvasSize, self.canvasBackend.cellSize)]
|
||||||
self.SetMinSize(newWinSize)
|
self.SetMinSize(newWinSize); self.SetSize(wx.DefaultCoord, wx.DefaultCoord, *newWinSize);
|
||||||
self.SetSize(wx.DefaultCoord, wx.DefaultCoord, *newWinSize)
|
|
||||||
curWindow = self
|
curWindow = self
|
||||||
while curWindow != None:
|
while curWindow != None:
|
||||||
curWindow.Layout()
|
curWindow.Layout(); curWindow = curWindow.GetParent();
|
||||||
curWindow = curWindow.GetParent()
|
|
||||||
|
|
||||||
self.canvasBackend.resize(newCanvasSize, self.canvasBackend.cellSize)
|
self.canvasBackend.resize(newCanvasSize, self.canvasBackend.cellSize)
|
||||||
eventDc = self.canvasBackend.getDeviceContext(self)
|
eventDc = self.canvasBackend.getDeviceContext(self)
|
||||||
self.canvasJournal.resetCursor(); self.canvasJournal.resetUndo();
|
self.canvasJournal.resetCursor()
|
||||||
|
|
||||||
|
if commitUndo:
|
||||||
|
undoPatches, redoPatches = ["resize", *oldCanvasSize], ["resize", *newCanvasSize]
|
||||||
|
if not self._canvasDirty:
|
||||||
|
self.canvasJournal.pushDeltas([], []); self._canvasDirty = True;
|
||||||
|
self.canvasJournal.updateCurrentDeltas(undoPatches, redoPatches)
|
||||||
|
|
||||||
if deltaCanvasSize[0] < 0:
|
if deltaCanvasSize[0] < 0:
|
||||||
for numRow in range(oldCanvasSize[1]):
|
for numRow in range(oldCanvasSize[1]):
|
||||||
|
if commitUndo:
|
||||||
|
for numCol in range((oldCanvasSize[0] + deltaCanvasSize[0]), oldCanvasSize[0]):
|
||||||
|
if not self._canvasDirty:
|
||||||
|
self.canvasJournal.pushDeltas([], []); self._canvasDirty = True;
|
||||||
|
self.canvasJournal.updateCurrentDeltas([numCol, numRow, *self.canvasMap[numRow][numCol]], [numCol, numRow, 1, 1, 0, " "])
|
||||||
del self.canvasMap[numRow][-1:(deltaCanvasSize[0]-1):-1]
|
del self.canvasMap[numRow][-1:(deltaCanvasSize[0]-1):-1]
|
||||||
else:
|
else:
|
||||||
for numRow in range(oldCanvasSize[1]):
|
for numRow in range(oldCanvasSize[1]):
|
||||||
self.canvasMap[numRow].extend( \
|
self.canvasMap[numRow].extend([[1, 1, 0, " "]] * deltaCanvasSize[0])
|
||||||
[[1, 1, 0, " "]] * deltaCanvasSize[0])
|
|
||||||
for numNewCol in range(oldCanvasSize[0], newCanvasSize[0]):
|
for numNewCol in range(oldCanvasSize[0], newCanvasSize[0]):
|
||||||
self.canvasBackend.drawPatch( \
|
self._dispatchPatch(eventDc, False, [numNewCol, numRow, 1, 1, 0, " "], commitUndo)
|
||||||
eventDc, [numNewCol, numRow, \
|
|
||||||
*self.canvasMap[numRow][-1]])
|
|
||||||
if deltaCanvasSize[1] < 0:
|
if deltaCanvasSize[1] < 0:
|
||||||
|
if commitUndo:
|
||||||
|
for numRow in range((oldCanvasSize[1] + deltaCanvasSize[1]), oldCanvasSize[1]):
|
||||||
|
for numCol in range(oldCanvasSize[0] + deltaCanvasSize[0]):
|
||||||
|
if not self._canvasDirty:
|
||||||
|
self.canvasJournal.pushDeltas([], []); self._canvasDirty = True;
|
||||||
|
self.canvasJournal.updateCurrentDeltas([numCol, numRow, *self.canvasMap[numRow][numCol]], [numCol, numRow, 1, 1, 0, " "])
|
||||||
del self.canvasMap[-1:(deltaCanvasSize[1]-1):-1]
|
del self.canvasMap[-1:(deltaCanvasSize[1]-1):-1]
|
||||||
else:
|
else:
|
||||||
for numNewRow in range(oldCanvasSize[1], newCanvasSize[1]):
|
for numNewRow in range(oldCanvasSize[1], newCanvasSize[1]):
|
||||||
self.canvasMap.extend( \
|
self.canvasMap.extend([[[1, 1, 0, " "]] * newCanvasSize[0]])
|
||||||
[[[1, 1, 0, " "]] * newCanvasSize[0]])
|
|
||||||
for numNewCol in range(newCanvasSize[0]):
|
for numNewCol in range(newCanvasSize[0]):
|
||||||
self.canvasBackend.drawPatch( \
|
self._dispatchPatch(eventDc, False, [numNewCol, numNewRow, 1, 1, 0, " "], commitUndo)
|
||||||
eventDc, [numNewCol, numNewRow, \
|
|
||||||
*self.canvasMap[-1][-1]])
|
|
||||||
|
|
||||||
self.canvasSize = newCanvasSize
|
self.canvasSize = newCanvasSize; wx.SafeYield(); self.parentFrame.onCanvasUpdate(size=newCanvasSize, undoLevel=self.canvasJournal.patchesUndoLevel)
|
||||||
wx.SafeYield()
|
|
||||||
self.parentFrame.onCanvasUpdate(size=newCanvasSize, undoLevel=-1)
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
# {{{ __del__(self): destructor method
|
# {{{ __del__(self): destructor method
|
||||||
@ -169,8 +174,10 @@ class Canvas(wx.Panel):
|
|||||||
super().__init__(parent, pos=defaultCanvasPos, size=[w * h for w, h in zip(defaultCanvasSize, defaultCellSize)])
|
super().__init__(parent, pos=defaultCanvasPos, size=[w * h for w, h in zip(defaultCanvasSize, defaultCellSize)])
|
||||||
|
|
||||||
self.brushColours, self.brushPos, self.brushSize = [4, 1], [0, 0], [1, 1]
|
self.brushColours, self.brushPos, self.brushSize = [4, 1], [0, 0], [1, 1]
|
||||||
|
self._canvasDirty, self._canvasDirtyCursor = False, False
|
||||||
self.canvasMap, self.canvasPos, self.canvasSize, = None, defaultCanvasPos, defaultCanvasSize
|
self.canvasMap, self.canvasPos, self.canvasSize, = None, defaultCanvasPos, defaultCanvasSize
|
||||||
self.defaultCanvasPos, self.defaultCanvasSize, self.defaultCellSize = defaultCanvasPos, defaultCanvasSize, defaultCellSize
|
self.defaultCanvasPos, self.defaultCanvasSize, self.defaultCellSize = defaultCanvasPos, defaultCanvasSize, defaultCellSize
|
||||||
|
self.imgurApiKey = ImgurApiKey.imgurApiKey
|
||||||
self.parentFrame = parentFrame
|
self.parentFrame = parentFrame
|
||||||
self.parentFrame.onCanvasUpdate(brushSize=self.brushSize, colours=self.brushColours)
|
self.parentFrame.onCanvasUpdate(brushSize=self.brushSize, colours=self.brushColours)
|
||||||
|
|
||||||
@ -189,4 +196,4 @@ class Canvas(wx.Panel):
|
|||||||
self.Bind(eventType, self.onPanelInput)
|
self.Bind(eventType, self.onPanelInput)
|
||||||
self.Bind(wx.EVT_PAINT, self.onPanelPaint)
|
self.Bind(wx.EVT_PAINT, self.onPanelPaint)
|
||||||
|
|
||||||
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=0
|
||||||
|
@ -9,9 +9,6 @@ import wx
|
|||||||
|
|
||||||
class CanvasBackend():
|
class CanvasBackend():
|
||||||
"""XXX"""
|
"""XXX"""
|
||||||
_font = _brushes = _pens = None
|
|
||||||
_lastBrush = _lastPen = None
|
|
||||||
canvasBitmap = cellSize = None
|
|
||||||
|
|
||||||
# {{{ _drawBrushPatch(self, eventDc, patch): XXX
|
# {{{ _drawBrushPatch(self, eventDc, patch): XXX
|
||||||
def _drawBrushPatch(self, eventDc, patch):
|
def _drawBrushPatch(self, eventDc, patch):
|
||||||
@ -76,6 +73,11 @@ class CanvasBackend():
|
|||||||
return [a * b for a, b in zip(patch[0:2], self.cellSize)]
|
return [a * b for a, b in zip(patch[0:2], self.cellSize)]
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
# {{{ drawCursorMaskWithJournal(self, canvasJournal, eventDc): XXX
|
||||||
|
def drawCursorMaskWithJournal(self, canvasJournal, eventDc):
|
||||||
|
for patch in canvasJournal.popCursor():
|
||||||
|
self.drawPatch(eventDc, patch)
|
||||||
|
# }}}
|
||||||
# {{{ drawPatch(self, eventDc, patch): XXX
|
# {{{ drawPatch(self, eventDc, patch): XXX
|
||||||
def drawPatch(self, eventDc, patch):
|
def drawPatch(self, eventDc, patch):
|
||||||
if patch[0] < self.canvasSize[0] \
|
if patch[0] < self.canvasSize[0] \
|
||||||
@ -90,15 +92,9 @@ class CanvasBackend():
|
|||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ drawCursorMaskWithJournal(self, canvasJournal, eventDc): XXX
|
|
||||||
def drawCursorMaskWithJournal(self, canvasJournal, eventDc):
|
|
||||||
for patch in canvasJournal.popCursor():
|
|
||||||
self.drawPatch(eventDc, patch)
|
|
||||||
# }}}
|
|
||||||
# {{{ getDeviceContext(self, parentWindow): XXX
|
# {{{ getDeviceContext(self, parentWindow): XXX
|
||||||
def getDeviceContext(self, parentWindow):
|
def getDeviceContext(self, parentWindow):
|
||||||
eventDc = wx.BufferedDC( \
|
eventDc = wx.BufferedDC(wx.ClientDC(parentWindow), self.canvasBitmap)
|
||||||
wx.ClientDC(parentWindow), self.canvasBitmap)
|
|
||||||
self._lastBrushBg = self._lastBrushFg = self._lastPen = None;
|
self._lastBrushBg = self._lastBrushFg = self._lastPen = None;
|
||||||
return eventDc
|
return eventDc
|
||||||
# }}}
|
# }}}
|
||||||
@ -151,6 +147,8 @@ class CanvasBackend():
|
|||||||
#
|
#
|
||||||
# __init__(self, canvasSize, cellSize): initialisation method
|
# __init__(self, canvasSize, cellSize): initialisation method
|
||||||
def __init__(self, canvasSize, cellSize):
|
def __init__(self, canvasSize, cellSize):
|
||||||
|
self._brushes, self._font, self._lastBrush, self._lastPen, self._pens = None, None, None, None, None
|
||||||
|
self.canvasBitmap, self.cellSize = None, None
|
||||||
self._initBrushesAndPens()
|
self._initBrushesAndPens()
|
||||||
self.reset(canvasSize, cellSize)
|
self.reset(canvasSize, cellSize)
|
||||||
|
|
||||||
|
@ -20,7 +20,8 @@ except ImportError:
|
|||||||
|
|
||||||
class CanvasExportStore():
|
class CanvasExportStore():
|
||||||
"""XXX"""
|
"""XXX"""
|
||||||
parentCanvas = None
|
ImgurUploadUrl = "https://api.imgur.com/3/upload.json"
|
||||||
|
PastebinPostUrl = "https://pastebin.com/api/api_post.php"
|
||||||
|
|
||||||
# {{{ _exportFileToImgur(self, apiKey, imgName, imgTitle, pathName): upload single PNG file to Imgur
|
# {{{ _exportFileToImgur(self, apiKey, imgName, imgTitle, pathName): upload single PNG file to Imgur
|
||||||
def _exportFileToImgur(self, apiKey, imgName, imgTitle, pathName):
|
def _exportFileToImgur(self, apiKey, imgName, imgTitle, pathName):
|
||||||
@ -33,9 +34,7 @@ class CanvasExportStore():
|
|||||||
"title": imgTitle, \
|
"title": imgTitle, \
|
||||||
"type": "base64"}
|
"type": "base64"}
|
||||||
requestHeaders = {"Authorization": "Client-ID " + apiKey}
|
requestHeaders = {"Authorization": "Client-ID " + apiKey}
|
||||||
responseHttp = requests.post( \
|
responseHttp = requests.post(ImgurUploadUrl, data=requestData, headers=requestHeaders)
|
||||||
"https://api.imgur.com/3/upload.json", \
|
|
||||||
data=requestData, headers=requestHeaders)
|
|
||||||
responseDict = json.loads(responseHttp.text)
|
responseDict = json.loads(responseHttp.text)
|
||||||
if responseHttp.status_code == 200:
|
if responseHttp.status_code == 200:
|
||||||
return [200, responseDict.get("data").get("link")]
|
return [200, responseDict.get("data").get("link")]
|
||||||
@ -43,10 +42,6 @@ class CanvasExportStore():
|
|||||||
return [responseHttp.status_code, ""]
|
return [responseHttp.status_code, ""]
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
# {{{ exportBitmapToPngFile(self, canvasBitmap, outPathName, outType): XXX
|
|
||||||
def exportBitmapToPngFile(self, canvasBitmap, outPathName, outType):
|
|
||||||
return canvasBitmap.ConvertToImage().SaveFile(outPathName, outType)
|
|
||||||
# }}}
|
|
||||||
# {{{ exportBitmapToImgur(self, apiKey, canvasBitmap, imgName, imgTitle, imgType): XXX
|
# {{{ exportBitmapToImgur(self, apiKey, canvasBitmap, imgName, imgTitle, imgType): XXX
|
||||||
def exportBitmapToImgur(self, apiKey, canvasBitmap, imgName, imgTitle, imgType):
|
def exportBitmapToImgur(self, apiKey, canvasBitmap, imgName, imgTitle, imgType):
|
||||||
tmpPathName = tempfile.mkstemp()
|
tmpPathName = tempfile.mkstemp()
|
||||||
@ -56,6 +51,10 @@ class CanvasExportStore():
|
|||||||
os.remove(tmpPathName[1])
|
os.remove(tmpPathName[1])
|
||||||
return imgurResult
|
return imgurResult
|
||||||
# }}}
|
# }}}
|
||||||
|
# {{{ exportBitmapToPngFile(self, canvasBitmap, outPathName, outType): XXX
|
||||||
|
def exportBitmapToPngFile(self, canvasBitmap, outPathName, outType):
|
||||||
|
return canvasBitmap.ConvertToImage().SaveFile(outPathName, outType)
|
||||||
|
# }}}
|
||||||
# {{{ exportPastebin(self, apiDevKey, canvasMap, canvasSize, pasteName="", pastePrivate=0): XXX
|
# {{{ exportPastebin(self, apiDevKey, canvasMap, canvasSize, pasteName="", pastePrivate=0): XXX
|
||||||
def exportPastebin(self, apiDevKey, canvasMap, canvasSize, pasteName="", pastePrivate=0):
|
def exportPastebin(self, apiDevKey, canvasMap, canvasSize, pasteName="", pastePrivate=0):
|
||||||
if haveUrllib:
|
if haveUrllib:
|
||||||
@ -67,8 +66,7 @@ class CanvasExportStore():
|
|||||||
"api_paste_code": outFile.getvalue().encode(), \
|
"api_paste_code": outFile.getvalue().encode(), \
|
||||||
"api_paste_name": pasteName, \
|
"api_paste_name": pasteName, \
|
||||||
"api_paste_private": pastePrivate}
|
"api_paste_private": pastePrivate}
|
||||||
responseHttp = requests.post("https://pastebin.com/api/api_post.php", \
|
responseHttp = requests.post(PastebinPostUrl, data=requestData)
|
||||||
data=requestData)
|
|
||||||
if responseHttp.status_code == 200:
|
if responseHttp.status_code == 200:
|
||||||
if responseHttp.text.startswith("http"):
|
if responseHttp.text.startswith("http"):
|
||||||
return (True, responseHttp.text)
|
return (True, responseHttp.text)
|
||||||
@ -91,33 +89,32 @@ class CanvasExportStore():
|
|||||||
def exportTextBuffer(self, canvasMap, canvasSize):
|
def exportTextBuffer(self, canvasMap, canvasSize):
|
||||||
outBuffer = ""
|
outBuffer = ""
|
||||||
for canvasRow in range(canvasSize[1]):
|
for canvasRow in range(canvasSize[1]):
|
||||||
canvasLastColours = []
|
canvasLastColours = [15, 1]
|
||||||
for canvasCol in range(canvasSize[0]):
|
for canvasCol in range(canvasSize[0]):
|
||||||
canvasColColours = canvasMap[canvasRow][canvasCol][0:2]
|
canvasColColours = canvasMap[canvasRow][canvasCol][0:2]
|
||||||
canvasColText = canvasMap[canvasRow][canvasCol][3]
|
canvasColText = canvasMap[canvasRow][canvasCol][3]
|
||||||
if canvasColColours != canvasLastColours:
|
if canvasColColours[0] != canvasLastColours[0] \
|
||||||
|
and canvasColColours[1] != canvasLastColours[1]:
|
||||||
|
if canvasColColours[0] == canvasLastColours[1] \
|
||||||
|
and canvasColColours[1] == canvasLastColours[0]:
|
||||||
|
outBuffer += "\u0016"
|
||||||
|
else:
|
||||||
|
outBuffer += "\u0003{},{}".format(canvasColColours[0], canvasColColours[1])
|
||||||
canvasLastColours = canvasColColours
|
canvasLastColours = canvasColColours
|
||||||
outBuffer += "\x03" + \
|
elif canvasColColours[1] != canvasLastColours[1]:
|
||||||
str(canvasColColours[0]) + \
|
outBuffer += "\u0003{},{}".format(canvasLastColours[0], canvasColColours[1])
|
||||||
"," + str(canvasColColours[1])
|
canvasLastColours[1] = canvasColColours[1]
|
||||||
|
elif canvasColColours[0] != canvasLastColours[0]:
|
||||||
|
outBuffer += "\u0003{}".format(canvasColColours[0])
|
||||||
|
canvasLastColours[0] = canvasColColours[0]
|
||||||
outBuffer += canvasColText
|
outBuffer += canvasColText
|
||||||
outBuffer += "\n"
|
outBuffer += "\n"
|
||||||
return outBuffer
|
return outBuffer
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ exportTextFile(self, canvasMap, canvasSize, outFile): XXX
|
# {{{ exportTextFile(self, canvasMap, canvasSize, outFile): XXX
|
||||||
def exportTextFile(self, canvasMap, canvasSize, outFile):
|
def exportTextFile(self, canvasMap, canvasSize, outFile):
|
||||||
for canvasRow in range(canvasSize[1]):
|
outBuffer = self.exportTextBuffer(canvasMap, canvasSize)
|
||||||
canvasLastColours = []
|
outFile.write(outBuffer)
|
||||||
for canvasCol in range(canvasSize[0]):
|
|
||||||
canvasColColours = canvasMap[canvasRow][canvasCol][0:2]
|
|
||||||
canvasColText = canvasMap[canvasRow][canvasCol][3]
|
|
||||||
if canvasColColours != canvasLastColours:
|
|
||||||
canvasLastColours = canvasColColours
|
|
||||||
outFile.write("\x03" + \
|
|
||||||
str(canvasColColours[0]) + \
|
|
||||||
"," + str(canvasColColours[1]))
|
|
||||||
outFile.write(canvasColText)
|
|
||||||
outFile.write("\n")
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -25,10 +25,7 @@ class CanvasImportStore():
|
|||||||
|
|
||||||
# {{{ _flipCellStateBit(self, cellState, bit): XXX
|
# {{{ _flipCellStateBit(self, cellState, bit): XXX
|
||||||
def _flipCellStateBit(self, cellState, bit):
|
def _flipCellStateBit(self, cellState, bit):
|
||||||
if cellState & bit:
|
return cellState & ~bit if cellState & bit else cellState | bit
|
||||||
return cellState & ~bit
|
|
||||||
else:
|
|
||||||
return cellState | bit
|
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ _parseCharAsColourSpec(self, colourSpec, curColours): XXX
|
# {{{ _parseCharAsColourSpec(self, colourSpec, curColours): XXX
|
||||||
def _parseCharAsColourSpec(self, colourSpec, curColours):
|
def _parseCharAsColourSpec(self, colourSpec, curColours):
|
||||||
@ -36,8 +33,7 @@ class CanvasImportStore():
|
|||||||
colourSpec = colourSpec.split(",")
|
colourSpec = colourSpec.split(",")
|
||||||
if len(colourSpec) == 2 \
|
if len(colourSpec) == 2 \
|
||||||
and len(colourSpec[1]) > 0:
|
and len(colourSpec[1]) > 0:
|
||||||
return (int(colourSpec[0] or curColours[0]), \
|
return (int(colourSpec[0] or curColours[0]), int(colourSpec[1]))
|
||||||
int(colourSpec[1]))
|
|
||||||
elif len(colourSpec) == 1 \
|
elif len(colourSpec) == 1 \
|
||||||
or len(colourSpec[1]) == 0:
|
or len(colourSpec[1]) == 0:
|
||||||
return (int(colourSpec[0]), curColours[1])
|
return (int(colourSpec[0]), curColours[1])
|
||||||
@ -49,6 +45,13 @@ class CanvasImportStore():
|
|||||||
def importIntoPanel(self):
|
def importIntoPanel(self):
|
||||||
self.parentCanvas.onStoreUpdate(self.inSize, self.outMap)
|
self.parentCanvas.onStoreUpdate(self.inSize, self.outMap)
|
||||||
# }}}
|
# }}}
|
||||||
|
# {{{ importNew(self, newCanvasSize=None): XXX
|
||||||
|
def importNew(self, newCanvasSize=None):
|
||||||
|
newMap = [[[1, 1, 0, " "] \
|
||||||
|
for x in range(newCanvasSize[0])] \
|
||||||
|
for y in range(newCanvasSize[1])]
|
||||||
|
self.parentCanvas.onStoreUpdate(newCanvasSize, newMap)
|
||||||
|
# }}}
|
||||||
# {{{ importTextFile(self, pathName): XXX
|
# {{{ importTextFile(self, pathName): XXX
|
||||||
def importTextFile(self, pathName):
|
def importTextFile(self, pathName):
|
||||||
return self.importTextFileBuffer(open(pathName, "r", encoding="utf-8-sig"))
|
return self.importTextFileBuffer(open(pathName, "r", encoding="utf-8-sig"))
|
||||||
@ -127,13 +130,6 @@ class CanvasImportStore():
|
|||||||
inSize[0] = inMaxCols; self.inSize, self.outMap = inSize, outMap;
|
inSize[0] = inMaxCols; self.inSize, self.outMap = inSize, outMap;
|
||||||
inFile.close()
|
inFile.close()
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ importNew(self, newCanvasSize=None): XXX
|
|
||||||
def importNew(self, newCanvasSize=None):
|
|
||||||
newMap = [[[1, 1, 0, " "] \
|
|
||||||
for x in range(newCanvasSize[0])] \
|
|
||||||
for y in range(newCanvasSize[1])]
|
|
||||||
self.parentCanvas.onStoreUpdate(newCanvasSize, newMap)
|
|
||||||
# }}}
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# __init__(self, inFile=None, parentCanvas=None): initialisation method
|
# __init__(self, inFile=None, parentCanvas=None): initialisation method
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
class CanvasJournal():
|
class CanvasJournal():
|
||||||
"""XXX"""
|
"""XXX"""
|
||||||
patchesCursor = patchesUndo = patchesUndoLevel = None
|
|
||||||
|
|
||||||
# {{{ popCursor(self): XXX
|
# {{{ popCursor(self): XXX
|
||||||
def popCursor(self):
|
def popCursor(self):
|
||||||
@ -74,6 +73,7 @@ class CanvasJournal():
|
|||||||
#
|
#
|
||||||
# __init__(self): initialisation method
|
# __init__(self): initialisation method
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.patchesCursor, self.patchesUndo, self. patchesUndoLevel = None, None, None
|
||||||
self.resetCursor(); self.resetUndo();
|
self.resetCursor(); self.resetUndo();
|
||||||
|
|
||||||
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
||||||
|
Loading…
Reference in New Issue
Block a user