2
# tk/image.rb : treat Tk image objects
10
TkCommandNames = ['image'.freeze].freeze
12
Tk_IMGTBL = TkCore::INTERP.create_table
13
Tk_Image_ID = ['i'.freeze, '00000'.taint].freeze
15
TkCore::INTERP.init_ip_env{ Tk_IMGTBL.clear }
17
def self.new(keys=nil)
18
if keys.kind_of?(Hash)
20
if keys.key?(:imagename)
21
name = keys[:imagename]
22
elsif keys.key?('imagename')
23
name = keys['imagename']
26
if name.kind_of?(TkImage)
29
name = _get_eval_string(name)
33
if !(keys[:without_creating] || keys['without_creating'])
34
keys = _symbolkey2str(keys)
35
keys.delete('imagename')
36
keys.delete('without_creating')
38
tk_call_without_enc('image', 'create',
39
@type, @path, *hash_kv(keys, true))
49
def initialize(keys=nil)
51
without_creating = false
52
if keys.kind_of?(Hash)
53
keys = _symbolkey2str(keys)
54
@path = keys.delete('imagename')
55
without_creating = keys.delete('without_creating')
58
# @path = Tk_Image_ID.join('')
59
@path = Tk_Image_ID.join(TkCore::INTERP._ip_id_)
62
unless without_creating
63
tk_call_without_enc('image', 'create',
64
@type, @path, *hash_kv(keys, true))
66
Tk_IMGTBL[@path] = self
70
Tk_IMGTBL.delete(@id) if @id
71
tk_call_without_enc('image', 'delete', @path)
75
number(tk_call_without_enc('image', 'height', @path))
78
bool(tk_call_without_enc('image', 'inuse', @path))
81
tk_call_without_enc('image', 'type', @path)
84
number(tk_call_without_enc('image', 'width', @path))
88
Tk.tk_call_without_enc('image', 'names').split.collect!{|id|
89
(Tk_IMGTBL[id])? Tk_IMGTBL[id] : id
94
Tk.tk_call_without_enc('image', 'types').split
98
class TkBitmapImage<TkImage
100
super() + ['maskdata', 'maskfile']
102
private :__strval_optkeys
104
def initialize(*args)
110
class TkPhotoImage<TkImage
111
NullArgOptionKeys = [ "shrink", "grayscale" ]
113
def _photo_hash_kv(keys)
114
keys = _symbolkey2str(keys)
115
NullArgOptionKeys.collect{|opt|
126
private :_photo_hash_kv
128
def initialize(*args)
134
tk_send_without_enc('blank')
141
tk_send 'cget', '-' << option.to_s
143
tk_tcl2ruby(tk_send('cget', '-' << option.to_s))
150
elsif opts.size == 1 && opts[0].kind_of?(Hash)
151
tk_send('copy', src, *_photo_hash_kv(opts[0]))
153
# for backward compatibility
154
args = opts.collect{|term|
155
if term.kind_of?(String) && term.include?(?\s)
161
tk_send('copy', src, *args)
167
#tk_send('data', *_photo_hash_kv(keys))
168
tk_split_list(tk_send('data', *_photo_hash_kv(keys)))
172
tk_send('get', x, y).split.collect{|n| n.to_i}
178
elsif opts.size == 1 && opts[0].kind_of?(Hash)
179
tk_send('put', data, *_photo_hash_kv(opts[0]))
181
# for backward compatibility
182
tk_send('put', data, '-to', *opts)
187
def read(file, *opts)
189
tk_send('read', file)
190
elsif opts.size == 1 && opts[0].kind_of?(Hash)
191
tk_send('read', file, *_photo_hash_kv(opts[0]))
193
# for backward compatibility
194
args = opts.collect{|term|
195
if term.kind_of?(String) && term.include?(?\s)
201
tk_send('read', file, *args)
211
def get_transparency(x, y)
212
bool(tk_send('transparency', 'get', x, y))
214
def set_transparency(x, y, st)
215
tk_send('transparency', 'set', x, y, st)
219
def write(file, *opts)
221
tk_send('write', file)
222
elsif opts.size == 1 && opts[0].kind_of?(Hash)
223
tk_send('write', file, *_photo_hash_kv(opts[0]))
225
# for backward compatibility
226
args = opts.collect{|term|
227
if term.kind_of?(String) && term.include?(?\s)
233
tk_send('write', file, *args)