Eiffel Media API
Overview Cluster Class Classes Index      Previous Next      Top Features

em.video.animation

Class EM_SPRITE


Direct ancestors

EM_TIME_SINGLETON, EM_SHARED_BITMAP_FACTORY, EM_DRAWABLE

Known direct descendants

EM_SPRITE_COMPOSITION

Creation

Features

Invariants

indexing

description

A sprite is a list of drawables with seperate framerates for each image.
Sprites may be generated with an *.anim file using EM_ANIMATION to parse
the file.

date

$Date: 2005/10/23 10:46:16 $

revision

$Revision: 1.4 $

class

EM_SPRITE

inherit

EM_DRAWABLE

create

make (img:STRING; duration, an_x, a_y: INTEGER)

-- creates an animation with 1 element
-- looping is set to false by default
-- duration is the time in milliseconds this image will be displayed

make_from_drawable (drawable: EM_DRAWABLE; delay, an_x, a_y: INTEGER)

-- same as make, but takes a bitmap instead of a path to the image
-- void can be given to display nothing for a period of time

make_from_animation (an_animation: EM_ANIMATION; an_x, a_y: INTEGER)

-- Creates a sprite from an animation.
-- takes an EM_ANIMATION and the delay of each image.

require
animation_not_void: an_animation /= Void

feature -- Access

do_loop: BOOLEAN

-- Does the animation loop?

height: INTEGER

-- Height of the animation

-- (From EM_DRAWABLE)

ensure
result_not_negative: Result >= 0
playing: BOOLEAN

-- Is the animation playing?

time_paused: INTEGER

-- Saves, when the animation was paused (-1 if not paused)

width: INTEGER

-- Width of the animation

-- (From EM_DRAWABLE)

ensure
result_not_negative: Result >= 0

feature -- Status report

is_size_fixed: BOOLEAN

-- Should Current not scale when drawed?
-- True means that the object will be drawed unscaled
-- but its position (reference_point) will still be transformed correctly
-- if drawed on a transformed scaled coordinate system
-- (This is handled accordingly by draw_object of EM_SURFACE)

-- (From EM_DRAWABLE)

x: INTEGER

-- Horizontal position, distance in pixels from left

-- (From EM_DRAWABLE)

y: INTEGER

-- Vertical position, distance in pixels from top

-- (From EM_DRAWABLE)

feature -- Status setting

set_size_fixed (a_boolean: BOOLEAN)

-- Set is_size_fixed to a_boolean.

-- (From EM_DRAWABLE)

ensure
size_fixed_set: is_size_fixed = a_boolean
set_x (x_position: INTEGER)

-- Set x to x_position.

-- (From EM_DRAWABLE)

ensure
x_set: x = x_position
set_y (y_position: INTEGER)

-- Set y to y_position.

-- (From EM_DRAWABLE)

ensure
y_set: y = y_position

feature -- creation

make (img:STRING; duration, an_x, a_y: INTEGER)

-- creates an animation with 1 element
-- looping is set to false by default
-- duration is the time in milliseconds this image will be displayed

make_from_animation (an_animation: EM_ANIMATION; an_x, a_y: INTEGER)

-- Creates a sprite from an animation.
-- takes an EM_ANIMATION and the delay of each image.

require
animation_not_void: an_animation /= Void
make_from_drawable (drawable: EM_DRAWABLE; delay, an_x, a_y: INTEGER)

-- same as make, but takes a bitmap instead of a path to the image
-- void can be given to display nothing for a period of time

feature -- Element Change

pause

-- pauses the animation

set_x_y (an_x, a_y: INTEGER)

-- sets x and y

-- (From EM_DRAWABLE)

ensure
x_set: x = an_x
y_set: y = a_y
start

-- starts the animation

stop

-- stops and sets back the animation

feature -- modify

extend (img: STRING; duration: INTEGER)

-- extends the list by an image and an offset

extend_drawable (drawable: EM_DRAWABLE; duration: INTEGER)

-- same as extend, but takes a bitmap instead of a path to the image
-- void can be given to display nothing for a period of time

