Sha256: f0d752d67866919a9311cd5ccbd63c1c73330aeaae4b5256d5e7d51e2caa6dfa

Contents?: true

Size: 1.72 KB

Versions: 14

Compression:

Stored size: 1.72 KB

Contents

#!/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()

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
gtk3-2.2.5-x64-mingw32 sample/misc/alpha-demo.rb
gtk3-2.2.5-x86-mingw32 sample/misc/alpha-demo.rb
gtk3-2.2.5 sample/misc/alpha-demo.rb
gtk3-2.2.4-x64-mingw32 sample/misc/alpha-demo.rb
gtk3-2.2.4-x86-mingw32 sample/misc/alpha-demo.rb
gtk3-2.2.4 sample/misc/alpha-demo.rb
gtk3-2.2.3-x86-mingw32 sample/misc/alpha-demo.rb
gtk3-2.2.3 sample/misc/alpha-demo.rb
gtk3-2.2.2-x86-mingw32 sample/misc/alpha-demo.rb
gtk3-2.2.2 sample/misc/alpha-demo.rb
gtk3-2.2.1-x86-mingw32 sample/misc/alpha-demo.rb
gtk3-2.2.1 sample/misc/alpha-demo.rb
gtk3-2.2.0-x86-mingw32 sample/misc/alpha-demo.rb
gtk3-2.2.0 sample/misc/alpha-demo.rb