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

📄 slidercontrol.cpp

📁 RGA: Biowaste Game Example This C++ application demonstrates how to create a 2D mobile game for S60
💻 CPP
字号:


#include "SliderControl.h"


CSliderControl::CSliderControl()	:
	iLowLimit(0),
	iHighLimit(100),
	iValue(NULL),
	iStepSize(1),
	iLowColor(KRgbGreen),
	iHighColor(KRgbRed)
	{
	
	}


CSliderControl::~CSliderControl()
	{
	
	}


void CSliderControl::SetSliderValueSource(TInt* aValue)
	{
	iValue = aValue;
	}



void CSliderControl::Draw(	IGraphicsContext& aContext,
							const TPoint& aPosition,
							const TSize& aSize)
	{
	// compute slider phase (0=beginning, 1.0=end)
	const TReal phase = (TReal)(*iValue - iLowLimit) /
		(TReal)(iHighLimit - iLowLimit);

	// compute actual width of the slider
	const TInt width = (TInt)((TReal)aSize.iWidth * phase);
	
	// access graphics context data
	IGraphicsDevice* device = aContext.GetGraphicsDevice();
	TUint32* data = (TUint32*)device->GetAddress();
	const TInt destwidth = device->GetSize().mX;
	
	// move data pointer to correct starting location
	data += destwidth * aPosition.iY + aPosition.iX;
	
	// skip every sixth pixel on horline to create vertical 'bars'
	const TInt skippixel = 6;
	
	// interpolate colors from low value to high value
	// 16:16 fixed point values are used here to make algorithm faster
	TInt red1 = (iLowColor.Red() << 16);
	TInt green1 = (iLowColor.Green() << 16);
	TInt blue1 = (iLowColor.Blue() << 16);
	TInt red2 = (iHighColor.Red() << 16);
	TInt green2 = (iHighColor.Green() << 16);
	TInt blue2 = (iHighColor.Blue() << 16);
	
	TInt redinc = (red2 - red1) / aSize.iWidth;
	TInt greeninc = (green2 - green1) / aSize.iWidth;
	TInt blueinc = (blue2 - blue1) / aSize.iWidth;

	TInt slopeinc = (0 - (aSize.iHeight << 16)) / aSize.iWidth;
	
	int x, y;
	for (y=0; y<aSize.iHeight; y++)
		{
		TInt slope = (aSize.iHeight << 16);
		TInt skip = 0;

		// set the color start values for each horline
		red1 = (iLowColor.Red() << 16);
		green1 = (iLowColor.Green() << 16);
		blue1 = (iLowColor.Blue() << 16);
		
		for (x=0; x<width; x++)
			{
			if ((slope >> 16) < y)
			{
				// check if we need to skip a pixel
				if (skip)
				{
					// draw the pixel, extract red, green, and blue
					// values and build 32bit pixel value
					data[x] = 	((red1 >> 16) << 16) |
								((green1 >> 16) << 8) |
								(blue1 >> 16);
				}
			}
			
			if (++skip == skippixel)
				{
				skip = 0;
				}
			
			slope += slopeinc;
			red1 += redinc;
			green1 += greeninc;
			blue1 += blueinc;
			}
		
		// move to next horline
		data += destwidth;
		}
	}


TInt CSliderControl::Increase()
	{
	*iValue += iStepSize;
	if (*iValue > iHighLimit)
		{
		*iValue = iHighLimit;
		}
	if (*iValue < iLowLimit)
		{
		*iValue = iLowLimit;
		}
	return *iValue;
	}


TInt CSliderControl::Decrease()
	{
	*iValue -= iStepSize;
	if (*iValue > iHighLimit)
		{
		*iValue = iHighLimit;
		}
	if (*iValue < iLowLimit)
		{
		*iValue = iLowLimit;
		}
	return *iValue;
	}


void CSliderControl::SetValueRange(const TInt aLow, const TInt aHigh)
	{
	// set the slider value limits
	iLowLimit = aLow;
	iHighLimit = aHigh;
	
	// make sure that current value stays within limits
	if (*iValue > aHigh || *iValue < aLow)
		{
		*iValue = aLow;
		}
	}


void CSliderControl::SetStepSize(const TInt aStepSize)
	{
	iStepSize = aStepSize;
	}


void CSliderControl::SetColors(const TRgb& aLowColor, const TRgb& aHighColor)
	{
	iLowColor = aLowColor;
	iHighColor = aHighColor;
	}


TInt CSliderControl::CurrentValue() const
	{
	return *iValue;
	}


TInt CSliderControl::StepSize() const
	{
	return iStepSize;
	}

⌨️ 快捷键说明

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