indexing description: "[ An image pane, which holds an image (EM_BITMAP). ]" date: "$Date$" revision: "$Revision$" class IMAGE_PANE inherit EM_SHARED_BITMAP_FACTORY export {NONE} all undefine is_equal end COMPARABLE EM_SHARED_ERROR_HANDLER export {NONE} all undefine is_equal end create make feature -- Initialization make (image_file: STRING) is -- create an IMAGE_PANE object require image_file_not_void: image_file /= Void local error_occurred: BOOLEAN do if error_occurred then if error_handler.last_error_code = 2211 then error_code := 2 else error_code := 1 end else error_code := 0 bitmap_factory.create_bitmap_from_image (image_file) image := bitmap_factory.last_bitmap image_scaled := image transparency := 255 last_scale := 1 image_file_path := image_file end scale_x := 1 scale_y := 1 rescue error_occurred := True retry end feature -- Access x, y: DOUBLE -- Position of the top left corner of the image true_x, true_y: DOUBLE -- `x' and `y' are just temporary values -- `true_x' and `true_y' are the real values, of where the image pane is -- This is done because of the history and movement scale_x, scale_y: DOUBLE -- scale of the image (1 is original size) transparency: INTEGER -- transparency of the image (between 0 and 255) -- 0 being invisible and 255 visible image: EM_BITMAP -- bitmap of the current image image_scaled: EM_BITMAP -- currently saved scaled `image' z_index: INTEGER -- the level in z-direction. the greater `z_index', the later it will be displayed infix "<" (other: like Current): BOOLEAN is -- Is current integer less than `other'? do Result := z_index > other.z_index end is_selected: BOOLEAN -- is the current image pane selected by `selection_tool'? error_code: INTEGER -- error code for creation -- 0: no error -- 1: file not found -- 2: file type not supported image_file_path: STRING -- absolute image file path feature -- Element Change set_x_y (an_x, a_y: DOUBLE) is -- sets the top left corner of the pane do x := an_x y := a_y ensure x_set: x = an_x y_set: y = a_y end set_true_x_y (an_x, a_y: DOUBLE) is -- sets the top left corner of the pane do x := an_x y := a_y true_x := an_x true_y := a_y ensure x_set: x = an_x y_set: y = a_y true_x_set: true_x = an_x true_y_set: true_y = a_y end set_x (an_x: DOUBLE) is -- sets `x' do x := an_x ensure x_set: x = an_x end set_y (a_y: DOUBLE) is -- sets `y' do y := a_y ensure x_set: y= a_y end set_transparency (t: INTEGER) is -- set `transparency'. require t_valid: t >= 0 and t <= 255 do transparency := t ensure transparency_set: transparency = t end set_scale (a_scale_x, a_scale_y: DOUBLE) is -- set `scale'. require scale_valid: a_scale_x > 0 and a_scale_y > 0 do scale_x := a_scale_x scale_y := a_scale_y generate_image_scaled (last_scale) ensure scale_set: scale_x = a_scale_x and scale_y = a_scale_y end set_z_index (a_z_index: INTEGER) is -- set `z_index'. do z_index := a_z_index ensure z_index_set: z_index = a_z_index end set_selected (b: BOOLEAN) is -- sets `is_selected' do is_selected := b ensure selected_set: is_selected = b end feature -- Computation generate_image_scaled (a_scale: DOUBLE) is -- generates `image_scaled' depending on `scale_x', `scale_y' and `a_scale' require a_scale_valid: a_scale > 0 do if scale_x = scale_y then -- just zoom, no scaling needed bitmap_factory.create_zoomed_bitmap (image, scale_x * a_scale) else bitmap_factory.create_stretched_bitmap (image, scale_x * a_scale, scale_y * a_scale) end image_scaled := bitmap_factory.last_bitmap last_scale := a_scale end is_coordinate_on_image (an_x, a_y: DOUBLE): BOOLEAN is -- is the given coordinage (not screen position) on the image? do Result := an_x >= x and an_x <= x + image.width * scale_x and a_y >= y and a_y <= y + image.height * scale_y ensure result_set: Result = (an_x >= x and an_x <= x + image.width * scale_x and a_y >= y and a_y <= y + image.height * scale_y) end feature {NONE} -- Implementation last_scale: DOUBLE -- last scale given by `generate_image_scaled' invariant scale_valid: scale_x > 0 and scale_y > 0 transparency_valid: transparency >= 0 and transparency <= 255 end