Implemented pool flipping.
[kaya.git] / lib / themes / layouts / cool / cool.rb
bloba32a38ed2f48f331d61a177cfe9b8611e595de63
1 require 'themes/theme'
3 class CoolLayout
4   include Theme
5   
6   theme :name => 'Layouts/Cool',
7         :keywords => %w(layout)
8         
9   # values relative to unit = 1
10   MARGIN = 0.2
11   CLOCK_WIDTH = 2.6
12   CLOCK_HEIGHT_RATIO = 0.4
13         
14   def initialize(opts)
15     @game = opts[:game]
16     @size = @game.size
17     @flipped = false
18   end
19         
20   def layout(rect, elements)
21     xrel = @size.x + MARGIN * 3 + CLOCK_WIDTH
22     yrel = @size.y + MARGIN * 2
23     unit = [rect.width / xrel, rect.height / yrel].min.floor
24     margin = MARGIN * unit
25     clock_width = CLOCK_WIDTH * unit
27     base = Qt::Point.new((rect.width - xrel * unit) / 2,
28                           (rect.height - yrel * unit) / 2)
29     
30     board_rect = Qt::Rect.new(
31       base.x + margin, base.y + margin,
32       @size.x * unit, @size.y * unit)
33     elements[:board].flip(@flipped)
34     elements[:board].set_geometry(board_rect)
36     if @game.respond_to? :pool
37       pool_height = (board_rect.height - margin) / @game.players.size
38       offy = base.y
39       flip = !@flipped
40       pools_rect = @game.players.reverse.map do |player|
41         r = Qt::Rect.new(
42           board_rect.right + margin,
43           offy + margin,
44           clock_width,
45           pool_height)
46         elements[:pools][player].flip(flip = !flip)
47         elements[:pools][player].set_geometry(r)
48         offy = r.bottom
49         r
50       end
51     end
52   end
53   
54   def flip(value)
55     @flipped = value
56   end
57   
58   def flipped?
59     @flipped
60   end
61 end