2 require 'plugins/plugin'
3 require 'plugins/shadow'
4 require 'plugins/background'
6 class ShogibanBackground
10 BACKGROUND_COLOR = Qt::Color.new(0xeb, 0xd6, 0xa0)
11 LINE_COLOR = Qt::Color.new(0x9c, 0x87, 0x55)
12 BASE_DIR = File.dirname(__FILE__)
14 plugin :name => 'Shogiban',
15 :keywords => %w(shogi board)
17 def initialize(opts = {})
18 @squares = opts[:board_size] || opts[:game].size
19 @background = opts[:background] || 'kaya'
23 Qt::Image.painted(Qt::Point.new(size.x * @squares.x, size.y * @squares.y)) do |p|
25 bg = Qt::Image.new(File.join(BASE_DIR, @background + '.png'))
26 p.draw_tiled_pixmap(Qt::Rect.new(0, 0, size.x * @squares.x, size.y * @squares.y), bg.to_pix)
28 (0...@squares.x).each do |x|
29 (0...@squares.y).each do |y|
30 rect = Qt::RectF.new(size.x * x, size.y * y, size.x, size.y)
31 p.fill_rect(rect, Qt::Brush.new(BACKGROUND_COLOR))
37 pen.color = LINE_COLOR
39 (0..@squares.x).each do |x|
40 p.draw_line(x * size.x, 0, x * size.x, @squares.y * size.y)
42 (0..@squares.y).each do |y|
43 p.draw_line(0, y * size.y, size.x * @squares.x, y * size.y)
53 BASE_DIR = File.dirname(__FILE__)
54 TYPES = { :knight => 'n' }
55 NUDE_TILE = File.join(BASE_DIR, 'nude_tile.svg')
66 plugin :name => 'Shogi',
67 :keywords => %w(shogi pieces)
69 def initialize(opts = {})
70 @loader = lambda do |piece, size|
71 tile = Qt::SvgRenderer.new(NUDE_TILE)
72 kanji = Qt::SvgRenderer.new(filename(piece))
73 ratio = RATIOS[piece.type] || 0.9
74 img = Qt::Image.painted(size) do |p|
76 p.translate(size * (1 - ratio) / 2)
77 if piece.color == :white
85 if opts.has_key? :shadow
86 @loader = with_shadow(@loader)
90 def pixmap(piece, size)
91 @loader[piece, size].to_pix
95 color = piece.color.to_s[0, 1]
96 # type = TYPES[piece.type] || piece.type.to_s[0, 1]
97 name = piece.type.to_s.gsub(/^promoted_/, 'p') + ".svg"
98 File.join(BASE_DIR, name)