| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
from .abstract_select import AbstractSelectionTool |
| 19 |
from .utilities_overlay import utilities_show_overlay_on_context |
| 20 |
|
| 21 |
class ToolRectSelect(AbstractSelectionTool): |
| 22 |
__gtype_name__ = 'ToolRectSelect' |
| 23 |
|
| 24 |
def __init__(self, window, **kwargs): |
| 25 |
super().__init__('rect_select', _("Rectangle selection"), 'tool-select-rect-symbolic', window) |
| 26 |
|
| 27 |
def get_tooltip(self, event_x, event_y, motion_behavior): |
| 28 |
if motion_behavior != 1: |
| 29 |
return None |
| 30 |
|
| 31 |
delta_x = abs(self.x_press - event_x) |
| 32 |
delta_y = abs(self.y_press - event_y) |
| 33 |
line1 = _("Width: %spx") % str(delta_x) |
| 34 |
line2 = _("Height: %spx") % str(delta_y) |
| 35 |
return line1 + "\n" + line2 |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
def press_define(self, event_x, event_y): |
| 40 |
pass |
| 41 |
|
| 42 |
def motion_define(self, event_x, event_y, render): |
| 43 |
if not render: |
| 44 |
return |
| 45 |
self._build_rectangle_path(self.x_press, self.y_press, event_x, event_y) |
| 46 |
self.restore_pixbuf() |
| 47 |
rect = self.get_selection().get_future_path() |
| 48 |
if rect is not None: |
| 49 |
ccontext = self.get_context() |
| 50 |
thickness = self.get_overlay_thickness() |
| 51 |
utilities_show_overlay_on_context(ccontext, rect, thickness) |
| 52 |
|
| 53 |
def release_define(self, surface, event_x, event_y): |
| 54 |
self._build_rectangle_path(self.x_press, self.y_press, event_x, event_y) |
| 55 |
self.operation_type = 'op-define' |
| 56 |
operation = self.build_operation() |
| 57 |
self.apply_operation(operation) |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|