diff options
| author | Lex Neva <github.com@lexneva.name> | 2019-04-16 21:01:25 -0400 |
|---|---|---|
| committer | Lex Neva <github.com@lexneva.name> | 2019-04-16 21:01:25 -0400 |
| commit | 30d80ab41bfe19b5bd9d71a903c5e796266a849b (patch) | |
| tree | b8e5c1b1ac4232b0caf738dd5cfc2a11daf3fcc1 /lib/gui | |
| parent | 313cd44483bf216c123e19dfb3dd294eb57a9c3d (diff) | |
add scale bar to simulator for comparison
Diffstat (limited to 'lib/gui')
| -rw-r--r-- | lib/gui/simulator.py | 55 |
1 files changed, 46 insertions, 9 deletions
diff --git a/lib/gui/simulator.py b/lib/gui/simulator.py index e0d78983..c07a7af3 100644 --- a/lib/gui/simulator.py +++ b/lib/gui/simulator.py @@ -356,14 +356,51 @@ class DrawingPanel(wx.Panel): self.last_frame_duration = time.time() - start if last_stitch: - x = last_stitch[0] - y = last_stitch[1] - x, y = transform.TransformPoint(float(x), float(y)) - canvas.SetTransform(canvas.CreateMatrix()) - crosshair_radius = 10 - canvas.SetPen(self.black_pen) - canvas.DrawLines(((x - crosshair_radius, y), (x + crosshair_radius, y))) - canvas.DrawLines(((x, y - crosshair_radius), (x, y + crosshair_radius))) + self.draw_crosshair(last_stitch[0], last_stitch[1], canvas, transform) + + self.draw_scale(canvas) + + def draw_crosshair(self, x, y, canvas, transform): + x, y = transform.TransformPoint(float(x), float(y)) + canvas.SetTransform(canvas.CreateMatrix()) + crosshair_radius = 10 + canvas.SetPen(self.black_pen) + canvas.DrawLines(((x - crosshair_radius, y), (x + crosshair_radius, y))) + canvas.DrawLines(((x, y - crosshair_radius), (x, y + crosshair_radius))) + + def draw_scale(self, canvas): + canvas_width, canvas_height = self.GetClientSize() + + one_mm = PIXELS_PER_MM * self.zoom + scale_width = one_mm + max_width = min(canvas_width * 0.5, 300) + + while scale_width > max_width: + scale_width /= 2.0 + + while scale_width < 50: + scale_width += one_mm + + scale_width_mm = scale_width / self.zoom / PIXELS_PER_MM + + # The scale bar looks like this: + # + # | | + # |_____|_____| + + scale_lower_left_x = 20 + scale_lower_left_y = canvas_height - 20 + + canvas.DrawLines(((scale_lower_left_x, scale_lower_left_y - 6), + (scale_lower_left_x, scale_lower_left_y), + (scale_lower_left_x + scale_width / 2.0, scale_lower_left_y), + (scale_lower_left_x + scale_width / 2.0, scale_lower_left_y - 3), + (scale_lower_left_x + scale_width / 2.0, scale_lower_left_y), + (scale_lower_left_x + scale_width, scale_lower_left_y), + (scale_lower_left_x + scale_width, scale_lower_left_y - 5))) + + canvas.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL), wx.Colour((0, 0, 0))) + canvas.DrawText("%s mm" % scale_width_mm, scale_lower_left_x, scale_lower_left_y + 5) def clear(self): dc = wx.ClientDC(self) @@ -520,7 +557,7 @@ class DrawingPanel(wx.Panel): # If we just change the zoom, the design will appear to move on the # screen. We have to adjust the pan to compensate. We want to keep # the part of the design under the mouse pointer in the same spot - # after we zoom, so that we appar to be zooming centered on the + # after we zoom, so that we appear to be zooming centered on the # mouse pointer. # This will create a matrix that takes a point in the design and |
