class Object

Constants

AUTHOR_COLUMN
BlendMode

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

Theming/CSS Blend Modes

You can blend multiple backgrounds using the CSS blend modes available.
CHECKED_COLUMN
COLORS
CapitalItem
EXECUTE
FILENAME_COLUMN
GI
GNOME2Package
GST_PLAY_FLAG_VIS
HANDLE_SIZE
HEIGHT
Icon

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

Combo Boxes

The GtkComboBox widget allows to select one option out of a list.
The GtkComboBoxEntry additionally allows the user to enter a value
that is not in the list of options.

How the options are displayed is controlled by cell renderers.
NOTCH
N_STATS
N_WORDS
PATH
PIXBUF_COLUMN
RADIUS
RSVG
Rectangle

Drawing area

SEEK_H
SEEK_W
SIZE
STATS_UPDATE_TIME

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

Benchmark/Fishbowl

This demo models the fishbowl demos seen on the web in a GTK way.
It's also a neat little tool to see how fast your computer (or
your GTK version) is.
STYLE_COLUMN
SUBDIRS
TARGET_SIZE
TEXT_COLUMN
TITLE_COLUMN
T_APPLICATION
T_COMBO_EDITABLE
T_COMBO_HAS_ENTRY
T_COMBO_MODEL
T_COMBO_TEXT
T_COMBO_TEXT_COLUMN
URI

Create bookmarkfile data.

WIDTH

Public Instance Methods

actor_animate(actor, mode, duration, first_property, *args) click to toggle source
# File clutter-gstreamer/sample/2.0/video-player.rb, line 79
def actor_animate(actor, mode, duration, first_property, *args)
  actor.save_easing_state
  actor.easing_mode = mode
  actor.easing_duration = duration

  actor.set_property(first_property, args.first)
end
add_depend_package(target_name, target_srcdir, top_srcdir, options={}) click to toggle source

#add_depend_package(“glib2”, “ext/glib2”, “/.…./ruby-gnome2”)

# File glib2/lib/mkmf-gnome2.rb, line 151
def add_depend_package(target_name, target_srcdir, top_srcdir, options={})
  gem_spec = find_gem_spec(target_name)
  if gem_spec
    target_source_dir = File.join(gem_spec.full_gem_path, "ext/#{target_name}")
    target_build_dir = target_source_dir
    add_depend_package_path(target_name,
                            target_source_dir,
                            target_build_dir)
  end

  [top_srcdir,
   File.join(top_srcdir, target_name),
   $configure_args['--topdir'],
   File.join($configure_args['--topdir'], target_name)].each do |topdir|
    topdir = File.expand_path(topdir)
    target_source_dir_full_path = File.join(topdir, target_srcdir)

    top_build_dir = options[:top_build_dir] || topdir
    target_build_dir = options[:target_build_dir] || target_srcdir
    target_build_dir_full_path = File.join(top_build_dir, target_build_dir)
    unless File.exist?(target_build_dir_full_path)
      target_build_dir_full_path = File.join(top_build_dir, target_srcdir)
    end
    unless File.exist?(target_build_dir_full_path)
      target_build_dir_full_path = File.join(topdir, target_build_dir)
    end
    unless File.exist?(target_build_dir_full_path)
      target_build_dir_full_path = File.join(topdir, target_srcdir)
    end
    add_depend_package_path(target_name,
                            target_source_dir_full_path,
                            target_build_dir_full_path)
  end
end
add_depend_package_path(target_name, target_source_dir, target_build_dir) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 186
def add_depend_package_path(target_name, target_source_dir, target_build_dir)
  if File.exist?(target_source_dir)
    $INCFLAGS = "-I#{target_source_dir} #{$INCFLAGS}"
  end

  if windows_platform?
    target_base_dir = Pathname.new(target_source_dir).parent.parent
    target_binary_base_dir = target_base_dir + "vendor" + "local"
    if target_binary_base_dir.exist?
      $INCFLAGS = "-I#{target_binary_base_dir}/include #{$INCFLAGS}"
      target_pkg_config_dir = target_binary_base_dir + "lib" + "pkgconfig"
      PKGConfig.add_path(target_pkg_config_dir.to_s)
    end
  end

  return unless File.exist?(target_build_dir)
  if target_source_dir != target_build_dir
    $INCFLAGS = "-I#{target_build_dir} #{$INCFLAGS}"
  end

  if windows_platform?
    library_base_name = "ruby-#{target_name.gsub(/-/, '_')}"
    case RUBY_PLATFORM
    when /cygwin|mingw/
      $LDFLAGS << " -L#{target_build_dir}"
      $libs << " -l#{library_base_name}"
    when /mswin/
      $DLDFLAGS << " /libpath:#{target_build_dir}"
      $libs << " lib#{library_base_name}.lib"
    end
  end
end
add_distcleanfile(file) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 219
def add_distcleanfile(file)
  $distcleanfiles ||= []
  $distcleanfiles << file
end
add_obj(name) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 409
def add_obj(name)
  ensure_objs
  $objs << name unless $objs.index(name)
