indexing description: "[ same as SELECTION_TOOL, just in vertex mode. ]" date: "$Date$" revision: "$Revision$" class VERTEX_SELECTION_TOOL inherit TOOL redefine make, set_toolchanged end create make feature -- Initialization make (a_scene: SCENE) is -- creation procedure do Precursor {TOOL} (a_scene) end feature -- Access cursor: MOUSE_CURSOR is -- appropriate cursor do if scene.focus_on_scene then if dragging_vertex /= Void then Result := dragging_vertex.cursor elseif is_over_vertex /= Void then Result := is_over_vertex.cursor else Result := arrow_cursor end else Result := arrow_cursor end end feature -- Event Handling handle_mouse_button_down_event (event: EM_MOUSEBUTTON_EVENT) is -- Handle mouse button down event. do if scene.focus_on_scene and event.is_left_button then is_pressed := True select_drag_start_coords := scene.coordinates_from_screen_position (x, y) select_drag_start_screen_position := create {EM_VECTOR_2D}.make (x, y) if is_over_vertex /= Void then dragging_vertex := is_over_vertex else dragging_vertex := Void end end end handle_mouse_button_up_event (event: EM_MOUSEBUTTON_EVENT) is -- Handle mouse button up event. do if event.is_left_button then is_pressed := False end if dragging_vertex /= Void then scene.history.execute (dragging_vertex.command, dragging_vertex.args) if scene.history.execute_successful then scene.set_changed end dragging_vertex.set_selected (False) dragging_vertex := Void end select_drag_start_coords := Void select_drag_start_screen_position := Void end handle_mouse_motion_event (event: EM_MOUSEMOTION_EVENT) is -- Handle mouse motion event. local circles: DS_LINKED_LIST_CURSOR [CIRCLE] rectangles: DS_LINKED_LIST_CURSOR [RECTANGLE] polygons: DS_LINKED_LIST_CURSOR [POLYGON] vertexes: DS_LINKED_LIST_CURSOR [VERTEX] do x := event.screen_x y := event.screen_y - 32 if is_pressed and event.button_state_left then -- the mouse is dragged over the scene if dragging_vertex /= Void and select_drag_start_coords /= Void then dragging_vertex.set_vector (create {EM_VECTOR_2D}.make (x,y)) dragging_vertex.object.set_vertexes_updated end end -- update `is_over_vertex' and `is_over_object' if scene.focus_on_scene then if is_over_vertex /= Void then is_over_vertex.set_selected (False) is_over_vertex := Void end create circles.make (scene.circles) from circles.start until circles.off or is_over_vertex /= Void loop create vertexes.make (circles.item.vertex_list) -- loop through vertexes from vertexes.start until vertexes.off or is_over_vertex /= Void loop if vertexes.item.is_point_over_vertex (x, y) then is_over_vertex := vertexes.item is_over_vertex.set_selected (True) end vertexes.forth end circles.forth end create rectangles.make (scene.rectangles) from rectangles.start until rectangles.off or is_over_vertex /= Void loop create vertexes.make (rectangles.item.vertex_list) -- loop through vertexes from vertexes.start until vertexes.off or is_over_vertex /= Void loop if vertexes.item.is_point_over_vertex (x, y) then is_over_vertex := vertexes.item is_over_vertex.set_selected (True) end vertexes.forth end rectangles.forth end create polygons.make (scene.polygons) from polygons.start until polygons.off or is_over_vertex /= Void loop create vertexes.make (polygons.item.vertex_list) -- loop through vertexes from vertexes.start until vertexes.off or is_over_vertex /= Void loop if vertexes.item.is_point_over_vertex (x, y) then is_over_vertex := vertexes.item is_over_vertex.set_selected (True) end vertexes.forth end polygons.forth end end if dragging_vertex /= Void then dragging_vertex.set_selected (True) end last_x := x last_y := y end handle_key_down_event (event: EM_KEYBOARD_EVENT) is -- Handle key down event. do end handle_key_up_event (event: EM_KEYBOARD_EVENT) is -- Handle key up event. do end feature -- Element Change set_toolchanged is -- tool was changed, unselect all items do unselect_all_selected end feature {NONE} -- Implementation unselect_all_selected is -- unselects all selected elements do if is_over_vertex /= Void then is_over_vertex.set_selected (False) is_over_vertex := Void end end select_drag_start_coords, select_drag_start_screen_position: EM_VECTOR_2D -- where the mouse started dragging is_over_vertex: VERTEX -- is the mouse currently over a vertex? dragging_vertex: VERTEX -- is the tool dragging a vertex? end