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',
16 :keywords => %w(shogi)
18 def initialize(opts = {})
19 @squares = opts[:board_size] || opts[:game].size
20 @background = opts[:background] || 'kaya'
24 Qt::Image.painted(Qt::Point.new(size.x * @squares.x, size.y * @squares.y)) do |p|
26 bg = Qt::Image.new(File.join(BASE_DIR, @background + '.png'))
27 p.draw_tiled_pixmap(Qt::Rect.new(0, 0, size.x * @squares.x, size.y * @squares.y), bg.to_pix)
29 (0...@squares.x).each do |x|
30 (0...@squares.y).each do |y|
31 rect = Qt::RectF.new(size.x * x, size.y * y, size.x, size.y)
32 p.fill_rect(rect, Qt::Brush.new(BACKGROUND_COLOR))
38 pen.color = LINE_COLOR
40 (0..@squares.x).each do |x|
41 p.draw_line(x * size.x, 0, x * size.x, @squares.y * size.y)
43 (0..@squares.y).each do |y|
44 p.draw_line(0, y * size.y, size.x * @squares.x, y * size.y)
54 BASE_DIR = File.dirname(__FILE__)
55 TYPES = { :knight => 'n' }
56 NUDE_TILE = File.join(BASE_DIR, 'nude_tile.svg')
67 plugin :name => 'Shogi Pieces',
68 :interface => :pieces,
69 :keywords => %w(shogi)
71 def initialize(opts = {})
72 @loader = lambda do |piece, size|
73 tile = Qt::SvgRenderer.new(NUDE_TILE)
74 kanji = Qt::SvgRenderer.new(filename(piece))
75 ratio = RATIOS[piece.type] || 0.9
76 img = Qt::Image.painted(size) do |p|
78 p.translate(size * (1 - ratio) / 2)
79 if (piece.color == :white) ^ @flipped
87 if opts.has_key? :shadow
88 @loader = with_shadow(@loader)
93 def pixmap(piece, size)
94 @loader[piece, size].to_pix
98 color = piece.color.to_s[0, 1]
99 # type = TYPES[piece.type] || piece.type.to_s[0, 1]
100 name = piece.type.to_s.gsub(/^promoted_/, 'p') + ".svg"
101 File.join(BASE_DIR, name)