indexing description: "[ A dialog for export options. A *very* sloppy adaption of EM_MESSAGE_DIALOG. Kids, don't do this at home! TODO: clean up ]" date: "$Date$" revision: "$Revision$" class EXPORT_DIALOG inherit EM_DIALOG redefine show end EM_SHARED_STANDARD_FONTS export {NONE} all end create make feature {NONE} -- Initialisation make (a_saver: SCENE_SAVER) is -- Initialise dialog with `a_question' and a question image. require a_saver_not_void: a_saver /= Void do scene_saver := a_saver make_from_text ("Please select the type you would like the file to be exported in.") set_title ("Export Type") display_yes_no center_on_screen end make_from_text (a_text: like text) is -- Initialise dialgo with `a_text' and `an_image'. require a_text_not_void: a_text /= Void do make_empty set_keyboard_sensitive (True) hide_close_button key_down_event.subscribe (agent handle_key_down_event) create button_clicked_event text := a_text create text_label.make_from_text (a_text) text_label.set_position (10, 30) add_widget (text_label) create ok_button.make_from_text ("Ok") ok_button.set_dimension (80, 20) ok_button.clicked_event.subscribe (agent handle_ok_button_clicked) add_widget (ok_button) create cancel_button.make_from_text ("Cancel") cancel_button.set_dimension (80, 20) cancel_button.clicked_event.subscribe (agent handle_cancel_button_clicked) add_widget (cancel_button) create yes_button.make_from_text ("Continue") yes_button.set_dimension (80, 20) yes_button.clicked_event.subscribe (agent handle_yes_button_clicked) add_widget (yes_button) create no_button.make_from_text ("Cancel") no_button.set_dimension (80, 20) no_button.clicked_event.subscribe (agent handle_no_button_clicked) add_widget (no_button) create list.make_empty from scene_saver.export_types.start until scene_saver.export_types.off loop list.put (scene_saver.export_types.item_for_iteration) scene_saver.export_types.forth end list.set_to_string_agent (agent exporter_to_string) list.set_selected_index (1) list.resize_to_optimal_dimension create scrollpanel.make_from_widget (list) add_widget (scrollpanel) do_layout center_on_screen ensure text_set: text = a_text end feature -- Access list: EM_TEXTLIST [EXPORTER] -- list of all possible export formats text: STRING -- Text to display image: EM_BITMAP -- Image to display ok_button: EM_BUTTON -- OK button cancel_button: EM_BUTTON -- Cancel button yes_button: EM_BUTTON -- Yes button no_button: EM_BUTTON -- No button text_label: EM_LABEL -- Label to display text scene_saver: SCENE_SAVER feature -- Status report was_ok_pressed: BOOLEAN -- Was ok button pressed? was_cancel_pressed: BOOLEAN -- Was cancel pressed? was_no_pressed: BOOLEAN -- Was no pressed? was_yes_pressed: BOOLEAN -- Was yes pressed? feature -- Status setting show is -- Show dialog. do was_ok_pressed := False was_cancel_pressed := False was_yes_pressed := False was_no_pressed := False Precursor {EM_DIALOG} end display_ok is -- Display ok button. do ok_button.show cancel_button.hide yes_button.hide no_button.hide do_layout end display_ok_cancel is -- Display ok and cancel buttons. do ok_button.show cancel_button.show yes_button.hide no_button.hide do_layout end display_yes_no is -- Display yes and no buttons. do ok_button.hide cancel_button.hide yes_button.show no_button.show do_layout end display_yes_no_cancel is -- Display yes, no and cancel buttons. do ok_button.hide cancel_button.show yes_button.show no_button.show do_layout end feature -- Element change set_text (a_text: like text) is -- Set `text' to `a_text'. require a_text_not_void: a_text /= Void do text := a_text do_layout ensure text_set: text = a_text end feature -- Events button_clicked_event: EM_EVENT_CHANNEL [TUPLE []] -- Any button clicked event. feature {NONE} -- Implementation scrollpanel: EM_SCROLLPANEL message_image: EM_BITMAP is -- Message image local a_font: EM_TTF_FONT do Bitmap_factory.create_empty_bitmap (40, 40) Result := Bitmap_factory.last_bitmap Result.set_drawing_color (create {EM_COLOR}.make_with_rgb (0, 0, 255)) Result.fill (Theme_colors.window_background) a_font := Standard_ttf_fonts.bitstream_vera_sans_bold (35) a_font.draw ('#', Result, 10, 5) end question_image: EM_BITMAP is -- Question image local a_font: EM_TTF_FONT do Bitmap_factory.create_empty_bitmap (40, 40) Result := Bitmap_factory.last_bitmap Result.set_drawing_color (create {EM_COLOR}.make_with_rgb (0, 255, 0)) Result.fill (Theme_colors.window_background) a_font := Standard_ttf_fonts.bitstream_vera_sans_bold (35) a_font.draw ('?', Result, 10, 5) end warning_image: EM_BITMAP is -- Warning image local a_font: EM_TTF_FONT do Bitmap_factory.create_empty_bitmap (40, 40) Result := Bitmap_factory.last_bitmap Result.set_drawing_color (create {EM_COLOR}.make_with_rgb (255, 128, 0)) Result.fill (Theme_colors.window_background) a_font := Standard_ttf_fonts.bitstream_vera_sans_bold (35) a_font.draw ('*', Result, 10, 15) end error_image: EM_BITMAP is -- Error image local a_font: EM_TTF_FONT do Bitmap_factory.create_empty_bitmap (40, 40) Result := Bitmap_factory.last_bitmap Result.set_drawing_color (create {EM_COLOR}.make_with_rgb (255, 0, 0)) Result.fill (Theme_colors.window_background) a_font := Standard_ttf_fonts.bitstream_vera_sans_bold (35) a_font.draw ('!', Result, 15, 5) end handle_ok_button_clicked is -- Handle ok button clicked. do was_ok_pressed := True hide button_clicked_event.publish ([]) end handle_cancel_button_clicked is -- Handle cancel button clicked. do was_cancel_pressed := True hide button_clicked_event.publish ([]) end handle_yes_button_clicked is -- Handle cancel button clicked. do was_yes_pressed := True hide button_clicked_event.publish ([]) end handle_no_button_clicked is -- Handle cancel button clicked. do was_no_pressed := True hide button_clicked_event.publish ([]) end handle_key_down_event (an_event: EM_KEYBOARD_EVENT) is -- Handle key down event. do if an_event.key = an_event.sdlk_escape then cancel_button.fire_clicked_event end end do_layout is -- Layout components. local dialog_width, dialog_height: INTEGER do text_label.enable_multilined text_label.resize_to_optimal_dimension dialog_width := 15 if ok_button.is_visible then dialog_width := dialog_width + 80 + 5 end if cancel_button.is_visible then dialog_width := dialog_width + 80 + 5 end if yes_button.is_visible then dialog_width := dialog_width + 80 + 5 end if no_button.is_visible then dialog_width := dialog_width + 80 + 5 end dialog_width := dialog_width.max (10 + text_label.width + 10) dialog_height := 30 + text_label.height.max (30) + 40 if list.height > 100 then scrollpanel.set_dimension (list.width + 14, 100) else scrollpanel.set_dimension (list.width, list.height) end scrollpanel.set_position ((dialog_width - list.width)//2, 15+(dialog_height-30-40-text_label.height)//2 + 25) dialog_height := dialog_height + scrollpanel.height - 20 set_dimension (dialog_width, dialog_height) text_label.set_position (10, 30+(10-text_label.height)//2) dialog_width := dialog_width - 10 if cancel_button.is_visible then cancel_button.set_position (dialog_width-80, dialog_height-25) dialog_width := dialog_width - 80 - 5 end if ok_button.is_visible then ok_button.set_position (dialog_width-80, dialog_height-25) dialog_width := dialog_width - 80 - 5 end if no_button.is_visible then no_button.set_position (dialog_width-80, dialog_height-25) dialog_width := dialog_width - 80 - 5 end if yes_button.is_visible then yes_button.set_position (dialog_width-80, dialog_height-25) dialog_width := dialog_width - 80 - 5 end end exporter_to_string (a: EXPORTER): STRING is -- agent for converting EXPORTER to STRING do Result := a.name end end