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

em.video.figure

Class EM_RECTANGLE


Direct ancestors

EM_CLOSED_FIGURE, EM_ORTHOGONAL_RECTANGLE

Creation

Features

Invariants

indexing

description

Iso-orriented (orthogonal, axis-parallel) rectangle that can be drawn in EiffelMedia,
possibly with rounded corners (see rounded_corner_radius).

date

$Date: 2005/10/23 10:57:04 $

revision

$Revision: 1.4 $

class

EM_RECTANGLE

inherit

EM_CLOSED_FIGURE
EM_ORTHOGONAL_RECTANGLE

create

make (a_point_a, a_point_b: EM_VECTOR_2D)

-- Initialize with a_point_a and a_point_b as corners of the rectangle.

-- (From EM_ORTHOGONAL_RECTANGLE)

require
a_point_a_not_void: a_point_a /= Void
a_point_b_not_void: a_point_b /= Void
ensure
point_a_set: point_a = a_point_a
point_b_set: point_b = a_point_b
make_from_coordinates (x1, y1, x2, y2: DOUBLE)

-- Create a rectangle from DOUBLE coordinates.

-- (From EM_ORTHOGONAL_RECTANGLE)

ensure
point_a_set: point_a.x = x1 and then point_a.y = y1
point_b_set: point_b.x = x2 and then point_b.y = y2
make_from_position_and_size (x1, y1, a_width, a_height: DOUBLE)

-- Create a rectangle with upper left corner x1, y1
-- and a_width, a_height.

-- (From EM_ORTHOGONAL_RECTANGLE)

require
a_width_not_negative: a_width >= 0.0
a_height_not_negative: a_height >= 0.0
ensure
upper_left_set: upper_left.x = x1 and then upper_left.y = y1
size_set: width = a_width and then height = a_height
make_from_rectangle (a_rectangle: EM_ORTHOGONAL_RECTANGLE)

-- Initialize from a_rectangle.

-- (From EM_ORTHOGONAL_RECTANGLE)

require
a_rectangle_not_void: a_rectangle /= Void
ensure
initialized_as_a_rectangle: point_a.is_equal (a_rectangle.point_a) and then point_b.is_equal (a_rectangle.point_b)

feature -- Initialization

default_create

-- Initialize Current as filled figure
-- in white colors with line width of 0.0.

-- (From ANY)

make_from_coordinates (x1, y1, x2, y2: DOUBLE)

-- Create a rectangle from DOUBLE coordinates.

-- (From EM_ORTHOGONAL_RECTANGLE)

ensure
point_a_set: point_a.x = x1 and then point_a.y = y1
point_b_set: point_b.x = x2 and then point_b.y = y2
make_from_position_and_size (x1, y1, a_width, a_height: DOUBLE)

-- Create a rectangle with upper left corner x1, y1
-- and a_width, a_height.

-- (From EM_ORTHOGONAL_RECTANGLE)

require
a_width_not_negative: a_width >= 0.0
a_height_not_negative: a_height >= 0.0
ensure
upper_left_set: upper_left.x = x1 and then upper_left.y = y1
size_set: width = a_width and then height = a_height
make_from_rectangle (a_rectangle: EM_ORTHOGONAL_RECTANGLE)

-- Initialize from a_rectangle.

-- (From EM_ORTHOGONAL_RECTANGLE)

require
a_rectangle_not_void: a_rectangle /= Void
ensure
initialized_as_a_rectangle: point_a.is_equal (a_rectangle.point_a) and then point_b.is_equal (a_rectangle.point_b)

feature -- Access

point_a: EM_VECTOR_2D

-- One corner point of the rectangle

-- (From EM_ORTHOGONAL_RECTANGLE)

point_b: EM_VECTOR_2D

-- The other corner point of the rectangle

-- (From EM_ORTHOGONAL_RECTANGLE)

feature -- Status report

exact_height: DOUBLE

-- Height of Current

-- (From EM_ORTHOGONAL_RECTANGLE)

exact_width: DOUBLE

-- Width of Current

-- (From EM_ORTHOGONAL_RECTANGLE)

fill_color: EM_COLOR

-- The color with which the interrior of the figure is drawed,
-- if is_filled is True

-- (From EM_CLOSED_FIGURE)

height: INTEGER

-- Height of Current.

-- (From EM_DRAWABLE)

ensure
result_not_negative: Result >= 0
is_filled: BOOLEAN

-- Is Current drawed filled with fill_color?
-- (otherwise only the border will be drawed)

-- (From EM_CLOSED_FIGURE)

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)

line_color: EM_COLOR

-- Line color used to draw Current

-- (From EM_FIGURE)

line_width: DOUBLE

-- Line width used to draw Current

-- (From EM_FIGURE)

rounded_corner_radius: DOUBLE

-- Radius used to draw corners of Current rounded.
-- (a value of 0.0 means no rounded corners)

size: DOUBLE

-- Size of Current.

-- (From EM_ORTHOGONAL_RECTANGLE)

ensure
size_calculated: size > width * height - eps and size < width * height + eps
width: INTEGER

-- Width of Current.

-- (From EM_DRAWABLE)

ensure
result_not_negative: Result >= 0
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_fill_color (a_color: EM_COLOR)

-- Set fill_color to a_color.

-- (From EM_CLOSED_FIGURE)

require
a_color_not_void: a_color /= Void
ensure
fill_color_assigned: fill_color = a_color
set_filled (a_bool: BOOLEAN)

-- Set is_filled to a_bool.

-- (From EM_CLOSED_FIGURE)

ensure
is_filled_set: is_filled = a_bool
set_line_color (a_color: EM_COLOR)

-- Set line_color to a_color.

-- (From EM_FIGURE)

require
a_color_not_void: a_color /= Void
ensure
line_color_assigned: line_color = a_color
set_line_width (a_width: DOUBLE)

-- Set line_width to a_width.

-- (From EM_FIGURE)

require
a_width_not_negative: a_width >= 0
ensure
line_width_set: line_width = a_width
set_rounded_corner_radius (a_radius: DOUBLE)

-- Set rounded_corner_radius to a_radius.

ensure
rounded_corner_radius_set: rounded_corner_radius = a_radius
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_x_y (x_position: INTEGER; y_position: INTEGER)

-- Set x and y to x_position and y_position.
-- Moves all contained points accordingly.

-- (From EM_DRAWABLE)

ensure
x_set: x = an_x
y_set: y = a_y
set_y (y_position: INTEGER)

-- Set y to y_position.

-- (From EM_DRAWABLE)

ensure
y_set: y = y_position
update_bounding_box

-- Recalculate bounding_box (x, y, width, height)
-- to surround Current rectangle.
-- (Should be called whenever rectangle has changed).

-- (From EM_FIGURE)

feature -- Element change

down_by (a_distance: DOUBLE)

-- Move Current down by a_distance.

-- (From EM_ORTHOGONAL_RECTANGLE)

ensure
upper_bound_moved_down: upper_bound > old upper_bound + a_distance - eps and upper_bound < old upper_bound + a_distance + eps
lower_bound_moved_down: lower_bound > old lower_bound + a_distance - eps and lower_bound < old lower_bound + a_distance + eps
extend (a_point: EM_VECTOR_2D)

-- Resize Current to contain a_point.

-- (From EM_ORTHOGONAL_RECTANGLE)

require
a_point_attached: a_point /= Void
ensure
has_a_point: has (a_point)
left_by (a_distance: DOUBLE)

-- Move Current left by a_distance.

-- (From EM_ORTHOGONAL_RECTANGLE)

ensure
left_bound_moved_left: left_bound > old left_bound - a_distance - eps and left_bound < old left_bound - a_distance + eps
right_bound_moved_left: right_bound > old right_bound - a_distance - eps and right_bound < old right_bound - a_distance + eps
move_by (a_distance: EM_VECTOR_2D)

-- Move Current by the vector a_distance.

-- (From EM_ORTHOGONAL_RECTANGLE)

require
a_distance_not_void: a_distance /= Void
a_distance_not_point_a: a_distance /= point_a
a_distance_not_point_b: a_distance /= point_b
ensure
left_bound_moved: left_bound > old left_bound +a_distance.x - eps and left_bound < old left_bound + a_distance.x + eps
right_bound_moved: right_bound > old right_bound + a_distance.x - eps and right_bound < old right_bound + a_distance.x + eps
upper_bound_moved: upper_bound > old upper_bound + a_distance.y - eps and upper_bound < old upper_bound + a_distance.y + eps
lower_bound_moved: lower_bound > old lower_bound + a_distance.y - eps and lower_bound < old lower_bound + a_distance.y + eps
move_center_to (a_position: EM_VECTOR_2D)

-- Move center to a_position.

-- (From EM_ORTHOGONAL_RECTANGLE)

require
a_position_not_void: a_position /= Void
ensure
size_unchanged: size = old size
move_to (a_position: EM_VECTOR_2D)

-- Move upper_left to a_position.

-- (From EM_ORTHOGONAL_RECTANGLE)

require
a_position_not_void: a_position /= Void
ensure
size_unchanged: size = old size
right_by (a_distance: DOUBLE)

-- Move Current right by a_distance.

