note
	description: "Representation of an image that can be paste on other image."
	author: "Louis Marchand"
	date: "Sat, 28 Mar 2015 14:00:33 +0000"
	revision: "2.0"

class interface
	GAME_SURFACE

create 
	make (a_width, a_height: INTEGER_32)
			-- Create an empty Current of dimension a_width x a_height
			-- conforming to the first founded GAME_DISPLAY.
		require
			surface_make_video_enabled: Game_library.is_video_enable
		ensure
			surface_make_is_open: has_error or is_open

	share_from_image (a_image: GAME_IMAGE)
			-- Create a Current from a_image_source.
			-- The image source in memory is not copied.
			-- If multiple surface is done with the same a_image,
			-- every modification to surface will affect all.
		require
			surface_make_video_enabled: Game_library.is_video_enable
			surface_make_from_image_source_is_open: a_image.is_open
		ensure
			surface_make_is_open: has_error or is_open

	make_from_image (a_image: GAME_IMAGE)
			-- Create a Current from a_image.
			-- The image source in memory is copied.
			-- Slower than share_from_image and use more memory.
			-- If multiple surface is done with the same a_image,
			-- every modification to surface will affect all.
		require
			surface_make_video_enabled: Game_library.is_video_enable
			surface_make_from_image_source_is_open: a_image.is_open
		ensure
			surface_make_is_open: has_error or is_open

	share_from_other (a_other: GAME_SURFACE)
			-- Create a Current from a_other.
			-- The image source in memory is not copied.
			-- If multiple surface is done with the same image,
			-- every modification to surface will affect all.
		require
			surface_make_video_enabled: Game_library.is_video_enable
			surface_make_other_opened: a_other.is_open
		ensure
			surface_make_is_open: has_error or is_open

	make_from_other (a_other: GAME_SURFACE)
			-- Create a Current from a_other.
			-- The image source in memory will be copied.
			-- Slower than share_from_other and use more memory.
		require
			surface_make_video_enabled: Game_library.is_video_enable
			surface_make_other_opened: a_other.is_open
		ensure
			surface_make_is_open: has_error or is_open

	make_for_window (a_window: GAME_WINDOW; a_width, a_height: INTEGER_32)
			-- Create an empty Current of dimension a_width x a_height
			-- conforming to a_window.
		require
			surface_make_video_enabled: Game_library.is_video_enable
		ensure
			surface_make_is_open: has_error or is_open

	make_for_display (a_display: GAME_DISPLAY; a_width, a_height: INTEGER_32)
			-- Create an empty Current of dimension a_width x a_height
			-- conforming to a_display.
		require
			surface_make_video_enabled: Game_library.is_video_enable
		ensure
			surface_make_is_open: has_error or is_open

	make_for_display_mode (a_display_mode: GAME_DISPLAY_MODE; a_width, a_height: INTEGER_32)
			-- Create an empty Current of dimension a_width x a_height
			-- conforming to a_display_mode.
		require
			surface_make_video_enabled: Game_library.is_video_enable
		ensure
			surface_make_is_open: has_error or is_open

	make_for_pixel_format (a_pixel_format: GAME_PIXEL_FORMAT_READABLE; a_width, a_height: INTEGER_32)
			-- Create an empty Current of dimension a_width x a_height
			-- conforming to a_pixel_format.
		require
			surface_make_video_enabled: Game_library.is_video_enable
		ensure
			surface_make_is_open: has_error or is_open

	make_with_masks (a_width, a_height, a_bits_per_pixel: INTEGER_32; a_rmask, a_gmask, a_bmask, a_amask: NATURAL_32)
			-- Initialization for Current.
			-- Create a new empty surface with RGBA mask and flags.
		require
			surface_make_video_enabled: Game_library.is_video_enable
		ensure
			surface_make_is_open: has_error or is_open

