note
	description: "An object that can use alpha blending"
	author: "Louis Marchand"
	date: "Thu, 26 Mar 2015 20:59:26 +0000"
	revision: "2.0"

deferred class 
	GAME_BLENDABLE

inherit
	GAME_SDL_ANY

feature -- Access

	is_valid: BOOLEAN
			-- Is item a valid pointer to be used as blenderable
		deferred
		end

	disable_blending
			-- Disable every blending mode to use for drawing operations.
			-- No blending mode:	dstRGBA = srcRGBA
		require
			blendable_is_valid: is_valid
		do
			set_blend_mode ({GAME_SDL_EXTERNAL}.sdl_blendmode_none)
		end

	is_blending_disabled: BOOLEAN
			-- True if no blending mode is used for drawing operations.
			-- No blending mode:	dstRGBA = srcRGBA
		require
			blendable_is_valid: is_valid
		local
			l_blending_mode: INTEGER_32
		do
			l_blending_mode := blend_mode
			if not has_error then
				Result := l_blending_mode = {GAME_SDL_EXTERNAL}.sdl_blendmode_none
			else
				Result := False
			end
		end

	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))
		require
			blendable_is_valid: is_valid
		do
			set_blend_mode ({GAME_SDL_EXTERNAL}.sdl_blendmode_blend)
		end

	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))
		require
			blendable_is_valid: is_valid
		local
			l_blending_mode: INTEGER_32
		do
			l_blending_mode := blend_mode
			if not has_error then
				Result := l_blending_mode = {GAME_SDL_EXTERNAL}.sdl_blendmode_blend
			else
				Result := False
			end
		end

	enable_additive_blending
			-- Set the additive blending mode to use for drawing operations.
			-- Additive blending:	dstRGB = (srcRGB * srcA) + dstRGB
			--						dstA = dstA
		require
			blendable_is_valid: is_valid
		do
			set_blend_mode ({GAME_SDL_EXTERNAL}.sdl_blendmode_add)
		end

	is_additive_blending_enabled: BOOLEAN
			-- True if the blending mode for drawing operation is additive blending.
			-- Additive blending:	dstRGB = (srcRGB * srcA) + dstRGB
			--						dstA = dstA
		require
			blendable_is_valid: is_valid
		local
			l_blending_mode: INTEGER_32
		do
			l_blending_mode := blend_mode
			if not has_error then
				Result := l_blending_mode = {GAME_SDL_EXTERNAL}.sdl_blendmode_add
			else
				Result := False
			end
		end

	enable_modulate_blending
			-- Set the color modulate blending mode to use for drawing operations.
			-- Color modulate:	dstRGB = srcRGB * dstRGB
			--					dstA = dstA
		require
			blendable_is_valid: is_valid
		do
			set_blend_mode ({GAME_SDL_EXTERNAL}.sdl_blendmode_mod)
		end

	is_modulate_blending_enabled: BOOLEAN
			-- True if the blending mode for drawing operation is color modulate blending.
			-- Color modulate:	dstRGB = srcRGB * dstRGB
			--					dstA = dstA
		require
			blendable_is_valid: is_valid
		local
			l_blending_mode: INTEGER_32
		do
			l_blending_mode := blend_mode
			if not has_error then
				Result := l_blending_mode = {GAME_SDL_EXTERNAL}.sdl_blendmode_mod
			else
				Result := False
			end
		end
	
feature {NONE} -- Implementation

	item: POINTER
			-- Internal pointer of Current
		deferred
		end

	blend_mode: INTEGER_32 assign set_blend_mode
			-- The alpha blending mode of Current
		local
			l_error, l_blending_mode: INTEGER_32
		do
			clear_error
			l_error := c_get_blend_mode (item, $l_blending_mode.to_pointer)
			if l_error < 0 then
				manage_error_code (l_error, "An error occured while retrieving the blending mode.")
				Result := 0
			end
			Result := l_blending_mode
		end

	set_blend_mode (a_blend_mode: INTEGER_32)
			-- The alpha blending mode of Current
		local
			l_error: INTEGER_32
		do
			clear_error
			l_error := c_set_blend_mode (item, a_blend_mode)
			manage_error_code (l_error, "An error occured while enabling color modulate blending on the renderer.")
		end
	
feature {NONE} -- External

	c_get_blend_mode (a_item, a_blend_mode: POINTER): INTEGER_32
			-- Internal getter for blend mode
		deferred
		end

	c_set_blend_mode (a_item: POINTER; a_blend_mode: INTEGER_32): INTEGER_32
			-- Internal setter for blend mode
		deferred
		end
	
end -- class GAME_BLENDABLE

Generated by ISE EiffelStudio