-- (From EM_ORTHOGONAL_RECTANGLE)

ensure
left_bound_moved_right: left_bound > old left_bound + a_distance - eps and left_bound < old left_bound + a_distance + eps
right_bound_moved_right: right_bound > old right_bound + a_distance - eps and right_bound < old right_bound + a_distance + eps
scale (a_factor: DOUBLE)

-- Scalar multiplication by a_factor

-- (From EM_ORTHOGONAL_RECTANGLE)

set_size (a_width, a_height: DOUBLE)

-- Set size to a_width and a_height
-- by not changing upper_left

-- (From EM_ORTHOGONAL_RECTANGLE)

require
a_width_not_negative: a_width >= 0
a_height_not_negative: a_height >= 0
ensure
upper_left_kept: upper_left.is_equal (old upper_left)
set_size_centered (a_width, a_height: DOUBLE)

-- Set size to a_width and a_height
-- by not changing center

-- (From EM_ORTHOGONAL_RECTANGLE)

require
a_width_not_negative: a_width >= 0
a_height_not_negative: a_height >= 0
up_by (a_distance: DOUBLE)

-- Move Current up by a_distance.

-- (From EM_ORTHOGONAL_RECTANGLE)

ensure
upper_bound_moved_up: upper_bound > old upper_bound - a_distance - eps and upper_bound < old upper_bound - a_distance + eps
lower_bound_moved_up: lower_bound > old lower_bound - a_distance - eps and lower_bound < old lower_bound - a_distance + eps
zoom (a_factor: DOUBLE)

-- Zoom Current by a_factor with respect to center.

-- (From EM_ORTHOGONAL_RECTANGLE)

feature -- Drawing

draw (surface: EM_SURFACE)

-- Draw Current onto surface.

-- (From EM_DRAWABLE)

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

-- Draw rectangular part of Current defined by a_rect to a_surface.
-- (Subclasses could redefine this feature for providing an implementation
-- with better performance, otherwise its just done per default by
-- transforming and clipping coordinates on a_surface before calling draw).

-- (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
center: EM_VECTOR_2D

-- Center of Current

-- (From EM_ORTHOGONAL_RECTANGLE)

ensure
result_not_void: Result /= Void
has (a_coordinate: EM_VECTOR_2D): BOOLEAN

-- Is a_coordinate inside Current?

-- (From EM_ORTHOGONAL_RECTANGLE)

require
a_coordinate_not_void: a_coordinate /= Void
intersection (other: like Current): like Current

-- Overlaping area of Current with other.

-- (From EM_ORTHOGONAL_RECTANGLE)

require
other_not_void: other /= Void
ensure
zero_sized_result_when_not_overlaping: not intersects (other) implies Result.size = 0
intersects (other: like Current): BOOLEAN

-- Do Current and other overlap?

-- (From EM_ORTHOGONAL_RECTANGLE)

require
other_not_void: other /= Void
left_bound: DOUBLE

-- Upper bound of Current

-- (From EM_ORTHOGONAL_RECTANGLE)

lower_bound: DOUBLE

-- Upper bound of Current

-- (From EM_ORTHOGONAL_RECTANGLE)

lower_left: EM_VECTOR_2D

-- Lower-left corner of Current

-- (From EM_ORTHOGONAL_RECTANGLE)

ensure
result_not_void: Result /= Void
lower_right: EM_VECTOR_2D

-- Lower-right corner of Current

-- (From EM_ORTHOGONAL_RECTANGLE)

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
right_bound: DOUBLE

-- Upper bound of Current

-- (From EM_ORTHOGONAL_RECTANGLE)

upper_bound: DOUBLE

-- Upper bound of Current

-- (From EM_ORTHOGONAL_RECTANGLE)

upper_left: EM_VECTOR_2D

-- Upper-left corner of Current

-- (From EM_ORTHOGONAL_RECTANGLE)

ensure
result_not_void: Result /= Void
upper_right: EM_VECTOR_2D

-- Upper-right corner of Current

-- (From EM_ORTHOGONAL_RECTANGLE)

ensure
result_not_void: Result /= Void

feature -- Constants

eps: DOUBLE

-- Epsilon for assertions with DOUBLES

-- (From EM_ORTHOGONAL_RECTANGLE)

invariant

rounded_corner_radius_not_negative: rounded_corner_radius >= 0.0

fill_color_not_void: fill_color /= Void

-- From EM_FIGURE
line_color_not_void: line_color /= Void
line_width_not_negative: line_width >= 0.0
points_not_void: points /= Void

-- 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

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

width_not_negative: width >= 0
height_not_negative: height >= 0
point_a_not_void: point_a /= Void
point_b_not_void: point_b /= Void

end