1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "object_viewer.h"
20 #include "value_gradient_dlg.h"
22 #include "edit_attrib_dlg.h"
23 #include "editable_range.h"
25 #include "popup_notify.h"
28 /////////////////////////////////////////////////////////////////////////////
29 // CValueGradientDlg dialog
32 CValueGradientDlg::CValueGradientDlg(IValueGradientDlgClient
*clientInterface
,
33 CParticleWorkspace::CNode
*ownerNode
,
34 bool destroyClientInterface
,
37 bool canTuneNbStages
/* = true*/,
39 : CDialog(CValueGradientDlg::IDD
, pParent
),
40 _ClientInterface(clientInterface
),
42 _DestroyClientInterface(destroyClientInterface
),
44 _CanTuneNbStages(canTuneNbStages
),
48 //{{AFX_DATA_INIT(CValueGradientDlg)
50 _NbStepDlg
= new CEditableRangeUInt(std::string("GRADIENT NB STEP"), ownerNode
, 1, 255);
54 CValueGradientDlg::~CValueGradientDlg()
56 if (_DestroyClientInterface
) delete _ClientInterface
;
58 _NbStepDlg
->DestroyWindow();
62 void CValueGradientDlg::init(CWnd
*pParent
)
64 CDialog::Create(IDD_GRADIENT_DLG
, pParent
);
70 void CValueGradientDlg::DoDataExchange(CDataExchange
* pDX
)
72 CDialog::DoDataExchange(pDX
);
73 //{{AFX_DATA_MAP(CValueGradientDlg)
74 DDX_Control(pDX
, IDC_NO_SAMPLES
, m_NoSamples
);
75 DDX_Control(pDX
, IDC_GRADIENT_LIST
, m_GradientList
);
76 DDX_Control(pDX
, IDC_EDITED_VALUE
, m_Value
);
77 DDX_Control(pDX
, IDC_REMOVE_VALUE
, m_RemoveCtrl
);
82 BEGIN_MESSAGE_MAP(CValueGradientDlg
, CDialog
)
83 //{{AFX_MSG_MAP(CValueGradientDlg)
84 ON_BN_CLICKED(IDC_ADD_VALUE
, OnAddValue
)
85 ON_BN_CLICKED(IDC_INSERT_VALUE
, OnInsertValue
)
86 ON_BN_CLICKED(IDC_REMOVE_VALUE
, OnRemoveValue
)
87 ON_BN_CLICKED(IDC_VALUE_DOWN
, OnValueDown
)
88 ON_BN_CLICKED(IDC_VALUE_UP
, OnValueUp
)
89 ON_LBN_SELCHANGE(IDC_GRADIENT_LIST
, OnSelchangeGradientList
)
94 /////////////////////////////////////////////////////////////////////////////
95 // CValueGradientDlg message handlers
97 void CValueGradientDlg::OnAddValue()
99 nlassert(_ClientInterface
);
102 _ClientInterface
->modifyGradient(IValueGradientDlgClient::Add
, 0);
103 m_GradientList
.AddString(_T("value"));
104 m_RemoveCtrl
.EnableWindow(TRUE
);
106 m_GradientList
.SetCurSel(_Size
- 1);
107 m_GradientList
.Invalidate();
108 OnSelchangeGradientList();
112 void CValueGradientDlg::OnInsertValue()
114 nlassert(_ClientInterface
);
116 uint oldIndex
= m_GradientList
.GetCurSel();
118 _ClientInterface
->modifyGradient(IValueGradientDlgClient::Insert
, m_GradientList
.GetCurSel());
119 m_GradientList
.InsertString(m_GradientList
.GetCurSel(), _T("value"));
120 m_GradientList
.Invalidate();
121 m_GradientList
.SetCurSel(oldIndex
);
122 OnSelchangeGradientList();
126 void CValueGradientDlg::OnRemoveValue()
128 nlassert(_ClientInterface
);
131 uint oldIndex
= m_GradientList
.GetCurSel();
133 _ClientInterface
->modifyGradient(IValueGradientDlgClient::Delete
, m_GradientList
.GetCurSel());
134 m_GradientList
.DeleteString(m_GradientList
.GetCurSel());
136 if (_Size
<= _MinSize
)
138 m_RemoveCtrl
.EnableWindow(FALSE
);
140 if (oldIndex
< _Size
)
142 m_GradientList
.SetCurSel(oldIndex
);
146 m_GradientList
.SetCurSel(oldIndex
- 1);
148 m_GradientList
.Invalidate();
149 OnSelchangeGradientList(); /// this won't be called automatically ...
153 void CValueGradientDlg::OnValueDown()
155 nlassert(_ClientInterface
);
157 uint currIndex
= m_GradientList
.GetCurSel();
158 if (currIndex
== (uint
) (m_GradientList
.GetCount() - 1)) return;
159 _ClientInterface
->modifyGradient(IValueGradientDlgClient::Down
, currIndex
);
160 m_GradientList
.SetCurSel(currIndex
+ 1);
161 m_GradientList
.Invalidate();
162 OnSelchangeGradientList();
166 void CValueGradientDlg::OnValueUp()
168 nlassert(_ClientInterface
);
170 uint currIndex
= m_GradientList
.GetCurSel();
171 if (currIndex
== 0) return;
172 _ClientInterface
->modifyGradient(IValueGradientDlgClient::Up
, currIndex
);
173 m_GradientList
.SetCurSel(currIndex
- 1);
174 m_GradientList
.Invalidate();
175 OnSelchangeGradientList();
179 BOOL
CValueGradientDlg::OnInitDialog()
181 nlassert(_ClientInterface
);
182 _Size
= _ClientInterface
->getSchemeSize();
183 CDialog::OnInitDialog();
185 m_GradientList
.InitStorage(_Size
, 16);
186 for (uint k
= 0; k
< _Size
; ++k
)
188 m_GradientList
.AddString(_T("value"));
190 m_RemoveCtrl
.EnableWindow(_Size
> _MinSize
? TRUE
: FALSE
);
191 m_GradientList
.SetCurSel(0);
192 m_GradientList
.setCtrlID(IDC_GRADIENT_LIST
);
193 m_GradientList
.setDrawer(_ClientInterface
);
195 if (_CanTuneNbStages
)
197 _NbStepWrapper
.I
= _ClientInterface
;
198 _NbStepDlg
->setWrapper(&_NbStepWrapper
);
199 _NbStepDlg
->init(181, 45, this);
200 _NbStepDlg
->enableLowerBound(0, true);
204 m_NoSamples
.ShowWindow(SW_HIDE
);
207 OnSelchangeGradientList();
208 return TRUE
; // return TRUE unless you set the focus to a control
209 // EXCEPTION: OCX Property Pages should return FALSE
212 void CValueGradientDlg::OnSelchangeGradientList()
214 nlassert(_ClientInterface
);
216 delete _EditValueDlg
;
217 _EditValueDlg
= _ClientInterface
->createDialog(m_GradientList
.GetCurSel(), this, _Node
);
221 m_Value
.GetWindowRect(&r
);
222 _EditValueDlg
->init(r
.left
- or.left
, r
.top
- or.top
, this);
228 void CValueGradientDlg::invalidateGrad(void)
231 m_GradientList
.Invalidate();
235 void CValueGradientDlg::OnClose()
238 if (_PN
) _PN
->childPopupClosed(this);