Merge branch 'develop' into develop_nutty_modifylayout_add_Boxes

This commit is contained in:
CaiWenzhi 2014-03-25 17:17:57 +08:00
commit c976791f7d
14 changed files with 96 additions and 8 deletions

View File

@ -1 +1 @@
819b72559f8be48c41958b0afb4c6513207b453a
5b8d2ae9f19e1ca958245cf11e144d18d6ee3f89

View File

@ -231,6 +231,8 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String)
auto pixelFormat = fontTTf->getOutlineSize() > 0 ? Texture2D::PixelFormat::AI88 : Texture2D::PixelFormat::A8;
bool existNewLetter = false;
int bottomHeight = _commonLineHeight - _fontAscender;
for (int i = 0; i < length; ++i)
{
auto outIterator = _fontLetterDefinitions.find(utf16String[i]);
@ -248,6 +250,7 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String)
tempDef.height = tempRect.size.height + _letterPadding;
tempDef.offsetX = tempRect.origin.x + offsetAdjust;
tempDef.offsetY = _fontAscender + tempRect.origin.y - offsetAdjust;
tempDef.clipBottom = bottomHeight - (tempDef.height + tempRect.origin.y + offsetAdjust);
if (_currentPageOrigX + tempDef.width > CacheTextureWidth)
{
@ -290,6 +293,7 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String)
tempDef.offsetX = 0;
tempDef.offsetY = 0;
tempDef.textureID = 0;
tempDef.clipBottom = 0;
_currentPageOrigX += 1;
}

View File

@ -50,6 +50,8 @@ struct FontLetterDefinition
int textureID;
bool validDefinition;
int xAdvance;
int clipBottom;
};
class CC_DLL FontAtlas : public Ref

View File

@ -340,6 +340,8 @@ void Label::reset()
_textColor = Color4B::WHITE;
_textColorF = Color4F::WHITE;
setColor(Color3B::WHITE);
_clipEnabled = false;
}
void Label::updateShaderProgram()

View File

@ -217,6 +217,10 @@ public:
virtual Sprite * getLetter(int lettetIndex);
/** clip upper and lower margin for reduce height of label.
*/
void setClipMarginEnabled(bool clipEnabled) { _clipEnabled = clipEnabled; }
bool isClipMarginEnabled() const { return _clipEnabled; }
// font related stuff
int getCommonLineHeight() const;
@ -365,6 +369,8 @@ protected:
Color4B _textColor;
Color4F _textColorF;
bool _clipEnabled;
private:
CC_DISALLOW_COPY_AND_ASSIGN(Label);

View File

@ -321,6 +321,16 @@ bool LabelTextFormatter::createStringSprites(Label *theLabel)
FontLetterDefinition tempDefinition;
Point letterPosition;
const auto& kernings = theLabel->_horizontalKernings;
float clipTop = 0;
float clipBottom = 0;
int lineIndex = 0;
bool lineStart = true;
bool clip = false;
if (theLabel->_currentLabelType == Label::LabelType::TTF && theLabel->_clipEnabled)
{
clip = true;
}
for (unsigned int i = 0; i < stringLen; i++)
{
@ -337,9 +347,10 @@ bool LabelTextFormatter::createStringSprites(Label *theLabel)
charYOffset = -1;
charAdvance = -1;
}
if (c == '\n')
{
lineIndex++;
nextFontPositionX = 0;
nextFontPositionY -= theLabel->_commonLineHeight;
@ -347,8 +358,30 @@ bool LabelTextFormatter::createStringSprites(Label *theLabel)
if(nextFontPositionY < theLabel->_commonLineHeight)
break;
lineStart = true;
continue;
}
else if (clip && tempDefinition.height > 0.0f)
{
if (lineStart)
{
if (lineIndex == 0)
{
clipTop = charYOffset;
}
lineStart = false;
clipBottom = tempDefinition.clipBottom;
}
else if(tempDefinition.clipBottom < clipBottom)
{
clipBottom = tempDefinition.clipBottom;
}
if (lineIndex == 0 && charYOffset < clipTop)
{
clipTop = charYOffset;
}
}
letterPosition.x = (nextFontPositionX + charXOffset + kernings[i]) / contentScaleFactor;
letterPosition.y = (nextFontPositionY - charYOffset) / contentScaleFactor;
@ -382,11 +415,26 @@ bool LabelTextFormatter::createStringSprites(Label *theLabel)
}
tmpSize.height = totalHeight;
if (theLabel->_labelHeight > 0)
{
tmpSize.height = theLabel->_labelHeight * contentScaleFactor;
}
if (clip)
{
int clipTotal = (clipTop + clipBottom) / contentScaleFactor;
tmpSize.height -= clipTotal * contentScaleFactor;
clipBottom /= contentScaleFactor;
for (int i = 0; i < theLabel->_limitShowCount; i++)
{
theLabel->_lettersInfo[i].position.y -= clipBottom;
}
}
theLabel->setContentSize(CC_SIZE_PIXELS_TO_POINTS(tmpSize));
return true;
}

View File

