@@ -28,6 +28,7 @@ local function install_notes_overlay(options)
2828 end
2929
3030 local overlay_state = overlay .get_state ()
31+
3132 return overlay_state .db [' notes.map_notes' ].widget
3233end
3334
8687function get_visible_map_center ()
8788 local viewport = guidm .Viewport .get ()
8889
89- local half_x = math.max (
90- math.floor ((viewport .x1 + viewport .x2 ) / 2 ),
91- 2
90+ local map_width , map_height = dfhack .maps .getTileSize ()
91+ local world_rect = gui .mkdims_wh (0 , 0 , map_width , map_height )
92+ -- find center of visible part of the map
93+ local map_rect = gui .ViewRect {rect = world_rect }:viewport (viewport )
94+
95+ local half_x = math.floor ((map_rect .clip_x1 + map_rect .clip_x2 ) / 2 )
96+ local normalized_half_x = math.min (
97+ math.max (half_x , map_rect .clip_x1 ),
98+ map_rect .clip_x2
9299 )
93- local half_y = math.max (
94- math.floor ((viewport .y1 + viewport .y2 ) / 2 ),
95- 2
100+
101+ local half_y = math.floor ((map_rect .clip_y1 + map_rect .clip_y2 ) / 2 )
102+ local normalized_half_y = math.min (
103+ math.max (half_y , map_rect .clip_y1 ),
104+ map_rect .clip_y2
96105 )
97106
98- return half_x , half_y , viewport .z
107+ return normalized_half_x , normalized_half_y , viewport .z
99108end
100109
101110function test .load_notes_overlay ()
0 commit comments