2013-06-06 12:02:54 +08:00
|
|
|
//
|
2013-06-20 14:15:53 +08:00
|
|
|
// Texture2DMutable.h
|
2013-06-06 12:02:54 +08:00
|
|
|
// Ported to C++ by Dmitry Matyukhin
|
|
|
|
//
|
2013-06-20 14:15:53 +08:00
|
|
|
// MutableTexture.m
|
2013-06-06 12:02:54 +08:00
|
|
|
// Created by Lam Hoang Pham.
|
|
|
|
// Improved by Manuel Martinez-Almeida.
|
|
|
|
//
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
#ifndef Texture2DMutable_cpp
|
|
|
|
#define Texture2DMutable_cpp
|
2013-06-06 12:02:54 +08:00
|
|
|
|
|
|
|
#include "cocos2d.h"
|
|
|
|
|
|
|
|
#define CC_MUTABLE_TEXTURE_SAVE_ORIGINAL_DATA 0
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
class Texture2DMutable : public cocos2d::Texture2D
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
|
|
|
#if CC_MUTABLE_TEXTURE_SAVE_ORIGINAL_DATA
|
|
|
|
|
|
|
|
CC_PROPERTY_READONLY(void*, originalData_, OriginalTexData);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
CC_PROPERTY(void*, data_, TexData);
|
|
|
|
|
|
|
|
|
|
|
|
unsigned int bytesPerPixel_;
|
|
|
|
bool dirty_;
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
cocos2d::Image *image_;
|
2013-06-06 12:02:54 +08:00
|
|
|
|
|
|
|
public:
|
2013-06-20 14:15:53 +08:00
|
|
|
Texture2DMutable(void);
|
|
|
|
~Texture2DMutable(void);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
|
|
|
void restore();
|
|
|
|
|
|
|
|
/** These functions are needed to create mutable textures */
|
|
|
|
void releaseData(void *data);
|
|
|
|
void* keepData(void *data, unsigned int length);
|
|
|
|
|
2013-07-25 19:52:44 +08:00
|
|
|
bool initWithImageFile(const char *imageFile, cocos2d::Texture2D::PixelFormat pixelFormat, unsigned int pixelsWide, unsigned int pixelsHigh, const cocos2d::Size& contentSize);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
|
|
|
bool initWithImageFile(const char *imageFilex);
|
|
|
|
|
|
|
|
/** Intializes with a texture2d with data */
|
2013-07-25 19:52:44 +08:00
|
|
|
bool initWithData(const void* data, cocos2d::Texture2D::PixelFormat pixelFormat, unsigned int pixelsWide, unsigned int pixelsHigh, const cocos2d::Size& contentSize);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
|
|
|
|
2013-07-05 16:49:22 +08:00
|
|
|
cocos2d::Color4B pixelAt(const cocos2d::Point& pt);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
|
|
|
///
|
|
|
|
// @param pt is a point to get a pixel (0,0) is top-left to (width,height) bottom-right
|
2013-07-05 16:49:22 +08:00
|
|
|
// @param c is a Color4B which is a colour.
|
2013-06-06 12:02:54 +08:00
|
|
|
// @returns if a pixel was set
|
|
|
|
// Remember to call apply to actually update the texture canvas.
|
|
|
|
///
|
2013-07-05 16:49:22 +08:00
|
|
|
bool setPixelAt(const cocos2d::Point& pt, cocos2d::Color4B c);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
|
|
|
///
|
|
|
|
// Fill with specified colour
|
|
|
|
///
|
2013-07-05 16:49:22 +08:00
|
|
|
void fill(cocos2d::Color4B c);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
|
|
|
///
|
|
|
|
// @param textureToCopy is the texture image to copy over
|
|
|
|
// @param offset also offset's the texture image
|
|
|
|
///
|
2013-06-20 14:15:53 +08:00
|
|
|
Texture2D* copyMutable(bool isMutable);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Texture2DMutable* copy();
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void copy(Texture2DMutable* textureToCopy, const cocos2d::Point& offset);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
|
|
|
///
|
|
|
|
// apply actually updates the texture with any new data we added.
|
|
|
|
///
|
|
|
|
void apply();
|
|
|
|
|
|
|
|
|
|
|
|
void *getData();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
#endif // Texture2DMutable_cpp
|