~mario-kemper/shutter/cleaner_toolbar

« back to all changes in this revision

Viewing changes to share/shutter/resources/modules/Shutter/Screenshot/SelectorAdvanced.pm

  • Committer: Mario Kemper
  • Date: 2012-01-26 13:17:37 UTC
  • Revision ID: mario.kemper@googlemail.com-20120126131737-u978vjirejeoym3a
SelectorAdvanced: load help text when idle

Show diffs side-by-side

added added

removed removed

Lines of Context:
103
103
                $self->{_root}->{h}
104
104
        );
105
105
 
 
106
        $self->{_view}->set_pixbuf($clean_pixbuf);
 
107
 
106
108
        #show help text?
107
109
        if($self->{_show_help}) {
108
 
 
109
 
                #we display the tip only on the current monitor
110
 
                #if we would use the root window we would display the next
111
 
                #right in the middle of both screens, this is pretty ugly
112
 
                my $mon1 = $self->get_current_monitor;
113
 
 
114
 
                print "Using monitor: "
115
 
                        . $mon1->x . " - "
116
 
                        . $mon1->y . " - "
117
 
                        . $mon1->width . " - "
118
 
                        . $mon1->height . "\n"
119
 
                        if $self->{_sc}->get_debug;
120
 
 
121
 
                #obtain current colors and font_desc from the main window
122
 
                my $style               = $self->{_sc}->get_mainwindow->get_style;
123
 
                #~ my $sel_bg           = $style->bg('selected');
124
 
                my $sel_bg              = Gtk2::Gdk::Color->parse('#131313');
125
 
                my $sel_tx              = $style->text('selected');
126
 
                my $font_fam    = $style->font_desc->get_family;
127
 
                my $font_size   = $style->font_desc->get_size / Gtk2::Pango->scale;
128
 
                
129
 
                #create cairo context und layout
130
 
                my $surface = Cairo::ImageSurface->create( 'argb32', $self->{_root}->{w}, $self->{_root}->{h} );
131
 
                my $cr          = Cairo::Context->create($surface);
132
 
 
133
 
                #set_source_pixbuf
134
 
                Gtk2::Gdk::Cairo::Context::set_source_pixbuf( $cr, $clean_pixbuf, 0, 0 );
135
 
                $cr->paint;
136
 
 
137
 
                my $layout = Gtk2::Pango::Cairo::create_layout($cr);
138
 
                $layout->set_width( int( $mon1->width / 2 ) * Gtk2::Pango->scale );
139
 
                $layout->set_alignment('left');
140
 
                $layout->set_wrap('word');
141
 
                
142
 
                #determine font-size
143
 
                my $size1 = int ($font_size * 2.0);
144
 
                my $size2 = int ($font_size * 1.5);
145
 
                my $size3 = int ($font_size * 1.0);
146
 
                
147
 
                my $text1 = 
148
 
                        $d->get("Draw a rectangular area using the mouse.");
149
 
                
150
 
                my $text2 =
151
 
                        $d->get("To take a screenshot, press the Enter key. Press Esc to quit.");
152
 
 
153
 
                my $text3 = 
154
 
                        $d->get("<b>shift/right-click</b> → selection dialog on/off")."\n".
155
 
                        $d->get("<b>ctrl + scrollwheel</b> → zoom in/out")."\n".
156
 
                        $d->get("<b>space</b> → zoom window on/off")."\n".
157
 
                        $d->get("<b>cursor keys</b> → move cursor")."\n".
158
 
                        $d->get("<b>cursor keys + alt</b> → move selection")."\n".
159
 
                        $d->get("<b>cursor keys + ctrl</b> → resize selection");
160
 
 
161
 
                #use this one for white font-color      
162
 
                $layout->set_markup("<span font_desc=\"$font_fam $size1\" foreground=\"#FFFFFF\">$text1</span>\n<span font_desc=\"$font_fam $size2\" foreground=\"#FFFFFF\">$text2</span>\n\n<span font_desc=\"$font_fam $size3\" foreground=\"#FFFFFF\">$text3</span>");
163
 
                
164
 
                #draw the rectangle
165
 
                $cr->set_source_rgba( $sel_bg->red / 257 / 255, $sel_bg->green / 257 / 255, $sel_bg->blue / 257 / 255, 0.85 );
166
 
 
167
 
                my ( $lw, $lh ) = $layout->get_pixel_size;
168
 
 
169
 
                my $w = $lw + $size1 * 2;
170
 
                my $h = $lh + $size1 * 2;
171
 
                my $x = int( ( $mon1->width - $w ) / 2 ) + $mon1->x;
172
 
                my $y = int( ( $mon1->height - $h ) / 2 ) + $mon1->y;
173
 
                my $r = 20;
174
 
 
175
 
                $cr->move_to( $x + $r, $y );
176
 
                $cr->line_to( $x + $w - $r, $y );
177
 
                $cr->curve_to( $x + $w, $y, $x + $w, $y, $x + $w, $y + $r );
178
 
                $cr->line_to( $x + $w, $y + $h - $r );
179
 
                $cr->curve_to( $x + $w, $y + $h, $x + $w, $y + $h, $x + $w - $r, $y + $h );
180
 
                $cr->line_to( $x + $r, $y + $h );
181
 
                $cr->curve_to( $x, $y + $h, $x, $y + $h, $x, $y + $h - $r );
182
 
                $cr->line_to( $x, $y + $r );
183
 
                $cr->curve_to( $x, $y, $x, $y, $x + $r, $y );
184
 
                $cr->fill;
185
 
 
186
 
                $cr->move_to( $x + $size1, $y + $size1 );
187
 
                
188
 
                #draw the pango layout
189
 
                Gtk2::Pango::Cairo::show_layout( $cr, $layout );
190
 
 
191
 
                #write surface to pixbuf
192
 
                my $loader = Gtk2::Gdk::PixbufLoader->new;
193
 
                $surface->write_to_png_stream(
194
 
                        sub {
195
 
                                my ( $closure, $data ) = @_;
196
 
                                $loader->write($data);
197
 
                        }
198
 
                );
199
 
                $loader->close;
200
 
                
201
 
                #set pixbuf
202
 
                $self->{_view}->set_pixbuf($loader->get_pixbuf);
203
 
 
204
 
        }else{
205
 
                
206
 
                #set pixbuf
207
 
                $self->{_view}->set_pixbuf($clean_pixbuf);
208
110
        
 
111
                Glib::Idle->add(sub{
 
112
 
 
113
                        #we display the tip only on the current monitor
 
114
                        #if we would use the root window we would display the next
 
115
                        #right in the middle of both screens, this is pretty ugly
 
116
                        my $mon1 = $self->get_current_monitor;
 
117
 
 
118
                        print "Using monitor: "
 
119
                                . $mon1->x . " - "
 
120
                                . $mon1->y . " - "
 
121
                                . $mon1->width . " - "
 
122
                                . $mon1->height . "\n"
 
123
                                if $self->{_sc}->get_debug;
 
124
 
 
125
                        #obtain current colors and font_desc from the main window
 
126
                        my $style               = $self->{_sc}->get_mainwindow->get_style;
 
127
                        #~ my $sel_bg           = $style->bg('selected');
 
128
                        my $sel_bg              = Gtk2::Gdk::Color->parse('#131313');
 
129
                        my $sel_tx              = $style->text('selected');
 
130
                        my $font_fam    = $style->font_desc->get_family;
 
131
                        my $font_size   = $style->font_desc->get_size / Gtk2::Pango->scale;
 
132
                        
 
133
                        #create cairo context und layout
 
134
                        my $surface = Cairo::ImageSurface->create( 'argb32', $self->{_root}->{w}, $self->{_root}->{h} );
 
135
                        my $cr          = Cairo::Context->create($surface);
 
136
 
 
137
                        #set_source_pixbuf
 
138
                        Gtk2::Gdk::Cairo::Context::set_source_pixbuf( $cr, $clean_pixbuf, 0, 0 );
 
139
                        $cr->paint;
 
140
 
 
141
                        my $layout = Gtk2::Pango::Cairo::create_layout($cr);
 
142
                        $layout->set_width( int( $mon1->width / 2 ) * Gtk2::Pango->scale );
 
143
                        $layout->set_alignment('left');
 
144
                        $layout->set_wrap('word');
 
145
                        
 
146
                        #determine font-size
 
147
                        my $size1 = int ($font_size * 2.0);
 
148
                        my $size2 = int ($font_size * 1.5);
 
149
                        my $size3 = int ($font_size * 1.0);
 
150
                        
 
151
                        my $text1 = 
 
152
                                $d->get("Draw a rectangular area using the mouse.");
 
153
                        
 
154
                        my $text2 =
 
155
                                $d->get("To take a screenshot, press the Enter key. Press Esc to quit.");
 
156
 
 
157
                        my $text3 = 
 
158
                                $d->get("<b>shift/right-click</b> → selection dialog on/off")."\n".
 
159
                                $d->get("<b>ctrl + scrollwheel</b> → zoom in/out")."\n".
 
160
                                $d->get("<b>space</b> → zoom window on/off")."\n".
 
161
                                $d->get("<b>cursor keys</b> → move cursor")."\n".
 
162
                                $d->get("<b>cursor keys + alt</b> → move selection")."\n".
 
163
                                $d->get("<b>cursor keys + ctrl</b> → resize selection");
 
164
 
 
165
                        #use this one for white font-color      
 
166
                        $layout->set_markup("<span font_desc=\"$font_fam $size1\" foreground=\"#FFFFFF\">$text1</span>\n<span font_desc=\"$font_fam $size2\" foreground=\"#FFFFFF\">$text2</span>\n\n<span font_desc=\"$font_fam $size3\" foreground=\"#FFFFFF\">$text3</span>");
 
167
                        
 
168
                        #draw the rectangle
 
169
                        $cr->set_source_rgba( $sel_bg->red / 257 / 255, $sel_bg->green / 257 / 255, $sel_bg->blue / 257 / 255, 0.85 );
 
170
 
 
171
                        my ( $lw, $lh ) = $layout->get_pixel_size;
 
172
 
 
173
                        my $w = $lw + $size1 * 2;
 
174
                        my $h = $lh + $size1 * 2;
 
175
                        my $x = int( ( $mon1->width - $w ) / 2 ) + $mon1->x;
 
176
                        my $y = int( ( $mon1->height - $h ) / 2 ) + $mon1->y;
 
177
                        my $r = 20;
 
178
 
 
179
                        $cr->move_to( $x + $r, $y );
 
180
                        $cr->line_to( $x + $w - $r, $y );
 
181
                        $cr->curve_to( $x + $w, $y, $x + $w, $y, $x + $w, $y + $r );
 
182
                        $cr->line_to( $x + $w, $y + $h - $r );
 
183
                        $cr->curve_to( $x + $w, $y + $h, $x + $w, $y + $h, $x + $w - $r, $y + $h );
 
184
                        $cr->line_to( $x + $r, $y + $h );
 
185
                        $cr->curve_to( $x, $y + $h, $x, $y + $h, $x, $y + $h - $r );
 
186
                        $cr->line_to( $x, $y + $r );
 
187
                        $cr->curve_to( $x, $y, $x, $y, $x + $r, $y );
 
188
                        $cr->fill;
 
189
 
 
190
                        $cr->move_to( $x + $size1, $y + $size1 );
 
191
                        
 
192
                        #draw the pango layout
 
193
                        Gtk2::Pango::Cairo::show_layout( $cr, $layout );
 
194
 
 
195
                        #write surface to pixbuf
 
196
                        my $loader = Gtk2::Gdk::PixbufLoader->new;
 
197
                        $surface->write_to_png_stream(
 
198
                                sub {
 
199
                                        my ( $closure, $data ) = @_;
 
200
                                        $loader->write($data);
 
201
                                }
 
202
                        );
 
203
                        $loader->close;
 
204
                        
 
205
                        #set pixbuf
 
206
                        $self->{_view}->set_pixbuf($loader->get_pixbuf);
 
207
 
 
208
                        return FALSE;
 
209
                });
 
210
 
209
211
        }
210
212
 
211
213
        #define zoom window
726
728
        my $s = $self->{_selector}->get_selection;
727
729
        my $v = $self->{_view}->get_viewport;
728
730
        
 
731
        return FALSE unless defined $v;
 
732
        
729
733
        my ( $window_at_pointer, $x, $y, $mask ) = $self->{_root}->get_pointer;
730
734
 
731
735
        #event coordinates