mirror of
https://github.com/lalbornoz/roar.git
synced 2024-11-22 07:16:38 +00:00
Initial canvas panel scrollbar implementation.
assets/text/TODO: updated. libgui/GuiCanvasPanel.py:__init__(): provide self.winSize & call SetScrollRate(). libgui/GuiCanvasPanel.py:{_drawPatch,dispatch{DeltaPatches,Patch},onPanel{Input,LeaveWindow},resize,update}(): receive and/or pass viewRect. libgui/GuiCanvasPanel.py:onPanelPaint(): updated. libgui/GuiCanvasPanel.py:resize(): call SetVirtualSize(). libgui/GuiCanvasWxBackend.py:_{draw{Brush,Char}Patch,_get{Brush,Char}PatchColours,xlatePoint}(): updated. libgui/GuiCanvasWxBackend.py:{draw{CursorMaskWithJournal,Patch},getDeviceContext,xlateEventPoint}(): receive and/or pass viewRect. libgui/GuiCanvasWxBackend.py:getDeviceContext(): return ClientDC() if viewRect > (0, 0) libgui/GuiCanvasWxBackend.py:onPanelPaintEvent(): blit subset of canvasBitmap into BufferedPaintDC() if viewRect > (0, 0). libtools/Tool{,Circle,Fill,Line,Rect,Select{,Clone,Move},Text}.py: receive & pass viewRect to dispatchFn().
This commit is contained in:
parent
e54429e29e
commit
88d69cb31e
@ -5,7 +5,7 @@
|
||||
5) Client-Server or Peer-to-Peer realtime collaboration
|
||||
6) Arbitrary {format,palette}s ({4,8} bit ANSI/mIRC, etc.)
|
||||
7) Hotkey & graphical interfaces to {composed,parametrised} tools
|
||||
8) GUI: a) scrollbar b) {de,in}crease cell size c) revisit About dialogue d) Settings panel e) switch from wxPython to GTK
|
||||
8) GUI: a) {de,in}crease cell size b) revisit About dialogue c) Settings panel d) switch from wxPython to GTK
|
||||
9) Layers, layout (e.g. for comics, zines, etc.) & asset management (e.g. kade, lion, etc.) & traits w/ {inserting,merging,linking}
|
||||
10) Sprites & scripted (Python?) animation on the basis of asset traits and {composable,parametrised} patterns (metric flow, particle system, rigging, ...)
|
||||
11) Composition and parametrisation of tools from higher-order operators (brushes, filters, outlines, patterns & shaders) and unit tools; unit tools:
|
||||
|
@ -6,54 +6,56 @@
|
||||
|
||||
import wx
|
||||
|
||||
class GuiCanvasPanel(wx.Panel):
|
||||
# {{{ _drawPatch(self, eventDc, isCursor, patch)
|
||||
def _drawPatch(self, eventDc, isCursor, patch):
|
||||
class GuiCanvasPanel(wx.ScrolledWindow):
|
||||
# {{{ _drawPatch(self, eventDc, isCursor, patch, viewRect)
|
||||
def _drawPatch(self, eventDc, isCursor, patch, viewRect):
|
||||
if not self.canvas.dirtyCursor:
|
||||
self.backend.drawCursorMaskWithJournal(self.canvas.journal, eventDc)
|
||||
self.backend.drawCursorMaskWithJournal(self.canvas.journal, eventDc, viewRect)
|
||||
self.canvas.dirtyCursor = True
|
||||
if self.backend.drawPatch(eventDc, patch) \
|
||||
and isCursor:
|
||||
if self.backend.drawPatch(eventDc, patch, viewRect) and isCursor:
|
||||
patchDeltaCell = self.canvas.map[patch[1]][patch[0]]; patchDelta = [*patch[0:2], *patchDeltaCell];
|
||||
self.canvas.journal.pushCursor(patchDelta)
|
||||
# }}}
|
||||
|
||||
# {{{ dispatchDeltaPatches(self, deltaPatches)
|
||||
def dispatchDeltaPatches(self, deltaPatches):
|
||||
eventDc = self.backend.getDeviceContext(self)
|
||||
eventDc = self.backend.getDeviceContext(self, self.GetViewStart())
|
||||
for patch in deltaPatches:
|
||||
if patch == None:
|
||||
continue
|
||||
elif patch[0] == "resize":
|
||||
del eventDc; self.resize(patch[1:], False); eventDc = self.backend.getDeviceContext(self);
|
||||
del eventDc; self.resize(patch[1:], False); eventDc = self.backend.getDeviceContext(self, self.GetViewStart());
|
||||
else:
|
||||
self.canvas._commitPatch(patch); self.backend.drawPatch(eventDc, patch);
|
||||
self.canvas._commitPatch(patch); self.backend.drawPatch(eventDc, patch, self.GetViewStart());
|
||||
# }}}
|
||||
# {{{ dispatchPatch(self, eventDc, isCursor, patch)
|
||||
def dispatchPatch(self, eventDc, isCursor, patch):
|
||||
# {{{ dispatchPatch(self, eventDc, isCursor, patch, viewRect)
|
||||
def dispatchPatch(self, eventDc, isCursor, patch, viewRect):
|
||||
if self.canvas.dispatchPatch(isCursor, patch, False if isCursor else True):
|
||||
self._drawPatch(eventDc, isCursor, patch)
|
||||
self._drawPatch(eventDc, isCursor, patch, viewRect)
|
||||
# }}}
|
||||
# {{{ resize(self, newSize, commitUndo=True)
|
||||
def resize(self, newSize, commitUndo=True):
|
||||
oldSize = [0, 0] if self.canvas.map == None else self.canvas.size
|
||||
deltaSize = [b - a for a, b in zip(oldSize, newSize)]
|
||||
if self.canvas.resize(newSize, commitUndo):
|
||||
newWinSize = [a * b for a, b in zip(newSize, self.backend.cellSize)]
|
||||
self.SetMinSize(newWinSize); self.SetSize(wx.DefaultCoord, wx.DefaultCoord, *newWinSize);
|
||||
self.winSize = [a * b for a, b in zip(newSize, self.backend.cellSize)]
|
||||
self.SetMinSize(self.winSize)
|
||||
self.SetSize(wx.DefaultCoord, wx.DefaultCoord, *self.winSize)
|
||||
self.SetVirtualSize(self.winSize)
|
||||
curWindow = self
|
||||
while curWindow != None:
|
||||
curWindow.Layout(); curWindow = curWindow.GetParent();
|
||||
self.backend.resize(newSize, self.backend.cellSize)
|
||||
eventDc = self.backend.getDeviceContext(self)
|
||||
eventDc = self.backend.getDeviceContext(self, self.GetViewStart())
|
||||
viewRect = self.GetViewStart()
|
||||
if deltaSize[0] > 0:
|
||||
for numRow in range(oldSize[1]):
|
||||
for numNewCol in range(oldSize[0], newSize[0]):
|
||||
self._drawPatch(eventDc, False, [numNewCol, numRow, 1, 1, 0, " "])
|
||||
self._drawPatch(eventDc, False, [numNewCol, numRow, 1, 1, 0, " "], viewRect)
|
||||
if deltaSize[1] > 1:
|
||||
for numNewRow in range(oldSize[1], newSize[1]):
|
||||
for numNewCol in range(newSize[0]):
|
||||
self._drawPatch(eventDc, False, [numNewCol, numNewRow, 1, 1, 0, " "])
|
||||
self._drawPatch(eventDc, False, [numNewCol, numNewRow, 1, 1, 0, " "], viewRect)
|
||||
del eventDc; wx.SafeYield();
|
||||
self.interface.update(size=newSize, undoLevel=self.canvas.journal.patchesUndoLevel)
|
||||
# }}}
|
||||
@ -61,10 +63,10 @@ class GuiCanvasPanel(wx.Panel):
|
||||
def update(self, newSize, commitUndo=True, newCanvas=None):
|
||||
self.resize(newSize, commitUndo)
|
||||
self.canvas.update(newSize, newCanvas)
|
||||
eventDc = self.backend.getDeviceContext(self)
|
||||
eventDc = self.backend.getDeviceContext(self, self.GetViewStart())
|
||||
for numRow in range(newSize[1]):
|
||||
for numCol in range(newSize[0]):
|
||||
self.backend.drawPatch(eventDc, [numCol, numRow, *self.canvas.map[numRow][numCol]])
|
||||
self.backend.drawPatch(eventDc, [numCol, numRow, *self.canvas.map[numRow][numCol]], self.GetViewStart())
|
||||
wx.SafeYield()
|
||||
# }}}
|
||||
|
||||
@ -79,22 +81,18 @@ class GuiCanvasPanel(wx.Panel):
|
||||
# {{{ onPanelInput(self, event)
|
||||
def onPanelInput(self, event):
|
||||
self.canvas.dirtyJournal, self.canvas.dirtyCursor = False, False
|
||||
eventDc, eventType, tool = self.backend.getDeviceContext(self), event.GetEventType(), self.interface.currentTool
|
||||
eventType, tool, viewRect = event.GetEventType(), self.interface.currentTool, self.GetViewStart()
|
||||
eventDc = self.backend.getDeviceContext(self, self.GetViewStart())
|
||||
if eventType == wx.wxEVT_CHAR:
|
||||
mapPoint = self.brushPos
|
||||
doSkip = tool.onKeyboardEvent(event, mapPoint, self.brushColours, self.brushSize, chr(event.GetUnicodeKey()), self.dispatchPatch, eventDc)
|
||||
if doSkip:
|
||||
if tool.onKeyboardEvent(event, mapPoint, self.brushColours, self.brushSize, chr(event.GetUnicodeKey()), self.dispatchPatch, eventDc, viewRect):
|
||||
event.Skip(); return;
|
||||
else:
|
||||
mapPoint = self.backend.xlateEventPoint(event, eventDc)
|
||||
if mapPoint[0] >= self.canvas.size[0] \
|
||||
or mapPoint[1] >= self.canvas.size[1]:
|
||||
return
|
||||
mapPoint = self.backend.xlateEventPoint(event, eventDc, viewRect)
|
||||
if (mapPoint[0] < self.canvas.size[0]) \
|
||||
and (mapPoint[1] < self.canvas.size[1]):
|
||||
self.brushPos = mapPoint
|
||||
tool.onMouseEvent( \
|
||||
event, mapPoint, self.brushColours, self.brushSize, \
|
||||
event.Dragging(), event.LeftIsDown(), event.RightIsDown(), \
|
||||
self.dispatchPatch, eventDc)
|
||||
tool.onMouseEvent(event, self.brushPos, self.brushColours, self.brushSize, event.Dragging(), event.LeftIsDown(), event.RightIsDown(), self.dispatchPatch, eventDc, viewRect)
|
||||
if self.canvas.dirtyJournal:
|
||||
self.dirty = True
|
||||
self.interface.update(dirty=self.dirty, cellPos=self.brushPos, undoLevel=self.canvas.journal.patchesUndoLevel)
|
||||
@ -103,18 +101,19 @@ class GuiCanvasPanel(wx.Panel):
|
||||
# }}}
|
||||
# {{{ onPanelLeaveWindow(self, event)
|
||||
def onPanelLeaveWindow(self, event):
|
||||
eventDc = self.backend.getDeviceContext(self)
|
||||
self.backend.drawCursorMaskWithJournal(self.canvas.journal, eventDc)
|
||||
eventDc = self.backend.getDeviceContext(self, self.GetViewStart())
|
||||
self.backend.drawCursorMaskWithJournal(self.canvas.journal, eventDc, self.GetViewStart())
|
||||
# }}}
|
||||
# {{{ onPanelPaint(self, event)
|
||||
def onPanelPaint(self, event):
|
||||
self.backend.onPanelPaintEvent(event, self)
|
||||
self.backend.onPanelPaintEvent(self.canvas.size, self.defaultCellSize, self.GetClientSize(), self, self.GetViewStart())
|
||||
# }}}
|
||||
|
||||
#
|
||||
# __init__(self, parent, parentFrame, backend, canvas, defaultCanvasPos, defaultCanvasSize, defaultCellSize, interface): initialisation method
|
||||
def __init__(self, parent, parentFrame, backend, canvas, defaultCanvasPos, defaultCanvasSize, defaultCellSize, interface):
|
||||
super().__init__(parent, pos=defaultCanvasPos, size=[w * h for w, h in zip(defaultCanvasSize, defaultCellSize)])
|
||||
self.winSize = [w * h for w, h in zip(defaultCanvasSize, defaultCellSize)]
|
||||
super().__init__(parent, pos=defaultCanvasPos, size=self.winSize)
|
||||
self.backend, self.interface = backend(defaultCanvasSize, defaultCellSize), interface(self, parentFrame)
|
||||
self.brushColours, self.brushPos, self.brushSize = [4, 1], [0, 0], [1, 1]
|
||||
self.canvas, self.canvasPos, self.defaultCanvasPos, self.defaultCanvasSize, self.defaultCellSize = canvas, defaultCanvasPos, defaultCanvasPos, defaultCanvasSize, defaultCellSize
|
||||
@ -127,5 +126,6 @@ class GuiCanvasPanel(wx.Panel):
|
||||
for eventType in (wx.EVT_LEFT_DOWN, wx.EVT_MOTION, wx.EVT_RIGHT_DOWN):
|
||||
self.Bind(eventType, self.onPanelInput)
|
||||
self.Bind(wx.EVT_PAINT, self.onPanelPaint)
|
||||
self.SetScrollRate(*defaultCellSize); self.SetVirtualSize(self.winSize);
|
||||
|
||||
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
||||
|
@ -5,26 +5,26 @@
|
||||
#
|
||||
|
||||
from GuiCanvasColours import Colours
|
||||
import wx
|
||||
import math, wx
|
||||
|
||||
class GuiCanvasWxBackend():
|
||||
# {{{ _drawBrushPatch(self, eventDc, patch)
|
||||
def _drawBrushPatch(self, eventDc, patch):
|
||||
absPoint = self._xlatePoint(patch)
|
||||
# {{{ _drawBrushPatch(self, eventDc, patch, point)
|
||||
def _drawBrushPatch(self, eventDc, patch, point):
|
||||
absPoint = self._xlatePoint(point)
|
||||
brushBg, brushFg, pen = self._getBrushPatchColours(patch)
|
||||
self._setBrushDc(brushBg, brushFg, eventDc, pen)
|
||||
eventDc.DrawRectangle(*absPoint, *self.cellSize)
|
||||
# }}}
|
||||
# {{{ _drawCharPatch(self, eventDc, patch)
|
||||
def _drawCharPatch(self, eventDc, patch):
|
||||
absPoint, fontBitmap = self._xlatePoint(patch), wx.Bitmap(*self.cellSize)
|
||||
# {{{ _drawCharPatch(self, eventDc, patch, point)
|
||||
def _drawCharPatch(self, eventDc, patch, point):
|
||||
absPoint, fontBitmap = self._xlatePoint(point), wx.Bitmap(*self.cellSize)
|
||||
brushBg, brushFg, pen = self._getCharPatchColours(patch)
|
||||
fontDc = wx.MemoryDC(); fontDc.SelectObject(fontBitmap);
|
||||
fontDc.SetTextForeground(wx.Colour(Colours[patch[2]][:4]))
|
||||
fontDc.SetTextBackground(wx.Colour(Colours[patch[3]][:4]))
|
||||
fontDc.SetTextForeground(wx.Colour(Colours[patch[0]][:4]))
|
||||
fontDc.SetTextBackground(wx.Colour(Colours[patch[1]][:4]))
|
||||
fontDc.SetBrush(brushBg); fontDc.SetBackground(brushBg); fontDc.SetPen(pen);
|
||||
fontDc.SetFont(self._font)
|
||||
fontDc.DrawRectangle(0, 0, *self.cellSize); fontDc.DrawText(patch[5], 0, 0);
|
||||
fontDc.DrawRectangle(0, 0, *self.cellSize); fontDc.DrawText(patch[3], 0, 0);
|
||||
eventDc.Blit(*absPoint, *self.cellSize, fontDc, 0, 0)
|
||||
# }}}
|
||||
# {{{ _finiBrushesAndPens(self)
|
||||
@ -35,26 +35,26 @@ class GuiCanvasWxBackend():
|
||||
# }}}
|
||||
# {{{ _getBrushPatchColours(self, patch)
|
||||
def _getBrushPatchColours(self, patch):
|
||||
if (patch[2] != -1) and (patch[3] != -1):
|
||||
brushBg, brushFg, pen = self._brushes[patch[2]], self._brushes[patch[3]], self._pens[patch[3]]
|
||||
elif (patch[2] == -1) and (patch[3] == -1):
|
||||
if (patch[0] != -1) and (patch[1] != -1):
|
||||
brushBg, brushFg, pen = self._brushes[patch[0]], self._brushes[patch[1]], self._pens[patch[1]]
|
||||
elif (patch[0] == -1) and (patch[1] == -1):
|
||||
brushBg, brushFg, pen = self._brushes[1], self._brushes[1], self._pens[1]
|
||||
elif patch[2] == -1:
|
||||
brushBg, brushFg, pen = self._brushes[patch[3]], self._brushes[patch[3]], self._pens[patch[3]]
|
||||
elif patch[3] == -1:
|
||||
brushBg, brushFg, pen = self._brushes[1], self._brushes[patch[2]], self._pens[1]
|
||||
elif patch[0] == -1:
|
||||
brushBg, brushFg, pen = self._brushes[patch[1]], self._brushes[patch[1]], self._pens[patch[1]]
|
||||
elif patch[1] == -1:
|
||||
brushBg, brushFg, pen = self._brushes[1], self._brushes[patch[0]], self._pens[1]
|
||||
return (brushBg, brushFg, pen)
|
||||
# }}}
|
||||
# {{{ _getCharPatchColours(self, patch)
|
||||
def _getCharPatchColours(self, patch):
|
||||
if (patch[2] != -1) and (patch[3] != -1):
|
||||
brushBg, brushFg, pen = self._brushes[patch[3]], self._brushes[patch[2]], self._pens[patch[3]]
|
||||
elif (patch[2] == -1) and (patch[3] == -1):
|
||||
if (patch[0] != -1) and (patch[1] != -1):
|
||||
brushBg, brushFg, pen = self._brushes[patch[1]], self._brushes[patch[0]], self._pens[patch[1]]
|
||||
elif (patch[0] == -1) and (patch[1] == -1):
|
||||
brushBg, brushFg, pen = self._brushes[1], self._brushes[1], self._pens[1]
|
||||
elif patch[2] == -1:
|
||||
brushBg, brushFg, pen = self._brushes[patch[3]], self._brushes[patch[3]], self._pens[patch[3]]
|
||||
elif patch[3] == -1:
|
||||
brushBg, brushFg, pen = self._brushes[1], self._brushes[patch[2]], self._pens[1]
|
||||
elif patch[0] == -1:
|
||||
brushBg, brushFg, pen = self._brushes[patch[1]], self._brushes[patch[1]], self._pens[patch[1]]
|
||||
elif patch[1] == -1:
|
||||
brushBg, brushFg, pen = self._brushes[1], self._brushes[patch[0]], self._pens[1]
|
||||
return (brushBg, brushFg, pen)
|
||||
# }}}
|
||||
# {{{ _initBrushesAndPens(self)
|
||||
@ -74,34 +74,51 @@ class GuiCanvasWxBackend():
|
||||
if self._lastPen != pen:
|
||||
dc.SetPen(pen); self._lastPen = pen;
|
||||
# }}}
|
||||
# {{{ _xlatePoint(self, patch)
|
||||
def _xlatePoint(self, patch):
|
||||
return [a * b for a, b in zip(patch[:2], self.cellSize)]
|
||||
# {{{ _xlatePoint(self, point)
|
||||
def _xlatePoint(self, point):
|
||||
return [a * b for a, b in zip(point, self.cellSize)]
|
||||
# }}}
|
||||
|
||||
# {{{ drawCursorMaskWithJournal(self, canvasJournal, eventDc)
|
||||
def drawCursorMaskWithJournal(self, canvasJournal, eventDc):
|
||||
[self.drawPatch(eventDc, patch) for patch in canvasJournal.popCursor()]
|
||||
# {{{ drawCursorMaskWithJournal(self, canvasJournal, eventDc, viewRect)
|
||||
def drawCursorMaskWithJournal(self, canvasJournal, eventDc, viewRect):
|
||||
[self.drawPatch(eventDc, patch, viewRect) for patch in canvasJournal.popCursor()]
|
||||
# }}}
|
||||
# {{{ drawPatch(self, eventDc, patch)
|
||||
def drawPatch(self, eventDc, patch):
|
||||
if ((patch[0] >= 0) and (patch[0] < self.canvasSize[0])) \
|
||||
and ((patch[1] >= 0) and (patch[1] < self.canvasSize[1])):
|
||||
self._drawBrushPatch(eventDc, patch) if patch[5] == " " else self._drawCharPatch(eventDc, patch)
|
||||
# {{{ drawPatch(self, eventDc, patch, viewRect)
|
||||
def drawPatch(self, eventDc, patch, viewRect):
|
||||
point = [m - n for m, n in zip(patch[:2], viewRect)]
|
||||
if [(c >= 0) and (c < s) for c, s in zip(point, self.canvasSize)] == [True, True]:
|
||||
if patch[5] == " ":
|
||||
self._drawBrushPatch(eventDc, patch[2:], point)
|
||||
else:
|
||||
self._drawCharPatch(eventDc, patch[2:], point)
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
# }}}
|
||||
# {{{ getDeviceContext(self, parentWindow)
|
||||
def getDeviceContext(self, parentWindow):
|
||||
# {{{ getDeviceContext(self, parentWindow, viewRect)
|
||||
def getDeviceContext(self, parentWindow, viewRect):
|
||||
if viewRect == (0, 0):
|
||||
eventDc = wx.BufferedDC(wx.ClientDC(parentWindow), self.canvasBitmap)
|
||||
else:
|
||||
eventDc = wx.ClientDC(parentWindow)
|
||||
self._lastBrushBg, self._lastBrushFg, self._lastPen = None, None, None
|
||||
return eventDc
|
||||
# }}}
|
||||
# {{{ onPanelPaintEvent(self, panelEvent, panelWindow)
|
||||
def onPanelPaintEvent(self, panelEvent, panelWindow):
|
||||
# {{{ onPanelPaintEvent(self, canvasSize, cellSize, clientSize, panelWindow, viewRect)
|
||||
def onPanelPaintEvent(self, canvasSize, cellSize, clientSize, panelWindow, viewRect):
|
||||
if self.canvasBitmap != None:
|
||||
if viewRect == (0, 0):
|
||||
eventDc = wx.BufferedPaintDC(panelWindow, self.canvasBitmap)
|
||||
else:
|
||||
canvasSize = [a - b for a, b in zip(canvasSize, viewRect)]
|
||||
clientSize = [math.ceil(m / n) for m, n in zip(clientSize, cellSize)]
|
||||
viewSize = [min(m, n) for m, n in zip(canvasSize, clientSize)]
|
||||
viewSize = [m * n for m, n in zip(cellSize, viewSize)]
|
||||
canvasDc = wx.MemoryDC(); canvasDc.SelectObject(self.canvasBitmap);
|
||||
viewDc = wx.MemoryDC(); viewBitmap = wx.Bitmap(viewSize); viewDc.SelectObject(viewBitmap);
|
||||
viewDc.Blit(0, 0, *viewSize, canvasDc, *[m * n for m, n in zip(cellSize, viewRect)])
|
||||
canvasDc.SelectObject(wx.NullBitmap); viewDc.SelectObject(wx.NullBitmap);
|
||||
eventDc = wx.BufferedPaintDC(panelWindow, viewBitmap)
|
||||
# }}}
|
||||
# {{{ reset(self, canvasSize, cellSize):
|
||||
def reset(self, canvasSize, cellSize):
|
||||
@ -121,12 +138,12 @@ class GuiCanvasWxBackend():
|
||||
self.canvasSize, self.cellSize = canvasSize, cellSize
|
||||
self._font = wx.Font(8, wx.FONTFAMILY_TELETYPE, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)
|
||||
# }}}
|
||||
# {{{ xlateEventPoint(self, event, eventDc)
|
||||
def xlateEventPoint(self, event, eventDc):
|
||||
# {{{ xlateEventPoint(self, event, eventDc, viewRect)
|
||||
def xlateEventPoint(self, event, eventDc, viewRect):
|
||||
eventPoint = event.GetLogicalPosition(eventDc)
|
||||
rectX, rectY = eventPoint.x - (eventPoint.x % self.cellSize[0]), eventPoint.y - (eventPoint.y % self.cellSize[1])
|
||||
mapX, mapY = int(rectX / self.cellSize[0] if rectX else 0), int(rectY / self.cellSize[1] if rectY else 0)
|
||||
return (mapX, mapY)
|
||||
return [m + n for m, n in zip((mapX, mapY), viewRect)]
|
||||
# }}}
|
||||
|
||||
# {{{ __del__(self): destructor method
|
||||
|
@ -124,6 +124,10 @@ class GuiFrame(wx.Frame):
|
||||
def onInput(self, event):
|
||||
eventId = event.GetId(); self.itemsById[eventId](self.canvasPanel.interface, event);
|
||||
# }}}
|
||||
# {{{ onMouseWheel(self, event)
|
||||
def onMouseWheel(self, event):
|
||||
self.canvasPanel.GetEventHandler().ProcessEvent(event)
|
||||
# }}}
|
||||
|
||||
#
|
||||
# __init__(self, canvasInterface, parent, appSize=(840, 630), defaultCanvasPos=(0, 75), defaultCanvasSize=(100, 30), defaultCellSize=(7, 14)): initialisation method
|
||||
@ -157,6 +161,8 @@ class GuiFrame(wx.Frame):
|
||||
self.canvasPanel.interface.canvasTool(self.canvasPanel.interface.canvasTool, 5)(self.canvasPanel.interface, None)
|
||||
self.canvasPanel.interface.update(brushSize=self.canvasPanel.brushSize, colours=self.canvasPanel.brushColours)
|
||||
|
||||
self.Bind(wx.EVT_MOUSEWHEEL, self.onMouseWheel)
|
||||
|
||||
# Set focus on & show window
|
||||
self.SetFocus(); self.Show(True);
|
||||
|
||||
|
@ -7,12 +7,12 @@
|
||||
class Tool():
|
||||
parentCanvas = None
|
||||
|
||||
# {{{ onKeyboardEvent(self, event, atPoint, brushColours, brushSize, keyChar, dispatchFn, eventDc):
|
||||
def onKeyboardEvent(self, event, atPoint, brushColours, brushSize, keyChar, dispatchFn, eventDc):
|
||||
# {{{ onKeyboardEvent(self, event, atPoint, brushColours, brushSize, keyChar, dispatchFn, eventDc, viewRect):
|
||||
def onKeyboardEvent(self, event, atPoint, brushColours, brushSize, keyChar, dispatchFn, eventDc, viewRect):
|
||||
return True
|
||||
# }}}
|
||||
# {{{ onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc)
|
||||
def onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc):
|
||||
# {{{ onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc, viewRect)
|
||||
def onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc, viewRect):
|
||||
return ()
|
||||
# }}}
|
||||
|
||||
|
@ -10,8 +10,8 @@ class ToolCircle(Tool):
|
||||
name = "Circle"
|
||||
|
||||
#
|
||||
# onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc)
|
||||
def onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc):
|
||||
# onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc, viewRect)
|
||||
def onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc, viewRect):
|
||||
brushColours = brushColours.copy()
|
||||
if isLeftDown:
|
||||
brushColours[1] = brushColours[0]
|
||||
@ -29,8 +29,8 @@ class ToolCircle(Tool):
|
||||
atPoint[1] + int(originPoint[1] + brushY), \
|
||||
*brushColours, 0, " "]
|
||||
if isLeftDown or isRightDown:
|
||||
dispatchFn(eventDc, False, patch); dispatchFn(eventDc, True, patch);
|
||||
dispatchFn(eventDc, False, patch, viewRect); dispatchFn(eventDc, True, patch, viewRect);
|
||||
else:
|
||||
dispatchFn(eventDc, True, patch)
|
||||
dispatchFn(eventDc, True, patch, viewRect)
|
||||
|
||||
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
||||
|
@ -10,8 +10,8 @@ class ToolFill(Tool):
|
||||
name = "Fill"
|
||||
|
||||
#
|
||||
# onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc)
|
||||
def onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc):
|
||||
# onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc, viewRect)
|
||||
def onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc, viewRect):
|
||||
pointStack, pointsDone = [list(atPoint)], []
|
||||
testColour = self.parentCanvas.canvas.map[atPoint[1]][atPoint[0]][0:2]
|
||||
if isLeftDown or isRightDown:
|
||||
@ -23,7 +23,7 @@ class ToolFill(Tool):
|
||||
if (pointCell[0:2] == testColour) \
|
||||
or ((pointCell[3] == " ") and (pointCell[1] == testColour[1])):
|
||||
if not point in pointsDone:
|
||||
dispatchFn(eventDc, False, [*point, brushColours[0], brushColours[0], 0, " "])
|
||||
dispatchFn(eventDc, False, [*point, brushColours[0], brushColours[0], 0, " "], viewRect)
|
||||
if point[0] > 0:
|
||||
pointStack.append([point[0] - 1, point[1]])
|
||||
if point[0] < (self.parentCanvas.canvas.size[0] - 1):
|
||||
|
@ -30,9 +30,9 @@ class ToolLine(Tool):
|
||||
originPoint[1] + lineX * lineXY + lineY * lineYY, \
|
||||
*brushColours, 0, " "]
|
||||
if isCursor:
|
||||
dispatchFn(eventDc, False, patch); dispatchFn(eventDc, True, patch);
|
||||
dispatchFn(eventDc, False, patch, viewRect); dispatchFn(eventDc, True, patch, viewRect);
|
||||
else:
|
||||
dispatchFn(eventDc, True, patch)
|
||||
dispatchFn(eventDc, True, patch, viewRect)
|
||||
if lineD > 0:
|
||||
lineD -= pointDelta[0]; lineY += 1;
|
||||
lineD += pointDelta[1]
|
||||
@ -47,8 +47,8 @@ class ToolLine(Tool):
|
||||
# }}}
|
||||
|
||||
#
|
||||
# onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc)
|
||||
def onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc):
|
||||
# onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc, viewRect)
|
||||
def onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc, viewRect):
|
||||
brushColours = brushColours.copy()
|
||||
if isLeftDown:
|
||||
brushColours[1] = brushColours[0]
|
||||
@ -59,7 +59,7 @@ class ToolLine(Tool):
|
||||
if self.toolState == self.TS_NONE:
|
||||
if isLeftDown or isRightDown:
|
||||
self.toolColours, self.toolOriginPoint, self.toolState = brushColours, list(atPoint), self.TS_ORIGIN
|
||||
dispatchFn(eventDc, True, [*atPoint, *brushColours, 0, " "])
|
||||
dispatchFn(eventDc, True, [*atPoint, *brushColours, 0, " "], viewRect)
|
||||
elif self.toolState == self.TS_ORIGIN:
|
||||
originPoint, targetPoint = self.toolOriginPoint, list(atPoint)
|
||||
self._getLine(self.toolColours, brushSize, dispatchFn, eventDc, isLeftDown or isRightDown, originPoint, targetPoint)
|
||||
|
@ -10,8 +10,8 @@ class ToolRect(Tool):
|
||||
name = "Rectangle"
|
||||
|
||||
#
|
||||
# onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc)
|
||||
def onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc):
|
||||
# onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc, viewRect)
|
||||
def onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc, viewRect):
|
||||
brushColours = brushColours.copy()
|
||||
if isLeftDown:
|
||||
brushColours[1] = brushColours[0]
|
||||
@ -26,8 +26,8 @@ class ToolRect(Tool):
|
||||
for brushCol in range(brushSize[0]):
|
||||
patch = [atPoint[0] + brushCol, atPoint[1] + brushRow, *brushColours, 0, " "]
|
||||
if isLeftDown or isRightDown:
|
||||
dispatchFn(eventDc, False, patch); dispatchFn(eventDc, True, patch);
|
||||
dispatchFn(eventDc, False, patch, viewRect); dispatchFn(eventDc, True, patch, viewRect);
|
||||
else:
|
||||
dispatchFn(eventDc, True, patch)
|
||||
dispatchFn(eventDc, True, patch, viewRect)
|
||||
|
||||
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
||||
|
@ -36,19 +36,19 @@ class ToolSelect(Tool):
|
||||
curColours = [0, 0]
|
||||
for rectX in range(rectFrame[0][0], rectFrame[1][0] + 1):
|
||||
curColours = [1, 1] if curColours == [0, 0] else [0, 0]
|
||||
dispatchFn(eventDc, True, [rectX, rectFrame[0][1], *curColours, 0, " "])
|
||||
dispatchFn(eventDc, True, [rectX, rectFrame[1][1], *curColours, 0, " "])
|
||||
dispatchFn(eventDc, True, [rectX, rectFrame[0][1], *curColours, 0, " "], viewRect)
|
||||
dispatchFn(eventDc, True, [rectX, rectFrame[1][1], *curColours, 0, " "], viewRect)
|
||||
for rectY in range(rectFrame[0][1], rectFrame[1][1] + 1):
|
||||
curColours = [1, 1] if curColours == [0, 0] else [0, 0]
|
||||
dispatchFn(eventDc, True, [rectFrame[0][0], rectY, *curColours, 0, " "])
|
||||
dispatchFn(eventDc, True, [rectFrame[1][0], rectY, *curColours, 0, " "])
|
||||
dispatchFn(eventDc, True, [rectFrame[0][0], rectY, *curColours, 0, " "], viewRect)
|
||||
dispatchFn(eventDc, True, [rectFrame[1][0], rectY, *curColours, 0, " "], viewRect)
|
||||
# }}}
|
||||
# {{{ _mouseEventTsNone(self, atPoint, brushColours, dispatchFn, eventDc, isDragging, isLeftDown, isRightDown)
|
||||
def _mouseEventTsNone(self, atPoint, brushColours, dispatchFn, eventDc, isDragging, isLeftDown, isRightDown):
|
||||
if isLeftDown:
|
||||
self.targetRect, self.toolState = [list(atPoint), []], self.TS_ORIGIN
|
||||
else:
|
||||
dispatchFn(eventDc, True, [*atPoint, *brushColours, 0, " "])
|
||||
dispatchFn(eventDc, True, [*atPoint, *brushColours, 0, " "], viewRect)
|
||||
# }}}
|
||||
# {{{ _mouseEventTsOrigin(self, atPoint, brushColours, dispatchFn, eventDc, isDragging, isLeftDown, isRightDown)
|
||||
def _mouseEventTsOrigin(self, atPoint, brushColours, dispatchFn, eventDc, isDragging, isLeftDown, isRightDown):
|
||||
@ -98,8 +98,8 @@ class ToolSelect(Tool):
|
||||
# }}}
|
||||
|
||||
#
|
||||
# onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc)
|
||||
def onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc):
|
||||
# onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc, viewRect)
|
||||
def onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc, viewRect):
|
||||
if self.toolState == self.TS_NONE:
|
||||
self._mouseEventTsNone(atPoint, brushColours, dispatchFn, eventDc, isDragging, isLeftDown, isRightDown)
|
||||
elif self.toolState == self.TS_ORIGIN:
|
||||
|
@ -16,6 +16,6 @@ class ToolSelectClone(ToolSelect):
|
||||
for numCol in range(len(self.toolSelectMap[numRow])):
|
||||
cellOld = self.toolSelectMap[numRow][numCol]
|
||||
rectX, rectY = selectRect[0][0] + numCol, selectRect[0][1] + numRow
|
||||
dispatchFn(eventDc, isCursor, [rectX + disp[0], rectY + disp[1], *cellOld])
|
||||
dispatchFn(eventDc, isCursor, [rectX + disp[0], rectY + disp[1], *cellOld], viewRect)
|
||||
|
||||
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
||||
|
@ -14,11 +14,11 @@ class ToolSelectMove(ToolSelect):
|
||||
def onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newToolRect, selectRect):
|
||||
for numRow in range(len(self.toolSelectMap)):
|
||||
for numCol in range(len(self.toolSelectMap[numRow])):
|
||||
dispatchFn(eventDc, isCursor, [self.srcRect[0] + numCol, self.srcRect[1] + numRow, 1, 1, 0, " "])
|
||||
dispatchFn(eventDc, isCursor, [self.srcRect[0] + numCol, self.srcRect[1] + numRow, 1, 1, 0, " "], viewRect)
|
||||
for numRow in range(len(self.toolSelectMap)):
|
||||
for numCol in range(len(self.toolSelectMap[numRow])):
|
||||
cellOld = self.toolSelectMap[numRow][numCol]
|
||||
rectX, rectY = selectRect[0][0] + numCol, selectRect[0][1] + numRow
|
||||
dispatchFn(eventDc, isCursor, [rectX + disp[0], rectY + disp[1], *cellOld])
|
||||
dispatchFn(eventDc, isCursor, [rectX + disp[0], rectY + disp[1], *cellOld], viewRect)
|
||||
|
||||
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
||||
|
@ -11,8 +11,8 @@ class ToolText(Tool):
|
||||
name = "Text"
|
||||
|
||||
#
|
||||
# onKeyboardEvent(self, event, atPoint, brushColours, brushSize, keyChar, dispatchFn, eventDc)
|
||||
def onKeyboardEvent(self, event, atPoint, brushColours, brushSize, keyChar, dispatchFn, eventDc):
|
||||
# onKeyboardEvent(self, event, atPoint, brushColours, brushSize, keyChar, dispatchFn, eventDc, viewRect)
|
||||
def onKeyboardEvent(self, event, atPoint, brushColours, brushSize, keyChar, dispatchFn, eventDc, viewRect):
|
||||
keyModifiers = event.GetModifiers()
|
||||
if keyModifiers != wx.MOD_NONE \
|
||||
and keyModifiers != wx.MOD_SHIFT:
|
||||
@ -20,7 +20,7 @@ class ToolText(Tool):
|
||||
else:
|
||||
if self.textPos == None:
|
||||
self.textPos = list(atPoint)
|
||||
dispatchFn(eventDc, False, [*self.textPos, *brushColours, 0, keyChar])
|
||||
dispatchFn(eventDc, False, [*self.textPos, *brushColours, 0, keyChar], viewRect)
|
||||
if self.textPos[0] < (self.parentCanvas.canvas.size[0] - 1):
|
||||
self.textPos[0] += 1
|
||||
elif self.textPos[1] < (self.parentCanvas.canvas.size[1] - 1):
|
||||
@ -30,11 +30,11 @@ class ToolText(Tool):
|
||||
return False
|
||||
|
||||
#
|
||||
# onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc)
|
||||
def onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc):
|
||||
# onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc, viewRect)
|
||||
def onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc, viewRect):
|
||||
if isLeftDown or isRightDown:
|
||||
self.textPos = list(atPoint)
|
||||
dispatchFn(eventDc, True, [*atPoint, *brushColours, 0, "_"])
|
||||
dispatchFn(eventDc, True, [*atPoint, *brushColours, 0, "_"], viewRect)
|
||||
|
||||
# __init__(self, *args): initialisation method
|
||||
def __init__(self, *args):
|
||||
|
Loading…
Reference in New Issue
Block a user