CCEGLView_win32.cpp

EAGLE, 2012-05-07 21:35

Download (18.1 kB)

 
1
/****************************************************************************
2
Copyright (c) 2010 cocos2d-x.org
3

    
4
http://www.cocos2d-x.org
5

    
6
Permission is hereby granted, free of charge, to any person obtaining a copy
7
of this software and associated documentation files (the "Software"), to deal
8
in the Software without restriction, including without limitation the rights
9
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
copies of the Software, and to permit persons to whom the Software is
11
furnished to do so, subject to the following conditions:
12

    
13
The above copyright notice and this permission notice shall be included in
14
all copies or substantial portions of the Software.
15

    
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
THE SOFTWARE.
23
****************************************************************************/
24

    
25
#include "CCEGLView.h"
26

    
27
#include "EGL/egl.h"
28
#include "gles/gl.h"
29

    
30
#include "CCSet.h"
31
#include "ccMacros.h"
32
#include "CCDirector.h"
33
#include "CCTouch.h"
34
#include "CCTouchDispatcher.h"
35
#include "CCIMEDispatcher.h"
36
#include "CCKeypadDispatcher.h"
37
#include "CCApplication.h"
38

    
39
NS_CC_BEGIN;
40

    
41
//////////////////////////////////////////////////////////////////////////
42
// impliment CCEGL
43
//////////////////////////////////////////////////////////////////////////
44

    
45
class CCEGL
46
{
47
public:
48
        ~CCEGL() 
49
        {
50
                if (EGL_NO_SURFACE != m_eglSurface)
51
                {
52
                        eglDestroySurface(m_eglDisplay, m_eglSurface);
53
                }
54
                if (EGL_NO_CONTEXT != m_eglContext)
55
                {
56
                        eglDestroyContext(m_eglDisplay, m_eglContext);
57
                }
58
                eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
59
                eglTerminate(m_eglDisplay);
60
                if (m_eglNativeDisplay)
61
                {
62
                        ReleaseDC(m_eglNativeWindow, m_eglNativeDisplay);
63
                }
64
        }
65

    
66
        static CCEGL * create(CCEGLView * pWindow)
67
        {
68
                CCEGL * pEGL = new CCEGL;
69
                BOOL bSuccess = FALSE;
70
                do 
71
                {
72
                        CC_BREAK_IF(! pEGL);
73

    
74
                        pEGL->m_eglNativeWindow = pWindow->getHWnd();
75

    
76
                        pEGL->m_eglNativeDisplay = GetDC(pEGL->m_eglNativeWindow);
77

    
78
                        EGLDisplay eglDisplay;
79
                        CC_BREAK_IF(EGL_NO_DISPLAY == (eglDisplay = eglGetDisplay(pEGL->m_eglNativeDisplay)));
80

    
81
                        EGLint nMajor, nMinor;
82
                        CC_BREAK_IF(EGL_FALSE == eglInitialize(eglDisplay, &nMajor, &nMinor) || 1 != nMajor);
83

    
84
                        const EGLint aConfigAttribs[] =
85
                        {
86
                                EGL_LEVEL,                                0,
87
                                EGL_SURFACE_TYPE,                EGL_WINDOW_BIT,
88
                                EGL_RENDERABLE_TYPE,        EGL_OPENGL_ES2_BIT,
89
                                EGL_NATIVE_RENDERABLE,        EGL_FALSE,
90
                                EGL_DEPTH_SIZE,                        16,
91
                                EGL_NONE,
92
                        };
93
                        EGLint iConfigs;
94
                        EGLConfig eglConfig;
95
                        CC_BREAK_IF(EGL_FALSE == eglChooseConfig(eglDisplay, aConfigAttribs, &eglConfig, 1, &iConfigs) 
96
                                || (iConfigs != 1));
97

    
98
                        EGLContext eglContext;
99
                        eglContext = eglCreateContext(eglDisplay, eglConfig, NULL, NULL);
100
                        CC_BREAK_IF(EGL_NO_CONTEXT == eglContext);
101

    
102
                        EGLSurface eglSurface;
103
                        eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig, pEGL->m_eglNativeWindow, NULL);
104
                        CC_BREAK_IF(EGL_NO_SURFACE == eglSurface);
105

    
106
                        CC_BREAK_IF(EGL_FALSE == eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext));
107

    
108
                        pEGL->m_eglDisplay = eglDisplay;
109
                        pEGL->m_eglConfig  = eglConfig;
110
                        pEGL->m_eglContext = eglContext;
111
                        pEGL->m_eglSurface = eglSurface;
112
                        bSuccess = TRUE;
113
                } while (0);
