indexing description: "[ Graphical objects that are defined through a sequence of 2-dimensional points. All graphical objects that are defined through a lot of points (like Polygons, Polylines etc.) and can be modified like a list should inherit from this class. The given default implementation just draws all contained points as points. ]" date: "$Date$" revision: "$Revision$" class EM_MULTI_POINTED_FIGURE inherit DS_LINKED_LIST [EM_VECTOR_2D] rename put_last as extend, extend as extend_with_list undefine default_create redefine make_from_array, extend end EM_FIGURE undefine is_equal, copy redefine publish_mouse_event end create make_empty, make_from_list, make_from_array feature {NONE} -- Initialization make_empty is -- Initialize with no points. do default_create if count /= 0 then wipe_out end make points := Current update_bounding_box set_visible (True) ensure points_are_empty: is_empty is_visible: is_visible end make_from_list (a_point_list: LIST [EM_VECTOR_2D]) is -- Initialize with points in `a_point_list' require a_point_list_not_void: a_point_list /= Void local old_cursor: CURSOR do make_empty old_cursor := a_point_list.cursor from a_point_list.start until a_point_list.after loop extend (a_point_list.item) extend_bounding_box (a_point_list.item) a_point_list.forth end a_point_list.go_to (old_cursor) ensure correct_position: before filled: count = a_point_list.count is_visible: is_visible end make_from_array (a_point_array: ARRAY [EM_VECTOR_2D]) is -- Initialize with points in `a_point_array'. do make_empty Precursor (a_point_array) update_bounding_box ensure then is_visible: is_visible end feature -- Basic operations extend (point: EM_VECTOR_2D) is -- Add `point' to end of list. -- Do not move cursors. -- Also extend `bounding_box' to contain `point'. -- (Performance: O(1).) do Precursor (point) extend_bounding_box (point) ensure then bounding_box_extended: bounding_box.has (point) end feature -- Drawing draw (drawing_interface: EM_SURFACE) is -- Draw `Current' using `drawing_interface'. local cursor: DS_LINKED_LIST_CURSOR [EM_VECTOR_2D] clipping_area: EM_RECTANGLE point: EM_VECTOR_2D do if is_visible then -- Get clipping area to only draw visible points. clipping_area := drawing_interface.coordinate_area -- Draw all points as pixels with `color'. drawing_interface.set_drawing_color (line_color) drawing_interface.set_line_width (line_width) cursor := new_cursor from cursor.start until cursor.after loop point := cursor.item if clipping_area.has (point) then drawing_interface.draw_point (point) end cursor.forth end end end feature -- Mouse Events publish_mouse_event (a_mouse_event: EM_MOUSE_EVENT) is -- Publish mouse event when `a_mouse_event' occured on `Current'. -- Only publish mouse event, if `proportional_point' lies on a point. local caught: BOOLEAN cursor: DS_LINKED_LIST_CURSOR [EM_VECTOR_2D] half_line_width: DOUBLE do half_line_width := line_width / 2 cursor := new_cursor from cursor.start until cursor.after or caught loop if a_mouse_event.proportional_position.distance (cursor.item) < half_line_width then caught := True end cursor.forth end if caught then dispatch_mouse_event (a_mouse_event) a_mouse_event.set_caught (True) end end end