// zsVegaView.cpp : implementation of the zsVegaView class
//
#include "stdafx.h"
#include "zsVegaView.h"
#include <vg.h>
#include <vgwin.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CzsVegaView
IMPLEMENT_DYNCREATE(zsVegaView, CView)
BEGIN_MESSAGE_MAP(zsVegaView, CView)
//{{AFX_MSG_MAP(zsVegaView)
ON_WM_SIZE()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// zsVegaView construction/destruction
zsVegaView::zsVegaView()
{
EnableAutomation();
vegaInitted = vegaDefined = vegaConfiged = FALSE;
vegaThread = NULL;
}
zsVegaView::~zsVegaView()
{
stopVega();
}
BOOL zsVegaView::PreCreateWindow(CREATESTRUCT& cs)
{
cs.style |= WS_OVERLAPPED | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// zsVegaView drawing
void zsVegaView::OnDraw(CDC* pDC)
{
// TODO: add draw code for native data here
}
const unsigned int kVegaWndID = 1301;
// Call this to create if using this View as just a Wnd
BOOL zsVegaView::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 zsVegaView
zsVegaView* pOwner = (zsVegaView*)pParam;
vgInitWinSys( AfxGetInstanceHandle(), pOwner->GetSafeHwnd() );
pOwner->setVegaInitted( TRUE );
pOwner->postInit();
vgDefineSys( pOwner->getAdfName() );
pOwner->setVegaDefined( TRUE );
pOwner->postDefine();
vgConfigSys();
pOwner->setVegaConfiged( TRUE );
pOwner->postConfig();
while ( pOwner->getContinueRunning() ) {
vgSyncFrame ();
pOwner->postSync();
vgFrame ();
pOwner->postFrame();
}
pOwner->setVegaInitted( FALSE );
// we have to ensure that vgSyncFrame gets called AFTER the shutdown
// flag as been set. This will end up calling system exit()
vgSyncFrame();
return 0;
}
void zsVegaView::runVega( void )
{
continueRunning = TRUE;
#if 1
// 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 );
#else
runVegaApp( this );
#endif
// 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 );
// Now the Vega window is initialized, but its size is set to whatever
// was in the ADF. We probably want it sized to match its parent.
RECT rect;
GetClientRect( &rect );
// note top-bottom is reversed in Vega coords
vgWinSize( win, rect.left, rect.right, rect.top, rect.bottom );
}
void zsVegaView::stopVega( void )
{
if ( ! vegaInitted ) return;
unPauseVega();
continueRunning = FALSE;
// Don't let MFC app exit until after the Vega thread has gone away
WaitForSingleObject( vegaThread->m_hThread, INFINITE );
}
int zsVegaView::pauseVega( void )
{
return vgDrawEnabled(0);
}
int zsVegaView::unPauseVega( void )
{
return vgDrawEnabled(1);
}
void zsVegaView::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* zsVegaView::getAdfName( void )
{
return "simple.adf";
}
// virtual
void zsVegaView::postInit( void )
{
}
//virtual
void zsVegaView::postDefine( void )
{
}
//virtual
void zsVegaView::postConfig( void )
{
}
//virtual
void zsVegaView::postSync( void )
{
}
// virtual
void zsVegaView::postFrame( void )
{
}
/////////////////////////////////////////////////////////////////////////////
// zsVegaView printing
BOOL zsVegaView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void zsVegaView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void zsVegaView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// zsVegaView diagnostics
#ifdef _DEBUG
void zsVegaView::AssertValid() const
{
CView::AssertValid();
}
void zsVegaView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// zsVegaView message handlers
void zsVegaView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
if ( ! getVegaInitted() ) return;
vgWinSize( win, 0, cx, 0, cy );
}
评论2