Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 76c2c7f

Browse files
committed
Fix rubberband on Cairo
1 parent f53c28d commit 76c2c7f

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

lib/matplotlib/backends/backend_gtk4.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def _mpl_to_gtk_cursor(mpl_cursor):
5252
class FigureCanvasGTK4(Gtk.DrawingArea, FigureCanvasBase):
5353
required_interactive_framework = "gtk4"
5454
_timer_cls = TimerGTK4
55+
_context_is_scaled = False
5556

5657
def __init__(self, figure=None):
5758
FigureCanvasBase.__init__(self, figure)
@@ -205,8 +206,15 @@ def _post_draw(self, widget, ctx):
205206
if self._rubberband_rect is None:
206207
return
207208

208-
x0, y0, w, h = (dim / self.device_pixel_ratio
209-
for dim in self._rubberband_rect)
209+
lw = 1
210+
dash = 3
211+
if not self._context_is_scaled:
212+
x0, y0, w, h = (dim / self.device_pixel_ratio
213+
for dim in self._rubberband_rect)
214+
else:
215+
x0, y0, w, h = self._rubberband_rect
216+
lw *= self.device_pixel_ratio
217+
dash *= self.device_pixel_ratio
210218
x1 = x0 + w
211219
y1 = y0 + h
212220

@@ -222,12 +230,12 @@ def _post_draw(self, widget, ctx):
222230
ctx.line_to(x1, y1)
223231

224232
ctx.set_antialias(1)
225-
ctx.set_line_width(1)
226-
ctx.set_dash((3, 3), 0)
233+
ctx.set_line_width(lw)
234+
ctx.set_dash((dash, dash), 0)
227235
ctx.set_source_rgb(0, 0, 0)
228236
ctx.stroke_preserve()
229237

230-
ctx.set_dash((3, 3), 3)
238+
ctx.set_dash((dash, dash), dash)
231239
ctx.set_source_rgb(1, 1, 1)
232240
ctx.stroke()
233241

lib/matplotlib/backends/backend_gtk4cairo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ def set_context(self, ctx):
1111

1212
class FigureCanvasGTK4Cairo(backend_gtk4.FigureCanvasGTK4,
1313
backend_cairo.FigureCanvasCairo):
14+
_context_is_scaled = True
1415

1516
def __init__(self, figure):
1617
super().__init__(figure)

0 commit comments

Comments
 (0)