114

    
115
                if (! bSuccess)
116
                {
117
                        CC_SAFE_DELETE(pEGL);  
118
                }
119

    
120
                return pEGL;
121
        }
122

    
123
        void resizeSurface()
124
        {
125
//                  if (! m_eglNativeWindow || EGL_NO_DISPLAY == m_eglDisplay)
126
//                  {
127
//                          return;
128
//                  }
129
//  
130
//                  // release old surface
131
//                  if (EGL_NO_SURFACE != m_eglSurface)
132
//                  {
133
//                          eglDestroySurface(m_eglDisplay, m_eglSurface);
134
//                          m_eglSurface = EGL_NO_SURFACE;
135
//                  }
136
//  
137
//                  // create new surface and make current
138
//                  m_eglSurface = eglCreateWindowSurface(m_eglDisplay, m_eglConfig, m_eglNativeWindow, NULL);
139
//                  eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext);
140
        }
141

    
142
        void swapBuffers()
143
        {
144
                if (EGL_NO_DISPLAY != m_eglDisplay)
145
                {
146
                        eglSwapBuffers(m_eglDisplay, m_eglSurface);
147
                }
148
        }
149
private:
150
        CCEGL() 
151
                : m_eglNativeWindow(NULL)
152
                , m_eglNativeDisplay(EGL_DEFAULT_DISPLAY)
153
                , m_eglDisplay(EGL_NO_DISPLAY)
154
                , m_eglConfig(0)
155
                , m_eglSurface(EGL_NO_SURFACE)
156
                , m_eglContext(EGL_NO_CONTEXT)
157
        {}
158

    
159
        EGLNativeWindowType     m_eglNativeWindow;
160
        EGLNativeDisplayType    m_eglNativeDisplay;
161
        EGLDisplay              m_eglDisplay;
162
        EGLConfig               m_eglConfig;
163
        EGLSurface              m_eglSurface;
164
        EGLContext              m_eglContext;
