Commit b5a74ff2bddf6839b5ce7ab48e6646af1e6f5ee0
1 parent
cb4d834e
Exists in
master
and in
25 other branches
Added a method to draw a rectangle inside the canvas
Showing
1 changed file
with
20 additions
and
3 deletions
Show diff stats
invesalius/data/viewer_slice.py
@@ -324,6 +324,25 @@ class CanvasRendererCTX: | @@ -324,6 +324,25 @@ class CanvasRendererCTX: | ||
324 | gc.StrokePath(path) | 324 | gc.StrokePath(path) |
325 | gc.FillPath(path) | 325 | gc.FillPath(path) |
326 | 326 | ||
327 | + def draw_rectangle(self, pos, width, height, line_colour=(255, 0, 0, 128), fill_colour=(0, 0, 0, 0)): | ||
328 | + """ | ||
329 | + Draw a rectangle with its top left at pos and with the given width and height. | ||
330 | + | ||
331 | + Params: | ||
332 | + pos: The top left pos (x, y) of the rectangle. | ||
333 | + width: width of the rectangle. | ||
334 | + height: heigth of the rectangle. | ||
335 | + line_colour: RGBA line colour. | ||
336 | + fill_colour: RGBA fill colour. | ||
337 | + """ | ||
338 | + if self.gc is None: | ||
339 | + return None | ||
340 | + gc = self.gc | ||
341 | + | ||
342 | + px, py = pos | ||
343 | + gc.SetPen(wx.Pen(line_colour)) | ||
344 | + gc.SetBrush(wx.Brush(fill_colour)) | ||
345 | + gc.DrawRectangle(px, py, width, height) | ||
327 | 346 | ||
328 | def draw_text_box(self, text, pos, font=None, txt_colour=(255, 255, 255), bg_colour=(128, 128, 128, 128), border=5): | 347 | def draw_text_box(self, text, pos, font=None, txt_colour=(255, 255, 255), bg_colour=(128, 128, 128, 128), border=5): |
329 | """ | 348 | """ |
@@ -353,9 +372,7 @@ class CanvasRendererCTX: | @@ -353,9 +372,7 @@ class CanvasRendererCTX: | ||
353 | 372 | ||
354 | # Drawing the box | 373 | # Drawing the box |
355 | cw, ch = w + border * 2, h + border * 2 | 374 | cw, ch = w + border * 2, h + border * 2 |
356 | - gc.SetBrush(wx.Brush(bg_colour)) | ||
357 | - gc.SetPen(wx.Pen(bg_colour)) | ||
358 | - gc.DrawRectangle(px, py, cw, ch) | 375 | + self.draw_rectangle((px, py), cw, ch, bg_colour, bg_colour) |
359 | 376 | ||
360 | tpx, tpy = px + border, py + border | 377 | tpx, tpy = px + border, py + border |
361 | gc.DrawText(text, tpx, tpy) | 378 | gc.DrawText(text, tpx, tpy) |