feature -- Access

	as_converted_to_pixel_format (a_pixel_format: GAME_PIXEL_FORMAT_READABLE): GAME_SURFACE
			-- Create a copy of Current conforming to a_pixel_format.
		require
			surface_is_video_enable: Game_library.is_video_enable
			surface_convert_is_open: is_open
			not_locked: not is_locked

	color_multiplier: TUPLE [red_multipier: NATURAL_8; green_multipier: NATURAL_8; blue_multipier: NATURAL_8]
			-- The additional color value multiplied into drawing operations
		require
			surface_is_open: is_open
			not_locked: not is_locked

	disable_blending
			-- Disable every blending mode to use for drawing operations.
			-- No blending mode:	dstRGBA = srcRGBA
			-- (from GAME_BLENDABLE)
		require -- from GAME_BLENDABLE
			blendable_is_valid: is_open

	disable_rle_acceleration
			-- Disable the possible optimisation when using drawing with transparent_color enabled or enable_alpha_blending.
		require
			surface_is_open: is_open
			not_locked: not is_locked

	disable_transparent
			-- Remove the transparency by color key.
		require
			surface_is_video_enable: Game_library.is_video_enable
			surface_is_open: is_open
			not_locked: not is_locked

	draw_rectangle (a_color: GAME_COLOR; a_x, a_y, a_width, a_height: INTEGER_32)
			-- Draw a a_color rectangle of dimension a_width x a_height on Current at (a_x,a_y).
		require
			surface_is_video_enable: Game_library.is_video_enable
			surface_draw_is_open: is_open
			not_locked: not is_locked

	draw_rectangles (a_color: GAME_COLOR; a_rectangles: CHAIN [TUPLE [x: INTEGER_32; y: INTEGER_32; width: INTEGER_32; height: INTEGER_32]])
			-- Drawing every a_color rectangle in a_rectangles
			-- that has it's left frontier at
			-- x, it's top frontier at y, with
			-- dimension widthxheight
		require
			surface_is_video_enable: Game_library.is_video_enable
			surface_draw_is_open: is_open
			not_locked: not is_locked

	draw_sub_surface (a_other: GAME_SURFACE; a_x_source, a_y_source, a_width, a_height, a_x_destination, a_y_destination: INTEGER_32)
			-- Draw on Current at (a_x_destination,a_y_destination) the portion of a_other
			-- starting at (a_x_source,a_y_source) with dimension a_width x a_height.
		require
			surface_is_video_enable: Game_library.is_video_enable
			surface_draw_is_open: is_open
			not_locked: not is_locked

	draw_sub_surface_with_scale (a_other: GAME_SURFACE; a_x_source, a_y_source, a_width_source, a_height_source, a_x_destination, a_y_destination, a_width_destination, a_height_destination: INTEGER_32)
			-- Draw on Current at (a_x_destination,a_y_destination) the portion of a_other
			-- starting at (a_x_source,a_y_source) with dimension a_width x a_height.
			-- Will scale a_other using a_width_destination and a_height_destination
		require
			surface_is_video_enable: Game_library.is_video_enable
			surface_draw_is_open: is_open
			not_locked: not is_locked

	draw_surface (a_other: GAME_SURFACE; a_x, a_y: INTEGER_32)
			-- Draw the whole surface a_other on Current at (a_x,a_y).
		require
			surface_is_video_enable: Game_library.is_video_enable
			surface_draw_is_open: is_open
			not_locked: not is_locked

	enable_additive_blending
			-- Set the additive blending mode to use for drawing operations.
			-- Additive blending:	dstRGB = (srcRGB * srcA) + dstRGB
			--						dstA = dstA
			-- (from GAME_BLENDABLE)
		require -- from GAME_BLENDABLE
			blendable_is_valid: is_open

	enable_alpha_blending
			-- Set the alpha blending mode to use for drawing operations.
			-- Alpha blending:	dstRGB = (srcRGB * srcA) + (dstRGB * (1-srcA))
			--					dstA = srcA + (dstA * (1-srcA))
			-- (from GAME_BLENDABLE)
		require -- from GAME_BLENDABLE
			blendable_is_valid: is_open

	enable_modulate_blending
			-- Set the color modulate blending mode to use for drawing operations.
			-- Color modulate:	dstRGB = srcRGB * dstRGB
			--					dstA = dstA
			-- (from GAME_BLENDABLE)
		require -- from GAME_BLENDABLE
			blendable_is_valid: is_open

	enable_rle_acceleration
			-- Enable possible optimisation when using drawing with transparent_color enabled or enable_alpha_blending.
		require
			surface_is_open: is_open
			not_locked: not is_locked

	Game_library: GAME_LIBRARY_CONTROLLER
			-- The main controller of the game library
			-- (from GAME_LIBRARY_SHARED)

	generating_type: TYPE [detachable GAME_SURFACE]
			-- Type of current object
			-- (type of which it is a direct instance)
			-- (from ANY)
		ensure -- from ANY
			generating_type_not_void: Result /= Void

	generator: STRING_8
			-- Name of current object's generating class
			-- (base class of the type of which it is a direct instance)
			-- (from ANY)
		ensure -- from ANY
			generator_not_void: Result /= Void
			generator_not_empty: not Result.is_empty

	has_error: BOOLEAN
			-- Is the library has generate an error
			-- (from GAME_ERROR_MANAGER)

	height: INTEGER_32
			-- The height of Current.
		require
			surface_is_open: is_open

	image: GAME_IMAGE
			-- The GAME_IMAGE that has served for creating Current

	is_additive_blending_enabled: BOOLEAN
			-- True if the blending mode for drawing operation is additive blending.
			-- Additive blending:	dstRGB = (srcRGB * srcA) + dstRGB
			--						dstA = dstA
			-- (from GAME_BLENDABLE)
		require -- from GAME_BLENDABLE
			blendable_is_valid: is_open

	is_alpha_blending_enabled: BOOLEAN
			-- True if the blending mode for drawing operation is alpha blending.
			-- Alpha blending:	dstRGB = (srcRGB * srcA) + (dstRGB * (1-srcA))
			--					dstA = srcA + (dstA * (1-srcA))
			-- (from GAME_BLENDABLE)
		require -- from GAME_BLENDABLE
			blendable_is_valid: is_open

	is_blending_disabled: BOOLEAN
			-- True if no blending mode is used for drawing operations.
			-- No blending mode:	dstRGBA = srcRGBA
			-- (from GAME_BLENDABLE)
		require -- from GAME_BLENDABLE
			blendable_is_valid: is_open

	is_locked: BOOLEAN
			-- Current is locked to access pixels. Current cannot be used until unlock is called.

	is_modulate_blending_enabled: BOOLEAN
			-- True if the blending mode for drawing operation is color modulate blending.
			-- Color modulate:	dstRGB = srcRGB * dstRGB
			--					dstA = dstA
			-- (from GAME_BLENDABLE)
		require -- from GAME_BLENDABLE
			blendable_is_valid: is_open

	is_open: BOOLEAN
			-- Current has been opened properly

	is_transparent_enable: BOOLEAN
			-- Is transparency by color key is enabled.
		require
			surface_is_video_enable: Game_library.is_video_enable
			surface_is_open: is_open
			not_locked: not is_locked

	last_error: READABLE_STRING_GENERAL
			-- The last error generate by the library
			-- (from GAME_SDL_ANY)

	lock
			-- Lock Current to access pixels.
			-- Must used unlock after the edition.
			-- You cannot draw on Current while locked.
		ensure
			is_locked: not has_error implies is_locked

	must_lock: BOOLEAN
			-- Current must be locked for pixel access

	overall_alpha: NATURAL_8 assign set_overall_alpha
			-- The Additionnal alpha value to use in drawing operation.
		require
			surface_is_open: is_open
			not_locked: not is_locked

	pixel_format: GAME_PIXEL_FORMAT_READABLE
			-- The internal format of the pixel representation in memory.
		require
			surface_is_video_enable: Game_library.is_video_enable
			surface_pixel_format_is_open: is_open

	pixels: GAME_PIXEL_READER_WRITER
			-- Used to fetch and edit pixels in Current
			-- Use lock before to access multiple pixels
		require
			locked_if_needed: must_lock implies is_locked

	save_bmp (a_filename: READABLE_STRING_GENERAL)
			-- Save Current into a BMP image file
		require
			surface_is_open: is_open

	set_color_multiplier (a_red_multiplier, a_green_multiplier, a_blue_multiplier: NATURAL_8)
			-- Assign the Additionnal color_multiplier value to use into drawing operation to a_red_multiplier,
			-- a_green_multiplier, a_blue_multiplier.
		require
			surface_is_open: is_open
			not_locked: not is_locked

	set_overall_alpha (a_overall_alpha: NATURAL_8)
			-- Assign the Additionnal overall_alpha value to use in drawing operation to a_overall_alpha.
		require
			surface_is_open: is_open
			not_locked: not is_locked

	set_transparent_color (a_color: GAME_COLOR_READABLE)
			-- Change all pixel of color color into transparency (and enable it). The transparency by color don't work if the surface
			-- have an alpha blending activated.
		require
			surface_is_video_enable: Game_library.is_video_enable
			surface_is_open: is_open
			not_locked: not is_locked

	transparent_color: GAME_COLOR_READABLE assign set_transparent_color
			-- The color that will be remove in the surface (the transparent color).
		require
			surface_is_video_enable: Game_library.is_video_enable
			surface_is_open: is_open
			surface_transparent_color_is_enable: is_transparent_enable
			not_locked: not is_locked

	unlock
			-- Unlock Current after access pixels.
		require
			is_locked: is_locked
		ensure
			not_locked: not is_locked

	width: INTEGER_32
			-- The width of Current.
		require
			surface_is_open: is_open
	
