// ParticleTestView.cpp : implementation of the CParticleTestView class
//
#include "stdafx.h"
#include "ParticleTest.h"
#include "ParticleTestDoc.h"
#include "ParticleTestView.h"
#include <math.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CParticleTestView
IMPLEMENT_DYNCREATE(CParticleTestView, CView)
BEGIN_MESSAGE_MAP(CParticleTestView, CView)
//{{AFX_MSG_MAP(CParticleTestView)
ON_WM_ERASEBKGND()
ON_WM_TIMER()
ON_UPDATE_COMMAND_UI(ID_MAPMODE_MM_TEXT, OnUpdateMapmodeMmText)
ON_COMMAND(ID_MAPMODE_MM_TEXT, OnMapmodeMmText)
ON_COMMAND(ID_MAPMODE_LOENGLISH, OnMapmodeLoenglish)
ON_UPDATE_COMMAND_UI(ID_MAPMODE_LOENGLISH, OnUpdateMapmodeLoenglish)
ON_COMMAND(ID_MAPMODE_MMHIGHENGLISH, OnMapmodeMmhighenglish)
ON_UPDATE_COMMAND_UI(ID_MAPMODE_MMHIGHENGLISH, OnUpdateMapmodeMmhighenglish)
ON_COMMAND(ID_FLICKER_OFF, OnFlickerOff)
ON_UPDATE_COMMAND_UI(ID_FLICKER_OFF, OnUpdateFlickerOff)
ON_COMMAND(ID_FLICKER_ON, OnFlickerOn)
ON_UPDATE_COMMAND_UI(ID_FLICKER_ON, OnUpdateFlickerOn)
ON_COMMAND(ID_MAPMODE_HIMETRIC, OnMapmodeHimetric)
ON_UPDATE_COMMAND_UI(ID_MAPMODE_HIMETRIC, OnUpdateMapmodeHimetric)
ON_COMMAND(ID_MAPMODE_LOMETRIC, OnMapmodeLometric)
ON_UPDATE_COMMAND_UI(ID_MAPMODE_LOMETRIC, OnUpdateMapmodeLometric)
ON_COMMAND(ID_MAPMODE_TWIPS, OnMapmodeTwips)
ON_UPDATE_COMMAND_UI(ID_MAPMODE_TWIPS, OnUpdateMapmodeTwips)
ON_COMMAND(ID_MAPMODE_ANISOTRIPIC, OnMapmodeAnisotripic)
ON_UPDATE_COMMAND_UI(ID_MAPMODE_ANISOTRIPIC, OnUpdateMapmodeAnisotripic)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CParticleTestView construction/destruction
CParticleTestView::CParticleTestView()
{
m_mapmode = MM_TEXT;
m_flickerFlag = FALSE;
}
CParticleTestView::~CParticleTestView()
{
m_container.Clean();
}
BOOL CParticleTestView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CParticleTestView drawing
CString MapMode(long mapmode)
{
switch (mapmode) {
case MM_TEXT: return _T("MM_TEXT");
case MM_TWIPS: return _T("MM_TWIPS");
case MM_LOENGLISH: return _T("MM_LOENGLISH");
case MM_HIENGLISH: return _T("MM_HIENGLISH");
case MM_LOMETRIC: return _T("MM_LOMETRIC");
case MM_HIMETRIC: return _T("MM_HIMETRIC");
case MM_ANISOTROPIC: return _T("MM_ANISOTROPIC");
}
return _T("???");
}
void CParticleTestView::OnDraw(CDC* dc)
{
CRect bounds;
CRect lBounds;
GetClientRect(&bounds);
lBounds = bounds;
if (m_flickerFlag) {
dc->DPtoLP(&lBounds);
dc->FillSolidRect(lBounds, dc->GetBkColor());
m_container.Draw(dc, bounds);
dc->SetTextColor(RGB(255, 255, 255));
dc->SetBkMode(TRANSPARENT);
dc->SetTextAlign(TA_LEFT | TA_TOP);
dc->TextOut(0, 0, MapMode(dc->GetMapMode()));
} else {
CMemDC pDC(dc);
m_container.Draw(pDC, bounds);
pDC->SetTextColor(RGB(255, 255, 255));
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextAlign(TA_LEFT | TA_TOP);
pDC->TextOut(0, 0, MapMode(pDC->GetMapMode()));
}
}
/////////////////////////////////////////////////////////////////////////////
// CParticleTestView diagnostics
#ifdef _DEBUG
void CParticleTestView::AssertValid() const
{
CView::AssertValid();
}
void CParticleTestView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CParticleTestDoc* CParticleTestView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CParticleTestDoc)));
return (CParticleTestDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CParticleTestView message handlers
BOOL CParticleTestView::OnEraseBkgnd(CDC* pDC)
{
if (m_flickerFlag) {
return CView::OnEraseBkgnd(pDC);
}
return FALSE;
}
void CParticleTestView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
pDC->SetBkColor(RGB(0, 0, 0));
pDC->SetMapMode(m_mapmode);
CView::OnPrepareDC(pDC, pInfo);
}
void CParticleTestView::OnTimer(UINT nIDEvent)
{
if (nIDEvent == 1) {
CRect client;
GetClientRect(&client);
m_container.Update(client);
Invalidate();
}
}
void CParticleTestView::OnInitialUpdate()
{
CRect client;
CView::OnInitialUpdate();
srand( (unsigned)time( NULL ) );
SetTimer(1, 33, NULL);
GetClientRect(&client);
m_container.Clean();
m_container.Add(new CParentParticle(
CPoint(client.left+client.Width()/2, client.top+client.Height()/2),
CPoint(2, -3),
RGB(255, 0, 0)));
m_container.Add(new CParentParticle(
CPoint(client.left+client.Width()/2, client.top+client.Height()/2),
CPoint(rand()%3, rand()%7-3),
RGB(0, 255, 0)));
m_container.Add(new CParentParticle(
CPoint(client.left+client.Width()/2, client.top+client.Height()/2),
CPoint(rand()%3, rand()%7-3),
RGB(100, 100, 255)));
m_container.Add(new CParentParticle(
CPoint(client.left+client.Width()/2, client.top+client.Height()/2),
CPoint(rand()%3, rand()%7-3),
RGB(250, 200, 255)));
m_container.Add(new CParentParticle(
CPoint(client.left+client.Width()/2, client.top+client.Height()/2),
CPoint(rand()%3, rand()%7-3),
RGB(243, 236, 288)));
m_container.Add(new CParentParticle(
CPoint(client.left+client.Width()/2, client.top+client.Height()/2),
CPoint(rand()%3, rand()%7-3),
RGB(255, 255, 255)));
}
int CParticleContainer::GetSize() const {return m_array.GetSize();}
CParticle* CParticleContainer::GetAt(int index) {return m_array.GetAt(index);}
void CParticleContainer::RemoveAt(int index) {m_array.RemoveAt(index);}
void CParticleContainer::Add(CParticle* value) {m_array.Add(value);}
void CParticleContainer::Clean()
{
for (int i = GetSize()-1; i >= 0; i--) {
if (GetAt(i) != NULL) delete GetAt(i);
RemoveAt(i);
}
}
void CParticleContainer::Update(const CRect& bounds)
{
CParticleContainer container;
int size = GetSize();
for (int i = 0; i < size; i++) {
CParticle* pParticle = GetAt(i);
if (pParticle != NULL && pParticle->UpdateTick(bounds, NULL, container)) {
RemoveAt(i);
delete pParticle;
size = GetSize();
continue;
}
}
size = container.GetSize();
for (i = 0; i < size; i++) {
Add(container.GetAt(i));
}
}
void CParticleContainer::Draw(CDC* pDC, const CRect& bounds)
{
for (int i = 0; i < GetSize(); i++) {
CParticle* pParticle = GetAt(i);
if (pParticle != NULL) pParticle->Draw(pDC, bounds);
}
}
CParentParticle::CParentParticle(CPoint loc, CPoint velocity, COLORREF color) : CParticle(loc, velocity, color)
{
m_pen = new CPen(PS_SOLID, 1, color);
m_updateTick = 0;
}
CParentParticle::~CParentParticle()
{
if (m_pen != NULL) delete m_pen;
}
double Random()
{
static double sum = 0.0;
static double count = 0.0;
double retval = ((double) rand())/((double) RAND_MAX)-0.5;
sum += retval;
count += 1.0;
return retval;
}
BOOL CParentParticle::UpdateTick(const CRect& bounds, CParticle* parent, CParticleContainer& decayList)
{
CPoint prev = m_loc;
m_loc.x += m_velocity.x;
m_loc.y += m_velocity.y;
if (m_loc.x >= bounds.right) {
m_loc.x = m_loc.x - bounds.right;
}
if (m_loc.x < bounds.left) {
m_loc.x = bounds.right - (m_loc.x - bounds.left);
}
if (m_loc.y >= bounds.bottom) {
m_loc.y = m_loc.y - bounds.bottom;
}
if (m_loc.y < bounds.top) {
m_loc.y = bounds.bottom - (m_loc.y - bounds.top);
}
m_updateTick++;
if (m_updateTick % 10 == 0) {
m_velocity.x += (long) (5.0*Random());
m_velocity.y += (long) (5.0*Random());
if (m_velocity.x > 4) m_velocity.x = 4;
if
没有合适的资源?快使用搜索试试~ 我知道了~
避免闪的类flickerfree
共46个文件
h:13个
cpp:9个
ico:3个
需积分: 10 9 下载量 199 浏览量
2008-09-16
10:13:02
上传
评论
收藏 60KB ZIP 举报
温馨提示
避免闪的类,探索屏幕刷新过程中避免刷新闪烁影响
资源推荐
资源详情
资源评论
收起资源包目录
flickerfree避免闪的类.zip (46个子文件)
ParticleTest
ParticleTestView.h 4KB
ParticleTest.odl 1KB
StdAfx.cpp 214B
resource.h 1KB
ParticleTest.reg 702B
ParticleTest.stt 62B
ParticleTestView.cpp 13KB
ParticleTest.h 1KB
MainFrm.h 1KB
ParticleTest.rc 12KB
ParticleTestDoc.cpp 3KB
ParticleTest.dsp 5KB
ParticleTestDoc.h 2KB
memdc.h 3KB
StdAfx.h 1KB
MainFrm.cpp 2KB
ParticleTest.dsw 547B
ParticleTest.clw 2KB
Release
res
ParticleTest.ico 1KB
ParticleTestDoc.ico 1KB
Toolbar.bmp 718B
ParticleTest.rc2 404B
ParticleTest.cpp 6KB
flickerfree.html 7KB
flickerfree.gif 5KB
ParticleTestCtl
ParticleTestCtl.dsp 9KB
ParticleTestCtl.h 1024B
ParticleTestCtl.dsw 553B
StdAfx.cpp 204B
ParticleTestCtl.ico 1KB
ParticleTestCtlCtl.bmp 238B
ParticleTestCtl.def 238B
ParticleTestCtl.clw 1KB
ParticleTestCtlCtl.h 4KB
MemDC.h 3KB
ParticleTestCtl.rc 4KB
StdAfx.h 1KB
ParticleTestCtlPpg.cpp 3KB
ParticleTestCtlPpg.h 1KB
Resource.h 604B
Release
ParticleTestCtl.lib 2KB
ParticleTestCtl.tlb 2KB
ParticleTestCtl.ocx 40KB
ParticleTestCtl.odl 2KB
ParticleTestCtl.cpp 2KB
ParticleTestCtlCtl.cpp 12KB
共 46 条
- 1
资源评论
legend0257s
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功