📄 vegaview.cpp
字号:
// Vegaview.cpp : implementation file
//
#include "stdafx.h"
#include "MFCVegaview.h"
#include "Vegaview.h"
#include "vg.h"
#include "vgwin.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// Vegaview
IMPLEMENT_DYNCREATE(Vegaview, CView)
Vegaview::Vegaview()
{
EnableAutomation();
}
Vegaview::~Vegaview()
{
}
void Vegaview::OnFinalRelease()
{
// When the last reference for an automation object is released
// OnFinalRelease is called. The base class will automatically
// deletes the object. Add additional cleanup required for your
// object before calling the base class.
CView::OnFinalRelease();
}
BEGIN_MESSAGE_MAP(Vegaview, CView)
//{{AFX_MSG_MAP(Vegaview)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BEGIN_DISPATCH_MAP(Vegaview, CView)
//{{AFX_DISPATCH_MAP(Vegaview)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()
// Note: we add support for IID_IVegaview to support typesafe binding
// from VBA. This IID must match the GUID that is attached to the
// dispinterface in the .ODL file.
// {57880DD0-8BD3-4BE0-9FBD-A978D4E5E41D}
static const IID IID_IVegaview =
{ 0x57880dd0, 0x8bd3, 0x4be0, { 0x9f, 0xbd, 0xa9, 0x78, 0xd4, 0xe5, 0xe4, 0x1d } };
BEGIN_INTERFACE_MAP(Vegaview, CView)
INTERFACE_PART(Vegaview, IID_IVegaview, Dispatch)
END_INTERFACE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Vegaview drawing
void Vegaview::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
// TODO: add draw code here
}
/////////////////////////////////////////////////////////////////////////////
// Vegaview diagnostics
#ifdef _DEBUG
void Vegaview::AssertValid() const
{
CView::AssertValid();
}
void Vegaview::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// Vegaview message handlers
const unsigned int kVegaWndID = 1301;
// Call this to create if using this View as just a Wnd
BOOL Vegaview::create( const RECT& rect, CWnd* parent )
{
DWORD style = WS_OVERLAPPED | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE ;
BOOL ret = CWnd::Create( NULL,
"Vega Window",
style,
rect, parent,
kVegaWndID );
return ret;
}
///////////////////////////////////////////////////////////////////////////////////
// The vega thread routines
///////////////////////////////////////////////////////////////////////////////////
// This routine is the thread that gets started to run Vega
UINT runVegaApp( LPVOID pParam )
{
// pParam is actually a pointer to a Vegaview
Vegaview* pOwner = (Vegaview*)pParam;
vgInitWinSys( AfxGetInstanceHandle(), pOwner->GetSafeHwnd() );
pOwner->setVegaInitted( TRUE );
pOwner->postInit();
vgDefineSys( pOwner->getAdfName() );
pOwner->setVegaDefined( TRUE );
pOwner->postDefine();
vgConfigSys();
pOwner->setVegaConfiged( TRUE );
pOwner->postConfig();
vgAddFunc( vgGetChan(0), VGCHAN_POSTDRAW, 0, NULL );
while ( pOwner->getContinueRunning() ) {
vgSyncFrame ();
pOwner->postSync();
vgFrame ();
pOwner->postFrame();
}
// For software symmetry, it would be nice to call vgExit here, since vgInitSys
// is called above. However, it calls pfExit which calls exit(), so the MFC
// app never gets a chance to clean up. So, it is now up to the MFC app using
// this class to call vgExit. CWinApp::ExitInstance() is a good place for this.
// vgExit(0);
pOwner->setVegaInitted( FALSE );
return 0;
}
void Vegaview::runVega( void )
{
continueRunning = TRUE;
// Kick off the thread that runs Vega. This thread will become the
// app thread.
vegaThread = AfxBeginThread( runVegaApp, this );
// THREAD_PRIORITY_HIGHEST );
// THREAD_PRIORITY_TIME_CRITICAL );
// SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_LOWEST );
// Wait for Vega thread to complete define
while ( ! getVegaDefined() ) {
Sleep(10);
}
// get some common objects defined in the adf
win = vgGetWin( 0 );
if( win == NULL ) {
vgNotify( VG_FATAL, VG_APP,
"ERROR:Couldn't find window -- check %s", getAdfName());
exit( -1 );
}
gfx = vgGetGfx( 0 );
if( gfx == NULL ) {
vgNotify( VG_FATAL, VG_APP,
"ERROR:Couldn't find gfx -- check %s", getAdfName());
exit( -1 );
}
chan = vgGetChan( 0 );
if( chan == NULL ) {
vgNotify( VG_FATAL, VG_APP,
"ERROR:Couldn't find chan -- check %s", getAdfName());
exit( -1 );
}
obs = vgGetObserv( 0 );
if( obs == NULL ) {
vgNotify( VG_FATAL, VG_APP,
"ERROR:Couldn't find obs -- check %s", getAdfName());
exit( -1 );
}
scene = vgGetScene( 0 );
if( scene == NULL ) {
vgNotify( VG_FATAL, VG_APP,
"ERROR:Couldn't find scene -- check %s", getAdfName());
exit( -1 );
}
// Override the border setting - we always want no border
vgProp( win, VGWIN_WINBORDER, 0 );
}
void Vegaview::stopVega( void )
{
if ( ! vegaInitted ) return;
unPauseVega();
continueRunning = FALSE;
// Wait for Vega thread to finish
while ( vegaInitted )
Sleep( 10 );
}
void Vegaview::pauseVega( void )
{
vgDrawEnabled(0);
}
void Vegaview::unPauseVega( void )
{
vgDrawEnabled(1);
}
void Vegaview::toggleGfx( int what )
{
long i = (long)vgGetProp( gfx, what );
if( i )
vgProp( gfx, what, VG_OFF );
else
vgProp( gfx, what, VG_ON );
}
/////////////////////////////////////////////////////////////////////////////
// Overrides
// virtual
const char* Vegaview::getAdfName( void )
{
return "simple.adf";
}
// virtual
void Vegaview::postInit( void )
{
}
//virtual
void Vegaview::postDefine( void )
{
}
//virtual
void Vegaview::postConfig( void )
{
}
//virtual
void Vegaview::postSync( void )
{
}
// virtual
void Vegaview::postFrame( void ) {
// ##########################################################
// # Function : #
// # To process any none latency critical processing #
// # such as keypressess and picking events #
// ##########################################################
static vgScene *scn = NULL;
static vgEnv *en1 = NULL ;
static float timeDay =0.95f;
static int stats = 0;
static int key, e,i=0,num=0;
while( (key = vgGetWinKey( vgGetWin(0) )) != 0 ) {
//if( cmdLineOpt.actionMode )
// processKeyBindings( key );
// ******************************************************
// * Check for and process any standard keyboard events *
// ******************************************************
switch( key ) {
case '<':
// *************************************************
// * Descrease the Time of day for all enviroments *
// *************************************************
timeDay -= 0.01f;
if( timeDay < 0.0f )
timeDay = 0.0f;
for ( e = 0; e < vgGetNumEnv(); e++ ){
en1 = vgGetEnv( e) ;
vgProp( en1, VGENV_TOD, timeDay );
}
break;
case '>':
// ************************************************
// * Increase the Time of day for all enviroments *
// ************************************************
timeDay += 0.01f;
if( timeDay > 0.98f )
timeDay = 0.98f;
for ( e = 0; e < vgGetNumEnv(); e++ ){
en1 = vgGetEnv( e) ;
vgProp( en1, VGENV_TOD, timeDay );
}
break;
case 's':
// *********************************************
// * Display and toggle throught the statitics *
// *********************************************
stats += 1;
if( stats > VGCHAN_FILL+1 )
stats = VGCHAN_STATSOFF;
vgProp( vgGetChan(0), VGCHAN_STATSSEL, stats );
break;
// ****************************************************
// * Toggle the default properties between on and off *
// ****************************************************
case 'f': toggleGfx( VGGFX_FOG ); break;
case 'l': toggleGfx( VGGFX_LIGHTING ); break;
case 't': toggleGfx( VGGFX_TEXTURE ); break;
case 'w': toggleGfx( VGGFX_WIREFRAME ); break;
default: break;
} // swithc( key )
} // while(key)
}
/////////////////////////////////////////////////////////////////////////////
// Vegaview printing
/////////////////////////////////////////////////////////////////////////////
// Vegaview diagnostics
/////////////////////////////////////////////////////////////////////////////
// Vegaview message handlers
void Vegaview::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
if ( ! getVegaInitted() ) return;
vgWinSize( win, 0, cx, 0, cy );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -