⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 faceattributesdialog.cpp

📁 3D游戏场景编辑器
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/****************************************************************************************/
/*  FaceAttributesDialog.cpp                                                            */
/*                                                                                      */
/*  Author:       Jim Mischel, Ken Baird, Jeff Lomax, John Moore                        */
/*  Description:  Face flag UI                                                          */
/*                                                                                      */
/*  The contents of this file are subject to the Genesis3D Public License               */
/*  Version 1.01 (the "License"); you may not use this file except in                   */
/*  compliance with the License. You may obtain a copy of the License at                */
/*  http://www.genesis3d.com                                                            */
/*                                                                                      */
/*  Software distributed under the License is distributed on an "AS IS"                 */
/*  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See                */
/*  the License for the specific language governing rights and limitations              */
/*  under the License.                                                                  */
/*                                                                                      */
/*  The Original Code is Genesis3D, released March 25, 1999.                            */
/*Genesis3D Version 1.1 released November 15, 1999                            */
/*  Copyright (C) 1999 WildTangent, Inc. All Rights Reserved           */
/*                                                                                      */
/*  Modified by Tom Morris for GenEdit-Classic ver. 0.55, Jan. 10, 2001					*/
/****************************************************************************************/
#include "stdafx.h"
#include "Globals.h"
#include "FaceAttributesDialog.h"



#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define MIN_TEX_OFF	-256
#define MAX_TEX_OFF	256
#define MIN_TEX_SCL	-20
#define MAX_TEX_SCL	20
#define MIN_TEX_ANG	-359
#define MAX_TEX_ANG	359

#define UNIT_OFFSET_INCR	1
#define UNIT_SCALE_INCR	0.05f
#define UNIT_ANGLE_INCR	1


// This table keeps track of the latest selection used in the combo box
// so that it can be set correctly when the dialog is closed and re-opened.
static int ComboBoxSelections[][2] = 
	{
		{IDC_CBXOFFSET, 2},
		{IDC_CBYOFFSET, 2},
		{IDC_CBXSCALE, 2},
		{IDC_CBYSCALE, 2},
		{IDC_CBXLIGHTSCALE, 2},
		{IDC_CBYLIGHTSCALE, 2},
		{IDC_CBANGLE, 2}
	};
static int nComboSelections = sizeof (ComboBoxSelections) / (2*sizeof (int));

static int GetComboSelection (const CComboBox &Combo)
{
	int CtrlId = Combo.GetDlgCtrlID ();

	for (int i = 0; i < nComboSelections; ++i)
	{
		if (ComboBoxSelections[i][0] == CtrlId)
		{
			return ComboBoxSelections[i][1];
		}
	}
	return 0;
}
/*
static void SetComboSelection (const CComboBox &Combo)
{
	int CtrlId = Combo.GetDlgCtrlID ();

	for (int i = 0; i < nComboSelections; ++i)
	{
		if (ComboBoxSelections[i][0] == CtrlId)
		{
			ComboBoxSelections[i][1] = Combo.GetCurSel ();
			return;
		}
	}
}
*/


typedef struct
{
	char *Text;
	float val; 
} ComboBoxItem;



static void FillComboBox (CComboBox &Combo, const ComboBoxItem Items[], int nItems)
{
	int i;

	Combo.ResetContent ();
	for (i = 0; i < nItems; ++i)
	{
		int Index;

		Index = Combo.AddString (Items[i].Text);
		if ((Index != CB_ERR) && (Index != CB_ERRSPACE))
		{
			// this big ugly cast lets us store a float in a DWORD.
			Combo.SetItemData (Index, *((DWORD *)&(Items[i].val)));
		}
	}

	Combo.SetCurSel (::GetComboSelection (Combo));
}



//CFaceAttributesDialog::CFaceAttributesDialog(CGenEditDoc* pGenEditDoc, CWnd* pParent) // old gedit
CFaceAttributesDialog::CFaceAttributesDialog(CWnd* pParent  /*=NULL*/)	// new g3dc
	: CDialog(CFaceAttributesDialog::IDD, pParent)
{	
	//{{AFX_DATA_INIT(CFaceAttributesDialog)
	m_TextureYScale = 1.0;
	m_TextureXScale = 1.0;
	m_TextureYOffset = 0;
	m_TextureXOffset = 0;
	m_TextureAngle = 0.0;
	m_FullBright = FALSE;
	m_Light = FALSE;
	m_Mirror = FALSE;
	m_Sky = FALSE;
	m_LightXScale = 0.0f;
	m_LightYScale = 0.0f;
	m_LightIntensity = 0;
	m_Flat = FALSE;
	m_Gouraud = FALSE;
	m_MipMapBias = 1.0f;
	m_TextureLock = FALSE;
	m_Reflectivity = 1.0f;
	m_Translucency = 255.0f;
	m_Transparent = FALSE;
	//}}AFX_DATA_INIT


	CDialog::Create(IDD,pParent);

//	m_pDoc = CGlobals::GetActiveDocument();

	SetupDialog();
}

void CFaceAttributesDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFaceAttributesDialog)
	DDX_Control(pDX, IDC_FACETRANSLUCENCY, m_EditTranslucency);
	DDX_Control(pDX, IDC_REFLECTIVITY, m_EditReflectivity);
	DDX_Control(pDX, IDC_MIPMAPBIAS, m_EditMipMapBias);
	DDX_Control(pDX, IDC_FACELIGHTINTENSITY, m_EditLightIntensity);
	DDX_Control(pDX, IDC_CBYLIGHTSCALE, m_ComboYLightScale);
	DDX_Control(pDX, IDC_CBXLIGHTSCALE, m_ComboXLightScale);
	DDX_Control(pDX, IDC_EDITYLIGHTSCALE, m_EditLightYScale);
	DDX_Control(pDX, IDC_EDITXLIGHTSCALE, m_EditLightXScale);
	DDX_Control(pDX, IDC_EDITANGLE, m_EditAngle);
	DDX_Control(pDX, IDC_EDITYSCALE, m_EditYScale);
	DDX_Control(pDX, IDC_EDITXSCALE, m_EditXScale);
	DDX_Control(pDX, IDC_EDITYOFFSET, m_EditYOffset);
	DDX_Control(pDX, IDC_EDITXOFFSET, m_EditXOffset);
	DDX_Control(pDX, IDC_CBXOFFSET, m_ComboXOffset);
	DDX_Control(pDX, IDC_CBYOFFSET, m_ComboYOffset);
	DDX_Control(pDX, IDC_CBXSCALE, m_ComboXScale);
	DDX_Control(pDX, IDC_CBYSCALE, m_ComboYScale);
	DDX_Control(pDX, IDC_CBANGLE, m_ComboAngle);
	DDX_Text(pDX, IDC_EDITYSCALE, m_TextureYScale);
	DDX_Text(pDX, IDC_EDITXSCALE, m_TextureXScale);
	DDX_Text(pDX, IDC_EDITYOFFSET, m_TextureYOffset);
	DDX_Text(pDX, IDC_EDITXOFFSET, m_TextureXOffset);
	DDX_Text(pDX, IDC_EDITANGLE, m_TextureAngle);
	DDV_MinMaxDouble(pDX, m_TextureAngle, -359.0, 359.0);
	DDX_Check(pDX, IDC_FACEFULLBRIGHT, m_FullBright);
	DDX_Check(pDX, IDC_FACELIGHT, m_Light);
	DDX_Check(pDX, IDC_FACEMIRROR, m_Mirror);
	DDX_Check(pDX, IDC_FACESKY, m_Sky);
	DDX_Text(pDX, IDC_EDITXLIGHTSCALE, m_LightXScale);
	DDX_Text(pDX, IDC_EDITYLIGHTSCALE, m_LightYScale);
	DDX_Text(pDX, IDC_FACELIGHTINTENSITY, m_LightIntensity);
	DDV_MinMaxInt(pDX, m_LightIntensity, 0, 999999);
	DDX_Check(pDX, IDC_FACEFLAT, m_Flat);
	DDX_Check(pDX, IDC_FACEGOURAUD, m_Gouraud);
	DDX_Text(pDX, IDC_MIPMAPBIAS, m_MipMapBias);
	DDX_Check(pDX, IDC_TEXTURELOCK, m_TextureLock);
	DDX_Text(pDX, IDC_REFLECTIVITY, m_Reflectivity);
	DDX_Text(pDX, IDC_FACETRANSLUCENCY, m_Translucency);
	DDX_Check(pDX, IDC_TRANSPARENT, m_Transparent);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CFaceAttributesDialog, CDialog)
	//{{AFX_MSG_MAP(CFaceAttributesDialog)
	ON_WM_VSCROLL()
	ON_EN_CHANGE(IDC_EDITXOFFSET, OnChangeXOffset)
	ON_EN_KILLFOCUS(IDC_EDITXOFFSET, OnKillfocusXOffset)
	ON_EN_CHANGE(IDC_EDITYOFFSET, OnChangeYOffset)
	ON_EN_KILLFOCUS(IDC_EDITYOFFSET, OnKillfocusYOffset)
	ON_EN_CHANGE(IDC_EDITXSCALE, OnChangeXScale)
	ON_EN_KILLFOCUS(IDC_EDITXSCALE, OnKillfocusXScale)
	ON_EN_CHANGE(IDC_EDITYSCALE, OnChangeYScale)
	ON_EN_KILLFOCUS(IDC_EDITYSCALE, OnKillfocusYScale)
	ON_EN_CHANGE(IDC_EDITANGLE, OnChangeAngle)
	ON_EN_KILLFOCUS(IDC_EDITANGLE, OnKillfocusAngle)
	ON_BN_CLICKED(IDC_FLIPVERTICAL, OnFlipvertical)
	ON_BN_CLICKED(IDC_FLIPHORIZONTAL, OnFliphorizontal)
	ON_WM_ACTIVATE()
	ON_EN_CHANGE(IDC_EDITXLIGHTSCALE, OnChangeEditxlightscale)
	ON_EN_KILLFOCUS(IDC_EDITXLIGHTSCALE, OnKillfocusEditxlightscale)
	ON_EN_CHANGE(IDC_EDITYLIGHTSCALE, OnChangeEditylightscale)
	ON_EN_KILLFOCUS(IDC_EDITYLIGHTSCALE, OnKillfocusEditylightscale)
	ON_BN_CLICKED(IDC_FACEMIRROR, OnFacemirror)
	ON_BN_CLICKED(IDC_FACESKY, OnFacesky)
	ON_BN_CLICKED(IDC_FACEFULLBRIGHT, OnFacefullbright)
	ON_EN_KILLFOCUS(IDC_FACELIGHTINTENSITY, OnKillfocusFacelightintensity)
	ON_BN_CLICKED(IDC_FACEGOURAUD, OnFacegouraud)
	ON_BN_CLICKED(IDC_FACEFLAT, OnFaceflat)
	ON_EN_KILLFOCUS(IDC_MIPMAPBIAS, OnKillfocusMipmapbias)
	ON_BN_CLICKED(IDC_TEXTURELOCK, OnTexturelock)
	ON_EN_KILLFOCUS(IDC_REFLECTIVITY, OnKillfocusReflectivity)
	ON_EN_KILLFOCUS(IDC_FACETRANSLUCENCY, OnKillfocusFacetranslucency)
	ON_BN_CLICKED(IDC_TRANSPARENT, OnTransparent)
	ON_BN_CLICKED(IDC_FACE_APPLYBTN, OnFaceApplybtn)
	ON_BN_CLICKED(ID_DEFAULTS, OnResetAll)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFaceAttributesDialog message handlers


