indexing description: "[ EM_DRAWABLE demo for EiffelMedia. This demonstrates how you can use the EM_DRAWABLE classes of EiffelMedia to build complex drawable objects. It uses an EM_SURFACE, EM_ANIMATION, EM_TILE_PATTERN_HORIZONTAL, EM_SPRITE, EM_DRAWABLE_CONTAINER and a EM_NEVER_ENDING_BACKGROUND_HORIZONTAL. See the feature `the_demo_code'. ]" date: "$Date$" revision: "$Revision$" class FIRST_SCENE inherit EM_DRAWABLE_SCENE redefine initialize_scene, handle_update_event, handle_key_down_event end EM_KEY_CONSTANTS export {NONE} all end EM_SHARED_BITMAP_FACTORY export {NONE} all end EM_SHARED_STANDARD_FONTS export {NONE} all end create make_scene feature -- Initialization initialize_scene is -- Create all needed objects and put them into `main_container'. local font: EM_FONT str: EM_STRING i: INTEGER flag: EM_BITMAP chain: EM_BITMAP plane: EM_BITMAP em_logo: EM_ANIMATION tp: EM_TILE_PATTERN_HORIZONTAL sprite: EM_SPRITE container: EM_DRAWABLE_CONTAINER [EM_DRAWABLE] nebh: EM_NEVER_ENDING_BACKGROUND_HORIZONTAL do font := standard_bmp_fonts.small_font set_frame_counter_visibility (true) create viewport.make (300, 300) main_container.extend (viewport) -- 1. create str.make ("1. Load all needed images (press return)", font) str.set_x_y (10, 40) viewport.extend (str) bitmap_factory.create_bitmap_from_image ("./pics/a_ende.png") flag := bitmap_factory.last_bitmap flag.set_x_y (-260, 60) viewport.extend (flag) bitmap_factory.create_bitmap_from_image ("./pics/a_kette.png") chain := bitmap_factory.last_bitmap chain.set_x_y (202,60) viewport.extend (chain) bitmap_factory.create_bitmap_from_image ("./pics/a_flieger.png") plane := bitmap_factory.last_bitmap plane.set_x_y (310,60) viewport.extend (plane) create em_logo.make_from_file ("./pics/em_4.anim") from i := 1 until i > em_logo.nr_of_frames loop em_logo.item (i).first.set_x_y (1024 - em_logo.item (i).first.width-(i-1)* 6, 57 + i * 4) viewport.extend (em_logo.item (i).first) i :=i + 1 end create str.make ("(EM_SURFACE)", font) str.set_x_y (180,70 + chain.height) viewport.extend (str) create str.make ("(EM_ANIMATION)", font) str.set_x_y (680,70 + chain.height) viewport.extend (str) -- 2. create str.make ("2. Create an EM_TILE_PATTERN_HORIZONTAL and a EM_SPRITE", font) str.set_x_y (10,350) viewport.extend (str) bitmap_factory.create_bitmap_from_image ("./pics/a_kette.png") chain := bitmap_factory.last_bitmap create tp.make (chain, 3) tp.set_x_y (140,370) viewport.extend (tp) create em_logo.make_from_file ("./pics/em_4.anim") create sprite.make_from_animation (em_logo, 600, 400) sprite.set_do_loop (True) sprite.start viewport.extend (sprite) create str.make ("(EM_TILE_PATTERN_HORIZONTAL)", font) str.set_x_y ( 50, 380+tp.height) viewport.extend (str) create str.make ("(EM_SPRITE)", font) str.set_x_y (670, 380+tp.height) viewport.extend (str) -- 3. create str.make ("3. Put it all into a EM_DRAWABLE_CONTAINER", font) str.set_x_y (10, 650) viewport.extend (str) create container.make bitmap_factory.create_bitmap_from_image ("./pics/a_ende.png") flag := bitmap_factory.last_bitmap flag.set_x_y (0, 0) container.extend (flag) bitmap_factory.create_bitmap_from_image ("./pics/a_kette.png") chain := bitmap_factory.last_bitmap create tp.make ( chain, 3) tp.set_x_y (flag.width,0) container.extend (tp) bitmap_factory.create_bitmap_from_image ("./pics/a_flieger.png") plane := bitmap_factory.last_bitmap plane.set_x_y (tp.x+tp.width,0) container.extend (plane) create sprite.make_from_animation (em_logo, 14, 30) sprite.set_do_loop (True) sprite.start container.extend (sprite) container.set_x_y ( 30, 670) viewport.extend (container) create str.make ("(EM_DRAWABLE_CONTAINER)", font) str.set_x_y (300, 680 + container.height) viewport.extend (str) -- 4. create str.make ("4. Now create an EM_NEVER_ENDING_BACKGROUND_HORIZONTAL", font) str.set_x_y (10, 940) viewport.extend (str) nebh := the_demo_code nebh.set_x_y (0, 960) nebh.set_speed (-40) viewport.extend (nebh) start_animating (nebh) create str.make ("(EM_NEVER_ENDING_BACKGROUND_HORIZONTAL)", font) str.set_x_y (220, 970 + nebh.height) viewport.extend (str) step_nr := 1 end the_demo_code: EM_NEVER_ENDING_BACKGROUND_HORIZONTAL is -- This is the sequence of code that builds the never ending background local flag: EM_BITMAP chain: EM_BITMAP plane: EM_BITMAP em_logo: EM_ANIMATION tp: EM_TILE_PATTERN_HORIZONTAL sprite: EM_SPRITE container: EM_DRAWABLE_CONTAINER [EM_DRAWABLE] do -- 1. Load all needed images bitmap_factory.create_bitmap_from_image ("./pics/a_ende.png") flag := bitmap_factory.last_bitmap bitmap_factory.create_bitmap_from_image ("./pics/a_kette.png") chain := bitmap_factory.last_bitmap bitmap_factory.create_bitmap_from_image ("./pics/a_flieger.png") plane := bitmap_factory.last_bitmap create em_logo.make_from_file ("./pics/em_4.anim") -- 2. Create an EM_TILE_PATTERN_HORIZONTAL and an EM_SPRITE create tp.make (chain, 3) create sprite.make_from_animation (em_logo, 14, 30) -- 3. Put it all into an EM_DRAWABLE_CONTAINER create container.make container.extend (flag) tp.set_x_y (flag.width,0) container.extend (tp) plane.set_x_y (tp.x+tp.width,0) container.extend (plane) sprite.set_do_loop (True) sprite.start container.extend (sprite) -- 4. Now create a EM_NEVER_ENDING_BACKGROUND_HORIZONTAL create Result.make (container) end feature {NONE} -- Implementation viewport: EM_ZOOMABLE_CONTAINER -- Viewport to restrict only viewing a part of the contained objects and to scroll them step_nr: INTEGER -- The step number currently shown to user pos: INTEGER -- Position used for animated scrolling handle_key_down_event (a_keyboard_event: EM_KEYBOARD_EVENT) is -- Handle keyboard events. do if a_keyboard_event.key = sdlk_escape then event_loop.stop end if a_keyboard_event.key = sdlk_return then step_nr := step_nr + 1 pos := 0 if step_nr > 4 then event_loop.stop end end end handle_update_event is -- Handle the outside event. do if pos < 100 then pos := pos + 2 end scroll_and_clip_viewport end scroll_and_clip_viewport is -- Clip and scroll content of `viewport' according to `step_nr' and `pos'. local position: EM_VECTOR_2D do if step_nr = 1 then viewport.set_x_y (0, 70) viewport.set_size (screen.width, 300) elseif step_nr = 2 then viewport.set_size (screen.width, 300 + 3 * pos) elseif step_nr = 3 then create position.make (0, 3 * pos) viewport.scroll (position - viewport.visible_area.upper_left) viewport.set_size (screen.width, 580) else create position.make (0, 300 + 3 * pos) viewport.scroll (position - viewport.visible_area.upper_left) viewport.set_size (screen.width, 580) end end end