indexing description: "[ MENU contains functionalities used by all menus in the game. ]" date: "$Date$" revision: "$Revision$" deferred class MENU inherit EM_SCENE redefine handle_key_down_event end EM_SHARED_SUBSYSTEMS export {NONE} all end EM_SHARED_BITMAP_FACTORY export {NONE} all end EM_SHARED_STANDARD_FONTS export {NONE} all end feature -- Initialization initialize_scene is -- Initialize the scene local bitmap: EM_BITMAP titel: EM_STRING keyboard: EM_KEYBOARD do create scene.make -- don't repeat key events create keyboard.make_snapshot keyboard.disable_repeating_key_down_events -- build the fonts normal_font := standard_bmp_fonts.big_font bitmap_factory.create_bitmap_from_image ("fonts/century_gothic.gif") bitmap := bitmap_factory.last_bitmap bitmap.set_transparent_color (0, 0, 0) create {EM_BMP_FONT} select_font.make (bitmap) -- build the titel create titel.make ("EM Racing 3D", normal_font) -- create {EM_COLOR_TTF_FONT}.make_from_ttf_font_color (Standard_ttf_fonts.bitstream_vera_sans (60), create {EM_COLOR}.make_white)) titel.set_x_y (60,40) scene.extend (titel) Video_subsystem.video_surface.set_clear_color (create {EM_COLOR}.make_black) end feature {NONE} -- Event handler handle_key_down_event (a_keyboard_event: EM_KEYBOARD_EVENT) is -- Handle keyboard events. local key: INTEGER do key := a_keyboard_event.key if key = a_keyboard_event.sdlk_down then selected_nr := selected_nr + 1 if selected_nr > menu_entries.count then selected_nr := 1 end end if key = a_keyboard_event.sdlk_up then selected_nr := selected_nr - 1 if selected_nr < 1 then selected_nr := menu_entries.count end end if key = a_keyboard_event.sdlk_return then on_select start_next_scene end end on_select is -- Set the `next_scene' according to `selected_nr' here deferred end feature {NONE} -- implementation scene: EM_DRAWABLE_CONTAINER [EM_DRAWABLE] -- The scene select_font: EM_FONT -- The font used to display a selected menu entry normal_font: EM_FONT -- The font used to display the not selected menu entries menu_entries: ARRAY [EM_STRING] -- The menu entries selected_nr: INTEGER -- The number of the selected entry draw_menu_entries is -- Draws the `menu_entry' local i: INTEGER do from i:=1 until i > menu_entries.count loop if i = selected_nr then menu_entries.item (selected_nr).set_font (select_font) else menu_entries.item (i).set_font (normal_font) end menu_entries.item (i).draw (screen) i := i+1 end end end