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