indexing description: "[ A screen cursor ]" date: "$Date$" revision: "$Revision$" class EM_CURSOR inherit EM_SHARED_ERROR_HANDLER export {NONE} all end MEMORY redefine dispose end SDL_MOUSE_FUNCTIONS_EXTERNAL export {NONE} all end create make_from_surface create {EM_VIDEO_SUBSYSTEM} make_from_pointer feature {NONE} -- Initialisation make_from_surface (a_surface: EM_SURFACE; an_x, a_y: INTEGER) is -- Initialise cursor with data of `a_surface' and hot spot `an_x' `a_y'. -- Only black white color is allowed. Other color is transparent. -- The hot spot defines the pixel which is exactly on the mouse position. require a_surface_not_void: a_surface /= Void a_surface_width_multiple_of_8: a_surface.width \\ 8 = 0 a_surface_height_multiple_of_8: a_surface.height \\ 8 = 0 an_x_in_range: 0 <= an_x and an_x <= a_surface.width a_y_in_range: 0 <= a_y and a_y <= a_surface.height do a_surface.lock create_data_from_surface (a_surface) a_surface.unlock sdl_cursor := sdl_create_cursor_external (data.item, mask.item, a_surface.width, a_surface.height, an_x, a_y) if sdl_cursor = Default_pointer then Error_handler.raise_error (Error_handler.Em_error_create_cursor, []) end is_freeing_on_dispose := True data := Void mask := Void end make_from_pointer (a_pointer: POINTER; free_on_dispose: BOOLEAN) is -- Initialise cursor from `a_pointer'. require a_pointer_not_null: a_pointer /= Default_pointer do sdl_cursor := a_pointer is_freeing_on_dispose := free_on_dispose end feature -- Status setting show is -- Show cursor. do sdl_set_cursor_external (sdl_cursor) end feature {NONE} -- Implementation sdl_cursor: POINTER -- SDL cursor pointer is_freeing_on_dispose: BOOLEAN -- Is cursor freed on dispose? data: EWG_MANAGED_POINTER -- Data pointer mask: EWG_MANAGED_POINTER -- Mask pointer create_data_from_surface (a_surface: EM_SURFACE) is -- Create `data' and `mask' from `a_surface'. local row, col, i: INTEGER color: EM_COLOR do create data.make_new_unshared ((a_surface.width * a_surface.height) // 8) create mask.make_new_unshared ((a_surface.width * a_surface.height) // 8) i := -1 from row := 0 until row = a_surface.width loop from col := 0 until col = a_surface.height loop if (col \\ 8) /= 0 then data.put_integer_8 (data.read_integer_8 (i).bit_shift_left (1).as_integer_8, i) mask.put_integer_8 (mask.read_integer_8 (i).bit_shift_left (1).as_integer_8, i) else i := i + 1 data.put_integer_8 (0, i) mask.put_integer_8 (0, i) end color := a_surface.pixel_format.pixel_value_to_color (a_surface.pixel_value (col, row)) if color.red = 0 and color.green = 0 and color.blue = 0 and color.alpha = 255 then mask.put_integer_8 (mask.read_integer_8 (i).bit_or (0x01), i) data.put_integer_8 (data.read_integer_8 (i).bit_or (0x01), i) end if color.red = 255 and color.green = 255 and color.blue = 255 and color.alpha = 255 then mask.put_integer_8 (mask.read_integer_8 (i).bit_or (0x01), i) end col := col + 1 end row := row + 1 end end dispose is -- Free external resources. do if is_freeing_on_dispose then sdl_free_cursor_external (sdl_cursor) end Precursor end end