📄 keyeditdlg.cpp
字号:
/****************************************************************************************/
/* KeyEditDlg.cpp */
/* */
/* Author: Jim Mischel */
/* Description: This file contains all of the dialogs that edit entity properties. */
/* KeyEditDlg is subclassed to edit strings, ints, and floats. */
/* */
/* 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.5, Dec. 15, 2000 */
/****************************************************************************************/
#include "stdafx.h"
#include "Globals.h"
#include "KeyEditDlg.h"
#include <assert.h>
#include "ram.h"
#include "util.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CKeyEditDlg dialog
CKeyEditDlg::CKeyEditDlg(CWnd* pParent, CString const KeyS, CString *pValS)
: CDialog(CKeyEditDlg::IDD, pParent),
Key(KeyS), pValue(pValS)
{
//{{AFX_DATA_INIT(CKeyEditDlg)
//}}AFX_DATA_INIT
}
void CKeyEditDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CKeyEditDlg)
DDX_Control(pDX, IDC_VALUE_EDIT, m_ValueEdit);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CKeyEditDlg, CDialog)
//{{AFX_MSG_MAP(CKeyEditDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CKeyEditDlg message handlers
BOOL CKeyEditDlg::OnInitDialog()
{
CDialog::OnInitDialog();
this->SetWindowText (Key);
m_ValueEdit.SetWindowText (*pValue);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CKeyEditDlg::OnOK()
{
CString Text;
m_ValueEdit.GetWindowText (Text);
// don't allow quotes in the string...
if (strchr (Text, '"') == NULL)
{
*pValue = Text;
CDialog::OnOK();
}
}
CColorKeyEditDlg::CColorKeyEditDlg
(
CWnd *pParent,
CString const KeyS,
CString *pValS
) : CColorDialog (0, (CC_ANYCOLOR | CC_FULLOPEN), pParent),
Key(KeyS), pValue(pValS)
{
// create RGB color...
int r, g, b;
r = 0;
g = 0;
b = 0;
sscanf (*pValS, "%d %d %d", &r, &g, &b);
this->m_cc.rgbResult = RGB (r, g, b);
this->m_cc.Flags |= CC_RGBINIT;
}
BOOL CColorKeyEditDlg::OnInitDialog
(
void
)
{
CColorDialog::OnInitDialog ();
this->SetWindowText (Key);
return TRUE;
}
int CColorKeyEditDlg::DoModal
(
void
)
{
/*
The MFC documentation for CColorDialog is incorrect.
It states that the selected color is available (through
GetColor()) when OnColorOK is fired. Not true. The only
way I could get the color was to do it at the end of DoModal.
*/
int rslt = CColorDialog::DoModal ();
COLORREF TheColor;
int r, g, b;
TheColor = this->GetColor ();
r = GetRValue (TheColor);
g = GetGValue (TheColor);
b = GetBValue (TheColor);
pValue->Format ("%d %d %d", r, g, b);
return rslt;
}
//////////////////
// CIntKeyEditDlg
CIntKeyEditDlg::CIntKeyEditDlg
(
CWnd* pParent,
CString const KeyS,
CString *pValS
) : CKeyEditDlg (pParent, KeyS, pValS)
{
}
void CIntKeyEditDlg::OnOK
(
void
)
{
CString Text;
int TheInt;
this->m_ValueEdit.GetWindowText (Text);
if (Util_IsValidInt (Text, &TheInt))
{
// in case it was a hex number
// convert int to text and set...
Text.Format ("%d", TheInt);
m_ValueEdit.SetWindowText (Text);
CKeyEditDlg::OnOK ();
}
else
{
m_ValueEdit.SetSel (0, -1, TRUE);
}
}
//////////////////
// CFloatKeyEditDlg
CFloatKeyEditDlg::CFloatKeyEditDlg
(
CWnd* pParent,
CString const KeyS,
CString *pValS
) : CKeyEditDlg (pParent, KeyS, pValS)
{
}
void CFloatKeyEditDlg::OnOK
(
void
)
{
CString Text;
float TheFloat;
this->m_ValueEdit.GetWindowText (Text);
if (Util_IsValidFloat (Text, &TheFloat))
{
CKeyEditDlg::OnOK ();
}
else
{
m_ValueEdit.SetSel (0, -1, TRUE);
}
}
static BOOL ValidateFloat
(
CEdit &EditControl
)
{
float TheFloat;
CString Text;
EditControl.GetWindowText (Text);
if (!Util_IsValidFloat (Text, &TheFloat))
{
EditControl.SetSel (0, -1, TRUE);
EditControl.SetFocus ();
return FALSE;
}
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CPointKeyEditDlg dialog
CPointKeyEditDlg::CPointKeyEditDlg(CWnd* pParent, CString const KeyS, CString *pValS)
: CDialog(CPointKeyEditDlg::IDD, pParent),
Key(KeyS), pValue(pValS)
{
//{{AFX_DATA_INIT(CPointKeyEditDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CPointKeyEditDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPointKeyEditDlg)
DDX_Control(pDX, IDC_ZEDIT, m_ZEdit);
DDX_Control(pDX, IDC_YEDIT, m_YEdit);
DDX_Control(pDX, IDC_XEDIT, m_XEdit);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPointKeyEditDlg, CDialog)
//{{AFX_MSG_MAP(CPointKeyEditDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPointKeyEditDlg message handlers
void CPointKeyEditDlg::OnOK()
{
if (ValidateFloat (m_XEdit) &&
ValidateFloat (m_YEdit) &&
ValidateFloat (m_ZEdit))
{
CString cx, cy, cz;
m_XEdit.GetWindowText (cx);
m_YEdit.GetWindowText (cy);
m_ZEdit.GetWindowText (cz);
pValue->Format ("%s %s %s", cx, cy, cz);
CDialog::OnOK ();
}
}
BOOL CPointKeyEditDlg::OnInitDialog()
{
CDialog::OnInitDialog();
static char *Zero = "0.0";
char *c;
char *temp;
this->SetWindowText (Key);
temp = Util_Strdup (*pValue);
c = strtok (temp, " ");
if (c == NULL)
{
c = Zero;
}
m_XEdit.SetWindowText (c);
c = strtok (NULL, " ");
if (c == NULL)
{
c = Zero;
}
m_YEdit.SetWindowText (c);
c = strtok (NULL, " ");
if (c == NULL)
{
c = Zero;
}
m_ZEdit.SetWindowText (c);
geRam_Free (temp);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
/////////////////////////////////////////////////////////////////////////////
// CStructKeyEditDlg dialog
CStructKeyEditDlg::CStructKeyEditDlg
(
CWnd* pParent,
CEntity const &aEnt,
CString const KeyS,
CEntityArray *Ents,
CString *pValS,
const EntityTable *pEntTable
) : CDialog(CStructKeyEditDlg::IDD, pParent),
Ent(aEnt), Key(KeyS), mEntityArray(Ents),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -