⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 actionball.cpp

📁 symbian中活动对象的一个例子
💻 CPP
字号:
#include "ActiveBall.h"
#include "Ballappview.h"


CActiveBall::CActiveBall(CBallAppView* aBallAppView, TInt ax,TInt ay)
:CActive(CActive::EPriorityStandard)
{
	iBallAppView = NULL;
	iPoint.SetXY(ax,ay);
	iBallAppView = aBallAppView;
	iTimer.CreateLocal();
	vx = 10;
	vy = 10;
	
	//将活动对象加入对象调度器
	CActiveScheduler::Add(this);
}

CActiveBall::~CActiveBall()
{
	Cancel();
	iTimer.Close();
}

void CActiveBall::Start()
{
	if(IsActive())
	{
		return;
	}
	else
	{
		//调用异步函数
		iTimer.After(iStatus,1000000);
		
		//激活活动对象
		SetActive();
	}
}

void CActiveBall::RunL()
{
	int x = iPoint.iX;
	int y = iPoint.iY;

	x += vx;
	y += vy;
	if(x < 0)
	{
		x = -x;
		vx = -vx;
	}
	if(x > 132)
	{
		x = 264 - x;
		vx = -vx;
	}
	if(y < 0)
	{
		y = -y;
		vy = -vy;
	}
	if(y > 100)
	{
		y = 200 - y;
		vy = -vy;
	}

	//设置新座标
	iPoint.SetXY(x,y);

	//重新绘制屏幕显示
	iBallAppView->DrawNow();

	//再次启动
	this->Start();
}

void CActiveBall::DoCancel()
{
	iTimer.Cancel();
}

TPoint& CActiveBall::GetPoint()
{
	return iPoint;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -