MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / paintEvent

Method paintEvent

python/examples/triage/byte.py:434–520  ·  view source on GitHub ↗
(self, event)

Source from the content-addressed store, hash-verified

432 self.adjustSize(event.size().width(), event.size().height())
433
434 def paintEvent(self, event):
435 p = QPainter(self.viewport())
436 render = self.createRenderContext()
437 render.init(p)
438 charWidth = render.getFontWidth()
439 charHeight = render.getFontHeight()
440
441 # Compute range that needs to be updated
442 topY = event.rect().y()
443 botY = topY + event.rect().height()
444 topY = (topY - 2) // charHeight
445 botY = ((botY - 2) // charHeight) + 1
446
447 # Compute selection range
448 selection = False
449 selStart, selEnd = self.getSelectionOffsets()
450 if selStart != selEnd:
451 selection = True
452
453 # Draw selection
454 if selection:
455 startY = None
456 endY = None
457 startX = None
458 endX = None
459 for i in range(0, len(self.lines)):
460 if selStart >= self.lines[i].address:
461 startY = i - self.topLine
462 startX = selStart - self.lines[i].address
463 if startX > self.cols:
464 startX = self.cols
465 if selEnd >= self.lines[i].address:
466 endY = i - self.topLine
467 endX = selEnd - self.lines[i].address
468 if endX > self.cols:
469 endX = self.cols
470
471 if startY is not None and endY is not None:
472 p.setPen(binaryninjaui.getThemeColor(ThemeColor.SelectionColor))
473 p.setBrush(binaryninjaui.getThemeColor(ThemeColor.SelectionColor))
474 if startY == endY:
475 p.drawRect(2 + (self.addrWidth + 2 + startX) * charWidth, 2 + startY * charHeight,
476 (endX - startX) * charWidth, charHeight + 1)
477 else:
478 p.drawRect(2 + (self.addrWidth + 2 + startX) * charWidth, 2 + startY * charHeight,
479 (self.cols - startX) * charWidth, charHeight + 1)
480 if endX > 0:
481 p.drawRect(2 + (self.addrWidth + 2) * charWidth, 2 + endY * charHeight,
482 endX * charWidth, charHeight + 1)
483 if (endY - startY) > 1:
484 p.drawRect(2 + (self.addrWidth + 2) * charWidth, 2 + (startY + 1) * charHeight,
485 self.cols * charWidth, ((endY - startY) - 1) * charHeight + 1)
486
487 # Paint each line
488 color = self.palette().color(QPalette.WindowText)
489 for y in range(topY, botY):
490 if (y + self.topLine) < 0:
491 continue

Callers

nothing calls this directly

Calls 7

createRenderContextMethod · 0.95
getSelectionOffsetsMethod · 0.95
yMethod · 0.80
initMethod · 0.45
heightMethod · 0.45
widthMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected