indexing description: "[ Objects of type GUI_CONTAINER consist of a background of type GUI_SPECIAL_FRAME and a collection of special buttons which can be drawn on that background. The buttons are aligned horizontally. You can specify the spacing between the items. This class is part of the XAE Extended Adventure Engine Project. ]" author: "Ralph Wiedemeier, ralphw@student.ethz.ch" date: "$Date$" revision: "$Revision$" class GUI_CONTAINER inherit GUI_SPECIAL_FRAME rename draw as draw_frame redefine make_from_position_and_size, set_x, set_y, publish_event_click, publish_event_hoover end create make_from_position_and_size, make_from_rect feature -- Initialization make_from_position_and_size (an_x: INTEGER; an_y: INTEGER; a_width: INTEGER; a_height: INTEGER) is -- create new container with specified position and size do create item_list.make Precursor (an_x, an_y, a_width, a_height) set_item_spacing (2) end feature -- List management start is -- Go to start of item list do item_list.start end forth is -- Advance to next element of item list do item_list.forth end after: BOOLEAN is -- Is current position after the end of item list? do result := item_list.after end item: GUI_SPECIAL_BUTTON is -- Get current item do result := item_list.item end extend (an_item: GUI_SPECIAL_BUTTON) is -- Add 'an_item' to item_list do item_list.extend (an_item) update_item_positions end prune (an_item: GUI_SPECIAL_BUTTON) is -- Remove 'an_item' from item_list do item_list.prune (an_item) update_item_positions end clear is -- Empty list of items do create item_list.make end count: INTEGER is -- Number of items in the item_list do result := item_list.count end feature -- Status set_x (an_x: INTEGER) is -- Set horizontal position of container and update all items do Precursor (an_x) update_item_positions end set_y (an_y: INTEGER) is -- Set vertical position of container and update all items do Precursor (an_y) update_item_positions end set_item_spacing (a_value: INTEGER) is -- Set spacing between items (in pixels) require spacing_valid: a_value >= 0 do item_spacing := a_value end item_spacing: INTEGER auto_resize is -- Resize container in respect to its items local w: INTEGER do from item_list.start w := item_spacing until item_list.after loop w := w + item_list.item.width + item_spacing item_list.forth end set_width (w) end feature -- Representation draw (a_surface: EM_VIDEO_SURFACE) is -- Draw representation of current to 'a_surface' do draw_frame (a_surface) from item_list.start until item_list.after loop item_list.item.draw (a_surface) item_list.forth end end feature -- Event handling publish_event_click (mouse_x: INTEGER; mouse_y: INTEGER) is -- do Precursor (mouse_x, mouse_y) from item_list.start until item_list.after loop item_list.item.publish_event_click (mouse_x, mouse_y) item_list.forth end end publish_event_hoover (mouse_x: INTEGER; mouse_y: INTEGER) is -- do Precursor (mouse_x, mouse_y) from item_list.start until item_list.after loop item_list.item.publish_event_hoover (mouse_x, mouse_y) item_list.forth end end feature {NONE} -- Implementation update_item_positions is -- If position of container changed, update positions -- of all elements in the item list local temp_x, temp_y: INTEGER do temp_x := x + item_spacing from item_list.start until item_list.after loop temp_y := y + (height - item_list.item.height) // 2 item_list.item.set_position (temp_x, temp_y) temp_x := temp_x + item_list.item.width + item_spacing item_list.forth end end item_list: LINKED_LIST [GUI_SPECIAL_BUTTON] end -- class GUI_CONTAINER