set_do_loop (b:BOOLEAN)

-- sets do_loop (if we want to loop the animation)

ensure
loop_set: b = do_loop
set_frame_rate (fps: INTEGER)

-- Resets all frames to a constant frame rate of fps

require
fps_valid: fps > 0
set_height (v: INTEGER)

-- set the height for EM_DRAWABLE.

require
height_valid: v > 0
set_width (v: INTEGER)

-- set the width for EM_DRAWABLE.

require
width_valid: v > 0

feature -- draw

draw (screen: EM_SURFACE)

-- draws the current bitmap on the screen (if it is playing)

-- (From EM_DRAWABLE)

require
a_surface_not_void: a_surface /= Void
draw_part (rect: EM_RECT; a_surface: EM_SURFACE)

-- Draws rectangular part of current defined by rect to a_surface

-- (From EM_DRAWABLE)

require
a_surface_not_void: a_surface /= Void
a_rect_not_void: a_rect /= Void

feature -- Mouse events

events_initialized: BOOLEAN

-- Have events been initialized?

-- (From EM_DRAWABLE)

initialize_events

-- Event initialization.
-- Needs to be called before subscribing for events.

-- (From EM_DRAWABLE)

require
not_yet_initialized: not events_initialized
ensure
events_initialized: events_initialized
mouse_button_down_event_initialized: mouse_button_down_event /= Void
mouse_button_up_event_initialized: mouse_button_up_event /= Void
mouse_motion_event_initialized: mouse_motion_event /= Void
mouse_button_down_event: EM_EVENT_TYPE [TUPLE [EM_MOUSE_EVENT]]

-- Mouse button down event,
-- gets published when the mouse button is pressed over Current,
-- an EM_MOUSEBUTTON_EVENT is passed as argument

-- (From EM_DRAWABLE)

mouse_button_up_event: EM_EVENT_TYPE [TUPLE [EM_MOUSE_EVENT]]

-- Mouse button up event,
-- gets published when the mouse button is released over Current,
-- an EM_MOUSEBUTTON_EVENT is passed as argument

-- (From EM_DRAWABLE)

mouse_motion_event: EM_EVENT_TYPE [TUPLE [EM_MOUSE_EVENT]]

-- Mouse button up event,
-- gets published when the mouse button is released over Current,
-- an EM_MOUSEMOTION_EVENT is passed as argument

-- (From EM_DRAWABLE)

publish_mouse_event (a_mouse_event: EM_MOUSE_EVENT)

-- Publish mouse event when a_mouse_event occured on Current.
-- Descendants should redefine this feature
-- for only catching and publishing their mouse events when mouse pointer
-- is realy inside object or for
-- distributing mouse events to child objects.

-- (From EM_DRAWABLE)

require
a_mouse_event_not_void: a_mouse_event /= Void

feature -- Queries

bounding_box: EM_ORTHOGONAL_RECTANGLE

-- Orthogonal rectangle surrounding Current; (i.e. usefull
-- for visibility testing if it intersects with
-- coordinate_area of EM_SURFACE) TODO: We create a new
-- one on each call. Maybe there is a more efficient way to
-- do that?

-- (From EM_DRAWABLE)

ensure
result_not_void: Result /= Void
reference_point: EM_VECTOR_2D

-- Reference point of Current relative to which it should be positioned.
-- (i.e. important when drawn on a scaled coordinate system and is_size_fixed is True)

-- (From EM_DRAWABLE)

ensure
result_not_void: Result /= Void

feature {EM_SPRITE_COMPOSITION} -- Implementation

process_change

-- recomputes the maximum width and height.
-- recreates the cursor

ensure
height_valid: height >= 0
width_valid: width >= 0

invariant


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

-- From EM_DRAWABLE
mouse_button_down_event_initialized: events_initialized implies mouse_button_down_event /= Void
mouse_button_up_event_initialized: events_initialized implies mouse_button_up_event /= Void
mouse_motion_event_initialized: events_initialized implies mouse_motion_event /= Void

end