Use integer coordinates everywhere.
[kaya.git] / lib / item.rb
blobf39ab30c48e394f00b6d4b9c98b4aefc65039603
1 require 'qtutils'
3 class Item < Qt::GraphicsPixmapItem
4   attr_reader :name, :item
5   attr_reader :opacity
6   
7   def initialize(name, pixmap, parent, scene)
8     super pixmap, parent, scene
9     @name = name
10     @opacity = 1.0
11   end
12   
13   def paint(p, options, widget)
14     p.saving do |p|
15       p.opacity = @opacity
16       super p, options, widget
17     end
18   end
19   
20   def opacity=(value)
21     @opacity = value
22     update
23   end
24   
25   def remove
26     scene.remove_item self
27   end
28 end
30 module ItemUtils
31   def create_item(key, pix, opts = {})
32     name = opts[:name] || key.to_s
33     item = Item.new(name, pix, self, scene)
34     item.pos = opts[:pos] || Qt::PointF.new(0, 0)
35     item.z_value = opts[:z] || 0
36     item.visible = false if opts[:hidden]
37     item
38   end
39   
40   def destroy_item(item)
41     scene.remove_item item
42   end
43 end