home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Anthology
/
aDELPHI.iso
/
ActiveX
/
3DText_ActiveX_v3.1-FCN
/
data1.cab
/
Example_Files
/
3DText
/
Vc
/
VC3DTextDemoDlg.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1999-10-27
|
19KB
|
645 lines
// VCGLTextDemoDlg.cpp : implementation file
//
#include "stdafx.h"
#include <atlconv.h>
#include <Afxctl.h>
#include "NFont.h"
#include "VC3DTextDemo.h"
#include "VC3DTextDemoDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
using namespace N3DTEXTLib;
/////////////////////////////////////////////////////////////////////////////
// some useful macro definitions
#define BOOL_TO_VAR(x) ( (x) ? VARIANT_TRUE : VARIANT_FALSE)
#define VAR_TO_BOOL(x) (x == VARIANT_TRUE)
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CVCGLTextDemoDlg dialog
CVCGLTextDemoDlg::CVCGLTextDemoDlg(CWnd* pParent /*=NULL*/)
: CDialog(CVCGLTextDemoDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CVCGLTextDemoDlg)
m_sElevation = _T("");
m_sExtrusion = _T("");
m_sLineSpacing = _T("");
m_sRotation = _T("");
m_sText = _T("");
m_sZoom = _T("");
m_bEnableLightning = FALSE;
m_bEnableMouse = FALSE;
m_bOrtographicProjection = FALSE;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
//////////////////////////////////////////////////////////////////////
void CVCGLTextDemoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CVCGLTextDemoDlg)
DDX_Text(pDX, IDC_ELEVATION_EDIT, m_sElevation);
DDX_Text(pDX, IDC_EXTRUSION_EDIT, m_sExtrusion);
DDX_Text(pDX, IDC_LINE_SPACING_EDIT, m_sLineSpacing);
DDX_Text(pDX, IDC_ROTATION_EDIT, m_sRotation);
DDX_Text(pDX, IDC_TEXT_EDIT, m_sText);
DDX_Text(pDX, IDC_ZOOM_EDIT, m_sZoom);
DDX_Check(pDX, IDC_ENABLE_LIGHTNING_CHECK, m_bEnableLightning);
DDX_Check(pDX, IDC_ENABLE_MOUSE_CHECK, m_bEnableMouse);
DDX_Check(pDX, IDC_ORTOGRAPHIC_PROJECTION_CHECK, m_bOrtographicProjection);
//}}AFX_DATA_MAP
}
//////////////////////////////////////////////////////////////////////
BEGIN_MESSAGE_MAP(CVCGLTextDemoDlg, CDialog)
//{{AFX_MSG_MAP(CVCGLTextDemoDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_ABOUT_BUTTON, OnAboutButton)
ON_BN_CLICKED(ID_ARIAL_FONT_BUTTON, OnArialFontButton)
ON_BN_CLICKED(ID_CURRIER_NEW_FONT_BUTTON, OnCurrierNewFontButton)
ON_BN_CLICKED(IDC_ANIMATE_ROTATEXY_BUTTON, OnAnimateRotatexyButton)
ON_BN_CLICKED(IDC_ANIMATE_ROTATEZ_BUTTON, OnAnimateRotatezButton)
ON_BN_CLICKED(IDC_ENABLE_MOUSE_CHECK, OnEnableMouseCheck)
ON_BN_CLICKED(IDC_GRADIENT_BUTTON, OnGradientButton)
ON_BN_CLICKED(ID_TEXTURE_BUTTON, OnTextureButton)
ON_BN_CLICKED(IDC_BK_FILL_EFFECT_BUTTON, OnBkFillEffectButton)
ON_BN_CLICKED(IDC_ENABLE_LIGHTNING_CHECK, OnEnableLightningCheck)
ON_BN_CLICKED(IDC_FILL_EFFECT_BUTTON, OnFillEffectButton)
ON_BN_CLICKED(IDC_MATERIAL_BUTTON, OnMaterialButton)
ON_BN_CLICKED(ID_SOLID_COLOR_BUTTON, OnSolidColorButton)
ON_BN_CLICKED(IDC_ANIMATED_TEXTURE_BUTTON, OnAnimatedTextureButton)
ON_BN_CLICKED(IDC_PATTERN_BUTTON, OnPatternButton)
ON_EN_CHANGE(IDC_ZOOM_EDIT, OnChangeZoomEdit)
ON_EN_CHANGE(IDC_TEXT_EDIT, OnChangeTextEdit)
ON_EN_CHANGE(IDC_ROTATION_EDIT, OnChangeRotationEdit)
ON_EN_CHANGE(IDC_LINE_SPACING_EDIT, OnChangeLineSpacingEdit)
ON_EN_CHANGE(IDC_ELEVATION_EDIT, OnChangeElevationEdit)
ON_EN_CHANGE(IDC_EXTRUSION_EDIT, OnChangeExtrusionEdit)
ON_BN_CLICKED(IDC_ORTOGRAPHIC_PROJECTION_CHECK, OnOrtographicProjectionCheck)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CVCGLTextDemoDlg message handlers
BOOL CVCGLTextDemoDlg::OnInitDialog()
{
USES_CONVERSION;
CDialog::OnInitDialog();
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
SetButtonFonts();
// Get the window of the text
CWnd* pTextChartWnd = GetDlgItem(IDC_NGLTEXTCTRL1);
ASSERT(pTextChartWnd);
// Query for the IDualPieChart - it is faster than the disp interface
IDual3dText *pTextControl;
if (FAILED(pTextChartWnd->GetControlUnknown()->QueryInterface(__uuidof(pTextControl), (void**)&pTextControl)))
{
AfxMessageBox("Query interace failed");
return TRUE;
}
// the pointer is addrefed (QueryInterface was called) - we attach it to a smart pointer and
// thus does not forget to call Release when the object is destroyed
m_pTextControl.Attach(pTextControl);
// update interface controls
m_sRotation.Format("%.2f", m_pTextControl->Get3DView()->Rotation);
m_sElevation.Format("%.2f", m_pTextControl->Get3DView()->Elevation);
m_sZoom.Format("%.2f", m_pTextControl->Get3DView()->Zoom);
m_sText = OLE2A(m_pTextControl->Text);
m_sExtrusion.Format("%.2f", m_pTextControl->TextExtrusion);
m_sLineSpacing.Format("%.2f", m_pTextControl->LineSpacing);
m_bEnableMouse = VAR_TO_BOOL(m_pTextControl->Get3DView()->EnableMouse);
m_bEnableLightning = VAR_TO_BOOL(m_pTextControl->LightModel()->EnableLightning);
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
}
//////////////////////////////////////////////////////////////////////
CString CVCGLTextDemoDlg::GetImageDir()
{
char path[_MAX_PATH], drive[_MAX_DRIVE], dir[_MAX_DIR];
::GetModuleFileName(AfxGetInstanceHandle(), path, _MAX_PATH);
CString sPath;
_splitpath(path, drive, dir, NULL, NULL);
sPath.Format("%s%s", drive, dir);
// move several directories up - test images are located in the Images
sPath += "..\\..\\..\\Images";
return sPath;
}
//////////////////////////////////////////////////////////////////////
CString CVCGLTextDemoDlg::GetControlText(int nControlId)
{
CString sText;
CWnd *pWnd;
pWnd = GetDlgItem(nControlId);
ASSERT(pWnd);
pWnd->GetWindowText(sText);
return sText;
}
//////////////////////////////////////////////////////////////////////
void CVCGLTextDemoDlg::SetControlText(int nControlId, const CString& sText)
{
CWnd *pWnd;
pWnd = GetDlgItem(nControlId);
ASSERT(pWnd);
pWnd->SetWindowText(sText);
}
//////////////////////////////////////////////////////////////////////
BOOL CVCGLTextDemoDlg::GetChecked(int nControlId)
{
CButton *pButton;
pButton = (CButton*)GetDlgItem(nControlId);
ASSERT(pButton);
return pButton->GetCheck();
}
//////////////////////////////////////////////////////////////////////
void CVCGLTextDemoDlg::SetChecked(int nControlId, BOOL bCheck)
{
CButton *pButton;
pButton = (CButton*)GetDlgItem(nControlId);
ASSERT(pButton);
pButton->SetCheck(bCheck);
}
//////////////////////////////////////////////////////////////////////
void CVCGLTextDemoDlg::InitLogFont(const CString& sFontName, BOOL bBold, BOOL bItalic, LOGFONT *pLogFont)
{
ASSERT(pLogFont);
memset(pLogFont, 0, sizeof(LOGFONT));
// set the paramaters of the logfont structure
pLogFont->lfHeight = -12;
pLogFont->lfWidth = 0;
pLogFont->lfEscapement = 0;
pLogFont->lfOrientation = 0;
pLogFont->lfWeight = (bBold ? FW_BOLD : FW_NORMAL);
pLogFont->lfItalic = bItalic;
pLogFont->lfUnderline = FALSE;
pLogFont->lfStrikeOut = FALSE;
pLogFont->lfCharSet = ANSI_CHARSET;
pLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
pLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
pLogFont->lfQuality = DEFAULT_QUALITY;
pLogFont->lfPitchAndFamily = FF_DONTCARE;
strcpy(pLogFont->lfFaceName, sFontName);
}
/////////////////////////////////////////////////////////////////////
void CVCGLTextDemoDlg::SetButtonFonts()
{
CWnd *pWnd;
CFont Font;
LOGFONT LogFont;
// set the font of the Arial button
InitLogFont("Arial", FALSE, TRUE, &LogFont);
if (!Font.CreateFontIndirect(&LogFont))
return;
pWnd = GetDlgItem(ID_ARIAL_FONT_BUTTON);
ASSERT(pWnd);
pWnd->SetFont(&Font);
Font.Detach();
// set the font of the Currier New button
InitLogFont("Courier New", TRUE, FALSE, &LogFont);
if (!Font.CreateFontIndirect(&LogFont))
return;
pWnd = GetDlgItem(ID_CURRIER_NEW_FONT_BUTTON);
ASSERT(pWnd);
pWnd->SetFont(&Font);
Font.Detach();
}
//////////////////////////////////////////////////////////////////////
void CVCGLTextDemoDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CVCGLTextDemoDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CVCGLTextDemoDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
//////////////////////////////////////////////////////////////////////
void CVCGLTextDemoDlg::OnAboutButton()
{
m_pTextControl->AboutBox();
}
//////////////////////////////////////////////////////////////////////
void CVCGLTextDemoDlg::OnArialFontButton()
{
CWaitCursor wait;
IFontDisp *pFontDisp;
m_pTextControl->get_TextFont(&pFontDisp);
ASSERT(pFontDisp);
CNFont font;
LOGFONT lf;
font.SetDispatch(pFontDisp);
font.GetLogFont(lf);
memcpy(lf.lfFaceName, "Arial", sizeof("Arial"));
lf.lfHeight = -14;
lf.lfWeight = FW_NORMAL;
lf.lfItalic = TRUE;
font.SetLogFont(lf);
m_pTextControl->put_TextFont(font.GetFontDispatch());
}
//////////////////////////////////////////////////////////////////////
void CVCGLTextDemoDlg::OnCurrierNewFontButton()
{
CWaitCursor wait;
IFontDisp *pFontDisp;
m_pTextControl->get_TextFont(&pFontDisp);
ASSERT(pFontDisp);
CNFont font;
LOGFONT lf;
font.SetDispatch(pFontDisp);
font.GetLogFont(lf);
memcpy(lf.lfFaceName, "Courier New", sizeof("Courier New"));
lf.lfHeight = -14;
lf.lfWeight = FW_BOLD;
lf.lfItalic = FALSE;
font.SetLogFont(lf);
m_pTextControl->put_TextFont(font.GetFontDispatch());
}
//////////////////////////////////////////////////////////////////////
void CVCGLTextDemoDlg::OnAnimateRotatexyButton()
{
CWaitCursor wait;
IDual3DViewPtr pView = m_pTextControl->Get3DView();
UpdateData();
float fCurrentRotation = (float)atof(m_sRotation);
for (int i = 1; i < 30; i++)
{
fCurrentRotation += 3;
pView->Rotation = fCurrentRotation;
m_pTextControl->Update();
}
m_sRotation.Format("%.2f", pView->Rotation);
UpdateData(FALSE);
}
//////////////////////////////////////////////////////////////////////
void CVCGLTextDemoDlg::OnAnimateRotatezButton()
{
CWaitCursor wait;
IDual3DViewPtr pView = m_pTextControl->Get3DView();
UpdateData();
float fCurrentElevation = (float)atof(m_sElevation);
for (int i = 1; i < 30; i++)
{
fCurrentElevation += 3;
pView->Elevation = fCurrentElevation;
m_pTextControl->Update();
}
m_sElevation.Format("%.2f", pView->Elevation);
UpdateData(FALSE);
}
//////////////////////////////////////////////////////////////////////
void CVCGLTextDemoDlg::OnEnableMouseCheck()
{
UpdateData();
m_pTextControl->Get3DView()->EnableMouse = BOOL_TO_VAR(m_bEnableMouse);
}
//////////////////////////////////////////////////////////////////////
void CVCGLTextDemoDlg::OnSolidColorButton()
{
IDualFillEffectPtr pTextFillEffect = m_pTextControl->FillEffect();
pTextFillEffect->Type = fetSolidColor;
pTextFillEffect->Color = RGB(0, 255, 0);
}
//////////////////////////////////////////////////////////////////////
void CVCGLTextDemoDlg::OnGradientButton()
{
IDualFillEffectPtr pTextFillEffect = m_pTextControl->FillEffect();
m_pTextControl->Redraw = VARIANT_FALSE;
pTextFillEffect->Type = fetGradient;
pTextFillEffect->GradientStyle = gsDiagonalUp;
pTextFillEffect->GradientVariant = gvVariant4;
pTextFillEffect->GradientColor1 = RGB(0, 255, 0);
pTextFillEffect->GradientColor2 = RGB(0, 0, 0);
m_pTextControl->Redraw = VARIANT_TRUE;
}
//////////////////////////////////////////////////////////////////////
void CVCGLTextDemoDlg::OnTextureButton()
{
CString sFullPath;
IDualFillEffectPtr pTextFillEffect = m_pTextControl->FillEffect();
sFullPath = GetImageDir() + CString("\\Seaside.bmp");
m_pTextControl->Redraw = VARIANT_FALSE;
try
{
pTextFillEffect->Type = fetImage;
pTextFillEffect->ImageMapType = mtMapType0; // Object linear texture mapping
pTextFillEffect->ImageFileName = sFullPath.AllocSysString();
}
catch (_com_error err)
{
AfxMessageBox(CString((LPCTSTR)err.Description()));
}
m_pTextControl->Redraw = VARIANT_TRUE;
}
//////////////////////////////////////////////////////////////////////
void CVCGLTextDemoDlg::OnBkFillEffectButton()
{
m_pTextControl->BackgroundFillEffect()->ShowDialog();
}
//////////////////////////////////////////////////////////////////////
void CVCGLTextDemoDlg::OnEnableLightningCheck()
{
UpdateData();
m_pTextControl->LightModel()->EnableLightning = BOOL_TO_VAR(m_bEnableLightning);
}
//////////////////////////////////////////////////////////////////////
void CVCGLTextDemoDlg::OnFillEffectButton()
{
m_pTextControl->FillEffect()->ShowDialog();
}
//////////////////////////////////////////////////////////////////////
void CVCGLTextDemoDlg::OnMaterialButton()
{
m_pTextControl->Material()->ShowDialog();
}
//////////////////////////////////////////////////////////////////////
void CVCGLTextDemoDlg::OnAnimatedTextureButton()
{
m_pTextControl->Redraw = VARIANT_FALSE;
IDualFillEffectPtr pTextFillEffect = m_pTextControl->FillEffect();
CString sFullPath;
sFullPath = GetImageDir() + CString("\\animation1.avi");
pTextFillEffect->Type = fetAnimation;
pTextFillEffect->AnimationMapType = mtMapType1;
pTextFillEffect->AnimationFileName = sFullPath.AllocSysString();
m_pTextControl->Redraw = VARIANT_TRUE;
}
//////////////////////////////////////////////////////////////////////
void CVCGLTextDemoDlg::OnPatternButton()
{
m_pTextControl->Redraw = VARIANT_FALSE;
IDualFillEffectPtr pTextFillEffect = m_pTextControl->FillEffect();
pTextFillEffect->Type = fetPattern;
pTextFillEffect->PatternBackgroundColor = RGB(255, 255, 0); // yellow
pTextFillEffect->PatternForegroundColor = RGB(0, 0, 255); // blue
pTextFillEffect->PatternType = ptDivot;
m_pTextControl->Redraw = VARIANT_TRUE;
}
//////////////////////////////////////////////////////////////////////
void CVCGLTextDemoDlg::OnChangeZoomEdit()
{
m_pTextControl->Redraw = VARIANT_FALSE;
UpdateData();
m_pTextControl->Get3DView()->Zoom = (float)atof(m_sZoom);
m_pTextControl->Redraw = VARIANT_TRUE;
}
//////////////////////////////////////////////////////////////////////
void CVCGLTextDemoDlg::OnChangeTextEdit()
{
m_pTextControl->Redraw = VARIANT_FALSE;
UpdateData();
m_pTextControl->Text = m_sText.AllocSysString();
m_pTextControl->Redraw = VARIANT_TRUE;
}
//////////////////////////////////////////////////////////////////////
void CVCGLTextDemoDlg::OnChangeRotationEdit()
{
m_pTextControl->Redraw = VARIANT_FALSE;
UpdateData();
m_pTextControl->Get3DView()->Rotation = (float)atof(m_sRotation);
m_pTextControl->Redraw = VARIANT_TRUE;
}
//////////////////////////////////////////////////////////////////////
void CVCGLTextDemoDlg::OnChangeLineSpacingEdit()
{
m_pTextControl->Redraw = VARIANT_FALSE;
UpdateData();
m_pTextControl->LineSpacing = (float)atof(m_sLineSpacing);
m_pTextControl->Redraw = VARIANT_TRUE;
}
//////////////////////////////////////////////////////////////////////
void CVCGLTextDemoDlg::OnChangeElevationEdit()
{
m_pTextControl->Redraw = VARIANT_FALSE;
UpdateData();
m_pTextControl->Get3DView()->Elevation = (float)atof(m_sElevation);
m_pTextControl->Redraw = VARIANT_TRUE;
}
//////////////////////////////////////////////////////////////////////
void CVCGLTextDemoDlg::OnChangeExtrusionEdit()
{
m_pTextControl->Redraw = VARIANT_FALSE;
UpdateData();
m_pTextControl->TextExtrusion = (float)atof(m_sExtrusion);
m_pTextControl->Redraw = VARIANT_TRUE;
}
//////////////////////////////////////////////////////////////////////
void CVCGLTextDemoDlg::OnOrtographicProjectionCheck()
{
UpdateData();
if (m_bOrtographicProjection)
{
m_pTextControl->Get3DView()->ProjectionType = N3DTEXTLib::ptOrtogonal;
}
else
{
m_pTextControl->Get3DView()->ProjectionType = N3DTEXTLib::ptPerspective;
}
}