indexing description: "[ Main scene of this example ]" date: "$Date$" revision: "$Revision$" class CDPLAYER_SCENE inherit EM_WIDGET_SCENE redefine handle_update_event end EM_SHARED_BITMAP_FACTORY export {NONE} all end EM_SHARED_STANDARD_FONTS export {NONE} all end create make feature {NONE} -- Initialisation make is -- Initialise scene. local bitmap_background: EM_BITMAP_BACKGROUND label: EM_LABEL button: EM_BUTTON do -- init scene load_eclipse_theme make_widget_scene set_frame_counter_visibility (false) -- create background Bitmap_factory.create_bitmap_from_image ("./image/background.png") create bitmap_background.make_from_bitmap (Bitmap_factory.last_bitmap) set_background (bitmap_background) -- create all widgets -- the rev button Bitmap_factory.create_bitmap_from_image ("./image/rev.png") create button.make_from_image (Bitmap_factory.last_bitmap) button.set_position (5, 10) button.clicked_event.subscribe (agent previous) add_widget (button) -- the play button Bitmap_factory.create_bitmap_from_image ("./image/play.png") create button.make_from_image (Bitmap_factory.last_bitmap) button.set_position (20, 10) button.clicked_event.subscribe (agent play) add_widget (button) -- the pause button Bitmap_factory.create_bitmap_from_image ("./image/pause.png") create button.make_from_image (Bitmap_factory.last_bitmap) button.set_position (35, 10) button.clicked_event.subscribe (agent pause) add_widget (button) -- the stop button Bitmap_factory.create_bitmap_from_image ("./image/stop.png") create button.make_from_image (Bitmap_factory.last_bitmap) button.set_position (50, 10) button.clicked_event.subscribe (agent stop) add_widget (button) -- the forward button Bitmap_factory.create_bitmap_from_image ("./image/forward.png") create button.make_from_image (Bitmap_factory.last_bitmap) button.set_position (65, 10) button.clicked_event.subscribe (agent next) add_widget (button) -- the eject button Bitmap_factory.create_bitmap_from_image ("./image/eject.png") create button.make_from_image (Bitmap_factory.last_bitmap) button.set_position (80, 10) button.clicked_event.subscribe (agent eject) add_widget (button) -- status text create status.make_from_text ("No device selected, please select a device") status.set_dimension (390, status.optimal_height) status.set_position (5, 35) add_widget (status) -- show details about selected cdrom create listbox.make_empty listbox.set_position (0, 0) listbox.set_dimension (390, 140) listbox.set_font (Standard_ttf_fonts.bitstream_vera_sans_mono (8)) create scroll_panel.make_from_widget (listbox) scroll_panel.set_position (5, 55) scroll_panel.set_dimension (390, 140) add_widget (scroll_panel) -- select your cdrom device create label.make_from_text ("Select a CDRom device:") label.align_right label.set_position (265 - label.optimal_width, 10) add_widget (label) create combobox.make_from_list (cdrom_subsystem.name_list) combobox.set_position (270, 10) -- check if there is any cdrom drives and set the standard drive to true if cdrom_subsystem.count > 0 then combobox.selection_changed_event.subscribe (agent on_device_changed(?)) combobox.set_selected_index (1) -- set standard drive else combobox.put ("None") combobox.set_selected_index (1) -- disable everything needed combobox.disable end combobox.set_dimension (120, combobox.optimal_height) add_widget (combobox) end feature -- Status text update handle_update_event is -- Update the status text periodically local str: STRING do -- call first the precursor precursor -- update only every 25th frame if update_counter = 25 then update_counter := 0 -- check drive status and put out some string if combobox.selected_index = 0 or cdrom_subsystem.count = 0 then str := "No device selected, please select a device" -- clear listbox if no device is selected listbox.wipe_out else if not cdrom.has_cd_in_drive then str := "No CD in drive" if cd_in_tray then update_listbox cd_in_tray := false end elseif cdrom.is_playing then str := (cdrom.current_track + 1).out + " - " + cdrom.current_time_string + " / " + cdrom.current_track_length_string if not cd_in_tray then update_listbox cd_in_tray := true end elseif cdrom.is_stopped then str := "Stopped - Tracks: " + cdrom.count.out + " - Length: " + cdrom.length_string if not cd_in_tray then update_listbox cd_in_tray := true end elseif cdrom.is_paused then str := "Paused..." if not cd_in_tray then update_listbox cd_in_tray := true end else str := "unknown status" if cd_in_tray then listbox.wipe_out cd_in_tray := false end end end if not str.is_equal (status.text) then status.set_text (str) end end update_counter := update_counter + 1 end feature -- Access on_device_changed (selected: STRING) is -- combobox selection has changed -- update detailed information in the listbox do create_cdrom_device_handler update_listbox end feature {NONE} -- Implementation update_listbox is -- update content of listbox with actual -- infromation about CD Drive require cdrom_not_void: cdrom /= void local tracks_array: DS_LINKED_LIST [EM_CDROM_TRACK] cur_track: EM_CDROM_TRACK do -- first purge listbox listbox.wipe_out -- print device information listbox.put ("CDRom Subsystem:") listbox.put ("") listbox.put ("CD Device: " + cdrom.device.out) listbox.put ("CD ID: " + cdrom.device_id.out) listbox.put ("CD Label: " + cdrom.name) if not cdrom.has_cd_in_drive then listbox.put ("Remarks: No CD in drive") else listbox.put ("Tracks: " + cdrom.count.out) listbox.put ("Errorous: " + cdrom.is_erroneous.out) listbox.put ("") listbox.put ("Has Data Track(s): " + cdrom.has_data_track.out) listbox.put ("Has Audio Track(s): " + cdrom.has_audio_track.out) listbox.put ("") if cdrom.has_audio_track then listbox.put ("Length: " + cdrom.length_string + " (" + cdrom.length.out + " sec)") listbox.put ("") listbox.put ("Playing: " + cdrom.is_playing.out) listbox.put ("") listbox.put ("Information about all Tracks:") listbox.put ("") tracks_array := cdrom.tracks from tracks_array.start until tracks_array.after loop cur_track := tracks_array.item_for_iteration listbox.put ("Track: " + cur_track.track_number.out) if cur_track.is_audio_track then listbox.put ("Type: Audio") else listbox.put ("Type: Data") end listbox.put ("Length: " + cur_track.length_string + " (" + cur_track.length.out + " sec)") listbox.put ("Offset: " + cur_track.offset_string + " (" + cur_track.offset.out + " sec)") if cur_track.is_audio_track then listbox.put ("Type: Audio") else listbox.put ("Type: Data") end listbox.put ("") tracks_array.forth end end end listbox.resize_to_optimal_dimension end create_cdrom_device_handler is -- create a device handler with the selected -- device in the combobox do -- first close the existing handler if any if cdrom /= void then cdrom.close end -- if the combobox has a valid selection it will be between 1 and cdrom_subsystem.count -- but device index are from 0 to cdrom_subsystem.count -1. So we need `-1' create cdrom.make_for_device (combobox.selected_index -1) end play is -- Button > was clicked do if cdrom /= void and then cdrom.has_cd_in_drive then cdrom.play_cd end end pause is -- Button || was clicked do if cdrom /= void and then cdrom.has_cd_in_drive then if cdrom.is_paused then cdrom.resume else cdrom.pause end end end stop is -- Button # was clicked do if cdrom /= void and then cdrom.has_cd_in_drive then cdrom.stop end end next is -- Button >> was clicked do if cdrom /= void and then cdrom.has_cd_in_drive then cdrom.next end end previous is -- Button << was clicked do if cdrom /= void and then cdrom.has_cd_in_drive then cdrom.previous end end eject is -- Button `eject' was clicked do if cdrom /= void and then cdrom.has_cd_in_drive then cdrom.eject end end cdrom: EM_CDROM -- container for the selected cdrom device status: EM_LABEL -- show CD-Status (time played, ...) combobox: EM_COMBOBOX [STRING] -- Combobox to select a CDRom device scroll_panel: EM_SCROLLPANEL -- listbox container listbox: EM_TEXTLIST [STRING] -- ListBox to display details about the selected -- CDRom device update_counter: INTEGER -- The only purpose of this is to boost performance out cd_in_tray: BOOLEAN -- indicates if a CD is in tray end