From 73cf18163e04990453e0b02cd6053058ee5a1c5c Mon Sep 17 00:00:00 2001 From: Yongkang Chen Date: Tue, 22 Jul 2014 15:06:44 +0800 Subject: [PATCH] fix font size of editbox for mac when glview scale --- extensions/GUI/CCEditBox/CCEditBoxImplMac.mm | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/extensions/GUI/CCEditBox/CCEditBoxImplMac.mm b/extensions/GUI/CCEditBox/CCEditBoxImplMac.mm index 8ca0fd5d25..4defc0882f 100644 --- a/extensions/GUI/CCEditBox/CCEditBoxImplMac.mm +++ b/extensions/GUI/CCEditBox/CCEditBoxImplMac.mm @@ -307,7 +307,10 @@ bool EditBoxImplMac::initWithSize(const Size& size) void EditBoxImplMac::setFont(const char* pFontName, int fontSize) { NSString * fntName = [NSString stringWithUTF8String:pFontName]; - NSFont *textFont = [NSFont fontWithName:fntName size:fontSize]; + float retinaFactor = _inRetinaMode ? 2.0f : 1.0f; + auto glview = cocos2d::Director::getInstance()->getOpenGLView(); + float scaleFactor = glview->getScaleX(); + NSFont *textFont = [NSFont fontWithName:fntName size:fontSize * scaleFactor / retinaFactor]; if (textFont != nil) { [_sysEdit.textField setFont:textFont]; [_sysEdit.secureTextField setFont:textFont]; @@ -317,7 +320,10 @@ void EditBoxImplMac::setFont(const char* pFontName, int fontSize) void EditBoxImplMac::setPlaceholderFont(const char* pFontName, int fontSize) { NSString *fontName = [NSString stringWithUTF8String:pFontName]; - NSFont *font = [NSFont fontWithName:fontName size:fontSize]; + float retinaFactor = _inRetinaMode ? 2.0f : 1.0f; + auto glview = cocos2d::Director::getInstance()->getOpenGLView(); + float scaleFactor = glview->getScaleX(); + NSFont *font = [NSFont fontWithName:fontName size:fontSize * scaleFactor / retinaFactor]; if (!font) { CCLOGWARN("Font not found: %s", pFontName);