Merge pull request #6052 from pipu/develop_pipu_fixedbugsforeditor_1301

Fixed bugs for Editor
This commit is contained in:
minggo 2014-03-31 15:37:45 +08:00
commit 98ed579b34
6 changed files with 102 additions and 13 deletions

View File

@ -116,6 +116,11 @@ namespace cocostudio
} }
panel->setLayoutType((LayoutType)DICTOOL->getIntValue_json(options, "layoutType")); panel->setLayoutType((LayoutType)DICTOOL->getIntValue_json(options, "layoutType"));
int bgimgcr = DICTOOL->getIntValue_json(options, "colorR");
int bgimgcg = DICTOOL->getIntValue_json(options, "colorG");
int bgimgcb = DICTOOL->getIntValue_json(options, "colorB");
panel->setBackGroundImageColor(Color3B(bgimgcr, bgimgcg, bgimgcb));
WidgetReader::setColorPropsFromJsonDictionary(widget, options); WidgetReader::setColorPropsFromJsonDictionary(widget, options);
} }

View File

@ -391,10 +391,17 @@ void Button::onPressStateChangedToNormal()
} }
} }
else else
{
if (_scale9Enabled)
{
updateTextureRGBA();
}
else
{ {
_buttonNormalRenderer->stopAllActions(); _buttonNormalRenderer->stopAllActions();
_buttonNormalRenderer->setScale(_normalTextureScaleXInSize, _normalTextureScaleYInSize); _buttonNormalRenderer->setScale(_normalTextureScaleXInSize, _normalTextureScaleYInSize);
} }
}
} }
void Button::onPressStateChangedToPressed() void Button::onPressStateChangedToPressed()
@ -418,9 +425,16 @@ void Button::onPressStateChangedToPressed()
_buttonNormalRenderer->setVisible(true); _buttonNormalRenderer->setVisible(true);
_buttonClickedRenderer->setVisible(true); _buttonClickedRenderer->setVisible(true);
_buttonDisableRenderer->setVisible(false); _buttonDisableRenderer->setVisible(false);
if (_scale9Enabled)
{
_buttonNormalRenderer->setColor(Color3B::GRAY);
}
else
{
_buttonNormalRenderer->stopAllActions(); _buttonNormalRenderer->stopAllActions();
_buttonNormalRenderer->setScale(_normalTextureScaleXInSize + 0.1f, _normalTextureScaleYInSize + 0.1f); _buttonNormalRenderer->setScale(_normalTextureScaleXInSize + 0.1f, _normalTextureScaleYInSize + 0.1f);
} }
}
} }
void Button::onPressStateChangedToDisabled() void Button::onPressStateChangedToDisabled()

View File

@ -49,6 +49,7 @@ ListView::~ListView()
_listViewEventListener = nullptr; _listViewEventListener = nullptr;
_listViewEventSelector = nullptr; _listViewEventSelector = nullptr;
_items.clear(); _items.clear();
CC_SAFE_RELEASE(_model);
} }
ListView* ListView::create() ListView* ListView::create()

View File

