3 class Pool < Qt::GraphicsItemGroup
4 BACKGROUND_ZVALUE = -10
12 def initialize(scene, theme, game, field)
15 @scene.add_element(self)
22 @size = Point.new(3, 5)
26 pieces = @items.map do |item|
31 pieces.each_with_index do |piece, index|
32 add_piece(index, piece)
36 def set_geometry(rect)
39 self.pos = @rect.top_left.to_f
41 @unit = (@rect.width / @size.x).floor
45 def add_piece(index, piece)
46 item = create_piece piece,
47 @theme.pieces.pixmap(piece, Qt::Point.new(@unit, @unit)),
48 :pos => to_real(index)
49 @items.insert(index, item)
51 # TODO shift the other items
57 index = to_logical(pos)
58 puts "index = #{index}"
62 result = Point.new((p.x.to_f / @unit).floor,
63 (p.y.to_f / @unit).floor)
65 x = y % 2 == 0 ? result.x : @size.x - result.x - 1
72 x = @size.x - x - 1 if y % 2 == 1
74 Qt::PointF.new(x * @unit, y * @unit)