Sha256: 725030728b069b621b66f51d2271bf9a753e48f8775cb639c155994c36dff2b0

Contents?: true

Size: 1.61 KB

Versions: 122

Compression:

Stored size: 1.61 KB

Contents

# Copyright (c) 2015-2016 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
class TextmaskDemo
  def initialize(_main_window)
    @window = Gtk::Window.new(:toplevel)
    @window.resizable = true
    @window.set_size_request(400, 200)
    @window.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
  end

  def run
    if !@window.visible?
      @window.show_all
    else
      @window.destroy
    end
    @window
  end
end

Version data entries

122 entries across 114 versions & 2 rubygems

Version Path
gtk3-3.1.8-x64-mingw32 sample/gtk-demo/textmask.rb
gtk3-3.1.8-x86-mingw32 sample/gtk-demo/textmask.rb
gtk3-3.1.8 sample/gtk-demo/textmask.rb
gtk3-3.1.7-x64-mingw32 sample/gtk-demo/textmask.rb
gtk3-3.1.7-x86-mingw32 sample/gtk-demo/textmask.rb
gtk3-3.1.7 sample/gtk-demo/textmask.rb
gtk3-3.1.6-x64-mingw32 sample/gtk-demo/textmask.rb
gtk3-3.1.6-x86-mingw32 sample/gtk-demo/textmask.rb
gtk3-3.1.6 sample/gtk-demo/textmask.rb
gtk3-3.1.5-x64-mingw32 sample/gtk-demo/textmask.rb
gtk3-3.1.5-x86-mingw32 sample/gtk-demo/textmask.rb
gtk3-3.1.4-x64-mingw32 sample/gtk-demo/textmask.rb
gtk3-3.1.4-x86-mingw32 sample/gtk-demo/textmask.rb
gtk3-3.1.4 sample/gtk-demo/textmask.rb
gtk3-3.1.3-x64-mingw32 sample/gtk-demo/textmask.rb
gtk3-3.1.3-x86-mingw32 sample/gtk-demo/textmask.rb
gtk3-3.1.3 sample/gtk-demo/textmask.rb
gtk3-3.1.2-x64-mingw32 sample/gtk-demo/textmask.rb
gtk3-3.1.2-x86-mingw32 sample/gtk-demo/textmask.rb
gtk3-3.1.2 sample/gtk-demo/textmask.rb