@ -29,6 +29,23 @@ NS_CC_BEGIN
namespace ui { namespace ui {
static int _calcCharCount(const char * pszText)
{
int n = 0;
char ch = 0;
while ((ch = *pszText))
{
CC_BREAK_IF(! ch);
if (0x80 != (0xC0 & ch))
{
++n;
}
++pszText;
}
return n;
}
bool RichElement::init(int tag, const Color3B &color, GLubyte opacity) bool RichElement::init(int tag, const Color3B &color, GLubyte opacity)
{ {
_tag = tag; _tag = tag;
@ -262,7 +279,7 @@ void RichText::handleTextRenderer(const char *text, const char *fontName, float
{ {
float overstepPercent = (-_leftSpaceWidth) / textRendererWidth; float overstepPercent = (-_leftSpaceWidth) / textRendererWidth;
std::string curText = text; std::string curText = text;
size_t stringLength = curText.length(); size_t stringLength = _calcCharCount(text);
int leftLength = stringLength * (1.0f - overstepPercent); int leftLength = stringLength * (1.0f - overstepPercent);
std::string leftWords = curText.substr(0, leftLength); std::string leftWords = curText.substr(0, leftLength);
std::string cutWords = curText.substr(leftLength, curText.length()-1); std::string cutWords = curText.substr(leftLength, curText.length()-1);

View File

@ -167,14 +167,15 @@ void UICCTextField::insertText(const char * text, size_t len)
} }
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) #elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
int input_count = _calcCharCount(text); int input_count = _calcCharCount(text);
if (input_count > _maxLength) int total = text_count + input_count;
if (total > _maxLength)
{ {
int ascii = 0; int ascii = 0;
int unicode = 0; int unicode = 0;
int end = 0; int end = 0;
int count = 0; int count = 0;
for (int i = 0; i < input_count * 3; ++i) for (int i = 0; i < total * 3; ++i)
{ {
char value = text[i]; char value = text[i];
@ -291,12 +292,24 @@ void UICCTextField::setPasswordStyleText(const char* styleText)
void UICCTextField::setPasswordText(const char *text) void UICCTextField::setPasswordText(const char *text)
{ {
std::string tempStr; std::string tempStr = "";
for (size_t i = 0; i < strlen(text); ++i) int text_count = _calcCharCount(text);
int max = text_count;
if (_maxLengthEnabled)
{
if (text_count > _maxLength)
{
max = _maxLength;
}
}
for (int i = 0; i < max; ++i)
{ {
tempStr.append(_passwordStyleText); tempStr.append(_passwordStyleText);
} }
Label::setString(tempStr.c_str());
Label::setString(tempStr);
} }
void UICCTextField::setAttachWithIME(bool attach) void UICCTextField::setAttachWithIME(bool attach)
@ -433,21 +446,59 @@ Size TextField::getTouchSize()
void TextField::setText(const std::string& text) void TextField::setText(const std::string& text)
{ {
std::string strText(text); std::string strText(text);
if (isMaxLengthEnabled()) if (isMaxLengthEnabled())
{ {
strText = strText.substr(0, getMaxLength()); int max = _textFieldRenderer->getMaxLength();
int text_count = _calcCharCount(text.c_str());
int total = text_count + _calcCharCount(getStringValue().c_str());
if (total > max)
{
int ascii = 0;
int unicode = 0;
int end = 0;
int count = 0;
for (int i = 0; i < total * 3; ++i)
{
char value = text[i];
if (value >= 0 && value <= 127) // ascii
{
ascii++;
count++;
} }
else
{
unicode++;
if (unicode % 3 == 0)
{
count++;
}
}
if (count == max)
{
break;
}
}
end = ascii + unicode;
strText = strText.substr(0, end);
}
}
const char* content = strText.c_str(); const char* content = strText.c_str();
if (isPasswordEnabled()) if (isPasswordEnabled())
{ {
_textFieldRenderer->setPasswordText(content); _textFieldRenderer->setPasswordText(content);
_textFieldRenderer->setString(""); _textFieldRenderer->setString("");
_textFieldRenderer->insertText(content, static_cast<int>(strlen(content))); _textFieldRenderer->insertText(content, strlen(content));
} }
else else
{ {
_textFieldRenderer->setString(content); _textFieldRenderer->setString(content);
} }
textfieldRendererScaleChangedWithSize(); textfieldRendererScaleChangedWithSize();
} }

View File

@ -50,7 +50,8 @@ bool UITextTest_LineWrap::init()
// Create the line wrap // Create the line wrap
Text* text = Text::create(); Text* text = Text::create();
text->setTextAreaSize(Size(280, 150)); text->ignoreContentAdaptWithSize(false);
text->setSize(Size(280, 150));
text->setTextHorizontalAlignment(TextHAlignment::CENTER); text->setTextHorizontalAlignment(TextHAlignment::CENTER);
text->setText("Text can line wrap"); text->setText("Text can line wrap");
text->setFontName("AmericanTypewriter"); text->setFontName("AmericanTypewriter");