_method graphics_system.align_current_set(_optional mode) ## Aligns selected geometries based on bounds. MODE can be ## :horiz_left (default), :horiz_centre, :horiz_right, ## :vert_top, :vert_centre, or :vert_bottom mode << mode.default(:left) s << _self.current_set n << s.size _if n < 2 _then _return _endif # Find extreme points bb << s.an_element().bounds leftmost << bb.centre_left.x rightmost << bb.centre_right.x topmost << bb.top_centre.y bottommost << bb.bottom_centre.y _for g _over s.fast_elements() _loop bb << g.bounds l << bb.centre_left.x _if l < leftmost _then leftmost << l _endif r << bb.centre_right.x _if r > rightmost _then rightmost << r _endif b << bb.bottom_centre.y _if b < bottommost _then bottommost << b _endif t << bb.top_centre.y _if t > topmost _then topmost << t _endif _endloop centre_x << (rightmost + leftmost) / 2 centre_y << (topmost + bottommost) / 2 # Now go back and readjust _for g _over s.elements() _loop bb << g.bounds l << bb.centre_left.x r << bb.centre_right.x t << bb.top_centre.y b << bb.bottom_centre.y cx << (r + l) / 2 cy << (t + b) / 2 # Create transform based on mode tr << transform.new() _if mode _is :vert_bottom _then tr << tr.translate(0, bottommost - b) _elif mode _is :vert_centre _then tr << tr.translate(0, centre_y - cy) _elif mode _is :vert_top _then tr << tr.translate(0, topmost - t) _elif mode _is :horiz_right _then tr << tr.translate(rightmost - r, 0) _elif mode _is :horiz_centre _then tr << tr.translate(centre_x - cx, 0) _else # horiz_left tr << tr.translate(leftmost - l, 0) _endif g.transform(tr) _endloop _endmethod