BOOL CFaceAttributesDialog::OnInitDialog()
{
	m_pDoc = CGlobals::GetActiveDocument();
	
	m_pDoc->mpMainFrame->HideAllPropDialogsBut(this);

	pFace = NULL;	
	
//	UpdatePolygonFocus (pFace);			// Update dialog members from face

	SetWindowPos(NULL,5,10,0,0,SWP_NOZORDER|SWP_NOSIZE);
	this->ShowWindow(SW_SHOW);


	GetDlgItem( IDC_FACELIGHTINTENSITY )->EnableWindow( m_Light ) ;

	UpdateData (FALSE);
	CDialog::OnInitDialog();



	return TRUE;
}


bool CFaceAttributesDialog::UpdateFaceAttributes(CGenEditDoc *pDoc, Face *pFace)
{
	if (pDoc != m_pDoc)
		AfxMessageBox("pDoc != m_pDoc in UpdateFaceAttributes");

	if (m_pDoc != NULL)
	{
		UpdatePolygonFocus (pFace);			// Update dialog members from face
//		SetupDialog ();		//	no no no don't put that thang here.



//		GetDlgItem( IDC_FACELIGHTINTENSITY )->EnableWindow( m_Light ) ;

				//	Restore focus to active view so arrow keys work
				//	for cycling through individual faces

				//	Restore focus to active view
	CMDIChildWnd *pMDIChild	=(CMDIChildWnd *)pDoc->mpMainFrame->MDIGetActive();
	if(pMDIChild)
	{
		CView	*cv	=(CView *)pMDIChild->GetActiveView();
		if( cv)
			cv->SetFocus() ;
	}


		UpdateData (FALSE);

	}

	return true;
}


void CFaceAttributesDialog::ShowDialog()
{
	SetWindowPos(NULL,5,10,0,0,SWP_NOZORDER|SWP_NOSIZE);
	this->ShowWindow(SW_SHOW);

}




