Sha256: 1a73a5034c782d73bb25c84593775f40feb1b671a2acb74b53f5de379b64862d

Contents?: true

Size: 1.75 KB

Versions: 26

Compression:

Stored size: 1.75 KB

Contents

# Enumeration
def enum(start, count)
  (start...(start+count)).to_a
end

module Responder
  # Generates identifiers as class constants. Originally submitted by
  # Sean O'Halpin, slightly modified by Lyle.
  def identifier(*ids)
    ids << :ID_LAST
    base = self.class.superclass::ID_LAST
    vals = enum(base, ids.size)
    ids.each_index do |i|
      unless self.class.const_defined?(ids[i])
        self.class.class_eval("#{ids[i].id2name} = #{vals[i]}")
      end
    end
  end

  # Return the array of (selector -> func) associations
  def messageMap
    unless instance_variables.include? "@assocs"
      @assocs = []
    end
    @assocs
  end

  # Look up array index of this message map entry
  def assocIndex(lo, hi)
    currIndex = -1
    assocs = messageMap
    assocs.each_index do |i|
      if assocs[i][0] == lo && assocs[i][1] == hi
        currIndex = i
      end
    end
    currIndex
  end

  # Add new or replace existing map entry
  def addMapEntry(lo, hi, func)
    func = func.intern if func.is_a? String
    currIndex = assocIndex(lo, hi)
    if currIndex < 0
      messageMap.push([lo, hi, func])
    else
      messageMap[currIndex] = [lo, hi, func]
    end
  end

  # Define range of function types
  def FXMAPTYPES(typelo, typehi, func)
    addMapEntry(Fox.MKUINT(Fox::MINKEY, typelo), Fox.MKUINT(Fox::MAXKEY, typehi), func)
  end

  # Define one function type
  def FXMAPTYPE(type, func)
    addMapEntry(Fox.MKUINT(Fox::MINKEY, type), Fox.MKUINT(Fox::MAXKEY, type), func)
  end

  # Define range of functions
  def FXMAPFUNCS(type, keylo, keyhi, func)
    addMapEntry(Fox.MKUINT(keylo, type), Fox.MKUINT(keyhi, type), func)
  end

  # Define one function
  def FXMAPFUNC(type, id, func)
    addMapEntry(Fox.MKUINT(id, type), Fox.MKUINT(id, type), func)
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
fxruby-1.6.14-mswin32 lib/fox16/responder.rb
fxruby-1.6.13-mswin32 lib/fox16/responder.rb
fxruby-1.6.11 lib/fox16/responder.rb
fxruby-1.6.10 lib/fox16/responder.rb
fxruby-1.6.12 lib/fox16/responder.rb
fxruby-1.6.13 lib/fox16/responder.rb
fxruby-1.6.14-universal-darwin-9 lib/fox16/responder.rb
fxruby-1.6.15-universal-darwin-9 lib/fox16/responder.rb
fxruby-1.6.14 lib/fox16/responder.rb
fxruby-1.6.15-x86-mswin32-60 lib/fox16/responder.rb
fxruby-1.6.15 lib/fox16/responder.rb
fxruby-1.6.16-universal-darwin-9 lib/fox16/responder.rb
fxruby-1.6.16-x86-mswin32-60 lib/fox16/responder.rb
fxruby-1.6.17-universal-darwin-9 lib/fox16/responder.rb
fxruby-1.6.16 lib/fox16/responder.rb
fxruby-1.6.17-x86-mswin32-60 lib/fox16/responder.rb
fxruby-1.6.17 lib/fox16/responder.rb
fxruby-1.6.18-universal-darwin-9 lib/fox16/responder.rb
fxruby-1.6.18-x86-mswin32-60 lib/fox16/responder.rb
fxruby-1.6.18 lib/fox16/responder.rb