ListBrowser/SelectXPM.pm

filter: Statementstmt 19.1% 14 / 73 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 57.1% 4 / 7 Podpod 0.0% 0 / 3 totaltotal 18.1% 18 / 99 CC 13 SCAR 43.6
CC
13
Cov
16%
selectimage
132.0
offset
12.0
new
2.0
CRAP 78.6
« ListBrowser/Item.pm ↑ Summary ListBrowser/SideColumn.pm »
1 package Tk::ListBrowser::SelectXPM;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Convert::Color;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 $VERSION = 0.11;
9  
10 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
11 0 my ($class, $lb) = @_;
12 0 my $self = {
13 LB => $lb
14 };
15 0 bless($self, $class);
16 0 return $self
17 }
18  
19 0 ▶sub offset {
Subroutine offset: not called CC=3 SCAR=24.8
Pod undocumented
20 0 my ($self, $base, $factor, $div) = @_;
21 0 ▶ $div = 2 unless defined $div;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $div 0 0 0
22 0 $base = $base * 255;
23 0 my $new = ($base + $factor)/$div;
24 0 $new = $new/255;
25 0 ▶ return 1 if $new > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $new > 1 0 0 0
26 0 return $new
27 }
28  
29 0 ▶sub selectimage {
Subroutine selectimage: not called CC=11 SCAR=48.8
Pod undocumented
30 0 my ($self, $x1, $y1, $x2, $y2, $left, $right) = @_;
31 0 $x2 ++;
32 0 $y2 ++;
33 0 ▶ $left = 1 unless defined $left;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $left 0 0 0
34 0 ▶ $right = 1 unless defined $right;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $right 0 0 0
35  
36 0 my $width = $x2 - $x1;
37 0 my $height = $y2 - $y1;
38 0 my $lb = $self->{LB};
39  
40 #create rgb
41 0 my $sbg = $lb->cget('-selectbackground');
42 0 $sbg =~ s/^#//;
43 0 my $bg = Convert::Color->new("rgb8:$sbg");
44 0 my ($red, $green, $blue) = $bg->rgb;
45 #convert top rgb
46 0 my $tred = $self->offset($red, 255, 1.79);
47 0 my $tgreen = $self->offset($green, 255, 2);
48 0 my $tblue = $self->offset($blue, 255, 2);
49  
50 #convert bottom rgb
51 0 my $bred = $self->offset($red, 0, 1.81);
52 0 my $bgreen = $self->offset($green, 0, 1.81);
53 0 my $bblue = $self->offset($blue, 0, 1.75);
54  
55  
56 #uncomment this to test color conversion on kde theme Human KDE
57 # my $reft = Convert::Color->new("rgb8:EFB18F");
58 # my ($rtred, $rtgreen, $rtblue) = $reft->rgb;
59 #
60 # my $refb = Convert::Color->new("rgb8:673B12");
61 # my ($rbred, $rbgreen, $rbblue) = $refb->rgb;
62 #
63 # my $tored = $rtred / $tred;
64 # my $togreen = $rtgreen / $tgreen;
65 # my $toblue = $rtblue / $tblue;
66 #
67 # my $bored = $rbred / $bred;
68 # my $bogreen = $rbgreen / $bgreen;
69 # my $boblue = $rbblue / $bblue;
70 #
71 # print "ratio top: $tored, $togreen, $toblue\n";
72 # print "ratio bottom: $bored, $bogreen, $boblue\n";
73  
74 #create xpm color definitions
75 0 my $t = Convert::Color->new("rgb:$tred,$tgreen,$tblue");
76 0 my $b = Convert::Color->new("rgb:$bred,$bgreen,$bblue");
77 0 my $top = '#' . $t->as_rgb8->hex;
78 0 my $bottom = '#' . $b->as_rgb8->hex;
79 0 my $fill = '#' . $bg->as_rgb8->hex;
80  
81 #create the image
82 0 my $xpm = "/* XPM */
83 static char * select_draft_xpm[] = {
84 \"$width $height 3 1\",
85 \" c $top\",
86 \". c $bottom\",
87 \"+ c $fill\",
88 ";
89
90 0 my $base = "\" ";
91 0 my $end = ".\",\n";
92
93 #create top line
94 0 $xpm = "$xpm$base";
95 0 for (1 .. $width - 2) { $xpm = "$xpm "}
96 0 ▶ if ($right) {
Branch: 1 branch
BranchTrueFalseTotal
if ($right) { } 0 0 0
97 0 $xpm = "$xpm$end";
98 } else {
99 0 $xpm = "$xpm \",\n"
100 }
101  
102 #create body
103 0 my $line ="\"+";
104 0 ▶ $line = $base if $left;
Branch: 1 branch
BranchTrueFalseTotal
if $left 0 0 0
105 0 for (1 .. $width - 2) { $line = "$line+"}
106 0 ▶ if ($right) {
Branch: 1 branch
BranchTrueFalseTotal
if ($right) { } 0 0 0
107 0 $line = "$line$end";
108 } else {
109 0 $line = "$line+\",\n"
110 }
111 0 for (1 .. $height - 2) { $xpm = "$xpm$line" }
112  
113 #create bottom line
114 0 ▶ if ($left) {
Branch: 1 branch
BranchTrueFalseTotal
if ($left) { } 0 0 0
115 0 $xpm = "$xpm$base";
116 } else {
117 0 $xpm = "$xpm\"."
118 }
119 0 for (1 .. $width - 2) { $xpm = "$xpm."}
120 0 $xpm = "$xpm$end";
121
122 0 return $lb->Pixmap(-data => $xpm);
123 }
124  
125 1 1;
« ListBrowser/Item.pm ↑ Summary ListBrowser/SideColumn.pm »