22import lvgl as lv
33import mpos .util
44
5+ import math
6+ import mpos .util
57
68def get_object_center (obj ):
7- """Calculate the center (x, y) of an object based on its position and size."""
8- width = obj .get_width ()
9- height = obj .get_height ()
10- x = obj .get_x ()
11- y = obj .get_y ()
9+ """Calculate the center (x, y) of an object based on its absolute screen coordinates."""
10+ obj_area = lv .area_t ()
11+ obj .get_coords (obj_area )
12+ width = obj_area .x2 - obj_area .x1
13+ height = obj_area .y2 - obj_area .y1
14+ x = obj_area .x1
15+ y = obj_area .y1
1216 center_x = x + width / 2
1317 center_y = y + height / 2
1418 return center_x , center_y
@@ -27,7 +31,7 @@ def compute_angle_to_object(from_obj, to_obj):
2731 dy = to_y - from_y
2832
2933 # Calculate angle (0° = UP, 90° = RIGHT, 180° = DOWN, 270° = LEFT)
30- angle_rad = math .atan2 (dx , - dy ) # Fixed for correct convention
34+ angle_rad = math .atan2 (dx , - dy )
3135 angle_deg = math .degrees (angle_rad )
3236 return (angle_deg + 360 ) % 360 # Normalize to [0, 360)
3337
@@ -45,12 +49,14 @@ def get_closest_edge_point_and_distance(from_x, from_y, obj, direction_degrees,
4549 Calculate the distance to the closest edge point on obj, and check if its angle is within the direction cone.
4650 Returns (distance, closest_x, closest_y, angle_deg) or None if not in direction or inside.
4751 """
48- x = obj .get_x ()
49- y = obj .get_y ()
50- width = obj .get_width ()
51- height = obj .get_height ()
52- right = x + width
53- bottom = y + height
52+ obj_area = lv .area_t ()
53+ obj .get_coords (obj_area )
54+ x = obj_area .x1
55+ y = obj_area .y1
56+ right = obj_area .x2
57+ bottom = obj_area .y2
58+ width = right - x
59+ height = bottom - y
5460
5561 # Clamp to the rect bounds to find closest point
5662 closest_x = max (x , min (from_x , right ))
@@ -70,15 +76,15 @@ def get_closest_edge_point_and_distance(from_x, from_y, obj, direction_degrees,
7076 distance = math .sqrt (dx ** 2 + dy ** 2 )
7177
7278 # Compute angle to the closest point (using same convention)
73- angle_rad = math .atan2 (dx , - dy ) # Fixed
79+ angle_rad = math .atan2 (dx , - dy )
7480 angle_deg = math .degrees (angle_rad )
7581 angle_deg = (angle_deg + 360 ) % 360
7682
7783 # Check if in direction cone (±45°)
7884 angle_diff = min ((angle_deg - direction_degrees ) % 360 , (direction_degrees - angle_deg ) % 360 )
7985 if angle_diff > 45 :
8086 if debug :
81- print (f" { obj } at ({ x } , { y } ) size ({ width } x{ height } ): closest point ({ closest_x :.1f} , { closest_y :.1f} ), angle { angle_deg :.1f} °, diff { angle_diff :.1f} ° > 45, skipped" )
87+ print (f" { obj } at ({ x } , { y } ) size ({ width } x{ height } ): closest point ({ closest_x :.1f} , { closest_y :.1f} ), angle { angle_deg :.1f} °, diff { angle_diff :.1f} ° > 45° , skipped" )
8288 return None
8389
8490 if debug :
@@ -145,6 +151,18 @@ def process_object(obj, depth=0):
145151
146152 return closest_obj
147153
154+
155+
156+
157+
158+
159+
160+
161+
162+
163+
164+
165+
148166# This function is missing so emulate it using focus_next():
149167def emulate_focus_obj (focusgroup , target ):
150168 for objnr in range (focusgroup .get_obj_count ()):
0 commit comments