class TransparentDemo

# Copyright © 2016 Ruby-GNOME2 Project Team # This program is licenced under the same licence as Ruby-GNOME2. #

Overlay/Transparency

Use transparent background on GdkWindows to create a shadow effect on a GtkOverlay widget.

Constants

SHADOW_OFFSET_X
SHADOW_OFFSET_Y
SHADOW_RADIUS

Public Class Methods

new(main_window) click to toggle source
# File gtk3/sample/gtk-demo/transparent.rb, line 14
def initialize(main_window)
  @window = Gtk::Window.new(:toplevel)
  @window.screen = main_window.screen
  @window.set_default_size(450, 450)
  @window.title = "Transparency"

  view = Gtk::TextView.new
  sw = Gtk::ScrolledWindow.new
  sw.set_policy(:automatic, :automatic)
  sw.add(view)

  overlay = Gtk::Overlay.new
  overlay.add(sw)
  @window.add(overlay)

  entry = Gtk::Entry.new
  css = <<-CSS
  * { border-width: 0px #{SHADOW_OFFSET_X}px #{SHADOW_OFFSET_Y}px 0px; }
  CSS
  provider = Gtk::CssProvider.new
  provider.load_from_data(css)
  style_context = entry.style_context
  style_context.add_provider(provider,
                             Gtk::StyleProvider::PRIORITY_APPLICATION)
  entry.signal_connect "draw" do |widget, cr|
    allocation = widget.allocation
    rect = [allocation.x + SHADOW_OFFSET_X,
            allocation.y + SHADOW_OFFSET_Y,
            allocation.width - SHADOW_OFFSET_X,
            allocation.height - SHADOW_OFFSET_Y
           ]
    draw_shadow_box(cr, rect, SHADOW_RADIUS, 0.4)
    false
  end

  overlay.add_overlay(entry)
  entry.valign = :center
  entry.halign = :start
  overlay.show_all
end

Public Instance Methods

run() click to toggle source
# File gtk3/sample/gtk-demo/transparent.rb, line 55
def run
  if !@window.visible?
    @window.show_all
  else
    @window.destroy
  end
  @window
end