[Fwd: Re: ComboBox with multiple cellrenderers]




--- Begin Message ---


as far as "the performance on this thing is pretty poor", um, in what way?  it
seems to run pretty smoothly for me.


sorry about the confusion. The demo I sent does alright (although it
does chew up the cpu).  What I had was a variation for the progress bar
which I called CellRendererPct.  I gave the bars within the ComboBox
view (what is it really? GtkCellView?) a certain percentage red and the
remainder green.  I typically have between 10-30 entries in the
combobox.  That was where I was having problems with performance.  

Brian
 

package CellRendererPct;

use strict;
use warnings;
use Glib qw(G_PARAM_READWRITE);
use Gtk2;


use Glib::Object::Subclass
  Gtk2::CellRenderer::,
  properties => [
    Glib::ParamSpec->double ('percentage',
                             'Percentage',
                             'The fractional progress to display',
                             0.0, 1.0, 0.0, G_PARAM_READWRITE),
  ],
  ;


sub INIT_INSTANCE {
  my $self = shift;
  $self->set (mode => 'activatable',
              xpad => 4,
              ypad => 2);
  $self->{percentage} = 0.0;
 
}

# we'll use the default new, GET_PROPERTY and SET_PROPERTY provided by
# Glib::Object::Subclass.


#
# calculate the size of our cell, taking into account padding and
# alignment properties of parent.
#

use constant FIXED_WIDTH  => 30;
use constant FIXED_HEIGHT => 25;
use constant RED => Gtk2::Gdk::Color->new(0xFFFF,0x0,0x0);
use constant GREEN => Gtk2::Gdk::Color->new(0x0,0xFFFF,0x0);
use constant GREY => Gtk2::Gdk::Color->parse('grey');

sub MAX { $_[0] > $_[1] ? $_[0] : $_[1] }

sub GET_SIZE {
  my ($cell, $widget, $cell_area) = @_;
  my ($x_offset, $y_offset) = (0, 0);

  my $width  = int ($cell->get ('xpad') * 2 + FIXED_WIDTH);
  my $height = int ($cell->get ('ypad') * 2 + FIXED_HEIGHT);

  if ($cell_area) {

    $x_offset = $cell->get ('xalign') * ($cell_area->width - $width);
    $x_offset = MAX ($x_offset, 0);

    $y_offset = $cell->get ('yalign') * ($cell_area->height - $height);
    $y_offset = MAX ($y_offset, 0);
  }

  return ($x_offset, $y_offset, $width, $height);
}

sub RENDER {
  my ($cell, $window, $widget, $background_area, $cell_area,
$expose_area, $flags) = @_;

#  my $defcolor = $widget->style->base('selected');

  my ($x_offset, $y_offset, $width, $height)
            = $cell->GET_SIZE ($widget, $cell_area);
 
  my $state = $widget->has_focus ? 'active' : 'normal';

  my ($xpad, $ypad) = $cell->get (qw(xpad ypad));

  $width  -= $xpad*2;
  $height -= $ypad*2;

  my $plainstyle = $widget->get_modifier_style->copy;

#   $cell->set('cell_background_set' => 'grey'); 
#   $widget->modify_base('normal',GREY);
#  $widget->style->paint_box ($window,
#                            'normal', 'out',
#                            undef, $widget, "flatbar",
#                            $background_area->x,
#                            $background_area->y,
#                            $background_area->width,
#                            $background_area->height);

#  $widget->style->paint_box ($window,
#                     'normal', 'in',
#                     undef, $widget, "trough",
#                     $cell_area->x + $x_offset + $xpad,
#                     $cell_area->y + $y_offset + $ypad,
#                     $width-1, $height-1 );

 
  my $xstart = $cell_area->x + $x_offset + $xpad;
  if ($cell->{percentage} >= (1.0/9.0))
  {
      $widget->modify_bg($state, RED);
      
      $widget->style->paint_box ($window,
                                 $state, 'out',
                                 undef, $widget, "flatbar",
                                 $xstart,
                                 $cell_area->y + $y_offset + $ypad,
                                 $width * $cell->{percentage},
                                 $height-1);
  }
  $widget->modify_bg($state, GREEN);
      
  $xstart += ($width*$cell->{percentage});

  $widget->style->paint_box ($window,
                             $state, 'out',
                             undef, $widget, "flatbar",
                             $xstart,
                             $cell_area->y + $y_offset + $ypad,
                             $width * (1-$cell->{percentage}),
                             $height-1);
  $widget->modify_style($plainstyle);
}



--- End Message ---


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]