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.
This commit is contained in:
2025-09-26 17:37:35 +02:00
parent b6c7863b77
commit b9c60ffc25

View File

@@ -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,10 +3561,11 @@ 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)
# 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)
@@ -3591,9 +3583,6 @@ class VideoEditor:
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:
# Store tracking points in ROTATED frame coordinates (pre-crop)
rx, ry = self._map_screen_to_rotated(x, y)
threshold = self.TRACKING_POINT_THRESHOLD