tahoma2d/toonz/sources/toonzlib/fullcolorpalette.cpp

83 lines
2.3 KiB
C++
Raw Normal View History

2016-03-19 06:57:51 +13:00
#include "toonz/fullcolorpalette.h"
#include "toonz/tscenehandle.h"
#include "toonz/toonzscene.h"
#include "toonz/toonzfolders.h"
2016-03-19 06:57:51 +13:00
#include "tsystem.h"
#include "tstream.h"
#include "tpalette.h"
//==================================================
//
2016-06-15 18:43:10 +12:00
// FullColorPalette
2016-03-19 06:57:51 +13:00
//
//==================================================
FullColorPalette::FullColorPalette()
2016-06-15 18:43:10 +12:00
: m_fullcolorPalettePath("+palettes\\Raster_Drawing_Palette.tpl")
, m_palette(0) {}
2016-03-19 06:57:51 +13:00
//----------------------------------------------------
2016-06-15 18:43:10 +12:00
FullColorPalette *FullColorPalette::instance() {
static FullColorPalette _instance;
return &_instance;
2016-03-19 06:57:51 +13:00
}
//----------------------------------------------------
2016-06-15 18:43:10 +12:00
FullColorPalette::~FullColorPalette() { clear(); }
2016-03-19 06:57:51 +13:00
//----------------------------------------------------
2016-06-15 18:43:10 +12:00
void FullColorPalette::clear() {
if (m_palette) m_palette->release();
m_palette = 0;
2016-03-19 06:57:51 +13:00
}
//----------------------------------------------------
2016-06-15 18:43:10 +12:00
TPalette *FullColorPalette::getPalette(ToonzScene *scene) {
if (m_palette) return m_palette;
m_palette = new TPalette();
m_palette->addRef();
TFilePath fullPath = scene->decodeFilePath(m_fullcolorPalettePath);
if (!TSystem::doesExistFileOrLevel(fullPath)) {
// For the French who have the old name of the headstock
// The old one will be loaded but saved with the new name!
2016-06-15 18:43:10 +12:00
TFilePath app("+palettes\\fullcolorPalette.tpl");
fullPath = scene->decodeFilePath(app);
// If fullcolorPalette not found, look fora default raster palette is
// defined
if (!TSystem::doesExistFileOrLevel(fullPath))
fullPath = ToonzFolder::getMyPalettesDir() + "raster_default.tpl";
2016-06-15 18:43:10 +12:00
}
if (TSystem::doesExistFileOrLevel(fullPath)) {
TPalette *app = new TPalette();
TIStream is(fullPath);
is >> app;
m_palette->assign(app);
delete app;
}
m_palette->setPaletteName(L"Raster Drawing Palette");
return m_palette;
2016-03-19 06:57:51 +13:00
}
//----------------------------------------------------
2016-06-15 18:43:10 +12:00
void FullColorPalette::savePalette(ToonzScene *scene) {
if (!m_palette || !m_palette->getDirtyFlag()) return;
TFilePath fullPath = scene->decodeFilePath(m_fullcolorPalettePath);
if (TSystem::touchParentDir(fullPath)) {
if (TSystem::doesExistFileOrLevel(fullPath))
TSystem::removeFileOrLevel(fullPath);
TOStream os(fullPath);
os << m_palette;
m_palette->setDirtyFlag(false);
}
2016-03-19 06:57:51 +13:00
}