indexing description: "[ a TOOL handles events accordingly. ]" date: "$Date$" revision: "$Revision$" deferred class TOOL inherit EM_SHARED_BITMAP_FACTORY export {NONE} all end feature -- Initialization make (a_scene: SCENE) is -- creation procedure require a_scene_not_void: a_scene /= Void do scene := a_scene create hand_cursor_closed.make create hand_cursor_open.make create arrow_cursor.make create zoom_cursor.make create polygon_close_cursor.make create polygon_cross_cursor.make create move_cursor.make ensure scene_set: scene = a_scene end feature -- Access scene: SCENE -- the scene on which the tool is to be used cursor: MOUSE_CURSOR is -- appropriate cursor deferred end is_pressed: BOOLEAN -- is the mouse button pressed? x, y: INTEGER -- position of the mouse last_x, last_y: INTEGER -- save last positions feature -- Element change set_scene (a_scene: SCENE) is -- sets `scene' require a_scene_not_void: a_scene /= Void do scene := a_scene ensure scene_set: scene = a_scene end set_toolchanged is -- tool will change after this - clean up do end feature -- Event Handling handle_mouse_button_down_event (event: EM_MOUSEBUTTON_EVENT) is -- Handle mouse button down event. require event_not_void: event /= Void deferred end handle_mouse_button_up_event (event: EM_MOUSEBUTTON_EVENT) is -- Handle mouse button up event. require event_not_void: event /= Void deferred end handle_mouse_motion_event (event: EM_MOUSEMOTION_EVENT) is -- Handle mouse motion event. require event_not_void: event /= Void deferred end handle_key_down_event (event: EM_KEYBOARD_EVENT) is -- Handle key down event. require event_not_void: event /= Void deferred end handle_key_up_event (event: EM_KEYBOARD_EVENT) is -- Handle key down event. require event_not_void: event /= Void deferred end feature {NONE} -- Implementation hand_cursor_open: HAND_CURSOR_OPEN -- open hand cursor hand_cursor_closed: HAND_CURSOR_CLOSED -- closed hand cursor arrow_cursor: ARROW_CURSOR -- arrow cursor zoom_cursor: ZOOM_CURSOR -- zoom_cursor polygon_close_cursor: CLOSE_POLY_CURSOR -- close polygon cursor polygon_cross_cursor: POLYGON_CROSS_CURSOR -- polygon cross cursor move_cursor: MOVE_CURSOR -- move cursor transform_position (an_x, a_y: INTEGER): EM_VECTOR_2D is -- returns the transformed position of the mouse local top_left_x, top_left_y: DOUBLE do top_left_x := scene.center_x - scene.half_screen_width / scene.scale top_left_y := scene.center_y - scene.half_screen_height / scene.scale create Result.make (an_x / scene.scale + top_left_x, a_y / scene.scale + top_left_y) end invariant scene_not_void: scene /= Void hand_cursor_open_not_void: hand_cursor_open /= Void hand_cursor_closed_not_void: hand_cursor_closed /= Void arrow_cursor_not_void: arrow_cursor /= Void zoom_cursor_not_void: zoom_cursor /= Void end