indexing description: "[ Base class for interactive EiffelMedia applications. To start an EiffelMedia application: - First you have to initialize the screen to run the application on (`initialize_screen'). - Set `scene' to the scene you want to run (a descendant of EM_SCENE, i.e. EM_SIMPLE_SCENE) - Call `launch' to let the application run. An EM_APPLICATION initializes the video subsystem and holds the `screen' on which the application is displayed. To change the way the screen is initialized, descendant classes can redefine the feature `initialize_video_subsystem' to set up the `video_subsystem' before the screen is initialized. ]" date: "$Date$" revision: "$Revision$" class EM_APPLICATION inherit EM_SHARED_SUBSYSTEMS export {NONE} all end EM_SHARED_BITMAP_FACTORY export {NONE} all end EM_SHARED_ERROR_HANDLER export {NONE} all end SDL_VIDEO_FUNCTIONS_EXTERNAL export {NONE} all end MEMORY export {NONE} all end feature -- Initialization initialize_video_subsystem is -- Configure video subsystem. -- (Descendants can redefine this feature to set up -- the video system before the screen is initialized) do end initialize_screen is -- Initialize `screen' to `video_surface'. do initialize_video_subsystem if not Video_subsystem.is_enabled then Video_subsystem.enable end screen := Video_subsystem.video_surface if screen = Void then Error_handler.raise_exception (Error_handler.Em_error_initializing_screen, []) end ensure screen_initialized: screen /= Void end feature -- Access scene: EM_SCENE -- Scene that `launch' executes screen: EM_VIDEO_SURFACE -- Screen where application is displayed icon_filename: STRING -- Path of applications icon application_name: STRING -- Name of application feature -- Status report is_video_subsystem_enabled: BOOLEAN is -- Is video subsystem enabled? do Result := Video_subsystem.is_enabled end feature -- Element change set_scene (a_scene: like scene) is -- Set `scene' to `a_scene'. do scene := a_scene ensure scene_set: scene = a_scene end set_application_name (a_name: like application_name) is -- Set application window title to `a_name'. -- This is only visible in windowed mode. require a_name_not_void: a_name /= Void a_name_not_empty: not a_name.is_empty local title_c_string: EWG_ZERO_TERMINATED_STRING icon_c_string: EWG_ZERO_TERMINATED_STRING do application_name := a_name create title_c_string.make_unshared_from_string (a_name) create icon_c_string.make_unshared_from_string ("") sdl_wm_set_caption_external (title_c_string.item, icon_c_string.item) ensure name_set: application_name = a_name end set_application_icon (a_filename: like icon_filename) is -- Set applications window icon to `a_filename'. -- Transparent areas of the icon should be green. -- This is only visible in windowed mode. require a_filename_not_void: a_filename /= Void a_filename_not_empty: not a_filename.is_empty a_filename_valid: (not a_filename.has ('\')) and (not has_upper (a_filename)) video_subsystem_is_enabled: is_video_subsystem_enabled do icon_filename := a_filename Bitmap_factory.create_bitmap_from_image (icon_filename) if Bitmap_factory.last_bitmap = Void then Error_handler.raise_exception (Error_handler.Em_error_loading_image, [icon_filename]) end Bitmap_factory.last_bitmap.set_transparent_color (0, 255, 0) sdl_wm_set_icon_external (Bitmap_factory.last_bitmap.item, default_pointer) ensure icon_set: icon_filename = a_filename end feature -- Basic operations launch is -- Launch the application by running `scene'. require screen_initialized: screen /= Void scene_not_void: scene /= Void do -- Keep the application running (scene after scene, until finished) from until scene = Void loop scene.initialize_scene scene.run (screen) scene := scene.next_scene -- Free memory now instead in the middle of the game full_collect end end feature -- Implementation has_upper (a_string: STRING): BOOLEAN is -- Does `a_string' contain upper case characters? local i: INTEGER do from i := a_string.count until i = 0 or Result loop Result := a_string.item (i).is_upper i := i - 1 end end end