void CFaceAttributesDialog::SetupDialog()
{

	// Fill combo boxes with proper data and set accordingly
	static const ComboBoxItem OffsetValues[] =
	{
		{"4", 4.0f},
		{"8", 8.0f},
		{"16", 16.0f},
		{"32", 32.0f},
		{"64", 64.0f},
		{"128", 128.0f}
	};
	static const int nOffsetItems = sizeof (OffsetValues) / sizeof (ComboBoxItem);

	static const ComboBoxItem ScaleValues[] =
	{
		"0.1", 0.1f,
		"0.2", 0.2f,
		"0.5", 0.5f,
		"0.75", 0.75f,
		"1.0", 1.0f,
		"2.0", 2.0f
	};
	static const int nScaleItems = sizeof (ScaleValues) / sizeof (ComboBoxItem);

	static const ComboBoxItem AngleValues[] =
	{
		"5", 5.0f,
		"10", 10.0f,
		"15", 15.0f,
		"30", 30.0f,
		"45", 45.0f,
		"90", 90.0f
	};
	static const int nAngleItems = sizeof (AngleValues) / sizeof (ComboBoxItem);

	FillComboBox (m_ComboXOffset, OffsetValues, nOffsetItems);
	FillComboBox (m_ComboYOffset, OffsetValues, nOffsetItems);
	FillComboBox (m_ComboXScale, ScaleValues, nScaleItems);
	FillComboBox (m_ComboYScale, ScaleValues, nScaleItems);
	FillComboBox (m_ComboXLightScale, ScaleValues, nScaleItems);
	FillComboBox (m_ComboYLightScale, ScaleValues, nScaleItems);
	FillComboBox (m_ComboAngle, AngleValues, nAngleItems);
}





void CFaceAttributesDialog::AssignFaceValues (Face *pFace)
{
	Face_SetLight (pFace, m_Light);
	Face_SetFullBright (pFace, m_FullBright);
	Face_SetGouraud (pFace, m_Gouraud);
	Face_SetFlat (pFace, m_Flat);
	Face_SetTextureLock (pFace, m_TextureLock);
	Face_SetTransparent (pFace, m_Transparent);
	Face_SetSky (pFace, m_Sky);
	Face_SetMirror (pFace, m_Mirror);
	Face_SetTextureRotate (pFace, (geFloat)m_TextureAngle);
	Face_SetTextureShift (pFace, m_TextureXOffset, m_TextureYOffset);
	Face_SetTextureScale (pFace, m_TextureXScale, m_TextureYScale);
	Face_SetLightScale (pFace, m_LightXScale, m_LightYScale);
	Face_SetLightIntensity (pFace, m_LightIntensity) ;
	Face_SetMipMapBias (pFace, m_MipMapBias);
	Face_SetTranslucency (pFace, m_Translucency);
	Face_SetReflectivity (pFace, m_Reflectivity);
}

static geBoolean AssignFaceValues (Face *pFace, void *lParam)
{
	CFaceAttributesDialog *pDlg = (CFaceAttributesDialog *)lParam;

	pDlg->AssignFaceValues (pFace);
	return GE_TRUE;
}

void CFaceAttributesDialog::OnResetAll() 
{
	if (m_pDoc == NULL)
		m_pDoc = CGlobals::GetActiveDocument();

	UpdateData(TRUE);

	m_TextureXOffset = 0;
	m_TextureYOffset = 0;
	m_TextureAngle = 0.0f;

	m_TextureXScale = 1.0f;
	m_TextureYScale = 1.0f;
	m_LightXScale = 2.0f;
	m_LightYScale = 2.0f;

	m_Mirror = FALSE;
	m_FullBright = FALSE;
	m_Gouraud = FALSE;
	m_Flat = FALSE;
	m_TextureLock = FALSE;
	m_Transparent = FALSE;
	m_Sky = FALSE;
	m_Light = FALSE;
	m_LightIntensity = 0;
	m_MipMapBias = 1.0f;
	m_Reflectivity = 1.0f;
	m_Translucency = 255.0f;

	UpdateData(FALSE);

	SelFaceList_Enum (m_pDoc->pSelFaces, ::AssignFaceValues, this);

	AssignCurrentToViews();
}

float CFaceAttributesDialog::DoIncrement (float v, float incr, float vMin, float vMax, int nSBCode)
{
	if (nSBCode == SB_LINEUP)
	{
		v += incr;
	}
	else
	{
		v -= incr;
	}

	if (v < vMin)
	{
		v = vMin;
	}
	if (v > vMax)
	{
		v = vMax;
	}
	return v;
}


float CFaceAttributesDialog::GetIncrement (CComboBox &combo)
{
	int CurSel;
	DWORD d;

	CurSel = combo.GetCurSel ();
	if (CurSel == CB_ERR)
	{
		return 1.0f;
	}
	d = combo.GetItemData (CurSel);
	return *((float *)&d);
}


#pragma warning (disable:4100)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -