Commit 319e0fe152ff9bd5acf33f6f357b5a455139aafc

Authored by Thiago Franco de Moraes
1 parent b5a74ff2

Added a method to draw a text without a box

Showing 1 changed file with 27 additions and 3 deletions   Show diff stats
invesalius/data/viewer_slice.py
... ... @@ -344,6 +344,29 @@ class CanvasRendererCTX:
344 344 gc.SetBrush(wx.Brush(fill_colour))
345 345 gc.DrawRectangle(px, py, width, height)
346 346  
  347 + def draw_text(self, text, pos, font=None, txt_colour=(255, 255, 255)):
  348 + """
  349 + Draw text.
  350 +
  351 + Params:
  352 + text: an unicode text.
  353 + pos: (x, y) position.
  354 + font: if None it'll use the default gui font.
  355 + txt_colour: RGB text colour
  356 + """
  357 + if self.gc is None:
  358 + return None
  359 + gc = self.gc
  360 +
  361 + if font is None:
  362 + font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
  363 +
  364 + font = gc.CreateFont(font, txt_colour)
  365 + gc.SetFont(font)
  366 +
  367 + px, py = pos
  368 + gc.DrawText(text, px, py)
  369 +
347 370 def draw_text_box(self, text, pos, font=None, txt_colour=(255, 255, 255), bg_colour=(128, 128, 128, 128), border=5):
348 371 """
349 372 Draw text inside a text box.
... ... @@ -363,8 +386,8 @@ class CanvasRendererCTX:
363 386 if font is None:
364 387 font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
365 388  
366   - font = gc.CreateFont(font, txt_colour)
367   - gc.SetFont(font)
  389 + _font = gc.CreateFont(font, txt_colour)
  390 + gc.SetFont(_font)
368 391 w, h = gc.GetTextExtent(text)
369 392  
370 393 px, py = pos
... ... @@ -374,8 +397,9 @@ class CanvasRendererCTX:
374 397 cw, ch = w + border * 2, h + border * 2
375 398 self.draw_rectangle((px, py), cw, ch, bg_colour, bg_colour)
376 399  
  400 + # Drawing the text
377 401 tpx, tpy = px + border, py + border
378   - gc.DrawText(text, tpx, tpy)
  402 + self.draw_text(text, (tpx, tpy), font, txt_colour)
379 403  
380 404 def draw_arc(self, center, p0, p1, line_colour=(255, 0, 0, 128), width=2):
381 405 """
... ...