2004-07-01 05:38:48 -04:00
|
|
|
#
|
|
|
|
# tkextlib/tkDND/shape.rb
|
|
|
|
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
|
|
|
|
#
|
|
|
|
|
|
|
|
require 'tk'
|
|
|
|
|
|
|
|
# call setup script for general 'tkextlib' libraries
|
|
|
|
require 'tkextlib/setup.rb'
|
|
|
|
|
|
|
|
# call setup script
|
2004-07-06 05:42:12 -04:00
|
|
|
require 'tkextlib/tkDND/setup.rb'
|
2004-07-01 05:38:48 -04:00
|
|
|
|
|
|
|
# TkPackage.require('shape', '0.3')
|
|
|
|
TkPackage.require('shape')
|
|
|
|
|
|
|
|
module Tk
|
|
|
|
module TkDND
|
|
|
|
module Shape
|
2004-07-06 05:42:12 -04:00
|
|
|
=begin
|
|
|
|
def self.package_version
|
2004-10-11 00:51:21 -04:00
|
|
|
begin
|
|
|
|
TkPackage.require('shape')
|
|
|
|
rescue
|
|
|
|
''
|
|
|
|
end
|
2004-07-06 05:42:12 -04:00
|
|
|
end
|
|
|
|
=end
|
|
|
|
def self.package_version
|
2004-10-11 00:51:21 -04:00
|
|
|
Tk.tk_call('set', 'shape_version')
|
2004-07-06 05:42:12 -04:00
|
|
|
end
|
|
|
|
alias shape_version package_version
|
|
|
|
|
|
|
|
def self.package_patchlevel
|
2004-10-11 00:51:21 -04:00
|
|
|
Tk.tk_call('set', 'shape_patchlevel')
|
2004-07-06 05:42:12 -04:00
|
|
|
end
|
|
|
|
alias shape_patchlevel package_patchlevel
|
|
|
|
|
2004-07-01 05:38:48 -04:00
|
|
|
def self.version
|
2004-10-11 00:51:21 -04:00
|
|
|
tk_call('shape', 'version')
|
2004-07-01 05:38:48 -04:00
|
|
|
end
|
2004-07-06 05:42:12 -04:00
|
|
|
alias xshape_version version
|
2004-07-01 05:38:48 -04:00
|
|
|
|
|
|
|
############################
|
|
|
|
|
|
|
|
def shape_bounds(kind=nil)
|
2004-10-11 00:51:21 -04:00
|
|
|
if kind
|
|
|
|
ret = tk_call('shape', 'bounds', @path, "-#{kind}")
|
|
|
|
else
|
|
|
|
ret = tk_call('shape', 'bounds', @path)
|
|
|
|
end
|
|
|
|
if ret == ""
|
|
|
|
nil
|
|
|
|
else
|
|
|
|
list(ret)
|
|
|
|
end
|
2004-07-01 05:38:48 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def shape_get(kind=nil)
|
2004-10-11 00:51:21 -04:00
|
|
|
if kind
|
|
|
|
list(tk_call('shape', 'get', @path, "-#{kind}"))
|
|
|
|
else
|
|
|
|
list(tk_call('shape', 'get', @path))
|
|
|
|
end
|
2004-07-01 05:38:48 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def shape_offset(x, y, kind=nil)
|
2004-10-11 00:51:21 -04:00
|
|
|
if kind
|
|
|
|
tk_call('shape', 'get', @path, "-#{kind}", x, y)
|
|
|
|
else
|
|
|
|
tk_call('shape', 'get', @path, x, y)
|
|
|
|
end
|
|
|
|
self
|
2004-07-01 05:38:48 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def _parse_shapespec_param(args)
|
2004-10-11 00:51:21 -04:00
|
|
|
cmd = []
|
2004-07-01 05:38:48 -04:00
|
|
|
|
2004-10-11 00:51:21 -04:00
|
|
|
kind_keys = ['bounding', 'clip', 'both']
|
|
|
|
offset_keys = ['offset']
|
|
|
|
srckind_keys = ['bitmap', 'rectangles', 'reset', 'test', 'window']
|
2004-07-01 05:38:48 -04:00
|
|
|
|
2004-10-11 00:51:21 -04:00
|
|
|
cmd << "-#{args.shift}" if kind_keys.member?(args[0].to_s)
|
2004-07-01 05:38:48 -04:00
|
|
|
|
2004-10-11 00:51:21 -04:00
|
|
|
if offset_keys.member?(args[0].to_s)
|
|
|
|
cmd << "-#{args.shift}"
|
|
|
|
cmd << args.shift # xOffset
|
|
|
|
cmd << args.shift # yOffset
|
|
|
|
end
|
2004-07-01 05:38:48 -04:00
|
|
|
|
2004-10-11 00:51:21 -04:00
|
|
|
if srckind_keys.member?(args[0].to_s)
|
|
|
|
cmd << "-#{args.shift}"
|
|
|
|
end
|
2004-07-01 05:38:48 -04:00
|
|
|
|
2004-10-11 00:51:21 -04:00
|
|
|
cmd.concat(args)
|
2004-07-01 05:38:48 -04:00
|
|
|
|
2004-10-11 00:51:21 -04:00
|
|
|
cmd
|
2004-07-01 05:38:48 -04:00
|
|
|
end
|
|
|
|
private :_parse_shapespec_param
|
|
|
|
|
|
|
|
def shape_set(*args) # ?kind? ?offset <x> <y>? srckind ?arg ...?
|
2004-10-11 00:51:21 -04:00
|
|
|
tk_call('shape', 'set', @path, *(_parse_shapespec_param(args)))
|
|
|
|
self
|
2004-07-01 05:38:48 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def shape_update(op, *args) # ?kind? ?offset <x> <y>? srckind ?arg ...?
|
2004-10-11 00:51:21 -04:00
|
|
|
tk_call('shape', 'update', @path, op, *(_parse_shapespec_param(args)))
|
|
|
|
self
|
2004-07-01 05:38:48 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class TkWindow
|
|
|
|
include Tk::TkDND::Shape
|
|
|
|
end
|