1
/*=========================================================================
3
Program: Ionization FRont Interactive Tool (IFRIT)
7
Copyright (c) 2002-2006 Nick Gnedin
10
This file may be distributed and/or modified under the terms of the
11
GNU General Public License version 2 as published by the Free Software
12
Foundation and appearing in the file LICENSE.GPL included in the
13
packaging of this file.
15
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
16
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
19
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
=========================================================================*/
1
/*=========================================================================
3
Program: Ionization FRont Interactive Tool (IFRIT)
7
Copyright (c) 2002-2006 Nick Gnedin
10
This file may be distributed and/or modified under the terms of the
11
GNU General Public License version 2 as published by the Free Software
12
Foundation and appearing in the file LICENSE.GPL included in the
13
packaging of this file.
15
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
16
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
19
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
=========================================================================*/
29
29
#include "iconfigure.h"
77
79
virtual void Execute()
80
if(mOldFileName.IsEmpty()) mOldFileName = this->GetShell()->GetEnvironment(_EnvironmentPalette);
82
if(mOldFileName.IsEmpty()) mOldFileName = this->GetShell()->GetEnvironment(Environment::Palette);
81
83
fn = this->GetMainWindow()->GetFileName("Open palette file",mOldFileName,"Palette file (*.ipf)");
82
84
if(!fn.IsEmpty() && fn.Part(-4).Lower()!=".ipf") fn += ".ipf";
85
87
if(!f.Open(iFile::_Read,iFile::_Text))
87
this->GetMainWindow()->PopupWindow(mDialog->GetFrame(),"Failed to open a palette file.",_PopupWindowError);
89
this->GetMainWindow()->PopupWindow(mDialog->GetFrame(),"Failed to open a palette file.",PopupWindow::Error);
92
if(!f.ReadLine(ws) || !this->GetShell()->GetControlModule()->UnPackValuePalette(ws,mDialog->GetCurrentPalette()))
94
if(!f.ReadLine(ws) || !iPaletteSet::Default()->UnPackValuePalette(ws,mDialog->GetCurrentPalette()))
94
this->GetMainWindow()->PopupWindow(mDialog->GetFrame(),"Palette file is corrupted.",_PopupWindowError);
96
this->GetMainWindow()->PopupWindow(mDialog->GetFrame(),"Palette file is corrupted.",PopupWindow::Error);
124
126
virtual void Execute()
127
if(mOldFileName.IsEmpty()) mOldFileName = this->GetShell()->GetEnvironment(_EnvironmentPalette);
129
if(mOldFileName.IsEmpty()) mOldFileName = this->GetShell()->GetEnvironment(Environment::Palette);
128
130
fn = this->GetMainWindow()->GetFileName("Save palette file",mOldFileName,"Palette file (*.ipf)",false);
129
131
if(!fn.IsEmpty() && fn.Part(-4).Lower()!=".ipf") fn += ".ipf";
132
134
if(!f.Open(iFile::_Write,iFile::_Text))
134
this->GetMainWindow()->PopupWindow(mDialog->GetFrame(),"Failed to create a palette file.",_PopupWindowError);
136
this->GetMainWindow()->PopupWindow(mDialog->GetFrame(),"Failed to create a palette file.",PopupWindow::Error);
139
this->GetShell()->GetControlModule()->PackValuePalette(ws,mDialog->GetCurrentPalette());
141
iPaletteSet::Default()->PackValuePalette(ws,mDialog->GetCurrentPalette());
140
142
if(!f.WriteLine(ws))
142
this->GetMainWindow()->PopupWindow(mDialog->GetFrame(),"Unable to write into a palette file.",_PopupWindowError);
144
this->GetMainWindow()->PopupWindow(mDialog->GetFrame(),"Unable to write into a palette file.",PopupWindow::Error);
329
313
virtual void Execute()
331
315
mDialog->Apply(true);
332
if(!this->GetShell()->GetControlModule()->AddEmptyPalette())
316
if(!iPaletteSet::Default()->AddEmptyPalette())
334
this->GetMainWindow()->PopupWindow(mDialog->GetFrame(),"Unable to create a new palette.\nPerhaps, there is not enough free memory.",_PopupWindowError);
318
this->GetMainWindow()->PopupWindow(mDialog->GetFrame(),"Unable to create a new palette.\nPerhaps, there is not enough free memory.",PopupWindow::Error);
338
mDialog->SetCurrentPaletteIndex(this->GetShell()->GetControlModule()->GetNumberOfPalettes()-1);
322
mDialog->SetCurrentPaletteIndex(iPaletteSet::Default()->GetNumberOfPalettes()-1);
350
334
iggDialogPaletteEditor::iggDialogPaletteEditor(iggMainWindow *parent) : iggDialog(parent,0U,iImageFactory::FindIcon("paled.png"),"Palette Editor","sr.gg.de",2)
352
336
mCurrentPalette = new iPalette;
353
mCurrentPalette->Copy(this->GetShell()->GetControlModule()->GetPalette(0));
337
mCurrentPalette->Copy(iPaletteSet::Default()->GetPalette(0));
354
338
mCurrentPaletteIndex = 0;
356
340
iggFrame *cpb = new iggFrame(mFrame,2);
371
355
iggWidget *pf1, *pf2, *pf3;
372
356
pf1 = new PiecewiseFunctionControls(0,this,spb);
373
ps->AddDependent(pf1);
374
358
pf2 = new PiecewiseFunctionControls(1,this,spb);
375
ps->AddDependent(pf2);
376
360
pf3 = new PiecewiseFunctionControls(2,this,spb);
377
ps->AddDependent(pf3);
378
362
spb->AddLine(pf1,pf2,pf3);
380
364
spb->SetRowStretch(0,0);
424
408
void iggDialogPaletteEditor::SetCurrentPaletteIndex(int n)
426
if(n>0 && n<=this->GetShell()->GetControlModule()->GetNumberOfPalettes())
410
if(n>=0 && n<iPaletteSet::Default()->GetNumberOfPalettes())
428
412
if(mApplyButton->IsEnabled()) this->Apply(true);
429
mCurrentPalette->Copy(this->GetShell()->GetControlModule()->GetPalette(n));
413
mCurrentPalette->Copy(iPaletteSet::Default()->GetPalette(n));
430
414
mCurrentPaletteIndex = n;
431
415
this->UpdateDialog();
438
422
if(mApplyButton->IsEnabled() && (!ask || this->GetMainWindow()->AskForConfirmation("Do you want to apply changes?","Apply")))
440
this->GetShell()->GetControlModule()->GetPalette(mCurrentPaletteIndex)->Copy(mCurrentPalette);
424
iPaletteSet::Default()->GetPalette(mCurrentPaletteIndex)->Copy(mCurrentPalette);
441
425
iggFramePaletteSelectionBase::UpdateAll();
442
this->GetShell()->GetControlModule()->Render(_RenderOptionAll);
426
this->GetShell()->GetControlModule()->Render(RenderOption::All);
443
427
mApplyButton->Enable(false);