issue $48, implement CCXBitmapDC

This commit is contained in:
Walzer 2010-08-16 07:02:17 +00:00
parent adbf5a659f
commit bb04891ccb
7 changed files with 84 additions and 40 deletions

View File

@ -25,28 +25,10 @@ THE SOFTWARE.
#ifndef __CCRADIAL_TRANSITION_H__ #ifndef __CCRADIAL_TRANSITION_H__
#define __CCRADIAL_TRANSITION_H__ #define __CCRADIAL_TRANSITION_H__
#include "CCTransition.h" #include "CCTransition.h"
///@todo #include "CCProgressTimer.h" #include "misc_nodes/CCProgressTimer.h"
///@todo #include "CCProgressTimerActions.h"
namespace cocos2d { namespace cocos2d {
typedef enum {
/// Radial Counter-Clockwise
kCCProgressTimerTypeRadialCCW,
/// Radial ClockWise
kCCProgressTimerTypeRadialCW,
/// Horizontal Left-Right
kCCProgressTimerTypeHorizontalBarLR,
/// Horizontal Right-Left
kCCProgressTimerTypeHorizontalBarRL,
/// Vertical Bottom-top
kCCProgressTimerTypeVerticalBarBT,
/// Vertical Top-Bottom
kCCProgressTimerTypeVerticalBarTB,
} CCProgressTimerType;/// @todo to be deleted
/// ///
// A counter colock-wise radial transition to the next scene // A counter colock-wise radial transition to the next scene
/// ///

View File

@ -31,15 +31,10 @@ THE SOFTWARE.
#include "Cocos2dDefine.h" #include "Cocos2dDefine.h"
#include "NSObject.h" #include "NSObject.h"
#include "CGGeometry.h" #include "CGGeometry.h"
#include "ccTypes.h"
namespace cocos2d { namespace cocos2d {
class UIImage; class UIImage;
typedef enum
{
UITextAlignmentLeft,
UITextAlignmentCenter,
UITextAlignmentRight,
} UITextAlignment;// @todo to be deleted
//CONSTANTS: //CONSTANTS:
@ -142,9 +137,9 @@ public:
Note that the generated textures are of type A8 - use the blending mode (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA). Note that the generated textures are of type A8 - use the blending mode (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA).
*/ */
/** Initializes a texture from a string with dimensions, alignment, font name and font size */ /** Initializes a texture from a string with dimensions, alignment, font name and font size */
CCTexture2D * initWithString(const char *str, CGSize dimensions, UITextAlignment alignment, const char *fontName, float fontSize); CCTexture2D * initWithString(const char *text, CGSize dimensions, UITextAlignment alignment, const char *fontName, float fontSize);
/** Initializes a texture from a string with font name and font size */ /** Initializes a texture from a string with font name and font size */
CCTexture2D * initWithString(const char *str, const char *fontName, float fontSize); CCTexture2D * initWithString(const char *text, const char *fontName, float fontSize);
/** /**
Extensions to make it easy to create a CCTexture2D object from a PVRTC file Extensions to make it easy to create a CCTexture2D object from a PVRTC file

View File

@ -262,6 +262,14 @@ typedef struct _ccBlendFunc
//! if you want more resolution redefine it as a double //! if you want more resolution redefine it as a double
typedef float ccTime; typedef float ccTime;
//typedef double ccTime; //typedef double ccTime;
typedef enum
{
UITextAlignmentLeft,
UITextAlignmentCenter,
UITextAlignmentRight,
} UITextAlignment;
}//namespace cocos2d }//namespace cocos2d
#endif //__CCTYPES_H__ #endif //__CCTYPES_H__

View File

@ -21,8 +21,62 @@ 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 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
****************************************************************************/ ****************************************************************************/
#include <cstring>
#include "CCXBitmapDC.h" #include "CCXBitmapDC.h"
namespace cocos2d { namespace cocos2d {
CCXBitmapDC::CCXBitmapDC(const char *text, CGSize dimensions, UITextAlignment alignment, const char *fontName, float fontSize)
{
TFont font;
int len = strlen(text) + 1;
TUChar * pText = new TUChar[len];
TUString::StrGBToUnicode(pText, (Char*)text);
if (CGSize::CGSizeEqualToSize(dimensions, CGSizeZero))
{
m_tTextSize.width = font.CharsWidth(pText, len);
m_tTextSize.height = font.LineHeight();
}else
{
m_tTextSize = dimensions;
}
int i;
int width = (int)m_tTextSize.width;
int height = (int)m_tTextSize.height;
if((width!= 1) && (width & (width - 1)))
{
i = 1;
while(i < width)
i>>=1;
width = i;
}
if((height != 1) && (height & (height - 1)))
{
i = 1;
while(i < height)
i >>= 1;
height = i;
}
m_tScaleSize.width = (float)width;
m_tScaleSize.height = (float)height;
m_pBitmap = TBitmap::Create(width, height, 32);
TDC dc(NULL);
dc.DrawCharsInBitmap(pText, len, m_pBitmap, RGBA(255,0,0,255), RGBA(0,255,0,255), font, GUI_API_STYLE_ALIGNMENT_CENTER);
}
void *CCXBitmapDC::GetBuffer()
{
return m_pBitmap->GetDataPtr();
}
CGSize CCXBitmapDC::GetSize()
{
return m_tScaleSize;
}
CGSize CCXBitmapDC::GetTextSize()
{
return m_tTextSize;
}
} }

View File

@ -23,20 +23,25 @@ THE SOFTWARE.
****************************************************************************/ ****************************************************************************/
#ifndef __CCXBITMAP_DC_H__ #ifndef __CCXBITMAP_DC_H__
#define __CCXBITMAP_DC_H__ #define __CCXBITMAP_DC_H__
#include "CCTexture2D.h"
#include "TG3.h"
#include "ccTypes.h"
namespace cocos2d{ namespace cocos2d{
class CCX_DLL CCXBitmapDC class CCX_DLL CCXBitmapDC
{ {
public: public:
CCXBitmapDC(const char *text, CGSize dimensions, const char *fontName, CGFloat fontSize, UITextAlignment alignment); CCXBitmapDC();
CCXBitmapDC(int nWidth, int nHeight); CCXBitmapDC(const char *text, CGSize dimensions, UITextAlignment alignment, const char *fontName, float fontSize);
~CCXBitmapDC(void); ~CCXBitmapDC(void);
void CreateBitmapDC(int nWidth, int nHeight);
void* GetBuffer(void); void* GetBuffer(void);
CGSize GetSize(); CGSize GetSize();
CGSize GetTextSize(); CGSize GetTextSize();
protected: protected:
TBitmap *m_pBitmap;
CGSize m_tTextSize;
CGSize m_tScaleSize;
}; };
} }

View File

@ -373,13 +373,13 @@ CCTexture2D * CCTexture2D::initPremultipliedATextureWithImage(UIImage *image, un
} }
// implementation CCTexture2D (Text) // implementation CCTexture2D (Text)
CCTexture2D * CCTexture2D::initWithString(const char *str, const char *fontName, float fontSize) CCTexture2D * CCTexture2D::initWithString(const char *text, const char *fontName, float fontSize)
{ {
return initWithString(str, CGSizeMake(0,0), UITextAlignmentCenter, fontName, fontSize); return initWithString(text, CGSizeMake(0,0), UITextAlignmentCenter, fontName, fontSize);
} }
CCTexture2D * CCTexture2D::initWithString(const char *str, CGSize dimensions, UITextAlignment alignment, const char *fontName, float fontSize) CCTexture2D * CCTexture2D::initWithString(const char *text, CGSize dimensions, UITextAlignment alignment, const char *fontName, float fontSize)
{ {
CCXBitmapDC *pBitmapDC = new CCXBitmapDC(str, dimensions, fontName, fontSize, alignment); CCXBitmapDC *pBitmapDC = new CCXBitmapDC(text, dimensions, alignment, fontName, fontSize);
void* pBitData = pBitmapDC->GetBuffer(); void* pBitData = pBitmapDC->GetBuffer();
CGSize szImage = pBitmapDC->GetSize(); CGSize szImage = pBitmapDC->GetSize();