@@ -49,7 +49,7 @@ local rect_centered = false
49
49
local rect_keepaspect = false
50
50
local needs_drawing = false
51
51
local crop_first_corner = nil -- in normalized video space
52
- local crop_cursor = {
52
+ local cursor = {
53
53
x = 0 ,
54
54
y = 0
55
55
}
@@ -82,6 +82,11 @@ function rect_from_two_points(p1, p2, centered, ratio)
82
82
return { x = c1 [1 ], y = c1 [2 ] }, { x = c2 [1 ], y = c2 [2 ] }
83
83
end
84
84
85
+ function round (num , num_decimal_places )
86
+ local mult = 10 ^ (num_decimal_places or 0 )
87
+ return math.floor (num * mult + 0.5 ) / mult
88
+ end
89
+
85
90
function clamp (low , value , high )
86
91
if value <= low then
87
92
return low
@@ -92,10 +97,10 @@ function clamp(low, value, high)
92
97
end
93
98
end
94
99
95
- function clamp_point (top_left , point , bottom_right )
100
+ function clamp_point (point , dim )
96
101
return {
97
- x = clamp (top_left . x , point .x , bottom_right . x ),
98
- y = clamp (top_left . y , point .y , bottom_right . y )
102
+ x = clamp (dim . ml , point .x , dim . w - dim . mr ),
103
+ y = clamp (dim . mt , point .y , dim . h - dim . mb )
99
104
}
100
105
end
101
106
@@ -210,10 +215,7 @@ function draw_crop_zone()
210
215
return
211
216
end
212
217
213
- local cursor = {
214
- x = crop_cursor .x ,
215
- y = crop_cursor .y ,
216
- }
218
+ cursor = clamp_point (cursor , dim )
217
219
local ass = assdraw .ass_new ()
218
220
219
221
if crop_first_corner and (opts .draw_shade or opts .draw_frame ) then
@@ -247,9 +249,13 @@ function draw_crop_zone()
247
249
local cursor_norm = screen_to_video_norm (cursor , dim )
248
250
local text = string.format (" %d, %d" , cursor_norm .x * vop .w , cursor_norm .y * vop .h )
249
251
if crop_first_corner then
250
- text = string.format (" %s (%dx%d)" , text ,
251
- math.abs ((cursor_norm .x - crop_first_corner .x ) * vop .w ),
252
- math.abs ((cursor_norm .y - crop_first_corner .y ) * vop .h )
252
+ local crop_zone_w = math.abs ((cursor_norm .x - crop_first_corner .x ) * vop .w )
253
+ local crop_zone_h = math.abs ((cursor_norm .y - crop_first_corner .y ) * vop .h )
254
+ local crop_zone_aspect = round (crop_zone_w / crop_zone_h , 3 )
255
+ text = string.format (" %s (%dx%d/%s)" , text ,
256
+ crop_zone_w ,
257
+ crop_zone_h ,
258
+ crop_zone_aspect
253
259
)
254
260
end
255
261
draw_position_text (ass , text , cursor , { w = dim .w , h = dim .h }, 6 )
@@ -308,14 +314,13 @@ function update_crop_zone_state()
308
314
cancel_crop ()
309
315
return
310
316
end
311
- local corner = crop_cursor
312
317
if crop_first_corner == nil then
313
- crop_first_corner = screen_to_video_norm (crop_cursor , dim )
318
+ crop_first_corner = screen_to_video_norm (cursor , dim )
314
319
redraw ()
315
320
else
316
321
local c1 , c2 = rect_from_two_points (
317
322
video_norm_to_screen (crop_first_corner , dim ),
318
- crop_cursor ,
323
+ cursor ,
319
324
rect_centered ,
320
325
rect_keepaspect and dim .w / dim .h )
321
326
local c1norm = screen_to_video_norm (c1 , dim )
@@ -361,7 +366,7 @@ function start_crop(mode)
361
366
active_mode = mode_maybe
362
367
363
368
if opts .mouse_support then
364
- crop_cursor .x , crop_cursor .y = mp .get_mouse_pos ()
369
+ cursor .x , cursor .y = mp .get_mouse_pos ()
365
370
end
366
371
redraw ()
367
372
for key , func in pairs (bindings ) do
405
410
406
411
-- bindings
407
412
if opts .mouse_support then
408
- bindings [" MOUSE_MOVE" ] = function () crop_cursor .x , crop_cursor .y = mp .get_mouse_pos (); redraw () end
413
+ bindings [" MOUSE_MOVE" ] = function () cursor .x , cursor .y = mp .get_mouse_pos (); redraw () end
409
414
end
410
415
for _ , key in ipairs (opts .accept ) do
411
416
bindings [key ] = update_crop_zone_state
@@ -415,8 +420,8 @@ for _, key in ipairs(opts.cancel) do
415
420
end
416
421
function movement_func (move_x , move_y )
417
422
return function ()
418
- crop_cursor .x = crop_cursor .x + move_x
419
- crop_cursor .y = crop_cursor .y + move_y
423
+ cursor .x = cursor .x + move_x
424
+ cursor .y = cursor .y + move_y
420
425
redraw ()
421
426
end
422
427
end
0 commit comments