1 2 3 #include "toonz/fullcolorpalette.h" 4 #include "toonz/tscenehandle.h" 5 #include "toonz/toonzscene.h" 6 #include "tsystem.h" 7 #include "tstream.h" 8 #include "tpalette.h" 9 10 //================================================== 11 // 12 // FullColorPalette 13 // 14 //================================================== 15 FullColorPalette()16FullColorPalette::FullColorPalette() 17 : m_fullcolorPalettePath("+palettes\\Raster_Drawing_Palette.tpl") 18 , m_palette(0) {} 19 20 //---------------------------------------------------- 21 instance()22FullColorPalette *FullColorPalette::instance() { 23 static FullColorPalette _instance; 24 return &_instance; 25 } 26 27 //---------------------------------------------------- 28 ~FullColorPalette()29FullColorPalette::~FullColorPalette() { clear(); } 30 31 //---------------------------------------------------- 32 clear()33void FullColorPalette::clear() { 34 if (m_palette) m_palette->release(); 35 m_palette = 0; 36 } 37 38 //---------------------------------------------------- 39 getPalette(ToonzScene * scene)40TPalette *FullColorPalette::getPalette(ToonzScene *scene) { 41 if (m_palette) return m_palette; 42 m_palette = new TPalette(); 43 m_palette->addRef(); 44 TFilePath fullPath = scene->decodeFilePath(m_fullcolorPalettePath); 45 if (!TSystem::doesExistFileOrLevel(fullPath)) { 46 // Per I francesi che hanno il nome vecchio della paletta 47 // Verra' caricata la vecchia ma salvata col nome nuovo! 48 TFilePath app("+palettes\\fullcolorPalette.tpl"); 49 fullPath = scene->decodeFilePath(app); 50 } 51 if (TSystem::doesExistFileOrLevel(fullPath)) { 52 TPalette *app = new TPalette(); 53 TIStream is(fullPath); 54 is >> app; 55 m_palette->assign(app); 56 delete app; 57 } 58 m_palette->setPaletteName(L"Raster Drawing Palette"); 59 60 return m_palette; 61 } 62 63 //---------------------------------------------------- 64 savePalette(ToonzScene * scene)65void FullColorPalette::savePalette(ToonzScene *scene) { 66 if (!m_palette || !m_palette->getDirtyFlag()) return; 67 68 TFilePath fullPath = scene->decodeFilePath(m_fullcolorPalettePath); 69 if (TSystem::touchParentDir(fullPath)) { 70 if (TSystem::doesExistFileOrLevel(fullPath)) 71 TSystem::removeFileOrLevel(fullPath); 72 TOStream os(fullPath); 73 os << m_palette; 74 m_palette->setDirtyFlag(false); 75 } 76 } 77