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_DRAWABLE_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_APPLICATION_ID EM_SHARED_VIDEO_SUBSYSTEM export {NONE} all end EM_SHARED_AUDIO_SUBSYSTEM export {NONE} all end EM_SHARED_NETWORK_SUBSYSTEM export {NONE} all end EM_SHARED_BASE_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_error (Error_handler.Em_error_initializing_screen, []) end window_height := screen.height window_width := screen.width screen_resolution := screen.resolution ensure screen_initialized: screen /= Void window_height = screen.height window_width = screen.width screen_resolution = screen.resolution end feature -- Access Window_width: INTEGER -- Window width Window_height: INTEGER -- Window height Screen_resolution: INTEGER -- Screen resolution Is_fullscreen_enabled: BOOLEAN -- Is fullscreen enabled? Is_opengl_enabled: BOOLEAN -- Is OpenGL enabled? scene: EM_SCENE -- Scene that `launch' executes screen: EM_VIDEO_SURFACE -- Screen where application is displayed icon_filename: STRING -- Path of applications icon window_title: STRING -- Window Title feature -- Status report is_video_subsystem_enabled: BOOLEAN is -- Is video subsystem enabled? do Result := Video_subsystem.is_enabled end feature -- Element change set_window_height (a_height: INTEGER) is -- set em_application window height require window_height_not_below_zero: a_height >= 0 do window_height := a_height video_subsystem.set_video_surface_height (window_height) ensure video_subsystem.video_surface_height = window_height end set_window_width (a_width: INTEGER) is -- set em_application window width require winow_width_not_below_zero: a_width >= 0 do window_width := a_width video_subsystem.set_video_surface_width (window_width) ensure video_subsystem.video_surface_width = window_width end set_screen_resolution (a_resolution: INTEGER) is -- set screen resolution (8/16/24/32) require resolution_greater_than_zero: a_resolution > 0 do screen_resolution := a_resolution video_subsystem.set_video_bpp (screen_resolution) ensure video_subsystem.video_surface_bpp = a_resolution end set_fullscreen (fullscreen_enabled: BOOLEAN) is -- set fullscreen mode of em_application window do is_fullscreen_enabled := fullscreen_enabled video_subsystem.set_fullscreen (fullscreen_enabled) video_subsystem.enable ensure video_subsystem.fullscreen = is_fullscreen_enabled end set_opengl (opengl_enabled: BOOLEAN) is -- set opengl do is_opengl_enabled := opengl_enabled Video_subsystem.set_opengl (opengl_enabled) ensure video_subsystem.opengl = is_opengl_enabled end set_noframe (frame_enabled: BOOLEAN) is -- do video_subsystem.set_noframe (frame_enabled) ensure video_subsystem.noframe = frame_enabled end set_scene (a_scene: like scene) is -- Set `scene' to `a_scene'. do scene := a_scene ensure scene_set: scene = a_scene end set_window_title (a_name: like window_title) 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 video_subsystem_is_enabled: is_video_subsystem_enabled local title_c_string: EWG_ZERO_TERMINATED_STRING icon_c_string: EWG_ZERO_TERMINATED_STRING do window_title := 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 title_set: window_title = a_name end set_window_icon (a_filename: like icon_filename) is -- Set application's 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) -- TODO fix bug Bitmap_factory.last_bitmap.set_transparent_color (0, 0, 0) sdl_wm_set_icon_external (Bitmap_factory.last_bitmap.item, default_pointer) ensure icon_set: icon_filename = a_filename end set_application_id (an_id: STRING) is -- Set the application's ID. This is ID is used in the EM net libraries and when writing -- stuff to the user's folder. require id_not_void: an_id /= void is_valid: application_id.is_valid (an_id) do application_id.set (an_id) ensure id_set: application_id.item.is_equal (an_id) 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