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

📄 position.cpp

📁 a position control(using in musicplayer) of symbian
💻 CPP
字号:

#include "Position.h"

COggSlider64::COggSlider64()
: iMaxValue(100)
	{
	}

void COggSlider64::Draw(CBitmapContext& aBitmapContext)
	{
	if (!iKnobIcon)
		return;

	DrawFocus(aBitmapContext);
	TSize s(iKnobIcon->Bitmap()->SizeInPixels());
	TRect r(TPoint(0, 0), TSize(240,20));
	TPoint p(ix, iy);

	iPos = GetPosFromValue();
	switch (iStyle)
		{
		case 0:
			r.iBr.iX= iPos;
			break;

		case 1:
			r.iTl.iY= iPos;
			break;

		case 2:
			p.iX= iPos;
			break;

		case 3:
			p.iY= iPos;
			break;

		case 4:
			p.iX= ix+iPos;
			
			r = TRect(TPoint(iPos, 0), TSize((TInt) (TInt64(iw)/iMaxValue), ih));
			break;
		}

	aBitmapContext.BitBltMasked(p, iKnobIcon->Bitmap(), r, iKnobIcon->Mask(), ETrue);
	}

void COggSlider64::SetValue(TInt64 aValue)
	{
	if (aValue == iValue)
		return;

	if (aValue<0)
		aValue = 0;
	else if (aValue>iMaxValue)
		aValue = iMaxValue;

	iValue = aValue;
	iRedraw = (GetPosFromValue() != iPos); 
	}

void COggSlider64::SetMaxValue(TInt64 aMaxValue)
	{
	iMaxValue = aMaxValue;
	if (iValue>iMaxValue)
		iValue = iMaxValue;

	iRedraw = ETrue;
	}

TInt64 COggSlider64::CurrentValue()
	{
	return iValue;
	}

TInt COggSlider64::GetPosFromValue()
	{
	if (!iKnobIcon)
		return 0;

	TSize s(iKnobIcon->Bitmap()->SizeInPixels());
	if (iMaxValue == 0)
		{
		// Implies iValue also zero, so return pos accordingly
		switch (iStyle)
			{
			case 0:
			case 1:
			case 4:
				return 0;

			case 2:
				return ix;

			case 3:
				return iy + (ih - s.iHeight);
			}

		return 0;
		}

	switch (iStyle)
		{
		case 0:
		case 4:
			return (TInt) ((TInt64(iw)*iValue)/iMaxValue);
			break;
	
		case 1:
			return (TInt) ((TInt64(ih)*iValue)/iMaxValue);
			break;

		case 2:
			return ix + ((TInt) ((TInt64(iw - s.iWidth)*iValue)/iMaxValue));
			break;

		case 3:
			return iy + (ih - s.iHeight) - ((TInt) ((TInt64(ih-s.iHeight)*iValue)/iMaxValue));
			break;
		}

	return 0;
	}

TInt64 COggSlider64::GetValueFromPos(TInt aPos)
	{
	if (!iKnobIcon)
		return 0;

	TSize s(iKnobIcon->Bitmap()->SizeInPixels());
	switch (iStyle)
		{
		case 0:
			return (TInt64(aPos)*iMaxValue)/TInt64(iw);
			break;

		case 1:
			return (TInt64(aPos)*iMaxValue)/TInt64(ih);
			break;

		case 2:
			return (TInt64(aPos - s.iWidth/2)*iMaxValue)/TInt64(iw - s.iWidth);
			break;

		case 3:
			return (TInt64((ih - s.iHeight)-(aPos - s.iHeight/2))*iMaxValue)/TInt64(ih - s.iHeight);
			break;
		}

	return 0;
	}

void COggSlider64::PointerEvent(const TPointerEvent& p)
	{
	if (iDimmed)
		return;

	if (p.iType == TPointerEvent::EButton1Down)
		iIsMoving = ETrue;

	if (iIsMoving)
		{
		TPoint pt(p.iPosition);
		pt.iX -= ix ; pt.iY -= iy;

		switch (iStyle)
			{
			case 0:
				SetValue(GetValueFromPos(pt.iX));
				break;

			case 1:
				SetValue(GetValueFromPos(pt.iY));
				break;

			case 2:
				SetValue(GetValueFromPos(pt.iX));
				break;

			case 3:
				SetValue(GetValueFromPos(pt.iY));
				break;
			}
		}

	if (p.iType == TPointerEvent::EButton1Up)
		{
		iIsMoving = EFalse;
		iRedraw = ETrue;
		}

	COggControl::PointerEvent(p);
	}

⌨️ 快捷键说明

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