Re: Scribble Example



On Tue, 05 Aug 2008 10:06:45 +1000
Kevin Ryde <user42 zip com au> wrote:

zentara <zentara1 sbcglobal net> writes:

I chopped down your model to the point where it would draw a simple
rectangle, without the mouse drag. Then I added a line at a time back in,
until it stopped working.

The culprit is:

$gc->set_function ('xor');

Yes and no, I suspect there's no pixel values set into the gc.  The RGB
parts of a GdkColor have no effect at the gc->set_foreground level ...


You're right. I changed it to

 my $gc = Gtk2::Gdk::GC->new( $root, undef );                                           
   my $color = Gtk2::Gdk::Color->parse('pink');                                           
   my $colormap = $root->get_colormap;                                                    
   $colormap->alloc_color($color,TRUE,TRUE);                                              
   Gtk2::Gdk::GC::set_foreground($gc, $color);                                            
   Gtk2::Gdk::GC::set_background($gc, $color);                                            
                                                                                          
   $gc->set_subwindow( 'include-inferiors' );                                             
   $gc->set_function ('xor');     

and that let the dashed lines show. It's not perfect though.
It will be pink on the desktop, but on an existing window, it will
show as black. This could get to be a problem, since you can't
predict what colors will be on existing windows.

As far as the numerous rectangles being drawn on the drag, a
cheap solution is to draw a horizontal and vertical line on the drag,
showing the upper and left sides, then draw a rect on button release.

if ( $event->type eq 'button-release' ) {
$done = 1;
print "Type: " . $event->type . "\n" if defined $event;

#write a rect after done dragging
$root->draw_rectangle($gc, 0, $rect_x, $rect_y, $rect_w, $rect_h);

}
elsif ( $event->type eq 'button-press' ) {
$btn_pressed = 1;
$rx          = $event->x;
$ry          = $event->y;
print "Type: " . $event->type . "\n" if defined $event;
}
elsif ( $event->type eq 'motion-notify' ) {
print "Type: " . $event->type . "\n" if defined $event;

if ( $btn_pressed ) {
if ( $rect_w ) {

#  $root->draw_rectangle( $gc, 0, $rect_x, $rect_y, $rect_w, $rect_h );

# draw lines instead
$root->draw_line ($gc, $rect_x, $rect_y, $rect_x + $rect_w, $rect_y); #horizontal line
$root->draw_line ($gc, $rect_x, $rect_y, $rect_x, $rect_y + $rect_h); #vertical line
}


I also tried with the dragging rectangles and trying to use clear_area on each draw, 
to clear all the interior rectangles. But it seemed you need to adjust corners by + or - 1 pixel
to compute the area to be cleared, and it didn't work right. 
But it may be possible to perfect.


All in all, this is a tricky problem, and I can now appreciate 
what conventional screenshot tools do.

zentara


-- 
I'm not really a human, but I play one on earth.
http://zentara.net/Remember_How_Lucky_You_Are.html 



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