From 26a1954bb1b6c122c24227622797f8dd6c3daf25 Mon Sep 17 00:00:00 2001 From: Jano Paetzold Date: Sun, 14 Aug 2022 00:09:32 +0200 Subject: [PATCH 1/2] Fix tab visual glitch on high dpi as good as possible The tab should melt with the view below it, by cutting a hole into the separator that separates the tab bar from the widget below. This was achieved by drawing the tab background over the separator line, covering it. Also, the tab shouldn't have a bottom border itself, obviously. This was achieved by drawing a full polygon with full borders for the tab background, but limiting it by a clipping region, so the bottom border was cut off (as it was drawn outside the boundaries of the clipping region). This broke on high dpi screens, as the sizes for the clipping box and the tab were calculated on pixel basis, and didn't line up with higher precision. Therefore, you could see the bottom line of the tab background. Making the clipping region smaller, however, made the background not cover the seperator line anymore. This commit fixes this, by drawing the background first as a polygon (without borders) and then draw the borders (without the bottom border). The borders will be drawn with a smaller clipping region, so they don't cross the seperator line. --- src/misc.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/misc.py b/src/misc.py index a052003d..629aea63 100644 --- a/src/misc.py +++ b/src/misc.py @@ -453,7 +453,8 @@ def OnPaint(self, event): dc.DrawRectangle(0, 0, w, h) dc.SetPen(cfgGui.tabBorderPen) - dc.DrawLine(0,h-1,w,h-1) + separatorLineThickness = cfgGui.tabBorderPen.GetWidth() + dc.DrawLine(0,h-separatorLineThickness,w,h-separatorLineThickness) xpos = self.paddingX @@ -474,19 +475,25 @@ def OnPaint(self, event): dc.SetFont(self.font) p = self.pages[i] - dc.DestroyClippingRegion() - dc.SetClippingRegion(xpos, tabY, tabW, tabH) - dc.SetPen(cfgGui.tabBorderPen) - if i == self.selected: - points=((6,1),(tabW-8,1),(tabW-6,2),(tabW-2,tabH),(0,tabH),(4,2)) + points=((0,tabH),(4,2),(6,1),(tabW-8,1),(tabW-6,2),(tabW-2,tabH)) dc.SetBrush(cfgGui.workspaceBrush) else: - points=((5,2),(tabW-8,2),(tabW-6,3),(tabW-2,tabH-1),(0,tabH-1),(3,3)) + points=((0,tabH-separatorLineThickness),(3,3),(5,2),(tabW-8,2),(tabW-6,3),(tabW-2,tabH-separatorLineThickness)) dc.SetBrush(cfgGui.tabNonActiveBgBrush) + dc.DestroyClippingRegion() + + # draw tab background + dc.SetClippingRegion(xpos, tabY, tabW, tabH) + dc.SetPen(wx.Pen(wx.NullPen)) dc.DrawPolygon(points,xpos,tabY) + # draw tab borders + dc.SetClippingRegion(xpos, tabY, tabW, tabH-separatorLineThickness) # tab borders should never cross the seperator line + dc.SetPen(cfgGui.tabBorderPen) + dc.DrawLines(points,xpos,tabY) + # clip the text to fit within the tabs dc.DestroyClippingRegion() dc.SetClippingRegion(xpos, tabY, tabW - self.paddingX * 3, tabH) From 42a5a77d0580229b62837925dd0807ef6b267b5f Mon Sep 17 00:00:00 2001 From: Jano Paetzold Date: Sun, 14 Aug 2022 00:15:21 +0200 Subject: [PATCH 2/2] Document code --- src/misc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/misc.py b/src/misc.py index 629aea63..d64ad16d 100644 --- a/src/misc.py +++ b/src/misc.py @@ -479,7 +479,7 @@ def OnPaint(self, event): points=((0,tabH),(4,2),(6,1),(tabW-8,1),(tabW-6,2),(tabW-2,tabH)) dc.SetBrush(cfgGui.workspaceBrush) else: - points=((0,tabH-separatorLineThickness),(3,3),(5,2),(tabW-8,2),(tabW-6,3),(tabW-2,tabH-separatorLineThickness)) + points=((0,tabH-separatorLineThickness),(3,3),(5,2),(tabW-8,2),(tabW-6,3),(tabW-2,tabH-separatorLineThickness)) # subtract its thickness to not cover the separator line dc.SetBrush(cfgGui.tabNonActiveBgBrush) dc.DestroyClippingRegion()