Sha256: e2c0b012439cf0c75c48e90cfe0c52cf353a6f2d2c309a75a3421c99c11d7738

Contents?: true

Size: 1.59 KB

Versions: 6

Compression:

Stored size: 1.59 KB

Contents

# Copyright (c) 2015 Ruby-GNOME2 Project Team
# This program is licenced under the same licence as Ruby-GNOME2.
#
=begin
= Pango/Text Mask

This demo shows how to use PangoCairo to draw text with more than
just a single color.
=end
module TextmaskDemo
  def self.run_demo(_main_window)
    window = Gtk::Window.new(:toplevel)
    window.set_resizable(true)
    window.set_size_request(400, 200)
    window.set_title("Text Mask")

    da = Gtk::DrawingArea.new

    window.add(da)

    da.signal_connect "draw" do |_widget, cr|
      cr.save

      layout = da.create_pango_layout("Pango power!\nPango power!\nPango power!")
      desc = Pango::FontDescription.new("sans bold 34")
      layout.font_description = desc

      cr.move_to(30, 20)
      cr.pango_layout_path(layout)

      pattern = Cairo::LinearPattern.new(0.0, 0.0,
                                         da.allocated_width,
                                         da.allocated_height)

      pattern.add_color_stop(0.0, 1.0, 0.0, 0.0)
      pattern.add_color_stop(0.2, 1.0, 0.0, 0.0)
      pattern.add_color_stop(0.3, 1.0, 1.0, 0.0)
      pattern.add_color_stop(0.4, 0.0, 1.0, 0.0)
      pattern.add_color_stop(0.6, 0.0, 1.0, 1.0)
      pattern.add_color_stop(0.7, 0.0, 0.0, 1.0)
      pattern.add_color_stop(0.8, 1.0, 0.0, 1.0)
      pattern.add_color_stop(1.0, 1.0, 0.0, 1.0)
      cr.set_source(pattern)
      cr.fill_preserve

      cr.set_source_rgb(0.0, 0.0, 0.0)
      cr.set_line_width(0.5)
      cr.stroke
      cr.restore
      true
    end

    if !window.visible?
      window.show_all
    else
      window.destroy
    end

    window
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
gtk3-3.0.9-x64-mingw32 sample/gtk-demo/textmask.rb
gtk3-3.0.9-x86-mingw32 sample/gtk-demo/textmask.rb
gtk3-3.0.9 sample/gtk-demo/textmask.rb
gtk3-3.0.8-x86-mingw32 sample/gtk-demo/textmask.rb
gtk3-3.0.8-x64-mingw32 sample/gtk-demo/textmask.rb
gtk3-3.0.8 sample/gtk-demo/textmask.rb