-- | Construct a new invisible GTK unit from a Unit (but do not attach to a layout yet)
newFromUnit :: FilePath -> Color -> Unit -> IO GTKUnit
newFromUnit iconsdir color unit@(Unit long lat name typ size rcp i) = do
  let imagex = round long
  let imagey = round lat
  let iconf = iconsdir ++ "/" ++ (pickUnitIconFileName color typ size)

  -- construct both the image and its EventBox container (used to handle click events)
  image <- Gtk.imageNewFromFile iconf
  evbox <- Gtk.eventBoxNew
  _ <- Gtk.containerAdd evbox image

--  liftIO $ putInfo $ "newFromUnit: new GTK unit: unit " ++ show unit ++ ", icon " ++ iconf
  return $ GTKUnit i evbox image imagex imagey False


-- | Select the unit's correct icon filename
newFromUnit :: FilePath -> Color -> Unit -> IO GTKUnit
newFromUnit iconsdir color unit@(Unit long lat name typ size rcp i) = do
  let imagex = round long
  let imagey = round lat
  let iconf = iconsdir ++ "/" ++ (pickUnitIconFileName color typ size)

  -- construct both the image and its EventBox container (used to handle click events)
  image <- Gtk.imageNewFromFile iconf
  evbox <- Gtk.eventBoxNew
  _ <- Gtk.containerAdd evbox image

--  liftIO $ putInfo $ "newFromUnit: new GTK unit: unit " ++ show unit ++ ", icon " ++ iconf
  return $ GTKUnit i evbox image imagex imagey False


-- | Select the unit's correct icon filename
newFromUnit iconsdir color unit@(Unit long lat name typ size rcp i) = do
  let imagex = round long
  let imagey = round lat
  let iconf = iconsdir ++ "/" ++ (pickUnitIconFileName color typ size)

  -- construct both the image and its EventBox container (used to handle click events)
  image <- Gtk.imageNewFromFile iconf
  evbox <- Gtk.eventBoxNew
  _ <- Gtk.containerAdd evbox image

--  liftIO $ putInfo $ "newFromUnit: new GTK unit: unit " ++ show unit ++ ", icon " ++ iconf
  return $ GTKUnit i evbox image imagex imagey False


-- | Select the unit's correct icon filename