2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
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.
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.
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/>.
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.
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.
26 ===========================================================================
29 #include "../../idlib/precompiled.h"
34 #include "../../game/game.h"
35 #include "../comafx/DialogColorPicker.h"
38 #ifdef ID_DEBUG_MEMORY
45 void CLightInfo::Defaults() {
50 explicitStartEnd = false;
67 color[0] = color[1] = color[2] = 255;
68 fogDensity[0] = fogDensity[1] = fogDensity[2] = 0;
70 lightRadius[0] = lightRadius[1] = lightRadius[2] = 300;
74 void CLightInfo::DefaultPoint() {
75 idVec3 oldColor = color;
81 void CLightInfo::DefaultProjected() {
82 idVec3 oldColor = color;
86 lightTarget[2] = -256;
91 void CLightInfo::FromDict( const idDict *e ) {
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");
107 isParallel = e->GetBool("parallel");
109 if (!e->GetVector("_color", "", color)) {
110 color[0] = color[1] = color[2] = 1;
112 // windows needs 0-255 scale
117 if (e->GetVec4("fog", "", fogDensity)) {
123 if (e->GetVector("light_right","", lightRight)) {
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
133 VectorCopy(lightTarget, lightEnd);
136 explicitStartEnd = false;
137 // create a start a quarter of the way to the target
138 lightStart = lightTarget * 0.25;
139 VectorCopy(lightTarget, lightEnd);
143 if (e->GetVector("light_radius", "", lightRadius)) {
146 float radius = e->GetFloat("light");
150 lightRadius[0] = lightRadius[1] = lightRadius[2] = radius;
153 if (e->GetVector("light_center", "", lightCenter)) {
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 );
163 if ( kv->GetValue().Length() > 0 ) {
164 e->Set ( kv->GetKey() ,kv->GetValue() );
166 e->Delete ( kv->GetKey() );
169 common->Printf( "Applied difference: %s %s\n" , kv->GetKey().c_str() , kv->GetValue().c_str() );
173 //write all info to a dict, regardless of light type
174 void CLightInfo::ToDictWriteAllInfo( idDict *e ) {
175 e->Set("noshadows", (!castShadows) ? "1" : "0");
176 e->Set("nospecular", (!castSpecular) ? "1" : "0");
177 e->Set("nodiffuse", (!castDiffuse) ? "1" : "0");
179 e->SetFloat("falloff",fallOff);
181 if (strTexture.GetLength() > 0 ) {
182 e->Set("texture", strTexture);
187 e->SetVector("_color", temp);
190 e->Set("light_radius", va("%g %g %g", lightRadius[0], lightRadius[1], lightRadius[2]));
192 e->Set("light_radius", va("%g %g %g", lightRadius[0], lightRadius[0], lightRadius[0]));
195 e->Set("light_center", va("%g %g %g", lightCenter[0], lightCenter[1], lightCenter[2]));
196 e->Set("parallel", isParallel?"1":"0");
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]));
205 void CLightInfo::ToDict( idDict *e ) {
207 e->Delete("noshadows");
208 e->Delete("nospecular");
209 e->Delete("nodiffuse");
210 e->Delete("falloff");
211 e->Delete("parallel");
212 e->Delete("texture");
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");
224 e->Set("noshadows", (!castShadows) ? "1" : "0");
225 e->Set("nospecular", (!castSpecular) ? "1" : "0");
226 e->Set("nodiffuse", (!castDiffuse) ? "1" : "0");
228 e->SetFloat("falloff",fallOff);
230 if (strTexture.GetLength() > 0) {
231 e->Set("texture", strTexture);
236 e->SetVector("_color", temp);
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));
244 e->Set("light_radius", va("%g %g %g", lightRadius[0], lightRadius[1], lightRadius[2]));
246 e->Set("light_radius", va("%g %g %g", lightRadius[0], lightRadius[0], lightRadius[0]));
250 e->Set("light_center", va("%g %g %g", lightCenter[0], lightCenter[1], lightCenter[2]));
254 e->Set("parallel", "1");
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]));
267 CLightInfo::CLightInfo() {
273 /////////////////////////////////////////////////////////////////////////////
276 CLightDlg *g_LightDialog = NULL;
279 CLightDlg::CLightDlg(CWnd* pParent /*=NULL*/)
280 : CDialog(CLightDlg::IDD, pParent)
282 //{{AFX_DATA_INIT(CLightDlg)
283 m_bEqualRadius = FALSE;
284 m_bExplicitFalloff = FALSE;
285 m_bPointLight = FALSE;
286 m_bCheckProjected = FALSE;
316 m_bIsParallel = FALSE;
318 m_drawMaterial = new idGLDrawableMaterial();
321 CLightDlg::~CLightDlg() {
322 delete m_drawMaterial;
325 void CLightDlg::DoDataExchange(CDataExchange* pDX)
327 CDialog::DoDataExchange(pDX);
328 //{{AFX_DATA_MAP(CLightDlg)
329 if ( com_editorActive ) {
330 DDX_Control(pDX, IDC_LIGHTPREVIEW, m_wndPreview);
332 DDX_Control(pDX, IDC_COMBO_TEXTURE, m_wndLights);
333 DDX_Check(pDX, IDC_CHECK_EQUALRADIUS, m_bEqualRadius);
334 DDX_Check(pDX, IDC_CHECK_EXPLICITFALLOFF, m_bExplicitFalloff);
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);
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)
380 ON_CBN_SELCHANGE(IDC_COMBO_TEXTURE, OnSelchangeComboTexture)
381 ON_BN_CLICKED(IDC_CHECK_CENTER, OnCheckCenter)
382 ON_BN_CLICKED(IDC_CHECK_PARALLEL, OnCheckParallel)
386 /////////////////////////////////////////////////////////////////////////////
387 // CLightDlg message handlers
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);
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);
406 void CLightDlg::EnableControls() {
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);
437 reinterpret_cast<CButton*>(GetDlgItem(IDC_CHECK_PROJECTED))->SetCheck(!lightInfo.pointLight);
438 reinterpret_cast<CButton*>(GetDlgItem(IDC_CHECK_POINT))->SetCheck(lightInfo.pointLight);
443 void CLightDlg::UpdateDialogFromLightInfo( void ) {
444 m_hasCenter = lightInfo.hasCenter;
445 m_bEqualRadius = lightInfo.equalRadius;
446 m_bExplicitFalloff = lightInfo.explicitStartEnd;
447 m_bPointLight = lightInfo.pointLight;
448 m_bCheckProjected = !lightInfo.pointLight;
449 m_fFallloff = lightInfo.fallOff;
450 if (lightInfo.fallOff < 0.35) {
452 } else if (lightInfo.fallOff < 0.70) {
457 //m_bFog = lightInfo.fog;
458 m_bRotate = lightInfo.rotate;
459 m_bShadows = lightInfo.castShadows;
460 m_bSpecular = lightInfo.castSpecular;
461 //m_bStrobe = lightInfo.strobe;
462 //m_fStrobe = lightInfo.strobeSpeed;
463 int sel = m_wndLights.FindStringExact(-1, lightInfo.strTexture);
464 m_wndLights.SetCurSel(sel);
466 m_drawMaterial->setMedia(lightInfo.strTexture);
468 m_drawMaterial->setMedia(lightInfo.strTexture);
471 m_bDiffuse = lightInfo.castDiffuse;
472 m_fEndX = lightInfo.lightEnd[0];
473 m_fEndY = lightInfo.lightEnd[1];
474 m_fEndZ = lightInfo.lightEnd[2];
475 m_fRadiusX = lightInfo.lightRadius[0];
476 m_fRadiusY = lightInfo.lightRadius[1];
477 m_fRadiusZ = lightInfo.lightRadius[2];
478 m_fRightX = lightInfo.lightRight[0];
479 m_fRightY = lightInfo.lightRight[1];
480 m_fRightZ = lightInfo.lightRight[2];
481 //m_bRotate = lightInfo.rotate;
482 //m_fRotate = lightInfo.rotateSpeed;
483 m_fStartX = lightInfo.lightStart[0];
484 m_fStartY = lightInfo.lightStart[1];
485 m_fStartZ = lightInfo.lightStart[2];
486 m_fTargetX = lightInfo.lightTarget[0];
487 m_fTargetY = lightInfo.lightTarget[1];
488 m_fTargetZ = lightInfo.lightTarget[2];
489 m_fUpX = lightInfo.lightUp[0];
490 m_fUpY = lightInfo.lightUp[1];
491 m_fUpZ = lightInfo.lightUp[2];
492 VectorCopy(lightInfo.color, color);
493 //m_fFogAlpha = lightInfo.fogDensity[3];
494 m_centerX = lightInfo.lightCenter[0];
495 m_centerY = lightInfo.lightCenter[1];
496 m_centerZ = lightInfo.lightCenter[2];
498 //jhefty - added parallel light updating
499 m_bIsParallel = lightInfo.isParallel;
504 void CLightDlg::UpdateLightInfoFromDialog( void ) {
507 lightInfo.pointLight = ( m_bPointLight != FALSE );
508 lightInfo.equalRadius = ( m_bEqualRadius != FALSE );
509 lightInfo.explicitStartEnd = ( m_bExplicitFalloff != FALSE );
511 if (lightInfo.pointLight) {
512 if (m_nFalloff == 0) {
514 } else if (m_nFalloff == 1) {
521 lightInfo.fallOff = m_fFallloff;
523 //lightInfo.fog = m_bFog;
524 lightInfo.rotate = ( m_bRotate != FALSE );
525 lightInfo.castShadows = ( m_bShadows != FALSE );
526 lightInfo.castSpecular = ( m_bSpecular != FALSE );
528 VectorCopy(color, lightInfo.color);
529 lightInfo.isParallel = (m_bIsParallel == TRUE);
531 //lightInfo.fogDensity[3] = m_fFogAlpha;
533 //lightInfo.strobe = m_bStrobe;
534 //lightInfo.strobeSpeed = m_fStrobe;
535 //lightInfo.rotate = m_bRotate;
536 //lightInfo.rotateSpeed = m_fRotate;
538 int sel = m_wndLights.GetCurSel();
541 m_wndLights.GetLBText(sel, str);
543 lightInfo.strTexture = str;
545 lightInfo.castDiffuse = ( m_bDiffuse != FALSE );
546 lightInfo.lightEnd[0] = m_fEndX;
547 lightInfo.lightEnd[1] = m_fEndY;
548 lightInfo.lightEnd[2] = m_fEndZ;
549 lightInfo.lightRadius[0] = m_fRadiusX;
550 lightInfo.lightRadius[1] = m_fRadiusY;
551 lightInfo.lightRadius[2] = m_fRadiusZ;
552 lightInfo.lightRight[0] = m_fRightX;
553 lightInfo.lightRight[1] = m_fRightY;
554 lightInfo.lightRight[2] = m_fRightZ;
555 lightInfo.lightStart[0] = m_fStartX;
556 lightInfo.lightStart[1] = m_fStartY;
557 lightInfo.lightStart[2] = m_fStartZ;
558 lightInfo.lightTarget[0] = m_fTargetX;
559 lightInfo.lightTarget[1] = m_fTargetY;
560 lightInfo.lightTarget[2] = m_fTargetZ;
561 lightInfo.lightUp[0] = m_fUpX;
562 lightInfo.lightUp[1] = m_fUpY;
563 lightInfo.lightUp[2] = m_fUpZ;
565 lightInfo.hasCenter = ( m_hasCenter != FALSE );
566 lightInfo.lightCenter[0] = m_centerX;
567 lightInfo.lightCenter[1] = m_centerY;
568 lightInfo.lightCenter[2] = m_centerZ;
571 void CLightDlg::SaveLightInfo( const idDict *differences ) {
573 if ( com_editorActive ) {
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 ) {
579 lightInfo.ToDictFromDifferences( &b->owner->epairs, differences );
581 lightInfo.ToDict( &b->owner->epairs );
590 idList<idEntity *> list;
593 int count = gameEdit->GetSelectedEntities( list.Ptr(), list.Num() );
594 list.SetNum( count );
596 for ( int i = 0; i < count; i++ ) {
598 gameEdit->EntityChangeSpawnArgs( list[i], differences );
599 gameEdit->EntityUpdateChangeableSpawnArgs( list[i], NULL );
602 lightInfo.ToDict( &newArgs );
603 gameEdit->EntityChangeSpawnArgs( list[i], &newArgs );
604 gameEdit->EntityUpdateChangeableSpawnArgs( list[i], NULL );
606 gameEdit->EntityUpdateVisuals( list[i] );
611 void CLightDlg::ColorButtons() {
616 CButton *pBtn = (CButton *)GetDlgItem(IDC_BTN_COLOR);
617 pBtn->GetClientRect(&r);
618 colorBitmap.DeleteObject();
619 colorBitmap.CreateCompatibleBitmap(&dc, r.Width(), r.Height());
621 MemDC.CreateCompatibleDC(&dc);
622 CBitmap *pOldBmp = MemDC.SelectObject(&colorBitmap);
624 CBrush br(RGB(color[0], color[1], color[2]));
625 MemDC.FillRect(r,&br);
627 dc.SelectObject(pOldBmp);
628 pBtn->SetBitmap(HBITMAP(colorBitmap));
632 void CLightDlg::LoadLightTextures() {
633 int count = declManager->GetNumDecls( DECL_MATERIAL );
635 const idMaterial *mat;
636 for (i = 0; i < count; i++) {
637 mat = declManager->MaterialByIndex(i, false);
638 idStr str = mat->GetName();
640 if (str.Icmpn("lights/", strlen("lights/")) == 0 || str.Icmpn("fogs/", strlen("fogs/")) == 0) {
641 m_wndLights.AddString(mat->GetName());
646 BOOL CLightDlg::OnInitDialog()
648 CDialog::OnInitDialog();
650 com_editors |= EDITOR_LIGHT;
652 UpdateDialog( true );
656 if ( com_editorActive ) {
657 m_wndPreview.setDrawable(m_drawMaterial);
660 return TRUE; // return TRUE unless you set the focus to a control
661 // EXCEPTION: OCX Property Pages should return FALSE
664 void CLightDlg::OnDestroy() {
666 com_editors &= ~EDITOR_LIGHT;
668 return CDialog::OnDestroy();
671 void CLightDlg::OnBtnTexture()
673 // TODO: Add your control notification handler code here
677 void CLightDlg::OnCheckEqualradius()
679 lightInfo.equalRadius = ( reinterpret_cast<CButton*>(GetDlgItem(IDC_CHECK_EQUALRADIUS))->GetCheck() != 0 );
683 void CLightDlg::OnCheckExplicitfalloff()
685 lightInfo.explicitStartEnd = ( reinterpret_cast<CButton*>(GetDlgItem(IDC_CHECK_EXPLICITFALLOFF))->GetCheck() != 0 );
689 void CLightDlg::OnCheckPoint()
691 lightInfo.DefaultPoint();
692 UpdateDialogFromLightInfo();
696 void CLightDlg::OnCheckProjected()
698 lightInfo.DefaultProjected();
699 UpdateDialogFromLightInfo();
703 void CLightDlg::OnRadioFalloff()
707 void CLightDlg::OnOK() {
708 UpdateLightInfoFromDialog();
709 SaveLightInfo( NULL );
710 Sys_UpdateWindows(W_ALL);
714 entity_t *SingleLightSelected() {
715 if ( QE_SingleBrush( true, true ) ) {
716 brush_t *b = selected_brushes.next;
717 if ( ( b->owner->eclass->nShowFlags & ECLASS_LIGHT ) && !b->entityModel ) {
724 void CLightDlg::UpdateDialog( bool updateChecks )
728 lightInfo.Defaults();
729 lightInfoOriginal.Defaults ();
731 if ( com_editorActive ) {
733 entity_t *e = SingleLightSelected();
735 lightInfo.FromDict(&e->epairs);
736 lightInfoOriginal.FromDict(&e->epairs); //our original copy of the values that we compare against for apply differences
737 title = "Light Editor";
739 //find the last brush belonging to the last entity selected and use that as the source
741 for ( brush_t *b = selected_brushes.next ; b != &selected_brushes ; b = b->next ) {
742 if ( ( b->owner->eclass->nShowFlags & ECLASS_LIGHT ) && !b->entityModel ) {
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)";
753 title = "Light Editor - (No lights selected)";
758 idList<idEntity *> list;
761 int count = gameEdit->GetSelectedEntities( list.Ptr(), list.Num() );
762 list.SetNum( count );
765 lightInfo.FromDict( gameEdit->EntityGetSpawnArgs( list[count-1] ) );
766 title = "Light Editor";
768 title = "Light Editor - (No entities selected)";
772 SetWindowText( title );
774 UpdateDialogFromLightInfo();
777 if ( updateChecks ) {
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" );
789 if ( g_LightDialog == NULL ) {
791 g_LightDialog = new CLightDlg();
794 if ( g_LightDialog->GetSafeHwnd() == NULL ) {
795 g_LightDialog->Create( IDD_DIALOG_LIGHT );
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);
803 idKeyInput::ClearStates();
805 g_LightDialog->ShowWindow( SW_SHOW );
806 g_LightDialog->SetFocus();
807 g_LightDialog->UpdateDialog( true );
810 // FIXME: select light based on spawn args
814 void LightEditorRun( void ) {
816 MSG *msg = AfxGetCurrentMessage(); // TODO Robert fix me!!
818 MSG *msg = &m_msgCur;
821 while( ::PeekMessage(msg, NULL, NULL, NULL, PM_NOREMOVE) ) {
823 if ( !AfxGetApp()->PumpMessage() ) {
828 void LightEditorShutdown( void ) {
829 delete g_LightDialog;
830 g_LightDialog = NULL;
833 void UpdateLightInspector() {
834 if ( g_LightDialog && g_LightDialog->GetSafeHwnd() != NULL ) {
835 g_LightDialog->UpdateDialog(true); //jhefty - update ALL info about the light, including check boxes
839 void CLightDlg::OnApply() {
840 UpdateLightInfoFromDialog();
841 SaveLightInfo( NULL );
842 Sys_UpdateWindows( W_ALL );
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 );
850 void CLightDlg::UpdateColor( float r, float g, float b, float a ) {
855 UpdateLightInfoFromDialog();
856 SaveLightInfo( NULL );
857 Sys_UpdateWindows( W_CAMERA );
860 void CLightDlg::OnBtnColor() {
866 if ( DoNewColor( &r, &g, &b, &ob, UpdateLightDialog ) ) {
874 void CLightDlg::OnCancel() {
878 HBRUSH CLightDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
880 HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
885 BOOL CLightDlg::DestroyWindow()
891 SaveRegistryInfo("Radiant::LightWindow", &rct, sizeof(rct));
893 return CDialog::DestroyWindow();
896 void CLightDlg::OnSelchangeComboTexture()
899 int sel = m_wndLights.GetCurSel();
902 m_wndLights.GetLBText(sel, str);
903 m_drawMaterial->setMedia(str);
904 if ( com_editorActive ) {
905 m_wndPreview.RedrawWindow();
908 Sys_UpdateWindows(W_ALL);
911 void CLightDlg::OnCheckCenter()
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;
919 lightInfo.hasCenter = false;
920 lightInfo.lightCenter.Zero();
922 UpdateDialogFromLightInfo();
926 void CLightDlg::OnCheckParallel() {
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;
934 lightInfo.isParallel = false;
935 lightInfo.hasCenter = false;
938 UpdateDialogFromLightInfo();
942 //jhefty - only apply settings that are different
943 void CLightDlg::OnApplyDifferences () {
944 idDict differences, modified, original;
946 UpdateLightInfoFromDialog();
948 lightInfo.ToDict( &modified );
949 lightInfoOriginal.ToDictWriteAllInfo( &original );
951 differences = modified;
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() );
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() );
964 SaveLightInfo( &differences );
966 lightInfoOriginal.FromDict( &modified );
968 Sys_UpdateWindows( W_ALL );