~ubuntu-branches/ubuntu/wily/ifrit/wily

« back to all changes in this revision

Viewing changes to shells/generic/iggdialogpaletteeditor.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2009-09-13 14:53:24 UTC
  • mfrom: (1.1.11 upstream) (2.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20090913145324-084ivqvf29arkc1b
Tags: 3.3.2-1
* New upstream release.
* Bump Standards-Version to 3.8.3.  No changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*=========================================================================
2
 
 
3
 
  Program:   Ionization FRont Interactive Tool (IFRIT)
4
 
  Language:  C++
5
 
 
6
 
 
7
 
Copyright (c) 2002-2006 Nick Gnedin 
8
 
All rights reserved.
9
 
 
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.
14
 
 
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.
25
 
 
26
 
=========================================================================*/
 
1
/*=========================================================================
 
2
 
 
3
  Program:   Ionization FRont Interactive Tool (IFRIT)
 
4
  Language:  C++
 
5
 
 
6
 
 
7
Copyright (c) 2002-2006 Nick Gnedin 
 
8
All rights reserved.
 
9
 
 
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.
 
14
 
 
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.
 
25
 
 
26
=========================================================================*/
27
27
 
28
28
 
29
29
#include "iconfigure.h"
38
38
#include "iimagefactory.h"
39
39
#include "ifile.h"
40
40
#include "ipalette.h"
 
41
#include "ipaletteset.h"
41
42
#include "ipiecewisefunction.h"
42
43
#include "ishell.h"
43
44
 
51
52
#include "ibgwidgetentrysubject.h"
52
53
 
53
54
#include "iggsubjectfactory.h"
54
 
#include "iggparameter.h"
55
 
using namespace iggParameter;
 
55
 
 
56
 
 
57
using namespace iParameter;
56
58
using namespace iParameter;
57
59
 
58
60
 
77
79
                virtual void Execute()
78
80
                {
79
81
                        iString fn;
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";
83
85
 
84
86
                        iFile f(fn);
85
87
                        if(!f.Open(iFile::_Read,iFile::_Text))
86
88
                        {
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);
88
90
                                return;
89
91
                        }
90
92
 
91
93
                        iString ws;
92
 
                        if(!f.ReadLine(ws) || !this->GetShell()->GetControlModule()->UnPackValuePalette(ws,mDialog->GetCurrentPalette()))
 
94
                        if(!f.ReadLine(ws) || !iPaletteSet::Default()->UnPackValuePalette(ws,mDialog->GetCurrentPalette()))
93
95
                        {
94
 
                                this->GetMainWindow()->PopupWindow(mDialog->GetFrame(),"Palette file is corrupted.",_PopupWindowError);
 
96
                                this->GetMainWindow()->PopupWindow(mDialog->GetFrame(),"Palette file is corrupted.",PopupWindow::Error);
95
97
                        }
96
98
                        else
97
99
                        {
124
126
                virtual void Execute()
125
127
                {
126
128
                        iString fn;
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";
130
132
 
131
133
                        iFile f(fn);
132
134
                        if(!f.Open(iFile::_Write,iFile::_Text))
133
135
                        {
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);
135
137
                                return;
136
138
                        }
137
139
 
138
140
                        iString ws;
139
 
                        this->GetShell()->GetControlModule()->PackValuePalette(ws,mDialog->GetCurrentPalette());
 
141
                        iPaletteSet::Default()->PackValuePalette(ws,mDialog->GetCurrentPalette());
140
142
                        if(!f.WriteLine(ws))
141
143
                        {
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);
143
145
                        }
144
146
                        else
145
147
                        {
170
172
                        return mEditor->GetCurrentPalette();
171
173
                }
172
174
 
173
 
                virtual int GetCurrentPaletteIndex() const
 
175
        protected:
 
176
 
 
177
                virtual int GetPaletteId() const
174
178
                {
175
179
                        return mEditor->GetCurrentPaletteIndex() + 1;
176
180
                }
177
181
 
178
 
        protected:
179
 
 
180
 
                virtual void SetCurrentPaletteIndexBody(int n)
 
182
                virtual void SetPaletteId(int n)
181
183
                {
182
184
                        mEditor->SetCurrentPaletteIndex(n-1);
183
185
                }
209
211
 
210
212
                virtual iPiecewiseFunction* GetFunction()
211
213
                {
212
 
                        switch(mType)
213
 
                        {
214
 
                        case 0:
215
 
                                {
216
 
                                        return mEditor->GetCurrentPalette()->GetRedComponent();
217
 
                                }
218
 
                        case 1:
219
 
                                {
220
 
                                        return mEditor->GetCurrentPalette()->GetGreenComponent();
221
 
                                }
222
 
                        case 2:
223
 
                                {
224
 
                                        return mEditor->GetCurrentPalette()->GetBlueComponent();
225
 
                                }
226
 
                        default:
227
 
                                {
228
 
                                        return 0;
229
 
                                }
230
 
                        }
 
214
                        return mEditor->GetCurrentPalette()->GetComponent(mType);
231
215
                }
232
216
 
233
217
                virtual void OnRender()
298
282
                {
299
283
                        if(s.Find("*") >= 0)
300
284
                        {
301
 
                                this->GetMainWindow()->PopupWindow(mDialog->GetFrame(),"A palette name may not contain symbols '*'",_PopupWindowError);
 
285
                                this->GetMainWindow()->PopupWindow(mDialog->GetFrame(),"A palette name may not contain symbols '*'",PopupWindow::Error);
302
286
                                mSubject->SetText(mDialog->GetCurrentPalette()->GetName());
303
287
                        }
304
288
                        else
329
313
                virtual void Execute()
330
314
                {
331
315
                        mDialog->Apply(true);
332
 
                        if(!this->GetShell()->GetControlModule()->AddEmptyPalette())
 
316
                        if(!iPaletteSet::Default()->AddEmptyPalette())
333
317
                        {
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);
335
319
                        }
336
320
                        else
337
321
                        {
338
 
                                mDialog->SetCurrentPaletteIndex(this->GetShell()->GetControlModule()->GetNumberOfPalettes()-1);
 
322
                                mDialog->SetCurrentPaletteIndex(iPaletteSet::Default()->GetNumberOfPalettes()-1);
339
323
                        }
340
324
                }
341
325
 
350
334
iggDialogPaletteEditor::iggDialogPaletteEditor(iggMainWindow *parent) : iggDialog(parent,0U,iImageFactory::FindIcon("paled.png"),"Palette Editor","sr.gg.de",2)
351
335
{
352
336
        mCurrentPalette = new iPalette;
353
 
        mCurrentPalette->Copy(this->GetShell()->GetControlModule()->GetPalette(0));
 
337
        mCurrentPalette->Copy(iPaletteSet::Default()->GetPalette(0));
354
338
        mCurrentPaletteIndex = 0;
355
339
 
356
340
        iggFrame *cpb = new iggFrame(mFrame,2);
370
354
 
371
355
        iggWidget *pf1, *pf2, *pf3;
372
356
        pf1 = new PiecewiseFunctionControls(0,this,spb);
373
 
        ps->AddDependent(pf1);
 
357
        ps->AddBuddy(pf1);
374
358
        pf2 = new PiecewiseFunctionControls(1,this,spb);
375
 
        ps->AddDependent(pf2);
 
359
        ps->AddBuddy(pf2);
376
360
        pf3 = new PiecewiseFunctionControls(2,this,spb);
377
 
        ps->AddDependent(pf3);
 
361
        ps->AddBuddy(pf3);
378
362
        spb->AddLine(pf1,pf2,pf3);
379
363
 
380
364
        spb->SetRowStretch(0,0);
423
407
 
424
408
void iggDialogPaletteEditor::SetCurrentPaletteIndex(int n)
425
409
{
426
 
        if(n>0 && n<=this->GetShell()->GetControlModule()->GetNumberOfPalettes())
 
410
        if(n>=0 && n<iPaletteSet::Default()->GetNumberOfPalettes())
427
411
        {
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();
432
416
        }
437
421
{
438
422
        if(mApplyButton->IsEnabled() && (!ask || this->GetMainWindow()->AskForConfirmation("Do you want to apply changes?","Apply")))
439
423
        {
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);
444
428
        }
445
429
}