end
append_children(model, source, parent = nil) click to toggle source
# File gtk3/sample/gtk-demo/main.rb, line 116
def append_children(model, source, parent = nil)
  source.each do |title, filename, children|
    iter = model.append(parent)
    iter[TITLE_COLUMN] = title
    iter[FILENAME_COLUMN] = filename
    iter[STYLE_COLUMN] = Pango::Style::NORMAL

    append_children(model, children, iter) if children
  end
end
check_cairo(options={}) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 421
def check_cairo(options={})
  rcairo_source_dir = options[:rcairo_source_dir]
  if rcairo_source_dir.nil?
    suffix = nil
    if windows_platform?
      case RUBY_PLATFORM
      when /\Ax86-mingw/
        suffix = "win32"
      when /\Ax64-mingw/
        suffix = "win64"
      end
    end
    rcairo_source_base_dir = "rcairo"
    rcairo_source_base_dir << ".#{suffix}" if suffix
    top_dir = options[:top_dir]
    if top_dir
      rcairo_source_dir = File.join(top_dir, "..", rcairo_source_base_dir)
    end
  end

  if rcairo_source_dir and !File.exist?(rcairo_source_dir)
    rcairo_source_dir = nil
  end
  if rcairo_source_dir.nil?
    cairo_gem_spec = find_gem_spec("cairo")
    rcairo_source_dir = cairo_gem_spec.full_gem_path if cairo_gem_spec
  end

  unless rcairo_source_dir.nil?
    if windows_platform?
      options = {}
      build_dir = "tmp/#{RUBY_PLATFORM}/cairo/#{RUBY_VERSION}"
      if File.exist?(File.join(rcairo_source_dir, build_dir))
        options[:target_build_dir] = build_dir
      end
      add_depend_package("cairo", "ext/cairo", rcairo_source_dir, options)
      $defs << "-DRUBY_CAIRO_PLATFORM_WIN32"
    end
    $INCFLAGS += " -I#{rcairo_source_dir}/ext/cairo"
  end

  PKGConfig.have_package('cairo') and have_header('rb_cairo.h')
end
clamp(x, low, high) click to toggle source
# File clutter-gstreamer/sample/2.0/video-player.rb, line 313
def clamp(x, low, high)
  if x > high
    high
  elsif x < low
    low
  else
    x
  end
end
clear_surface(surface) click to toggle source
# File gtk3/sample/misc/drawing.rb, line 12
def clear_surface(surface)
  cr = Cairo::Context.new(surface)
  cr.set_source_rgb(1, 1, 1)
  cr.paint
  cr.destroy
end
compile_shader(shader_handle) click to toggle source
# File gtk3/sample/misc/gtkglarea2.rb, line 59
def compile_shader(shader_handle)
  # Compile the vertex shader
  glCompileShader(shader_handle)
  # Check the vertex shader compilation
  compiled_buf = "    "
  glGetShaderiv(shader_handle, GL_COMPILE_STATUS, compiled_buf)
  compiled = compiled_buf.unpack("L")[0]
  compiled
end
compute_size(width, height, rotate) click to toggle source
# File poppler/sample/pdf2.rb, line 60
def compute_size(width, height, rotate)
  width = width.to_f
  height = height.to_f
  radius = 0
  unless rotate.zero?
    radius = rotate / 180.0 * Math::PI
    if (90 < rotate and rotate < 180) or
        (270 < rotate and rotate < 360)
      radius -= Math::PI / 2
    end
  end
  inner_angle1 = Math.atan(width / height)
  inner_angle2 = Math.atan(height / width)
  diagonal = Math.sqrt(width ** 2 + height ** 2)

  angle1 = radius + inner_angle1
  angle2 = radius + inner_angle2

  bottom1 = diagonal * Math.cos(angle1)
  length1 = (bottom1 * Math.tan(angle1)).abs.to_i
  bottom2 = diagonal * Math.cos(angle2)
  length2 = (bottom2 * Math.tan(angle2)).abs.to_i

  if (0 <= rotate and rotate <= 90) or
      (180 <= rotate and rotate <= 270)
    [length1, length2]
  else
    [length2, length1]
  end
end
controls_timeout_cb(app) click to toggle source
# File clutter-gstreamer/sample/2.0/video-player.rb, line 73
def controls_timeout_cb(app)
  app.controls_timeout = 0
  show_controls(app, false)
  false
end
create_bbox_window(horizontal, title, pos, spacing, layout) click to toggle source
# File gtk2/sample/misc/buttonbox.rb, line 13
def create_bbox_window(horizontal, title, pos, spacing, layout)
  window = Gtk::Window.new(title)
  window.signal_connect("delete_event") do
    window.destroy
  end

  box1 = Gtk::VBox.new(false, 0)
  window.add(box1)

  if horizontal
    window.set_default_size(550, 60)
    window.move(150, pos)
    bbox = Gtk::HButtonBox.new
  else
    window.set_default_size(150, 400)
    window.move(pos, 200)
    bbox = Gtk::VButtonBox.new
  end

  bbox.layout_style = layout
  bbox.spacing = spacing
  box1.border_width = 25
  box1.pack_start(bbox, true, true, 0)

  button = Gtk::Button.new("OK")
  bbox.add(button)
  button.signal_connect("clicked") do
    window.destroy
  end

  button = Gtk::Button.new("Cancel")
  bbox.add(button)
  button.signal_connect("clicked") do
    window.destroy
  end

  button = Gtk::Button.new("Help")
  bbox.add(button)
  window.show_all
