indexing description: "[ Main scene of widget browser ]" date: "$Date$" revision: "$Revision$" class WIDGET_BROWSER_SCENE inherit EM_COMPONENT_SCENE redefine handle_quit_event end EM_SHARED_BITMAP_FACTORY export {NONE} all end EM_SHARED_STANDARD_FONTS export {NONE} all end MEMORY export {NONE} all end create make feature {NONE} -- Initialisation make is -- Initialise scene. local label: EM_LABEL menu_list: EM_TEXTLIST [TUPLE [STRING, ROUTINE [ANY, TUPLE []]]] do make_component_scene create title_label.make_empty title_label.set_position (100, 0) title_label.set_dimension (width-100, 20) title_label.set_font (standard_ttf_fonts.bitstream_vera_sans_bold (16)) title_label.set_background_color (Theme_colors.window_background) title_label.enable_shadow title_label.set_shadow_color (create {EM_COLOR}.make_with_rgb (150, 200,255)) title_label.align_center create fps_label.make fps_label.set_position (0, height-20) fps_label.set_dimension (100, 20) create menu_panel.make_from_dimension (100, height-20) create label.make_from_text ("Select demo") label.set_position (0, 0) label.set_dimension (100, 20) label.align_center menu_panel.add_widget (label) create menu_list.make_empty menu_list.set_position (0, 20) menu_list.set_dimension (100, height-20) menu_panel.add_widget (menu_list) menu_list.set_to_string_agent (agent string_from_tuple) menu_list.put (["Widgets", agent show_panel (create {WIDGETS_DEMO_PANEL}.make)]) menu_list.put (["Windows", agent show_panel (create {WINDOW_DEMO_PANEL}.make)]) menu_list.put (["Background", agent show_panel (create {BACKGROUND_DEMO_PANEL}.make)]) menu_list.put (["Border", agent show_panel (create {BORDER_DEMO_PANEL}.make)]) menu_list.put (["Custom widget", agent show_panel (create {DRAWING_DEMO_PANEL}.make)]) menu_list.put (["Drawables", agent show_panel (create {DRAWABLES_DEMO_PANEL}.make (Current))]) menu_list.put (["GOOF", agent show_panel (create {GOOF_DEMO_PANEL}.make)]) if Video_subsystem.opengl_enabled then menu_list.put (["Sierpinski (3D)", agent show_opengl_demo]) end menu_list.selection_changed_event.subscribe (agent handle_menu_selection) menu_list.unselect end feature -- Access title_label: EM_LABEL -- Title label menu_panel: EM_PANEL -- Menu panel fps_label: EM_FPS_LABEL -- Frame counter sierpinski_display: SIERPINSKI_DISPLAY -- Sierpinski piramyd display sierpinski_control_panel: EM_PANEL -- Panel with controls for sierpinski display sierpinski_help_panel: EM_PANEL -- Panel to display help text feature -- Basic operations prepare_demo is -- Remove all components and place base components. do components_impl.wipe_out add_component (title_label) add_component (fps_label) add_component (menu_panel) end show_default is -- Show default page. local panel: EM_PANEL label: EM_LABEL do create panel.make_from_dimension (width-100, height-20) panel.set_position (100, 20) add_component (panel) create label.make_from_text ("Select a demo from the list.") label.set_position (20, 20) panel.add_widget (label) end show_panel (a_panel: EM_PANEL) is -- Show 'a_panel' as demo. do a_panel.set_position (100, 20) a_panel.set_dimension (width-100, height-20) add_component (a_panel) end show_opengl_demo is -- Show OpenGL demo. local text: STRING label: EM_LABEL button: EM_BUTTON checkbox: EM_CHECKBOX do -- First time create widgets if sierpinski_display = Void then -- Help text create sierpinski_help_panel.make_from_dimension (width-100, 100) sierpinski_help_panel.set_position (100, 20) create text.make_empty text.append_string ("To display 3D content together with widgets, use an EM_3D_COMPONENT.%N") text.append_string ("Basic approach:%N") text.append_string (" - inherit from EM_3D_COMPONENT%N") text.append_string (" - place OpenGL code in 'draw'%N") text.append_string (" - subscribe on desired event types to react on input events") create label.make_from_text (text) label.set_position (70, 10) label.set_dimension (500, 90) label.enable_multilined label.align_top sierpinski_help_panel.add_widget (label) -- Sierpinski pyramid create sierpinski_display.make sierpinski_display.set_position (100, 120) sierpinski_display.set_dimension (width-100, height-160) -- Usage text create sierpinski_control_panel.make_from_dimension (width-100, 40) sierpinski_control_panel.set_position (100, height-40) create label.make_from_text ("Level: ") label.set_dimension (50, 20) label.align_right sierpinski_control_panel.add_widget (label) create button.make_from_text ("+") button.set_dimension (20, 20) button.set_position (50, 0) button.clicked_event.subscribe (agent sierpinski_display.increase_subdivisions) sierpinski_control_panel.add_widget (button) create button.make_from_text ("-") button.set_dimension (20, 20) button.set_position (70, 0) button.clicked_event.subscribe (agent sierpinski_display.decrease_subdivisions) sierpinski_control_panel.add_widget (button) create label.make_from_text ("Zoom: ") label.set_position (100, 0) label.set_dimension (50, 20) label.align_right sierpinski_control_panel.add_widget (label) create button.make_from_text ("+") button.set_dimension (20, 20) button.set_position (150, 0) button.clicked_event.subscribe (agent sierpinski_display.decrease_distance) sierpinski_control_panel.add_widget (button) create button.make_from_text ("-") button.set_dimension (20, 20) button.set_position (170, 0) button.clicked_event.subscribe (agent sierpinski_display.increase_distance) sierpinski_control_panel.add_widget (button) create checkbox.make_from_text ("Lighting") checkbox.set_position (200, 0) checkbox.set_dimension (100, 20) checkbox.checked_event.subscribe (agent sierpinski_display.enable_lighting) checkbox.unchecked_event.subscribe (agent sierpinski_display.disable_lighting) sierpinski_control_panel.add_widget (checkbox) create checkbox.make_from_text ("Fog") checkbox.set_position (300, 0) checkbox.set_dimension (100, 20) checkbox.checked_event.subscribe (agent sierpinski_display.enable_fog) checkbox.unchecked_event.subscribe (agent sierpinski_display.disable_fog) sierpinski_control_panel.add_widget (checkbox) create label.make_from_text ("drag to rotate - mouse wheel to zoom - left click increase level - right click decrease level") label.set_dimension (width-100, 20) label.set_position (0, 20) label.align_center sierpinski_control_panel.add_widget (label) end add_component (sierpinski_display) add_component (sierpinski_control_panel) add_component (sierpinski_help_panel) end feature {NONE} -- Implementation handle_menu_selection (an_element: TUPLE [STRING, ROUTINE [ANY, TUPLE []]]) is -- Handle selection event of menu list. local a_title: STRING an_agent: ROUTINE [ANY, TUPLE []] do prepare_demo full_collect if an_element = Void then show_default title_label.set_text ("EiffelMedia Widget Browser") else a_title ?= an_element.item (1) title_label.set_text ("EiffelMedia Widget Browser - "+a_title) an_agent ?= an_element.item (2) an_agent.call ([]) end end string_from_tuple (a_tuple: TUPLE [STRING, ROUTINE [ANY, TUPLE []]]): STRING is -- String element from tuple as STRING. do Result ?= a_tuple.item (1) end handle_quit_event (a_quit_event: EM_QUIT_EVENT) is -- Handle quit event. local dialog: EM_MESSAGE_DIALOG do create dialog.make_from_question ("Do you really want to quit?") dialog.set_modal (True) dialog.yes_button.clicked_event.subscribe (agent quit) dialog.show end end