165
};
166

    
167
//////////////////////////////////////////////////////////////////////////
168
// impliment CCEGLView
169
//////////////////////////////////////////////////////////////////////////
170
static CCEGLView * s_pMainWindow;
171
static const WCHAR * kWindowClassName = L"Cocos2dxWin32";
172

    
173
static LRESULT CALLBACK _WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
174
{
175
        if (s_pMainWindow && s_pMainWindow->getHWnd() == hWnd)
176
        {
177
                return s_pMainWindow->WindowProc(uMsg, wParam, lParam);
178
        }
179
        else
180
        {
181
                return DefWindowProc(hWnd, uMsg, wParam, lParam);
182
        }
183
}
184

    
185
CCEGLView::CCEGLView()
186
: m_bCaptured(false)
187
, m_bOrientationReverted(false)
188
, m_bOrientationInitVertical(false)
189
, m_pDelegate(NULL)
190
, m_pEGL(NULL)
191
, m_hWnd(NULL)
192
, m_eInitOrientation(CCDeviceOrientationPortrait)
193
, m_fScreenScaleFactor(1.0f)
194
, m_lpfnAccelerometerKeyHook(NULL)
195
{
196
    m_pTouch    = new CCTouch;
197
    m_pSet      = new CCSet;
198
    m_tSizeInPoints.cx = m_tSizeInPoints.cy = 0;
199
    SetRectEmpty(&m_rcViewPort);
200
}
201

    
202
CCEGLView::~CCEGLView()
203
{
204
}
205

    
206
bool CCEGLView::Create(LPCTSTR pTitle, int w, int h)
207
{
208
        bool bRet = false;
209
        do 
210
        {
211
                CC_BREAK_IF(m_hWnd);
212

    
213
                HINSTANCE hInstance = GetModuleHandle( NULL );
214
                WNDCLASS  wc;                // Windows Class Structure
215

    
216
                // Redraw On Size, And Own DC For Window.
217
                wc.style          = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;  
218
                wc.lpfnWndProc    = _WindowProc;                                        // WndProc Handles Messages
219
                wc.cbClsExtra     = 0;                              // No Extra Window Data
220
                wc.cbWndExtra     = 0;                                                                // No Extra Window Data
221
                wc.hInstance      = hInstance;                                                // Set The Instance
222
                wc.hIcon          = LoadIcon( NULL, IDI_WINLOGO );        // Load The Default Icon
223
                wc.hCursor        = LoadCursor( NULL, IDC_ARROW );        // Load The Arrow Pointer
224
                wc.hbrBackground  = NULL;                           // No Background Required For GL
225
                wc.lpszMenuName   = NULL;                           // We Don't Want A Menu
226
                wc.lpszClassName  = kWindowClassName;               // Set The Class Name
227

    
228
                CC_BREAK_IF(! RegisterClass(&wc) && 1410 != GetLastError());                
229

    
230
                // center window position
231
                RECT rcDesktop;
232
                GetWindowRect(GetDesktopWindow(), &rcDesktop);
233

    
234
                // create window
235
                m_hWnd = CreateWindowEx(
236
                        WS_EX_APPWINDOW | WS_EX_WINDOWEDGE,        // Extended Style For The Window
237
                        kWindowClassName,                                                                        // Class Name
238
                        pTitle,                                                                                                // Window Title
239
                        WS_CAPTION | WS_POPUPWINDOW | WS_MINIMIZEBOX,                // Defined Window Style
240
                        0, 0,                                                                                // Window Position
241
                        0,                                                  // Window Width
242
                        0,                                                  // Window Height
243
                        NULL,                                                                                                // No Parent Window
244
                        NULL,                                                                                                // No Menu
245
                        hInstance,                                                                                        // Instance
246
                        NULL );
247

    
248
                CC_BREAK_IF(! m_hWnd);
249

    
250
        m_eInitOrientation = CCDirector::sharedDirector()->getDeviceOrientation();
251
        m_bOrientationInitVertical = (CCDeviceOrientationPortrait == m_eInitOrientation
252
            || kCCDeviceOrientationPortraitUpsideDown == m_eInitOrientation) ? true : false;
253
        m_tSizeInPoints.cx = w;
254
        m_tSizeInPoints.cy = h;
255
        resize(w, h);
256

    
257
                // init egl
258
                m_pEGL = CCEGL::create(this);
259

    
260
                if (! m_pEGL)
261
                {
262
                        DestroyWindow(m_hWnd);
263
                        m_hWnd = NULL;
264
                        break;
265
                }
266

    
267
                s_pMainWindow = this;
268
                bRet = true;
269
        } while (0);
270

    
271
        return bRet;
272
}
273

    
274
LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
275
{
276
        PAINTSTRUCT ps;
277

    
278
        switch (message)
279
        {
280
        case WM_LBUTTONDOWN:
281
                if (m_pDelegate && m_pTouch && MK_LBUTTON == wParam)
282
                {
283
            POINT pt = {(short)LOWORD(lParam), (short)HIWORD(lParam)};
284
            if (PtInRect(&m_rcViewPort, pt))
285
            {
286
                m_bCaptured = true;
287
                SetCapture(m_hWnd);
288
                m_pTouch->SetTouchInfo(0, (float)(pt.x - m_rcViewPort.left) / m_fScreenScaleFactor,
289
                    (float)(pt.y - m_rcViewPort.top) / m_fScreenScaleFactor);
290
                m_pSet->addObject(m_pTouch);
291
                m_pDelegate->touchesBegan(m_pSet, NULL);
292
            }
293
                }
294
                break;
295

    
296
        case WM_MOUSEMOVE:
297
                if (MK_LBUTTON == wParam && m_bCaptured)
298
                {
299
            m_pTouch->SetTouchInfo(0, (float)((short)LOWORD(lParam)- m_rcViewPort.left) / m_fScreenScaleFactor,
300
                (float)((short)HIWORD(lParam) - m_rcViewPort.top) / m_fScreenScaleFactor);
301
            m_pDelegate->touchesMoved(m_pSet, NULL);
302
                }
303
                break;
304

    
305
        case WM_LBUTTONUP:
306
                if (m_bCaptured)
307
                {
308
                        m_pTouch->SetTouchInfo(0, (float)((short)LOWORD(lParam)- m_rcViewPort.left) / m_fScreenScaleFactor,
309
                (float)((short)HIWORD(lParam) - m_rcViewPort.top) / m_fScreenScaleFactor);
310
                        m_pDelegate->touchesEnded(m_pSet, NULL);
311
                        m_pSet->removeObject(m_pTouch);
312
            ReleaseCapture();
313
                        m_bCaptured = false;
314
                }
315
                break;
316
        case WM_SIZE:
317
                switch (wParam)
318
                {
319
                case SIZE_RESTORED:
320
                        CCApplication::sharedApplication().applicationWillEnterForeground();
321
                        break;
322
                case SIZE_MINIMIZED:
323
                        CCApplication::sharedApplication().applicationDidEnterBackground();
324
                        break;
325
                }
326
                break;
327
        case WM_KEYDOWN:
328
                {
329
                        CCTouch* keyIDContainer = new CCTouch();
330
                        keyIDContainer->SetTouchInfo(wParam,0,0);
331
                        CCSet* newSet = new CCSet();
332
                        newSet->addObject(keyIDContainer);
333
                        m_pDelegate->touchesBegan(newSet, NULL);
334
                        if (wParam == VK_F1 || wParam == VK_F2)
335
                        {
336
                                if (GetKeyState(VK_LSHIFT) < 0 ||  GetKeyState(VK_RSHIFT) < 0 || GetKeyState(VK_SHIFT) < 0)
337
                                        CCKeypadDispatcher::sharedDispatcher()->dispatchKeypadMSG(wParam == VK_F1 ? kTypeBackClicked : kTypeMenuClicked);
338
                        }
339
                        if ( m_lpfnAccelerometerKeyHook!=NULL )
340
                        {
341
                                (*m_lpfnAccelerometerKeyHook)( message,wParam,lParam );
342
                        }
343
                }
344
                break;
345
        case WM_KEYUP:
346
                {
347
                        CCTouch* keyIDContainer = new CCTouch();
348
                        keyIDContainer->SetTouchInfo(wParam,0,0);
349
                        CCSet* newSet = new CCSet();
350
                        newSet->addObject(keyIDContainer);
351
                        m_pDelegate->touchesEnded(newSet, NULL);
352
                        if ( m_lpfnAccelerometerKeyHook!=NULL )
353
                        {
354
                                (*m_lpfnAccelerometerKeyHook)( message,wParam,lParam );
355
                        }
356
                }
357
                break;
358
    case WM_CHAR:
359
        {
360
            if (wParam < 0x20)
361
            {
362
                if (VK_BACK == wParam)
363
                {
364
                    CCIMEDispatcher::sharedDispatcher()->dispatchDeleteBackward();
365
                }
366
                else if (VK_RETURN == wParam)
367
                {
368
                    CCIMEDispatcher::sharedDispatcher()->dispatchInsertText("\n", 1);
369
                }
370
                else if (VK_TAB == wParam)
371
                {
372
                    // tab input
373
                }
374
                else if (VK_ESCAPE == wParam)
375
                {
376
                    // ESC input
377
                                        CCDirector::sharedDirector()->end();
378
                }
379
            }
380
            else if (wParam < 128)
381
            {
382
                // ascii char
383
                CCIMEDispatcher::sharedDispatcher()->dispatchInsertText((const char *)&wParam, 1);
384
            }
385
            else
386
            {
387
                char szUtf8[8] = {0};
388
                int nLen = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)&wParam, 1, szUtf8, sizeof(szUtf8), NULL, NULL);
389

    
390
                CCIMEDispatcher::sharedDispatcher()->dispatchInsertText(szUtf8, nLen);
391
            }
392
                        if ( m_lpfnAccelerometerKeyHook!=NULL )
393
                        {
394
                                (*m_lpfnAccelerometerKeyHook)( message,wParam,lParam );
395
                        }
396
        }
