Skip to content

Commit 604029b

Browse files
committed
fixed cocos2d#176 test_win32 OK.
1 parent eae0e48 commit 604029b

File tree

5 files changed

+36
-18
lines changed

5 files changed

+36
-18
lines changed

cocos2dx/platform/win32/CCXBitmapDC.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ namespace cocos2d {
4343
HFONT hFont = NULL;
4444
HFONT hNewFont = NULL;
4545
LOGFONT lFont = {0};
46-
lFont.lfHeight = -MulDiv((int)fontSize, GetDeviceCaps(m_hMemDC, LOGPIXELSY), 72);
46+
lFont.lfHeight = -(LONG)fontSize;
4747
MultiByteToWideChar(CP_ACP, 0, fontName, -1, lFont.lfFaceName, LF_FACESIZE);
4848
hFont = CreateFontIndirect(&lFont);
4949
if (hFont)
@@ -57,9 +57,9 @@ namespace cocos2d {
5757
HGDIOBJ hOldFont = SelectObject(m_hMemDC, hNewFont);
5858

5959
// text
60-
int len = strlen(text) + 1;
61-
WCHAR *pText = new WCHAR[len];
62-
MultiByteToWideChar(CP_ACP, 0, text, len, pText, len);
60+
int len = strlen(text);
61+
WCHAR *pText = new WCHAR[len + 1];
62+
MultiByteToWideChar(CP_ACP, 0, text, len + 1, pText, len);
6363

6464
// calculate text size
6565
SIZE extent;
@@ -99,6 +99,7 @@ namespace cocos2d {
9999
// draw text
100100
RECT rc = {0, 0, extent.cx, extent.cy};
101101
SetBkMode(m_hMemDC, TRANSPARENT);
102+
SetTextColor(m_hMemDC, RGB(255, 255, 255)); // white color
102103
DrawText(m_hMemDC, pText, len, &rc, dwStyle);
103104

104105
// free resource

cocos2dx/platform/win32/CCXEGLView_win32.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,16 +227,14 @@ bool CCXEGLView::Create(LPCTSTR pTitle, int w, int h)
227227
RECT rect = {(rcDesktop.right + rcDesktop.left - w) / 2, (rcDesktop.bottom + rcDesktop.top - h) / 2, 0, 0};
228228
rect.right = rect.left + w;
229229
rect.bottom = rect.top + h;
230-
AdjustWindowRectEx(&rect, WS_POPUPWINDOW, false, WS_EX_TOPMOST | WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
230+
AdjustWindowRectEx(&rect, WS_CAPTION | WS_POPUPWINDOW, false, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
231231

232232
// create window
233233
m_hWnd = CreateWindowEx(
234-
WS_EX_TOPMOST | WS_EX_APPWINDOW | WS_EX_WINDOWEDGE, // Extended Style For The Window
234+
WS_EX_APPWINDOW | WS_EX_WINDOWEDGE, // Extended Style For The Window
235235
kWindowClassName, // Class Name
236236
pTitle, // Window Title
237-
WS_POPUPWINDOW/*WS_OVERLAPPEDWINDOW*/ // Defined Window Style
238-
| WS_CLIPSIBLINGS // Required Window Style
239-
| WS_CLIPCHILDREN, // Required Window Style
237+
WS_CAPTION | WS_POPUPWINDOW, // Defined Window Style
240238
rect.left, rect.top, // Window Position
241239
rect.right - rect.left, // Window Width
242240
rect.bottom - rect.top, // Window Height
@@ -290,7 +288,7 @@ LRESULT CCXEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
290288
break;
291289

292290
case WM_LBUTTONUP:
293-
if (MK_LBUTTON == wParam && m_bCaptured)
291+
if (m_bCaptured)
294292
{
295293
m_pTouch->SetTouchInfo(0, (float)LOWORD(lParam), (float)HIWORD(lParam));
296294
m_pDelegate->touchesEnded(m_pSet, NULL);
@@ -304,6 +302,10 @@ LRESULT CCXEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
304302
EndPaint(m_hWnd, &ps);
305303
break;
306304

305+
case WM_CLOSE:
306+
CCDirector::getSharedDirector()->end();
307+
break;
308+
307309
case WM_DESTROY:
308310
PostQuitMessage(0);
309311
break;

cocos2dx/platform/win32/CCXUIImage_win32.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ static void pngReadCallback(png_structp png_ptr, png_bytep data, png_size_t leng
7171

7272
UIImage::UIImage(void)
7373
{
74-
m_pBitmap = NULL;
75-
7674
m_imageInfo.hasAlpha = false;
7775
m_imageInfo.isPremultipliedAlpha = false;
7876
m_imageInfo.height = 0;
@@ -98,14 +96,32 @@ UIImage::UIImage(CCXBitmapDC * pBmpDC)
9896
GetDIBits(pBmpDC->getDC(), pBmpDC->getBitmap(), 0, 0, NULL, (LPBITMAPINFO)&bi, DIB_RGB_COLORS);
9997

10098
// init imageinfo
101-
m_imageInfo.height = bi.bmiHeader.biHeight;
99+
m_imageInfo.height = (bi.bmiHeader.biHeight < 0) ? - bi.bmiHeader.biHeight : bi.bmiHeader.biHeight;
102100
m_imageInfo.width = bi.bmiHeader.biWidth;
103101
m_imageInfo.bitsPerComponent = bi.bmiHeader.biBitCount / 4;
104102
m_imageInfo.hasAlpha = true;
105103
m_imageInfo.isPremultipliedAlpha = false;
106-
m_imageInfo.data = new BYTE[m_imageInfo.height * m_imageInfo.width * m_imageInfo.bitsPerComponent];
104+
m_imageInfo.data = new BYTE[m_imageInfo.height * m_imageInfo.width * 4];
105+
106+
bi.bmiHeader.biHeight = (bi.bmiHeader.biHeight > 0) ? - bi.bmiHeader.biHeight : bi.bmiHeader.biHeight;
107107
GetDIBits(pBmpDC->getDC(), pBmpDC->getBitmap(), 0, m_imageInfo.height, m_imageInfo.data,
108108
(LPBITMAPINFO)&bi, DIB_RGB_COLORS);
109+
110+
// change pixel's alpha value to 255, when it's RGB != 0
111+
COLORREF * pPixel = NULL;
112+
for (int y = 0; y < m_imageInfo.height; ++y)
113+
{
114+
pPixel = (COLORREF *)m_imageInfo.data + y * m_imageInfo.width;
115+
for (int x = 0; x < m_imageInfo.width; ++x)
116+
{
117+
COLORREF& clr = *pPixel;
118+
if (GetRValue(clr) || GetGValue(clr) || GetBValue(clr))
119+
{
120+
clr |= 0xff000000;
121+
}
122+
++pPixel;
123+
}
124+
}
109125
}
110126

111127
UIImage::~UIImage(void)

cocos2dx/platform/win32/CCXUIImage_win32.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ class CCX_DLL UIImage
104104
bool loadJpg(const char *strFileName);
105105

106106
private:
107-
HBITMAP *m_pBitmap;
108107
tImageInfo m_imageInfo;
109108
};
110109
}//namespace cocos2d

test_win32/TestApplication.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ bool TestApplication::initCocos2d()
2222
pDirector->setDisplayFPS(true);
2323

2424
CCScene * pScene = CCScene::node();
25-
CCLayer * pLayer = new TestController();
25+
CCLayer * pLayer = new TestController(kCCDeviceOrientationPortrait);
2626
pLayer->autorelease();
2727

2828
pScene->addChild(pLayer);
29-
pDirector->replaceScene(pScene);
29+
pDirector->runWithScene(pScene);
3030

3131
return true;
3232
}
@@ -39,4 +39,4 @@ void TestApplication::applicationDidEnterBackground()
3939
void TestApplication::applicationWillEnterForeground()
4040
{
4141
CCDirector::getSharedDirector()->startAnimation();
42-
}
42+
}

0 commit comments

Comments
 (0)