-------------------------------------------------------------------------------
--                                                                           --
-- D2K: A Doom Source Port for the 21st Century                              --
--                                                                           --
-- Copyright (C) 2014: See COPYRIGHT file                                    --
--                                                                           --
-- This file is part of D2K.                                                 --
--                                                                           --
-- D2K is free software: you can redistribute it and/or modify it under the  --
-- terms of the GNU General Public License as published by the Free Software --
-- Foundation, either version 2 of the License, or (at your option) any      --
-- later version.                                                            --
--                                                                           --
-- D2K is distributed in the hope that it will be useful, but WITHOUT ANY    --
-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS --
-- FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more    --
-- details.                                                                  --
--                                                                           --
-- You should have received a copy of the GNU General Public License along   --
-- with D2K.  If not, see <http://www.gnu.org/licenses/>.                    --
--                                                                           --
-------------------------------------------------------------------------------

local class = require('middleclass')
local lgi = require('lgi')
local Cairo = lgi.cairo
local Fonts = require('fonts')

local InputInterface = require('input_interface')
local InputInterfaceContainer = require('input_interface_container')

HUD = class('HUD', InputInterface.InputInterface)
HUD:include(InputInterfaceContainer.InputInterfaceContainer)

function HUD:initialize(h)
  h = h or {}

  h.name = h.name or 'HUD'

  InputInterface.InputInterface.initialize(self, h)

  self.interfaces = {}

  self:set_font_description_text(
    h.font_description_text or Fonts.DEFAULT_HUD_FONT
  )

  self:set_pixel_width(d2k.overlay:get_width())
  self:set_pixel_height(d2k.overlay:get_height())
end

function HUD:get_x()
  return 0
end

function HUD:get_y()
  return 0
end

function HUD:get_font_description_text()
  return self.font_description_text
end

function HUD:set_font_description_text(font_description_text)
  local fallback_fonts = Fonts.DEFAULT_UNICODE_FALLBACK_FONTS

  if #font_description_text <= 0 then
    font_description_text = Fonts.DEFAULT_FONT
  end

  self.font_description_text = font_description_text .. ',' .. fallback_fonts

  self:handle_display_change()
end

function HUD:sort_interfaces()
  table.sort(self.interfaces, function(i1, i2)
    return i1:get_z_index() < i2:get_z_index()
  end)
end

return {HUD = HUD}

-- vi: et ts=2 sw=2

