Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "thumbnail.h"
Toshihiro Shimizu 890ddd
#include "tstream.h"
Toshihiro Shimizu 890ddd
#include "tvectorrenderdata.h"
Toshihiro Shimizu 890ddd
#include "tvectorimage.h"
Toshihiro Shimizu 890ddd
#include "tlevel_io.h"
Toshihiro Shimizu 890ddd
#include "tpalette.h"
Toshihiro Shimizu 890ddd
#include "tsystem.h"
Toshihiro Shimizu 890ddd
#include "tsound_io.h"
Toshihiro Shimizu 890ddd
#include "trop.h"
Toshihiro Shimizu 890ddd
#include "tw/mainshell.h"
Toshihiro Shimizu 890ddd
//#include "zapplication.h"
Toshihiro Shimizu 890ddd
#include "tw/dragdrop.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tw/message.h"
Toshihiro Shimizu 890ddd
#include "pixmapFiletype.h"
Toshihiro Shimizu 890ddd
#include "tofflinegl.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//============================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// Thumbnail
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//============================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Thumbnail::Thumbnail(const TDimension &size)
Shinya Kitaoka 120a6e
    : m_currentFrameIndex(0)
Shinya Kitaoka 120a6e
    , m_iconLoaded(false)
Shinya Kitaoka 120a6e
    , m_playing(false)
Shinya Kitaoka 120a6e
    , m_size(size)
