
class GameEntry < IGSEntry

  attr_reader   :gameinfo

  def initialize(canvas,x1,y1, gameinfo, sizes, titles= nil, &cb)
    @gameinfo= gameinfo
    @sizes = sizes

    @number= gameinfo.nil? ? nil : gameinfo.number.to_s
     @items=[]
    # @rect=nil
    super(canvas,x1,y1, @number, sizes, titles)
    # @rect.bind ('ButtonPress-3', proc {|e| cb.call(e,gameinfo) } ) unless @rect.nil?
    if @rect
      $tk_cb['ge'+@rect.to_s]= cb
      $ip._eval("#{@canvas.path} bind #@rect <Button-3> {ruby {tk_callback( '#{'ge'+@rect}', %X, %Y)}}") 
    end 
  end

  def init
    unless  @gameinfo.nil?
      add_blank  5
      @items.push(add_text(  @number,  @sizes[0] - 5, '-fill blue'))
     #item.configure('fill' => 'blue')

    if  @gameinfo.free
        @items.push(add_bitmap( Defaults::ICONS['free']   ,  @sizes[1]))
    elsif @gameinfo.teach
      @items.push(add_bitmap( Defaults::ICONS['teach']   ,  @sizes[1]))
    elsif @gameinfo.tournament
      @items.push(add_bitmap( Defaults::ICONS['tournament']   ,  @sizes[1]))
    else
      @items.push(add_text( '' , @sizes[1]))
    end

    @items.push(add_text(  @gameinfo.w_player,  @sizes[2]))
    @items.push(add_text(  @gameinfo.w_rank  ,  @sizes[3]))
    @items.push(add_text(  @gameinfo.b_player,  @sizes[4]))
    @items.push(add_text(  @gameinfo.b_rank  ,  @sizes[5]))
    @items.push(add_text(  @gameinfo.move    ,  @sizes[6]))
    @items.push(add_text(  @gameinfo.size    ,  @sizes[7]))
    @items.push(add_text(  @gameinfo.handicap,  @sizes[8]))
    @items.push(add_text(  @gameinfo.komi    ,  @sizes[9]))
    @items.push(add_text(  @gameinfo.byo     ,  @sizes[10]))
    @items.push(add_text(  @gameinfo.observers  ,  @sizes[11]))


  end

end

def set_disabled (line)
  $ip._eval("#{@canvas.path} delete #@rect")
#  $ip._eval("#{@canvas.path} delete #{@items[1]}") if @items[1]
  for i in 7...@items.length
       #@items[i].configure('text'=>'') unless @items[i].nil?
 $ip._eval("#{@canvas.path} delete #{@items[i]}") if @items[i]
  end

      #@items[6].configure('text' => line, 'fill' => 'brown')
#debug "#{@canvas.path} itemconfigure #{@items[6]} -text {#{line}}"
      $ip._eval("#{@canvas.path} itemconfigure #{@items[6]} -text {#{line}} -fill brown")
  end

end
