Widget = Object:extend()
DummyWidget = Widget:extend()

function Widget:new()
  self.destroyed = false
  self.selectable = false
  self.selection_margin = 0
  self.margin = 2
  self.label = ""
end

function Widget:selectAction()
  -- Do nothing
end

function DummyWidget:new()
  DummyWidget.super.new(self)
  self.r = love.math.random(128)
  self.g = love.math.random(128)
  self.b = love.math.random(128)
  self.selectable = true
  self.label = "DUMMY WIDGET (see modules.menus.widget)"
end

function DummyWidget:draw(x, y, w, h)
  x = x + self.margin
  y = y + self.margin
  w = w - self.margin * 2
  h = h - self.margin * 2

  love.graphics.setColor(self.r,self.g,self.b,70)
  love.graphics.rectangle("fill", x, y, w, h)
  love.graphics.setColor(self.r,self.g,self.b)
  love.graphics.rectangle("line", x, y, w, h)
end

function Widget:drawSelected(x,y,w,h)
    self:draw(x, y, w, h)
    x = x + self.selection_margin
    y = y + self.selection_margin
    w = w - self.selection_margin * 2
    h = h - self.selection_margin * 2

    love.graphics.setColor(0,0,0)
    love.graphics.rectangle("fill", x, y, 4, 8)
    love.graphics.rectangle("fill", x, y, 8, 4)

    love.graphics.rectangle("fill", x + w, y, -4, 8)
    love.graphics.rectangle("fill", x + w, y, -8, 4)

    love.graphics.rectangle("fill", x, y + h, 4, -8)
    love.graphics.rectangle("fill", x, y + h, 8, -4)

    love.graphics.rectangle("fill", x + w, y + h, -4, -8)
    love.graphics.rectangle("fill", x + w, y + h, -8, -4)

    love.graphics.setColor(255,255,255)
    love.graphics.rectangle("fill", x + 1, y + 1, 2, 6)
    love.graphics.rectangle("fill", x + 1, y + 1, 6, 2)

    love.graphics.rectangle("fill", x + w - 1, y + 1, -2, 6)
    love.graphics.rectangle("fill", x + w - 1, y + 1, -6, 2)

    love.graphics.rectangle("fill", x + 1, y + h - 1, 2, -6)
    love.graphics.rectangle("fill", x + 1, y + h - 1, 6, -2)

    love.graphics.rectangle("fill", x + w - 1, y + h - 1, -2, -6)
    love.graphics.rectangle("fill", x + w - 1, y + h - 1, -6, -2)

end

function Widget:draw(x, y, w, h)
end

function Widget:update(dt)
 -- N/A
end

function Widget:action()
  self:destroy()
end

function Widget:destroy()
  self.destroyed = true
end

function drawWidget_selected(x, y, w, h)
  love.graphics.setColor(0,0,0)
  love.graphics.rectangle("fill", x, y, 4, 8)
  love.graphics.rectangle("fill", x, y, 8, 4)

  love.graphics.rectangle("fill", x + w, y, -4, 8)
  love.graphics.rectangle("fill", x + w, y, -8, 4)

  love.graphics.rectangle("fill", x, y + h, 4, -8)
  love.graphics.rectangle("fill", x, y + h, 8, -4)

  love.graphics.rectangle("fill", x + w, y + h, -4, -8)
  love.graphics.rectangle("fill", x + w, y + h, -8, -4)

  love.graphics.setColor(255,255,255)
  love.graphics.rectangle("fill", x + 1, y + 1, 2, 6)
  love.graphics.rectangle("fill", x + 1, y + 1, 6, 2)

  love.graphics.rectangle("fill", x + w - 1, y + 1, -2, 6)
  love.graphics.rectangle("fill", x + w - 1, y + 1, -6, 2)

  love.graphics.rectangle("fill", x + 1, y + h - 1, 2, -6)
  love.graphics.rectangle("fill", x + 1, y + h - 1, 6, -2)

  love.graphics.rectangle("fill", x + w - 1, y + h - 1, -2, -6)
  love.graphics.rectangle("fill", x + w - 1, y + h - 1, -6, -2)

end
