| 1 | package LPDS::Util; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use feature qw/say/; | ||
| 5 | use Gtk2; | ||
| 6 | |||
| 7 | use Exporter; | ||
| 8 | our @ISA = qw/Exporter/; | ||
| 9 | |||
| 10 | our @EXPORT = qw/uint_to_gdk_color gdk_color_to_uint search_list_store/; | ||
| 11 | |||
| 12 | sub gdk_color_to_uint { | ||
| 13 | my $color_obj = shift; | ||
| 14 | |||
| 15 | my $color = 0x000000ff; | ||
| 16 | my $red = int( 255 * $color_obj->red / 65535 ) << 24; | ||
| 17 | my $green = int( 255 * $color_obj->green / 65535 ) << 16; | ||
| 18 | my $blue = int( 255 * $color_obj->blue / 65535 ) << 8; | ||
| 19 | $color += $red; | ||
| 20 | $color += $green; | ||
| 21 | $color += $blue; | ||
| 22 | |||
| 23 | return $color; | ||
| 24 | } | ||
| 25 | |||
| 26 | sub uint_to_gdk_color { | ||
| 27 | my $color = shift; | ||
| 28 | my $red = ( $color & 0xff000000 ) >> 24; | ||
| 29 | my $green = ( $color & 0x00ff0000 ) >> 16; | ||
| 30 | my $blue = ( $color & 0x0000ff00 ) >> 8; | ||
| 31 | |||
| 32 | foreach ( $red, $green, $blue ) { | ||
| 33 | $_ = int( 65535 * $_ / 255 ); | ||
| 34 | } | ||
| 35 | |||
| 36 | return Gtk2::Gdk::Color->new( $red, $green, $blue ); | ||
| 37 | } | ||
| 38 | |||
| 39 | sub search_list_store { | ||
| 40 | my ( $store, $column, $value ) = @_; | ||
| 41 | my $iter; | ||
| 42 | for ( | ||
| 43 | $iter = $store->get_iter_first ; | ||
| 44 | defined $iter ; | ||
| 45 | $iter = $store->iter_next($iter) | ||
| 46 | ) | ||
| 47 | { | ||
| 48 | my $curr = $store->get($iter,$column); | ||
| 49 | last if $curr eq $value; | ||
| 50 | } | ||
| 51 | |||
| 52 | return $iter; | ||
| 53 | } | ||
| 54 | |||
| 55 | 1; |