From 8a81d2e8cafa2f4471b03538c9ba846603a3ed15 Mon Sep 17 00:00:00 2001 From: Thierry Vignaud Date: Mon, 1 Mar 2004 08:09:12 +0000 Subject: lighter cpu usage on wait_area: do not keep reseting wait_area background color once color has stabilized (aka once fading is complete) --- control-center | 49 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/control-center b/control-center index 4598748d..bc41cd49 100755 --- a/control-center +++ b/control-center @@ -684,20 +684,24 @@ sub stop_wait_area() { } $wait_darea->signal_connect(expose_event => sub { + my ($w) = @_; return if !$wait_darea->realized; return unless $run_pixbuf; # some people got an expose event before we start an embedded tool $wait_darea->{layout} ||= $wait_darea->create_pango_layout(N("Loading... Please wait")); my $pixbuf = $run_pixbufs{$run_counter} ||= render_alpha($run_pixbuf, $run_counter); - my $size = $wait_darea->allocation; - my ($d_width, $d_height) = ($size->width, $size->height); - my ($window, $gc, $width, $height) = ($wait_darea->window, $wait_darea->style->fg_gc('normal'), $pixbuf->get_width, $pixbuf->get_height); - my ($txt_width, $txt_height) = $wait_darea->{layout}->get_pixel_size; - my ($y_icon, $x_icon) = (($d_width - $width)/2, ($d_height - $height - $txt_height)/2); - my ($y_text, $x_text) = ($y_icon, $x_icon + $width + 5); - - $pixbuf->render_to_drawable($window, $gc, 0, 0, $y_icon, $x_icon, $width, $height, 'normal', 0, 0); + if (!$wait_darea->{size}) { + my $size = $wait_darea->{size} ||= $wait_darea->allocation; + my ($d_width, $d_height) = ($size->width, $size->height); + ($w->{pix_width}, $w->{pix_height}) = ($pixbuf->get_width, $pixbuf->get_height); + my ($txt_width, $txt_height) = $wait_darea->{layout}->get_pixel_size; + $w->{pix_yy} = ($d_width - $w->{pix_width})/2; + $w->{pix_xx} = ($d_height - $w->{pix_height} - $txt_height)/2; + $w->{text_yy} = $w->{pix_yy} + ($w->{pix_width} - $txt_width)/2; + $w->{text_xx} = $w->{pix_xx} + $w->{pix_height} + 5; + } + $pixbuf->render_to_drawable($w->window, $w->style->fg_gc('normal'), 0, 0, $w->{pix_yy}, $w->{pix_xx}, $w->{pix_width}, $w->{pix_height}, 'normal', 0, 0); my $style = $wait_darea->{style} ||= $wait_darea->get_style; - $wait_darea->window->draw_layout($style->text_gc('normal'), $y_text + $width/2 - $txt_width/2, $x_text, $wait_darea->{layout}); + $wait_darea->window->draw_layout($style->text_gc('normal'), $w->{text_yy}, $w->{text_xx}, $w->{layout}); $run_counter += $run_counter_add; $run_counter_add = -$run_counter_add if $run_counter < 100 || 255-$run_counter_add < $run_counter; }); @@ -850,19 +854,32 @@ sub compute_exec_string { $run_counter = 255; $run_counter_add = -5; undef $wait_darea->{color}; + undef $wait_darea->{size}; + $wait_darea->{not_yet_complete} = 1; $timeout = Glib::Timeout->add(35, sub { + my $size = $wait_darea->{size} ||= $wait_darea->allocation; + my ($width, $height) = ($size->width, $size->height); my $style = $wait_darea->{style} ||= $wait_darea->get_style; my $bg = $wait_darea->{bg} ||= $style->bg('normal'); my $base = $wait_darea->{base} ||= $style->base('normal'); my $color = $wait_darea->{color} ||= $base; # $base -> $bg - $wait_darea->window->set_background($color); - $wait_darea->{color} = gtkcolor(map { $_->[0] - min(500, $_->[0] - $_->[1]) } - ([ $color->red, $bg->red ], - [ $color->green, $bg->green ], - [ $color->blue, $bg->blue ]) - ); - $wait_darea->queue_draw; + my @colors = ([ $color->red, $bg->red ], + [ $color->green, $bg->green ], + [ $color->blue, $bg->blue ]); + if ($wait_darea->{not_yet_complete} && any { $_->[0] != $_->[1] } @colors) { + $wait_darea->window->set_background($color); + $wait_darea->{color} = gtkcolor(map { $_->[0] - min(500, $_->[0] - $_->[1]) } @colors); + $wait_darea->queue_draw; + } elsif ($wait_darea->{not_yet_complete}) { + # set exact color + $wait_darea->window->set_background($bg); + $wait_darea->queue_draw; + $wait_darea->{not_yet_complete} = 0; + } else { + my $w = $wait_darea; + $wait_darea->queue_draw_area($w->{pix_yy}, $w->{pix_xx}, $w->{pix_width}, $w->{pix_height}); + } 1; }); $left_locked = 1; -- cgit v1.2.1