mirror of https://github.com/axmolengine/axmol.git
issue $48, implement CCXBitmapDC
This commit is contained in:
parent
adbf5a659f
commit
bb04891ccb
|
@ -25,28 +25,10 @@ THE SOFTWARE.
|
|||
#ifndef __CCRADIAL_TRANSITION_H__
|
||||
#define __CCRADIAL_TRANSITION_H__
|
||||
#include "CCTransition.h"
|
||||
///@todo #include "CCProgressTimer.h"
|
||||
///@todo #include "CCProgressTimerActions.h"
|
||||
#include "misc_nodes/CCProgressTimer.h"
|
||||
|
||||
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
|
||||
///
|
||||
|
|
|
@ -31,15 +31,10 @@ THE SOFTWARE.
|
|||
#include "Cocos2dDefine.h"
|
||||
#include "NSObject.h"
|
||||
#include "CGGeometry.h"
|
||||
#include "ccTypes.h"
|
||||
|
||||
namespace cocos2d {
|
||||
class UIImage;
|
||||
typedef enum
|
||||
{
|
||||
UITextAlignmentLeft,
|
||||
UITextAlignmentCenter,
|
||||
UITextAlignmentRight,
|
||||
} UITextAlignment;// @todo to be deleted
|
||||
|
||||
//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).
|
||||
*/
|
||||
/** 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 */
|
||||
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
|
||||
|
|
|
@ -262,6 +262,14 @@ typedef struct _ccBlendFunc
|
|||
//! if you want more resolution redefine it as a double
|
||||
typedef float ccTime;
|
||||
//typedef double ccTime;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
UITextAlignmentLeft,
|
||||
UITextAlignmentCenter,
|
||||
UITextAlignmentRight,
|
||||
} UITextAlignment;
|
||||
|
||||
}//namespace cocos2d
|
||||
|
||||
#endif //__CCTYPES_H__
|
||||
|
|
|
@ -28,12 +28,12 @@ THE SOFTWARE.
|
|||
#include "config_platform.h"
|
||||
|
||||
#ifdef CCX_PLATFORM_UPHONE
|
||||
#include "uphone/CCFileUtils.h"
|
||||
#include "uphone/CCTime.h"
|
||||
#include "uphone/NSLock.h"
|
||||
#include "uphone/CCFileUtils.h"
|
||||
#include "uphone/CCTime.h"
|
||||
#include "uphone/NSLock.h"
|
||||
#include "uphone/UIImage.h"
|
||||
#include "uphone/Cocos2dTypes.h"
|
||||
#include "uphone/CCXGLExtFunc.h"
|
||||
#include "uphone/Cocos2dTypes.h"
|
||||
#include "uphone/CCXGLExtFunc.h"
|
||||
#include "uphone/CCXBitmapDC.h"
|
||||
#else
|
||||
#error
|
||||
|
|
|
@ -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
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include <cstring>
|
||||
#include "CCXBitmapDC.h"
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -23,20 +23,25 @@ THE SOFTWARE.
|
|||
****************************************************************************/
|
||||
#ifndef __CCXBITMAP_DC_H__
|
||||
#define __CCXBITMAP_DC_H__
|
||||
#include "CCTexture2D.h"
|
||||
|
||||
#include "TG3.h"
|
||||
#include "ccTypes.h"
|
||||
|
||||
namespace cocos2d{
|
||||
class CCX_DLL CCXBitmapDC
|
||||
{
|
||||
public:
|
||||
CCXBitmapDC(const char *text, CGSize dimensions, const char *fontName, CGFloat fontSize, UITextAlignment alignment);
|
||||
CCXBitmapDC(int nWidth, int nHeight);
|
||||
CCXBitmapDC();
|
||||
CCXBitmapDC(const char *text, CGSize dimensions, UITextAlignment alignment, const char *fontName, float fontSize);
|
||||
~CCXBitmapDC(void);
|
||||
|
||||
void CreateBitmapDC(int nWidth, int nHeight);
|
||||
void* GetBuffer(void);
|
||||
CGSize GetSize();
|
||||
CGSize GetTextSize();
|
||||
protected:
|
||||
TBitmap *m_pBitmap;
|
||||
CGSize m_tTextSize;
|
||||
CGSize m_tScaleSize;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -373,13 +373,13 @@ CCTexture2D * CCTexture2D::initPremultipliedATextureWithImage(UIImage *image, un
|
|||
}
|
||||
|
||||
// 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();
|
||||
CGSize szImage = pBitmapDC->GetSize();
|
||||
|
|
Loading…
Reference in New Issue