#===============================================================================
#
#===============================================================================
class AnimationEditor::MenuBar < UIControls::ControlsContainer
  MENU_BUTTON_WIDTH = 80
  NAME_BUTTON_WIDTH = 400   # The animation's name

  def initialize(x, y, width, height, viewport)
    super(x, y, width, height)
    @viewport.z = viewport.z + 10   # So that it appears over the canvas
  end

  #-----------------------------------------------------------------------------

  def add_button(id, button_text)
    ctrl = UIControls::Button.new(MENU_BUTTON_WIDTH, @height, @viewport, button_text)
    ctrl.set_fixed_size
    add_control(id, ctrl)
  end

  def add_name_button(id, button_text)
    ctrl = UIControls::Button.new(NAME_BUTTON_WIDTH, @height, @viewport, button_text)
    ctrl.set_fixed_size
    add_control(id, ctrl)
  end

  def anim_name=(val)
    ctrl = get_control(:name)
    ctrl.set_text(val) if ctrl
  end

  #-----------------------------------------------------------------------------

  private

  def add_control(id, control, add_offset = false)
    i = @controls.length
    control_x = (add_offset ? @row_count - 1 : @row_count) * MENU_BUTTON_WIDTH
    control_x = @width - control.width if control.width == NAME_BUTTON_WIDTH
    control_y = 0
    control.x = control_x + (add_offset ? OFFSET_FROM_LABEL_X : 0)
    control.y = control_y + (add_offset ? OFFSET_FROM_LABEL_Y : 0)
    control.set_interactive_rects
    @controls[i] = [id, control]
    @row_count += 1 if !add_offset
    repaint
  end
end
