doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LightDlg.cpp
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 
29 #include "../../idlib/precompiled.h"
30 #pragma hdrstop
31 
32 #include "qe3.h"
33 #include "Radiant.h"
34 #include "../../game/game.h"
35 #include "../comafx/DialogColorPicker.h"
36 #include "LightDlg.h"
37 
38 #ifdef ID_DEBUG_MEMORY
39 #undef new
40 #undef DEBUG_NEW
41 #define DEBUG_NEW new
42 #endif
43 
44 
46  pointLight = true;
47  fallOff = 1;
48  strTexture = "";
49  equalRadius = true;
50  explicitStartEnd = false;
51  lightRadius.Zero();
52  lightTarget.Zero();
53  lightRight.Zero();
54  lightUp.Zero();
55  lightStart.Zero();
56  lightEnd.Zero();
57  lightCenter.Zero();
58  hasCenter = false;
59  isParallel = false;
60  castShadows = true;
61  castSpecular = true;
62  castDiffuse = true;
63  rotate = false;
64  strobe = false;
65  rotateSpeed = 0;
66  strobeSpeed = 0;
67  color[0] = color[1] = color[2] = 255;
68  fogDensity[0] = fogDensity[1] = fogDensity[2] = 0;
69  fog = false;
70  lightRadius[0] = lightRadius[1] = lightRadius[2] = 300;
71 }
72 
73 
75  idVec3 oldColor = color;
76  Defaults();
77  color = oldColor;
78  pointLight = true;
79 }
80 
82  idVec3 oldColor = color;
83  Defaults();
84  color = oldColor;
85  pointLight = false;
86  lightTarget[2] = -256;
87  lightUp[1] = -128;
88  lightRight[0] = -128;
89 }
90 
91 void CLightInfo::FromDict( const idDict *e ) {
92 
93  lightRadius.Zero();
94  lightTarget.Zero();
95  lightRight.Zero();
96  lightUp.Zero();
97  lightStart.Zero();
98  lightEnd.Zero();
99  lightCenter.Zero();
100 
101  castShadows = !e->GetBool("noshadows");
102  castSpecular = !e->GetBool("nospecular");
103  castDiffuse = !e->GetBool("nodiffuse");
104  fallOff = e->GetFloat("falloff");
105  strTexture = e->GetString("texture");
106 
107  isParallel = e->GetBool("parallel");
108 
109  if (!e->GetVector("_color", "", color)) {
110  color[0] = color[1] = color[2] = 1;
111  }
112  // windows needs 0-255 scale
113  color[0] *= 255;
114  color[1] *= 255;
115  color[2] *= 255;
116 
117  if (e->GetVec4("fog", "", fogDensity)) {
118  fog = true;
119  } else {
120  fog = false;
121  }
122 
123  if (e->GetVector("light_right","", lightRight)) {
124  // projected light
125  pointLight = false;
126  e->GetVector("light_target", "", lightTarget);
127  e->GetVector("light_up", "", lightUp);
128  if (e->GetVector("light_start", "", lightStart)) {
129  // explicit start and end points
130  explicitStartEnd = true;
131  if (!e->GetVector("light_end", "", lightEnd)) {
132  // no end, use target
134  }
135  } else {
136  explicitStartEnd = false;
137  // create a start a quarter of the way to the target
138  lightStart = lightTarget * 0.25;
140  }
141  } else {
142  pointLight = true;
143  if (e->GetVector("light_radius", "", lightRadius)) {
144  equalRadius = false;
145  } else {
146  float radius = e->GetFloat("light");
147  if (radius == 0) {
148  radius = 300;
149  }
150  lightRadius[0] = lightRadius[1] = lightRadius[2] = radius;
151  equalRadius = true;
152  }
153  if (e->GetVector("light_center", "", lightCenter)) {
154  hasCenter = true;
155  }
156  }
157 }
158 
159 void CLightInfo::ToDictFromDifferences ( idDict *e, const idDict *differences ) {
160  for ( int i = 0 ; i < differences->GetNumKeyVals () ; i ++ ) {
161  const idKeyValue *kv = differences->GetKeyVal( i );
162 
163  if ( kv->GetValue().Length() > 0 ) {
164  e->Set ( kv->GetKey() ,kv->GetValue() );
165  } else {
166  e->Delete ( kv->GetKey() );
167  }
168 
169  common->Printf( "Applied difference: %s %s\n" , kv->GetKey().c_str() , kv->GetValue().c_str() );
170  }
171 }
172 
173 //write all info to a dict, regardless of light type
175  e->Set("noshadows", (!castShadows) ? "1" : "0");
176  e->Set("nospecular", (!castSpecular) ? "1" : "0");
177  e->Set("nodiffuse", (!castDiffuse) ? "1" : "0");
178 
179  e->SetFloat("falloff",fallOff);
180 
181  if (strTexture.GetLength() > 0 ) {
182  e->Set("texture", strTexture);
183  }
184 
185  idVec3 temp = color;
186  temp /= 255;
187  e->SetVector("_color", temp);
188 
189  if (!equalRadius) {
190  e->Set("light_radius", va("%g %g %g", lightRadius[0], lightRadius[1], lightRadius[2]));
191  } else {
192  e->Set("light_radius", va("%g %g %g", lightRadius[0], lightRadius[0], lightRadius[0]));
193  }
194 
195  e->Set("light_center", va("%g %g %g", lightCenter[0], lightCenter[1], lightCenter[2]));
196  e->Set("parallel", isParallel?"1":"0");
197 
198  e->Set("light_target", va("%g %g %g", lightTarget[0], lightTarget[1], lightTarget[2]));
199  e->Set("light_up", va("%g %g %g", lightUp[0], lightUp[1], lightUp[2]));
200  e->Set("light_right", va("%g %g %g", lightRight[0], lightRight[1], lightRight[2]));
201  e->Set("light_start", va("%g %g %g", lightStart[0], lightStart[1], lightStart[2]));
202  e->Set("light_end", va("%g %g %g", lightEnd[0], lightEnd[1], lightEnd[2]));
203 }
204 
206 
207  e->Delete("noshadows");
208  e->Delete("nospecular");
209  e->Delete("nodiffuse");
210  e->Delete("falloff");
211  e->Delete("parallel");
212  e->Delete("texture");
213  e->Delete("_color");
214  e->Delete("fog");
215  e->Delete("light_target");
216  e->Delete("light_right");
217  e->Delete("light_up");
218  e->Delete("light_start");
219  e->Delete("light_end");
220  e->Delete("light_radius");
221  e->Delete("light_center");
222  e->Delete("light");
223 
224  e->Set("noshadows", (!castShadows) ? "1" : "0");
225  e->Set("nospecular", (!castSpecular) ? "1" : "0");
226  e->Set("nodiffuse", (!castDiffuse) ? "1" : "0");
227 
228  e->SetFloat("falloff",fallOff);
229 
230  if (strTexture.GetLength() > 0) {
231  e->Set("texture", strTexture);
232  }
233 
234  idVec3 temp = color;
235  temp /= 255;
236  e->SetVector("_color", temp);
237 
238  if (fog) {
239  e->Set("fog", va("%g %g %g %g", fogDensity[0]/255.0, fogDensity[1]/255.0, fogDensity[2]/255.0, fogDensity[3]/255.0));
240  }
241 
242  if (pointLight) {
243  if (!equalRadius) {
244  e->Set("light_radius", va("%g %g %g", lightRadius[0], lightRadius[1], lightRadius[2]));
245  } else {
246  e->Set("light_radius", va("%g %g %g", lightRadius[0], lightRadius[0], lightRadius[0]));
247  }
248 
249  if (hasCenter) {
250  e->Set("light_center", va("%g %g %g", lightCenter[0], lightCenter[1], lightCenter[2]));
251  }
252 
253  if (isParallel) {
254  e->Set("parallel", "1");
255  }
256  } else {
257  e->Set("light_target", va("%g %g %g", lightTarget[0], lightTarget[1], lightTarget[2]));
258  e->Set("light_up", va("%g %g %g", lightUp[0], lightUp[1], lightUp[2]));
259  e->Set("light_right", va("%g %g %g", lightRight[0], lightRight[1], lightRight[2]));
260  if (explicitStartEnd) {
261  e->Set("light_start", va("%g %g %g", lightStart[0], lightStart[1], lightStart[2]));
262  e->Set("light_end", va("%g %g %g", lightEnd[0], lightEnd[1], lightEnd[2]));
263  }
264  }
265 }
266 
268  Defaults();
269 }
270 
271 
272 
274 // CLightDlg dialog
275 
277 
278 
279 CLightDlg::CLightDlg(CWnd* pParent /*=NULL*/)
280  : CDialog(CLightDlg::IDD, pParent)
281 {
282  //{{AFX_DATA_INIT(CLightDlg)
287  m_fFallloff = 0.0f;
288  m_nFalloff = -1;
289  m_bRotate = FALSE;
290  m_bShadows = FALSE;
291  m_bSpecular = FALSE;
292  m_bDiffuse = FALSE;
293  m_fEndX = 0.0f;
294  m_fEndY = 0.0f;
295  m_fEndZ = 0.0f;
296  m_fRadiusX = 0.0f;
297  m_fRadiusY = 0.0f;
298  m_fRadiusZ = 0.0f;
299  m_fRightX = 0.0f;
300  m_fRightY = 0.0f;
301  m_fRightZ = 0.0f;
302  m_fRotate = 0.0f;
303  m_fStartX = 0.0f;
304  m_fStartY = 0.0f;
305  m_fStartZ = 0.0f;
306  m_fTargetX = 0.0f;
307  m_fTargetY = 0.0f;
308  m_fTargetZ = 0.0f;
309  m_fUpX = 0.0f;
310  m_fUpY = 0.0f;
311  m_fUpZ = 0.0f;
312  m_hasCenter = FALSE;
313  m_centerX = 0.0f;
314  m_centerY = 0.0f;
315  m_centerZ = 0.0f;
317  //}}AFX_DATA_INIT
319 }
320 
322  delete m_drawMaterial;
323 }
324 
325 void CLightDlg::DoDataExchange(CDataExchange* pDX)
326 {
327  CDialog::DoDataExchange(pDX);
328  //{{AFX_DATA_MAP(CLightDlg)
329  if ( com_editorActive ) {
330  DDX_Control(pDX, IDC_LIGHTPREVIEW, m_wndPreview);
331  }
332  DDX_Control(pDX, IDC_COMBO_TEXTURE, m_wndLights);
333  DDX_Check(pDX, IDC_CHECK_EQUALRADIUS, m_bEqualRadius);
335  DDX_Check(pDX, IDC_CHECK_POINT, m_bPointLight);
336  DDX_Check(pDX, IDC_CHECK_PROJECTED, m_bCheckProjected);
337  DDX_Radio(pDX, IDC_RADIO_FALLOFF, m_nFalloff);
338  DDX_Check(pDX, IDC_CHECK_SHADOWS, m_bShadows);
339  DDX_Check(pDX, IDC_CHECK_SPECULAR, m_bSpecular);
340  DDX_Check(pDX, IDC_CHECK_DIFFUSE, m_bDiffuse);
341  DDX_Check(pDX , IDC_CHECK_PARALLEL , m_bIsParallel );
342  DDX_Text(pDX, IDC_EDIT_ENDX, m_fEndX);
343  DDX_Text(pDX, IDC_EDIT_ENDY, m_fEndY);
344  DDX_Text(pDX, IDC_EDIT_ENDZ, m_fEndZ);
345  DDX_Text(pDX, IDC_EDIT_RADIUSX, m_fRadiusX);
346  DDX_Text(pDX, IDC_EDIT_RADIUSY, m_fRadiusY);
347  DDX_Text(pDX, IDC_EDIT_RADIUSZ, m_fRadiusZ);
348  DDX_Text(pDX, IDC_EDIT_RIGHTX, m_fRightX);
349  DDX_Text(pDX, IDC_EDIT_RIGHTY, m_fRightY);
350  DDX_Text(pDX, IDC_EDIT_RIGHTZ, m_fRightZ);
351  DDX_Text(pDX, IDC_EDIT_STARTX, m_fStartX);
352  DDX_Text(pDX, IDC_EDIT_STARTY, m_fStartY);
353  DDX_Text(pDX, IDC_EDIT_STARTZ, m_fStartZ);
354  DDX_Text(pDX, IDC_EDIT_TARGETX, m_fTargetX);
355  DDX_Text(pDX, IDC_EDIT_TARGETY, m_fTargetY);
356  DDX_Text(pDX, IDC_EDIT_TARGETZ, m_fTargetZ);
357  DDX_Text(pDX, IDC_EDIT_UPX, m_fUpX);
358  DDX_Text(pDX, IDC_EDIT_UPY, m_fUpY);
359  DDX_Text(pDX, IDC_EDIT_UPZ, m_fUpZ);
360  DDX_Check(pDX, IDC_CHECK_CENTER, m_hasCenter);
361  DDX_Text(pDX, IDC_EDIT_CENTERX, m_centerX);
362  DDX_Text(pDX, IDC_EDIT_CENTERY, m_centerY);
363  DDX_Text(pDX, IDC_EDIT_CENTERZ, m_centerZ);
364  //}}AFX_DATA_MAP
365 }
366 
367 
368 BEGIN_MESSAGE_MAP(CLightDlg, CDialog)
369  //{{AFX_MSG_MAP(CLightDlg)
370  ON_BN_CLICKED(IDC_BTN_TEXTURE, OnBtnTexture)
371  ON_BN_CLICKED(IDC_CHECK_EQUALRADIUS, OnCheckEqualradius)
372  ON_BN_CLICKED(IDC_CHECK_EXPLICITFALLOFF, OnCheckExplicitfalloff)
373  ON_BN_CLICKED(IDC_CHECK_POINT, OnCheckPoint)
374  ON_BN_CLICKED(IDC_CHECK_PROJECTED, OnCheckProjected)
375  ON_BN_CLICKED(IDC_RADIO_FALLOFF, OnRadioFalloff)
376  ON_BN_CLICKED(IDC_APPLY, OnApply)
377  ON_BN_CLICKED(IDC_APPLY_DIFFERENT, OnApplyDifferences)
378  ON_BN_CLICKED(IDC_BTN_COLOR, OnBtnColor)
379  ON_WM_CTLCOLOR()
380  ON_CBN_SELCHANGE(IDC_COMBO_TEXTURE, OnSelchangeComboTexture)
381  ON_BN_CLICKED(IDC_CHECK_CENTER, OnCheckCenter)
382  ON_BN_CLICKED(IDC_CHECK_PARALLEL, OnCheckParallel)
383  //}}AFX_MSG_MAP
384 END_MESSAGE_MAP()
385 
387 // CLightDlg message handlers
388 
389 void CLightDlg::SetSpecifics() {
390  if (lightInfo.pointLight) {
391  GetDlgItem(IDC_EDIT_RADIUSY)->EnableWindow(!lightInfo.equalRadius);
392  GetDlgItem(IDC_EDIT_RADIUSZ)->EnableWindow(!lightInfo.equalRadius);
393  GetDlgItem(IDC_EDIT_CENTERX)->EnableWindow(lightInfo.hasCenter);
394  GetDlgItem(IDC_EDIT_CENTERY)->EnableWindow(lightInfo.hasCenter);
395  GetDlgItem(IDC_EDIT_CENTERZ)->EnableWindow(lightInfo.hasCenter);
396  } else {
397  GetDlgItem(IDC_EDIT_STARTX)->EnableWindow(lightInfo.explicitStartEnd);
398  GetDlgItem(IDC_EDIT_STARTY)->EnableWindow(lightInfo.explicitStartEnd);
399  GetDlgItem(IDC_EDIT_STARTZ)->EnableWindow(lightInfo.explicitStartEnd);
400  GetDlgItem(IDC_EDIT_ENDX)->EnableWindow(lightInfo.explicitStartEnd);
401  GetDlgItem(IDC_EDIT_ENDY)->EnableWindow(lightInfo.explicitStartEnd);
402  GetDlgItem(IDC_EDIT_ENDZ)->EnableWindow(lightInfo.explicitStartEnd);
403  }
404 }
405 
407  GetDlgItem(IDC_CHECK_EQUALRADIUS)->EnableWindow(lightInfo.pointLight);
408  GetDlgItem(IDC_EDIT_RADIUSX)->EnableWindow(lightInfo.pointLight);
409  GetDlgItem(IDC_EDIT_RADIUSY)->EnableWindow(lightInfo.pointLight);
410  GetDlgItem(IDC_EDIT_RADIUSZ)->EnableWindow(lightInfo.pointLight);
411  GetDlgItem(IDC_RADIO_FALLOFF)->EnableWindow(lightInfo.pointLight);
412  GetDlgItem(IDC_RADIO_FALLOFF2)->EnableWindow(lightInfo.pointLight);
413  GetDlgItem(IDC_RADIO_FALLOFF3)->EnableWindow(lightInfo.pointLight);
414  GetDlgItem(IDC_EDIT_TARGETX)->EnableWindow(!lightInfo.pointLight);
415  GetDlgItem(IDC_EDIT_TARGETY)->EnableWindow(!lightInfo.pointLight);
416  GetDlgItem(IDC_EDIT_TARGETZ)->EnableWindow(!lightInfo.pointLight);
417  GetDlgItem(IDC_EDIT_RIGHTX)->EnableWindow(!lightInfo.pointLight);
418  GetDlgItem(IDC_EDIT_RIGHTY)->EnableWindow(!lightInfo.pointLight);
419  GetDlgItem(IDC_EDIT_RIGHTZ)->EnableWindow(!lightInfo.pointLight);
420  GetDlgItem(IDC_EDIT_UPX)->EnableWindow(!lightInfo.pointLight);
421  GetDlgItem(IDC_EDIT_UPY)->EnableWindow(!lightInfo.pointLight);
422  GetDlgItem(IDC_EDIT_UPZ)->EnableWindow(!lightInfo.pointLight);
423  GetDlgItem(IDC_EDIT_STARTX)->EnableWindow(!lightInfo.pointLight);
424  GetDlgItem(IDC_EDIT_STARTY)->EnableWindow(!lightInfo.pointLight);
425  GetDlgItem(IDC_EDIT_STARTZ)->EnableWindow(!lightInfo.pointLight);
426  GetDlgItem(IDC_EDIT_ENDX)->EnableWindow(!lightInfo.pointLight);
427  GetDlgItem(IDC_EDIT_ENDY)->EnableWindow(!lightInfo.pointLight);
428  GetDlgItem(IDC_EDIT_ENDZ)->EnableWindow(!lightInfo.pointLight);
429  GetDlgItem(IDC_CHECK_EXPLICITFALLOFF)->EnableWindow(!lightInfo.pointLight);
430  GetDlgItem(IDC_CHECK_POINT)->EnableWindow(!lightInfo.pointLight);
431  GetDlgItem(IDC_CHECK_PROJECTED)->EnableWindow(lightInfo.pointLight);
432  GetDlgItem(IDC_EDIT_CENTERX)->EnableWindow(lightInfo.pointLight);
433  GetDlgItem(IDC_EDIT_CENTERY)->EnableWindow(lightInfo.pointLight);
434  GetDlgItem(IDC_EDIT_CENTERZ)->EnableWindow(lightInfo.pointLight);
435  GetDlgItem(IDC_CHECK_CENTER)->EnableWindow(lightInfo.pointLight);
436 
437  reinterpret_cast<CButton*>(GetDlgItem(IDC_CHECK_PROJECTED))->SetCheck(!lightInfo.pointLight);
438  reinterpret_cast<CButton*>(GetDlgItem(IDC_CHECK_POINT))->SetCheck(lightInfo.pointLight);
439 
440  SetSpecifics();
441 }
442 
450  if (lightInfo.fallOff < 0.35) {
451  m_nFalloff = 0;
452  } else if (lightInfo.fallOff < 0.70) {
453  m_nFalloff = 1;
454  } else {
455  m_nFalloff = 2;
456  }
457  //m_bFog = lightInfo.fog;
461  //m_bStrobe = lightInfo.strobe;
462  //m_fStrobe = lightInfo.strobeSpeed;
463  int sel = m_wndLights.FindStringExact(-1, lightInfo.strTexture);
464  m_wndLights.SetCurSel(sel);
465  if (sel >= 0) {
467  } else {
469  }
470 
481  //m_bRotate = lightInfo.rotate;
482  //m_fRotate = lightInfo.rotateSpeed;
489  m_fUpX = lightInfo.lightUp[0];
490  m_fUpY = lightInfo.lightUp[1];
491  m_fUpZ = lightInfo.lightUp[2];
493  //m_fFogAlpha = lightInfo.fogDensity[3];
497 
498  //jhefty - added parallel light updating
500 
501  UpdateData(FALSE);
502 }
503 
505  UpdateData( TRUE );
506 
510 
511  if (lightInfo.pointLight) {
512  if (m_nFalloff == 0) {
513  m_fFallloff = 0.0;
514  } else if (m_nFalloff == 1) {
515  m_fFallloff = 0.5;
516  } else {
517  m_fFallloff = 1.0;
518  }
519  }
520 
522 
523  //lightInfo.fog = m_bFog;
524  lightInfo.rotate = ( m_bRotate != FALSE );
527 
530 
531  //lightInfo.fogDensity[3] = m_fFogAlpha;
532 
533  //lightInfo.strobe = m_bStrobe;
534  //lightInfo.strobeSpeed = m_fStrobe;
535  //lightInfo.rotate = m_bRotate;
536  //lightInfo.rotateSpeed = m_fRotate;
537 
538  int sel = m_wndLights.GetCurSel();
539  CString str("");
540  if (sel >= 0) {
541  m_wndLights.GetLBText(sel, str);
542  }
543  lightInfo.strTexture = str;
544 
561  lightInfo.lightUp[0] = m_fUpX;
562  lightInfo.lightUp[1] = m_fUpY;
563  lightInfo.lightUp[2] = m_fUpZ;
564 
569 }
570 
571 void CLightDlg::SaveLightInfo( const idDict *differences ) {
572 
573  if ( com_editorActive ) {
574 
575  // used from Radiant
576  for ( brush_t *b = selected_brushes.next; b && b != &selected_brushes; b = b->next ) {
577  if ( ( b->owner->eclass->nShowFlags & ECLASS_LIGHT ) && !b->entityModel ) {
578  if ( differences ) {
579  lightInfo.ToDictFromDifferences( &b->owner->epairs, differences );
580  } else {
581  lightInfo.ToDict( &b->owner->epairs );
582  }
583  Brush_Build( b );
584  }
585  }
586 
587  } else {
588 
589  // used in-game
590  idList<idEntity *> list;
591 
592  list.SetNum( 128 );
593  int count = gameEdit->GetSelectedEntities( list.Ptr(), list.Num() );
594  list.SetNum( count );
595 
596  for ( int i = 0; i < count; i++ ) {
597  if ( differences ) {
598  gameEdit->EntityChangeSpawnArgs( list[i], differences );
600  } else {
601  idDict newArgs;
602  lightInfo.ToDict( &newArgs );
603  gameEdit->EntityChangeSpawnArgs( list[i], &newArgs );
605  }
606  gameEdit->EntityUpdateVisuals( list[i] );
607  }
608  }
609 }
610 
612  CRect r;
613 
614  CClientDC dc(this);
615 
616  CButton *pBtn = (CButton *)GetDlgItem(IDC_BTN_COLOR);
617  pBtn->GetClientRect(&r);
618  colorBitmap.DeleteObject();
619  colorBitmap.CreateCompatibleBitmap(&dc, r.Width(), r.Height());
620  CDC MemDC;
621  MemDC.CreateCompatibleDC(&dc);
622  CBitmap *pOldBmp = MemDC.SelectObject(&colorBitmap);
623  {
624  CBrush br(RGB(color[0], color[1], color[2]));
625  MemDC.FillRect(r,&br);
626  }
627  dc.SelectObject(pOldBmp);
628  pBtn->SetBitmap(HBITMAP(colorBitmap));
629 }
630 
631 
634  int i;
635  const idMaterial *mat;
636  for (i = 0; i < count; i++) {
637  mat = declManager->MaterialByIndex(i, false);
638  idStr str = mat->GetName();
639  str.ToLower();
640  if (str.Icmpn("lights/", strlen("lights/")) == 0 || str.Icmpn("fogs/", strlen("fogs/")) == 0) {
641  m_wndLights.AddString(mat->GetName());
642  }
643  }
644 }
645 
647 {
648  CDialog::OnInitDialog();
649 
651 
652  UpdateDialog( true );
653 
655 
656  if ( com_editorActive ) {
658  }
659 
660  return TRUE; // return TRUE unless you set the focus to a control
661  // EXCEPTION: OCX Property Pages should return FALSE
662 }
663 
665 
667 
668  return CDialog::OnDestroy();
669 }
670 
672 {
673  // TODO: Add your control notification handler code here
674 
675 }
676 
678 {
679  lightInfo.equalRadius = ( reinterpret_cast<CButton*>(GetDlgItem(IDC_CHECK_EQUALRADIUS))->GetCheck() != 0 );
680  SetSpecifics();
681 }
682 
684 {
685  lightInfo.explicitStartEnd = ( reinterpret_cast<CButton*>(GetDlgItem(IDC_CHECK_EXPLICITFALLOFF))->GetCheck() != 0 );
686  SetSpecifics();
687 }
688 
690 {
693  EnableControls();
694 }
695 
697 {
700  EnableControls();
701 }
702 
704 {
705 }
706 
709  SaveLightInfo( NULL );
710  Sys_UpdateWindows(W_ALL);
711  CDialog::OnOK();
712 }
713 
715  if ( QE_SingleBrush( true, true ) ) {
716  brush_t *b = selected_brushes.next;
717  if ( ( b->owner->eclass->nShowFlags & ECLASS_LIGHT ) && !b->entityModel ) {
718  return b->owner;
719  }
720  }
721  return NULL;
722 }
723 
724 void CLightDlg::UpdateDialog( bool updateChecks )
725 {
726  CString title;
727 
730 
731  if ( com_editorActive ) {
732  // used from Radiant
734  if ( e ) {
736  lightInfoOriginal.FromDict(&e->epairs); //our original copy of the values that we compare against for apply differences
737  title = "Light Editor";
738  } else {
739  //find the last brush belonging to the last entity selected and use that as the source
740  e = NULL;
741  for ( brush_t *b = selected_brushes.next ; b != &selected_brushes ; b = b->next ) {
742  if ( ( b->owner->eclass->nShowFlags & ECLASS_LIGHT ) && !b->entityModel ) {
743  e = b->owner;
744  break;
745  }
746  }
747 
748  if ( e ) {
749  lightInfo.FromDict( &e->epairs );
750  lightInfoOriginal.FromDict(&e->epairs); //our original copy of the values that we compaer against for apply differences
751  title = "Light Editor - (Multiple lights selected)";
752  } else {
753  title = "Light Editor - (No lights selected)";
754  }
755  }
756  } else {
757  // used in-game
758  idList<idEntity *> list;
759 
760  list.SetNum( 128 );
761  int count = gameEdit->GetSelectedEntities( list.Ptr(), list.Num() );
762  list.SetNum( count );
763 
764  if ( count > 0 ) {
765  lightInfo.FromDict( gameEdit->EntityGetSpawnArgs( list[count-1] ) );
766  title = "Light Editor";
767  } else {
768  title = "Light Editor - (No entities selected)";
769  }
770  }
771 
772  SetWindowText( title );
773 
775  ColorButtons();
776 
777  if ( updateChecks ) {
778  EnableControls();
779  }
780 }
781 
782 void LightEditorInit( const idDict *spawnArgs ) {
783  if ( renderSystem->IsFullScreen() ) {
784  common->Printf( "Cannot run the light editor in fullscreen mode.\n"
785  "Set r_fullscreen to 0 and vid_restart.\n" );
786  return;
787  }
788 
789  if ( g_LightDialog == NULL ) {
790  InitAfx();
791  g_LightDialog = new CLightDlg();
792  }
793 
794  if ( g_LightDialog->GetSafeHwnd() == NULL ) {
795  g_LightDialog->Create( IDD_DIALOG_LIGHT );
796  CRect rct;
797  LONG lSize = sizeof( rct );
798  if ( LoadRegistryInfo( "Radiant::LightWindow", &rct, &lSize ) ) {
799  g_LightDialog->SetWindowPos(NULL, rct.left, rct.top, 0,0, SWP_NOSIZE);
800  }
801  }
802 
804 
805  g_LightDialog->ShowWindow( SW_SHOW );
806  g_LightDialog->SetFocus();
807  g_LightDialog->UpdateDialog( true );
808 
809  if ( spawnArgs ) {
810  // FIXME: select light based on spawn args
811  }
812 }
813 
814 void LightEditorRun( void ) {
815 #if _MSC_VER >= 1300
816  MSG *msg = AfxGetCurrentMessage(); // TODO Robert fix me!!
817 #else
818  MSG *msg = &m_msgCur;
819 #endif
820 
821  while( ::PeekMessage(msg, NULL, NULL, NULL, PM_NOREMOVE) ) {
822  // pump message
823  if ( !AfxGetApp()->PumpMessage() ) {
824  }
825  }
826 }
827 
828 void LightEditorShutdown( void ) {
829  delete g_LightDialog;
830  g_LightDialog = NULL;
831 }
832 
834  if ( g_LightDialog && g_LightDialog->GetSafeHwnd() != NULL ) {
835  g_LightDialog->UpdateDialog(true); //jhefty - update ALL info about the light, including check boxes
836  }
837 }
838 
841  SaveLightInfo( NULL );
842  Sys_UpdateWindows( W_ALL );
843 }
844 
845 void UpdateLightDialog( float r, float g, float b, float a ) {
846  UpdateRadiantColor( 0.0f, 0.0f, 0.0f, 0.0f );
847  g_LightDialog->UpdateColor( r, g, b, a );
848 }
849 
850 void CLightDlg::UpdateColor( float r, float g, float b, float a ) {
851  color[0] = a * r;
852  color[1] = a * g;
853  color[2] = a * b;
854  ColorButtons();
856  SaveLightInfo( NULL );
857  Sys_UpdateWindows( W_CAMERA );
858 }
859 
861  int r, g, b;
862  float ob;
863  r = color[0];
864  g = color[1];
865  b = color[2];
866  if ( DoNewColor( &r, &g, &b, &ob, UpdateLightDialog ) ) {
867  color[0] = ob * r;
868  color[1] = ob * g;
869  color[2] = ob * b;
870  ColorButtons();
871  }
872 }
873 
875  CDialog::OnCancel();
876 }
877 
878 HBRUSH CLightDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
879 {
880  HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
881 
882  return hbr;
883 }
884 
886 {
887  if (GetSafeHwnd())
888  {
889  CRect rct;
890  GetWindowRect(rct);
891  SaveRegistryInfo("Radiant::LightWindow", &rct, sizeof(rct));
892  }
893  return CDialog::DestroyWindow();
894 }
895 
897 {
898  UpdateData(TRUE);
899  int sel = m_wndLights.GetCurSel();
900  CString str;
901  if (sel >= 0) {
902  m_wndLights.GetLBText(sel, str);
903  m_drawMaterial->setMedia(str);
904  if ( com_editorActive ) {
905  m_wndPreview.RedrawWindow();
906  }
907  }
908  Sys_UpdateWindows(W_ALL);
909 }
910 
912 {
913  if (reinterpret_cast<CButton*>(GetDlgItem(IDC_CHECK_CENTER))->GetCheck()) {
914  lightInfo.hasCenter = true;
915  lightInfo.lightCenter.x = 0;
916  lightInfo.lightCenter.y = 0;
917  lightInfo.lightCenter.z = 32;
918  } else {
919  lightInfo.hasCenter = false;
921  }
923  SetSpecifics();
924 }
925 
927  if ( reinterpret_cast<CButton*>(GetDlgItem(IDC_CHECK_PARALLEL))->GetCheck() ) {
928  lightInfo.hasCenter = true;
929  lightInfo.isParallel = true;
930  lightInfo.lightCenter.x = 0;
931  lightInfo.lightCenter.y = 0;
932  lightInfo.lightCenter.z = 32;
933  } else {
934  lightInfo.isParallel = false;
935  lightInfo.hasCenter = false;
936  }
937 
939  SetSpecifics();
940 }
941 
942 //jhefty - only apply settings that are different
944  idDict differences, modified, original;
945 
947 
948  lightInfo.ToDict( &modified );
950 
951  differences = modified;
952 
953  // jhefty - compile a set of modified values to apply
954  for ( int i = 0; i < modified.GetNumKeyVals (); i ++ ) {
955  const idKeyValue* valModified = modified.GetKeyVal ( i );
956  const idKeyValue* valOriginal = original.FindKey ( valModified->GetKey() );
957 
958  //if it hasn't changed, remove it from the list of values to apply
959  if ( !valOriginal || ( valModified->GetValue() == valOriginal->GetValue() ) ) {
960  differences.Delete ( valModified->GetKey() );
961  }
962  }
963 
964  SaveLightInfo( &differences );
965 
966  lightInfoOriginal.FromDict( &modified );
967 
968  Sys_UpdateWindows( W_ALL );
969 }
void UpdateColor(float r, float g, float b, float a)
Definition: LightDlg.cpp:850
virtual void EntityUpdateChangeableSpawnArgs(idEntity *ent, const idDict *dict)
Definition: GameEdit.cpp:864
float strobeSpeed
Definition: LightDlg.h:57
GLubyte g
Definition: glext.h:4662
void UpdateLightInspector()
Definition: LightDlg.cpp:833
float GetFloat(const char *key, const char *defaultString="0") const
Definition: Dict.h:248
#define IDC_EDIT_ENDX
void WINAPI Sys_UpdateWindows(int nBits)
Definition: MainFrm.cpp:3974
BOOL m_bPointLight
Definition: LightDlg.h:103
void UpdateRadiantColor(float r, float g, float b, float a)
Definition: MainFrm.cpp:2638
BOOL m_bExplicitFalloff
Definition: LightDlg.h:102
float m_fUpZ
Definition: LightDlg.h:129
#define IDC_CHECK_PROJECTED
#define IDD_DIALOG_LIGHT
float m_fUpX
Definition: LightDlg.h:127
float m_fTargetX
Definition: LightDlg.h:124
afx_msg void OnSelchangeComboTexture()
Definition: LightDlg.cpp:896
float m_fEndZ
Definition: LightDlg.h:113
afx_msg void OnCheckPoint()
Definition: LightDlg.cpp:689
virtual void setMedia(const char *name)
Definition: GLWidget.cpp:476
idGLDrawableMaterial * m_drawMaterial
Definition: LightDlg.h:182
void Delete(const char *key)
Definition: Dict.cpp:496
virtual BOOL OnInitDialog()
Definition: LightDlg.cpp:646
void ToLower(void)
Definition: Str.h:817
void LightEditorRun(void)
Definition: LightDlg.cpp:814
#define IDC_EDIT_STARTX
float m_centerX
Definition: LightDlg.h:131
BOOL m_bCheckProjected
Definition: LightDlg.h:104
#define IDC_CHECK_PARALLEL
brush_t selected_brushes
Definition: EditorMap.cpp:40
CONST PIXELFORMATDESCRIPTOR UINT
Definition: win_qgl.cpp:47
const idStr & GetKey(void) const
Definition: Dict.h:52
void SetNum(int newnum, bool resize=true)
Definition: List.h:289
bool equalRadius
Definition: LightDlg.h:44
void ToDictWriteAllInfo(idDict *e)
Definition: LightDlg.cpp:174
afx_msg void OnCheckCenter()
Definition: LightDlg.cpp:911
float m_fStartX
Definition: LightDlg.h:121
int Length(void) const
Definition: Str.h:702
afx_msg void OnCheckProjected()
Definition: LightDlg.cpp:696
#define IDC_CHECK_SHADOWS
idVec3 color
Definition: LightDlg.h:181
afx_msg HBRUSH OnCtlColor(CDC *pDC, CWnd *pWnd, UINT nCtlColor)
Definition: LightDlg.cpp:878
afx_msg void OnDestroy()
Definition: LightDlg.cpp:664
bool castSpecular
Definition: LightDlg.h:63
static void ClearStates(void)
Definition: KeyInput.cpp:746
bool castShadows
Definition: LightDlg.h:62
idVec3 lightStart
Definition: LightDlg.h:46
idRenderSystem * renderSystem
float z
Definition: Vector.h:320
bool explicitStartEnd
Definition: LightDlg.h:45
bool rotate
Definition: LightDlg.h:58
#define VectorCopy(a, b)
Definition: Vector.h:1999
#define IDC_COMBO_TEXTURE
virtual BOOL DestroyWindow()
Definition: LightDlg.cpp:885
#define IDC_EDIT_ENDZ
#define IDC_BTN_TEXTURE
const char * GetName(void) const
Definition: DeclManager.h:140
Definition: Vector.h:316
BOOL m_bSpecular
Definition: LightDlg.h:109
type * Ptr(void)
Definition: List.h:596
idVec3 lightTarget
Definition: LightDlg.h:50
CLightInfo lightInfo
Definition: LightDlg.h:179
#define IDC_CHECK_POINT
float m_fStartZ
Definition: LightDlg.h:123
BOOL m_bIsParallel
Definition: LightDlg.h:134
#define IDC_EDIT_TARGETZ
#define IDC_EDIT_TARGETY
idGLWidget m_wndPreview
Definition: LightDlg.h:98
void Set(const char *key, const char *value)
Definition: Dict.cpp:275
bool LoadRegistryInfo(const char *pszName, void *pvBuf, long *plSize)
Definition: Radiant.cpp:405
float x
Definition: Vector.h:318
#define IDC_EDIT_STARTY
void LightEditorInit(const idDict *spawnArgs)
Definition: LightDlg.cpp:782
void DefaultPoint()
Definition: LightDlg.cpp:74
#define IDC_EDIT_UPX
int i
Definition: process.py:33
#define BOOL
Definition: mprintf.c:71
void SetFloat(const char *key, float val)
Definition: Dict.h:188
void Brush_Build(brush_t *b, bool bSnap, bool bMarkMap, bool bConvert, bool updateLights)
idVec3 lightCenter
Definition: LightDlg.h:51
float m_fUpY
Definition: LightDlg.h:128
void setDrawable(idGLDrawable *d)
Definition: GLWidget.cpp:801
bool castDiffuse
Definition: LightDlg.h:64
idGameEdit * gameEdit
Definition: GameEdit.cpp:668
void InitAfx(void)
Definition: StdAfx.cpp:53
int com_editors
Definition: Common.cpp:97
int Icmpn(const char *text, int n) const
Definition: Str.h:672
float m_fRadiusX
Definition: LightDlg.h:114
void LoadLightTextures()
Definition: LightDlg.cpp:632
#define IDC_EDIT_RIGHTX
GLuint GLuint GLsizei count
Definition: glext.h:2845
float fallOff
Definition: LightDlg.h:42
#define IDC_EDIT_STARTZ
virtual bool IsFullScreen(void) const =0
float m_fRightZ
Definition: LightDlg.h:119
#define IDC_CHECK_EQUALRADIUS
BOOL m_bRotate
Definition: LightDlg.h:107
#define IDC_EDIT_RADIUSZ
const char * GetString(const char *key, const char *defaultString="") const
Definition: Dict.h:240
void SaveLightInfo(const idDict *differences)
Definition: LightDlg.cpp:571
#define IDC_EDIT_UPZ
idVec3 color
Definition: LightDlg.h:52
void UpdateLightInfoFromDialog(void)
Definition: LightDlg.cpp:504
void UpdateDialogFromLightInfo(void)
Definition: LightDlg.cpp:443
idVec3 lightRight
Definition: LightDlg.h:49
idVec3 lightEnd
Definition: LightDlg.h:47
#define IDC_EDIT_RADIUSX
idVec4 GetVec4(const char *key, const char *defaultString=NULL) const
Definition: Dict.h:272
float m_fStartY
Definition: LightDlg.h:122
float m_fEndY
Definition: LightDlg.h:112
CString strTexture
Definition: LightDlg.h:43
#define IDC_EDIT_RIGHTZ
idCommon * common
Definition: Common.cpp:206
bool DoNewColor(int *i1, int *i2, int *i3, float *overBright, void(*Update)(float, float, float, float))
void ColorButtons()
Definition: LightDlg.cpp:611
#define IDC_CHECK_CENTER
bool GetBool(const char *key, const char *defaultString="0") const
Definition: Dict.h:256
Definition: Dict.h:65
#define NULL
Definition: Lib.h:88
#define IDC_EDIT_CENTERZ
#define IDC_CHECK_SPECULAR
#define IDC_EDIT_TARGETX
#define IDC_BTN_COLOR
float y
Definition: Vector.h:319
#define IDC_EDIT_RADIUSY
idVec3 GetVector(const char *key, const char *defaultString=NULL) const
Definition: Dict.h:260
CComboBox m_wndLights
Definition: LightDlg.h:99
void LightEditorShutdown(void)
Definition: LightDlg.cpp:828
afx_msg void OnRadioFalloff()
Definition: LightDlg.cpp:703
#define IDC_RADIO_FALLOFF2
afx_msg void OnBtnTexture()
Definition: LightDlg.cpp:671
const idStr & GetValue(void) const
Definition: Dict.h:53
afx_msg void OnCheckEqualradius()
Definition: LightDlg.cpp:677
int m_nFalloff
Definition: LightDlg.h:106
bool SaveRegistryInfo(const char *pszName, void *pvBuf, long lSize)
Definition: Radiant.cpp:398
float m_fTargetZ
Definition: LightDlg.h:126
float m_fFallloff
Definition: LightDlg.h:105
const idKeyValue * FindKey(const char *key) const
Definition: Dict.cpp:451
GLubyte GLubyte GLubyte a
Definition: glext.h:4662
CLightDlg(CWnd *pParent=NULL)
Definition: LightDlg.cpp:279
virtual void Printf(const char *fmt,...) id_attribute((format(printf
int modified
float m_fTargetY
Definition: LightDlg.h:125
#define IDC_APPLY
idVec3 lightUp
Definition: LightDlg.h:48
CBitmap colorBitmap
Definition: LightDlg.h:177
void FromDict(const idDict *e)
Definition: LightDlg.cpp:91
virtual int GetSelectedEntities(idEntity *list[], int max)
Definition: GameEdit.cpp:676
idDeclManager * declManager
afx_msg void OnCheckParallel()
Definition: LightDlg.cpp:926
GLubyte GLubyte b
Definition: glext.h:4662
#define IDC_EDIT_UPY
idVec3 lightRadius
Definition: LightDlg.h:61
#define IDC_EDIT_RIGHTY
virtual int GetNumDecls(declType_t type)=0
idVec4 fogDensity
Definition: LightDlg.h:54
float m_fRightY
Definition: LightDlg.h:118
bool fog
Definition: LightDlg.h:53
void SetSpecifics()
Definition: LightDlg.cpp:389
void UpdateLightDialog(float r, float g, float b, float a)
Definition: LightDlg.cpp:845
long LONG
BOOL m_bEqualRadius
Definition: LightDlg.h:101
BOOL m_hasCenter
Definition: LightDlg.h:130
GLdouble GLdouble GLdouble r
Definition: glext.h:2951
void ToDict(idDict *e)
Definition: LightDlg.cpp:205
float m_fRadiusZ
Definition: LightDlg.h:116
#define IDC_CHECK_EXPLICITFALLOFF
float m_centerZ
Definition: LightDlg.h:133
float m_fRotate
Definition: LightDlg.h:120
#define IDC_EDIT_CENTERY
afx_msg void OnApplyDifferences()
Definition: LightDlg.cpp:943
afx_msg void OnCheckExplicitfalloff()
Definition: LightDlg.cpp:683
tuple f
Definition: idal.py:89
virtual void OnOK()
Definition: LightDlg.cpp:707
int Num(void) const
Definition: List.h:265
void Defaults()
Definition: LightDlg.cpp:45
virtual const idMaterial * MaterialByIndex(int index, bool forceParse=true)=0
virtual void OnCancel()
Definition: LightDlg.cpp:874
void DefaultProjected()
Definition: LightDlg.cpp:81
bool isParallel
Definition: LightDlg.h:66
#define IDC_CHECK_DIFFUSE
#define IDC_RADIO_FALLOFF3
Definition: Str.h:116
afx_msg void OnApply()
Definition: LightDlg.cpp:839
CLightInfo lightInfoOriginal
Definition: LightDlg.h:180
void EnableControls()
Definition: LightDlg.cpp:406
idDict epairs
Definition: EditorEntity.h:42
BOOL m_bDiffuse
Definition: LightDlg.h:110
#define IDC_RADIO_FALLOFF
#define IDC_LIGHTPREVIEW
const char * c_str(void) const
Definition: Str.h:487
#define FALSE
Definition: mprintf.c:70
#define IDC_EDIT_ENDY
CLightDlg * g_LightDialog
Definition: LightDlg.cpp:276
entity_t * SingleLightSelected()
Definition: LightDlg.cpp:714
BOOL m_bShadows
Definition: LightDlg.h:108
#define IDC_APPLY_DIFFERENT
const idKeyValue * GetKeyVal(int index) const
Definition: Dict.h:294
#define TRUE
Definition: mprintf.c:69
virtual const idDict * EntityGetSpawnArgs(idEntity *ent) const
Definition: GameEdit.cpp:852
float m_centerY
Definition: LightDlg.h:132
virtual void DoDataExchange(CDataExchange *pDX)
Definition: LightDlg.cpp:325
float m_fEndX
Definition: LightDlg.h:111
char * va(const char *fmt,...)
Definition: Str.cpp:1568
bool strobe
Definition: LightDlg.h:56
virtual void EntityChangeSpawnArgs(idEntity *ent, const idDict *newArgs)
Definition: GameEdit.cpp:875
bool hasCenter
Definition: LightDlg.h:65
float m_fRightX
Definition: LightDlg.h:117
float m_fRadiusY
Definition: LightDlg.h:115
void ToDictFromDifferences(idDict *e, const idDict *differences)
Definition: LightDlg.cpp:159
afx_msg void OnBtnColor()
Definition: LightDlg.cpp:860
bool pointLight
Definition: LightDlg.h:41
int GetNumKeyVals(void) const
Definition: Dict.h:290
void Zero(void)
Definition: Vector.h:415
float rotateSpeed
Definition: LightDlg.h:59
bool com_editorActive
Definition: Common.cpp:98
#define IDC_EDIT_CENTERX
void SetVector(const char *key, const idVec3 &val)
Definition: Dict.h:200
void UpdateDialog(bool updateChecks)
Definition: LightDlg.cpp:724
virtual void EntityUpdateVisuals(idEntity *ent)
Definition: GameEdit.cpp:894