indexing description: "[ Deferred Brick Breaker Menu ]" date: "$Date$" revision: "$Revision$" deferred class BB_MENU inherit EM_WIDGET_SCENE redefine handle_key_down_event end BB_CONSTANTS EM_SHARED_STANDARD_FONTS export {NONE} all end BB_SHARED_AUDIO export {NONE} all end feature {NONE} -- Initialization init_menu is -- create backround and title do make_widget_scene -- create background create menu_background.make_from_file ("./images/backgrounds/menubg.jpg") set_background (menu_background) -- create title create title.make_from_text ("Brick Breaker") title.set_font(create {EM_TTF_FONT}.make_from_ttf_file ("./fonts/dungeon.ttf", 80)) title.set_foreground_color (create {EM_COLOR}.make_white) title.resize_to_optimal_dimension title.set_position (Window_width // 2 - title.width // 2, 10) add_widget(title) -- create subtitle create subtitle.make_from_text ("Cow Edition") subtitle.set_font(create {EM_TTF_FONT}.make_from_ttf_file ("./fonts/moo.ttf", 30)) subtitle.set_foreground_color (create {EM_COLOR}.make_white) subtitle.resize_to_optimal_dimension subtitle.set_position (435, 90) add_widget(subtitle) create menu_buttons.make video_subsystem.show_cursor end feature -- Status setting set_selected_menu_item (item: integer) is -- select menu item 'item' require valid_menu_item: item >= 1 and item <= menu_buttons.count do if selected_menu_item >= 1 and selected_menu_item <= menu_buttons.count then menu_buttons.i_th (selected_menu_item).set_foreground_color (create {EM_COLOR}.make_white) end menu_buttons.i_th (item).set_foreground_color (create {EM_COLOR}.make_with_rgb(255,0,0)) selected_menu_item := item ensure selected_menu_item_set: selected_menu_item = item end feature -- Access add_button (button: BB_MENU_BUTTON) is -- add button require button_not_void: button /= Void do button.mouse_entered_event.subscribe (agent menu_item_mouse_enter (menu_buttons.count + 1)) button.pressed_event.subscribe (agent handle_pressed_event) menu_buttons.extend (button) add_widget (button) end feature -- Events back_button_pressed is -- back button pressed deferred end handle_pressed_event is -- do play_sound (Sound_menu_click) end menu_item_mouse_enter (item: INTEGER) is -- handle mouse enter event require valid_menu_item: item >= 1 and item <= menu_buttons.count do set_selected_menu_item(item) end handle_key_down_event (a_keyboard_event: EM_KEYBOARD_EVENT) is -- Handle keyboard events require else a_keyboard_event_not_void: a_keyboard_event /= Void local do Precursor (a_keyboard_event) if a_keyboard_event.key = a_keyboard_event.sdlk_down then if selected_menu_item < menu_buttons.count then set_selected_menu_item (selected_menu_item + 1) end elseif a_keyboard_event.key = a_keyboard_event.sdlk_up then if selected_menu_item > 1 then set_selected_menu_item (selected_menu_item - 1) end elseif a_keyboard_event.key = a_keyboard_event.sdlk_return then menu_buttons.i_th (selected_menu_item).pressed_event.publish ([]) elseif a_keyboard_event.key = a_keyboard_event.sdlk_escape then back_button_pressed end end feature -- Status menu_buttons: LINKED_LIST[BB_MENU_BUTTON] -- menu items feature {NONE} -- Implementation menu_background: EM_BITMAP_BACKGROUND -- background bitmap title: EM_LABEL -- title subtitle: EM_LABEL -- subtitle selected_menu_item: INTEGER -- selected menu item end