indexing description: "[ A component which displays the content of an EM_SURFACE. To use a 2D component, create a subclass of EM_2D_COMPONENT and put your drawing code in the feature `draw'. Draw on `surface' and not directly on the screen. Coordinates on `surface' are relative to `Current's position. Subclasses should call one of `make_void_surface', `make_from_surface' or `make_from_dimension' at creation. See EM_COMPONENT ]" date: "$Date$" revision: "$Revision$" deferred class EM_2D_COMPONENT inherit EM_COMPONENT EM_SHARED_BITMAP_FACTORY export {NONE} all end EM_SHARED_ERROR_HANDLER export {NONE} all end feature {NONE} -- Initialisation make_from_dimension (a_width: like width; a_height: like height) is -- Initialise `Current' with dimensions `a_width' `a_height'. do make_void_surface width := a_width height := a_height lazy_resize_surface ensure surface_created: surface /= Void width_set: width = a_width height_set: height = a_height end make_from_surface (a_surface: like surface) is -- Initialise `Current' with `a_surface' as surface. require a_surface_not_void: a_surface /= Void do make_void_surface surface := a_surface width := surface.width height := surface.height ensure surface_set: surface = a_surface width_set: width = a_surface.width height_set: height = a_surface.height end make_void_surface is -- Initialise `Current' with a Void surface. -- The first call to `set_dimension' will create a surface. do make_component set_keyboard_sensitive (False) resize_event.subscribe (agent lazy_resize_surface) ensure surface_void: surface = Void end feature -- Access surface: EM_SURFACE -- Surface to draw on feature -- Drawing prepare_drawing is -- Prepare for drawing `Current'. do if Video_subsystem.opengl_enabled and not Video_subsystem.video_surface.is_opengl_blitting_enabled then Video_subsystem.video_surface.enable_opengl_blitting end end finish_drawing is -- Finish drawing `Current'. do Video_subsystem.video_surface.blit_surface_part (surface, 0, 0, width, height, x, y) end feature {NONE} -- Implementation lazy_resize_surface is -- Resize surface if dimensions get bigger or surface is to large. do if surface = Void or else ( surface.width < width or surface.height < height or surface.width * 2 > width or surface.height * 2 > height ) then Bitmap_factory.create_empty_alpha_surface (width, height) surface := Bitmap_factory.last_surface end end end