Shinya Kitaoka 120a6e
    , m_raster() {
Shinya Kitaoka 120a6e
  m_raster = TRaster32P(m_size);
Shinya Kitaoka 120a6e
  m_raster->fill(TPixel32(100, 100, 100));
Shinya Kitaoka 120a6e
  m_raster->extractT(m_raster->getBounds().enlarge(-20))
Shinya Kitaoka 120a6e
      ->fill(TPixel32(80, 90, 100));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
Thumbnail::~Thumbnail() { clearPointerContainer(m_frames); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Thumbnail::addFrame(const TFrameId &fid) {
Shinya Kitaoka 120a6e
  m_frames.push_back(new Frame(fid));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool Thumbnail::gotoFrame(int index) {
Shinya Kitaoka 120a6e
  assert(m_playing);
Shinya Kitaoka 120a6e
  if (m_currentFrameIndex == index) return true;
Shinya Kitaoka 120a6e
  if (index < 0 || index >= (int)m_frames.size()) return false;
Shinya Kitaoka 120a6e
  m_currentFrameIndex = index;
Shinya Kitaoka 120a6e
  m_raster            = TRaster32P();
Shinya Kitaoka 120a6e
  if (!m_frames[index]->m_raster) loadFrame(index);
Shinya Kitaoka 120a6e
  m_raster = m_frames[index]->m_raster;
Shinya Kitaoka 120a6e
  return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TAffine Thumbnail::getAffine(const TDimension &cameraSize) const {
Shinya Kitaoka 120a6e
  double scx = 1 * m_size.lx / (double)cameraSize.lx;
Shinya Kitaoka 120a6e
  double scy = 1 * m_size.ly / (double)cameraSize.ly;
Shinya Kitaoka 120a6e
  double sc  = tmin(scx, scy);
Shinya Kitaoka 120a6e
  double dx  = (m_size.lx - cameraSize.lx * sc) * 0.5;
Shinya Kitaoka 120a6e
  double dy  = (m_size.ly - cameraSize.ly * sc) * 0.5;
Shinya Kitaoka 120a6e
  return TScale(sc) * TTranslation(0.5 * TPointD(cameraSize.lx, cameraSize.ly) +
Shinya Kitaoka 120a6e
                                   TPointD(dx, dy));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//============================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// Pli Thumbnail
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//============================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class PliThumbnail : public FileThumbnail {
Shinya Kitaoka 120a6e
  TLevelReaderP m_lr;
Shinya Kitaoka 120a6e
  TPaletteP m_palette;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  PliThumbnail(const TDimension &size, const TFilePath &fp);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void loadIcon();
Shinya Kitaoka 120a6e
  void loadFrame(int index);
Shinya Kitaoka 120a6e
  void setPlaying(bool on);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  Type getType() const { return LEVEL; };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  // not implemented
Shinya Kitaoka 120a6e
  PliThumbnail(const PliThumbnail &);
Shinya Kitaoka 120a6e
  PliThumbnail &operator=(const PliThumbnail &);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//============================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
PliThumbnail::PliThumbnail(const TDimension &size, const TFilePath &fp)
Shinya Kitaoka 120a6e
    : FileThumbnail(size, fp), m_lr() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PliThumbnail::loadIcon() {
Shinya Kitaoka 120a6e
  clearPointerContainer(m_frames);
Shinya Kitaoka 120a6e
  m_lr          = TLevelReaderP(m_filepath);
Shinya Kitaoka 120a6e
  TLevelP level = m_lr->loadInfo();
Shinya Kitaoka 120a6e
  m_palette     = level->getPalette();
Shinya Kitaoka 120a6e
  for (TLevel::Iterator it = level->begin(); it != level->end(); ++it)
Shinya Kitaoka 120a6e
    addFrame(it->first);
Shinya Kitaoka 120a6e
  loadFrame(0);
Shinya Kitaoka 120a6e
  m_lr         = TLevelReaderP();
Shinya Kitaoka 120a6e
  m_raster     = m_frames[0]->m_raster;
Shinya Kitaoka 120a6e
  m_iconLoaded = true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
void doRender(const TVectorImageP &vi, const TVectorRenderData &rd,
Shinya Kitaoka 120a6e
              const TRaster32P &ras) {
Shinya Kitaoka 120a6e
  TOfflineGL *glContext = TOfflineGL::getStock(ras->getSize());
Shinya Kitaoka 120a6e
  glContext->getRaster()->copy(ras);
Shinya Kitaoka 120a6e
  glContext->draw(vi, rd);
Shinya Kitaoka 120a6e
  ras->copy(glContext->getRaster());
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
void PliThumbnail::loadFrame(int index) {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < (int)m_frames.size());
Shinya Kitaoka 120a6e
  if (!m_lr) {
Shinya Kitaoka 120a6e
    assert(m_playing);
Shinya Kitaoka 120a6e
    m_lr = TLevelReaderP(m_filepath);
Shinya Kitaoka 120a6e
    m_lr->loadInfo();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  TVectorImageP vi   = m_lr->getFrameReader(m_frames[index]->m_fid)->load();
Shinya Kitaoka 120a6e
  TRaster32P &raster = m_frames[index]->m_raster;
Shinya Kitaoka 120a6e
  raster             = TRaster32P(m_size);
Shinya Kitaoka 120a6e
  if (vi) {
Shinya Kitaoka 120a6e
    raster->fill(TPixel32::White);
Shinya Kitaoka 120a6e
    TDimension cameraSize(640, 480);
Shinya Kitaoka 120a6e
    const TVectorRenderData rd(getAffine(cameraSize),
Shinya Kitaoka 120a6e
                               TRect(),  // raster->getBounds(),
Shinya Kitaoka 120a6e
                               m_palette.getPointer(), 0);
Shinya Kitaoka 120a6e
    // vi->render(rd,raster);
Shinya Kitaoka 120a6e
    doRender(vi, rd, raster);
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    raster->fill(TPixel32(255, 0, 0));
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void PliThumbnail::setPlaying(bool on) {
Shinya Kitaoka 120a6e
  if (m_playing == on) return;
Shinya Kitaoka 120a6e
  m_playing = on;
Shinya Kitaoka 120a6e
  if (!m_playing) {
Shinya Kitaoka 120a6e
    m_lr      = TLevelReaderP();
Shinya Kitaoka 120a6e
    m_palette = TPaletteP();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//============================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// Raster Thumbnail
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//============================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class RasterThumbnail : public FileThumbnail {
Shinya Kitaoka 120a6e
  TLevelReaderP m_lr;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  RasterThumbnail(const TDimension &size, const TFilePath &fp);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void loadIcon();
Shinya Kitaoka 120a6e
  void loadFrame(int index);
Shinya Kitaoka 120a6e
  void setPlaying(bool on);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  Type getType() const { return LEVEL; };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  // not implemented
Shinya Kitaoka 120a6e
  RasterThumbnail(const RasterThumbnail &);
Shinya Kitaoka 120a6e
  RasterThumbnail &operator=(const RasterThumbnail &);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//============================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
RasterThumbnail::RasterThumbnail(const TDimension &size, const TFilePath &fp)
Shinya Kitaoka 120a6e
    : FileThumbnail(size, fp), m_lr() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void RasterThumbnail::loadIcon() {
Shinya Kitaoka 120a6e
  clearPointerContainer(m_frames);
Shinya Kitaoka 120a6e
  m_lr = TLevelReaderP(m_filepath);
Shinya Kitaoka 120a6e
  try {
Shinya Kitaoka 120a6e
    TLevelP level = m_lr->loadInfo();
Shinya Kitaoka 120a6e
    if (level && level->getFrameCount() != 0) {
Shinya Kitaoka 120a6e
      for (TLevel::Iterator it = level->begin(); it != level->end(); ++it)
Shinya Kitaoka 120a6e
        addFrame(it->first);
Shinya Kitaoka 120a6e
      loadFrame(0);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      m_raster = m_frames[0]->m_raster;
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      m_raster = TRaster32P(m_size);
Shinya Kitaoka 120a6e
      m_raster->fill(TPixel32::Red);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  } catch (TException &e) {
Shinya Kitaoka 120a6e
    TMessage::error(toString(e.getMessage()));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    m_raster = TRaster32P(m_size);
Shinya Kitaoka 120a6e
    m_raster->fill(TPixel32::Red);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_lr         = TLevelReaderP();
Shinya Kitaoka 120a6e
  m_iconLoaded = true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void RasterThumbnail::loadFrame(int index) {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < (int)m_frames.size());
Shinya Kitaoka 120a6e
  if (!m_lr) {
Shinya Kitaoka 120a6e
    assert(m_playing);
Shinya Kitaoka 120a6e
    m_lr = TLevelReaderP(m_filepath);
Shinya Kitaoka 120a6e
    m_lr->loadInfo();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  TRasterImageP ri   = m_lr->getFrameReader(m_frames[index]->m_fid)->load();
Shinya Kitaoka 120a6e
  TRaster32P &raster = m_frames[index]->m_raster;
Shinya Kitaoka 120a6e
  raster             = TRaster32P(m_size);
Shinya Kitaoka 120a6e
  TRaster32P inputRaster;
Shinya Kitaoka 120a6e
  if (ri) inputRaster = ri->getRaster();
Shinya Kitaoka 120a6e
  if (inputRaster) {
Shinya Kitaoka 120a6e
    raster->fill(TPixel32::White);
Shinya Kitaoka 120a6e
    double sx = (double)(raster->getLx()) / (double)(inputRaster->getLx());
Shinya Kitaoka 120a6e
    double sy = (double)(raster->getLy()) / (double)(inputRaster->getLy());
Shinya Kitaoka 120a6e
    double sc = tmin(sx, sy);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TAffine aff =
Shinya Kitaoka 120a6e
        TScale(sc).place(inputRaster->getCenterD(), raster->getCenterD());
Shinya Kitaoka 120a6e
    TRop::resample(raster, inputRaster, aff);
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    raster->fill(TPixel32(255, 0, 0));
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void RasterThumbnail::setPlaying(bool on) {
Shinya Kitaoka 120a6e
  if (m_playing == on) return;
Shinya Kitaoka 120a6e
  m_playing = on;
Shinya Kitaoka 120a6e
  if (!m_playing) {
Shinya Kitaoka 120a6e
    m_lr = TLevelReaderP();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//============================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// Soundtrack Thumbnail
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//============================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class SoundtrackThumbnail : public FileThumbnail {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  SoundtrackThumbnail(const TDimension &size, const TFilePath &fp);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void loadIcon();
Shinya Kitaoka 120a6e
  void loadFrame(int index);
Shinya Kitaoka 120a6e
  void setPlaying(bool on);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  Type getType() const { return LEVEL; };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  // not implemented
Shinya Kitaoka 120a6e
  SoundtrackThumbnail(const SoundtrackThumbnail &);
Shinya Kitaoka 120a6e
  SoundtrackThumbnail &operator=(const SoundtrackThumbnail &);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//============================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
SoundtrackThumbnail::SoundtrackThumbnail(const TDimension &size,
Shinya Kitaoka 120a6e
                                         const TFilePath &fp)
Shinya Kitaoka 120a6e
    : FileThumbnail(size, fp) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SoundtrackThumbnail::loadIcon() { m_iconLoaded = true; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SoundtrackThumbnail::loadFrame(int index) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SoundtrackThumbnail::setPlaying(bool on) {
Shinya Kitaoka 120a6e
  if (m_playing == on) return;
Shinya Kitaoka 120a6e
  m_playing = on;
Shinya Kitaoka 120a6e
  /*
Shinya Kitaoka 120a6e
if(!m_playing)
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 120a6e
m_lr = TLevelReaderP();
Shinya Kitaoka 120a6e
}
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//============================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// Casm Thumbnail
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//============================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class CasmThumbnail : public FileThumbnail {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  CasmThumbnail(const TDimension &size, const TFilePath &fp);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void loadIcon();
Shinya Kitaoka 120a6e
  void loadFrame(int index);
Shinya Kitaoka 120a6e
  void setPlaying(bool on);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  Type getType() const { return LEVEL; };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  // not implemented
Shinya Kitaoka 120a6e
  CasmThumbnail(const CasmThumbnail &);
Shinya Kitaoka 120a6e
  CasmThumbnail &operator=(const CasmThumbnail &);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//============================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
CasmThumbnail::CasmThumbnail(const TDimension &size, const TFilePath &fp)
Shinya Kitaoka 120a6e
    : FileThumbnail(size, fp) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void CasmThumbnail::loadIcon() {
Shinya Kitaoka 120a6e
  m_iconLoaded    = true;
Shinya Kitaoka 120a6e
  TRaster32P icon = casm_browser_icon;
Shinya Kitaoka 120a6e
  if (!icon) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  double sx = (double)(m_raster->getLx()) / (double)(icon->getLx());
Shinya Kitaoka 120a6e
  double sy = (double)(m_raster->getLy()) / (double)(icon->getLy());
Shinya Kitaoka 120a6e
  double sc = tmax(sx, sy);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TAffine aff = TScale(sc).place(icon->getCenterD(), m_raster->getCenterD());
Shinya Kitaoka 120a6e
  TRop::resample(m_raster, icon, aff);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void CasmThumbnail::loadFrame(int index) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void CasmThumbnail::setPlaying(bool on) {
Shinya Kitaoka 120a6e
  if (m_playing == on) return;
Shinya Kitaoka 120a6e
  m_playing = on;
Shinya Kitaoka 120a6e
  /*
Shinya Kitaoka 120a6e
if(!m_playing)
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 120a6e
m_lr = TLevelReaderP();
Shinya Kitaoka 120a6e
}
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//============================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// Setup file Thumbnail
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//============================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class SetupThumbnail : public FileThumbnail {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  SetupThumbnail(const TDimension &size, const TFilePath &fp);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void loadIcon();
Shinya Kitaoka 120a6e
  void loadFrame(int index);
Shinya Kitaoka 120a6e
  void setPlaying(bool on);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  Type getType() const { return LEVEL; };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  // not implemented
Shinya Kitaoka 120a6e
  SetupThumbnail(const SetupThumbnail &);
Shinya Kitaoka 120a6e
  SetupThumbnail &operator=(const SetupThumbnail &);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//============================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
SetupThumbnail::SetupThumbnail(const TDimension &size, const TFilePath &fp)
Shinya Kitaoka 120a6e
    : FileThumbnail(size, fp) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SetupThumbnail::loadIcon() {
Shinya Kitaoka 120a6e
  m_iconLoaded    = true;
Shinya Kitaoka 120a6e
  TRaster32P icon = setup_browser_icon;
Shinya Kitaoka 120a6e
  if (!icon) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  double sx = (double)(m_raster->getLx()) / (double)(icon->getLx());
Shinya Kitaoka 120a6e
  double sy = (double)(m_raster->getLy()) / (double)(icon->getLy());
Shinya Kitaoka 120a6e
  double sc = tmax(sx, sy);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TAffine aff = TScale(sc).place(icon->getCenterD(), m_raster->getCenterD());
Shinya Kitaoka 120a6e
  TRop::resample(m_raster, icon, aff);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SetupThumbnail::loadFrame(int index) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SetupThumbnail::setPlaying(bool on) {
Shinya Kitaoka 120a6e
  if (m_playing == on) return;
Shinya Kitaoka 120a6e
  m_playing = on;
Shinya Kitaoka 120a6e
  /*
Shinya Kitaoka 120a6e
if(!m_playing)
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 120a6e
m_lr = TLevelReaderP();
Shinya Kitaoka 120a6e
}
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//============================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// Txt Thumbnail
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//============================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class TxtThumbnail : public FileThumbnail {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TxtThumbnail(const TDimension &size, const TFilePath &fp);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void loadIcon();
Shinya Kitaoka 120a6e
  void loadFrame(int index);
Shinya Kitaoka 120a6e
  void setPlaying(bool on);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  Type getType() const { return LEVEL; };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  // not implemented
Shinya Kitaoka 120a6e
  TxtThumbnail(const TxtThumbnail &);
Shinya Kitaoka 120a6e
  TxtThumbnail &operator=(const TxtThumbnail &);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//============================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TxtThumbnail::TxtThumbnail(const TDimension &size, const TFilePath &fp)
Shinya Kitaoka 120a6e
    : FileThumbnail(size, fp) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TxtThumbnail::loadIcon() { m_iconLoaded = true; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TxtThumbnail::loadFrame(int index) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TxtThumbnail::setPlaying(bool on) {
Shinya Kitaoka 120a6e
  if (m_playing == on) return;
Shinya Kitaoka 120a6e
  m_playing = on;
Shinya Kitaoka 120a6e
  /*
Shinya Kitaoka 120a6e
if(!m_playing)
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 120a6e
m_lr = TLevelReaderP();
Shinya Kitaoka 120a6e
}
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//============================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// Script Thumbnail
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//============================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class ScriptThumbnail : public FileThumbnail {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  ScriptThumbnail(const TDimension &size, const TFilePath &fp);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void loadIcon();
Shinya Kitaoka 120a6e
  void loadFrame(int index);
Shinya Kitaoka 120a6e
  void setPlaying(bool on);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  Type getType() const { return LEVEL; };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  // not implemented
Shinya Kitaoka 120a6e
  ScriptThumbnail(const ScriptThumbnail &);
Shinya Kitaoka 120a6e
  ScriptThumbnail &operator=(const ScriptThumbnail &);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//============================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ScriptThumbnail::ScriptThumbnail(const TDimension &size, const TFilePath &fp)
Shinya Kitaoka 120a6e
    : FileThumbnail(size, fp) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ScriptThumbnail::loadIcon() {
Shinya Kitaoka 120a6e
  m_iconLoaded    = true;
Shinya Kitaoka 120a6e
  TRaster32P icon = script_browser_icon;
Shinya Kitaoka 120a6e
  if (!icon) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  double sx = (double)(m_raster->getLx()) / (double)(icon->getLx());
Shinya Kitaoka 120a6e
  double sy = (double)(m_raster->getLy()) / (double)(icon->getLy());
Shinya Kitaoka 120a6e
  double sc = tmax(sx, sy);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TAffine aff = TScale(sc).place(icon->getCenterD(), m_raster->getCenterD());
Shinya Kitaoka 120a6e
  TRop::resample(m_raster, icon, aff);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ScriptThumbnail::loadFrame(int index) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ScriptThumbnail::setPlaying(bool on) {
Shinya Kitaoka 120a6e
  if (m_playing == on) return;
Shinya Kitaoka 120a6e
  m_playing = on;
Shinya Kitaoka 120a6e
  /*
Shinya Kitaoka 120a6e
if(!m_playing)
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 120a6e
m_lr = TLevelReaderP();
Shinya Kitaoka 120a6e
}
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//============================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// Scene Thumbnail
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//============================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class ZSceneThumbnail : public FileThumbnail {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  ZSceneThumbnail(const TDimension &size, const TFilePath &fp);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void loadIcon();
Shinya Kitaoka 120a6e
  void loadFrame(int index);
Shinya Kitaoka 120a6e
  void setPlaying(bool on);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void setName(string name);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  Type getType() const { return SCENE; };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  // not implemented
Shinya Kitaoka 120a6e
  ZSceneThumbnail(const ZSceneThumbnail &);
Shinya Kitaoka 120a6e
  ZSceneThumbnail &operator=(const ZSceneThumbnail &);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//============================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ZSceneThumbnail::ZSceneThumbnail(const TDimension &size, const TFilePath &fp)
Shinya Kitaoka 120a6e
    : FileThumbnail(size, fp) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ZSceneThumbnail::loadIcon() {
Shinya Kitaoka 120a6e
  m_iconLoaded = true;
Shinya Kitaoka 120a6e
  clearPointerContainer(m_frames);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  string name        = m_filepath.getName();
Shinya Kitaoka 120a6e
  TFilePath dir      = m_filepath.getParentDir();
Shinya Kitaoka 120a6e
  TFilePath iconPath = dir + TFilePath(name + "_files") + "icon.bmp";
Shinya Kitaoka 120a6e
  if (!TFileStatus(iconPath).isReadable()) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TRasterP ras;
Shinya Kitaoka 120a6e
  TImageReader::load(iconPath, ras);
Shinya Kitaoka 120a6e
  TRaster32P icon = ras;
Shinya Kitaoka 120a6e
  if (!icon) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  double sx = (double)(m_raster->getLx()) / (double)(icon->getLx());
Shinya Kitaoka 120a6e
  double sy = (double)(m_raster->getLy()) / (double)(icon->getLy());
Shinya Kitaoka 120a6e
  double sc = tmax(sx, sy);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TAffine aff = TScale(sc).place(icon->getCenterD(), m_raster->getCenterD());
Shinya Kitaoka 120a6e
  TRop::resample(m_raster, icon, aff);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ZSceneThumbnail::loadFrame(int index) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ZSceneThumbnail::setPlaying(bool on) {
Shinya Kitaoka 120a6e
  if (m_playing == on) return;
Shinya Kitaoka 120a6e
  m_playing = on;
Shinya Kitaoka 120a6e
  /*
Shinya Kitaoka 120a6e
if(on)
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 120a6e
if(m_frames.empty()) loadXsheet();
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
else
Shinya Kitaoka 120a6e
{
Shinya Kitaoka 120a6e
m_xsh = TXsheetP();
Shinya Kitaoka 120a6e
m_palette = TPaletteP();
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
*/
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ZSceneThumbnail::setName(string name) {
Shinya Kitaoka 120a6e
  assert(!m_playing);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TFilePath oldPath = m_filepath;
Shinya Kitaoka 120a6e
  TFilePath newPath = m_filepath.withName(name);
Shinya Kitaoka 120a6e
  if (oldPath == newPath) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  string oldName          = m_filepath.getName();
Shinya Kitaoka 120a6e
  TFilePath oldRepository = oldPath.getParentDir() + (oldName + "_files");
Shinya Kitaoka 120a6e
  TFilePath newRepository = newPath.getParentDir() + (name + "_files");
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TSystem::renameFile(newPath, oldPath);
Shinya Kitaoka 120a6e
  TSystem::renameFile(newRepository, oldRepository);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_filepath = newPath;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//============================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// File Thumbnail
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//============================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FileThumbnail::FileThumbnail(const TDimension &size, const TFilePath &path)
Shinya Kitaoka 120a6e
    : Thumbnail(size), m_filepath(path) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void FileThumbnail::setName(string name) {
Shinya Kitaoka 120a6e
  assert(!m_playing);
Shinya Kitaoka 120a6e
  TFilePath fp = m_filepath.withName(name);
Shinya Kitaoka 120a6e
  if (fp != m_filepath) {
Shinya Kitaoka 120a6e
    TSystem::renameFile(fp, m_filepath);
Shinya Kitaoka 120a6e
    m_filepath = fp;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
FileThumbnail *FileThumbnail::create(const TDimension &size,
Shinya Kitaoka 120a6e
                                     const TFilePath &path) {
Shinya Kitaoka 120a6e
  vector<string> fileTypes;</string>
Shinya Kitaoka 120a6e
  vector<string> soundTypes;</string>
Shinya Kitaoka 120a6e
  TImageReader::getSupportedFormats(fileTypes);
Shinya Kitaoka 120a6e
  TLevelReader::getSupportedFormats(fileTypes);
Shinya Kitaoka 120a6e
  TSoundTrackReader::getSupportedFormats(soundTypes);
Shinya Kitaoka 120a6e
  string type = path.getType();
Shinya Kitaoka 120a6e
  if (type == "pli") return new PliThumbnail(size, path);
Shinya Kitaoka 120a6e
  if (type == "casm") return new CasmThumbnail(size, path);
Shinya Kitaoka 120a6e
  if (type == "setup") return new SetupThumbnail(size, path);
Shinya Kitaoka 120a6e
  if (type == "txt") return new TxtThumbnail(size, path);
Shinya Kitaoka 120a6e
  if (type == "bat" || type == "sh" || type == "csh" || type == "tcsh")
Shinya Kitaoka 120a6e
    return new ScriptThumbnail(size, path);
Shinya Kitaoka 120a6e
  /*
Shinya Kitaoka 120a6e
else if (type == ZComp::getApplication()->getSceneFileExt())
Shinya Kitaoka 120a6e
return new ZSceneThumbnail(size,path);
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
  else if (std::find(soundTypes.begin(), soundTypes.end(), type) !=
Shinya Kitaoka 120a6e
           soundTypes.end())
Shinya Kitaoka 120a6e
    return new SoundtrackThumbnail(size, path);
Shinya Kitaoka 120a6e
  else if (std::find(fileTypes.begin(), fileTypes.end(), type) !=
Shinya Kitaoka 120a6e
           fileTypes.end())
Shinya Kitaoka 120a6e
    return new RasterThumbnail(size, path);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    return 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool FileThumbnail::startDragDrop() {
Shinya Kitaoka 120a6e
  TDropSource dropSource;
Shinya Kitaoka 120a6e
  std::vector<std::string> v;</std::string>
Shinya Kitaoka 120a6e
  v.push_back(toString(m_filepath.getWideString()));
Shinya Kitaoka 120a6e
  TDataObject data(v);
Shinya Kitaoka 120a6e
  dropSource.doDragDrop(data);
Shinya Kitaoka 120a6e
  return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------