class Object

Constants

COLORS
EXECUTE
FONT
GNOME2Package
GST_PLAY_FLAG_VIS
HANDLE_SIZE
HEIGHT
NOTCH
N_WORDS
PIXBUF_COLUMN
RADIUS
Rectangle

Drawing area

SEEK_H
SEEK_W
SIZE
SUBDIRS
TARGET_SIZE
TEXT_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 155
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 190
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 223
def add_distcleanfile(file)
  $distcleanfiles ||= []
  $distcleanfiles << file
end
add_obj(name) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 441
def add_obj(name)
  ensure_objs
  $objs << name unless $objs.index(name)
end
check_cairo(options={}) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 453
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
    $CFLAGS += " -I#{rcairo_source_dir}/ext/cairo"
  end

  PKGConfig.have_package('cairo') and have_header('rb_cairo.h')
end
check_ruby_func() click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 413
def check_ruby_func
  #Other options
  ruby_header = "ruby.h"
  have_func("rb_define_alloc_func", ruby_header) # for ruby-1.8
  have_func("rb_block_proc", ruby_header) # for ruby-1.8

  STDOUT.print("checking for new allocation framework... ") # for ruby-1.7
  if Object.respond_to? :allocate
    STDOUT.print "yes\n"
    $defs << "-DHAVE_OBJECT_ALLOCATE"
  else
    STDOUT.print "no\n"
  end

  STDOUT.print("checking for attribute assignment... ") # for ruby-1.7
  STDOUT.flush
  if defined? try_compile and try_compile <<SRC
#include "ruby.h"
#include "node.h"
int node_attrasgn = (int)NODE_ATTRASGN;
SRC
    STDOUT.print "yes\n"
    $defs << "-DHAVE_NODE_ATTRASGN"
  else
    STDOUT.print "no\n"
  end
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 288
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 228
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 322
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 23
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
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
draw_text(cr) click to toggle source
# File pango/sample/pango_cairo.rb, line 24
def draw_text(cr)
  # Center coordinates on the middle of the region we are drawing
  cr.translate(RADIUS, RADIUS);

  # Create a PangoLayout, set the font and text
  layout = cr.create_pango_layout
  
  layout.set_text("Text")
  desc = Pango::FontDescription.new(FONT)
  layout.set_font_description(desc)

  # Draw the layout N_WORDS times in a circle
  N_WORDS.times do |i|
    angle = (360.0 * i) / N_WORDS;
    cr.save do
      # Gradient from red at angle == 60 to blue at angle == 300
      red = (1 + Math.cos((angle - 60) * Math::PI / 180.0)) / 2
      cr.set_source_rgb(red, 0, 1.0 - red)
      cr.rotate(angle * Math::PI / 180.0)
    
      # Inform Pango to re-layout the text with the new transformation
      cr.update_pango_layout(layout)
    
      width, height = layout.size
      cr.move_to(-(width.to_f / Pango::SCALE) / 2, -RADIUS)
      cr.show_pango_layout(layout)
    end
  end
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 31
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 274
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
find_gem_spec(package) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 141
def find_gem_spec(package)
  begin
    require 'rubygems'
    if Gem::Specification.respond_to?(:find_by_name)
      Gem::Specification.find_by_name(package)
    else
      Gem.source_index.find_name(package).last
    end
  rescue LoadError
    nil
  end
end
gcc?() click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 19
def gcc?
  CONFIG["GCC"] == "yes"
end
glib_mkenums(prefix, files, g_type_prefix, include_files, options={}) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 446
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
install_missing_native_package(native_package_info) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 529
def install_missing_native_package(native_package_info)
  platform = package_platform
  native_package_info = normalize_native_package_info(native_package_info)
  package = native_package_info[platform]
  return false if package.nil?

  package_name, *options = package
  package_command_line = [package_name, *options].join(" ")
  need_super_user_priviledge = true
  case platform
  when :debian
    install_command = "apt-get install -V -y #{package_command_line}"
  when :fedora, :redhat
    install_command = "yum install -y #{package_command_line}"
  when :suse
    install_command = "zypper --non-interactive install #{package_command_line}"
  when :arch
    install_command = "pacman -S --noconfirm #{package_command_line}"
  when :homebrew
    need_super_user_priviledge = false
    install_command = "brew install #{package_command_line}"
  when :macports
    install_command = "port install -y #{package_command_line}"
  else
    return false
  end

  have_priviledge = (not need_super_user_priviledge or super_user?)
  unless have_priviledge
    sudo = find_executable("sudo")
  end

  installing_message = "installing '#{package_name}' native package... "
  message("%s", installing_message)
  failed_to_get_super_user_priviledge = false
  if have_priviledge
    succeeded = xsystem(install_command)
  else
    if sudo
      prompt = "[sudo] password for %u to install <#{package_name}>: "
      sudo_options = "-p #{Shellwords.escape(prompt)}"
      install_command = "#{sudo} #{sudo_options} #{install_command}"
      succeeded = xsystem(install_command)
    else
      succeeded = false
      failed_to_get_super_user_priviledge = true
    end
  end

  if failed_to_get_super_user_priviledge
    result_message = "require super user privilege"
  else
    result_message = succeeded ? "succeeded" : "failed"
  end
  Logging.postpone do
    "#{installing_message}#{result_message}\n"
  end
  message("#{result_message}\n")

  error_message = nil
  unless succeeded
    if failed_to_get_super_user_priviledge
      error_message = <<-EOM
'#{package_name}' native package is required.
run the following command as super user to install required native package:
  \# #{install_command}
EOM
    else
      error_message = <<-EOM
failed to run '#{install_command}'.
EOM
    end
  end
  if error_message
    message("%s", error_message)
    Logging.message("%s", error_message)
  end

  Logging.message("--------------------\n\n")

  succeeded
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 359
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
normalize_native_package_info(native_package_info) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 521
def normalize_native_package_info(native_package_info)
  native_package_info ||= {}
  native_package_info = native_package_info.dup
  native_package_info[:fedora] ||= native_package_info[:redhat]
  native_package_info[:suse] ||= native_package_info[:fedora]
  native_package_info
end
package_platform() click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 497
def package_platform
  if File.exist?("/etc/debian_version")
    :debian
  elsif File.exist?("/etc/fedora-release")
    :fedora
  elsif File.exist?("/etc/redhat-release")
    :redhat
  elsif File.exist?("/etc/SuSE-release")
    :suse
  elsif find_executable("pacman")
    :arch
  elsif find_executable("brew")
    :homebrew
  elsif find_executable("port")
    :macports
  else
    :unknown
  end
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 612
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)

  native_package_info ||= {}
  return false unless install_missing_native_package(native_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 250
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_make_in_sub_dir(sub_dir, target) click to toggle source

generate top-level Makefile

# File extconf.rb, line 111
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 306
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
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 137
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 116
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?
        $CFLAGS += " -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
super_user?() click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 517
def super_user?
  Process.uid.zero?
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 44
def to_pixbuf(input, ratio)
  RSVG.pixbuf_from_file_at_zoom(input, ratio, ratio)
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
  Gdk::Pixbuf.new(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
try_compiler_option(opt, &block) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 56
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 112
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