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/>.
17 // VegetableApperancePage.cpp : implementation file
21 #include "object_viewer.h"
22 #include "vegetable_apperance_page.h"
23 #include "vegetable_edit_tools.h"
24 #include "vegetable_noise_value_dlg.h"
25 #include "vegetable_select_dlg.h"
26 #include "vegetable_dlg.h"
27 #include "nel/misc/noise_value.h"
28 #include "nel/3d/vegetable.h"
31 /////////////////////////////////////////////////////////////////////////////
32 // CVegetableApperancePage property page
34 IMPLEMENT_DYNCREATE(CVegetableApperancePage
, CPropertyPage
)
38 CVegetableApperancePage::CVegetableApperancePage() : CPropertyPage(CVegetableApperancePage::IDD
),
39 _BendPhaseDlg(NULL
), _BendFactorDlg(NULL
), _ColorDlg(NULL
)
41 //{{AFX_DATA_INIT(CVegetableApperancePage)
45 CVegetableApperancePage::~CVegetableApperancePage()
47 #define REMOVE_WND(wnd) if (wnd) { wnd->DestroyWindow(); delete wnd; }
48 REMOVE_WND(_BendPhaseDlg
);
49 REMOVE_WND(_BendFactorDlg
);
50 REMOVE_WND(_ColorDlg
);
53 void CVegetableApperancePage::DoDataExchange(CDataExchange
* pDX
)
55 CPropertyPage::DoDataExchange(pDX
);
56 //{{AFX_DATA_MAP(CVegetableApperancePage)
57 DDX_Control(pDX
, IDC_LIST_VEGETABLE_COLOR
, ColorList
);
62 BEGIN_MESSAGE_MAP(CVegetableApperancePage
, CPropertyPage
)
63 //{{AFX_MSG_MAP(CVegetableApperancePage)
64 ON_BN_CLICKED(IDC_BUTTON_VEGETABLE_ADD
, OnButtonVegetableAdd
)
65 ON_BN_CLICKED(IDC_BUTTON_VEGETABLE_GETOTHER
, OnButtonVegetableGetother
)
66 ON_BN_CLICKED(IDC_BUTTON_VEGETABLE_INSERT
, OnButtonVegetableInsert
)
67 ON_BN_CLICKED(IDC_BUTTON_VEGETABLE_REMOVE
, OnButtonVegetableRemove
)
68 ON_LBN_DBLCLK(IDC_LIST_VEGETABLE_COLOR
, OnDblclkListVegetableColor
)
73 // ***************************************************************************
74 // ***************************************************************************
75 // ***************************************************************************
76 // ***************************************************************************
80 // ***************************************************************************
81 void CVegetableApperancePage::setVegetableToEdit(NL3D::CVegetable
*vegetable
)
83 _Vegetable
= vegetable
;
85 // If not NULL, init all controls.
90 _BendPhaseDlg
->setNoiseValue(&_Vegetable
->BendPhase
, _VegetableDlg
);
91 _BendFactorDlg
->setNoiseValue(&_Vegetable
->BendFactor
, _VegetableDlg
);
92 _ColorDlg
->setNoiseValue(&_Vegetable
->Color
.NoiseValue
, _VegetableDlg
);
96 readFromVegetableColor(_Vegetable
);
102 // ***************************************************************************
103 void CVegetableApperancePage::readFromVegetableColor(NL3D::CVegetable
*vegetable
)
108 for(uint i
=0; i
<vegetable
->Color
.Gradients
.size(); i
++)
110 CRGBA color
= vegetable
->Color
.Gradients
[i
];
111 ColorList
.addValue(color
);
115 // ***************************************************************************
116 void CVegetableApperancePage::writeToVegetableColor(NL3D::CVegetable
*vegetable
)
118 // setup the vegetable
119 vegetable
->Color
.Gradients
.clear();
120 for(uint i
=0; i
<ColorList
.getColors().size(); i
++)
122 CRGBA color
= ColorList
.getColors()[i
];
123 vegetable
->Color
.Gradients
.push_back(color
);
128 // ***************************************************************************
129 // ***************************************************************************
130 // CVegetableScalePage message handlers
131 // ***************************************************************************
132 // ***************************************************************************
135 // ***************************************************************************
136 BOOL
CVegetableApperancePage::OnInitDialog()
138 CPropertyPage::OnInitDialog();
142 // Position of the density DlgBox relative to CVegetableDensityPage.
146 // Init BendPhase Dialog.
147 _BendPhaseDlg
= new CVegetableNoiseValueDlg (std::string("BendPhase"));
148 _BendPhaseDlg
->setDefaultRangeAbs(NL_VEGETABLE_BENDPHASE_RANGE_MIN
, NL_VEGETABLE_BENDPHASE_RANGE_MAX
);
149 _BendPhaseDlg
->setDefaultRangeRand(NL_VEGETABLE_BENDPHASE_RANGE_MIN
, NL_VEGETABLE_BENDPHASE_RANGE_MAX
);
150 _BendPhaseDlg
->setDefaultRangeFreq(NL_VEGETABLE_FREQ_RANGE_MIN
, NL_VEGETABLE_FREQ_RANGE_MAX
);
151 _BendPhaseDlg
->init(x
, y
, this);
152 y
+= CVegetableNoiseValueDlg::ControlHeight
+ spaceDy
;
153 // Init BendFactor Dialog.
154 _BendFactorDlg
= new CVegetableNoiseValueDlg (std::string("BendFactor"));
155 _BendFactorDlg
->setDefaultRangeAbs(NL_VEGETABLE_BENDFACTOR_RANGE_MIN
, NL_VEGETABLE_BENDFACTOR_RANGE_MAX
);
156 _BendFactorDlg
->setDefaultRangeRand(NL_VEGETABLE_BENDFACTOR_RANGE_MIN
, NL_VEGETABLE_BENDFACTOR_RANGE_MAX
);
157 _BendFactorDlg
->setDefaultRangeFreq(NL_VEGETABLE_FREQ_RANGE_MIN
, NL_VEGETABLE_FREQ_RANGE_MAX
);
158 _BendFactorDlg
->init(x
, y
, this);
159 y
+= CVegetableNoiseValueDlg::ControlHeight
+ spaceDy
;
160 // Init Color Dialog.
161 _ColorDlg
= new CVegetableNoiseValueDlg (std::string("Color Noise"));
162 _ColorDlg
->setDefaultRangeAbs(NL_VEGETABLE_COLOR_RANGE_MIN
, NL_VEGETABLE_COLOR_RANGE_MAX
);
163 _ColorDlg
->setDefaultRangeRand(NL_VEGETABLE_COLOR_RANGE_MIN
, NL_VEGETABLE_COLOR_RANGE_MAX
);
164 _ColorDlg
->setDefaultRangeFreq(NL_VEGETABLE_FREQ_RANGE_MIN
, NL_VEGETABLE_FREQ_RANGE_MAX
);
165 _ColorDlg
->init(x
, y
, this);
166 y
+= CVegetableNoiseValueDlg::ControlHeight
+ spaceDy
;
169 ColorList
.setCtrlID(IDC_LIST_VEGETABLE_COLOR
);
171 ColorList
.setupItem(size
, size
, size
-10, size
-10);
174 return TRUE
; // return TRUE unless you set the focus to a control
175 // EXCEPTION: OCX Property Pages should return FALSE
179 // ***************************************************************************
180 void CVegetableApperancePage::OnButtonVegetableAdd()
182 // copy the current selected color
183 CRGBA
color(255, 255, 255);
184 int id
= ColorList
.GetCount()-1;
186 color
= ColorList
.getValue(id
);
187 // update view and vegetable
188 ColorList
.addValue(color
);
189 writeToVegetableColor(_Vegetable
);
192 _VegetableDlg
->refreshVegetableDisplay();
196 // ***************************************************************************
197 void CVegetableApperancePage::OnButtonVegetableInsert()
199 // copy the current selected color
200 CRGBA
color(255, 255, 255);
201 int id
= ColorList
.GetCurSel();
203 color
= ColorList
.getValue(id
);
204 // update view and vegetable
205 ColorList
.insertValueBeforeCurSel(color
);
206 writeToVegetableColor(_Vegetable
);
209 _VegetableDlg
->refreshVegetableDisplay();
212 // ***************************************************************************
213 void CVegetableApperancePage::OnButtonVegetableRemove()
215 // remove curSel from the list
216 ColorList
.removeCurSelValue();
217 writeToVegetableColor(_Vegetable
);
220 _VegetableDlg
->refreshVegetableDisplay();
224 // ***************************************************************************
225 void CVegetableApperancePage::OnButtonVegetableGetother()
227 // Open A dialog to select the other vegetable to copy color.
228 CVegetableSelectDlg
dlg(_VegetableDlg
);
229 if( dlg
.DoModal()==IDOK
)
231 int id
= dlg
.VegetableSelected
;
234 // read colors from this vegetable
235 NL3D::CVegetable
*otherVegetable
= _VegetableDlg
->getVegetable(id
);
236 _Vegetable
->Color
.Gradients
= otherVegetable
->Color
.Gradients
;
238 readFromVegetableColor(_Vegetable
);
241 _VegetableDlg
->refreshVegetableDisplay();
246 // ***************************************************************************
247 void CVegetableApperancePage::OnDblclkListVegetableColor()
251 // get the current color of the value.
252 int id
= ColorList
.GetCurSel();
255 color
= ColorList
.getValue(id
);
257 // Open a colorDialog.
258 CColorDialog
colorDialog(RGB(color
.R
, color
.G
, color
.B
), CC_FULLOPEN
);
259 if( colorDialog
.DoModal()==IDOK
)
262 COLORREF cref
= colorDialog
.GetColor();
263 color
.set(GetRValue(cref
), GetGValue(cref
), GetBValue(cref
));
264 ColorList
.changeCurSelValue(color
);
266 writeToVegetableColor(_Vegetable
);
269 _VegetableDlg
->refreshVegetableDisplay();