end
create_makefile_at_srcdir(pkg_name, srcdir, defs = nil) { || ... } click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 284
def create_makefile_at_srcdir(pkg_name, srcdir, defs = nil)
  base_dir = File.basename(Dir.pwd)
  last_common_index = srcdir.rindex(base_dir)
  if last_common_index
    builddir = srcdir[(last_common_index + base_dir.size + 1)..-1]
  end
  builddir ||= "."
  FileUtils.mkdir_p(builddir)

  Dir.chdir(builddir) do
    yield if block_given?

    $defs << defs if defs
    ensure_objs
    create_makefile(pkg_name, srcdir)
  end
end
create_menu(depth) click to toggle source
# File gtk2/sample/misc/menu.rb, line 13
def create_menu(depth)
  return nil if depth < 1
  
  menu = Gtk::Menu.new
  group = nil
  submenu = nil

  for i in 0..4
    buf = sprintf("item %2d - %d", depth, i + 1)
    menuitem = Gtk::RadioMenuItem.new(group, buf)
    group = menuitem.group
    menu.append(menuitem)
    if depth > 1
      menuitem.set_submenu create_menu(depth - 1)
    end
  end
  menu
end
create_option_menu() click to toggle source
# File gtk3/sample/misc/menu.rb, line 28
def create_option_menu
  lstore = Gtk::ListStore.new(TrueClass, String)
  (1..5).each do |i|
    lstore.append.set_values([false, "item #{i}"])
  end

  combobox = Gtk::ComboBox.new(:model => lstore, :entry => true)

  toggle = Gtk::CellRendererToggle.new

  combobox.pack_start(toggle, true)
  combobox.add_attribute(toggle, "active", 0)
  combobox.set_entry_text_column(1)

  combobox.signal_connect("changed") do |widget|
    list = widget.model
    list.each do |model, _path, iter|
      model.set_value(iter, 0, false)
    end
    iter = widget.active_iter
    list.set_value(iter, 0, true)
  end

  combobox
end
create_pkg_config_file(package_name, c_package, version=nil, pc_file_name=nil) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 224
def create_pkg_config_file(package_name, c_package,
                           version=nil, pc_file_name=nil)
  pc_file_name ||= "#{package_name.downcase.sub(/\//, '-')}.pc"
  version ||= ruby_gnome2_version || PKGConfig.modversion(c_package)

  puts "creating #{pc_file_name}"

  File.open(pc_file_name, 'w') do |pc_file|
    if package_name.nil?
      c_module_name = PKGConfig.name(c_package)
      package_name = "Ruby/#{c_module_name}" if c_module_name
    end
    pc_file.puts("Name: #{package_name}") if package_name

    description = PKGConfig.description(c_package)
    pc_file.puts("Description: Ruby bindings for #{description}") if description
    pc_file.printf("Version: #{version}")
  end

  add_distcleanfile(pc_file_name)
