indexing description: "[ Rectangle. Used for clipping and blitting. ]" date: "$Date$" revision: "$Revision$" class EM_RECT inherit SDL_RECT_STRUCT rename h as height, w as width, set_h as set_height, set_w as set_width end create make feature {NONE} -- Initialization make (an_x: INTEGER; an_y: INTEGER; a_width: INTEGER; a_height: INTEGER) is -- Create with `an_x' and `an_y' as upper left corner, `a_width' wide and `a_height' -- tall. do -- create sdl_rect_struct.make_new_unshared -- sdl_rect_struct.set_x (an_x) -- sdl_rect_struct.set_y (an_y) -- sdl_rect_struct.set_w (a_width) -- sdl_rect_struct.set_h (a_height) make_new_unshared set_x (an_x) set_y (an_y) set_height (a_height) set_width (a_width) end feature -- Access -- x: INTEGER is -- -- X coordinate of upper left corner of the rectangle -- do -- Result := sdl_rect_struct.x -- end -- y: INTEGER is -- -- Y coordinate of upper left corner of the rectangle -- do -- Result := sdl_rect_struct.y -- end -- width: INTEGER is -- -- Width of the rectangle -- do -- Result := sdl_rect_struct.w -- end -- height: INTEGER is -- -- Height of the rectangle -- do -- Result := sdl_rect_struct.h -- end feature -- Status report intersects (other: like Current): BOOLEAN is -- Is the intersection between `current' and `other' not empty require other_not_void: other /= Void do Result := not ((x + width < other.x) or (y + height < other.y) or (x > other.x + other.width) or (y > other.y + other.height)) end inside (other: like Current): BOOLEAN is -- Is `current' completly inside `other'? require other_not_void: other /= Void do Result := (x >= other.x) and (x + width <= other.width + other.x) and (y >= other.y) and (y + height <= other.height + other.y) end feature -- Element change -- set_x (an_x: INTEGER) is -- -- Set `an_x'. -- do -- sdl_rect_struct.set_x (an_x) -- end -- set_y (an_y: INTEGER) is -- -- Set `an_y'. -- do -- sdl_rect_struct.set_y (an_y) -- end -- set_width (a_width: INTEGER) is -- -- Set `a_width'. -- do -- sdl_rect_struct.set_w (a_width) -- end -- set_height (a_height: INTEGER) is -- -- Set `a_height'. -- do -- sdl_rect_struct.set_h (a_height) -- end feature -- Basic operations intersection (other: like Current): like Current is -- Intersection between `current' and `other' EM_RECT require other_not_void: other /= Void local pos: INTEGER do if intersects (other) then create Result.make (max (x, other.x), max (y, other.y), 0, 0) pos := min (x + width, other.x + other.width) Result.set_width (pos - Result.x) pos := min (y + height, other.y + other.height) Result.set_height (pos - Result.y) else create Result.make (0, 0, 0, 0) end end feature {EM_SURFACE} -- Implementation -- sdl_rect_struct: SDL_RECT_STRUCT -- C structure representing rectangle feature {NONE} -- Implementation min (a: INTEGER; b: INTEGER): INTEGER is -- Minumum of `a' and `b' do if a < b then Result := a else Result := b end end max (a: INTEGER; b: INTEGER): INTEGER is -- Maximum of `a' and `b' do if a > b then Result := a else Result := b end end end