issue $48, implement CCXBitmapDC and implement CCTexture2D.cpp

This commit is contained in:
Walzer 2010-08-16 03:59:53 +00:00
parent 2c5cbd7e1a
commit 3fa4d2dcc4
5 changed files with 89 additions and 67 deletions

View File

@ -736,6 +736,14 @@
RelativePath=".\platform\uphone\CCXApplication_uphone.h" RelativePath=".\platform\uphone\CCXApplication_uphone.h"
> >
</File> </File>
<File
RelativePath=".\platform\uphone\CCXBitmapDC.cpp"
>
</File>
<File
RelativePath=".\platform\uphone\CCXBitmapDC.h"
>
</File>
<File <File
RelativePath=".\platform\uphone\CCXEGLView_uphone.cpp" RelativePath=".\platform\uphone\CCXEGLView_uphone.cpp"
> >

View File

@ -34,6 +34,7 @@ THE SOFTWARE.
#include "uphone/UIImage.h" #include "uphone/UIImage.h"
#include "uphone/Cocos2dTypes.h" #include "uphone/Cocos2dTypes.h"
#include "uphone/CCXGLExtFunc.h" #include "uphone/CCXGLExtFunc.h"
#include "uphone/CCXBitmapDC.h"
#else #else
#error #error
#endif #endif

View File

@ -0,0 +1,28 @@
/****************************************************************************
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.
****************************************************************************/
#include "CCXBitmapDC.h"
namespace cocos2d {
}

View File

@ -0,0 +1,43 @@
/****************************************************************************
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 __CCXBITMAP_DC_H__
#define __CCXBITMAP_DC_H__
#include "CCTexture2D.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(void);
void CreateBitmapDC(int nWidth, int nHeight);
void* GetBuffer(void);
CGSize GetSize();
CGSize GetTextSize();
protected:
};
}
#endif //__CCXBITMAP_DC_H__

View File

@ -375,77 +375,19 @@ 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 *str, const char *fontName, float fontSize)
{ {
/** @todo about UIFont return initWithString(str, CGSizeMake(0,0), UITextAlignmentCenter, fontName, fontSize);
CGSize dim;
#if CC_FONT_LABEL_SUPPORT
ZFont *zFont = [[FontManager sharedManager] zFontWithName:name pointSize:size];
if (zFont != nil)
dim = [string sizeWithZFont:zFont];
else
#endif
dim = [string sizeWithFont:[UIFont fontWithName:name size:size]];
return [self initWithString:string dimensions:dim alignment:UITextAlignmentCenter fontName:name fontSize:size];*/
return NULL;// tobe deleted
} }
CCTexture2D * CCTexture2D::initWithString(const char *str, CGSize dimensions, UITextAlignment alignment, const char *fontName, float fontSize) CCTexture2D * CCTexture2D::initWithString(const char *str, CGSize dimensions, UITextAlignment alignment, const char *fontName, float fontSize)
{ {
/** @todo UITextAlignment CCXBitmapDC *pBitmapDC = new CCXBitmapDC(str, dimensions, fontName, fontSize, alignment);
NSUInteger width,
height,
i;
CGContextRef context;
void* data;
CGColorSpaceRef colorSpace;
id uiFont;
width = dimensions.width; void* pBitData = pBitmapDC->GetBuffer();
if((width != 1) && (width & (width - 1))) { CGSize szImage = pBitmapDC->GetSize();
i = 1; CGSize szText = pBitmapDC->GetTextSize();
while(i < width)
i *= 2;
width = i;
}
height = dimensions.height;
if((height != 1) && (height & (height - 1))) {
i = 1;
while(i < height)
i *= 2;
height = i;
}
colorSpace = CGColorSpaceCreateDeviceGray(); initWithData(pBitData, kCCTexture2DPixelFormat_RGBA8888, (UINT)szImage.width, (UINT)szImage.height, szText);
data = calloc(height, width);
context = CGBitmapContextCreate(data, width, height, 8, width, colorSpace, kCGImageAlphaNone);
CGColorSpaceRelease(colorSpace);
delete pBitmapDC;
CGContextSetGrayFillColor(context, 1.0f, 1.0f);
CGContextTranslateCTM(context, 0.0f, height);
CGContextScaleCTM(context, 1.0f, -1.0f); //NOTE: NSString draws in UIKit referential i.e. renders upside-down compared to CGBitmapContext referential
UIGraphicsPushContext(context);
#if CC_FONT_LABEL_SUPPORT
uiFont = [[FontManager sharedManager] zFontWithName:name pointSize:size];
if (uiFont != nil)
[string drawInRect:CGRectMake(0, 0, dimensions.width, dimensions.height) withZFont:uiFont lineBreakMode:UILineBreakModeWordWrap alignment:alignment];
else
#endif // CC_FONT_LABEL_SUPPORT
{
uiFont = [UIFont fontWithName:name size:size];
[string drawInRect:CGRectMake(0, 0, dimensions.width, dimensions.height) withFont:uiFont lineBreakMode:UILineBreakModeWordWrap alignment:alignment];
}
if( ! uiFont )
CCLOG(@"cocos2d: Texture2D: Font '%@' not found", name);
UIGraphicsPopContext();
self = [self initWithData:data pixelFormat:kCCTexture2DPixelFormat_A8 pixelsWide:width pixelsHigh:height contentSize:dimensions];
CGContextRelease(context);
free(data);
*/
return this; return this;
} }
@ -586,7 +528,7 @@ void CCTexture2D::generateMipmap()
{ {
NSAssert( m_uPixelsWide == nextPOT(m_uPixelsWide) && m_uPixelsHigh == nextPOT(m_uPixelsHigh), "Mimpap texture only works in POT textures"); NSAssert( m_uPixelsWide == nextPOT(m_uPixelsWide) && m_uPixelsHigh == nextPOT(m_uPixelsHigh), "Mimpap texture only works in POT textures");
glBindTexture( GL_TEXTURE_2D, this->m_uName ); glBindTexture( GL_TEXTURE_2D, this->m_uName );
/// @todo include what??? glGenerateMipmapOES(GL_TEXTURE_2D); glGenerateMipmapOES(GL_TEXTURE_2D);
} }
void CCTexture2D::setTexParameters(ccTexParams *texParams) void CCTexture2D::setTexParameters(ccTexParams *texParams)