NAME
CSS::SpriteMaker::Layout - Layout interface for items placed on a 2D grid.
Allows to access coordinates of items laid out on a 2D grid.
Shouldn't be instantiated directly, but subclasses should be instantiated instead.
VERSION
Version 0.04
_layout_items
Lays out the items given their properties. These properties can be global or about individual items, and have the form of the following hashref:
{
'<item_id>' : {
width => <integer>,
height => <integer>,
first_pixel_x => <integer>,
first_pixel_y => <integer>,
... other arbitrary properties, if any
},
...
}
This method should never be called on this class, but on a subclass. It contains the implementation of the specific layout after all.
get_item_coord
Gets the coordinates of a specific item within the layout.
my ($x, $y) = $Layout->get_item_coord("129");
Returns a list containing the x and the y coordinates of the specified element respectively.
set_item_coord
Sets the coordinates of a layout item.
# sets coordinates of item #129 to x: 100 y: 200
$Layout->set_item_coord("129", 100, 200);
Sets coordinates of the given element internally and returns undef.
move_items
Moves all the items in this layout by the given deltay and deltax.
delete_item
Deletes the item with the specified id from the internal list of items that have been layed out.
WARNING - this doesn't trigger a re-layout: will result in having a hole in the current layout. Be aware of it.
Triggers a warning if the element with the specified id doesn't exist in the current layout.
merge_with
Merges the current layout with the one specified. For a successful merge to happen, items in the old and in the new layout must have different ids.
get_item_ids
Returns the id of each item into an array.
my @ids = $Layout->get_item_ids();
get_layout_ascii_string
Returns the current layout in an ascii string suitable for console printing.
Optionally takes width and height of the canvas in px if the canvas is to be reduced to a specific dimension in pixels.
my $ascii_string = $Layout->get_layout_ascii_string();
OR
my $ascii_string = $Layout->get_layout_ascii_string({
canvas_width => 80,
canvas_height => 60,
rh_item_info => {
'<item_id>' => {
width => <integer>,
height => <integer>,
},
...
}
});
NOTE: the $Layout->finalize() method should've been called prior calling this method.
width
Returns the width of the overall layout in pixels.
my $width = $Layout->width();
height
Returns the height of the overall layout in pixels.
my $width = $Layout->height();
finalize
Sets this layout as instantiated. To only be called by a subclass of this base class once class is instantiated.
$Layout->finalize();
Once called, some checks are performed on the layout and warnings are issued emitted if something is wrong.
Always returns undef.