Skip to content

Commit

Permalink
Add tool's width/height/length/radius information to the "ctrl" tooltip
Browse files Browse the repository at this point in the history
issue #46, fixes #439
  • Loading branch information
maoschanz committed Nov 7, 2021
1 parent fd05e59 commit 4aaa807
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/tools/classic_tools/tool_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import cairo
import cairo, math
from .abstract_classic_tool import AbstractClassicTool
from .utilities_paths import utilities_add_arrow_triangle

Expand All @@ -41,6 +41,19 @@ def __init__(self, window, **kwargs):
self.add_tool_action_boolean('line-ortholock', self._ortholock)
self._set_options_attributes() # Not optimal but more readable

def get_tooltip(self, event_x, event_y, motion_behavior):
if motion_behavior != 1:
return None # no line is being drawn

delta_x = abs(self.x_press - event_x)
delta_y = abs(self.y_press - event_y)
line1 = _("Width: %spx") % str(delta_x)
line2 = _("Height: %spx") % str(delta_y)
length = round(math.sqrt(delta_x * delta_x + delta_y * delta_y), 2)
return line1 + "\n" + line2 + "\n" + _("Length: %spx") % str(length)

############################################################################

def _set_active_shape(self):
state_as_string = self.get_option_value('line_shape')
if state_as_string == 'thin':
Expand Down
19 changes: 19 additions & 0 deletions src/tools/classic_tools/tool_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,25 @@ def _reset_temp_points(self):
self.initial_x = -1.0
self.initial_y = -1.0

def get_tooltip(self, event_x, event_y, motion_behavior):
if motion_behavior != 1:
return None # no line is being drawn
if self._shape_id in ['polygon', 'freeshpae']:
return None # no tooltip for these shapes

delta_x = abs(self.x_press - event_x)
delta_y = abs(self.y_press - event_y)

if self._shape_id == 'circle':
length = round(math.sqrt(delta_x * delta_x + delta_y * delta_y), 2)
return _("Radius: %spx") % length

line1 = _("Width: %spx") % str(delta_x)
line2 = _("Height: %spx") % str(delta_y)
return line1 + "\n" + line2

############################################################################

def _set_filling_style(self):
self._filling_id = self.get_option_value('shape_filling')

Expand Down
12 changes: 12 additions & 0 deletions src/tools/selection_tools/select_rect.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ class ToolRectSelect(AbstractSelectionTool):
def __init__(self, window, **kwargs):
super().__init__('rect_select', _("Rectangle selection"), 'tool-select-rect-symbolic', window)

def get_tooltip(self, event_x, event_y, motion_behavior):
if motion_behavior != 1:
return None # no line is being drawn

delta_x = abs(self.x_press - event_x)
delta_y = abs(self.y_press - event_y)
line1 = _("Width: %spx") % str(delta_x)
line2 = _("Height: %spx") % str(delta_y)
return line1 + "\n" + line2

############################################################################

def press_define(self, event_x, event_y):
pass

Expand Down

0 comments on commit 4aaa807

Please sign in to comment.