use
Carp;
$VERSION
= 0.01;
sub
new {
my
$class
=
shift
;
my
%args
=
@_
;
my
$canv
=
delete
$args
{
'-canvas'
};
croak
'You did not specify a canvas'
unless
defined
$canv
;
my
$data
=
delete
$args
{
'-data'
};
my
$hidden
=
delete
$args
{
'-hidden'
};
$hidden
= 0
unless
defined
$hidden
;
my
$image
=
delete
$args
{
'-image'
};
my
$name
=
delete
$args
{
'-name'
};
croak
'You did not specify an name'
unless
defined
$name
;
my
$text
=
delete
$args
{
'-text'
};
$text
=
''
unless
defined
$text
;
my
$self
= {
ANCHOR
=> 0,
CANVAS
=>
$canv
,
COLUMN
=>
undef
,
DATA
=>
$data
,
HIDDEN
=>
$hidden
,
IMAGE
=>
$image
,
NAME
=>
$name
,
REGION
=> [0, 0, 0, 0],
ROW
=>
undef
,
SELECTED
=> 0,
TEXT
=>
$text
,
TFILL
=>
undef
,
};
bless
$self
,
$class
;
return
$self
}
sub
anchor {
my
(
$self
,
$flag
) =
@_
;
my
$c
=
$self
->canvas;
my
$p
=
$c
->Subwidget(
'Canvas'
);
$flag
= 1
unless
defined
$flag
;
my
$r
=
$self
->crect;
$self
->{ANCHOR} =
$flag
;
if
(
$flag
) {
my
$fg
=
$c
->cget(
'-foreground'
);
$p
->itemconfigure(
$r
,
-outline
=>
$fg
,
-dash
=> [3, 2],
);
}
else
{
my
$outline
;
$outline
=
$c
->cget(
'-selectbackground'
)
if
$self
->selected;
$p
->itemconfigure(
$r
,
-outline
=>
$outline
,
-dash
=>
undef
,
);
}
}
sub
anchored {
return
$_
[0]->{ANCHOR} }
sub
canvas {
return
$_
[0]->{CANVAS} }
sub
cimage {
my
$self
=
shift
;
$self
->{CIMAGE} =
shift
if
@_
;
return
$self
->{CIMAGE}
}
sub
clear {
my
$self
=
shift
;
my
$c
=
$self
->canvas->Subwidget(
'Canvas'
);
for
(
$self
->cimage,
$self
->ctext,
$self
->crect) {
$c
->
delete
(
$_
)
if
defined
$_
;
}
$self
->cimage(
undef
);
$self
->ctext(
undef
);
$self
->crect(
undef
);
$self
->column(
undef
);
$self
->row(
undef
);
$self
->region(0, 0, 0, 0);
}
sub
column {
my
$self
=
shift
;
$self
->{COLUMN} =
shift
if
@_
;
return
$self
->{COLUMN}
}
sub
crect {
my
$self
=
shift
;
$self
->{CRECT} =
shift
if
@_
;
return
$self
->{CRECT}
}
sub
ctext {
my
$self
=
shift
;
$self
->{CTEXT} =
shift
if
@_
;
return
$self
->{CTEXT}
}
sub
data {
my
$self
=
shift
;
$self
->{DATA} =
shift
if
@_
;
return
$self
->{DATA}
}
sub
hidden {
my
$self
=
shift
;
$self
->{HIDDEN} =
shift
if
@_
;
return
$self
->{HIDDEN}
}
sub
image {
my
$self
=
shift
;
$self
->{IMAGE} =
shift
if
@_
;
return
$self
->{IMAGE}
}
sub
inregion {
my
(
$self
,
$x
,
$y
) =
@_
;
my
(
$cx
,
$cy
,
$cdx
,
$cdy
) =
$self
->region;
return
''
unless
$x
>=
$cx
;
return
''
unless
$x
<=
$cdx
;
return
''
unless
$y
>=
$cy
;
return
''
unless
$y
<=
$cdy
;
return
1
}
sub
name {
return
$_
[0]->{NAME} }
sub
region {
my
$self
=
shift
;
$self
->{REGION} = [
@_
]
if
@_
;
my
$r
=
$self
->{REGION};
return
@$r
;
}
sub
row {
my
$self
=
shift
;
$self
->{ROW} =
shift
if
@_
;
return
$self
->{ROW}
}
sub
select
{
my
(
$self
,
$flag
) =
@_
;
$flag
= 1
unless
defined
$flag
;
my
$c
=
$self
->canvas;
my
$p
=
$c
->Subwidget(
'Canvas'
);
my
$r
=
$self
->crect;
my
$t
=
$self
->ctext;
$self
->{TFILL} =
$p
->itemcget(
$t
,
'-fill'
)
unless
defined
$self
->{TFILL};
$self
->{SELECTED} =
$flag
;
if
(
$flag
) {
$p
->itemconfigure(
$r
,
-fill
=>
$c
->cget(
'-selectbackground'
),
-outline
=>
$c
->cget(
'-selectbackground'
),
);
$p
->raise(
$self
->cimage);
$p
->raise(
$t
);
$p
->itemconfigure(
$t
,
-fill
=>
$c
->cget(
'-selectforeground'
),
);
}
else
{
my
$outline
=
$c
->cget(
'-foreground'
);
$outline
=
undef
unless
$self
->anchored;
$p
->itemconfigure(
$r
,
-fill
=>
undef
,
-outline
=>
$outline
,
);
$p
->itemconfigure(
$t
,
-fill
=>
$self
->{TFILL},
);
}
}
sub
selected {
return
$_
[0]->{SELECTED} }
sub
text {
my
$self
=
shift
;
$self
->{TEXT} =
shift
if
@_
;
return
$self
->{TEXT}
}