bugfix: safety against breaking the AI if you press undo while it's thinking
[kaya.git] / lib / plugins / squares / default.rb
blob8bcd67d4f5bf52a8c8f7e45cc5643e19eea492ad
1 # Copyright (c) 2009 Paolo Capriotti <p.capriotti@gmail.com>
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 require 'plugins/plugin'
9 require 'plugins/background'
11 class DefaultBackground
12   include Plugin
13   include Background
14   
15   plugin :name => 'Default Background',
16          :interface => :board,
17          :keywords => %w(chess)
18   
19   def initialize(opts)
20     @squares = opts[:board_size] || opts[:game].size
21   end
23   def pixmap(size)
24     Qt::Image.painted(Qt::Point.new(size.x * @squares.x, size.y * @squares.y)) do |p|
25       (0...@squares.x).each do |x|
26         (0...@squares.y).each do |y|
27           rect = Qt::RectF.new(size.x * x, size.y * y, size.x, size.y)
28           color = if (x + y) % 2 == 1
29             Qt::Color.new(0x6b, 0x82, 0x9c)
30           else
31             Qt::Color.new(0xb8, 0xc0, 0xc0)
32           end
33           p.fill_rect(rect, Qt::Brush.new(color))
34         end
35       end
36     end.to_pix
37   end
38 end