[WIN32] Enabled retina. Updated the implementation of fullPathFromRelativePath.

This commit is contained in:
James Chen 2012-08-24 18:01:16 +08:00
parent a8e4cbe3b5
commit 369eb3daa3
4 changed files with 35 additions and 18 deletions

View File

@ -149,6 +149,7 @@ void CCEGLViewProtocol::setTouchDelegate(EGLTouchDelegate * pDelegate)
bool CCEGLViewProtocol::setContentScaleFactor(float contentScaleFactor)
{
m_fScaleX = m_fScaleY = contentScaleFactor;
return false;
}

View File

@ -210,7 +210,7 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
if (m_pDelegate && MK_LBUTTON == wParam)
{
POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)};
CCPoint pt(point.x/CC_CONTENT_SCALE_FACTOR(), point.y/CC_CONTENT_SCALE_FACTOR());
CCPoint pt(point.x, point.y);
CCPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y);
if (m_obViewPortRect.equals(CCRectZero) || m_obViewPortRect.containsPoint(tmp))
{
@ -226,7 +226,7 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
if (MK_LBUTTON == wParam && m_bCaptured)
{
POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)};
CCPoint pt(point.x/CC_CONTENT_SCALE_FACTOR(), point.y/CC_CONTENT_SCALE_FACTOR());
CCPoint pt(point.x, point.y);
int id = 0;
handleTouchesMove(1, &id, &pt.x, &pt.y);
}
@ -236,7 +236,7 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
if (m_bCaptured)
{
POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)};
CCPoint pt(point.x/CC_CONTENT_SCALE_FACTOR(), point.y/CC_CONTENT_SCALE_FACTOR());
CCPoint pt(point.x, point.y);
int id = 0;
handleTouchesEnd(1, &id, &pt.x, &pt.y);
@ -370,6 +370,11 @@ void CCEGLView::setIMEKeyboardState(bool /*bOpen*/)
}
bool CCEGLView::enableRetina()
{
return true;
}
HWND CCEGLView::getHWnd()
{
return m_hWnd;

View File

@ -47,7 +47,7 @@ public:
virtual bool setContentScaleFactor(float contentScaleFactor);
virtual void setFrameSize(float width, float height);
virtual void setIMEKeyboardState(bool bOpen);
virtual bool enableRetina();
private:
virtual bool Create(LPCTSTR pTitle, int w, int h);
bool initGL();

View File

@ -37,17 +37,11 @@ static void _CheckPath()
{
if (! s_pszResourcePath[0])
{
WCHAR wszPath[MAX_PATH];
WCHAR wszPath[MAX_PATH] = {0};
int nNum = WideCharToMultiByte(CP_ACP, 0, wszPath,
GetCurrentDirectoryW(sizeof(wszPath), wszPath),
s_pszResourcePath, MAX_PATH, NULL, NULL);
s_pszResourcePath[nNum] = '\\';
const char* resDir = CCFileUtils::sharedFileUtils()->getResourceDirectory();
if (resDir != NULL)
{
strcat(s_pszResourcePath, resDir);
}
}
}
@ -58,6 +52,7 @@ CCFileUtils* CCFileUtils::sharedFileUtils()
if (s_pFileUtils == NULL)
{
s_pFileUtils = new CCFileUtils();
_CheckPath();
}
return s_pFileUtils;
}
@ -79,10 +74,10 @@ void CCFileUtils::purgeCachedEntries()
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
{
_CheckPath();
bool bFileExist = true;
const char* resDir = CCFileUtils::sharedFileUtils()->getResourceDirectory();
CCString* pRet = CCString::create("");
CCString * pRet = new CCString();
pRet->autorelease();
if ((strlen(pszRelativePath) > 1 && pszRelativePath[1] == ':'))
{
// path start with "x:", is absolute path
@ -99,19 +94,35 @@ const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
else
{
pRet->m_sString = s_pszResourcePath;
pRet->m_sString += resDir;
pRet->m_sString += pszRelativePath;
}
// If file or directory doesn't exist, try to find it in the root path.
if (GetFileAttributesA(pRet->m_sString.c_str()) == -1)
{
pRet->m_sString = s_pszResourcePath;
pRet->m_sString += pszRelativePath;
if (GetFileAttributesA(pRet->m_sString.c_str()) == -1)
{
bFileExist = false;
}
}
if (!bFileExist)
{ // Can't find the file, return the relative path.
pRet->m_sString = pszRelativePath;
}
return pRet->m_sString.c_str();
}
const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile)
{
_CheckPath();
// std::string relativeFile = fullPathFromRelativePath(pszRelativeFile);
std::string relativeFile = pszRelativeFile;
CCString *pRet = new CCString();
pRet->autorelease();
CCString *pRet = CCString::create("");
pRet->m_sString = relativeFile.substr(0, relativeFile.find_last_of("/\\") + 1);
pRet->m_sString += pszFilename;
return pRet->m_sString.c_str();