From 0d5f588108bbf3ee276692cb60ed5c8bb34dd130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucio=20Andr=C3=A9s=20Illanes=20Albornoz?= Date: Sun, 15 Sep 2019 16:54:19 +0200 Subject: [PATCH] Fix assets management canvas panel scrolling. libgui/GuiWindow.py: ONCE, THERE WAS A _LETHALLY FUCKING WOUNDED_ WXPYTHON libroar/RoarAssetsWindow.py: ON THE VERY EDGE OF ITS MISERABLE EXISTENCE libroar/RoarCanvasWindow.py: BECAUSE A LION VICIOUSLY MAULED IT AND TORTURED IT FOR 392 DAYS AND TWO (2) SECONDS --- libgui/GuiWindow.py | 21 +++++++++++---------- libroar/RoarAssetsWindow.py | 17 ++++++++++++----- libroar/RoarCanvasWindow.py | 3 ++- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/libgui/GuiWindow.py b/libgui/GuiWindow.py index 91fb6b6..48c1dc0 100644 --- a/libgui/GuiWindow.py +++ b/libgui/GuiWindow.py @@ -9,12 +9,13 @@ import wx class GuiWindow(wx.ScrolledWindow): # {{{ _updateScrollBars(self) def _updateScrollBars(self): - clientSize = self.GetClientSize() - if (self.size[0] > clientSize[0]) or (self.size[1] > clientSize[1]): - self.scrollFlag = True; super().SetVirtualSize(self.size); - elif self.scrollFlag \ - and ((self.size[0] <= clientSize[0]) or (self.size[1] <= clientSize[1])): - self.scrollFlag = False; super().SetVirtualSize((0, 0)); + if self.size != None: + clientSize = self.GetClientSize() + if (self.size[0] > clientSize[0]) or (self.size[1] > clientSize[1]): + self.scrollFlag = True; super().SetVirtualSize(self.size); + elif self.scrollFlag \ + and ((self.size[0] <= clientSize[0]) or (self.size[1] <= clientSize[1])): + self.scrollFlag = False; super().SetVirtualSize((0, 0)); # }}} # {{{ onClose(self, event) @@ -59,10 +60,10 @@ class GuiWindow(wx.ScrolledWindow): # }}} # - # __init__(self, parent, pos, scrollStep, size, style=0): initialisation method - def __init__(self, parent, pos, scrollStep, size, style=0): - super().__init__(parent, pos=pos, size=size, style=style) - self.pos, self.scrollFlag, self.scrollStep, self.size = pos, False, scrollStep, size + # __init__(self, parent, pos, scrollStep, style=0): initialisation method + def __init__(self, parent, pos, scrollStep, style=0): + super().__init__(parent, pos=pos, style=style) if style != 0 else super().__init__(parent, pos=pos) + self.pos, self.scrollFlag, self.scrollStep, self.size = pos, False, scrollStep, None for eventType, f in ( (wx.EVT_CHAR, self.onKeyboardInput), (wx.EVT_CLOSE, self.onClose), (wx.EVT_ENTER_WINDOW, self.onEnterWindow), (wx.EVT_LEAVE_WINDOW, self.onLeaveWindow), (wx.EVT_LEFT_DOWN, self.onMouseInput), (wx.EVT_MOTION, self.onMouseInput), diff --git a/libroar/RoarAssetsWindow.py b/libroar/RoarAssetsWindow.py index 5ab70fe..675d6e7 100644 --- a/libroar/RoarAssetsWindow.py +++ b/libroar/RoarAssetsWindow.py @@ -88,10 +88,16 @@ class RoarAssetsWindow(GuiMiniFrame): # {{{ _updateScrollBars(self) def _updateScrollBars(self): clientSize = self.panelCanvas.GetClientSize() - if (self.panelCanvas.size[0] > clientSize[0]) or (self.panelCanvas.size[1] > clientSize[1]): - self.scrollFlag = True; super(wx.ScrolledWindow, self.panelCanvas).SetVirtualSize(self.panelCanvas.size); + if self.currentIndex != None: + panelSize = [a * b for a, b in zip(self.canvasList[self.currentIndex][0].size, self.backend.cellSize)] + elif self.panelCanvas.size != None: + panelSize = list(self.panelCanvas.size) + else: + return + if (panelSize[0] > clientSize[0]) or (panelSize[1] > clientSize[1]): + self.scrollFlag = True; super(wx.ScrolledWindow, self.panelCanvas).SetVirtualSize(panelSize); elif self.scrollFlag \ - and ((self.panelCanvas.size[0] <= clientSize[0]) or (self.panelCanvas.size[1] <= clientSize[1])): + and ((panelSize[0] <= clientSize[0]) or (panelSize[1] <= clientSize[1])): self.scrollFlag = False; super(wx.ScrolledWindow, self.panelCanvas).SetVirtualSize((0, 0)); # }}} @@ -324,15 +330,16 @@ class RoarAssetsWindow(GuiMiniFrame): self.listView.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onListViewItemSelected) self.listView.Bind(wx.EVT_RIGHT_DOWN, self.onListViewRightDown) - self.panelCanvas = GuiWindow(self, (0, 0), cellSize, (int(size[0] / 2), int(size[1] / 2)), wx.BORDER_SUNKEN) + self.panelCanvas = GuiWindow(self, (0, 0), cellSize, wx.BORDER_SUNKEN) self.panelCanvas.Bind(wx.EVT_LEFT_DOWN, self.onPanelLeftDown) self.panelCanvas.Bind(wx.EVT_PAINT, self.onPanelPaint) self.panelCanvas.Bind(wx.EVT_SIZE, self.onPanelSize) - self._updateScrollBars() self.sizer = wx.BoxSizer(wx.VERTICAL) self.sizer.AddMany(((self.listView, 0, wx.ALL | wx.EXPAND, 4), (self.panelCanvas, 1, wx.ALL | wx.EXPAND, 4),)) + self.panelCanvas.SetMinSize((int(size[0] / 2), int(size[1] / 2))) self.SetSizerAndFit(self.sizer) + self._updateScrollBars() self.Show(True) # vim:expandtab foldmethod=marker sw=4 ts=4 tw=120 diff --git a/libroar/RoarCanvasWindow.py b/libroar/RoarCanvasWindow.py index c6ee63d..c3dff64 100644 --- a/libroar/RoarCanvasWindow.py +++ b/libroar/RoarCanvasWindow.py @@ -201,7 +201,8 @@ class RoarCanvasWindow(GuiWindow): # # __init__(self, backend, canvas, cellSize, commands, parent, parentFrame, pos, scrollStep, size): initialisation method def __init__(self, backend, canvas, cellSize, commands, parent, parentFrame, pos, scrollStep, size): - super().__init__(parent, pos, scrollStep, [w * h for w, h in zip(cellSize, size)]) + super().__init__(parent, pos, scrollStep) + self.size = size self.backend, self.canvas, self.cellSize, self.commands, self.parentFrame = backend(self.size, cellSize), canvas, cellSize, commands(self, parentFrame), parentFrame self.brushColours, self.brushPos, self.brushSize, self.dirty, self.lastCellState = [4, 1], [0, 0], [1, 1], False, None self.popupEventDc = None