end
create_top_makefile(sub_dirs=["src"]) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 318
def create_top_makefile(sub_dirs=["src"])
  File.open("Makefile", "w") do |makefile|
    makefile.print("all:
#{run_make_in_sub_dirs_command("all", sub_dirs)}

install:
#{run_make_in_sub_dirs_command("install", sub_dirs)}

site-install:
#{run_make_in_sub_dirs_command("site-install", sub_dirs)}

clean:
#{run_make_in_sub_dirs_command("clean", sub_dirs)}
")

    if /mswin/ =~ RUBY_PLATFORM
      makefile.print("        @if exist extconf.h del extconf.h
        @if exist conftest.* del conftest.*
        @if exist *.lib del *.lib
        @if exist *~ del *~
        @if exist mkmf.log del mkmf.log
")
    else
      makefile.print("
distclean: clean
#{run_make_in_sub_dirs_command("distclean", sub_dirs)}
        @rm -f Makefile extconf.h conftest.*
        @rm -f core *~ mkmf.log
")
    end
  end
end
disable_optimization_build_flag(flags) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 24
def disable_optimization_build_flag(flags)
  if gcc?
    flags.gsub(/(^|\s)?-O\d(\s|$)?/, '\1-O0\2')
  else
    flags
  end
end
display_compile_shader_log(shader_handle) click to toggle source
# File gtk3/sample/misc/gtkglarea2.rb, line 53
def display_compile_shader_log(shader_handle)
  info_log = " " * 1024
  glGetShaderInfoLog(shader_handle, 1023, nil, info_log)
  puts "Shader InfoLog:\n#{info_log}\n"
end
display_model(model) click to toggle source
# File gtk3/sample/misc/treestore.rb, line 54
def display_model(model)
  win = Gtk::Window.new(:toplevel)
  win.title = "Simple Gtk::TreeStore"
  win.add(treeview_widget_of(model))
  win.show_all
  win.signal_connect("destroy") { Gtk.main_quit }
  Gtk.main
end
draw_brush(widget, surface, x, y) click to toggle source
# File gtk3/sample/misc/drawing.rb, line 19
def draw_brush(widget, surface, x, y)
  cr = Cairo::Context.new(surface)
  cr.rectangle(x - 3, y - 3, 6, 6)
  cr.fill
  cr.destroy
  widget.queue_draw_area(x - 3, y - 3, 6, 6)
end
drawingarea_query_tooltip(keyboard_tip, x, y, tooltip, rectangles) click to toggle source
# File gtk2/sample/misc/tooltips.rb, line 55
def drawingarea_query_tooltip(keyboard_tip, x, y, tooltip, rectangles)
    if keyboard_tip
        return false
    end
    for r in rectangles
        if r.x < x && x < r.x + 50 && r.y < y && y < r.y + 50
            tooltip.markup = r.tooltip
            return true
        end
    end
    return false
end
enable_debug_build_flag(flags) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 32
def enable_debug_build_flag(flags)
  if gcc?
    debug_option_pattern = /(^|\s)-g\d?(\s|$)/
    if debug_option_pattern =~ flags
      flags.gsub(debug_option_pattern, '\1-g3\2')
    else
      flags + " -g3"
    end
  else
    flags
  end
end
ensure_objs() click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 270
def ensure_objs
  return unless $objs.nil?

  source_dir = '$(srcdir)'
  RbConfig.expand(source_dir)

  pattern = "*.{#{SRC_EXT.join(',')}}"
  srcs = Dir[File.join(source_dir, pattern)]
  srcs |= Dir[File.join(".", pattern)]
  $objs = srcs.collect do |f|
    File.basename(f, ".*") + ".o"
  end.uniq
end
event_loop(pipe) click to toggle source
# File gstreamer/sample/framestep1.rb, line 26
def event_loop(pipe)
  running = true

  bus = pipe.bus

  while running
    message = bus.timed_pop_filtered(Gst::CLOCK_TIME_NONE, Gst::MessageType::ANY)
    raise "message nil" if message.nil?

    case message.type
    when Gst::MessageType::EOS
      puts "got EOS"
      running = false
    when Gst::MessageType::WARNING
      warning, debug = message.parse_warning
      puts "Debugging info: #{debug || 'none'}"
      puts "Warning: #{warning.message}"
    when Gst::MessageType::ERROR
      error, debug = message.parse_error
      puts "Debugging info: #{debug || 'none'}"
      puts "Error: #{error.message}"
      running = false
    when Gst::MessageType::STEP_DONE
      format, amount, rate, flush, intermediate, duration, eos =
        message.parse_step_done
      if format == Gst::Format::DEFAULT
        puts "step done: #{gst_time(duration)} skipped in #{gst_time(amount)} frames"
      else
        puts "step done: #{gst_time(duration)} skipped"
      end
      running = false
    end
  end
end
fill_model(icons) click to toggle source
# File gtk3/sample/misc/icons-theme-viewer.rb, line 11
def fill_model(icons)
  model = Gtk::ListStore.new(String, GdkPixbuf::Pixbuf)
  icons.each do |icon|
    pixbuf = Gtk::IconTheme.default.load_icon(icon, 32, 0)
    iter = model.append
    iter[0] = icon
    iter[1] = pixbuf
  end
  model
end
find_demo_filename_from_name(source, name) click to toggle source
# File gtk3/sample/gtk-demo/main.rb, line 155
def find_demo_filename_from_name(source, name)
  demo_filename = nil
  source.each do |_title, filename, children|
    if filename && name == get_demo_name_from_filename(filename)
      demo_filename = filename
    end
    break if demo_filename
    (demo_filename = find_demo_filename_from_name(children, name)) if children
  end
  demo_filename
end
find_gem_spec(package) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 142
def find_gem_spec(package)
  begin
    Gem::Specification.find_by_name(package)
  rescue LoadError
    nil
  end
end
gcc?() click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 20
def gcc?
  CONFIG["GCC"] == "yes"
end
gen_icon_view(pattern, context = nil) click to toggle source
# File gtk3/sample/misc/icons-theme-viewer.rb, line 22
def gen_icon_view(pattern, context = nil)
  icon_theme = Gtk::IconTheme.default
  icons = icon_theme.icons(context).grep(/#{pattern}/)
  model = fill_model(icons)
  icon_view = Gtk::IconView.new(:model => model)
  icon_view.text_column = 0
  icon_view.pixbuf_column = 1
  icon_view
end
generate_index() click to toggle source
# File gtk3/sample/gtk-demo/main.rb, line 68
def generate_index
  # Target scripts
  scripts = Dir.glob(File.join(File.dirname(__FILE__), "*.rb"))
  # Generate index tree
  children = {}
  index = []

  scripts.each do |script|
    next if "main.rb" == File.basename(script)
    title, depend = script_info(script)

    next if depend && !Gtk.const_defined?(depend)

    if title =~ %r{^(.+?)/(.+)$}
      parent = Regexp.last_match(1)
      child = Regexp.last_match(2)

      unless children[parent]
        children[parent] = []
        index += [[parent, nil, []]]
      end
      children[parent] += [[child, script]]
    else
      index += [[title, script]]
    end
  end

  # Sort children
  children.each_key do |parent|
    children[parent].sort! do |a, b|
      a[0] <=> b[0]
    end
  end

  # Expand children
  index.collect! do |row|
    row[2] = children[row[0]] if row[2]

    row
  end

  index.sort! do |a, b|
    a[0] <=> b[0]
  end

  index
end
get_class_name_from_filename(filename) click to toggle source
# File gtk3/sample/gtk-demo/main.rb, line 131
def get_class_name_from_filename(filename)
  pattern = get_demo_name_from_filename(filename)
  class_name = pattern.split("_").map(&:capitalize).join
  class_name << "Demo"
end
get_demo_filename_from_name(name) click to toggle source
# File gtk3/sample/gtk-demo/main.rb, line 167
def get_demo_filename_from_name(name)
  index = generate_index
  filename = find_demo_filename_from_name(index, name)
  puts "Demo not found" unless filename

  filename
end
get_demo_name_from_filename(filename) click to toggle source
# File gtk3/sample/gtk-demo/main.rb, line 127
def get_demo_name_from_filename(filename)
  File.basename(filename, ".rb").tr("-", "_")
end
glib_mkenums(prefix, files, g_type_prefix, include_files, options={}) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 414
def glib_mkenums(prefix, files, g_type_prefix, include_files, options={})
  add_distcleanfile(prefix + ".h")
  add_distcleanfile(prefix + ".c")
  GLib::MkEnums.create(prefix, files, g_type_prefix, include_files, options)
  add_obj("#{prefix}.o")
end
gst_time(time) click to toggle source
# File gstreamer/sample/framestep1.rb, line 61
def gst_time(time)
  Time.at(time / 1000000000.0).utc.strftime("%H:%M:%S.%N")
end
list_demos(source, is_child = false) click to toggle source
# File gtk3/sample/gtk-demo/main.rb, line 137
def list_demos(source, is_child = false)
  source.each do |title, filename, children|
    if is_child
      printf("%-30.30s", "\t" + title)
      printf("%-30.30s", get_demo_name_from_filename(filename))
      puts ""
    elsif filename
      printf("%-38.38s", title)
      printf("%-30.30s", get_demo_name_from_filename(filename))
      puts ""
    else
      puts "#{title} : "
    end

    list_demos(children, true) if children
  end
end
load_list() click to toggle source
# File gtk3/sample/misc/list-store-usage.rb, line 22
def load_list
  model = Gtk::ListStore.new(TrueClass, String)

  4.times do |i|
    model.append.set_values([false, "index#{i}"])
  end
  model
end
make_version_header(app_name, pkgname, dir = "src") click to toggle source

This is used for the library which doesn't support version info.

# File glib2/lib/mkmf-gnome2.rb, line 355
def make_version_header(app_name, pkgname, dir = "src")
  version = PKGConfig.modversion(pkgname).split(/\./)
  (0..2).each do |v|
    version[v] = "0" unless version[v]
    if /\A(\d+)/ =~ version[v]
      number = $1
      tag = $POSTMATCH
      unless tag.empty?
        version[v] = number
        version[3] = tag
      end
    end
  end
  filename = "rb#{app_name.downcase}version.h"

  puts "creating #{filename}"

  add_distcleanfile(filename)

  FileUtils.mkdir_p(dir)
  out = File.open(File.join(dir, filename), "w")

  version_definitions = []
  ["MAJOR", "MINOR", "MICRO", "TAG"].each_with_index do |type, i|
    _version = version[i]
    next if _version.nil?
    version_definitions << "#define #{app_name}_#{type}_VERSION (#{_version})"
  end
  out.print %Q[/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
/************************************************

  #{filename} -

  This file was generated by mkmf-gnome2.rb.

************************************************/

#ifndef __RB#{app_name}_VERSION_H__
#define __RB#{app_name}_VERSION_H__

#{version_definitions.join("\n")}

#define #{app_name}_CHECK_VERSION(major,minor,micro)    \\
    (#{app_name}_MAJOR_VERSION > (major) || \\
     (#{app_name}_MAJOR_VERSION == (major) && #{app_name}_MINOR_VERSION > (minor)) || \\
     (#{app_name}_MAJOR_VERSION == (major) && #{app_name}_MINOR_VERSION == (minor) && \\
      #{app_name}_MICRO_VERSION >= (micro)))


#endif /* __RB#{app_name}_VERSION_H__ */
]
      out.close
end
new_rectangle_with_color(color) click to toggle source
# File clutter-gstreamer/sample/2.0/video-player.rb, line 142
def new_rectangle_with_color(color)
  actor = Clutter::Actor.new
  actor.background_color = color
  actor
end
parse(argv) click to toggle source
# File gstreamer/sample/gst-inspect.rb, line 34
def parse(argv)
  options = OpenStruct.new
  options.print_all = false
  options.print_auto_install_info = false

  opts = OptionParser.new do |opts|
    opts.banner += " [ELEMENT-NAME|PLUGIN-NAME]"

    opts.version = Gst.version

    opts.separator("")
    opts.on("-a", "--print-all", "Print all elements") do
      options.print_all = true
    end

    opts.on("--print-plugin-auto-install-info",
            "Print a machine-parsable list of features",
            "the specified plugin provides.",
            "Useful in connection with external",
            "automatic plugin installation mechanisms") do
      options.print_auto_install_info = true
    end
  end
  opts.parse!(argv)

  [options, argv.first]
end
position_controls(app, controls) click to toggle source
# File clutter-gstreamer/sample/2.0/video-player.rb, line 132
def position_controls(app, controls)
  stage_width, stage_height = app.stage.size
  bg_width, bg_height = app.control.size

  x = ((stage_width - bg_width) / 2).floor
  y =  stage_height - bg_height - 28

  controls.set_position(x, y)
end
print_list(list) click to toggle source
required_pkg_config_package(package_info, native_package_info=nil) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 465
def required_pkg_config_package(package_info, native_package_info=nil)
  if package_info.is_a?(Array)
    required_package_info = package_info
  else
    required_package_info = [package_info]
  end
  return true if PKGConfig.have_package(*required_package_info)

  PKGConfig.have_package(*required_package_info)
end
ruby_gnome2_version(glib_source_directory=nil) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 246
def ruby_gnome2_version(glib_source_directory=nil)
  glib_source_directory ||= File.join(File.dirname(__FILE__), "..",
                                      "ext", "glib2")
  rbglib_h = File.join(glib_source_directory, "rbglib.h")
  return nil unless File.exist?(rbglib_h)

  version = nil
  File.open(rbglib_h) do |h_file|
    version_info = {}
    h_file.each_line do |line|
      case line
      when /\A#define RBGLIB_(MAJOR|MINOR|MICRO)_VERSION\s+(\d+)/
        version_info[$1] = $2
      end
    end
    version_info = [version_info["MAJOR"],
                    version_info["MINOR"],
                    version_info["MICRO"]].compact
    version = version_info.join(".") if version_info.size == 3
  end

  version
end
run_demo_from_file(filename, window) click to toggle source
# File gtk3/sample/gtk-demo/main.rb, line 175
def run_demo_from_file(filename, window)
  class_name = get_class_name_from_filename(filename)

  require filename unless Object.const_defined?(class_name)

  klass = Object.const_get(class_name)
  demo = klass.new(window)
  demo_window = demo.run

  if demo_window.is_a?(Gtk::Window)
    demo_window.set_transient_for(window)
    demo_window.modal = true
  end
  demo_window
end
run_make_in_sub_dir(sub_dir, target) click to toggle source

generate top-level Makefile

# File extconf.rb, line 110
def run_make_in_sub_dir(sub_dir, target)
  if /mswin/ =~ RUBY_PLATFORM
    "   $(COMMAND) '#{sub_dir}' $(MAKE) #{target}"
  else
    "   (cd '#{sub_dir}' && $(MAKE) #{target})"
  end
end
run_make_in_sub_dirs_command(command, sub_dirs) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 302
def run_make_in_sub_dirs_command(command, sub_dirs)
  if /mswin/ =~ RUBY_PLATFORM
    sub_dirs.collect do |dir|
      "        @cd #{dir}
        @nmake -nologo DESTDIR=$(DESTDIR) #{command}
        @cd ..
".chmop
    end.join("\n")
  else
    sub_dirs.collect do |dir|
      "\t@cd #{dir}; $(MAKE) #{command}"
    end.join("\n")
  end
end
script_info(path) click to toggle source
# File gtk3/sample/gtk-demo/main.rb, line 50
def script_info(path)
  title = depend = nil
  file = File.open(path)
  file.each do |ln|
    if !title && ln =~ /^=\s+(.*)$/
      title = Regexp.last_match(1)
      if title =~ /^(.*)\((.+?)\)$/
        title = Regexp.last_match(1)
        depend = Regexp.last_match(2)
      end
    end

    break if title
  end

  [title, depend]
end
select_treeview_item(treeview, filename) click to toggle source
# File gtk3/sample/gtk-demo/main.rb, line 191
def select_treeview_item(treeview, filename)
  to_select = nil
  treeview.model.each do |model, path, iter|
    if iter[FILENAME_COLUMN] == filename
      to_select = path
      break
    end
  end
  treeview.expand_to_path(to_select)
  treeview.set_cursor(to_select, treeview.columns[FILENAME_COLUMN])
end
setup_shaders(vertex, fragment) click to toggle source
# File gtk3/sample/misc/gtkglarea2.rb, line 69
def setup_shaders(vertex, fragment)
  # Load the shaders sources
  vs_handle = glCreateShader(GL_VERTEX_SHADER)
  fs_handle = glCreateShader(GL_FRAGMENT_SHADER)

  glShaderSource(vs_handle,
                 1,
                 [vertex].pack("p"),
                 [vertex.bytesize].pack("I")
                )

  glShaderSource(fs_handle,
                 1,
                 [fragment].pack("p"),
                 [fragment.bytesize].pack("I")
                )

  vert_compiled = compile_shader(vs_handle)
  display_compile_shader_log(vs_handle) if vert_compiled == 0

  frag_compiled = compile_shader(fs_handle)
  display_compile_shader_log(fs_handle) if frag_compiled == 0

  return false if vert_compiled == 0 || frag_compiled == 0

  # Load those 2 shaders (vertex and fragment) into a GPU shader program
  prog_handle = glCreateProgram
  glAttachShader(prog_handle, vs_handle)
  glAttachShader(prog_handle, fs_handle)

  glLinkProgram(prog_handle)

  # Check if the program is valid
  linked_buf = "    "
  glGetProgramiv(prog_handle, GL_LINK_STATUS, linked_buf)
  linked = linked_buf.unpack("L")[0]
  if linked == 0
    info_log = " " * 1024
    glGetProgramInfoLog(prog_handle, 1023, nil, info_log)
    puts "Program InfoLog:\n#{info_log}\n"
  end
  return false if linked == 0

  return true, prog_handle
end
setup_win32(*args, &block) click to toggle source

For backward compatibility

# File glib2/lib/mkmf-gnome2.rb, line 138
def setup_win32(*args, &block)
  setup_windows(*args, &block)
end
setup_windows(target_name, base_dir=nil) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 117
def setup_windows(target_name, base_dir=nil)
  checking_for(checking_message("Windows")) do
    if windows_platform?
      import_library_name = "libruby-#{target_name}.a"
      $DLDFLAGS << " -Wl,--out-implib=#{import_library_name}"
      $cleanfiles << import_library_name
      base_dir ||= Pathname($0).dirname.parent.parent.expand_path
      base_dir = Pathname(base_dir) if base_dir.is_a?(String)
      binary_base_dir = base_dir + "vendor" + "local"
      if binary_base_dir.exist?
        $INCFLAGS += " -I#{binary_base_dir}/include"
        pkg_config_dir = binary_base_dir + "lib" + "pkgconfig"
        PKGConfig.add_path(pkg_config_dir.to_s)
      end
      true
    else
      false
    end
  end
end
show_controls(app, vis) click to toggle source
# File clutter-gstreamer/sample/2.0/video-player.rb, line 87
def show_controls(app, vis)
  return if app.control.nil?

  if vis == true && app.controls_showing == true
    if app.controls_timeout == 0
      app.controls_timeout = GLib::Timeout.add_seconds(5) do
                               controls_timeout_cb(app)
                             end
    end
    return
  end

  if vis == true && app.controls_showing == false
    app.controls_showing = true
    app.stage.show_cursor
    actor_animate(app.control, :ease_out_quint, 250, "opacity", 224)
    return
  end

  if vis == false && app.controls_showing == true
    app.controls_showing = false
    if app.mouse_in_window
      app.stage.hide_cursor
    end
    actor_animate(app.control, :ease_out_quint, 250, "opacity", 0)
    return
  end
end
test_hbbox() click to toggle source
# File gtk2/sample/misc/buttonbox.rb, line 54
def test_hbbox
  create_bbox_window(true, "Spread", 50, 40, Gtk::ButtonBox::SPREAD)
  create_bbox_window(true, "Edge", 250, 40, Gtk::ButtonBox::EDGE)
  create_bbox_window(true, "Start", 450, 40,  Gtk::ButtonBox::START)
  create_bbox_window(true, "End", 650, 15, Gtk::ButtonBox::END)
end
test_vbbox() click to toggle source
# File gtk2/sample/misc/buttonbox.rb, line 61
def test_vbbox
  create_bbox_window(false, "Spread", 50, 40, Gtk::ButtonBox::SPREAD)
  create_bbox_window(false, "Edge", 250, 40,  Gtk::ButtonBox::EDGE)
  create_bbox_window(false, "Start", 450, 40, Gtk::ButtonBox::START)
  create_bbox_window(false, "End", 650, 15, Gtk::ButtonBox::END)
end
textview_query_tooltip(textview, keyboard_tip, x, y, tooltip, tag) click to toggle source
# File gtk2/sample/misc/tooltips.rb, line 40
def textview_query_tooltip(textview, keyboard_tip, x, y, tooltip, tag)
    if keyboard_tip
        iter = textview.buffer.get_iter_at_offset(textview.buffer.cursor_position)
    else
        bx, by = textview.window_to_buffer_coords(Gtk::TextView::WINDOW_TEXT, x, y)
        iter, = textview.get_iter_at_position(bx, by)
    end
    if iter.has_tag?(tag)
        tooltip.text = 'Tooltip on text tag'
        return true
    else
        return false
    end
end
to_pixbuf(input, ratio) click to toggle source
# File rsvg2/sample/svg2.rb, line 24
def to_pixbuf(input, ratio)
  handle = nil
  Dir.chdir(File.dirname(File.expand_path(input))) do
    handle = Rsvg::Handle.new(:path => input)
  end
  dim = handle.dimensions
  width = dim.width * ratio
  height = dim.height * ratio
  surface = Cairo::ImageSurface.new(Cairo::FORMAT_ARGB32, width, height)
  cr = Cairo::Context.new(surface)
  cr.scale(ratio, ratio)
  cr.render_rsvg_handle(handle)
  temp = Tempfile.new("svg2")
  cr.target.write_to_png(temp.path)
  cr.target.finish
  GdkPixbuf::Pixbuf.new(:file => temp.path)
end
to_pixbuf_with_cairo(input, page_number, scale, rotate) click to toggle source
# File poppler/sample/pdf2.rb, line 91
def to_pixbuf_with_cairo(input, page_number, scale, rotate)
  doc = Poppler::Document.new(input)
  page = doc[page_number]
  width, height = page.size.collect {|x| x * scale}
  surface_width, surface_height = compute_size(width, height, rotate)

  surface = Cairo::ImageSurface.new(Cairo::FORMAT_ARGB32,
                                    surface_width, surface_height)
  cr = Cairo::Context.new(surface)

  half_width = surface_width / 2.0
  half_height = surface_height / 2.0
  cr.translate(half_width, half_height)
  cr.rotate(rotate / 180.0 * Math::PI)
  cr.translate(-half_width, -half_height)

  cr.translate((surface_width - width) / 2.0,
               (surface_height - height) / 2.0)
  cr.set_source_rgb(1, 1, 1)
  cr.rectangle(0, 0, width, height)
  cr.fill

  cr.scale(scale, scale)
  cr.render_poppler_page(page)
  temp = Tempfile.new("pdf2")
  cr.target.write_to_png(temp.path)
  cr.target.finish
  GdkPixbuf::Pixbuf.new(:file => temp.path)
end
toggle_pause_state(app) click to toggle source
# File clutter-gstreamer/sample/2.0/video-player.rb, line 116
def toggle_pause_state(app)
  return if app.vtexture.nil?

  if app.paused
    app.vtexture.playing = true
    app.paused = false
    app.control_play.hide
    app.control_pause.show
  else
    app.vtexture.playing = false
    app.paused = true
    app.control_pause.hide
    app.control_play.show
  end
end
treeview_query_tooltip(treeview, keyboard_tip, x, y, tooltip) click to toggle source
# File gtk2/sample/misc/tooltips.rb, line 20
def treeview_query_tooltip(treeview, keyboard_tip, x, y, tooltip)
    if keyboard_tip
        # Keyboard mode
        path, = treeview.cursor
        if not path
            return false
        end
    else
        bin_x, bin_y = treeview.convert_widget_to_bin_window_coords(x, y)
        # Mouse mode
        path, = treeview.get_path_at_pos(bin_x, bin_y)
        if not path
            return false
        end
    end
    data = treeview.model.get_value(treeview.model.get_iter(path), 0)
    tooltip.markup = "<b>Path #{path}:</b> #{data}"
    return true
end
treeview_widget_of(model) click to toggle source
# File gtk3/sample/misc/treestore.rb, line 40
def treeview_widget_of(model)
  treeview = Gtk::TreeView.new(model)
  treeview.append_column(Gtk::TreeViewColumn.new("Title",
                                                 Gtk::CellRendererText.new,
                                                 :text => TITLE_COLUMN))
  treeview.append_column(Gtk::TreeViewColumn.new("Author",
                                                 Gtk::CellRendererText.new,
                                                 :text => AUTHOR_COLUMN))
  treeview.append_column(Gtk::TreeViewColumn.new("Author",
                                                 Gtk::CellRendererToggle.new,
                                                 :active => CHECKED_COLUMN))
  treeview
end
try_compiler_option(opt, &block) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 57
def try_compiler_option(opt, &block)
  checking_for "#{opt} option to compiler" do
    if try_compile '', opt + " -Werror", &block
      $CFLAGS += " #{opt}"
      true
    else
      false
    end
  end
end
windows_platform?() click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 113
def windows_platform?
  /cygwin|mingw|mswin/ === RUBY_PLATFORM
end
xbm_data_to_cairo_data(data, width, stride) click to toggle source
# File gtk3/sample/misc/xbm-cursor.rb, line 38
def xbm_data_to_cairo_data(data, width, stride)
  n_bytes_per_row = (width / 8.0).ceil

  cairo_data_bytes = []
  data.unpack("C*").each_slice(n_bytes_per_row) do |row|
    row.each do |byte|
      cairo_data_bytes << byte
    end
    (stride - n_bytes_per_row).times do
      cairo_data_bytes << 0b0
    end
  end
  cairo_data_bytes.pack("C*")
end