/*------------------------------------------------------------------------------
 src/lib/djWidget/icon.cxx
 
 Copyright (c) 2004-2006 Darby Johnston.
 All rights reserved.
 Use is subject to license terms.
------------------------------------------------------------------------------*/

#include "djIcon.h"
#include <djApp.h>
#include <FL/Fl_Pixmap.H>

#include "icon/left.xpm"
#include "icon/right.xpm"
#include "icon/up.xpm"
#include "icon/down.xpm"
#include "icon/reload.xpm"

#include "icon/file.xpm"
#include "icon/fileSeq.xpm"
#include "icon/dir.xpm"
#include "icon/fileOpen.xpm"
#include "icon/fileClose.xpm"

#include "icon/windowNew.xpm"
#include "icon/windowCopy.xpm"
#include "icon/windowClose.xpm"
#include "icon/windowFit.xpm"
#include "icon/windowFullscreen.xpm"

#include "icon/viewLeft.xpm"
#include "icon/viewRight.xpm"
#include "icon/viewUp.xpm"
#include "icon/viewDown.xpm"
#include "icon/viewZoomIn.xpm"
#include "icon/viewZoomOut.xpm"
#include "icon/viewZoomReset.xpm"
#include "icon/viewFit.xpm"

#include "icon/playbackStop.xpm"
#include "icon/playbackForward.xpm"
#include "icon/playbackReverse.xpm"
#include "icon/playbackFrameStart.xpm"
#include "icon/playbackFrameEnd.xpm"
#include "icon/playbackFramePrev.xpm"
#include "icon/playbackFrameNext.xpm"

#include "icon/toolMode.xpm"

#include "icon/shuttle0.xpm"
#include "icon/shuttle1.xpm"
#include "icon/shuttle2.xpm"
#include "icon/shuttle3.xpm"
#include "icon/shuttle4.xpm"
#include "icon/shuttle5.xpm"
#include "icon/shuttle6.xpm"
#include "icon/shuttle7.xpm"

#include "icon/toolStart.xpm"
#include "icon/toolEnd.xpm"
#include "icon/toolX.xpm"
#include "icon/toolLock.xpm"
#include "icon/toolInc.xpm"
#include "icon/toolDec.xpm"

namespace dj {

IconFactory::IconFactory() :
  _empty(0, 0, 0)
{
  add("left", new Fl_Pixmap((const char **)left_xpm));
  add("right", new Fl_Pixmap((const char **)right_xpm));
  add("up", new Fl_Pixmap((const char **)up_xpm));
  add("down", new Fl_Pixmap((const char **)down_xpm));
  add("reload", new Fl_Pixmap((const char **)reload_xpm));
  
  add("file", new Fl_Pixmap((const char **)file_xpm));
  add("fileSeq", new Fl_Pixmap((const char **)fileSeq_xpm));
  add("dir", new Fl_Pixmap((const char **)dir_xpm));
  add("fileOpen", new Fl_Pixmap((const char **)fileOpen_xpm));
  add("fileClose", new Fl_Pixmap((const char **)fileClose_xpm));
  
  add("windowNew", new Fl_Pixmap((const char **)windowNew_xpm));
  add("windowCopy", new Fl_Pixmap((const char **)windowCopy_xpm));
  add("windowClose", new Fl_Pixmap((const char **)windowClose_xpm));
  add("windowFit", new Fl_Pixmap((const char **)windowFit_xpm));
  add("windowFullscreen", new Fl_Pixmap((const char **)windowFullscreen_xpm));
  
  add("viewLeft", new Fl_Pixmap((const char **)viewLeft_xpm));
  add("viewRight", new Fl_Pixmap((const char **)viewRight_xpm));
  add("viewUp", new Fl_Pixmap((const char **)viewUp_xpm));
  add("viewDown", new Fl_Pixmap((const char **)viewDown_xpm));
  add("viewZoomIn", new Fl_Pixmap((const char **)viewZoomIn_xpm));
  add("viewZoomOut", new Fl_Pixmap((const char **)viewZoomOut_xpm));
  add("viewZoomReset", new Fl_Pixmap((const char **)viewZoomReset_xpm));
  add("viewFit", new Fl_Pixmap((const char **)viewFit_xpm));
  
  add("playbackStop", new Fl_Pixmap((const char **)playbackStop_xpm));
  add("playbackForward", new Fl_Pixmap((const char **)playbackForward_xpm));
  add("playbackReverse", new Fl_Pixmap((const char **)playbackReverse_xpm));
  add(
    "playbackFrameStart", new Fl_Pixmap((const char **)playbackFrameStart_xpm)
  );
  add("playbackFrameEnd", new Fl_Pixmap((const char **)playbackFrameEnd_xpm));
  add("playbackFramePrev", new Fl_Pixmap((const char **)playbackFramePrev_xpm));
  add("playbackFrameNext", new Fl_Pixmap((const char **)playbackFrameNext_xpm));
  
  add("toolMode", new Fl_Pixmap((const char **)toolMode_xpm));

  add("shuttle0", new Fl_Pixmap((const char **)shuttle0_xpm));
  add("shuttle1", new Fl_Pixmap((const char **)shuttle1_xpm));
  add("shuttle2", new Fl_Pixmap((const char **)shuttle2_xpm));
  add("shuttle3", new Fl_Pixmap((const char **)shuttle3_xpm));
  add("shuttle4", new Fl_Pixmap((const char **)shuttle4_xpm));
  add("shuttle5", new Fl_Pixmap((const char **)shuttle5_xpm));
  add("shuttle6", new Fl_Pixmap((const char **)shuttle6_xpm));
  add("shuttle7", new Fl_Pixmap((const char **)shuttle7_xpm));

  add("toolStart", new Fl_Pixmap((const char **)toolStart_xpm));
  add("toolEnd", new Fl_Pixmap((const char **)toolEnd_xpm));
  add("toolX", new Fl_Pixmap((const char **)toolX_xpm));
  add("toolLock", new Fl_Pixmap((const char **)toolLock_xpm));
  add("toolInc", new Fl_Pixmap((const char **)toolInc_xpm));
  add("toolDec", new Fl_Pixmap((const char **)toolDec_xpm));
}

IconFactory::~IconFactory()
{
  const List<Fl_Image *> valueList = _icons.valueList();
  for (ConstListIt<Fl_Image *> it = valueList; it.isValid(); ++it)
    delete it();
}

void IconFactory::add(const Str & name, Fl_Image * icon)
{
  _icons.set(name, icon);
}

Fl_Image * IconFactory::get(const Str & name) const
{
  return _icons.find(name) ? _icons[name] : const_cast<Fl_Image *>(&_empty);
}

Fl_Image * icon(const Str & name)
{
  return djApp->icon().get(name);
}

}
