Skip to content

Commit 65947fb

Browse files
committed
Merge remote-tracking branch 'origin/master'
Resolved Conflicts: 9a-cairo-drawing.pl Perl Gtk3 Tutorial.odt Perl Gtk3 Tutorial.pdf
1 parent e563aed commit 65947fb

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
lines changed

9a-cairo-drawing.pl

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#! /usr/bin/perl
2+
3+
use strict;
4+
use warnings;
5+
use feature ':5.14';
6+
use Gtk3 '-init';
7+
use Glib qw/TRUE FALSE/;
8+
use Cairo::GObject;
9+
10+
use constant PI => 3.1415927;
11+
12+
my $window = Gtk3::Window->new('toplevel');
13+
$window->set_title("Grid Example");
14+
$window->set_position("mouse");
15+
$window->set_default_size(600, 400);
16+
$window->set_border_width(5);
17+
$window->signal_connect (delete_event => sub { Gtk3->main_quit });
18+
19+
my $frame = Gtk3::Frame->new("Cairo Drawings");
20+
$window->add($frame);
21+
22+
my $drawable = Gtk3::DrawingArea->new;
23+
$drawable->signal_connect( draw => \&cairo_draw );
24+
$frame->add($drawable);
25+
26+
$window->show_all;
27+
28+
Gtk3->main;
29+
30+
sub cairo_draw {
31+
my ( $widget, $context, $ref_status ) = @_;
32+
33+
# Background
34+
$context->set_source_rgb(0.9, 0.9, 0.7);
35+
$context->paint;
36+
37+
# Solid box
38+
$context->set_source_rgb(0.6, 0.0, 0.0);
39+
$context->set_line_width(10);
40+
$context->rectangle( 5, 5, 160, 130);
41+
$context->stroke;
42+
43+
# Transparent Rectangle
44+
$context->set_source_rgba(0.0, 0.7, 0.0, 0.5);
45+
$context->set_line_width(10);
46+
$context->rectangle( 85, 85, 160, 230);
47+
$context->fill;
48+
49+
# Circle with border - transparent
50+
$context->set_source_rgba(0.0, 0.0, 0.9, 0.5);
51+
$context->arc( 220, 150, 100, 0, PI * 2 );
52+
$context->set_line_width(10);
53+
$context->stroke_preserve;
54+
$context->set_source_rgba(0.9, 0.2, 0.2, 0.2);
55+
$context->fill;
56+
57+
# Segment
58+
$context->set_source_rgba(0.9, 0.2, 0.2, 0.4);
59+
$context->set_line_width(2);
60+
$context->arc( 400, 200, 100, 0, 5);
61+
$context->stroke_preserve;
62+
$context->line_to(400, 200);
63+
$context->stroke_preserve;
64+
$context->close_path;
65+
$context->stroke_preserve;
66+
$context->set_source_rgba(0.1, 0.4, 0.4, 0.4);
67+
$context->fill;
68+
69+
# Arc
70+
$context->set_source_rgba(0.1, 0.1, 0.1, 0.8);
71+
$context->set_line_width(2);
72+
$context->arc( 450, 220, 100, 0, 5);
73+
$context->stroke;
74+
75+
# Line
76+
$context->set_source_rgba(0, 0, 0, 0.5);
77+
$context->set_line_width(30);
78+
$context->move_to(50, 50);
79+
$context->line_to(550, 350);
80+
$context->stroke;
81+
82+
# Curve
83+
$context->set_line_width(10);
84+
$context->set_source_rgba(0.9, 0.9, 0, 0.9);
85+
$context->move_to(50, 50);
86+
$context->curve_to( 100, 250, 250, 150, 550, 350);
87+
$context->stroke;
88+
89+
# Text
90+
$context->set_source_rgba(0.0, 0.9, 0.9, 0.7);
91+
$context->select_font_face( "Sans", "normal", "bold" );
92+
$context->set_font_size( 50 );
93+
$context->move_to(220, 50);
94+
$context->show_text( "Ooooooh");
95+
$context->stroke;
96+
97+
$context->move_to(370, 170);
98+
$context->text_path( "pretty" );
99+
$context->set_source_rgba(0.9, 0, 0.9, 0.7);
100+
$context->fill_preserve;
101+
$context->set_source_rgba(0.2, 0.1, 0.1, 0.7);
102+
$context->set_line_width( 2 );
103+
$context->stroke;
104+
105+
# Gradients
106+
my $pattern = Cairo::RadialGradient->create(40, 220, 25, 60, 240, 150);
107+
$pattern->add_color_stop_rgba(0, 1, 0.7, 1, 0.95);
108+
$pattern->add_color_stop_rgba(1, 0, 0, 0.5, 0.95);
109+
$context->set_source( $pattern );
110+
$context->arc( 80, 250, 80, 0, PI * 2 );
111+
$context->fill;
112+
113+
return FALSE;
114+
}

Perl Gtk3 Tutorial.odt

65.4 KB
Binary file not shown.

Perl Gtk3 Tutorial.pdf

27.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)