File: cairo-cursor.rb

package info (click to toggle)
ruby-gnome2 3.1.0-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 16,072 kB
  • ctags: 17,433
  • sloc: ansic: 93,621; ruby: 62,273; xml: 335; sh: 246; makefile: 25
file content (37 lines) | stat: -rw-r--r-- 1,057 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
=begin
  cairo_cursor.rb Ruby/GTK3 script
  Adapted from https://developer.gnome.org/gtk3/stable/ch25s02.html#id-1.6.3.4.5
  Copyright (c) 2015 Ruby-GNOME2 Project Team
  This program is licenced under the same licence as Ruby-GNOME2.
=end

require "gtk3"

window = Gtk::Window.new("Gdk cursor sample")
window.signal_connect("destroy") { Gtk.main_quit }

# see cairo formats information here:
# http://cairographics.org/manual/cairo-Image-Surfaces.html#cairo-format-t
surface = Cairo::ImageSurface.new(Cairo::FORMAT_ARGB32, 6, 6)

cr = Cairo::Context.new(surface)
cr.set_source_rgba(0, 1, 0, 0.7)
cr.arc(3, 3, 3, 0, 2 * Math::PI)
cr.fill
cr.destroy

pixbuf = surface.to_pixbuf(0, 0, 6, 6)
cursor = Gdk::Cursor.new(pixbuf, 0, 0)

# generate the underlaying GDK resource associated with the window widget.
# Here just create window.window without calling #show_all method.
window.realize
window.window.set_cursor(cursor)

label = Gtk::Label.new("Put your cursor on this window.")
window.add(label)

window.set_default_size(200, 100)
window.show_all

Gtk.main