@@ -135,12 +135,26 @@ def _fpl_add_plot_area_hook(self, plot_area):
135135 self ._plot_area = plot_area
136136
137137 # when the pointer is pressed on a fill, edge or vertex
138- for wo in self ._world_objects :
139- pfunc_down = partial (self ._move_start , wo )
140- wo .add_event_handler (pfunc_down , "pointer_down" )
141-
142- # double-click to enable arrow-key moveable mode
143- wo .add_event_handler (self ._toggle_arrow_key_moveable , "double_click" )
138+ # we cannot just do self.world_object.add_event_handler
139+ # since we need to know if the event source was an edge,
140+ # fill, or a vertex
141+ # for wo in self._world_objects:
142+ # # pfunc_down = partial(self._move_start, wo)
143+ # wo.add_event_handler(self._move_start, "pointer_down")
144+ #
145+ # # double-click to enable arrow-key moveable mode
146+ # wo.add_event_handler(self._toggle_arrow_key_moveable, "double_click")
147+ #
148+ # # when the pointer moves
149+ # wo.add_event_handler(self._move, "pointer_move")
150+ #
151+ # # when the pointer is released
152+ # wo.add_event_handler(self._move_end, "pointer_up")
153+
154+ self .add_event_handler (self ._move_start , "pointer_down" )
155+ self .add_event_handler (self ._move , "pointer_move" )
156+ self .add_event_handler (self ._move_end , "pointer_up" )
157+ self .add_event_handler (self ._toggle_arrow_key_moveable , "double_click" )
144158
145159 for fill in self ._fill :
146160 if fill .material .color_is_transparent :
@@ -149,12 +163,6 @@ def _fpl_add_plot_area_hook(self, plot_area):
149163 self ._pfunc_fill , "pointer_down"
150164 )
151165
152- # when the pointer moves
153- self ._plot_area .renderer .add_event_handler (self ._move , "pointer_move" )
154-
155- # when the pointer is released
156- self ._plot_area .renderer .add_event_handler (self ._move_end , "pointer_up" )
157-
158166 # move directly to location of center mouse button click
159167 self ._plot_area .renderer .add_event_handler (self ._move_to_pointer , "click" )
160168
@@ -191,9 +199,11 @@ def _check_fill_pointer_event(self, event_source: WorldObject, ev):
191199 if not (ymin <= world_pos [1 ] <= ymax ):
192200 return
193201
194- self . _move_start ( event_source , ev )
202+ ev . target = event_source
195203
196- def _move_start (self , event_source : WorldObject , ev ):
204+ self ._move_start (ev )
205+
206+ def _move_start (self , ev ):
197207 """
198208 Called on "pointer_down" events
199209
@@ -210,10 +220,13 @@ def _move_start(self, event_source: WorldObject, ev):
210220 """
211221 last_position = self ._plot_area .map_screen_to_world (ev )
212222
213- self ._move_info = MoveInfo (last_position = last_position , source = event_source )
223+ self ._move_info = MoveInfo (last_position = last_position , source = ev . target )
214224 self ._moving = True
225+ print (self ._move_info )
215226
216- self ._initial_controller_state = self ._plot_area .controller .enabled
227+ # capture pointer until "pointer_up" event
228+ self .world_object .set_pointer_capture (ev .pointer_id , ev .root )
229+ print ("move start" )
217230
218231 def _move (self , ev ):
219232 """
@@ -230,9 +243,6 @@ def _move(self, ev):
230243 if self ._move_info is None :
231244 return
232245
233- # disable controller during moves
234- self ._plot_area .controller .enabled = False
235-
236246 # get pointer current world position
237247 world_pos = self ._plot_area .map_screen_to_world (ev )
238248
@@ -249,21 +259,15 @@ def _move(self, ev):
249259 # update last position
250260 self ._move_info .last_position = world_pos
251261
252- # restore the initial controller state
253- # if it was disabled, keep it disabled
254- self ._plot_area .controller .enabled = self ._initial_controller_state
255-
256262 def _move_graphic (self , delta : np .ndarray ):
257263 raise NotImplementedError ("Must be implemented in subclass" )
258264
259265 def _move_end (self , ev ):
266+ self .world_object .release_pointer_capture (ev .pointer_id )
260267 self ._move_info = None
261268 self ._moving = False
262269
263- # restore the initial controller state
264- # if it was disabled, keep it disabled
265- if self ._initial_controller_state is not None :
266- self ._plot_area .controller .enabled = self ._initial_controller_state
270+ self ._pointer_leave (ev )
267271
268272 def _move_to_pointer (self , ev ):
269273 """
0 commit comments