Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonz/fullcolorpalette.h"
Toshihiro Shimizu 890ddd
#include "toonz/tscenehandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/toonzscene.h"
Toshihiro Shimizu 890ddd
#include "tsystem.h"
Toshihiro Shimizu 890ddd
#include "tstream.h"
Toshihiro Shimizu 890ddd
#include "tpalette.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==================================================
Toshihiro Shimizu 890ddd
//
Shinya Kitaoka 120a6e
// FullColorPalette
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//==================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FullColorPalette::FullColorPalette()
Shinya Kitaoka 120a6e
    : m_fullcolorPalettePath("+palettes\\Raster_Drawing_Palette.tpl")
Shinya Kitaoka 120a6e
    , m_palette(0) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
FullColorPalette *FullColorPalette::instance() {
Shinya Kitaoka 120a6e
  static FullColorPalette _instance;
Shinya Kitaoka 120a6e
  return &_instance;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
FullColorPalette::~FullColorPalette() { clear(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FullColorPalette::clear() {
Shinya Kitaoka 120a6e
  if (m_palette) m_palette->release();
Shinya Kitaoka 120a6e
  m_palette = 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TPalette *FullColorPalette::getPalette(ToonzScene *scene) {
Shinya Kitaoka 120a6e
  if (m_palette) return m_palette;
Shinya Kitaoka 120a6e
  m_palette = new TPalette();
Shinya Kitaoka 120a6e
  m_palette->addRef();
Shinya Kitaoka 120a6e
  TFilePath fullPath = scene->decodeFilePath(m_fullcolorPalettePath);
Shinya Kitaoka 120a6e
  if (!TSystem::doesExistFileOrLevel(fullPath)) {
Shinya Kitaoka 120a6e
    // Per I francesi che hanno il nome vecchio della paletta
Shinya Kitaoka 120a6e
    // Verra' caricata la vecchia ma salvata col nome nuovo!
Shinya Kitaoka 120a6e
    TFilePath app("+palettes\\fullcolorPalette.tpl");
Shinya Kitaoka 120a6e
    fullPath = scene->decodeFilePath(app);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (TSystem::doesExistFileOrLevel(fullPath)) {
Shinya Kitaoka 120a6e
    TPalette *app = new TPalette();
Shinya Kitaoka 120a6e
    TIStream is(fullPath);
Shinya Kitaoka 120a6e
    is >> app;
Shinya Kitaoka 120a6e
    m_palette->assign(app);
Shinya Kitaoka 120a6e
    delete app;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  m_palette->setPaletteName(L"Raster Drawing Palette");
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return m_palette;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FullColorPalette::savePalette(ToonzScene *scene) {
Shinya Kitaoka 120a6e
  if (!m_palette || !m_palette->getDirtyFlag()) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TFilePath fullPath = scene->decodeFilePath(m_fullcolorPalettePath);
Shinya Kitaoka 120a6e
  if (TSystem::touchParentDir(fullPath)) {
Shinya Kitaoka 120a6e
    if (TSystem::doesExistFileOrLevel(fullPath))
Shinya Kitaoka 120a6e
      TSystem::removeFileOrLevel(fullPath);
Shinya Kitaoka 120a6e
    TOStream os(fullPath);
Shinya Kitaoka 120a6e
    os << m_palette;
Shinya Kitaoka 120a6e
    m_palette->setDirtyFlag(false);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}