File: alpha-demo.rb

package info (click to toggle)
ruby-gnome2 2.2.0-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 11,360 kB
  • ctags: 14,222
  • sloc: ansic: 85,875; ruby: 38,232; sh: 80; xml: 41; makefile: 22
file content (70 lines) | stat: -rwxr-xr-x 1,758 bytes parent folder | download | duplicates (6)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env ruby
=begin
  alpha-demo.rb - alpha blended window sample script. (need xcompmgr)

  Original: alphademo.py by Mike Hearn (*1) and David Trowbridge (*2)
  * (1) http://plan99.net/~mike/blog/2006/06/05/alpha-blended-windows-in-python/
  * (2) http://david.navi.cx/blog/?p=91

  Translated to Ruby by Juergen Mangler <juergen.mangler@univie.ac.at>

  Copyright (c) 2006  Ruby-GNOME2 Project Team
  This program is licenced under the same licence as Ruby-GNOME2.

  $Id: alpha-demo.rb,v 1.1 2007/01/06 03:55:44 ktou Exp $
=end

require 'gtk3'
require 'cairo'

class AlphaDemo < Gtk::Window

  def initialize()
    super()

    set_app_paintable(true)
    set_title("AlphaDemo")
    set_decorated(false)
    set_default_size(200, 220)
    signal_connect("delete_event") do
      Gtk.main_quit
    end
    set_double_buffered(false)

    signal_connect('draw') do |widget, event|
      cr = widget.window.create_cairo_context

      rgba = [1.0, 1.0, 1.0]
      rgba << 0.0 if @supports_alpha
      cr.set_source_rgba(rgba)
      cr.set_operator(Cairo::OPERATOR_SOURCE)
      cr.paint

      twidth, theight = widget.size

      cr.set_source_rgba(1.0, 0.2, 0.2, 0.6)
      radius = [twidth, theight].min.to_f / 2 - 0.8

      cr.arc(twidth.to_f / 2, theight.to_f / 2, radius, 0, 2.0 * Math::PI)
      cr.fill_preserve
      cr.stroke
    end
    signal_connect('screen-changed') do |widget, old_screen|
      screen_changed(widget, old_screen)
    end

    screen_changed(self)
  end

  def screen_changed(widget,old_screen=nil)
    tcolormap = widget.screen.rgba_colormap
    @supports_alpha = !tcolormap.nil?
    tcolormap ||= widget.screen.rgb_colormap
    widget.set_colormap(tcolormap)
  end
end

alpha = AlphaDemo.new
alpha.show

Gtk.main()