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

em.joystick

Class EM_JOYSTICK


Direct ancestors

EM_CONSTANTS, EM_SHARED_SUBSYSTEMS, EM_SHARED_ERROR_HANDLER, SDL_JOYSTICK_STRUCT_EXTERNAL, SDL_JOYSTICK_FUNCTIONS_EXTERNAL, EWG_STRUCT

Creation

Features

Invariants

indexing

description

Class for wrapping C SDL_JOYSTICK struct. This class represents a joystick.

Use this class for access directly a joystick and to get all information
about the given device (number of buttons, axies, hats and balls)

For getting information about position changes, pressed buttons, ...
bette use those handlers form the event loop:
- handle_joystick_axis_event
- handle_joystick_ball_event
- handle_joystick_button_event
- handle_joystick_hat_event

or simple subscribe to:
- joystick_axis_event
- joystick_ball_event
- joystick_button_down_event
- joystick_button_up_event
- joystick_hat_event

Note: This class should only be uses for customizing joystick event publishing
or for reading the joystick properties.

date

$Date: 2005/10/23 09:58:00 $

revision

$Revision: 1.3 $

class

EM_JOYSTICK

inherit

EWG_STRUCT

create

make_default

-- Initialization class for CD-Rom device 0 (default)

make_for_device (a_device: INTEGER)

-- Initialization class for CD-Rom device a_device

require
joystick_subsystem_enbaled: joystick_subsystem.is_enabled
valid_device: a_device >= 0 and a_device < joystick_subsystem.count
ensure
device_set: device = a_device
device_registered: joystick_subsystem.devices.has (current)

feature {ANY} -- Access

exists: BOOLEAN

-- Does item point to a valid C struct ?

-- (From EWG_STRUCT)

is_shared: BOOLEAN

-- Is the contents of item referenced by other C or Eiffel code?
-- If is_shared is True then when the current object will be
-- collected by the garbage collector, the wrapped struct will
-- also be freed.
-- This is a good idea, only if you can be sure that when the
-- Eiffel object gets collected, the C side does not have a reference
-- to the wrapped struct anymore.

-- (From EWG_STRUCT)

require
exists: exists
item: POINTER

-- Pointer to the wrapped struct

-- (From EWG_STRUCT)

require
exists: exists
ensure
item_not_default_pointer: Result /= Default_pointer

feature -- Device handler handling

close

-- Here free the device handler
-- Automatically called by the cdrom_subsystem if called disable

require
valid_joystick_handler: exists implies valid_handler
ensure
device_unregistered: not joystick_subsystem.devices.has (current)

feature -- Joystick Access

axes: DS_LINKED_LIST [INTEGER]

-- axies returns the current state of the given axis on item.
--
-- On most modern joysticks the X axis is usually represented by axis 0
-- and the Y axis by axis 1. The value returned by axies is a signed
-- integer (-32768 to 32767) representing the current position of the
-- axis, it may be necessary to impose certain tolerances on these values
-- to account for jitter. It is worth noting that some joysticks use
-- axes 2 and 3 for extra buttons.

require
valid_joystick_handler: exists implies valid_handler
balls: DS_LINKED_LIST [INTEGER]

-- Get the ball axis change since the last call of balls
-- Trackballs can only return relative motion since the last call to
-- balls, these motion deltas are placed into dx and dy.

require
valid_joystick_handler: exists implies valid_handler
buttons: DS_LINKED_LIST [INTEGER]

-- button returns the current state of all buttons on the given joystick
-- in a DS_LINKED_LIST sturcture.
-- Subrcribe to the appropriate joystick event to speed things up.

require
valid_joystick_handler: exists implies valid_handler
hats: DS_LINKED_LIST [EM_JOYSTICK_HAT]

-- The current state is returned as a Uint8 which is an OR'd combination
-- of one or more of the following:
-- - SDL_HAT_CENTERED
-- - SDL_HAT_UP
-- - SDL_HAT_RIGHT
-- - SDL_HAT_DOWN
-- - SDL_HAT_LEFT
-- - SDL_HAT_RIGHTUP
-- - SDL_HAT_RIGHTDOWN
-- - SDL_HAT_LEFTUP
-- - SDL_HAT_LEFTDOWN

require
valid_joystick_handler: exists implies valid_handler

feature -- Properties

count_axes: INTEGER

-- return the number of axes available from the opened Joystick (item)

require
valid_joystick_handler: exists implies valid_handler
ensure
count_set: result = sdl_joystick_num_axes_external (item)
count_balls: INTEGER

-- return the number of trackballs available from the opened Joystick (item)

require
valid_joystick_handler: exists implies valid_handler
ensure
count_set: result = sdl_joystick_num_balls_external (item)
count_buttons: INTEGER

-- return the number of buttons available from the opened Joystick (item)

require
valid_joystick_handler: exists implies valid_handler
ensure
count_set: result = sdl_joystick_num_buttons_external (item)
count_hats: INTEGER

-- return the number of hats available from the opened Joystick (item)

require
valid_joystick_handler: exists implies valid_handler
ensure
count_set: result = sdl_joystick_num_hats_external (item)
device: INTEGER

-- Device indentifier
-- 0 is the default device

feature -- Joystick subsystem flags

valid_handler: BOOLEAN

-- Indicates if this Joystick handler (current) is valid
-- An invalid handler can be the result of following code
-- create instance of EM_JOYSTICK
-- joystick_subsystem.disable <-- from here the handler is invalid and can cause an segmentation fault
--
-- joystick_subsystem.enable

invariant

joystick_subsystem_enabled: joystick_subsystem.is_enabled

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

-- From EWG_STRUCT
managed_data_not_void: managed_data /= Void
managed_capacity_equals_sizeof: exists implies managed_data.capacity = sizeof

end