class Tkar::Tkaroid
Constants
- DRAG_COLOR
- HOVER_COLOR
Attributes
flags[RW]
id[RW]
layer[RW]
newly_added[RW]
note r is in radians, unlike Tk
params[RW]
parts[R]
r[RW]
shape[RW]
tag[R]
x[RW]
y[RW]
Public Class Methods
new() { |self| ... }
click to toggle source
# File lib/tkar/tkaroid.rb 8 def initialize 9 yield self if block_given? 10 @tag = Tkaroid.tag(@id) 11 @parts = [] 12 end
tag(id)
click to toggle source
# File lib/tkar/tkaroid.rb 14 def self.tag id 15 "tkar#{id}" 16 end
Public Instance Methods
colorize(canvas, color)
click to toggle source
note: call after update, or else color is lost
# File lib/tkar/tkaroid.rb 43 def colorize canvas, color 44 canvas.itemconfigure tag, :fill => color 45 rescue => ex 46 if ex.message =~ /unknown option "-fill"/ 47 extend CarefulColorize 48 colorize canvas, color 49 else 50 raise 51 end 52 end
decolorize(canvas)
click to toggle source
# File lib/tkar/tkaroid.rb 62 def decolorize canvas 63 colorize canvas, nil 64 update canvas 65 end
drag_colorize(canvas)
click to toggle source
# File lib/tkar/tkaroid.rb 54 def drag_colorize canvas 55 colorize canvas, DRAG_COLOR 56 end
draggable?()
click to toggle source
# File lib/tkar/tkaroid.rb 18 def draggable? 19 true ## get from flags 20 end
drop_target?()
click to toggle source
# File lib/tkar/tkaroid.rb 22 def drop_target? 23 true ## get from flags 24 end
hover_colorize(canvas)
click to toggle source
# File lib/tkar/tkaroid.rb 58 def hover_colorize canvas 59 colorize canvas, HOVER_COLOR 60 end
update(canvas, zoom=canvas.zoom)
click to toggle source
# File lib/tkar/tkaroid.rb 67 def update canvas, zoom=canvas.zoom 68 tags = [tag] 69 result = @newly_added 70 71 if @newly_added 72 @shape[self].each do |klass, coords, config| 73 coords.map! {|x| x*zoom} if zoom 74 coords << config 75 part = klass.new(canvas, *coords) 76 @parts << part 77 part.raise tag rescue nil 78 part.tags tags 79 end 80 @newly_added = false 81 82 else 83 i = 0 84 @shape[self].each do |klass, coords, config| 85 part = parts[i]; i += 1 86 coords.map! {|x| x*zoom} if zoom 87 part.coords(*coords) 88 part.configure(config) 89 end 90 end 91 92 return result 93 end