indexing description: "[ In a EM_TILE_PATTERN_HORIZONTAL a EM_DRAWABLE is glued together in horizontal direction exactly `times' times ]" date: "$Date$" revision: "$Revision$" class EM_TILE_PATTERN_HORIZONTAL inherit EM_TILE_PATTERN create make feature {NONE} -- creation make (a_drawable: EM_DRAWABLE; an_integer: INTEGER) is -- Create a EM_TILE_PATTERN_HORIZONTAL drawing `a_drawable' gluet together `an_integer' times require a_drawable_not_void: a_drawable /= void an_integer_greater_zero: an_integer > 0 do -- create left_part_rect.make (0, 0, 0, 0) -- create right_part_rect.make (0, 0, 0, 0) img := a_drawable times := an_integer set_visible (True) ensure set: img = a_drawable and times = an_integer end feature -- commands draw (a_surface: EM_SURFACE) is -- Draws current to `a_surface' local i: INTEGER translation, translation_step: EM_VECTOR_2D do if is_visible then -- Set up coordinate system to draw image at the right position create translation.make (x - img.x, y - img.y) a_surface.translate_coordinates (translation) -- Calculate step to translate after each image. create translation_step.make (img.width, 0) -- Draw image `times' times moved by `translation_step'. from i := 0 until i >= times loop a_surface.draw_object (img) i := i + 1 a_surface.translate_coordinates (translation_step) end -- Retranslate corrdinates by the whole distance. translation_step.scale (i) translation := translation + translation_step a_surface.translate_coordinates (- translation) end end -- draw_part (rect: EM_RECT; a_surface: EM_SURFACE) is -- -- Draws `rect' part of `current' to `a_surface' -- do -- if rect.x < width then -- left_part_rect.set_x (0) -- left_part_rect.set_y (rect.y) -- left_part_rect.set_width (rect.x \\ img.width) -- left_part_rect.set_height (rect.height) -- -- right_part_rect.set_x (rect.x \\ img.width) -- right_part_rect.set_y (rect.y) -- right_part_rect.set_width (img.width - rect.x \\ img.width) -- right_part_rect.set_height (rect.height) -- -- draw_it (a_surface, rect.width) -- end -- end feature -- Status width: INTEGER is -- The `width' of `current' do result := img.width * times end height: INTEGER is -- The `height' of `current' do result := img.height end feature {NONE} -- implementation -- draw_it (a_surface: EM_SURFACE; max_width: INTEGER) is -- -- Draws exactly `max_width' pixel to `a_surface' to position starting at `x' `y'. -- -- Use `left_part_rect' and `right_part_rect' as the two parts of the img. -- local -- cur_width: INTEGER -- do -- img.set_y (y) -- from -- cur_width := 0 -- until -- cur_width + right_part_rect.width >= max_width -- loop -- if right_part_rect.width>0 then -- img.set_x (x + cur_width) -- img.draw_part(right_part_rect, a_surface) -- cur_width := cur_width + right_part_rect.width -- end -- if left_part_rect.width>0 then -- if not ( cur_width + left_part_rect.width > max_width ) then -- img.set_x (x + cur_width) -- img.draw_part (left_part_rect, a_surface) -- cur_width := cur_width + left_part_rect.width -- else -- -- draw the rest -- left_part_rect.set_width (max_width - cur_width) -- img.set_x (x + cur_width) -- img.draw_part (left_part_rect, a_surface) -- cur_width := cur_width + (max_width - cur_width ) -- check -- cur_width = max_width -- end -- end -- end -- end -- if cur_width < max_width then -- -- draw the rest if any -- right_part_rect.set_width ( max_width - cur_width ) -- img.set_x (x + cur_width) -- img.draw_part (right_part_rect, a_surface) -- cur_width := cur_width + ( max_width - cur_width ) -- end -- check -- cur_width = max_width -- end -- end -- -- left_part_rect: EM_RECT -- -- The left part of `img' to be drawen -- -- right_part_rect: EM_RECT -- -- The right part of `img' to be drawen -- end