indexing description: "[ Widget demo panel. ]" date: "$Date$" revision: "$Revision$" class WIDGETS_DEMO_PANEL inherit EM_PANEL EM_SHARED_STANDARD_FONTS export {NONE} all end SDL_MOUSE_FUNCTIONS_EXTERNAL export {NONE} all end create make feature {NONE} -- Initialisation make is -- Initialise panel. local panel: EM_PANEL imagepanel: EM_IMAGEPANEL label: EM_LABEL textbox: EM_TEXTBOX textarea: EM_TEXTAREA button: EM_BUTTON checkbox: EM_CHECKBOX slider: EM_SLIDER progressbar: EM_PROGRESS_BAR list: EM_TEXTLIST [STRING] combobox: EM_COMBOBOX [STRING] scrollpanel: EM_SCROLLPANEL cursor: EM_CURSOR do make_void_surface -- EM_LABEL create panel.make_from_dimension (300, 150) panel.set_border (create {EM_NAMED_BORDER}.make_from_text ("Labels")) panel.set_position (10, 10) add_widget (panel) create label.make_from_text ("Left aligned") label.set_font (Standard_ttf_fonts.bitstream_vera_sans_bold (14)) label.align_left label.set_position (5, 10) label.set_dimension (panel.inner_width-10, 20) panel.add_widget (label) create label.make_from_text ("Center aligned") label.set_font (Standard_ttf_fonts.bitstream_vera_sans_bold (14)) label.align_center label.set_position (5, 35) label.set_dimension (panel.inner_width-10, 20) panel.add_widget (label) create label.make_from_text ("Right aligned") label.set_font (Standard_ttf_fonts.bitstream_vera_sans_bold (14)) label.align_right label.set_position (5, 60) label.set_dimension (panel.inner_width-10, 20) panel.add_widget (label) create label.make_from_text ("Colored + shadow") label.set_font (standard_ttf_fonts.bitstream_vera_sans (16)) label.resize_to_optimal_dimension label.set_foreground_color (create {EM_COLOR}.make_with_rgb (255, 100, 200)) label.set_position (5, 85) label.enable_shadow panel.add_widget (label) create label.make_from_text ("Hover for one second over text") label.set_tooltip ("and see the tooltip") label.set_position (100, 125) panel.add_widget (label) create label.make_from_text ("Bitmap-font") label.set_foreground_color (create {EM_COLOR}.make_with_rgb (255, 100, 200)) label.set_background_color (create {EM_COLOR}.make_black) label.set_position (5, 105) label.set_font (Standard_bmp_fonts.small_vera_font) label.resize_to_optimal_dimension panel.add_widget (label) -- EM_TEXTBOX / EM_TEXTAREA create panel.make_from_dimension (300, 150) panel.set_border (create {EM_NAMED_BORDER}.make_from_text ("Textbox / Textarea")) panel.set_position (10, 170) add_widget (panel) create textbox.make_empty textbox.set_position (5, 15) textbox.set_dimension (280, 20) panel.add_widget (textbox) create textbox.make_from_text ("Predefined text and custom color") textbox.set_position (5, 40) textbox.set_dimension (280, 20) textbox.set_foreground_color (create {EM_COLOR}.make_with_rgb (255, 0, 0)) textbox.set_background_color (create {EM_COLOR}.make_with_rgb (255, 255, 100)) panel.add_widget (textbox) create textarea.make_from_text ("EM_TEXTAREA has no cursor yet. Just type in some text.") textarea.set_position (5, 65) textarea.set_dimension (280, 60) panel.add_widget (textarea) -- EM_BUTTON / EM_CHECKBOX / EM_RADIOBUTTON create panel.make_from_dimension (300, 150) panel.set_border (create {EM_NAMED_BORDER}.make_from_text ("Button / Checkbox")) panel.set_position (10, 330) add_widget (panel) create button.make_from_text ("Textbutton") button.set_position (5, 15) panel.add_widget (button) Bitmap_factory.create_bitmap_from_image ("image/misc.png") create button.make_from_image (Bitmap_factory.last_bitmap) button.set_position (100, 15) panel.add_widget (button) create button.make_from_text_image ("Text and Image", Bitmap_factory.last_bitmap) button.set_position (150, 15) panel.add_widget (button) create checkbox.make_from_text ("Check me") checkbox.set_position (5, 60) panel.add_widget (checkbox) -- EM_SLIDER / EM_PROGRESS_BAR create panel.make_from_dimension (300, 150) panel.set_border (create {EM_NAMED_BORDER}.make_from_text ("Slider / Progressbar")) panel.set_position (330, 10) add_widget (panel) create label.make_empty label.set_position (220, 15) label.set_dimension (50, 20) panel.add_widget (label) create slider.make_horizontal slider.set_position (5, 15) slider.set_dimension (200, 20) slider.position_changed_event.subscribe (agent set_label_text (label, ?)) panel.add_widget (slider) create label.make_empty label.set_position (220, 35) label.set_dimension (50, 20) panel.add_widget (label) create slider.make_from_range_horizontal (-7, 25) slider.set_position (5, 35) slider.set_dimension (200, 20) slider.position_changed_event.subscribe (agent set_label_text (label, ?)) panel.add_widget (slider) create label.make_empty label.set_position (220, 60) label.set_dimension (50, 20) panel.add_widget (label) create slider.make_from_range_vertical (-7, -3) slider.set_position (275, 10) slider.set_dimension (20, 80) slider.position_changed_event.subscribe (agent set_label_text (label, ?)) panel.add_widget (slider) create progressbar.make_from_dimension (200, 20) progressbar.set_position (5, 100) panel.add_widget (progressbar) create button.make_from_text ("+") button.set_position (220, 100) button.clicked_event.subscribe (agent progressbar.advance) panel.add_widget (button) create button.make_from_text ("reset") button.set_position (240, 100) button.clicked_event.subscribe (agent progressbar.reset) panel.add_widget (button) -- EM_LIST / EM_COMBOBOX create panel.make_from_dimension (300, 150) panel.set_border (create {EM_NAMED_BORDER}.make_from_text ("List / Combobox")) panel.set_position (330, 170) add_widget (panel) create list.make_empty list.set_position (5, 15) list.set_dimension (120, 90) list.insert_void_element list.put ("with") list.put ("empty") list.put ("element") panel.add_widget (list) create combobox.make_from_list (list.elements) combobox.insert_void_element combobox.set_position (5, 115) combobox.set_dimension (120, combobox.optimal_height) panel.add_widget (combobox) create list.make_empty list.set_position (140, 15) list.set_dimension (120, 90) list.put ("without") list.put ("empty") list.put ("element") panel.add_widget (list) create combobox.make_from_list (list.elements) combobox.set_position (140, 115) combobox.set_dimension (120, combobox.optimal_height) panel.add_widget (combobox) -- EM_SCROLLPANEL create panel.make_from_dimension (300, 150) panel.set_border (create {EM_NAMED_BORDER}.make_from_text ("Scrollpanel")) panel.set_position (330, 330) add_widget (panel) create list.make_empty list.insert_void_element list.put ("a") list.put ("very") list.put ("long") list.put ("list") list.put ("that") list.put ("needs") list.put ("scrollbars") list.put ("to") list.put ("scroll") list.put ("to") list.put ("the") list.put ("bottom") create scrollpanel.make_from_widget (list) scrollpanel.set_position (5, 15) scrollpanel.set_dimension (120, 120) panel.add_widget (scrollpanel) create imagepanel.make_from_file ("image/rotation_test.png") imagepanel.strech (2, 2) create scrollpanel.make_from_widget (imagepanel) scrollpanel.set_position (130, 15) scrollpanel.set_dimension (120, 120) panel.add_widget (scrollpanel) -- EM_CURSOR create panel.make_from_dimension (300, 150) panel.set_border (create {EM_NAMED_BORDER}.make_from_text ("Cursor")) panel.set_position (10, 490) add_widget (panel) -- Restore default cursor on exit cursor := Video_subsystem.default_cursor panel.mouse_exited_event.subscribe (agent cursor.show) Bitmap_factory.create_bitmap_from_image ("image/hand1.gif") create cursor.make_from_surface (Bitmap_factory.last_bitmap, 7, 5) panel.mouse_entered_event.subscribe (agent cursor.show) panel.mouse_button_up_event.subscribe (agent show_cursor(cursor, ?)) Bitmap_factory.create_bitmap_from_image ("image/hand2.gif") create cursor.make_from_surface (Bitmap_factory.last_bitmap, 7, 5) panel.mouse_button_down_event.subscribe (agent show_cursor(cursor, ?)) -- EM_CONTEXT_MENU create panel.make_from_dimension (300, 150) panel.set_border (create {EM_NAMED_BORDER}.make_from_text ("Context Menu")) panel.set_position (330, 490) panel.mouse_button_down_event.subscribe (agent popup_menu) add_widget (panel) create label_status.make_from_text ("right click for context menu") label_status.set_position (10, 65) label_status.set_dimension (280, 20) panel.add_widget (label_status) create context_menu.make_empty -- adding the menues in correct order is important -- it will show them in foreground or behind an other -- menu, so root menu first and then all sub menues add_widget (context_menu) -- create label.make_from_text ("Show Some") label.mouse_clicked_event.subscribe (agent handle_clicked) context_menu.put (label) create label.make_from_text ("Does It?") label.mouse_clicked_event.subscribe (agent handle_clicked) context_menu.put (label) create button.make_from_text ("Or Button") button.mouse_clicked_event.subscribe (agent handle_clicked) context_menu.put (button) -- create menu_item.make_from_text ("Sub Menu >") context_menu.put (menu_item) -- create context_sub_menu.make_empty -- it is also important in which parent widget you -- insert your context menues add_widget (context_sub_menu) create checkbox.make_from_text ("Checkbox 1") checkbox.checked_event.subscribe (agent handle_checkbox ("checked", 1)) checkbox.unchecked_event.subscribe (agent handle_checkbox ("unchecked", 1)) context_sub_menu.put (checkbox) create checkbox.make_from_text ("Checkbox 2") checkbox.checked_event.subscribe (agent handle_checkbox ("checked", 2)) checkbox.unchecked_event.subscribe (agent handle_checkbox ("unchecked", 2)) context_sub_menu.put (checkbox) menu_item.add_from_menu (context_sub_menu) -- end feature -- Agent wrapper set_label_text (label: EM_LABEL; number: INTEGER) is -- Set text of 'label' to 'number'. do label.set_text (number.out) end show_cursor (a_cursor: EM_CURSOR; an_event: EM_MOUSEBUTTON_EVENT) is -- Show 'a_cursor'. do a_cursor.show end feature {NONE} -- Context Menu context_menu: EM_CONTEXT_MENU context_sub_menu: EM_CONTEXT_MENU menu_item: EM_MENU_ITEM label_status: EM_LABEL popup_menu (an_event: EM_MOUSEBUTTON_EVENT) is -- do if an_event.is_right_button then -- we have to insert an offset of the widget -- because the event gives you the coordinates relative to -- the widget it occurs context_menu.set_position (an_event.x + 330, an_event.y + 490) context_menu.show_menu else context_menu.hide_menu end end handle_clicked (an_event: EM_MOUSEBUTTON_EVENT) is -- do label_status.set_text ("label or button has been pressed") end handle_checkbox (stat: STRING; nr: INTEGER) is -- do label_status.set_text ("checkbox " + nr.out + " has been " + stat) end end