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

📄 oandxappview.h

📁 Symbian OS C++ for Mobile Phones Volume 3 源码
💻 H
字号:
// Copyright (c) 2004 - 2006, Symbian Software Ltd. All rights reserved.

#ifndef OANDXAPPVIEW_H
#define OANDXAPPVIEW_H

#include <coecntrl.h>
#include <coedef.h>

class COandXAppView;


class COandXSymbolControl : public CCoeControl
    {
protected:
    void DrawSymbol(CWindowGc& aGc, TRect& aRect, TBool aDrawCross) const;
    };
    

class COandXTile : public COandXSymbolControl
/**
	This control represents a single tile on the board,
	which can be blank, a nought, or a cross.
 */
    {
public:
	static COandXTile* NewL(const CCoeControl* aContainer);
	
private:
    COandXTile();
    void ConstructL(const CCoeControl* aContainer);

public: // New function
    void SetOwnerAndObserver(COandXAppView* aControl);

public: // From CCoeControl
    TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);
	TCoeInputCapabilities InputCapabilities() const;

private:
    void Draw(const TRect& aRect) const;
    
private: // New function
    void TryHitL();
    
protected:
    void FocusChanged(TDrawNow aDrawNow);
    void HandlePointerEventL(const TPointerEvent& aPointerEvent);

private:
    COandXAppView* iAppView; // Pointer to the owning view
    };

class COandXStatusWin : public COandXSymbolControl
    {
public:
    static COandXStatusWin* NewL(RWindow& aWindow);
	
private:
	COandXStatusWin();
    void ConstructL(RWindow& aWindow);

public:
    void SetStatus(TBool aIsCrosses);
    
private:
    void Draw(const TRect& aRect) const;
    };

class MOandXGameObserver
/**
	The UI implements this interface so it can notify the user
	about game events.
 */
	{
public:
	/**
		Called at start of match, to redraw entire (blank) board
		and current player.
	 */
	virtual void ResetView() = 0;
	/**
		Called when a player is asked to select a square.  The UI
		should indicate the current player to the local user,
		e.g. by displaying a nought or cross icon on the screen.
	 */
	virtual void RedrawCurrentPlayer() = 0;
	/**
		Called when a square is selected.  The UI should redraw the
		indexed square.  The new value will be available from the engine.

		@param	aIndex			The square to update.
		@pre The square at aIndex must be blank.
	 */
	virtual void RedrawSquare(TInt aIndex) = 0;
	/**
		Report the winner, or whether the game was a draw.

		@param	aWinner			ETileNought, ETileCross, or ETileBlank
								if there was no winner.
	 */
	virtual void ReportWinner(TInt aWinner) = 0;
#if 0
	/**
		Report a connection failure with the remote device.

		@param	aError			Symbian OS error code.
	 */
	virtual void ConnectionError(TInt aError) = 0;
#endif
	};

class COandXAppView : public CCoeControl, public MCoeControlObserver, public MOandXGameObserver
    {
public:
    static COandXAppView* NewL(const TRect& aRect);
    virtual ~COandXAppView();
    void ConstructL(const TRect& aRect);
    
	// implement MOandXGameObserver
	virtual void ResetView();
	virtual void RedrawSquare(TInt aIndex);
	virtual void RedrawCurrentPlayer();
	virtual void ReportWinner(TInt aWinner);

public: // From CCoeControl
    TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);
    
private:
	COandXAppView();

public:
    TInt IdOfFocusControl();
    void MoveFocusTo(const TInt aIndex);
    void TryHitSquareL(const COandXTile* aControl);
    TInt SquareStatus(const COandXTile* aControl);

private:
    void SwitchFocus(TInt aFromIndex, CCoeControl* aToControl);
    void DrawComps(TRect& aRect) const;
    COandXTile * CreateTileL();

private: // From CCoeControl
    void Draw(const TRect& aRect) const;
    TInt CountComponentControls() const;
    CCoeControl* ComponentControl(TInt aIndex) const;
    void SizeChanged();
    
private: // From MCoeControlObserver
    void HandleControlEventL(CCoeControl* aControl, TCoeEvent aEventType);

private:
    TRect iBoardRect;  // Board area
    TRect iBorderRect; // Bounding rectangle for border
    TInt iTileSide;    // allowing for line widths and border
    RPointerArray<COandXTile> iTiles; // View owns the tiles
    COandXStatusWin* iStatusWin;      // and its own status window.
    };

#endif // OANDXAPPVIEW_H

⌨️ 快捷键说明

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