feature -- Comparison

	frozen deep_equal (a: detachable ANY; b: like arg #1): BOOLEAN
			-- Are a and b either both void
			-- or attached to isomorphic object structures?
			-- (from ANY)
		ensure -- from ANY
			instance_free: class
			shallow_implies_deep: standard_equal (a, b) implies Result
			both_or_none_void: (a = Void) implies (Result = (b = Void))
			same_type: (Result and (a /= Void)) implies (b /= Void and then a.same_type (b))
			symmetric: Result implies deep_equal (b, a)

	frozen equal (a: detachable ANY; b: like arg #1): BOOLEAN
			-- Are a and b either both void or attached
			-- to objects considered equal?
			-- (from ANY)
		ensure -- from ANY
			instance_free: class
			definition: Result = (a = Void and b = Void) or else ((a /= Void and b /= Void) and then a.is_equal (b))

	frozen is_deep_equal alias "≡≡≡" (other: GAME_SURFACE): BOOLEAN
			-- Are Current and other attached to isomorphic object structures?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		ensure -- from ANY
			shallow_implies_deep: standard_is_equal (other) implies Result
			same_type: Result implies same_type (other)
			symmetric: Result implies other.is_deep_equal (Current)

	is_equal (other: GAME_SURFACE): BOOLEAN
			-- Is other attached to an object considered
			-- equal to current object?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		ensure -- from ANY
			symmetric: Result implies other ~ Current
			consistent: standard_is_equal (other) implies Result

	frozen standard_equal (a: detachable ANY; b: like arg #1): BOOLEAN
			-- Are a and b either both void or attached to
			-- field-by-field identical objects of the same type?
			-- Always uses default object comparison criterion.
			-- (from ANY)
		ensure -- from ANY
			instance_free: class
			definition: Result = (a = Void and b = Void) or else ((a /= Void and b /= Void) and then a.standard_is_equal (b))

	frozen standard_is_equal alias "" (other: GAME_SURFACE): BOOLEAN
			-- Is other attached to an object of the same type
			-- as current object, and field-by-field identical to it?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		ensure -- from ANY
			same_type: Result implies same_type (other)
			symmetric: Result implies other.standard_is_equal (Current)
	
feature -- Status report

	conforms_to (other: ANY): BOOLEAN
			-- Does type of current object conform to type
			-- of other (as per Eiffel: The Language, chapter 13)?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void

	same_type (other: ANY): BOOLEAN
			-- Is type of current object identical to type of other?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		ensure -- from ANY
			definition: Result = (conforms_to (other) and other.conforms_to (Current))
	
feature -- Duplication

	copy (other: GAME_SURFACE)
			-- Update current object using fields of object attached
			-- to other, so as to yield equal objects.
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
			type_identity: same_type (other)
		ensure -- from ANY
			is_equal: Current ~ other

	frozen deep_copy (other: GAME_SURFACE)
			-- Effect equivalent to that of:
			--		copy (other . deep_twin)
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		ensure -- from ANY
			deep_equal: deep_equal (Current, other)

	frozen deep_twin: GAME_SURFACE
			-- New object structure recursively duplicated from Current.
			-- (from ANY)
		ensure -- from ANY
			deep_twin_not_void: Result /= Void
			deep_equal: deep_equal (Current, Result)

	frozen standard_copy (other: GAME_SURFACE)
			-- Copy every field of other onto corresponding field
			-- of current object.
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
			type_identity: same_type (other)
		ensure -- from ANY
			is_standard_equal: standard_is_equal (other)

	frozen standard_twin: GAME_SURFACE
			-- New object field-by-field identical to other.
			-- Always uses default copying semantics.
			-- (from ANY)
		ensure -- from ANY
			standard_twin_not_void: Result /= Void
			equal: standard_equal (Result, Current)

	frozen twin: GAME_SURFACE
			-- New object equal to Current
			-- twin calls copy; to change copying/twinning semantics, redefine copy.
			-- (from ANY)
		ensure -- from ANY
			twin_not_void: Result /= Void
			is_equal: Result ~ Current
	
feature -- Basic operations

	frozen default: detachable GAME_SURFACE
			-- Default value of object's type
			-- (from ANY)

	frozen default_pointer: POINTER
			-- Default value of type POINTER
			-- (Avoid the need to write p.default for
			-- some p of type POINTER.)
			-- (from ANY)
		ensure -- from ANY
			instance_free: class

	default_rescue
			-- Process exception for routines with no Rescue clause.
			-- (Default: do nothing.)
			-- (from ANY)

	frozen do_nothing
			-- Execute a null action.
			-- (from ANY)
		ensure -- from ANY
			instance_free: class
	
feature -- Output

	Io: STD_FILES
			-- Handle to standard file setup
			-- (from ANY)
		ensure -- from ANY
			instance_free: class
			io_not_void: Result /= Void

	out: STRING_8
			-- New string containing terse printable representation
			-- of current object
			-- (from ANY)
		ensure -- from ANY
			out_not_void: Result /= Void

	print (o: detachable ANY)
			-- Write terse external representation of o
			-- on standard output.
			-- (from ANY)
		ensure -- from ANY
			instance_free: class

	frozen tagged_out: STRING_8
			-- New string containing terse printable representation
			-- of current object
			-- (from ANY)
		ensure -- from ANY
			tagged_out_not_void: Result /= Void
	
feature -- Platform

	Operating_environment: OPERATING_ENVIRONMENT
			-- Objects available from the operating system
			-- (from ANY)
		ensure -- from ANY
			instance_free: class
			operating_environment_not_void: Result /= Void
	
invariant
	surface_valid: is_open implies image.is_open

		-- from ANY
	reflexive_equality: standard_is_equal (Current)
	reflexive_conformance: conforms_to (Current)

end -- class GAME_SURFACE

Generated by ISE EiffelStudio