From: Waldemar B. <wb...@sa...> - 2010-06-08 06:16:21
|
Hello! I have a question: How to improve refreshing speed? Problem is as follows: I refresh labels and textfields very offen in table views. The refreshing consists of changing mainly background, but also foreground, fontsize etc. The way I am doing it is using $object->Change( @parameters ) function which is encapsulated in my Refresh(...) function (this function is copied later on). As you can see the Change method is the main part of the Refresh function. Because there is many such refreshings the user fills some slowness. Is it possible in a relatively simple way to replace this Change function with some other which would be closer (and therefore faster) to Windows system graphics? Waldemar ============================== sub Refresh { my ( $screen, $object, $type ) = ( shift, shift, shift ); $object = '' unless $object; return unless $screen->{$object}; my %parameter; my @attributes = (); my @attributes_2; my ( $par, $val ); my %new_font = Win32::GUI::Font::Info($screen->{$object}->GetFont()); my $change_value = 0; my $value = ''; my $change_visible = 0; my $visible = 0; my $change_readonly = 0; my $readonly = 0; my $change_font = 0; while ( $par = shift ) { $val = shift; #print "par/value = $par / $value\n"; if ( $par eq '-visible' ) { $change_visible = 1; $visible = $val; $visible = 0 unless $visible; } elsif ( $par eq '-readonly' ) { $change_readonly = 1; $readonly = 1 if $val; $readonly = 0 unless $readonly; } elsif ( $par eq '-background' ) { push @attributes, ( -background=>$val ); # push @attributes_2, ( -background=>$val ); } elsif ( $par eq '-text' ) { $change_value = 1; $value = $val; $value = '' unless defined $value; } else { push @attributes, ( $par=>$val ); } if ( $par =~ /-fontsize|-fontweight/ ) { $val = 0 unless $val; $val += 0; if ( $par eq '-fontsize' && $val != $new_font{-height} ) { $change_font = 1; $new_font{-height} = $val; } elsif ( $par eq '-fontweight' && $val != $new_font{-weight} ) { $change_font = 1; $new_font{-weight} = $val; } } elsif ( $par =~ /-fontname/ && $val ne $new_font{-name} ) { $change_font = 1; $new_font{-name} = $val; } } if ( $change_font ) { $screen->{$object.'font'} = Win32::GUI::Font->new( -name => $new_font{-name}, -size => $new_font{-height}, -weight=> $new_font{-weight}, ); push @attributes, ( -font=>$screen->{$object.'font'} ); } if ( $type =~ /checkbox|boolean/i ) { if ( $value ) { push @attributes, ( -background=>0xccffcc ) } elsif ( $value eq '0' ) { push @attributes, ( -background=>0xccccff ) } else { push @attributes, ( -background=>0xffffff ) } } elsif ( $type =~ /integer/i ) { my $val = $value; $val = 0 unless $val; $val =~ s/ //g; $val += 0; } elsif ( $type =~ /money/i ) { my $val = $value; $val = 0 unless $val; $val =~ s/ //g; $val += 0; if ( $val < 0 ) { push @attributes, ( -foreground=>0x0000aa ) } elsif ( $val > 0 ) { push @attributes, ( -foreground=>0x000000 ) } else { push @attributes, ( -foreground=>0x333333 ) } } if ( @attributes ) { #print "object = $object\n"; #print "attributes = @attributes\n"; $screen->{$object}->Hide() if $change_font; $screen->{$object}->Change(@attributes) if @attributes; $screen->{$object}->Show() if $change_font; } $screen->{$object.'_2'}->Change(-text=>'',@attributes_2) if @attributes_2 && $screen->{$object.'_2'} && $object=~/VAR|FILL/i; $screen->{$object.'_3'}->Change(-text=>'',@attributes_2) if @attributes_2 && $screen->{$object.'_3'} && $object=~/VAR|FILL/i; if ( $change_visible ) { $screen->{$object}->Show(1) if $visible; $screen->{$object.'_0'}->Show(1) if $visible && $screen- >{$object.'_0'}; $screen->{$object.'_1'}->Show(1) if $visible && $screen- >{$object.'_1'}; $screen->{$object.'_2'}->Show(1) if $visible && $screen- >{$object.'_2'}; $screen->{$object.'_3'}->Show(1) if $visible && $screen- >{$object.'_3'}; $screen->{$object}->Hide() if $visible == 0; $screen->{$object.'_0'}->Hide() if $visible == 0 && $screen- >{$object.'_0'}; $screen->{$object.'_1'}->Hide() if $visible == 0 && $screen- >{$object.'_1'}; $screen->{$object.'_2'}->Hide() if $visible == 0 && $screen- >{$object.'_2'}; $screen->{$object.'_3'}->Hide() if $visible == 0 && $screen- >{$object.'_3'}; } if ( $change_readonly ) { $screen->{$object}->ReadOnly( $readonly ); $screen->{$object.'_2'}->ReadOnly( $readonly ) if $screen- >{$object.'_2'} && $object =~ /VAR/;; $screen->{$object.'_3'}->ReadOnly( $readonly ) if $screen- >{$object.'_3'} && $object =~ /VAR/;; } if ( $change_value ) { if ( $type =~ /checkbox/i ) { $value = 1 if $value; $value = 0 unless $value; $screen->{$object}->SetCheck( $value ) } elsif ( $type =~ /datetime/i ) { $value =~ /(\d{2})-(\d{2})-(\d{4})/; $screen->{$object}->SetDate( $1, $2, $3 ); } else { if ( $type =~ /boolean/i ) { $value = 1 if $value; $value = 0 unless $value; } $value = '' unless defined $value; $screen->{$object}->Change( -text => $value ); } } } |