397
        break;
398

    
399
        case WM_PAINT:
400
                BeginPaint(m_hWnd, &ps);
401
                EndPaint(m_hWnd, &ps);
402
                break;
403

    
404
        case WM_CLOSE:
405
                CCDirector::sharedDirector()->end();
406
                break;
407

    
408
        case WM_DESTROY:
409
                PostQuitMessage(0);
410
                break;
411

    
412
        default:
413
                return DefWindowProc(m_hWnd, message, wParam, lParam);
414
        }
415
        return 0;
416
}
417

    
418
void CCEGLView::setAccelerometerKeyHook( LPFN_ACCELEROMETER_KEYHOOK lpfnAccelerometerKeyHook )
419
{
420
        m_lpfnAccelerometerKeyHook=lpfnAccelerometerKeyHook;
421
}
422

    
423
CCSize CCEGLView::getSize()
424
{
425
    if (m_bOrientationReverted)
426
    {
427
        return CCSize((float)(m_tSizeInPoints.cy), (float)(m_tSizeInPoints.cx));
428
    }
429
    return CCSize((float)(m_tSizeInPoints.cx), (float)(m_tSizeInPoints.cy));
430
}
431

    
432
bool CCEGLView::isOpenGLReady()
433
{
434
    return (NULL != m_pEGL);
435
}
436

    
437
void CCEGLView::release()
438
{
439
        if (m_hWnd)
440
        {
441
                DestroyWindow(m_hWnd);
442
                m_hWnd = NULL;
443
        }
444
        s_pMainWindow = NULL;
445
        UnregisterClass(kWindowClassName, GetModuleHandle(NULL));
446

    
447
    CC_SAFE_DELETE(m_pSet);
448
    CC_SAFE_DELETE(m_pTouch);
449
    CC_SAFE_DELETE(m_pDelegate);
450
    CC_SAFE_DELETE(m_pEGL);
451
    delete this;
452
}
453

    
454
void CCEGLView::setTouchDelegate(EGLTouchDelegate * pDelegate)
455
{
456
    m_pDelegate = pDelegate;
457
}
458

    
459
void CCEGLView::swapBuffers()
460
{
461
    if (m_pEGL)
462
    {
463
        m_pEGL->swapBuffers();
464
    }
465
}
466

    
467
int CCEGLView::setDeviceOrientation(int eOritation)
468
{
469
        do 
470
        {
471
                bool bVertical = (CCDeviceOrientationPortrait == eOritation
472
                        || kCCDeviceOrientationPortraitUpsideDown == eOritation) ? true : false;
473

    
474
                CC_BREAK_IF(m_bOrientationReverted && bVertical != m_bOrientationInitVertical);
475
                CC_BREAK_IF(! m_bOrientationReverted && bVertical == m_bOrientationInitVertical);
476

    
477
        m_bOrientationReverted = (bVertical == m_bOrientationInitVertical) ? false : true;
478

    
479
        // swap width and height
480
                RECT rc;
481
                GetClientRect(m_hWnd, &rc);
482
        resize(rc.bottom - rc.top, rc.right - rc.left);
483

    
484
        } while (0);
485

    
486
        return m_eInitOrientation;
487
}
488

    
489
void CCEGLView::setViewPortInPoints(float x, float y, float w, float h)
490
{
491
    if (m_pEGL)
492
    {
493
        float factor = m_fScreenScaleFactor / CC_CONTENT_SCALE_FACTOR();
494
        glViewport((GLint)(x * factor) + m_rcViewPort.left,
495
            (GLint)(y * factor) + m_rcViewPort.top,
496
            (GLint)(w * factor),
497
            (GLint)(h * factor));
498
    }
499
}
500

    
501
void CCEGLView::setScissorInPoints(float x, float y, float w, float h)
502
{
503
    if (m_pEGL)
504
    {
505
        float factor = m_fScreenScaleFactor / CC_CONTENT_SCALE_FACTOR();
506
        glScissor((GLint)(x * factor) + m_rcViewPort.left,
507
            (GLint)(y * factor) + m_rcViewPort.top,
508
            (GLint)(w * factor),
509
            (GLint)(h * factor));
510
    }
511
}
512

    
513
void CCEGLView::setIMEKeyboardState(bool /*bOpen*/)
514
{
515
}
516

    
517
HWND CCEGLView::getHWnd()
518
{
519
    return m_hWnd;
520
}
521

    
522
void CCEGLView::resize(int width, int height)
523
{
524
    if (! m_hWnd)
525
    {
526
        return;
527
    }
528

    
529
    RECT rcClient;
530
    GetClientRect(m_hWnd, &rcClient);
531
    if (rcClient.right - rcClient.left == width &&
532
        rcClient.bottom - rcClient.top == height)
533
    {
534
        return;
535
    }
536
    // calculate new window width and height
537
    rcClient.right = rcClient.left + width;
538
    rcClient.bottom = rcClient.top + height;
539
    AdjustWindowRectEx(&rcClient, GetWindowLong(m_hWnd, GWL_STYLE), false, GetWindowLong(m_hWnd, GWL_EXSTYLE));
540

    
541
    // change width and height
542
    SetWindowPos(m_hWnd, 0, 0, 0, rcClient.right - rcClient.left, 
543
        rcClient.bottom - rcClient.top, SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER);
544

    
545
    if (m_pEGL)
546
    {
547
        m_pEGL->resizeSurface();
548
    }
549

    
550
    // calculate view port in pixels
551
    int viewPortW = (int)(m_tSizeInPoints.cx * m_fScreenScaleFactor);
552
    int viewPortH = (int)(m_tSizeInPoints.cy * m_fScreenScaleFactor);
553
    if (m_bOrientationReverted)
554
    {
555
        int tmp = viewPortW;
556
        viewPortW = viewPortH;
557
        viewPortH = tmp;
558
    }
559
    GetClientRect(m_hWnd, &rcClient);
560

    
561
    // calculate client new width and height
562
    int newW = rcClient.right - rcClient.left;
563
    int newH = rcClient.bottom - rcClient.top;
564

    
565
    // calculate new view port
566
    m_rcViewPort.left   = rcClient.left + (newW - viewPortW) / 2;
567
    m_rcViewPort.top    = rcClient.top + (newH - viewPortH) / 2;
568
    m_rcViewPort.right  = m_rcViewPort.left + viewPortW;
569
    m_rcViewPort.bottom = m_rcViewPort.top + viewPortH;
570
}
571

    
572
void CCEGLView::centerWindow()
573
{
574
    if (! m_hWnd)
575
    {
576
        return;
577
    }
578

    
579
    RECT rcDesktop, rcWindow;
580
    GetWindowRect(GetDesktopWindow(), &rcDesktop);
581

    
582
    // substract the task bar
583
    HWND hTaskBar = FindWindow(TEXT("Shell_TrayWnd"), NULL);
584
    if (hTaskBar != NULL)
585
    {
586
        APPBARDATA abd;
587

    
588
        abd.cbSize = sizeof(APPBARDATA);
589
        abd.hWnd = hTaskBar;
590

    
591
        SHAppBarMessage(ABM_GETTASKBARPOS, &abd);
592
        SubtractRect(&rcDesktop, &rcDesktop, &abd.rc);
593
    }
594
    GetWindowRect(m_hWnd, &rcWindow);
595

    
596
    int offsetX = (rcDesktop.right - rcDesktop.left - (rcWindow.right - rcWindow.left)) / 2;
597
    offsetX = (offsetX > 0) ? offsetX : rcDesktop.left;
598
    int offsetY = (rcDesktop.bottom - rcDesktop.top - (rcWindow.bottom - rcWindow.top)) / 2;
599
    offsetY = (offsetY > 0) ? offsetY : rcDesktop.top;
600

    
601
    SetWindowPos(m_hWnd, 0, offsetX, offsetY, 0, 0, SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOOWNERZORDER | SWP_NOZORDER);
602
}
603

    
604
void CCEGLView::setScreenScale(float factor)
605
{
606
    m_fScreenScaleFactor = factor;
607
}
608

    
609
bool CCEGLView::canSetContentScaleFactor()
610
{
611
    return true;
612
}
613

    
614
void CCEGLView::setContentScaleFactor(float contentScaleFactor)
615
{
616
    m_fScreenScaleFactor = contentScaleFactor;
617
    if (m_bOrientationReverted)
618
    {
619
        resize((int)(m_tSizeInPoints.cy * contentScaleFactor), (int)(m_tSizeInPoints.cx * contentScaleFactor));
620
    }
621
    else
622
    {
623
        resize((int)(m_tSizeInPoints.cx * contentScaleFactor), (int)(m_tSizeInPoints.cy * contentScaleFactor));
624
    }
625
    centerWindow();
626
}
627

    
628
CCEGLView& CCEGLView::sharedOpenGLView()
629
{
630
    CC_ASSERT(s_pMainWindow);
631
    return *s_pMainWindow;
632
}
633

    
634
NS_CC_END;