From bade43ca930389ddbdc49c28b0f975a9d4c172b0 Mon Sep 17 00:00:00 2001 From: andyque Date: Thu, 21 Aug 2014 15:03:50 +0800 Subject: [PATCH 01/14] update ui::Scale9Sprite release note --- docs/RELEASE_NOTES.md | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/docs/RELEASE_NOTES.md b/docs/RELEASE_NOTES.md index 78cd8ae2f3..8f6fde1bac 100644 --- a/docs/RELEASE_NOTES.md +++ b/docs/RELEASE_NOTES.md @@ -165,7 +165,30 @@ TBD ## ui::Scale9Sprite -TBD +Now we have implemented a new Scale9Sprite class under ui module. Its internal implementation is concise than the previous one plus more features. +The main reason of reimplementing this class is that the Scale9Sprite is heavily used in ui module. Now the ui module is not dependent from extension module. +By applying the new ui::Scale9Sprite, the code inside many widget classes are more cleaner and elegant. + +We could manually toggle "slice 9" feature by one function call: + +```c++ +//ui::Scale9Sprite is slice 9 enabled on default +auto sprite = ui::Scale9Sprite::create("foo.png"); +sprite->setScale9Enabled(false); +``` + +It also supports Flipping now. + +```c++ +auto sprite = ui::Scale9Sprite::create("bar.png"); +sprite->setFlippedX(true); +sprite->setFlippedY(false); +``` + +Since the ui::Scale9Sprite is a Node rather than a Sprite, so you can't add it to a batch node. If you do want to do some actions on the internal sprite, +you could call `sprite->getSprite()` to access it. + +Full test case please refer to `tests/cpp-tests/Classes/UITests/CocostudioGUITest/UIScale9SpriteTest.cpp`. ## c++11 random support From 909dd0d39700033ae6a6fec2e1b9146c06bc7c1e Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 21 Aug 2014 15:11:33 +0800 Subject: [PATCH 02/14] Update #3897: Refactor missed protected constructors --- cocos/2d/CCAction.h | 6 ++++-- cocos/2d/CCActionGrid.h | 6 ++++-- cocos/2d/CCActionGrid3D.h | 2 +- cocos/2d/CCActionInstant.h | 13 +++++++------ cocos/2d/CCActionTiledGrid.h | 8 ++++---- cocos/2d/CCLabel.h | 23 ++++++++++++----------- cocos/2d/CCLabelAtlas.h | 4 +++- cocos/2d/CCLayer.h | 2 +- cocos/2d/CCNodeGrid.h | 3 ++- cocos/2d/CCParallaxNode.h | 3 ++- cocos/base/CCEvent.h | 2 +- cocos/base/CCEventListener.h | 2 +- cocos/base/CCEventListenerAcceleration.h | 5 ++++- cocos/base/CCEventListenerFocus.h | 2 +- cocos/base/CCEventListenerKeyboard.h | 2 +- cocos/base/CCEventListenerMouse.h | 2 +- cocos/base/CCEventListenerTouch.h | 5 +++-- cocos/base/ccConfig.h | 2 +- 18 files changed, 53 insertions(+), 39 deletions(-) diff --git a/cocos/2d/CCAction.h b/cocos/2d/CCAction.h index 2842301b90..bdf4a26b21 100644 --- a/cocos/2d/CCAction.h +++ b/cocos/2d/CCAction.h @@ -99,10 +99,11 @@ public: inline int getTag() const { return _tag; } inline void setTag(int tag) { _tag = tag; } -protected: +CC_CONSTRUCTOR_ACCESS: Action(); virtual ~Action(); +protected: Node *_originalTarget; /** The "target". The target will be set with the 'startWithTarget' method. @@ -140,12 +141,13 @@ public: virtual FiniteTimeAction* reverse() const override = 0; virtual FiniteTimeAction* clone() const override = 0; -protected: +CC_CONSTRUCTOR_ACCESS: FiniteTimeAction() : _duration(0) {} virtual ~FiniteTimeAction(){} +protected: //! duration in seconds float _duration; diff --git a/cocos/2d/CCActionGrid.h b/cocos/2d/CCActionGrid.h index 77329cdbc4..64f766827f 100644 --- a/cocos/2d/CCActionGrid.h +++ b/cocos/2d/CCActionGrid.h @@ -52,12 +52,13 @@ public: virtual GridAction* reverse() const override; virtual void startWithTarget(Node *target) override; -protected: +CC_CONSTRUCTOR_ACCESS: GridAction() {} virtual ~GridAction() {} /** initializes the action with size and duration */ bool initWithDuration(float duration, const Size& gridSize); +protected: Size _gridSize; NodeGrid* _gridNodeTarget; @@ -273,10 +274,11 @@ public: virtual StopGrid* clone() const override; virtual StopGrid* reverse() const override; -protected: +CC_CONSTRUCTOR_ACCESS: StopGrid() {} virtual ~StopGrid() {} +protected: NodeGrid* _gridNodeTarget; void cacheTargetAsGridNode(); diff --git a/cocos/2d/CCActionGrid3D.h b/cocos/2d/CCActionGrid3D.h index 89c187cc58..4c9491e3c0 100644 --- a/cocos/2d/CCActionGrid3D.h +++ b/cocos/2d/CCActionGrid3D.h @@ -108,7 +108,7 @@ public: virtual void update(float time) override; virtual FlipY3D* clone() const override; -protected: +CC_CONSTRUCTOR_ACCESS: FlipY3D() {} virtual ~FlipY3D() {} private: diff --git a/cocos/2d/CCActionInstant.h b/cocos/2d/CCActionInstant.h index c74d6f0378..b8aa440a4b 100644 --- a/cocos/2d/CCActionInstant.h +++ b/cocos/2d/CCActionInstant.h @@ -74,7 +74,7 @@ public: virtual ActionInstant* reverse() const override; virtual Show* clone() const override; -protected: +CC_CONSTRUCTOR_ACCESS: Show(){} virtual ~Show(){} @@ -98,7 +98,7 @@ public: virtual ActionInstant* reverse() const override; virtual Hide* clone() const override; -protected: +CC_CONSTRUCTOR_ACCESS: Hide(){} virtual ~Hide(){} @@ -121,7 +121,7 @@ public: virtual ToggleVisibility* reverse() const override; virtual ToggleVisibility* clone() const override; -protected: +CC_CONSTRUCTOR_ACCESS: ToggleVisibility(){} virtual ~ToggleVisibility(){} @@ -402,13 +402,14 @@ public: virtual __CCCallFuncND* clone() const override; virtual void execute() override; -protected: +CC_CONSTRUCTOR_ACCESS: __CCCallFuncND() {} virtual ~__CCCallFuncND() {} /** initializes the action with the callback and the data to pass as an argument */ bool initWithTarget(Ref* target, SEL_CallFuncND selector, void* d); +protected: SEL_CallFuncND _callFuncND; void* _data; @@ -441,7 +442,7 @@ public: Ref* getObject() const; void setObject(Ref* obj); -protected: +CC_CONSTRUCTOR_ACCESS: __CCCallFuncO(); virtual ~__CCCallFuncO(); /** initializes the action with the callback @@ -450,7 +451,7 @@ protected: */ bool initWithTarget(Ref* target, SEL_CallFuncO selector, Ref* object); - +protected: /** object to be passed as argument */ Ref* _object; SEL_CallFuncO _callFuncO; diff --git a/cocos/2d/CCActionTiledGrid.h b/cocos/2d/CCActionTiledGrid.h index 6f3e846353..844e814b70 100644 --- a/cocos/2d/CCActionTiledGrid.h +++ b/cocos/2d/CCActionTiledGrid.h @@ -142,7 +142,7 @@ public: virtual void update(float time) override; virtual FadeOutTRTiles* clone() const override; -protected: +CC_CONSTRUCTOR_ACCESS: FadeOutTRTiles() {} virtual ~FadeOutTRTiles() {} @@ -163,7 +163,7 @@ public: virtual float testFunc(const Size& pos, float time) override; virtual FadeOutBLTiles* clone() const override; -protected: +CC_CONSTRUCTOR_ACCESS: FadeOutBLTiles() {} virtual ~FadeOutBLTiles() {} @@ -186,7 +186,7 @@ public: virtual FadeOutUpTiles* clone() const override; virtual float testFunc(const Size& pos, float time) override; -protected: +CC_CONSTRUCTOR_ACCESS: FadeOutUpTiles() {} virtual ~FadeOutUpTiles() {} @@ -207,7 +207,7 @@ public: virtual FadeOutDownTiles* clone() const override; virtual float testFunc(const Size& pos, float time) override; -protected: +CC_CONSTRUCTOR_ACCESS: FadeOutDownTiles() {} virtual ~FadeOutDownTiles() {} diff --git a/cocos/2d/CCLabel.h b/cocos/2d/CCLabel.h index a81daf8e6b..de4173527c 100644 --- a/cocos/2d/CCLabel.h +++ b/cocos/2d/CCLabel.h @@ -275,6 +275,18 @@ public: CC_DEPRECATED_ATTRIBUTE int getCommonLineHeight() const { return getLineHeight();} +CC_CONSTRUCTOR_ACCESS: + /** + * @js NA + */ + Label(FontAtlas *atlas = nullptr, TextHAlignment hAlignment = TextHAlignment::LEFT, + TextVAlignment vAlignment = TextVAlignment::TOP,bool useDistanceField = false,bool useA8Shader = false); + /** + * @js NA + * @lua NA + */ + virtual ~Label(); + protected: void onDraw(const Mat4& transform, bool transformUpdated); @@ -294,17 +306,6 @@ protected: STRING_TEXTURE }; - /** - * @js NA - */ - Label(FontAtlas *atlas = nullptr, TextHAlignment hAlignment = TextHAlignment::LEFT, - TextVAlignment vAlignment = TextVAlignment::TOP,bool useDistanceField = false,bool useA8Shader = false); - /** - * @js NA - * @lua NA - */ - virtual ~Label(); - virtual void setFontAtlas(FontAtlas* atlas,bool distanceFieldEnabled = false, bool useA8Shader = false); bool recordLetterInfo(const cocos2d::Vec2& point,const FontLetterDefinition& letterDef, int spriteIndex); diff --git a/cocos/2d/CCLabelAtlas.h b/cocos/2d/CCLabelAtlas.h index 2c373fe76e..b0e26d3ffb 100644 --- a/cocos/2d/CCLabelAtlas.h +++ b/cocos/2d/CCLabelAtlas.h @@ -87,7 +87,7 @@ public: virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override; #endif -protected: +CC_CONSTRUCTOR_ACCESS: LabelAtlas() :_string("") {} @@ -96,6 +96,8 @@ protected: { _string.clear(); } + +protected: virtual void updateColor() override; #if CC_LABELATLAS_DEBUG_DRAW diff --git a/cocos/2d/CCLayer.h b/cocos/2d/CCLayer.h index b6f985aa72..46d40c3df5 100644 --- a/cocos/2d/CCLayer.h +++ b/cocos/2d/CCLayer.h @@ -228,7 +228,7 @@ public: virtual void setOpacityModifyRGB(bool bValue) override { return Layer::setOpacityModifyRGB(bValue); } virtual bool isOpacityModifyRGB() const override { return Layer::isOpacityModifyRGB(); } -protected: +CC_CONSTRUCTOR_ACCESS: __LayerRGBA(); virtual ~__LayerRGBA() {} diff --git a/cocos/2d/CCNodeGrid.h b/cocos/2d/CCNodeGrid.h index 12266b1a41..46ec7e389a 100644 --- a/cocos/2d/CCNodeGrid.h +++ b/cocos/2d/CCNodeGrid.h @@ -56,10 +56,11 @@ public: // overrides virtual void visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) override; -protected: +CC_CONSTRUCTOR_ACCESS: NodeGrid(); virtual ~NodeGrid(); +protected: void onGridBeginDraw(); void onGridEndDraw(); diff --git a/cocos/2d/CCParallaxNode.h b/cocos/2d/CCParallaxNode.h index df584f2f63..cc1f12e146 100644 --- a/cocos/2d/CCParallaxNode.h +++ b/cocos/2d/CCParallaxNode.h @@ -70,7 +70,7 @@ public: virtual void removeAllChildrenWithCleanup(bool cleanup) override; virtual void visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) override; -protected: +CC_CONSTRUCTOR_ACCESS: /** Adds a child to the container with a z-order, a parallax ratio and a position offset It returns self, so you can chain several addChilds. @since v0.8 @@ -83,6 +83,7 @@ protected: */ virtual ~ParallaxNode(); +protected: Vec2 absolutePosition(); Vec2 _lastPosition; diff --git a/cocos/base/CCEvent.h b/cocos/base/CCEvent.h index 4bc129c052..98480961b9 100644 --- a/cocos/base/CCEvent.h +++ b/cocos/base/CCEvent.h @@ -55,7 +55,7 @@ public: CUSTOM }; -protected: +CC_CONSTRUCTOR_ACCESS: /** Constructor */ Event(Type type); public: diff --git a/cocos/base/CCEventListener.h b/cocos/base/CCEventListener.h index d890c6938d..a771f70443 100644 --- a/cocos/base/CCEventListener.h +++ b/cocos/base/CCEventListener.h @@ -63,7 +63,7 @@ public: typedef std::string ListenerID; -protected: +CC_CONSTRUCTOR_ACCESS: /** Constructor */ EventListener(); diff --git a/cocos/base/CCEventListenerAcceleration.h b/cocos/base/CCEventListenerAcceleration.h index 78e145c87a..0bf473e4bd 100644 --- a/cocos/base/CCEventListenerAcceleration.h +++ b/cocos/base/CCEventListenerAcceleration.h @@ -41,10 +41,13 @@ public: /// Overrides virtual EventListenerAcceleration* clone() override; virtual bool checkAvailable() override; -private: + +CC_CONSTRUCTOR_ACCESS: EventListenerAcceleration(); bool init(const std::function& callback); + +private: std::function onAccelerationEvent; friend class LuaEventListenerAcceleration; diff --git a/cocos/base/CCEventListenerFocus.h b/cocos/base/CCEventListenerFocus.h index dec59f774a..1e30eb9a9f 100644 --- a/cocos/base/CCEventListenerFocus.h +++ b/cocos/base/CCEventListenerFocus.h @@ -51,7 +51,7 @@ public: public: std::function onFocusChanged; -private: +CC_CONSTRUCTOR_ACCESS: EventListenerFocus(); bool init(); diff --git a/cocos/base/CCEventListenerKeyboard.h b/cocos/base/CCEventListenerKeyboard.h index 5f14abc2e9..1aa8a10f85 100644 --- a/cocos/base/CCEventListenerKeyboard.h +++ b/cocos/base/CCEventListenerKeyboard.h @@ -46,7 +46,7 @@ public: std::function onKeyPressed; std::function onKeyReleased; -private: +CC_CONSTRUCTOR_ACCESS: EventListenerKeyboard(); bool init(); }; diff --git a/cocos/base/CCEventListenerMouse.h b/cocos/base/CCEventListenerMouse.h index 22708e137b..57b98997dc 100644 --- a/cocos/base/CCEventListenerMouse.h +++ b/cocos/base/CCEventListenerMouse.h @@ -49,7 +49,7 @@ public: std::function onMouseMove; std::function onMouseScroll; -private: +CC_CONSTRUCTOR_ACCESS: EventListenerMouse(); bool init(); }; diff --git a/cocos/base/CCEventListenerTouch.h b/cocos/base/CCEventListenerTouch.h index c2fbace749..13b35d8a0e 100644 --- a/cocos/base/CCEventListenerTouch.h +++ b/cocos/base/CCEventListenerTouch.h @@ -56,10 +56,11 @@ public: std::function onTouchEnded; std::function onTouchCancelled; -private: +CC_CONSTRUCTOR_ACCESS: EventListenerTouchOneByOne(); bool init(); +private: std::vector _claimedTouches; bool _needSwallow; @@ -85,7 +86,7 @@ public: std::function&, Event*)> onTouchesEnded; std::function&, Event*)> onTouchesCancelled; -private: +CC_CONSTRUCTOR_ACCESS: EventListenerTouchAllAtOnce(); bool init(); private: diff --git a/cocos/base/ccConfig.h b/cocos/base/ccConfig.h index 3e36c6c702..1249819c48 100644 --- a/cocos/base/ccConfig.h +++ b/cocos/base/ccConfig.h @@ -281,7 +281,7 @@ To enable set it to a value different than 0. Disabled by default. protected by default. */ #ifndef CC_CONSTRUCTOR_ACCESS -#define CC_CONSTRUCTOR_ACCESS protected +#define CC_CONSTRUCTOR_ACCESS public #endif #endif // __CCCONFIG_H__ From b349ce43ae63717b2ef33c44b96b7968c08c034f Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 21 Aug 2014 15:19:26 +0800 Subject: [PATCH 03/14] use macro to control whether to use jpeg, tiff, webp or not --- cocos/base/ccConfig.h | 18 ++ cocos/platform/CCImage.cpp | 531 ++++++++++++++++++++++++++++++++----- cocos/platform/CCImage.h | 32 --- 3 files changed, 479 insertions(+), 102 deletions(-) diff --git a/cocos/base/ccConfig.h b/cocos/base/ccConfig.h index 2225998746..a44ede24ef 100644 --- a/cocos/base/ccConfig.h +++ b/cocos/base/ccConfig.h @@ -269,6 +269,24 @@ To enable set it to a value different than 0. Disabled by default. #define CC_USE_PHYSICS 1 #endif +/** Support JPEG or not. If your application don't use jpeg format picture, you can undefine this macro to save package size. + */ +#ifndef CC_USE_JPEG +#define CC_USE_JPEG 1 +#endif // CC_USE_JPEG + +/** Support TIFF or not. If your application don't use TIFF format picture, you can undefine this macro to save package size. + */ +#ifndef CC_USE_TIFF +#define CC_USE_TIFF 1 +#endif // CC_USE_TIFF + +/** Support webp or not. If your application don't use webp format picture, you can undefine this macro to save package size. + */ +#ifndef CC_USE_WEBP +#define CC_USE_WEBP 1 +#endif // CC_USE_WEBP + /** Enable Script binding */ #ifndef CC_ENABLE_SCRIPT_BINDING #define CC_ENABLE_SCRIPT_BINDING 1 diff --git a/cocos/platform/CCImage.cpp b/cocos/platform/CCImage.cpp index 80ba8e672b..3de73e09b7 100644 --- a/cocos/platform/CCImage.cpp +++ b/cocos/platform/CCImage.cpp @@ -30,6 +30,7 @@ THE SOFTWARE. #include #include "base/CCData.h" +#include "ccConfig.h" // CC_USE_JPEG, CC_USE_TIFF, CC_USE_WEBP extern "C" { @@ -51,21 +52,31 @@ extern "C" { return strerror(errnum); } - // int fputs(const char * __restrict, FILE * __restrict) __DARWIN_ALIAS(fputs); - int fputs$UNIX2003(const char *str, FILE *stream) - { - return fputs(str, stream); - } #endif #endif #include "png.h" + +#if CC_USE_TIFF +#include "tiffio.h" +#endif //CC_USE_TIFF + #include "base/etc1.h" + +#if CC_USE_JPEG +#include "jpeglib.h" +#endif // CC_USE_JPEG } #include "base/s3tc.h" #include "base/atitc.h" #include "base/pvr.h" #include "base/TGAlib.h" +#if (CC_TARGET_PLATFORM != CC_PLATFORM_WP8) && (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT) +#if CC_USE_WEBP +#include "decode.h" +#endif // CC_USE_WEBP +#endif + #include "base/ccMacros.h" #include "CCCommon.h" #include "CCStdC.h" @@ -73,7 +84,6 @@ extern "C" #include "base/CCConfiguration.h" #include "base/ccUtils.h" #include "base/ZipUtils.h" -#include "base/CCModuleManager.h" #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) #include "android/CCFileUtilsAndroid.h" #endif @@ -90,6 +100,7 @@ NS_CC_BEGIN namespace { static const int PVR_TEXTURE_FLAG_TYPE_MASK = 0xff; + static bool _PVRHaveAlphaPremultiplied = false; // Values taken from PVRTexture.h from http://www.imgtec.com @@ -752,28 +763,164 @@ bool Image::isCompressed() return Texture2D::getPixelFormatInfoMap().at(_renderFormat).compressed; } +namespace +{ +/* + * ERROR HANDLING: + * + * The JPEG library's standard error handler (jerror.c) is divided into + * several "methods" which you can override individually. This lets you + * adjust the behavior without duplicating a lot of code, which you might + * have to update with each future release. + * + * We override the "error_exit" method so that control is returned to the + * library's caller when a fatal error occurs, rather than calling exit() + * as the standard error_exit method does. + * + * We use C's setjmp/longjmp facility to return control. This means that the + * routine which calls the JPEG library must first execute a setjmp() call to + * establish the return point. We want the replacement error_exit to do a + * longjmp(). But we need to make the setjmp buffer accessible to the + * error_exit routine. To do this, we make a private extension of the + * standard JPEG error handler object. (If we were using C++, we'd say we + * were making a subclass of the regular error handler.) + * + * Here's the extended error handler struct: + */ +#if CC_USE_JPEG + struct MyErrorMgr + { + struct jpeg_error_mgr pub; /* "public" fields */ + jmp_buf setjmp_buffer; /* for return to caller */ + }; + + typedef struct MyErrorMgr * MyErrorPtr; + + /* + * Here's the routine that will replace the standard error_exit method: + */ + + METHODDEF(void) + myErrorExit(j_common_ptr cinfo) + { + /* cinfo->err really points to a MyErrorMgr struct, so coerce pointer */ + MyErrorPtr myerr = (MyErrorPtr) cinfo->err; + + /* Always display the message. */ + /* We could postpone this until after returning, if we chose. */ + /* internal message function cann't show error message in some platforms, so we rewrite it here. + * edit it if has version confilict. + */ + //(*cinfo->err->output_message) (cinfo); + char buffer[JMSG_LENGTH_MAX]; + (*cinfo->err->format_message) (cinfo, buffer); + CCLOG("jpeg error: %s", buffer); + + /* Return control to the setjmp point */ + longjmp(myerr->setjmp_buffer, 1); + } +#endif // CC_USE_JPEG +} + bool Image::initWithJpgData(const unsigned char * data, ssize_t dataLen) { - _hasPremultipliedAlpha = false; - - JPEGModule *jpegModule = static_cast(ModuleManager::getModule("jpeg")); - if (jpegModule) +#if CC_USE_JPEG + /* these are standard libjpeg structures for reading(decompression) */ + struct jpeg_decompress_struct cinfo; + /* We use our private extension JPEG error handler. + * Note that this struct must live as long as the main JPEG parameter + * struct, to avoid dangling-pointer problems. + */ + struct MyErrorMgr jerr; + /* libjpeg data structure for storing one row, that is, scanline of an image */ + JSAMPROW row_pointer[1] = {0}; + unsigned long location = 0; + unsigned int i = 0; + + bool bRet = false; + do { - DataFromModule dataFromJPEGInit; - bool result = jpegModule->initWithJPEGData(data, dataLen, dataFromJPEGInit); - _width = dataFromJPEGInit.width; - _height = dataFromJPEGInit.height; - _renderFormat = dataFromJPEGInit.renderFormat; - _dataLen = dataFromJPEGInit.dataLength; - _data = dataFromJPEGInit.data; - - return result; - } - else + /* We set up the normal JPEG error routines, then override error_exit. */ + cinfo.err = jpeg_std_error(&jerr.pub); + jerr.pub.error_exit = myErrorExit; + /* Establish the setjmp return context for MyErrorExit to use. */ + if (setjmp(jerr.setjmp_buffer)) { + /* If we get here, the JPEG code has signaled an error. + * We need to clean up the JPEG object, close the input file, and return. + */ + jpeg_destroy_decompress(&cinfo); + break; + } + + /* setup decompression process and source, then read JPEG header */ + jpeg_create_decompress( &cinfo ); + +#ifndef CC_TARGET_QT5 + jpeg_mem_src( &cinfo, const_cast(data), dataLen ); +#endif /* CC_TARGET_QT5 */ + + /* reading the image header which contains image information */ +#if (JPEG_LIB_VERSION >= 90) + // libjpeg 0.9 adds stricter types. + jpeg_read_header( &cinfo, TRUE ); +#else + jpeg_read_header( &cinfo, true ); +#endif + + // we only support RGB or grayscale + if (cinfo.jpeg_color_space == JCS_GRAYSCALE) + { + _renderFormat = Texture2D::PixelFormat::I8; + }else + { + cinfo.out_color_space = JCS_RGB; + _renderFormat = Texture2D::PixelFormat::RGB888; + } + + /* Start decompression jpeg here */ + jpeg_start_decompress( &cinfo ); + + /* init image info */ + _width = cinfo.output_width; + _height = cinfo.output_height; + _hasPremultipliedAlpha = false; + row_pointer[0] = static_cast(malloc(cinfo.output_width*cinfo.output_components * sizeof(unsigned char))); + CC_BREAK_IF(! row_pointer[0]); + + _dataLen = cinfo.output_width*cinfo.output_height*cinfo.output_components; + _data = static_cast(malloc(_dataLen * sizeof(unsigned char))); + CC_BREAK_IF(! _data); + + /* now actually read the jpeg into the raw buffer */ + /* read one scan line at a time */ + while( cinfo.output_scanline < cinfo.output_height ) + { + jpeg_read_scanlines( &cinfo, row_pointer, 1 ); + for( i=0; i0) + { + n=0x80000000UL; + if ((uint64)n>mb) + n=(unsigned long)mb; + + + if((int)(isource->offset + n) <= isource->size) + { + memcpy(ma, isource->data+isource->offset, n); + isource->offset += n; + o = n; + } + else + { + return 0; + } + + ma+=o; + mb-=o; + p+=o; + if (o!=n) + { + break; + } + } + return p; + } + + static tmsize_t tiffWriteProc(thandle_t fd, void* buf, tmsize_t size) + { + CC_UNUSED_PARAM(fd); + CC_UNUSED_PARAM(buf); + CC_UNUSED_PARAM(size); + return 0; + } + + + static uint64 tiffSeekProc(thandle_t fd, uint64 off, int whence) + { + tImageSource* isource = (tImageSource*)fd; + uint64 ret = -1; + do + { + if (whence == SEEK_SET) + { + CC_BREAK_IF(off >= (uint64)isource->size); + ret = isource->offset = (uint32)off; + } + else if (whence == SEEK_CUR) + { + CC_BREAK_IF(isource->offset + off >= (uint64)isource->size); + ret = isource->offset += (uint32)off; + } + else if (whence == SEEK_END) + { + CC_BREAK_IF(off >= (uint64)isource->size); + ret = isource->offset = (uint32)(isource->size-1 - off); + } + else + { + CC_BREAK_IF(off >= (uint64)isource->size); + ret = isource->offset = (uint32)off; + } + } while (0); + + return ret; + } + + static uint64 tiffSizeProc(thandle_t fd) + { + tImageSource* pImageSrc = (tImageSource*)fd; + return pImageSrc->size; + } + + static int tiffCloseProc(thandle_t fd) + { + CC_UNUSED_PARAM(fd); + return 0; + } + + static int tiffMapProc(thandle_t fd, void** pbase, toff_t* psize) + { + CC_UNUSED_PARAM(fd); + CC_UNUSED_PARAM(pbase); + CC_UNUSED_PARAM(psize); + return 0; + } + + static void tiffUnmapProc(thandle_t fd, void* base, toff_t size) + { + CC_UNUSED_PARAM(fd); + CC_UNUSED_PARAM(base); + CC_UNUSED_PARAM(size); + } +} +#endif // CC_USE_TIFF + bool Image::initWithTiffData(const unsigned char * data, ssize_t dataLen) { - _hasPremultipliedAlpha = true; - - TIFFModule *tiffModule = static_cast(ModuleManager::getModule("tiff")); - if (tiffModule) +#if CC_USE_TIFF + bool bRet = false; + do { - DataFromModule dataFromTIFFInit; - bool result = tiffModule->initWithTIFFData(data, dataLen, dataFromTIFFInit); - _width = dataFromTIFFInit.width; - _height = dataFromTIFFInit.height; - _renderFormat = dataFromTIFFInit.renderFormat; - _dataLen = dataFromTIFFInit.dataLength; - _data = dataFromTIFFInit.data; + // set the read call back function + tImageSource imageSource; + imageSource.data = data; + imageSource.size = dataLen; + imageSource.offset = 0; + + TIFF* tif = TIFFClientOpen("file.tif", "r", (thandle_t)&imageSource, + tiffReadProc, tiffWriteProc, + tiffSeekProc, tiffCloseProc, tiffSizeProc, + tiffMapProc, + tiffUnmapProc); + + CC_BREAK_IF(nullptr == tif); + + uint32 w = 0, h = 0; + uint16 bitsPerSample = 0, samplePerPixel = 0, planarConfig = 0; + size_t npixels = 0; - return result; - } - else - { - CCLOG("tiff module is not enabled"); - return false; - } + TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w); + TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h); + TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &bitsPerSample); + TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &samplePerPixel); + TIFFGetField(tif, TIFFTAG_PLANARCONFIG, &planarConfig); + + npixels = w * h; + + _renderFormat = Texture2D::PixelFormat::RGBA8888; + _width = w; + _height = h; + + _dataLen = npixels * sizeof (uint32); + _data = static_cast(malloc(_dataLen * sizeof(unsigned char))); + + uint32* raster = (uint32*) _TIFFmalloc(npixels * sizeof (uint32)); + if (raster != nullptr) + { + if (TIFFReadRGBAImageOriented(tif, w, h, raster, ORIENTATION_TOPLEFT, 0)) + { + /* the raster data is pre-multiplied by the alpha component + after invoking TIFFReadRGBAImageOriented*/ + _hasPremultipliedAlpha = true; + + memcpy(_data, raster, npixels*sizeof (uint32)); + } + + _TIFFfree(raster); + } + + + TIFFClose(tif); + + bRet = true; + } while (0); + return bRet; +#else + CCLOG("tiff is not enabled, please enalbe it in ccConfig.h"); + return false; +#endif } namespace @@ -1727,29 +2028,47 @@ bool Image::initWithPVRData(const unsigned char * data, ssize_t dataLen) bool Image::initWithWebpData(const unsigned char * data, ssize_t dataLen) { +#if CC_USE_WEBP + bool bRet = false; + #if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) CCLOG("WEBP image format not supported on WinRT or WP8"); - return false; #else - WEBPModule *webpModule = static_cast(ModuleManager::getModule("webp")); - if (webpModule) - { - DataFromModule dataFromWEBPInit; - bool result = webpModule->initWithWEBPData(data, dataLen, dataFromWEBPInit); - _width = dataFromWEBPInit.width; - _height = dataFromWEBPInit.height; - _renderFormat = dataFromWEBPInit.renderFormat; - _dataLen = dataFromWEBPInit.dataLength; - _data = dataFromWEBPInit.data; + do + { + WebPDecoderConfig config; + if (WebPInitDecoderConfig(&config) == 0) break; + if (WebPGetFeatures(static_cast(data), dataLen, &config.input) != VP8_STATUS_OK) break; + if (config.input.width == 0 || config.input.height == 0) break; - return result; - } - else - { - CCLOG("webp module is not enabled"); - return false; - } -#endif + config.output.colorspace = MODE_RGBA; + _renderFormat = Texture2D::PixelFormat::RGBA8888; + _width = config.input.width; + _height = config.input.height; + + _dataLen = _width * _height * 4; + _data = static_cast(malloc(_dataLen * sizeof(unsigned char))); + + config.output.u.RGBA.rgba = static_cast(_data); + config.output.u.RGBA.stride = _width * 4; + config.output.u.RGBA.size = _dataLen; + config.output.is_external_memory = 1; + + if (WebPDecode(static_cast(data), dataLen, &config) != VP8_STATUS_OK) + { + free(_data); + _data = nullptr; + break; + } + + bRet = true; + } while (0); +#endif // (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) + return bRet; +#else + CCLOG("webp is not enabled, please enable it in ccConfig.h"); + return false; +#endif // CC_USE_WEBP } @@ -1968,16 +2287,87 @@ bool Image::saveImageToPNG(const std::string& filePath, bool isToRGB) } bool Image::saveImageToJPG(const std::string& filePath) { - JPEGModule *jpegModule = static_cast(ModuleManager::getModule("jpeg")); - if (jpegModule) +#if CC_USE_JPEG + bool bRet = false; + do { - return jpegModule->saveImage(filePath, this); - } - else - { - CCLOG("jpeg module is not enabled"); - return false; - } + struct jpeg_compress_struct cinfo; + struct jpeg_error_mgr jerr; + FILE * outfile; /* target file */ + JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */ + int row_stride; /* physical row width in image buffer */ + + cinfo.err = jpeg_std_error(&jerr); + /* Now we can initialize the JPEG compression object. */ + jpeg_create_compress(&cinfo); + + CC_BREAK_IF((outfile = fopen(filePath.c_str(), "wb")) == nullptr); + + jpeg_stdio_dest(&cinfo, outfile); + + cinfo.image_width = _width; /* image width and height, in pixels */ + cinfo.image_height = _height; + cinfo.input_components = 3; /* # of color components per pixel */ + cinfo.in_color_space = JCS_RGB; /* colorspace of input image */ + + jpeg_set_defaults(&cinfo); + jpeg_set_quality(&cinfo, 90, TRUE); + + jpeg_start_compress(&cinfo, TRUE); + + row_stride = _width * 3; /* JSAMPLEs per row in image_buffer */ + + if (hasAlpha()) + { + unsigned char *pTempData = static_cast(malloc(_width * _height * 3 * sizeof(unsigned char))); + if (nullptr == pTempData) + { + jpeg_finish_compress(&cinfo); + jpeg_destroy_compress(&cinfo); + fclose(outfile); + break; + } + + for (int i = 0; i < _height; ++i) + { + for (int j = 0; j < _width; ++j) + + { + pTempData[(i * _width + j) * 3] = _data[(i * _width + j) * 4]; + pTempData[(i * _width + j) * 3 + 1] = _data[(i * _width + j) * 4 + 1]; + pTempData[(i * _width + j) * 3 + 2] = _data[(i * _width + j) * 4 + 2]; + } + } + + while (cinfo.next_scanline < cinfo.image_height) { + row_pointer[0] = & pTempData[cinfo.next_scanline * row_stride]; + (void) jpeg_write_scanlines(&cinfo, row_pointer, 1); + } + + if (pTempData != nullptr) + { + free(pTempData); + } + } + else + { + while (cinfo.next_scanline < cinfo.image_height) { + row_pointer[0] = & _data[cinfo.next_scanline * row_stride]; + (void) jpeg_write_scanlines(&cinfo, row_pointer, 1); + } + } + + jpeg_finish_compress(&cinfo); + fclose(outfile); + jpeg_destroy_compress(&cinfo); + + bRet = true; + } while (0); + return bRet; +#else + CCLOG("jpeg is not enabled, please enable it in ccConfig.h"); + return false; +#endif // CC_USE_JPEG } void Image::premultipliedAlpha() @@ -1994,6 +2384,7 @@ void Image::premultipliedAlpha() _hasPremultipliedAlpha = true; } + void Image::setPVRImagesHavePremultipliedAlpha(bool haveAlphaPremultiplied) { _PVRHaveAlphaPremultiplied = haveAlphaPremultiplied; diff --git a/cocos/platform/CCImage.h b/cocos/platform/CCImage.h index bb9e8d0014..483ea686ff 100644 --- a/cocos/platform/CCImage.h +++ b/cocos/platform/CCImage.h @@ -26,8 +26,6 @@ THE SOFTWARE. #ifndef __CC_IMAGE_H__ #define __CC_IMAGE_H__ -#include -#include #include "base/CCRef.h" #include "renderer/CCTexture2D.h" @@ -169,7 +167,6 @@ protected: void premultipliedAlpha(); - protected: /** @brief Determine how many mipmaps can we have. @@ -215,35 +212,6 @@ protected: bool isATITC(const unsigned char *data, ssize_t dataLen); }; -/* Data returned from jpeg/tiff/webp module initialization - */ -typedef struct DataFromModule -{ - Texture2D::PixelFormat renderFormat; - int width; - int height; - ssize_t dataLength; - unsigned char* data; - bool hasPremultiAlpha; -} DataFromModule; - -struct JPEGModule -{ - std::function saveImage; - std::function initWithJPEGData; -}; - -struct TIFFModule -{ - std::function initWithTIFFData; -}; - -struct WEBPModule -{ - std::function initWithWEBPData; -}; - - // end of platform group /// @} From 485dd1f7da0476ccbaaa51a005f968eca2e4f261 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 21 Aug 2014 15:40:22 +0800 Subject: [PATCH 04/14] Update #3897: Refactor missed protected constructors --- cocos/editor-support/cocostudio/CCInputDelegate.h | 2 +- cocos/editor-support/cocostudio/CCSSceneReader.h | 4 +++- cocos/platform/desktop/CCGLView.h | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cocos/editor-support/cocostudio/CCInputDelegate.h b/cocos/editor-support/cocostudio/CCInputDelegate.h index 89ef95b6c2..4d20fd53c2 100644 --- a/cocos/editor-support/cocostudio/CCInputDelegate.h +++ b/cocos/editor-support/cocostudio/CCInputDelegate.h @@ -43,7 +43,7 @@ namespace cocostudio { */ class InputDelegate { -protected: +CC_CONSTRUCTOR_ACCESS: /** * @js ctor */ diff --git a/cocos/editor-support/cocostudio/CCSSceneReader.h b/cocos/editor-support/cocostudio/CCSSceneReader.h index 7d982858b2..9f0d152bef 100644 --- a/cocos/editor-support/cocostudio/CCSSceneReader.h +++ b/cocos/editor-support/cocostudio/CCSSceneReader.h @@ -65,9 +65,11 @@ public: void setTarget(const std::function& selector); cocos2d::Node* getNodeByTag(int nTag); inline AttachComponentType getAttachComponentType(){return _attachComponent;} -private: +CC_CONSTRUCTOR_ACCESS: SceneReader(void); virtual ~SceneReader(void); + +private: std::string getComponentClassName(const std::string& name); cocos2d::Component* createComponent(const std::string classname); diff --git a/cocos/platform/desktop/CCGLView.h b/cocos/platform/desktop/CCGLView.h index b49a2f49d9..57f782fb05 100644 --- a/cocos/platform/desktop/CCGLView.h +++ b/cocos/platform/desktop/CCGLView.h @@ -80,7 +80,7 @@ public: /** Get retina factor */ int getRetinaFactor() const { return _retinaFactor; } -protected: +CC_CONSTRUCTOR_ACCESS: GLView(); virtual ~GLView(); @@ -88,6 +88,7 @@ protected: bool initWithFullScreen(const std::string& viewName); bool initWithFullscreen(const std::string& viewname, const GLFWvidmode &videoMode, GLFWmonitor *monitor); +protected: bool initGlew(); void updateFrameSize(); From 954448205893d6650976e37a4ef3303f2cd2335d Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 21 Aug 2014 15:40:42 +0800 Subject: [PATCH 05/14] Fix Android.mk s --- cocos/Android.mk | 1 + cocos/editor-support/cocostudio/Android.mk | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/cocos/Android.mk b/cocos/Android.mk index 92ff9a8b65..47d9e8bf5f 100644 --- a/cocos/Android.mk +++ b/cocos/Android.mk @@ -188,6 +188,7 @@ physics/chipmunk/CCPhysicsWorldInfo_chipmunk.cpp \ LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) \ $(LOCAL_PATH)/. \ $(LOCAL_PATH)/platform/android \ + $(LOCAL_PATH)/base \ $(LOCAL_PATH)/../external/tinyxml2 \ $(LOCAL_PATH)/../external/unzip \ $(LOCAL_PATH)/../external/chipmunk/include/chipmunk \ diff --git a/cocos/editor-support/cocostudio/Android.mk b/cocos/editor-support/cocostudio/Android.mk index d5efa765b3..69ea743984 100644 --- a/cocos/editor-support/cocostudio/Android.mk +++ b/cocos/editor-support/cocostudio/Android.mk @@ -66,7 +66,8 @@ $(LOCAL_PATH)/../../../external LOCAL_C_INCLUDES := $(LOCAL_PATH)/../.. \ $(LOCAL_PATH)/../../../external \ $(LOCAL_PATH)/.. \ -$(LOCAL_PATH)/../.. +$(LOCAL_PATH)/../.. \ +$(LOCAL_PATH)/WidgetReader LOCAL_CFLAGS += -fexceptions From 5fb9f596332f9523c66841fd68f5aaa368f56c8d Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 21 Aug 2014 15:40:53 +0800 Subject: [PATCH 06/14] Fix small issues --- cocos/3d/CCBundleReader.h | 2 +- cocos/base/CCData.cpp | 2 +- cocos/base/CCData.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cocos/3d/CCBundleReader.h b/cocos/3d/CCBundleReader.h index 4efc71f368..d71e17f74d 100644 --- a/cocos/3d/CCBundleReader.h +++ b/cocos/3d/CCBundleReader.h @@ -87,7 +87,7 @@ public: /** * Returns the position of the file pointer. */ - long int tell(); + ssize_t tell(); /** * Sets the position of the file pointer. diff --git a/cocos/base/CCData.cpp b/cocos/base/CCData.cpp index fda70d44b7..3092202337 100644 --- a/cocos/base/CCData.cpp +++ b/cocos/base/CCData.cpp @@ -100,7 +100,7 @@ ssize_t Data::getSize() const return _size; } -void Data::copy(unsigned char* bytes, const ssize_t size) +void Data::copy(const unsigned char* bytes, const ssize_t size) { clear(); diff --git a/cocos/base/CCData.h b/cocos/base/CCData.h index 8a9ec870e2..7532093bae 100644 --- a/cocos/base/CCData.h +++ b/cocos/base/CCData.h @@ -63,7 +63,7 @@ public: * Developer should free the pointer after invoking this method. * @see Data::fastSet */ - void copy(unsigned char* bytes, const ssize_t size); + void copy(const unsigned char* bytes, const ssize_t size); /** Fast set the buffer pointer and its size. Please use it carefully. * @param bytes The buffer pointer, note that it have to be allocated by 'malloc' or 'calloc', From 4563e6542718f6618ce5c8a70827a12596655812 Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 21 Aug 2014 15:41:05 +0800 Subject: [PATCH 07/14] fix compiling error on android and fix some coding style --- cocos/Android.mk | 6 ++ cocos/platform/CCImage.cpp | 141 +++++++++++++++++++------------------ 2 files changed, 78 insertions(+), 69 deletions(-) diff --git a/cocos/Android.mk b/cocos/Android.mk index e18bfa6995..69112f9a5d 100644 --- a/cocos/Android.mk +++ b/cocos/Android.mk @@ -214,6 +214,9 @@ LOCAL_EXPORT_LDLIBS := -lGLESv2 \ LOCAL_STATIC_LIBRARIES := cocos_freetype2_static LOCAL_STATIC_LIBRARIES += chipmunk_static LOCAL_STATIC_LIBRARIES += cocos_png_static +LOCAL_STATIC_LIBRARIES += cocos_jpeg_static +LOCAL_STATIC_LIBRARIES += cocos_tiff_static +LOCAL_STATIC_LIBRARIES += cocos_webp_static LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dxandroid_static # define the macro to compile through support/zip_support/ioapi.c @@ -228,3 +231,6 @@ $(call import-module,freetype2/prebuilt/android) $(call import-module,chipmunk) $(call import-module,platform/android) $(call import-module,png/prebuilt/android) +$(call import-module,jpeg/prebuilt/android) +$(call import-module,tiff/prebuilt/android) +$(call import-module,webp/prebuilt/android) diff --git a/cocos/platform/CCImage.cpp b/cocos/platform/CCImage.cpp index 3de73e09b7..d022327fc1 100644 --- a/cocos/platform/CCImage.cpp +++ b/cocos/platform/CCImage.cpp @@ -30,7 +30,7 @@ THE SOFTWARE. #include #include "base/CCData.h" -#include "ccConfig.h" // CC_USE_JPEG, CC_USE_TIFF, CC_USE_WEBP +#include "base/ccConfig.h" // CC_USE_JPEG, CC_USE_TIFF, CC_USE_WEBP extern "C" { @@ -837,14 +837,15 @@ bool Image::initWithJpgData(const unsigned char * data, ssize_t dataLen) unsigned long location = 0; unsigned int i = 0; - bool bRet = false; + bool ret = false; do { /* We set up the normal JPEG error routines, then override error_exit. */ cinfo.err = jpeg_std_error(&jerr.pub); jerr.pub.error_exit = myErrorExit; /* Establish the setjmp return context for MyErrorExit to use. */ - if (setjmp(jerr.setjmp_buffer)) { + if (setjmp(jerr.setjmp_buffer)) + { /* If we get here, the JPEG code has signaled an error. * We need to clean up the JPEG object, close the input file, and return. */ @@ -856,15 +857,15 @@ bool Image::initWithJpgData(const unsigned char * data, ssize_t dataLen) jpeg_create_decompress( &cinfo ); #ifndef CC_TARGET_QT5 - jpeg_mem_src( &cinfo, const_cast(data), dataLen ); + jpeg_mem_src(&cinfo, const_cast(data), dataLen); #endif /* CC_TARGET_QT5 */ /* reading the image header which contains image information */ #if (JPEG_LIB_VERSION >= 90) // libjpeg 0.9 adds stricter types. - jpeg_read_header( &cinfo, TRUE ); + jpeg_read_header(&cinfo, TRUE); #else - jpeg_read_header( &cinfo, true ); + jpeg_read_header(&cinfo, TRUE); #endif // we only support RGB or grayscale @@ -893,10 +894,10 @@ bool Image::initWithJpgData(const unsigned char * data, ssize_t dataLen) /* now actually read the jpeg into the raw buffer */ /* read one scan line at a time */ - while( cinfo.output_scanline < cinfo.output_height ) + while (cinfo.output_scanline < cinfo.output_height) { jpeg_read_scanlines( &cinfo, row_pointer, 1 ); - for( i=0; i(malloc(_dataLen * sizeof(unsigned char))); - if(!_data) + if (!_data) { if (row_pointers != nullptr) { @@ -1062,14 +1064,14 @@ bool Image::initWithPngData(const unsigned char * data, ssize_t dataLen) free(row_pointers); } - bRet = true; + ret = true; } while (0); if (png_ptr) { png_destroy_read_struct(&png_ptr, (info_ptr) ? &info_ptr : 0, 0); } - return bRet; + return ret; } #if CC_USE_TIFF @@ -1090,10 +1092,10 @@ namespace { n=0x80000000UL; if ((uint64)n>mb) - n=(unsigned long)mb; + n=(unsigned long)mb; - if((int)(isource->offset + n) <= isource->size) + if ((int)(isource->offset + n) <= isource->size) { memcpy(ma, isource->data+isource->offset, n); isource->offset += n; @@ -1157,8 +1159,8 @@ namespace static uint64 tiffSizeProc(thandle_t fd) { - tImageSource* pImageSrc = (tImageSource*)fd; - return pImageSrc->size; + tImageSource* imageSrc = (tImageSource*)fd; + return imageSrc->size; } static int tiffCloseProc(thandle_t fd) @@ -1167,11 +1169,11 @@ namespace return 0; } - static int tiffMapProc(thandle_t fd, void** pbase, toff_t* psize) + static int tiffMapProc(thandle_t fd, void** base, toff_t* size) { CC_UNUSED_PARAM(fd); - CC_UNUSED_PARAM(pbase); - CC_UNUSED_PARAM(psize); + CC_UNUSED_PARAM(base); + CC_UNUSED_PARAM(size); return 0; } @@ -1187,7 +1189,7 @@ namespace bool Image::initWithTiffData(const unsigned char * data, ssize_t dataLen) { #if CC_USE_TIFF - bool bRet = false; + bool ret = false; do { // set the read call back function @@ -1241,9 +1243,9 @@ bool Image::initWithTiffData(const unsigned char * data, ssize_t dataLen) TIFFClose(tif); - bRet = true; + ret = true; } while (0); - return bRet; + return ret; #else CCLOG("tiff is not enabled, please enalbe it in ccConfig.h"); return false; @@ -1368,7 +1370,7 @@ bool Image::initWithPVRv2Data(const unsigned char * data, ssize_t dataLen) { switch (formatFlags) { case PVR2TexturePixelFormat::PVRTC2BPP_RGBA: - if(!Configuration::getInstance()->supportsPVRTC()) + if (!Configuration::getInstance()->supportsPVRTC()) { CCLOG("cocos2d: Hardware PVR decoder not present. Using software decoder"); _unpack = true; @@ -1382,7 +1384,7 @@ bool Image::initWithPVRv2Data(const unsigned char * data, ssize_t dataLen) heightBlocks = height / 4; break; case PVR2TexturePixelFormat::PVRTC4BPP_RGBA: - if(!Configuration::getInstance()->supportsPVRTC()) + if (!Configuration::getInstance()->supportsPVRTC()) { CCLOG("cocos2d: Hardware PVR decoder not present. Using software decoder"); _unpack = true; @@ -1522,7 +1524,7 @@ bool Image::initWithPVRv3Data(const unsigned char * data, ssize_t dataLen) { case PVR3TexturePixelFormat::PVRTC2BPP_RGB : case PVR3TexturePixelFormat::PVRTC2BPP_RGBA : - if(!Configuration::getInstance()->supportsPVRTC()) + if (!Configuration::getInstance()->supportsPVRTC()) { CCLOG("cocos2d: Hardware PVR decoder not present. Using software decoder"); _unpack = true; @@ -1537,7 +1539,7 @@ bool Image::initWithPVRv3Data(const unsigned char * data, ssize_t dataLen) break; case PVR3TexturePixelFormat::PVRTC4BPP_RGB : case PVR3TexturePixelFormat::PVRTC4BPP_RGBA : - if(!Configuration::getInstance()->supportsPVRTC()) + if (!Configuration::getInstance()->supportsPVRTC()) { CCLOG("cocos2d: Hardware PVR decoder not present. Using software decoder"); _unpack = true; @@ -1551,7 +1553,7 @@ bool Image::initWithPVRv3Data(const unsigned char * data, ssize_t dataLen) heightBlocks = height / 4; break; case PVR3TexturePixelFormat::ETC1: - if(!Configuration::getInstance()->supportsETC()) + if (!Configuration::getInstance()->supportsETC()) { CCLOG("cocos2d: Hardware ETC1 decoder not present. Using software decoder"); int bytePerPixel = 3; @@ -1569,7 +1571,7 @@ bool Image::initWithPVRv3Data(const unsigned char * data, ssize_t dataLen) heightBlocks = height / 4; break; case PVR3TexturePixelFormat::BGRA8888: - if( ! Configuration::getInstance()->supportsBGRA8888()) + if (! Configuration::getInstance()->supportsBGRA8888()) { CCLOG("cocos2d: Image. BGRA8888 not supported on this device"); return false; @@ -1609,7 +1611,7 @@ bool Image::initWithPVRv3Data(const unsigned char * data, ssize_t dataLen) height = MAX(height >> 1, 1); } - if(_unpack) + if (_unpack) { _data = _mipmaps[0].address; _dataLen = _mipmaps[0].len; @@ -1623,7 +1625,7 @@ bool Image::initWithETCData(const unsigned char * data, ssize_t dataLen) const etc1_byte* header = static_cast(data); //check the data - if(!etc1_pkm_is_valid(header)) + if (! etc1_pkm_is_valid(header)) { return false; } @@ -1631,12 +1633,12 @@ bool Image::initWithETCData(const unsigned char * data, ssize_t dataLen) _width = etc1_pkm_get_width(header); _height = etc1_pkm_get_height(header); - if( 0 == _width || 0 == _height ) + if (0 == _width || 0 == _height) { return false; } - if(Configuration::getInstance()->supportsETC()) + if (Configuration::getInstance()->supportsETC()) { //old opengl version has no define for GL_ETC1_RGB8_OES, add macro to make compiler happy. #ifdef GL_ETC1_RGB8_OES @@ -2029,7 +2031,7 @@ bool Image::initWithPVRData(const unsigned char * data, ssize_t dataLen) bool Image::initWithWebpData(const unsigned char * data, ssize_t dataLen) { #if CC_USE_WEBP - bool bRet = false; + bool ret = false; #if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) CCLOG("WEBP image format not supported on WinRT or WP8"); @@ -2061,10 +2063,10 @@ bool Image::initWithWebpData(const unsigned char * data, ssize_t dataLen) break; } - bRet = true; + ret = true; } while (0); #endif // (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) - return bRet; + return ret; #else CCLOG("webp is not enabled, please enable it in ccConfig.h"); return false; @@ -2074,7 +2076,7 @@ bool Image::initWithWebpData(const unsigned char * data, ssize_t dataLen) bool Image::initWithRawData(const unsigned char * data, ssize_t dataLen, int width, int height, int bitsPerComponent, bool preMulti) { - bool bRet = false; + bool ret = false; do { CC_BREAK_IF(0 == width || 0 == height); @@ -2091,15 +2093,15 @@ bool Image::initWithRawData(const unsigned char * data, ssize_t dataLen, int wid CC_BREAK_IF(! _data); memcpy(_data, data, _dataLen); - bRet = true; + ret = true; } while (0); - return bRet; + return ret; } #if (CC_TARGET_PLATFORM != CC_PLATFORM_IOS) -bool Image::saveToFile(const std::string& filename, bool bIsToRGB) +bool Image::saveToFile(const std::string& filename, bool isToRGB) { //only support for Texture2D::PixelFormat::RGB888 or Texture2D::PixelFormat::RGBA8888 uncompressed data if (isCompressed() || (_renderFormat != Texture2D::PixelFormat::RGB888 && _renderFormat != Texture2D::PixelFormat::RGBA8888)) @@ -2108,7 +2110,7 @@ bool Image::saveToFile(const std::string& filename, bool bIsToRGB) return false; } - bool bRet = false; + bool ret = false; do { @@ -2123,7 +2125,7 @@ bool Image::saveToFile(const std::string& filename, bool bIsToRGB) if (std::string::npos != strLowerCasePath.find(".png")) { - CC_BREAK_IF(!saveImageToPNG(filename, bIsToRGB)); + CC_BREAK_IF(!saveImageToPNG(filename, isToRGB)); } else if (std::string::npos != strLowerCasePath.find(".jpg")) { @@ -2134,16 +2136,16 @@ bool Image::saveToFile(const std::string& filename, bool bIsToRGB) break; } - bRet = true; + ret = true; } while (0); - return bRet; + return ret; } #endif bool Image::saveImageToPNG(const std::string& filePath, bool isToRGB) { - bool bRet = false; + bool ret = false; do { FILE *fp; @@ -2222,8 +2224,8 @@ bool Image::saveImageToPNG(const std::string& filePath, bool isToRGB) { if (isToRGB) { - unsigned char *pTempData = static_cast(malloc(_width * _height * 3 * sizeof(unsigned char))); - if (nullptr == pTempData) + unsigned char *tempData = static_cast(malloc(_width * _height * 3 * sizeof(unsigned char))); + if (nullptr == tempData) { fclose(fp); png_destroy_write_struct(&png_ptr, &info_ptr); @@ -2237,15 +2239,15 @@ bool Image::saveImageToPNG(const std::string& filePath, bool isToRGB) { for (int j = 0; j < _width; ++j) { - pTempData[(i * _width + j) * 3] = _data[(i * _width + j) * 4]; - pTempData[(i * _width + j) * 3 + 1] = _data[(i * _width + j) * 4 + 1]; - pTempData[(i * _width + j) * 3 + 2] = _data[(i * _width + j) * 4 + 2]; + tempData[(i * _width + j) * 3] = _data[(i * _width + j) * 4]; + tempData[(i * _width + j) * 3 + 1] = _data[(i * _width + j) * 4 + 1]; + tempData[(i * _width + j) * 3 + 2] = _data[(i * _width + j) * 4 + 2]; } } for (int i = 0; i < (int)_height; i++) { - row_pointers[i] = (png_bytep)pTempData + i * _width * 3; + row_pointers[i] = (png_bytep)tempData + i * _width * 3; } png_write_image(png_ptr, row_pointers); @@ -2253,9 +2255,9 @@ bool Image::saveImageToPNG(const std::string& filePath, bool isToRGB) free(row_pointers); row_pointers = nullptr; - if (pTempData != nullptr) + if (tempData != nullptr) { - free(pTempData); + free(tempData); } } else @@ -2281,14 +2283,14 @@ bool Image::saveImageToPNG(const std::string& filePath, bool isToRGB) fclose(fp); - bRet = true; + ret = true; } while (0); - return bRet; + return ret; } bool Image::saveImageToJPG(const std::string& filePath) { #if CC_USE_JPEG - bool bRet = false; + bool ret = false; do { struct jpeg_compress_struct cinfo; @@ -2319,8 +2321,8 @@ bool Image::saveImageToJPG(const std::string& filePath) if (hasAlpha()) { - unsigned char *pTempData = static_cast(malloc(_width * _height * 3 * sizeof(unsigned char))); - if (nullptr == pTempData) + unsigned char *tempData = static_cast(malloc(_width * _height * 3 * sizeof(unsigned char))); + if (nullptr == tempData) { jpeg_finish_compress(&cinfo); jpeg_destroy_compress(&cinfo); @@ -2333,20 +2335,21 @@ bool Image::saveImageToJPG(const std::string& filePath) for (int j = 0; j < _width; ++j) { - pTempData[(i * _width + j) * 3] = _data[(i * _width + j) * 4]; - pTempData[(i * _width + j) * 3 + 1] = _data[(i * _width + j) * 4 + 1]; - pTempData[(i * _width + j) * 3 + 2] = _data[(i * _width + j) * 4 + 2]; + tempData[(i * _width + j) * 3] = _data[(i * _width + j) * 4]; + tempData[(i * _width + j) * 3 + 1] = _data[(i * _width + j) * 4 + 1]; + tempData[(i * _width + j) * 3 + 2] = _data[(i * _width + j) * 4 + 2]; } } - while (cinfo.next_scanline < cinfo.image_height) { - row_pointer[0] = & pTempData[cinfo.next_scanline * row_stride]; + while (cinfo.next_scanline < cinfo.image_height) + { + row_pointer[0] = & tempData[cinfo.next_scanline * row_stride]; (void) jpeg_write_scanlines(&cinfo, row_pointer, 1); } - if (pTempData != nullptr) + if (tempData != nullptr) { - free(pTempData); + free(tempData); } } else @@ -2361,9 +2364,9 @@ bool Image::saveImageToJPG(const std::string& filePath) fclose(outfile); jpeg_destroy_compress(&cinfo); - bRet = true; + ret = true; } while (0); - return bRet; + return ret; #else CCLOG("jpeg is not enabled, please enable it in ccConfig.h"); return false; From 2afbc7a698ae371d48515dc5fc0ce822bb13df9d Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 21 Aug 2014 16:21:23 +0800 Subject: [PATCH 08/14] fix warnings --- cocos/2d/CCSpriteFrameCache.cpp | 4 ++-- cocos/editor-support/cocostudio/CCActionManagerEx.cpp | 4 ++-- cocos/editor-support/cocostudio/CCSGUIReader.cpp | 2 +- cocos/renderer/CCPrimitive.cpp | 3 ++- cocos/renderer/CCVertexIndexData.cpp | 3 ++- cocos/ui/UICheckBox.cpp | 10 +++++----- tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp | 2 +- 7 files changed, 15 insertions(+), 13 deletions(-) diff --git a/cocos/2d/CCSpriteFrameCache.cpp b/cocos/2d/CCSpriteFrameCache.cpp index b86d6054c8..c3bbd003de 100644 --- a/cocos/2d/CCSpriteFrameCache.cpp +++ b/cocos/2d/CCSpriteFrameCache.cpp @@ -212,7 +212,7 @@ void SpriteFrameCache::addSpriteFramesWithFile(const std::string& plist, Texture void SpriteFrameCache::addSpriteFramesWithFileContent(const std::string& plist_content, Texture2D *texture) { - ValueMap dict = FileUtils::getInstance()->getValueMapFromData(plist_content.c_str(), plist_content.size()); + ValueMap dict = FileUtils::getInstance()->getValueMapFromData(plist_content.c_str(), static_cast(plist_content.size())); addSpriteFramesWithDictionary(dict, texture); } @@ -365,7 +365,7 @@ void SpriteFrameCache::removeSpriteFramesFromFile(const std::string& plist) void SpriteFrameCache::removeSpriteFramesFromFileContent(const std::string& plist_content) { - ValueMap dict = FileUtils::getInstance()->getValueMapFromData(plist_content.data(), plist_content.size()); + ValueMap dict = FileUtils::getInstance()->getValueMapFromData(plist_content.data(), static_cast(plist_content.size())); if (dict.empty()) { CCLOG("cocos2d:SpriteFrameCache:removeSpriteFramesFromFileContent: create dict by fail."); diff --git a/cocos/editor-support/cocostudio/CCActionManagerEx.cpp b/cocos/editor-support/cocostudio/CCActionManagerEx.cpp index 76a15e0bba..c935863e6f 100644 --- a/cocos/editor-support/cocostudio/CCActionManagerEx.cpp +++ b/cocos/editor-support/cocostudio/CCActionManagerEx.cpp @@ -159,8 +159,8 @@ void ActionManagerEx::releaseActions() for (iter = _actionDic.begin(); iter != _actionDic.end(); iter++) { cocos2d::Vector objList = iter->second; - int listCount = objList.size(); - for (int i = 0; i < listCount; i++) { + ssize_t listCount = objList.size(); + for (ssize_t i = 0; i < listCount; i++) { ActionObject* action = objList.at(i); if (action != nullptr) { action->stop(); diff --git a/cocos/editor-support/cocostudio/CCSGUIReader.cpp b/cocos/editor-support/cocostudio/CCSGUIReader.cpp index d86f04c166..a4359e8604 100644 --- a/cocos/editor-support/cocostudio/CCSGUIReader.cpp +++ b/cocos/editor-support/cocostudio/CCSGUIReader.cpp @@ -781,7 +781,7 @@ void WidgetPropertiesReader0250::setPropsForCheckBoxFromJsonDictionary(Widget*wi { checkBox->loadTextures(backGroundFileName_tp, backGroundSelectedFileName_tp, frontCrossFileName_tp,backGroundDisabledFileName_tp,frontCrossDisabledFileName_tp); } - checkBox->setSelectedState(DICTOOL->getBooleanValue_json(options, "selectedState")); + checkBox->setSelected(DICTOOL->getBooleanValue_json(options, "selectedState")); setColorPropsForWidgetFromJsonDictionary(widget,options); } diff --git a/cocos/renderer/CCPrimitive.cpp b/cocos/renderer/CCPrimitive.cpp index 8d0d27f63d..357e61fa43 100644 --- a/cocos/renderer/CCPrimitive.cpp +++ b/cocos/renderer/CCPrimitive.cpp @@ -93,7 +93,8 @@ void Primitive::draw() { GLenum type = (_indices->getType() == IndexBuffer::IndexType::INDEX_TYPE_SHORT_16) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT; glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indices->getVBO()); - glDrawElements((GLenum)_type, _count, type, (GLvoid*)(_start * _indices->getSizePerIndex())); + size_t offet = _start * _indices->getSizePerIndex(); + glDrawElements((GLenum)_type, _count, type, (GLvoid*)offet); } else { diff --git a/cocos/renderer/CCVertexIndexData.cpp b/cocos/renderer/CCVertexIndexData.cpp index 068230e455..cbad4d76ea 100644 --- a/cocos/renderer/CCVertexIndexData.cpp +++ b/cocos/renderer/CCVertexIndexData.cpp @@ -124,8 +124,9 @@ void VertexData::use() { //glEnableVertexAttribArray((GLint)element.second._stream._semantic); glBindBuffer(GL_ARRAY_BUFFER, element.second._buffer->getVBO()); + size_t offet = element.second._stream._offset; glVertexAttribPointer(GLint(element.second._stream._semantic),element.second._stream._size, - element.second._stream._type,element.second._stream._normalize, element.second._buffer->getSizePerVertex(), (GLvoid*)element.second._stream._offset); + element.second._stream._type,element.second._stream._normalize, element.second._buffer->getSizePerVertex(), (GLvoid*)offet); } } diff --git a/cocos/ui/UICheckBox.cpp b/cocos/ui/UICheckBox.cpp index a16d4be64a..9f2d933b0c 100644 --- a/cocos/ui/UICheckBox.cpp +++ b/cocos/ui/UICheckBox.cpp @@ -118,7 +118,7 @@ bool CheckBox::init(const std::string& backGround, break; } - setSelectedState(false); + setSelected(false); loadTextures(backGround, backGroundSeleted, cross, backGroundDisabled, frontCrossDisabled,texType); } while (0); return ret; @@ -128,7 +128,7 @@ bool CheckBox::init() { if (Widget::init()) { - setSelectedState(false); + setSelected(false); return true; } return false; @@ -300,12 +300,12 @@ void CheckBox::releaseUpEvent() Widget::releaseUpEvent(); if (_isSelected){ - setSelectedState(false); + setSelected(false); unSelectedEvent(); } else { - setSelectedState(true); + setSelected(true); selectedEvent(); } } @@ -590,7 +590,7 @@ void CheckBox::copySpecialProperties(Widget *widget) loadTextureFrontCross(checkBox->_frontCrossFileName, checkBox->_frontCrossTexType); loadTextureBackGroundDisabled(checkBox->_backGroundDisabledFileName, checkBox->_backGroundDisabledTexType); loadTextureFrontCrossDisabled(checkBox->_frontCrossDisabledFileName, checkBox->_frontCrossDisabledTexType); - setSelectedState(checkBox->_isSelected); + setSelected(checkBox->_isSelected); _checkBoxEventListener = checkBox->_checkBoxEventListener; _checkBoxEventSelector = checkBox->_checkBoxEventSelector; _checkBoxEventCallback = checkBox->_checkBoxEventCallback; diff --git a/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp b/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp index 6f0eda505a..be0263bdcc 100644 --- a/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp +++ b/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp @@ -125,7 +125,7 @@ void DrawLine3D::onDraw(const Mat4 &transform, uint32_t flags) glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_COLOR); glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V3F_C4B), &(_buffer[0].colors)); - glDrawArrays(GL_LINES, 0, _buffer.size()); + glDrawArrays(GL_LINES, 0, static_cast(_buffer.size())); glDisable(GL_DEPTH_TEST); } From 634847412bebb2f6962542f59ff20b8bb421c89d Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 21 Aug 2014 19:36:28 +0800 Subject: [PATCH 09/14] Reverse CC_CONSTRUCTOR_ACCESS modification --- cocos/base/ccConfig.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/base/ccConfig.h b/cocos/base/ccConfig.h index 90c10e6a56..2225998746 100644 --- a/cocos/base/ccConfig.h +++ b/cocos/base/ccConfig.h @@ -281,7 +281,7 @@ To enable set it to a value different than 0. Disabled by default. protected by default. */ #ifndef CC_CONSTRUCTOR_ACCESS -#define CC_CONSTRUCTOR_ACCESS public +#define CC_CONSTRUCTOR_ACCESS protected #endif #endif // __CCCONFIG_H__ From 59cedea6dc1070657b82fae49abd1026ab4be055 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 21 Aug 2014 19:40:18 +0800 Subject: [PATCH 10/14] Reverse useless change --- cocos/platform/desktop/CCGLViewImpl.h | 1 - 1 file changed, 1 deletion(-) diff --git a/cocos/platform/desktop/CCGLViewImpl.h b/cocos/platform/desktop/CCGLViewImpl.h index 58e0687164..368e6d97a2 100644 --- a/cocos/platform/desktop/CCGLViewImpl.h +++ b/cocos/platform/desktop/CCGLViewImpl.h @@ -116,7 +116,6 @@ protected: bool initWithFullScreen(const std::string& viewName); bool initWithFullscreen(const std::string& viewname, const GLFWvidmode &videoMode, GLFWmonitor *monitor); -protected: bool initGlew(); void updateFrameSize(); From bb5e189f300fef677fda216bc2852291a86b2086 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 21 Aug 2014 20:02:22 +0800 Subject: [PATCH 11/14] Fix warning or Bundle3D --- cocos/3d/CCBundle3D.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cocos/3d/CCBundle3D.h b/cocos/3d/CCBundle3D.h index b2b40aaf86..f66b0db5f6 100644 --- a/cocos/3d/CCBundle3D.h +++ b/cocos/3d/CCBundle3D.h @@ -168,10 +168,9 @@ protected: */ Reference* seekToFirstType(unsigned int type); -protected: CC_CONSTRUCTOR_ACCESS: Bundle3D(); - ~Bundle3D(); + virtual ~Bundle3D(); protected: From 7fd1521bbfb93cfa7ced028e3222884f2bd8cb97 Mon Sep 17 00:00:00 2001 From: minggo Date: Fri, 22 Aug 2014 11:48:14 +0800 Subject: [PATCH 12/14] update version --- CHANGELOG | 2 +- cocos/cocos2d.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index da8dcfcd4b..c79a097717 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,4 @@ -cocos2d-x-3.3 ?? +cocos2d-x-3.3alpha0 ?? [NEW] Added UIScale9Sprite [NEW] Added Camera, AABB, OBB and Ray [NEW] Added render primitive and render primitive command, support passing point, line and triangle data diff --git a/cocos/cocos2d.cpp b/cocos/cocos2d.cpp index 83c40ab695..adc8a7ac05 100644 --- a/cocos/cocos2d.cpp +++ b/cocos/cocos2d.cpp @@ -31,7 +31,7 @@ NS_CC_BEGIN CC_DLL const char* cocos2dVersion() { - return "cocos2d-x 3.3"; + return "cocos2d-x 3.3alpha0"; } NS_CC_END From 84cf0ee834991e9ec6ee5b16fd6f64a09d17a5e5 Mon Sep 17 00:00:00 2001 From: andyque Date: Fri, 22 Aug 2014 11:49:39 +0800 Subject: [PATCH 13/14] add disableCascadeOpacity to ProtectedNode and Scale9Sprite --- cocos/2d/CCProtectedNode.cpp | 13 +++++++++++++ cocos/2d/CCProtectedNode.h | 1 + cocos/ui/UIScale9Sprite.cpp | 13 +++++++++++++ cocos/ui/UIScale9Sprite.h | 1 + .../UITest/CocoStudioGUITest/UIScale9SpriteTest.cpp | 7 +++++-- 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/cocos/2d/CCProtectedNode.cpp b/cocos/2d/CCProtectedNode.cpp index 4eae3d0b5a..348a8c8e41 100644 --- a/cocos/2d/CCProtectedNode.cpp +++ b/cocos/2d/CCProtectedNode.cpp @@ -417,4 +417,17 @@ void ProtectedNode::disableCascadeColor() } } +void ProtectedNode::disableCascadeOpacity() +{ + _displayedOpacity = _realOpacity; + + for(auto child : _children){ + child->updateDisplayedOpacity(255); + } + + for(auto child : _protectedChildren){ + child->updateDisplayedOpacity(255); + } +} + NS_CC_END diff --git a/cocos/2d/CCProtectedNode.h b/cocos/2d/CCProtectedNode.h index dcc3ff5463..dff7fae398 100644 --- a/cocos/2d/CCProtectedNode.h +++ b/cocos/2d/CCProtectedNode.h @@ -162,6 +162,7 @@ public: virtual void updateDisplayedOpacity(GLubyte parentOpacity) override; virtual void updateDisplayedColor(const Color3B& parentColor) override; virtual void disableCascadeColor() override; + virtual void disableCascadeOpacity()override; CC_CONSTRUCTOR_ACCESS: ProtectedNode(); virtual ~ProtectedNode(); diff --git a/cocos/ui/UIScale9Sprite.cpp b/cocos/ui/UIScale9Sprite.cpp index c3f79d13b2..26c268031a 100644 --- a/cocos/ui/UIScale9Sprite.cpp +++ b/cocos/ui/UIScale9Sprite.cpp @@ -1021,6 +1021,19 @@ y+=ytranslate; \ } } + void Scale9Sprite::disableCascadeOpacity() + { + _displayedOpacity = _realOpacity; + + for(auto child : _children){ + child->updateDisplayedOpacity(255); + } + + for(auto child : _protectedChildren){ + child->updateDisplayedOpacity(255); + } + } + Sprite* Scale9Sprite::getSprite()const { return _scale9Image; diff --git a/cocos/ui/UIScale9Sprite.h b/cocos/ui/UIScale9Sprite.h index 1db19b9e1d..da54df5de0 100644 --- a/cocos/ui/UIScale9Sprite.h +++ b/cocos/ui/UIScale9Sprite.h @@ -305,6 +305,7 @@ namespace ui { virtual void updateDisplayedOpacity(GLubyte parentOpacity) override; virtual void updateDisplayedColor(const Color3B& parentColor) override; virtual void disableCascadeColor() override; + virtual void disableCascadeOpacity() override; Sprite* getSprite()const; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScale9SpriteTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScale9SpriteTest.cpp index 0a8e8d8fb9..77b3b0b68a 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScale9SpriteTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScale9SpriteTest.cpp @@ -568,8 +568,11 @@ bool UIS9CascadeOpacityAndColor::init() rgba->addChild(blocks_scaled_with_insets); auto actions = Sequence::create(FadeIn::create(1), TintTo::create(1, 0, 255, 0), - TintTo::create(1, 255, 255, 255), - FadeOut::create(1), + TintTo::create(1, 255, 0, 255), + CallFunc::create([=](){ + rgba->setCascadeColorEnabled(false); + rgba->setCascadeOpacityEnabled(false); + }), nullptr); auto repeat = RepeatForever::create(actions); rgba->runAction(repeat); From 13003fe0a633549ae5f93508a5a4e08d2f9aae08 Mon Sep 17 00:00:00 2001 From: andyque Date: Fri, 22 Aug 2014 11:56:13 +0800 Subject: [PATCH 14/14] add deprecated options for ui, add Scale9Sprite bindings --- .../lua-bindings/script/ui/DeprecatedUIFunc.lua | 13 +++++++++++++ .../CocoStudioGUITest/CocoStudioGUITest.lua | 1 + tools/tolua/cocos2dx_ui.ini | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cocos/scripting/lua-bindings/script/ui/DeprecatedUIFunc.lua b/cocos/scripting/lua-bindings/script/ui/DeprecatedUIFunc.lua index b11bf1d161..c6900ea23a 100644 --- a/cocos/scripting/lua-bindings/script/ui/DeprecatedUIFunc.lua +++ b/cocos/scripting/lua-bindings/script/ui/DeprecatedUIFunc.lua @@ -106,6 +106,19 @@ function UICheckBoxDeprecated.addEventListenerCheckBox(self,handler) return self:addEventListener(handler) end rawset(ccui.CheckBox,"addEventListenerCheckBox", UICheckBoxDeprecated.addEventListenerCheckBox) + +function UICheckBoxDeprecated.setSelectedState(self,flag) + deprecatedTip("ccui.CheckBox:setSelectedState", "ccui.CheckBox:setSelected") + return self:setSelected(flag) +end +rawset(ccui.CheckBox, "setSelectedState", UICheckBoxDeprecated.setSelectedState) + +function UICheckBoxDeprecated.getSelectedState(self) + deprecatedTip("ccui.CheckBox:getSelectedState", "ccui.CheckBox:getSelected") + return self:getSelected() +end +rawset(ccui.CheckBox, "getSelectedState", UICheckBoxDeprecated.setSelectedState) + --functions of ccui.CheckBox will be deprecated end --functions of ccui.Slider will be deprecated begin diff --git a/tests/lua-tests/src/CocoStudioTest/CocoStudioGUITest/CocoStudioGUITest.lua b/tests/lua-tests/src/CocoStudioTest/CocoStudioGUITest/CocoStudioGUITest.lua index ecf355110c..11f9ce3ed8 100644 --- a/tests/lua-tests/src/CocoStudioTest/CocoStudioGUITest/CocoStudioGUITest.lua +++ b/tests/lua-tests/src/CocoStudioTest/CocoStudioGUITest/CocoStudioGUITest.lua @@ -456,6 +456,7 @@ function UICheckBoxTest:initExtend() local checkBox = ccui.CheckBox:create() checkBox:setTouchEnabled(true) + checkBox:setSelectedState(true) checkBox:loadTextures("cocosui/check_box_normal.png", "cocosui/check_box_normal_press.png", "cocosui/check_box_active.png", diff --git a/tools/tolua/cocos2dx_ui.ini b/tools/tolua/cocos2dx_ui.ini index 79d54ac995..1852a16b97 100644 --- a/tools/tolua/cocos2dx_ui.ini +++ b/tools/tolua/cocos2dx_ui.ini @@ -30,7 +30,7 @@ headers = %(cocosdir)s/cocos/ui/CocosGUI.h # what classes to produce code for. You can use regular expressions here. When testing the regular # expression, it will be enclosed in "^$", like this: "^Menu*$". -classes = Helper Widget Layer Layout RootWidget Button CheckBox ImageView Text TextAtlas TextBMFont LoadingBar Slider Switch TextField ScrollView ListView PageView LayoutParameter LinearLayoutParameter RelativeLayoutParameter Rich.* HBox VBox RelativeBox +classes = Helper Widget Layer Layout RootWidget Button CheckBox ImageView Text TextAtlas TextBMFont LoadingBar Slider Switch TextField ScrollView ListView PageView LayoutParameter LinearLayoutParameter RelativeLayoutParameter Rich.* HBox VBox RelativeBox Scale9Sprite # what should we skip? in the format ClassName::[function function] # ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also