2019-09-01 10:34:00 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
#
|
2019-09-09 06:46:52 -04:00
|
|
|
# GuiCanvasWxBackend.py
|
2019-09-04 10:23:59 -04:00
|
|
|
# Copyright (c) 2018, 2019 Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de>
|
2019-09-01 10:34:00 -04:00
|
|
|
#
|
|
|
|
|
2019-09-07 04:39:26 -04:00
|
|
|
from GuiCanvasColours import Colours
|
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().
2019-09-09 06:30:25 -04:00
|
|
|
import math, wx
|
2019-09-01 10:34:00 -04:00
|
|
|
|
2019-09-07 04:39:26 -04:00
|
|
|
class GuiCanvasWxBackend():
|
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().
2019-09-09 06:30:25 -04:00
|
|
|
# {{{ _drawBrushPatch(self, eventDc, patch, point)
|
|
|
|
def _drawBrushPatch(self, eventDc, patch, point):
|
|
|
|
absPoint = self._xlatePoint(point)
|
2019-09-08 10:57:45 -04:00
|
|
|
brushBg, brushFg, pen = self._getBrushPatchColours(patch)
|
2019-09-01 10:34:00 -04:00
|
|
|
self._setBrushDc(brushBg, brushFg, eventDc, pen)
|
|
|
|
eventDc.DrawRectangle(*absPoint, *self.cellSize)
|
|
|
|
# }}}
|
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().
2019-09-09 06:30:25 -04:00
|
|
|
# {{{ _drawCharPatch(self, eventDc, patch, point)
|
|
|
|
def _drawCharPatch(self, eventDc, patch, point):
|
|
|
|
absPoint, fontBitmap = self._xlatePoint(point), wx.Bitmap(*self.cellSize)
|
2019-09-08 10:57:45 -04:00
|
|
|
brushBg, brushFg, pen = self._getCharPatchColours(patch)
|
2019-09-01 10:34:00 -04:00
|
|
|
fontDc = wx.MemoryDC(); fontDc.SelectObject(fontBitmap);
|
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().
2019-09-09 06:30:25 -04:00
|
|
|
fontDc.SetTextForeground(wx.Colour(Colours[patch[0]][:4]))
|
|
|
|
fontDc.SetTextBackground(wx.Colour(Colours[patch[1]][:4]))
|
2019-09-01 10:34:00 -04:00
|
|
|
fontDc.SetBrush(brushBg); fontDc.SetBackground(brushBg); fontDc.SetPen(pen);
|
|
|
|
fontDc.SetFont(self._font)
|
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().
2019-09-09 06:30:25 -04:00
|
|
|
fontDc.DrawRectangle(0, 0, *self.cellSize); fontDc.DrawText(patch[3], 0, 0);
|
2019-09-01 10:34:00 -04:00
|
|
|
eventDc.Blit(*absPoint, *self.cellSize, fontDc, 0, 0)
|
|
|
|
# }}}
|
2019-09-08 12:08:04 -04:00
|
|
|
# {{{ _finiBrushesAndPens(self)
|
2019-09-01 10:34:00 -04:00
|
|
|
def _finiBrushesAndPens(self):
|
2019-09-06 04:29:45 -04:00
|
|
|
[brush.Destroy() for brush in self._brushes or []]
|
|
|
|
[pen.Destroy() for pen in self._pens or []]
|
|
|
|
self._brushes, self._lastBrushBg, self._lastBrushFg, self._lastPen, self._pens = None, None, None, None, None
|
2019-09-01 10:34:00 -04:00
|
|
|
# }}}
|
2019-09-08 12:08:04 -04:00
|
|
|
# {{{ _getBrushPatchColours(self, patch)
|
2019-09-08 10:57:45 -04:00
|
|
|
def _getBrushPatchColours(self, patch):
|
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().
2019-09-09 06:30:25 -04:00
|
|
|
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):
|
2019-09-08 10:57:45 -04:00
|
|
|
brushBg, brushFg, pen = self._brushes[1], self._brushes[1], self._pens[1]
|
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().
2019-09-09 06:30:25 -04:00
|
|
|
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]
|
2019-09-08 10:57:45 -04:00
|
|
|
return (brushBg, brushFg, pen)
|
|
|
|
# }}}
|
2019-09-08 12:08:04 -04:00
|
|
|
# {{{ _getCharPatchColours(self, patch)
|
2019-09-08 10:57:45 -04:00
|
|
|
def _getCharPatchColours(self, patch):
|
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().
2019-09-09 06:30:25 -04:00
|
|
|
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):
|
2019-09-08 10:57:45 -04:00
|
|
|
brushBg, brushFg, pen = self._brushes[1], self._brushes[1], self._pens[1]
|
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().
2019-09-09 06:30:25 -04:00
|
|
|
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]
|
2019-09-08 10:57:45 -04:00
|
|
|
return (brushBg, brushFg, pen)
|
|
|
|
# }}}
|
2019-09-08 12:08:04 -04:00
|
|
|
# {{{ _initBrushesAndPens(self)
|
2019-09-01 10:34:00 -04:00
|
|
|
def _initBrushesAndPens(self):
|
2019-09-06 04:29:45 -04:00
|
|
|
self._brushes, self._pens = [None for x in range(len(Colours))], [None for x in range(len(Colours))]
|
2019-09-03 12:58:50 -04:00
|
|
|
for mircColour in range(len(Colours)):
|
2019-09-06 04:29:45 -04:00
|
|
|
self._brushes[mircColour] = wx.Brush(wx.Colour(Colours[mircColour][:4]), wx.BRUSHSTYLE_SOLID)
|
|
|
|
self._pens[mircColour] = wx.Pen(wx.Colour(Colours[mircColour][:4]), 1)
|
|
|
|
self._lastBrushBg, self._lastBrushFg, self._lastPen = None, None, None
|
2019-09-01 10:34:00 -04:00
|
|
|
# }}}
|
2019-09-08 12:08:04 -04:00
|
|
|
# {{{ _setBrushDc(self, brushBg, brushFg, dc, pen)
|
2019-09-01 10:34:00 -04:00
|
|
|
def _setBrushDc(self, brushBg, brushFg, dc, pen):
|
|
|
|
if self._lastBrushBg != brushBg:
|
2019-09-06 04:29:45 -04:00
|
|
|
dc.SetBackground(brushBg); self._lastBrushBg = brushBg;
|
2019-09-01 10:34:00 -04:00
|
|
|
if self._lastBrushFg != brushFg:
|
2019-09-06 04:29:45 -04:00
|
|
|
dc.SetBrush(brushFg); self._lastBrushFg = brushFg;
|
2019-09-01 10:34:00 -04:00
|
|
|
if self._lastPen != pen:
|
2019-09-06 04:29:45 -04:00
|
|
|
dc.SetPen(pen); self._lastPen = pen;
|
2019-09-01 10:34:00 -04: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().
2019-09-09 06:30:25 -04:00
|
|
|
# {{{ _xlatePoint(self, point)
|
|
|
|
def _xlatePoint(self, point):
|
|
|
|
return [a * b for a, b in zip(point, self.cellSize)]
|
2019-09-01 10:34:00 -04: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().
2019-09-09 06:30:25 -04:00
|
|
|
# {{{ 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, 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)
|
2019-09-01 10:34:00 -04:00
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
# }}}
|
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().
2019-09-09 06:30:25 -04:00
|
|
|
# {{{ 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)
|
2019-09-06 04:29:45 -04:00
|
|
|
self._lastBrushBg, self._lastBrushFg, self._lastPen = None, None, None
|
2019-09-01 10:34:00 -04:00
|
|
|
return eventDc
|
|
|
|
# }}}
|
2019-09-10 04:14:12 -04:00
|
|
|
# {{{ onPaintEvent(self, canvasSize, cellSize, clientSize, panelWindow, viewRect)
|
|
|
|
def onPaintEvent(self, canvasSize, cellSize, clientSize, panelWindow, viewRect):
|
2019-09-01 10:34:00 -04:00
|
|
|
if self.canvasBitmap != None:
|
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().
2019-09-09 06:30:25 -04:00
|
|
|
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)
|
2019-09-01 10:34:00 -04:00
|
|
|
# }}}
|
|
|
|
# {{{ resize(self, canvasSize, cellSize):
|
|
|
|
def resize(self, canvasSize, cellSize):
|
2019-09-03 12:58:50 -04:00
|
|
|
winSize = [a * b for a, b in zip(canvasSize, cellSize)]
|
2019-09-01 10:34:00 -04:00
|
|
|
if self.canvasBitmap == None:
|
|
|
|
self.canvasBitmap = wx.Bitmap(winSize)
|
|
|
|
else:
|
2019-09-06 04:29:45 -04:00
|
|
|
oldDc = wx.MemoryDC(); oldDc.SelectObject(self.canvasBitmap);
|
|
|
|
newDc = wx.MemoryDC(); newBitmap = wx.Bitmap(winSize); newDc.SelectObject(newBitmap);
|
2019-09-01 10:34:00 -04:00
|
|
|
newDc.Blit(0, 0, *self.canvasBitmap.GetSize(), oldDc, 0, 0)
|
|
|
|
oldDc.SelectObject(wx.NullBitmap)
|
|
|
|
self.canvasBitmap.Destroy(); self.canvasBitmap = newBitmap;
|
2019-09-06 04:29:45 -04:00
|
|
|
self.canvasSize, self.cellSize = canvasSize, cellSize
|
|
|
|
self._font = wx.Font(8, wx.FONTFAMILY_TELETYPE, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)
|
2019-09-01 10:34:00 -04: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().
2019-09-09 06:30:25 -04:00
|
|
|
# {{{ xlateEventPoint(self, event, eventDc, viewRect)
|
|
|
|
def xlateEventPoint(self, event, eventDc, viewRect):
|
2019-09-01 10:34:00 -04:00
|
|
|
eventPoint = event.GetLogicalPosition(eventDc)
|
2019-09-06 04:29:45 -04:00
|
|
|
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)
|
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().
2019-09-09 06:30:25 -04:00
|
|
|
return [m + n for m, n in zip((mapX, mapY), viewRect)]
|
2019-09-01 10:34:00 -04:00
|
|
|
# }}}
|
|
|
|
|
|
|
|
# {{{ __del__(self): destructor method
|
|
|
|
def __del__(self):
|
|
|
|
if self.canvasBitmap != None:
|
|
|
|
self.canvasBitmap.Destroy(); self.canvasBitmap = None;
|
|
|
|
self._finiBrushesAndPens()
|
|
|
|
# }}}
|
|
|
|
|
|
|
|
#
|
|
|
|
# __init__(self, canvasSize, cellSize): initialisation method
|
|
|
|
def __init__(self, canvasSize, cellSize):
|
2019-09-04 09:52:54 -04:00
|
|
|
self._brushes, self._font, self._lastBrush, self._lastPen, self._pens = None, None, None, None, None
|
|
|
|
self.canvasBitmap, self.cellSize = None, None
|
2019-09-09 11:27:37 -04:00
|
|
|
self._initBrushesAndPens(); self.resize(canvasSize, cellSize);
|
2019-09-01 10:34:00 -04:00
|
|
|
|
|
|
|
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|