line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Wx::App::Mastermind::Board::PegStrip; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
955
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
42
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
5
|
1
|
|
|
1
|
|
19
|
use base qw(Class::Accessor::Fast); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
1048
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
4064
|
use Wx qw(wxSOLID wxTRANSPARENT_BRUSH wxBLACK_PEN); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Wx::App::Mastermind::Board::Peg; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
__PACKAGE__->mk_ro_accessors( qw(peg_width peg_height peg_padding) ); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub draw { |
14
|
|
|
|
|
|
|
my( $self, $dc, $sx, $y, $pegs, $selected, $current ) = @_; |
15
|
|
|
|
|
|
|
my $delta = $self->peg_width + $self->peg_padding; |
16
|
|
|
|
|
|
|
my $x = $sx; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
$selected ||= ''; |
19
|
|
|
|
|
|
|
foreach my $peg ( @$pegs ) { |
20
|
|
|
|
|
|
|
Wx::App::Mastermind::Board::Peg->draw |
21
|
|
|
|
|
|
|
( $dc, $x, $y, |
22
|
|
|
|
|
|
|
$self->peg_width, $self->peg_height, |
23
|
|
|
|
|
|
|
$peg, $peg eq $selected ); |
24
|
|
|
|
|
|
|
$x += $delta; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
if( $current ) { |
28
|
|
|
|
|
|
|
$dc->SetPen( wxBLACK_PEN ); |
29
|
|
|
|
|
|
|
$dc->SetBrush( wxTRANSPARENT_BRUSH ); |
30
|
|
|
|
|
|
|
$dc->DrawRectangle( $sx - 2, $y - 2, |
31
|
|
|
|
|
|
|
$delta * @$pegs + 4 - $self->peg_padding, |
32
|
|
|
|
|
|
|
$self->peg_height + 4 ); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub get_size { |
37
|
|
|
|
|
|
|
my( $self, $peg_count ) = @_; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
return ( ( $self->peg_width + $self->peg_padding ) * $peg_count - |
40
|
|
|
|
|
|
|
$self->peg_padding, |
41
|
|
|
|
|
|
|
$self->peg_height ); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub hit_test { |
45
|
|
|
|
|
|
|
my( $self, $x, $y, $peg_count, $mx, $my ) = @_; |
46
|
|
|
|
|
|
|
my( $sx, $sy ) = $self->get_size( $peg_count ); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
return -1 if $my < $y || $my > $y + $sy |
49
|
|
|
|
|
|
|
|| $mx < $x || $mx > $x + $sx; |
50
|
|
|
|
|
|
|
my $delta = $self->peg_width + $self->peg_padding; |
51
|
|
|
|
|
|
|
my $hole = int( ( $mx - $x ) / $delta ); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
return $hole if $mx - $x <= $hole * $delta + $self->peg_width; |
54
|
|
|
|
|
|
|
return -1; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |