Theme -> Plugin.
[kaya.git] / lib / plugins / squares / default.rb
blob6da25d90bc971482e05ead796e9c10f85d4586a8
1 require 'plugins/plugin'
2 require 'plugins/background'
4 class DefaultBackground
5   include Plugin
6   include Background
7   
8   plugin :name => 'Default',
9          :keywords => %w(chess board)
10   
11   def initialize(opts)
12     @squares = opts[:board_size] || opts[:game].size
13   end
15   def pixmap(size)
16     Qt::Image.painted(Qt::Point.new(size.x * @squares.x, size.y * @squares.y)) do |p|
17       (0...@squares.x).each do |x|
18         (0...@squares.y).each do |y|
19           rect = Qt::RectF.new(size.x * x, size.y * y, size.x, size.y)
20           color = if (x + y) % 2 == 0
21             Qt::Color.new(0x6b, 0x82, 0x9c)
22           else
23             Qt::Color.new(0xb8, 0xc0, 0xc0)
24           end
25           p.fill_rect(rect, Qt::Brush.new(color))
26         end
27       end
28     end.to_pix
29   end
30 end