📄 view.h
字号:
// view.h
//
// Copyright (c) 2003 Symbian Ltd. All rights reserved.
//
#ifndef __VIEW_H
#define __VIEW_H
#include <coecntrl.h>
#include <coemain.h>
#include <coeview.h>
#include <MdaAudioSamplePlayer.h>
#include "controller.h"
#include "engine.h"
// forward declarations
class CGameController;
class MGameViewCmdHandler;
class CSoundEffects;
class CEikonEnv;
class CFleetViewData: public CBase
{
// Views are friends, as they access all the data
friend class CFleetView;
friend class COppFleetView;
friend class CMyFleetView;
public:
// Constructor for use by appUI
CFleetViewData(CSoundEffects& aSoundEffects,
MGameViewCmdHandler& aCmdHandler,
const TRect& aRect);
void ConstructL();
~CFleetViewData();
// zoom
void SetZoomL(TInt aZoomFactor);
//TInt GetZoom() const;
private:
// data set by appUI
// sound effects generator
CSoundEffects& iSoundEffects;
// command handler
MGameViewCmdHandler& iCmdHandler;
// window co-ordinates
TRect iClientRect;
// view rectangle
TRect iRect;
private:
// data dependent on zooming
TInt iZoomFactor;
// pre-calculated drawing stuff
CFont* iBorderFont;
CFont* iTileFont;
TRect iBoardRect; // whole board
TRect iTopBorder; // all of top border
TRect iBottomBorder; // all bottom border
TRect iLeftBorder; // left border, excluding top and bottom
TRect iRightBorder; // right border, excluding top and bottom
TRect iSeaArea; // sea area, inside board
TInt iTileSize; // side of board tile (1/8th board rect)
TInt iBorderSize; // size of border
private:
// cached helper
CEikonEnv* iEnv;
};
class CFleetView : public CCoeControl, public MCoeView
{
public:
// construct/destruct/setup
~CFleetView();
// cursor
void SetCursorOff();
void SetCursor(TInt aX, TInt aY);
TBool CursorOn() const;
void GetCursor(TInt& aX, TInt& aY) const;
// incremental drawing
void DrawTilesNow() const;
// sound
void ExplSound();
void MissSound();
void SunkSound();
void ConstructL(const TRect& aRect);
void SetController(TFleet& aFleet, MGameViewCmdHandler& aCmdHandler);
// zoom
void SetZoomL(TInt aZoomFactor);
TInt GetZoom() const;
protected:
// construct
CFleetView(CFleetViewData& aFleetViewData, TFleet& aFleet);
void ConstructL();
// from CCoeControl
void Draw(const TRect&) const;
// from MCoeView
TVwsViewId ViewId() const;
void ViewActivatedL(const TVwsViewId& aPrevViewId,TUid aCustomMessageId,const TDesC8& aCustomMessage);
void ViewDeactivated();
// auxiliary draw functions
void DrawOutside() const;
void DrawBorders() const;
void DrawHorizontalBorder(const TRect& aRect) const;
void DrawVerticalBorder(const TRect& aRect) const;
void DrawTiles() const;
virtual void DrawTile(TInt aX, TInt aY) const;
// cursor movement
void MoveCursor(TInt aDx, TInt aDy);
protected:
// Data common to all the fleet views
CFleetViewData& iData;
// View specific data
TFleet& iFleet;
// cursor
TBool iCursorOn;
TInt iCursorX;
TInt iCursorY;
TUid iViewUid; // UID of view
};
class COppFleetView : public CFleetView
{
public:
static COppFleetView* NewL(CFleetViewData& aFleetViewData,
TFleet& aFleet);//, TBool aP1);
private:
// construct
COppFleetView(CFleetViewData& aFleetViewData,
TFleet& aFleet);//, TBool aP1);
// from CCoeControl
void HandlePointerEventL(const TPointerEvent& aPointerEvent);
TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);
};
//
// CMyFleetView: specialises CFleetView for viewing own fleet
//
class CMyFleetView : public CFleetView
{
public:
static CMyFleetView* NewL(CFleetViewData& aFleetViewData,
TFleet& aFleet);//, TBool aP1);
private:
// Construct
CMyFleetView(CFleetViewData& aFleetViewData, TFleet& aFleet);//, TBool aP1);
};
//
// CSoundEffects: provides sound effects for views
//
class CSoundEffects : public CBase
{
public:
// Sounds that can be played
enum TSound {
EExplosion,
EMiss,
ESunk
};
public:
// construct/destruct
CSoundEffects();
void ConstructL();
~CSoundEffects();
// Cancel sounds
void CancelSounds();
// Do sound
void PlaySound(TSound aSound);
private:
// construction helper
void ConstructSoundPlayerL(const TDesC& aPath, const TDesC& aName, CMdaAudioPlayerUtility*& aPlayer );
private:
// Handles callbacks from sound player
class TAudioPlayerCallBackHandler: public MMdaAudioPlayerCallback
{
friend class CSoundEffects;
public:
TAudioPlayerCallBackHandler();
private:
// Implements MMdaAudioPlayerCallback
void MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& aDuration);
void MapcPlayComplete(TInt aError);
private:
TBool iOK;
TBool iPlaying;
};
private:
CMdaAudioPlayerUtility* iExplSoundPlayer;
CMdaAudioPlayerUtility* iMissSoundPlayer;
CMdaAudioPlayerUtility* iSunkSoundPlayer;
CMdaAudioPlayerUtility* iCurrentSoundPlayer;
TAudioPlayerCallBackHandler iSoundPlayerCallBack;
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -