The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Gtk2::Hexgrid::Tile - a hexagonal tile from a Hexgrid

SYNOPSIS

my @tiles = $hexgrid->get_all_tiles;
my $tile = $hexgrid->get_tile(3,5);
my $column = $tile->col;
my ($col, $row) = $tile->colrow;
my ($r, $g, $b) = $tile->rgb;
$tile->set_color(.1, .65, .35);
$tile->set_text('Clowndog', 13);
$tile->destroy_text;
$tile2 = $tile->southwest;

DESCRIPTION

CONSTRUCTOR

new

my $tile = new Gtk2::Hexgrid::Tile ($hexgrid, $col, $row, $r, $g, $b)

There's probably no reason to learn the constructor: Tiles are automatically generated with your hexgrid. $hexgrid, $col, $row are there so it knows. $r, $g, $b are it's default color, and it may be changed later.

METHODS

accessors

rgb
col
row
colrow
hexgrid
background
items

get_adjacent

See Gtk2::Hexgrid::get_adjacent_tiles

get_center

See Gtk2::Hexgrid::get_tile_center

relative locating

Methods are provided to find whatever tile is adjacent in a specific direction. These return the adjacent tile if it exists, else undef.

$tile->north
$tile->n
$tile->northeast
$tile->ne
etc...
north
n
northeast
ne
southeast
se
south
s
southwest
sw
northwest
nw

set_background

$tile->set_background("data/onion.png");

Loads a png file, scales it to tile size, and has $tile draw it first whenever it needs drawn.

Backgrounds are cached, so dont worry about loading the same file more than once Backgrounds are given a low (-21.21) priority so that they are drawn first.

Not redrawn automatically.

set_color

$tile->set_color($r, $g, $b);

Cairo colors (range is 0 to 1). Not redrawn automatically

set_text

my $size = 14
$tile->set_text('uoewriu', $size) = @_;

Text is given a priority of 21.21. If you want to paint over it, give something a higher prioriry. Not redrawn automatically.

add_item

$tile->add_item($item);

Attaches $item to $tile.

remove_item

$tile->remove_item($item);

Removes $item from $tile.

has_item

$tile->remove_item($item);

Returns true if $item is attached to $tile, else false.

destroy_background

$tile->destroy_background;

Removes background items from tile. Actually, it believes that all items with a -21.21 priority are background items.

destroy_text

$tile->destroy_text;

Removes all text items from tile. Actually, it believes that all items with a 21.21 priority are text items.

draw

$tile->draw();
$tile->draw($r, $g, $b);

Draws tile using tile's color unless another color is given. Associated with $hexgrid->draw_tile and $hexgrid->draw_tile_ref.