axmol/cocos2dx/include/CCSpriteFrame.h

121 lines
4.4 KiB
C++

/****************************************************************************
Copyright (c) 2010 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __SPRITE_CCSPRITE_FRAME_H__
#define __SPRITE_CCSPRITE_FRAME_H__
#include "CCNode.h"
#include "CCProtocols.h"
#include "NSObject.h"
namespace cocos2d {
class CGRect;
class CGPoint;
class CGSize;
class CCTexture2D;
class NSZone;
/** @brief A CCSpriteFrame has:
- texture: A CCTexture2D that will be used by the CCSprite
- rectangle: A rectangle of the texture
You can modify the frame of a CCSprite by doing:
CCSpriteFrame *frame = CCSpriteFrame::frameWithTexture(texture, rect, offset);
sprite->setDisplayFrame(frame);
*/
class CCX_DLL CCSpriteFrame : public NSObject
{
public:
// attributes
inline CGRect getRectInPixels(void) { return m_obRectInPixels; }
inline void setRectInPixels(CGRect rectInPixels) { m_obRectInPixels = rectInPixels; }
inline bool isRotated(void) { return m_bRotated; }
inline void setRotated(bool bRotated) { m_bRotated = bRotated; }
/** get rect of the frame */
inline CGRect getRect(void) { return m_obRect; }
/** set rect of the frame */
inline void setRect(CGRect rect) { m_obRect = rect; }
/** get offset of the frame */
inline CGPoint getOffsetInPixels(void) { return m_obOffsetInPixels; }
/** set offset of the frame */
inline void setOffsetInPixels(CGPoint offsetInPixels) { m_obOffsetInPixels = offsetInPixels; }
/** get original size of the trimmed image */
inline CGSize getOriginalSizeInPixels(void) { return m_obOriginalSizeInPixels; }
/** set original size of the trimmed image */
inline void setOriginalSizeInPixels(CGSize sizeInPixels) { m_obOriginalSizeInPixels = sizeInPixels; }
/** get texture of the frame */
inline CCTexture2D* getTexture(void) { return m_pobTexture; }
/** set texture of the frame, the texture is retained */
inline void setTexture(CCTexture2D* pobTexture)
{
CCX_SAFE_RETAIN(pobTexture);
CCX_SAFE_RELEASE(m_pobTexture);
m_pobTexture = pobTexture;
}
public:
~CCSpriteFrame(void);
virtual NSObject* copyWithZone(NSZone *pZone);
/** Create a CCSpriteFrame with a texture, rect in points.
It is assumed that the frame was not trimmed.
*/
static CCSpriteFrame* frameWithTexture(CCTexture2D* pobTexture, CGRect rect);
/** Create a CCSpriteFrame with a texture, rect, rotated, offset and originalSize in pixels.
The originalSize is the size in points of the frame before being trimmed.
*/
static CCSpriteFrame* frameWithTexture(CCTexture2D* pobTexture, CGRect rect, bool rotated, CGPoint offset, CGSize originalSize);
public:
/** Initializes a CCSpriteFrame with a texture, rect in points.
It is assumed that the frame was not trimmed.
*/
bool initWithTexture(CCTexture2D* pobTexture, CGRect rect);
/** Initializes a CCSpriteFrame with a texture, rect, rotated, offset and originalSize in pixels.
The originalSize is the size in points of the frame before being trimmed.
*/
bool initWithTexture(CCTexture2D* pobTexture, CGRect rect, bool rotated, CGPoint offset, CGSize originalSize);
protected:
CGRect m_obRectInPixels;
bool m_bRotated;
CGRect m_obRect;
CGPoint m_obOffsetInPixels;
CGSize m_obOriginalSizeInPixels;
CCTexture2D *m_pobTexture;
};
}//namespace cocos2d
#endif //__SPRITE_CCSPRITE_FRAME_H__