From b9c60ffc25db29afe01b2c60a5f5045ea7f58772 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Fri, 26 Sep 2025 17:37:35 +0200 Subject: [PATCH] Refactor template dot rendering and right-click functionality in VideoEditor This commit simplifies the rendering of template dots in the VideoEditor by standardizing their appearance to match motion tracking points. Additionally, it enhances the right-click functionality to allow for template removal when clicking near template centers, improving user interaction and feedback during video editing sessions. --- croppa/main.py | 55 ++++++++++++++++++++------------------------------ 1 file changed, 22 insertions(+), 33 deletions(-) diff --git a/croppa/main.py b/croppa/main.py index fe76bf1..48003b8 100644 --- a/croppa/main.py +++ b/croppa/main.py @@ -3342,18 +3342,9 @@ class VideoEditor: # Map to screen coordinates sx, sy = self._map_rotated_to_screen(center_x, center_y) - # Draw template dot (different colors for active/inactive) - is_active = (self.current_template_id == template_id) - if is_active: - cv2.circle(canvas, (sx, sy), 6, (0, 255, 0), -1) # Green for active - cv2.circle(canvas, (sx, sy), 6, (255, 255, 255), 2) - else: - cv2.circle(canvas, (sx, sy), 4, (0, 0, 255), -1) # Red for inactive - cv2.circle(canvas, (sx, sy), 4, (255, 255, 255), 1) - - # Draw template ID - cv2.putText(canvas, str(template_id), (sx + 8, sy - 8), - cv2.FONT_HERSHEY_SIMPLEX, 0.4, (255, 255, 255), 1) + # Draw template dot (same style as motion tracking points) + cv2.circle(canvas, (sx, sy), 6, (0, 255, 0), -1) # Green circle + cv2.circle(canvas, (sx, sy), 6, (255, 255, 255), 1) # White border # Draw selection rectangles for feature extraction/deletion if self.selective_feature_extraction_rect: @@ -3570,30 +3561,28 @@ class VideoEditor: self.template_selection_start = None self.template_selection_rect = None - # Handle Ctrl+Right-click for template removal - if event == cv2.EVENT_RBUTTONDOWN and (flags & cv2.EVENT_FLAG_CTRLKEY) and not (flags & cv2.EVENT_FLAG_SHIFTKEY): - if not self.is_image_mode and self.templates: - # Check if click is near any template dot (center of template region) - screen_x, screen_y = x, y - raw_x, raw_y = self._map_screen_to_rotated(screen_x, screen_y) - - for template_id, template_data in self.templates.items(): - # Only check templates that cover current frame - if (template_data['start_frame'] <= self.current_frame <= template_data['end_frame']): - tx, ty, tw, th = template_data['region'] - center_x = tx + tw // 2 - center_y = ty + th // 2 - - # Check if click is within 10px of template center - distance = ((raw_x - center_x) ** 2 + (raw_y - center_y) ** 2) ** 0.5 - if distance <= 10: - self.remove_template(template_id) - self.save_state() - return - # Handle right-click for tracking points (no modifiers) if event == cv2.EVENT_RBUTTONDOWN and not (flags & (cv2.EVENT_FLAG_CTRLKEY | cv2.EVENT_FLAG_SHIFTKEY)): if not self.is_image_mode: + # First check for template removal (like motion tracking points) + if self.templates: + screen_x, screen_y = x, y + raw_x, raw_y = self._map_screen_to_rotated(screen_x, screen_y) + + for template_id, template_data in self.templates.items(): + # Only check templates that cover current frame + if (template_data['start_frame'] <= self.current_frame <= template_data['end_frame']): + tx, ty, tw, th = template_data['region'] + center_x = tx + tw // 2 + center_y = ty + th // 2 + + # Check if click is within 10px of template center + distance = ((raw_x - center_x) ** 2 + (raw_y - center_y) ** 2) ** 0.5 + if distance <= 10: + self.remove_template(template_id) + self.save_state() + return + # Store tracking points in ROTATED frame coordinates (pre-crop) rx, ry = self._map_screen_to_rotated(x, y) threshold = self.TRACKING_POINT_THRESHOLD