📄 cquakedemoview.cpp
字号:
// CQuakeDemoView.cpp : implementation of the CCQuakeDemoView class
//
#include "stdafx.h"
#include "CQuakeDemo.h"
#include "CQuakeDemoDoc.h"
#include "CQuakeDemoView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCQuakeDemoView
IMPLEMENT_DYNCREATE(CCQuakeDemoView, CView)
BEGIN_MESSAGE_MAP(CCQuakeDemoView, CView)
//{{AFX_MSG_MAP(CCQuakeDemoView)
ON_COMMAND(ID_MENUITEM_VIEWSETTINGS, OnMenuitemViewsettings)
ON_COMMAND(ID_QUAKE_START, OnQuakeStart)
ON_COMMAND(ID_QUAKE_PAUSE, OnQuakePause)
ON_COMMAND(ID_QUAKE_STOP, OnQuakeStop)
ON_UPDATE_COMMAND_UI(ID_QUAKE_START, OnUpdateQuakeStart)
ON_UPDATE_COMMAND_UI(ID_QUAKE_PAUSE, OnUpdateQuakePause)
ON_UPDATE_COMMAND_UI(ID_QUAKE_STOP, OnUpdateQuakeStop)
ON_COMMAND(ID_QUAKE_SPEED_UPPER, OnQuakeSpeedUpper)
ON_UPDATE_COMMAND_UI(ID_QUAKE_SPEED_UPPER, OnUpdateQuakeSpeedUpper)
ON_COMMAND(ID_QUAKE_SPEED_LOWER, OnQuakeSpeedLower)
ON_UPDATE_COMMAND_UI(ID_QUAKE_SPEED_LOWER, OnUpdateQuakeSpeedLower)
ON_WM_SIZE()
ON_WM_TIMER()
ON_WM_ERASEBKGND()
//}}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)
ON_MESSAGE(WM_ENDQUAKE,OnEndQuake)
ON_MESSAGE(WM_UPDATEVIEW,OnUpdateView)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCQuakeDemoView construction/destruction
CCQuakeDemoView::CCQuakeDemoView()
{
m_pQuakeView = NULL;
m_pTopView = NULL;
m_pBottomView = NULL;
m_pCurveView = NULL;
m_pFileManager = NULL;
m_pDrawManager = NULL;
//多媒体定时器初始化
m_MultiTimer.SetProcParameter(LPTIMECALLBACK(CallBackQuakeDraw),DWORD(this));
}
CCQuakeDemoView::~CCQuakeDemoView()
{
}
/////////////////////////////////////////////////////////////////////////////
// CCQuakeDemoView drawing
void CCQuakeDemoView::OnDraw(CDC* pDC)
{
CCQuakeDemoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
pDC->FillSolidRect(m_SpaceRect1,RGB(150,150,150));
pDC->FillSolidRect(m_SpaceRect2,RGB(150,150,150));
pDC->FillSolidRect(m_SpaceRect3,RGB(150,150,150));
}
/////////////////////////////////////////////////////////////////////////////
// CCQuakeDemoView printing
BOOL CCQuakeDemoView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CCQuakeDemoView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CCQuakeDemoView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CCQuakeDemoView diagnostics
#ifdef _DEBUG
void CCQuakeDemoView::AssertValid() const
{
CView::AssertValid();
}
void CCQuakeDemoView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CCQuakeDemoDoc* CCQuakeDemoView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCQuakeDemoDoc)));
return (CCQuakeDemoDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CCQuakeDemoView message handlers
///////////////////////////////////////////////////////////////////////////////////
// Quake Play Control functions
//////////////////////////////////////////////////////////////////
void CCQuakeDemoView::OnQuakeStart()
{
if(m_MultiTimer.IsStop())
{
m_pQuakeView->ResetMark();
m_pQuakeView->ShowMark();
}
m_MultiTimer.Start();
SetTimer(CurveTimerID,100,0);
}
void CCQuakeDemoView::OnUpdateQuakeStart(CCmdUI* pCmdUI)
{pCmdUI->Enable(!m_MultiTimer.IsStart() && GetDocument()->IsDataReady());}
//////////////////////////////////////////////////////////////////
void CCQuakeDemoView::OnQuakePause()
{
m_MultiTimer.Pause();
KillTimer(CurveTimerID);
//同步更新工具条的数据显示
m_pCurveView->UpdateView();
m_InterFace.Update();
}
void CCQuakeDemoView::OnUpdateQuakePause(CCmdUI* pCmdUI)
{pCmdUI->Enable(m_MultiTimer.IsStart());}
//////////////////////////////////////////////////////////////////
void CCQuakeDemoView::OnQuakeStop()
{
m_MultiTimer.Stop();
KillTimer(CurveTimerID);
GetDocument()->m_QuakeFileList.ResetCurReadTime();
ClearViews();
}
void CCQuakeDemoView::OnUpdateQuakeStop(CCmdUI* pCmdUI)
{/*pCmdUI->Enable(m_MultiTimer.IsStart());/**/}
//////////////////////////////////////////////////////////////////
void CCQuakeDemoView::OnQuakeSpeedUpper()
{
m_MultiTimer.SpeedUp();
}
void CCQuakeDemoView::OnUpdateQuakeSpeedUpper(CCmdUI* pCmdUI)
{pCmdUI->Enable(!(m_MultiTimer.GetResState() == MCONTROL_NOSPEEDUP));}
//////////////////////////////////////////////////////////////////
void CCQuakeDemoView::OnQuakeSpeedLower()
{
m_MultiTimer.SlowDown();
}
void CCQuakeDemoView::OnUpdateQuakeSpeedLower(CCmdUI* pCmdUI)
{pCmdUI->Enable(!(m_MultiTimer.GetResState() == MCONTROL_NOSLOWDOWN));}
//////////////////////////////////////////////////////////////////////////////////
// On Draw Data flash Functions
void CCQuakeDemoView::OnMenuitemViewsettings()
{
CDlgViewSet dlg;
dlg.DoModal();
}
void CCQuakeDemoView::OnInitialUpdate()
{
CView::OnInitialUpdate();
//保存数据源指针备用
m_pFileManager = &(GetDocument()->m_QuakeFileList);
m_pDrawManager = &(GetDocument()->m_QuakeDrawList);
//
static BOOL bRunOnce = FALSE;
if(!bRunOnce)
{
CreateViews();
bRunOnce = TRUE;
}
CalcClientRect();
MoveViews();
m_pQuakeView->OnInitialUpdate();
m_pTopView->OnInitialUpdate();
m_pBottomView->OnInitialUpdate();
m_pCurveView->OnInitialUpdate();
//设置震动视图数据源和绘图模式
m_pQuakeView->SetFileManager(&(GetDocument()->m_QuakeFileList));
m_pQuakeView->SetDrawManager(&(GetDocument()->m_QuakeDrawList));
m_pQuakeView->SetDrawType(DT_Userdefined);
//设置曲线视图数据源和绘图模式
m_pCurveView->SetFileManager(&(GetDocument()->m_QuakeFileList));
//底部绘图视图
m_pBottomView->SetFileManager(&(GetDocument()->m_QuakeFileList));
//更新视图
SendMessage(WM_UPDATEVIEW,0,0);
//初始化界面接口对象
m_InterFace.SetViewPointer(m_pQuakeView);
m_InterFace.SetDocPointer(GetDocument());
AfxGetMainWnd()->SendMessage(WM_INIINTERFACE,WPARAM(&m_InterFace),0);
}
void CCQuakeDemoView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
CalcClientRect();
MoveViews();
}
//回调震动绘图函数
void PASCAL CallBackQuakeDraw(UINT wTimerID, UINT msg,DWORD dwUser,DWORD dwl,DWORD dw2)
{
static CCQuakeDemoView *pView =(CCQuakeDemoView *)dwUser;
(pView->m_pCurveView)->TimeProc();
(pView->m_pQuakeView)->TimeProc();
if(!pView->m_pFileManager->StepInt())
pView->OnQuakeStop();
}
void CCQuakeDemoView::OnTimer(UINT nIDEvent)
{
//Temp Test Functions for Profile
if(nIDEvent == 11)
{
m_pCurveView->TimeProc();
m_pQuakeView->TimeProc();
m_pFileManager->StepInt();
}
//同步更新工具条的数据显示
m_pCurveView->UpdateView();
m_InterFace.Update();
CView::OnTimer(nIDEvent);
}
BOOL CCQuakeDemoView::OnEraseBkgnd(CDC* pDC)
{return TRUE;}
void CCQuakeDemoView::CalcClientRect()
{
GetClientRect(m_ClientRect);
CRectPlus::DivideRectV(m_ClientRect,100,m_TopRect,m_LeftRect);
CRectPlus::DivideRectV(m_LeftRect,SPACE_Height,m_SpaceRect1,m_LeftRect);
CRectPlus::DivideRectV(m_LeftRect,-30,m_LeftRect,m_BottomRect);
CRectPlus::DivideRectH(m_LeftRect,0.7,m_LeftRect,m_RightRect);
CRectPlus::DivideRectH(m_RightRect,SPACE_Height,m_SpaceRect2,m_RightRect);
CRectPlus::DivideRectV(m_BottomRect,SPACE_Height,m_SpaceRect3,m_BottomRect);
}
void CCQuakeDemoView::CreateViews()
{//Create Views
CCreateContext ctx;
ctx.m_pCurrentDoc = GetDocument();
ctx.m_pCurrentFrame = NULL;
ctx.m_pLastView = NULL;
ctx.m_pNewDocTemplate = NULL;
//
ctx.m_pNewViewClass = RUNTIME_CLASS(CQuakeView);
m_pQuakeView = (CQuakeView *)((CFrameWnd *) this)->CreateView(&ctx);
m_pQuakeView->m_pCmdView = this;
//
ctx.m_pNewViewClass = RUNTIME_CLASS(CTopView);
m_pTopView = (CTopView *)((CFrameWnd *) this)->CreateView(&ctx);
m_pTopView->m_pCmdView = this;
//
ctx.m_pNewViewClass = RUNTIME_CLASS(CBottomView);
m_pBottomView = (CBottomView *)((CFrameWnd *) this)->CreateView(&ctx);
m_pBottomView->m_pCmdView = this;
//
ctx.m_pNewViewClass = RUNTIME_CLASS(CCurveView);
m_pCurveView = (CCurveView *)((CFrameWnd *) this)->CreateView(&ctx);
m_pCurveView->m_pCmdView = this;
}
void CCQuakeDemoView::MoveViews()
{
if(m_pQuakeView != NULL)
m_pQuakeView->MoveWindow(m_LeftRect);
if(m_pTopView != NULL)
m_pTopView->MoveWindow(m_TopRect);
if(m_pBottomView != NULL)
m_pBottomView->MoveWindow(m_BottomRect);
if(m_pCurveView != NULL)
m_pCurveView->MoveWindow(m_RightRect);
}
void CCQuakeDemoView::ClearViews()
{
if(m_pQuakeView != NULL)
m_pQuakeView->ClearView();
if(m_pCurveView != NULL)
m_pCurveView->ClearView();
}
LRESULT CCQuakeDemoView::OnEndQuake(LPARAM lParam, WPARAM wParam)
{
OnQuakeStop();
return NULL;
}
LRESULT CCQuakeDemoView::OnUpdateView(LPARAM lParam, WPARAM wParam)
{
m_InterFace.InitInterface();
if(m_pQuakeView != NULL)
m_pQuakeView->UpdateView();
if(m_pTopView != NULL)
m_pTopView->UpdateView();
if(m_pBottomView != NULL)
m_pBottomView->UpdateView();
if(m_pCurveView != NULL)
m_pCurveView->UpdateView();
return NULL;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -