class IGSEntry

  attr_reader  :height #, :items


  def width
    @x2 - @x1
  end


  def initialize(canvas,x1,y1, name, sizes, titles= nil)

    @name= name
    @canvas=canvas
    @height= 16
    @x1=x1
    @y1=y1
    @x2=@x1
    @y2=@y1 +   @height

    if titles.nil?
      init
      @rect= $ip._eval("#{@canvas.path} create polygon #@x1 #@y1 #@x2 #@y1 #@x2 #@y2 #@x1 #@y2 #@x1 #@y1\
    -outline {} -fill {} -tags {entry #@name rect_outline}")
    else
      @name='title'
      for i in 0...sizes.length do
        add_text titles[i],sizes[i]
      end
    end

  end

  def init
  #defined in childs
  end

  def add_blank(length)
    @x2 += length
  end

  def add_bitmap (bmp,length,anchor='w')
    ret=$ip._eval("#{@canvas.path} create image #{@x2} #{@y1+@height/2} -anchor #{anchor} -tags {entry #@name #{@name+'_image'} } -image #{bmp.path}")
    @x2 += length
    ret
  end

  def add_text(t, length,opts='')
    text=t.to_s
# text.gsub!('\}','')
 # text.gsub!('\{','')
    ret=$ip._eval("#{@canvas.path} create text #@x2 #{@y1+@height/2-6} -text {#{text}} -anchor nw -tags {entry #@name #{@name+'_text'}} #{opts}")
    @x2 += length
    ret
  end

  def delete
    $ip._eval("#{@canvas.path} delete #{@name}")
  end


  def set_disabled

    $ip._eval("#{@canvas.path} delete #{@rect}")
    $ip._eval("#{@canvas.path} itemconfigure #{@name+'_text'} -fill gray")
    $ip._eval("#{@canvas.path} delete #{@name+'_image'}")
  end

  def move (dx,dy)
    $ip._eval("#{@canvas.path} move #@name #{dx} #{dy}")
  end

  def set_text(id,text)
    $ip._eval("#{@canvas.path} itemconfigure #{id} -text #{text}")
  end


end


