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

📄 appstatesettingsscreen.cpp

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

#include "AppStateSettingsScreen.h"
#include "ExampleApplication.h"


const TInt KNumSettingsItems = 2;


CAppStateSettingsScreen::CAppStateSettingsScreen(CExampleApplication& aApp)
	: CAppState(aApp),
	  iNextState(EAppUpdateStateContinue)
	{

	}


CAppStateSettingsScreen::~CAppStateSettingsScreen()
	{
	}


TInt CAppStateSettingsScreen::Init()
	{
	// initialise slider controls
	CSettings* settings = App().Settings();

	iVolumeSlider.SetSliderValueSource(&settings->iVolume);
	iVolumeSlider.SetValueRange(0, 100);
	iVolumeSlider.SetStepSize(5);
	
	iDetailsSlider.SetSliderValueSource(&settings->iGraphicsDetail);
	iDetailsSlider.SetValueRange(1, 3);
	iDetailsSlider.SetStepSize(1);
	return KErrNone;
	}


EAppUpdateState CAppStateSettingsScreen::Update(const TReal64& /*aFrametime*/)
	{
	return iNextState;
	}


void CAppStateSettingsScreen::Draw(IGraphicsContext& aContext)
	{
	TSize bbsize = App().BackBufferSize();

	// blend background image
	App().BlendRect(TRect(	0,
			0,
			bbsize.iWidth,
			bbsize.iHeight));

	CGraphicsContext* context = App().SystemGc( App().BackBuffer() );
	const CFont* font = App().NormalFont();
	const TInt fontheight = font->HeightInPixels();
	const TRect screen(0, 0, bbsize.iWidth, bbsize.iHeight);
	const TInt margin = 5;
	
	context->UseFont(font);
	context->SetPenColor(KRgbGreen);
	
	
	TInt y = 10 + fontheight;
	context->DrawText(	KTextSettingsTitle,
						screen,
						y,
						CGraphicsContext::ECenter);
	y += fontheight * 5;

	if (iCurrentSelection == 0)
		{
		context->SetPenColor(KRgbRed);
		}
	else
		{
		context->SetPenColor(KRgbWhite);
		}
	
	context->DrawText(	KTextSettingsVolume,
						TPoint(margin, y));
	const TInt volumeslidery = y - fontheight * 3;
	y += fontheight * 5;

	if (iCurrentSelection == 1)
		{
		context->SetPenColor(KRgbRed);
		}
	else
		{
		context->SetPenColor(KRgbWhite);
		}
	
	context->DrawText(	KTextSettingsDetail,
						TPoint(margin, y));
	const TInt detailslidery = y - fontheight * 3;
	context->DiscardFont();
	App().ApplySystemGc();

	const TInt x = (bbsize.iWidth >> 1);
	const TSize slidersize(x - margin, fontheight * 3);
	iVolumeSlider.Draw(aContext, TPoint(x, volumeslidery), slidersize);
	iDetailsSlider.Draw(aContext, TPoint(x, detailslidery), slidersize);
	
	}


void CAppStateSettingsScreen::KeyDown(TUint32 aKeyCode)
	{
	CSettings* settings = App().Settings();

	switch (aKeyCode)
		{
		case INPUT_KEY_DIGITAL_LEFT:
			if (iCurrentSelection == 0)
				{
				// control volume
				iVolumeSlider.Decrease();
				App().SetMasterVolume(settings->iVolume);
				App().RePlayAudio(KAudioFileMenuMove);
				}
			else if (iCurrentSelection == 1)
				{
				// control details
				iDetailsSlider.Decrease();
				}
			break;
			
		case INPUT_KEY_DIGITAL_RIGHT:
			if (iCurrentSelection == 0)
				{
				// control volume
				iVolumeSlider.Increase();
				App().SetMasterVolume(settings->iVolume);
				App().RePlayAudio(KAudioFileMenuMove);
				}
			else if (iCurrentSelection == 1)
				{
				// control details
				iDetailsSlider.Increase();
				}
			break;

		case INPUT_KEY_DIGITAL_UP:
			if (--iCurrentSelection < 0)
				{
				iCurrentSelection = KNumSettingsItems - 1;
				}
			break;
		
		case INPUT_KEY_DIGITAL_DOWN:
			if (++iCurrentSelection >= KNumSettingsItems)
				{
				iCurrentSelection = 0;
				}
			break;
			
		default:
			iNextState = EAppUpdateStateInitMenu;
		}
	}


⌨️ 快捷键说明

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