@@ -22,7 +22,7 @@ local function install_notes_overlay(options)
2222
2323 overlay .rescan ()
2424 overlay .overlay_command ({' enable' , ' notes.map_notes' })
25- -- if overlay
25+
2626 local overlay_state = overlay .get_state ()
2727 if not overlay_state .config [' notes.map_notes' ].enabled then
2828 qerror (' can not enable notes.map_notes overlay' )
@@ -62,6 +62,27 @@ local function add_note(notes_overlay, pos, name, comment)
6262 gui .simulateInput (dfhack .gui .getCurViewscreen (true ), ' CUSTOM_CTRL_ENTER' )
6363end
6464
65+ function assert_note_pen (pen )
66+ if dfhack .screen .inGraphicsMode () then
67+ local pin_textpos = dfhack .textures .getTexposByHandle (
68+ notes_textures .green_pin [1 ]
69+ )
70+ expect .eq (pen and pen .tile , pin_textpos )
71+ else
72+ expect .eq (pen and pen .ch , string.byte (' N' ))
73+ end
74+ end
75+
76+ function set_mouse_screen_pos (screen_pos )
77+ -- should not be a test function to map screen tile to mouse pos?
78+ df .global .gps .precise_mouse_x = screen_pos .x * df .global .gps .viewport_zoom_factor / 4
79+ df .global .gps .precise_mouse_y = screen_pos .y * df .global .gps .viewport_zoom_factor / 4
80+
81+ df .global .gps .mouse_x = screen_pos .x
82+ df .global .gps .mouse_y = screen_pos .y
83+
84+ end
85+
6586function test .load_notes_overlay ()
6687 local notes_overlay = install_notes_overlay ()
6788 expect .ne (notes_overlay , nil )
@@ -90,26 +111,22 @@ function test.render_existing_notes()
90111 local half_x = math.floor ((viewport .x1 + viewport .x2 ) / 2 )
91112 local half_y = math.floor ((viewport .y1 + viewport .y2 ) / 2 )
92113
93- local pos_1 = {x = half_x , y = viewport . y1 , z = viewport .z }
94- local pos_2 = {x = viewport . x1 , y = half_y , z = viewport .z }
95- local pos_3 = {x = half_x , y = half_y , z = viewport .z }
114+ local pos_1 = {x = half_x , y = half_y , z = viewport .z }
115+ local pos_2 = {x = half_x - 2 , y = half_y + 2 , z = viewport .z }
116+ local pos_3 = {x = half_x + 2 , y = half_y + 2 , z = viewport .z }
96117
97118 add_note (notes_overlay , pos_1 , ' note 1' , ' first note' )
98119 add_note (notes_overlay , pos_2 , ' note 2' , ' second note' )
99120 add_note (notes_overlay , pos_3 , ' note 3' , ' last note' )
100121
101122 reload_notes ()
102123
103- local pin_textpos = dfhack .textures .getTexposByHandle (
104- notes_textures .green_pin [1 ]
105- )
106-
107124 for _ , pos in ipairs ({pos_1 , pos_2 , pos_3 }) do
108125 notes_overlay :render (gui .Painter .new ())
109126
110127 local screen_pos = viewport :tileToScreen (pos )
111128 local pen = dfhack .screen .readTile (screen_pos .x , screen_pos .y , true )
112- expect . eq (pen and pen . tile , pin_textpos )
129+ assert_note_pen (pen )
113130 end
114131
115132 cleanup (notes_overlay )
@@ -123,9 +140,9 @@ function test.edit_clicked_note()
123140 local half_x = math.floor ((viewport .x1 + viewport .x2 ) / 2 )
124141 local half_y = math.floor ((viewport .y1 + viewport .y2 ) / 2 )
125142
126- local pos_1 = {x = half_x , y = viewport . y1 , z = viewport .z }
127- local pos_2 = {x = viewport . x1 , y = half_y , z = viewport .z }
128- local pos_3 = {x = half_x , y = half_y , z = viewport .z }
143+ local pos_1 = {x = half_x , y = half_y , z = viewport .z }
144+ local pos_2 = {x = half_x - 2 , y = half_y + 2 , z = viewport .z }
145+ local pos_3 = {x = half_x + 2 , y = half_y + 2 , z = viewport .z }
129146
130147 add_note (notes_overlay , pos_1 , ' note 1' , ' note to edit' )
131148 add_note (notes_overlay , pos_2 , ' note 2' , ' other note' )
@@ -135,19 +152,16 @@ function test.edit_clicked_note()
135152
136153 local screen_pos = viewport :tileToScreen (pos_1 )
137154
138- local rect = gui . ViewRect { rect = notes_overlay . frame_rect }
155+ set_mouse_screen_pos ( screen_pos )
139156
140- -- should not be a test function to map screen tile to mouse pos?
141- df .global .gps .precise_mouse_x = screen_pos .x * df .global .gps .viewport_zoom_factor / 4
142- df .global .gps .precise_mouse_y = screen_pos .y * df .global .gps .viewport_zoom_factor / 4
143-
144- local screen = dfhack .gui .getCurViewscreen (true )
145- gui .simulateInput (screen , {
157+ gui .simulateInput (dfhack .gui .getCurViewscreen (true ), {
146158 _MOUSE_L = true ,
159+ _MOUSE_L_DOWN = true ,
147160 })
148161
149162 local note_manager = notes_overlay .note_manager
150163 expect .ne (note_manager , nil )
164+ expect .eq (note_manager :isDismissed (), false )
151165
152166 expect .eq (note_manager .subviews .name :getText (), ' note 1' )
153167 expect .eq (note_manager .subviews .comment :getText (), ' note to edit' )
@@ -171,9 +185,9 @@ function test.delete_clicked_note()
171185 local half_x = math.floor ((viewport .x1 + viewport .x2 ) / 2 )
172186 local half_y = math.floor ((viewport .y1 + viewport .y2 ) / 2 )
173187
174- local pos_1 = {x = half_x , y = viewport . y1 , z = viewport .z }
175- local pos_2 = {x = viewport . x1 , y = half_y , z = viewport .z }
176- local pos_3 = {x = half_x , y = half_y , z = viewport .z }
188+ local pos_1 = {x = half_x , y = half_y , z = viewport .z }
189+ local pos_2 = {x = half_x - 2 , y = half_y + 2 , z = viewport .z }
190+ local pos_3 = {x = half_x + 2 , y = half_y + 2 , z = viewport .z }
177191
178192 add_note (notes_overlay , pos_1 , ' note 1' , ' note to edit' )
179193 add_note (notes_overlay , pos_2 , ' note 2' , ' other note' )
@@ -185,13 +199,11 @@ function test.delete_clicked_note()
185199
186200 local rect = gui .ViewRect {rect = notes_overlay .frame_rect }
187201
188- -- should not be a test function to map screen tile to mouse pos?
189- df .global .gps .precise_mouse_x = screen_pos .x * df .global .gps .viewport_zoom_factor / 4
190- df .global .gps .precise_mouse_y = screen_pos .y * df .global .gps .viewport_zoom_factor / 4
202+ set_mouse_screen_pos (screen_pos )
191203
192- local screen = dfhack .gui .getCurViewscreen (true )
193- gui .simulateInput (screen , {
204+ gui .simulateInput (dfhack .gui .getCurViewscreen (true ), {
194205 _MOUSE_L = true ,
206+ _MOUSE_L_DOWN = true ,
195207 })
196208
197209 expect .eq (# map_points , 3 )
0 commit comments