Changeset 5600


Ignore:
Timestamp:
06/26/09 08:26:45 (3 years ago)
Author:
submersible_toaster
Message:

allow caller of ::find() to prefer

size= icons= ext= Padre::Wx::Icon::find('status/foo.png',{size='64x64'});

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Padre/lib/Padre/Wx/Icon.pm

    r5548 r5600  
    2121use Padre::Util (); 
    2222use Padre::Wx   (); 
     23use Params::Util qw( _HASH ); 
    2324 
    2425our $VERSION = '0.37'; 
     
    3738); 
    3839 
     40# Lay down some defaults from our common 
     41# constants 
     42my %PREFS = ( 
     43    size => SIZE, 
     44    ext  => EXT, 
     45    icons=> ICONS, 
     46); 
     47 
    3948our $DEFAULT_ICON_NAME = 'status/padre-fallback-icon'; 
    4049our $DEFAULT_ICON; 
     
    4857sub find { 
    4958    my $name = shift; 
    50  
     59    my $prefs = shift; 
     60    # If you _really_ are competant ;), prefer size,icons,ext 
     61    # over the defaults 
     62    my %pref = _HASH( $prefs ) 
     63        ? ( %PREFS , %$prefs ) 
     64        : %PREFS; 
    5165    # Search through the theme list 
    5266    foreach my $theme (THEMES) { 
     
    5670            : $name; 
    5771        my $file = File::Spec->catfile( 
    58             ICONS, 
     72            $pref{icons}, 
    5973            $theme, 
    60             SIZE, 
     74            $pref{size}, 
    6175            ( split /\//, $hinted ) 
    62         ) . '.png'; 
     76        ) . $pref{ext}; 
    6377        next unless -f $file; 
    64         return Wx::Bitmap->new( $file, Wx::wxBITMAP_TYPE_PNG ); 
     78        return cast_to_icon( 
     79            Wx::Bitmap->new( $file, Wx::wxBITMAP_TYPE_PNG ) 
     80        ); 
    6581    } 
    6682 
     
    86102} 
    87103 
     104sub cast_to_icon{ 
     105    my $icon = Wx::Icon->new; 
     106    $icon->CopyFromBitmap( shift ); 
     107    return $icon; 
     108} 
     109 
    881101; 
    89111 
Note: See TracChangeset for help on using the changeset viewer.