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:
@@ -3342,18 +3342,9 @@ class VideoEditor:
|
|||||||
# Map to screen coordinates
|
# Map to screen coordinates
|
||||||
sx, sy = self._map_rotated_to_screen(center_x, center_y)
|
sx, sy = self._map_rotated_to_screen(center_x, center_y)
|
||||||
|
|
||||||
# Draw template dot (different colors for active/inactive)
|
# Draw template dot (same style as motion tracking points)
|
||||||
is_active = (self.current_template_id == template_id)
|
cv2.circle(canvas, (sx, sy), 6, (0, 255, 0), -1) # Green circle
|
||||||
if is_active:
|
cv2.circle(canvas, (sx, sy), 6, (255, 255, 255), 1) # White border
|
||||||
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 selection rectangles for feature extraction/deletion
|
# Draw selection rectangles for feature extraction/deletion
|
||||||
if self.selective_feature_extraction_rect:
|
if self.selective_feature_extraction_rect:
|
||||||
@@ -3570,30 +3561,28 @@ class VideoEditor:
|
|||||||
self.template_selection_start = None
|
self.template_selection_start = None
|
||||||
self.template_selection_rect = 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)
|
# 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 event == cv2.EVENT_RBUTTONDOWN and not (flags & (cv2.EVENT_FLAG_CTRLKEY | cv2.EVENT_FLAG_SHIFTKEY)):
|
||||||
if not self.is_image_mode:
|
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)
|
# Store tracking points in ROTATED frame coordinates (pre-crop)
|
||||||
rx, ry = self._map_screen_to_rotated(x, y)
|
rx, ry = self._map_screen_to_rotated(x, y)
|
||||||
threshold = self.TRACKING_POINT_THRESHOLD
|
threshold = self.TRACKING_POINT_THRESHOLD
|
||||||
|
Reference in New Issue
Block a user