Sha256: 1e2f5f8b5fc932e6959d1e4a257e485972169e0719da34c3ab2ca82aa6c6a163

Contents?: true

Size: 1023 Bytes

Versions: 1

Compression:

Stored size: 1023 Bytes

Contents

require 'zerenity/base'

module Zerenity
  # Displays a color selection dialog. Returns the value of the color selected
  # as #rrrrggggbbbb, where r, g and b are hex digits representing the red, 
  # green and blue components respectively
  #
  #  ====Example Usage:
  #   Zereity::ColorSelection( :title => "Select a color" )
  def self.ColorSelection( options = {} )  
    ColorSelection.run( options )
  end

  class ColorSelection < Base # :nodoc:
    def self.run( options )
      self.check( options )
      Gtk.init
      color_selection = Gtk::ColorSelectionDialog.new( options[ :title ])
      result = nil
      color_selection.run do |response|
        if ( response == Gtk::Dialog::RESPONSE_OK )
          # I don't have the latest Ruby/GNOME2 on my system so this mimics current_color.to_s
          result = "##{ color_selection.colorsel.current_color.to_a.map{|channel| channel.to_s(16).rjust(4,'0').upcase }.join }"
        end
      end
      color_selection.destroy
      return result
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
zerenity-1.3 lib/zerenity/colorselection.rb