@ -1199,6 +1199,9 @@ void Texture2D::generateMipmap()
GL::bindTexture2D( _name );
glGenerateMipmap(GL_TEXTURE_2D);
_hasMipmaps = true;
#if CC_ENABLE_CACHE_TEXTURE_DATA
VolatileTextureMgr::setHasMipmaps(this, _hasMipmaps);
#endif
}
bool Texture2D::hasMipmaps() const

View File

@ -635,6 +635,12 @@ void VolatileTextureMgr::addStringTexture(Texture2D *tt, const char* text, const
vt->_fontDefinition = fontDefinition;
}
void VolatileTextureMgr::setHasMipmaps(Texture2D *t, bool hasMipmaps)
{
VolatileTexture *vt = findVolotileTexture(t);
vt->_hasMipmaps = hasMipmaps;
}
void VolatileTextureMgr::setTexParameters(Texture2D *t, const Texture2D::TexParams &texParams)
{
VolatileTexture *vt = findVolotileTexture(t);
@ -717,6 +723,9 @@ void VolatileTextureMgr::reloadAllTextures()
default:
break;
}
if (vt->_hasMipmaps) {
vt->_texture->generateMipmap();
}
vt->_texture->setTexParameters(vt->_texParams);
}

View File

@ -251,6 +251,7 @@ protected:
std::string _fileName;
bool _hasMipmaps;
Texture2D::TexParams _texParams;
std::string _text;
FontDefinition _fontDefinition;
@ -264,6 +265,7 @@ public:
static void addDataTexture(Texture2D *tt, void* data, int dataLen, Texture2D::PixelFormat pixelFormat, const Size& contentSize);
static void addImage(Texture2D *tt, Image *image);
static void setHasMipmaps(Texture2D *t, bool hasMipmaps);
static void setTexParameters(Texture2D *t, const Texture2D::TexParams &texParams);
static void removeTexture(Texture2D *t);
static void reloadAllTextures();

View File

@ -187,16 +187,19 @@ void WsThreadHelper::update(float dt)
WsMessage *msg = nullptr;
// Returns quickly if no message
std::lock_guard<std::mutex> lk(_UIWsMessageQueueMutex);
_UIWsMessageQueueMutex.lock();
if (0 == _UIWsMessageQueue->size())
{
_UIWsMessageQueueMutex.unlock();
return;
}
// Gets message
msg = *(_UIWsMessageQueue->begin());
_UIWsMessageQueue->pop_front();
_UIWsMessageQueueMutex.unlock();
if (_ws)
{

View File

@ -1 +1 @@
fa70974de744fb12ec4f753989e6e0a7eb9fc73a
d53bc7d6e68a49984c5971344f59bba8414d142b

View File

@ -38,6 +38,7 @@ static std::function<Layer*()> createFunctions[] =
{
CL(TexturePVRv3Premult),
CL(TextureMipMap),
CL(TextureMemoryAlloc),
CL(TextureAlias),
CL(TexturePVRMipMap),

View File

@ -23,6 +23,8 @@ ELAPSEDSECS=`date +%s`
COCOS_BRANCH="update_lua_bindings_$ELAPSEDSECS"
COCOS_ROBOT_REMOTE="https://${GH_USER}:${GH_PASSWORD}@github.com/${GH_USER}/cocos2d-x.git"
PULL_REQUEST_REPO="https://api.github.com/repos/cocos2d/cocos2d-x/pulls"
FETCH_REMOTE_BRANCH="develop"
COMMIT_PATH="cocos/scripting/lua-bindings/auto"
# Exit on error
set -e
@ -88,12 +90,14 @@ pushd "$PROJECT_ROOT"
git status
echo
echo Comparing with HEAD ...
echo Comparing with origin HEAD ...
echo
git fetch origin ${FETCH_REMOTE_BRANCH}
# Don't exit on non-zero return value
set +e
git diff --stat --exit-code
git diff FETCH_HEAD --stat --exit-code ${COMMIT_PATH}
DIFF_RETVAL=$?
if [ $DIFF_RETVAL -eq 0 ]

View File

@ -6,6 +6,8 @@ PROJECT_ROOT="$DIR"/../..
COMMITTAG="[AUTO][ci skip]: updating cocos2dx_files.json"
PUSH_REPO="https://api.github.com/repos/cocos2d/cocos2d-x/pulls"
OUTPUT_FILE_PATH="${PROJECT_ROOT}/templates/cocos2dx_files.json"
FETCH_REMOTE_BRANCH="develop"
COMMIT_PATH="templates/cocos2dx_files.json"
# Exit on error
set -e
@ -51,12 +53,14 @@ pushd "$PROJECT_ROOT"
git status
echo
echo Comparing with HEAD ...
echo Comparing with origin HEAD ...
echo
git fetch origin ${FETCH_REMOTE_BRANCH}
# Don't exit on non-zero return value
set +e
git diff --stat --exit-code
git diff FETCH_HEAD --stat --exit-code ${COMMIT_PATH}
DIFF_RETVAL=$?
if [ $DIFF_RETVAL -eq 0 ]