Exemplo n.º 1
0
QVariant Char8Codec::value( const PODData& data, int* byteCount ) const
{
    const unsigned char* pointer = (unsigned char*)data.pointer( 1 );

    *byteCount = pointer ? 1 : 0;
    QVariant result;
    if( pointer )
    {
        const Okteta::Character decodedChar = mCharCodec->decode( *pointer );

        result = QVariant::fromValue<Char8>( Char8(decodedChar) );
    }

    return result;
}
Exemplo n.º 2
0
void CSMNativeWindow::xMainLoop(void)
{
    XEvent event;
    char   buffer[31];
    KeySym keysym;

    // Sleep 2 sec to open the window;
    //sleep(_uiCreateNapTime);
    //sleep(1);
    osgSleep(100);

    while(_bRun == true)
    {
        WindowListIt      winIt  = _vWindowList.begin();
        WindowListConstIt winEnd = _vWindowList.end  ();
        
        while(winIt != winEnd)
        {
            Display *pDisplay = (*winIt)->getDisplay();

            while(XPending(pDisplay))
            {
                XNextEvent(pDisplay, &event);

                switch(event.type) 
                {
                    case KeyPress:           
                        
                        XLookupString(&event.xkey, buffer, 30, &keysym, NULL);
                        
#if 0
                        fprintf(stderr, "%x %x %x\n", 
                                keysym, 
                                XK_F12,
                                XK_Home);
#endif

                        if(keysym == XK_Escape) 
                        {
                            _bRun = false;
                            
                        }
                        else if(keysym == XK_End)
                        {
                            fprintf(stderr, "Dump\n");

                            (*winIt)->getWindow()->getShaderCache()->dump();
                        }
                        else if(keysym == XK_F12) 
                        {
                            FieldContainerFactory::the()->dump();
                        }
                        else if(keysym == XK_F11) 
                        {
                            fprintf(stderr, "dump vp[0] root\n");

                            Window *pWin = (*winIt)->getWindow();

                            if(pWin != NULL)
                            {
                                Viewport *pPort = pWin->getPort(0);

                                if(pPort != NULL)
                                {
                                    fprintf(stderr, "root %p\n",
                                            static_cast<void *>(
                                                pPort->getRoot()));

                                    DotFileGeneratorGraphOpRefPtr pGO =
                                        DotFileGeneratorGraphOp::create();

                                    pGO->traverse(pPort->getRoot());
                                }
                                else
                                {
                                    fprintf(stderr, "viewport NULL\n");
                                }
                            }
                            else
                            {
                                fprintf(stderr, "win NULL\n");
                            }
                        }
                        else if(keysym == XK_F10) 
                        {
                            fprintf(stderr, "osg dump vp[0] root\n");

                            Window *pWin = (*winIt)->getWindow();

                            if(pWin != NULL)
                            {
                                Viewport *pPort = pWin->getPort(0);

                                if(pPort != NULL)
                                {
                                    fprintf(stderr, "root %p\n",
                                            static_cast<void *>(
                                                pPort->getRoot()));

                                    SceneFileHandler::the()->write(
                                        pPort->getRoot(),
                                        "/tmp/csm.osg");

                                }
                                else
                                {
                                    fprintf(stderr, "viewport NULL\n");
                                }
                            }
                            else
                            {
                                fprintf(stderr, "win NULL\n");
                            }
                        }
                        else if(keysym == XK_F8) 
                        {
                            fprintf(stderr, "pass mask pool\n");
                            fprintf(stderr, "================\n");

                            PassMaskPool::the()->dump();

                            fprintf(stderr, "render prop pool\n");
                            fprintf(stderr, "================\n");

                            RenderPropertiesPool::the()->dump();
                        }
                        else if(keysym == XK_Home) 
                        {
                            ComplexSceneManager::the()->resetScene();
                        }
                        else if((XK_space      <= keysym) && 
                                (XK_asciitilde >= keysym))
                        {
                            ComplexSceneManager::the()->key(
                                event.xkey.x,
                                event.xkey.y,
                                CSMKeyData::ButtonDown,
                                Char8(keysym));
                        }
                        break;

                    case KeyRelease:           
                        
                        XLookupString(&event.xkey, buffer, 30, &keysym, NULL);
                        
                        //fprintf(stderr, "%x\n", keysym);

                        if(keysym == XK_Escape) 
                        {
                        }
                        else if((XK_space      <= keysym) && 
                                (XK_asciitilde >= keysym))
                        {
                            ComplexSceneManager::the()->key(
                                event.xkey.x,
                                event.xkey.y,
                                CSMKeyData::ButtonUp,
                                Char8(keysym));
                        }
                        break;


                    case ButtonPress:
                        
                        (*winIt)->mouse(event.xbutton.button - 1,
                                        MouseData::ButtonDown,
                                        mapModifier(event.xbutton.state),
                                        event.xbutton.x,
                                        event.xbutton.y);

                        break;

                    case ButtonRelease:

                        (*winIt)->mouse(event.xbutton.button - 1,
                                        MouseData::ButtonUp,
                                        mapModifier(event.xbutton.state),
                                        event.xbutton.x,
                                        event.xbutton.y);

                    break;

                    case MotionNotify:

                        (*winIt)->motion(event.xbutton.x, 
                                         event.xbutton.y,
                                         mapModifier(event.xbutton.state));

                    break;

                    case ConfigureNotify:
                    {
                        (*winIt)->reshape(event.xconfigure.width,
                                          event.xconfigure.height);
                    }                
                    break;

                    default:
                        break;
                }
                
            }
            
            ++winIt;
        }

        ComplexSceneManager::the()->frame();
        
        Thread::getCurrentChangeList()->commitChangesAndClear();
    }

    ComplexSceneManager::the()->terminate();
}
LRESULT CALLBACK  CSMNativeWindow::WndProc(HWND   hwnd, 
                                           UINT   uMsg,
                                           WPARAM wParam, 
                                           LPARAM lParam)
{
    CSMNativeWindow *pNWin = CSMNativeWindow::findWindowBy(hwnd);

    switch(uMsg)
    {       
        case WM_LBUTTONDOWN:

            if(pNWin != NULL)
            {
                pNWin->mouse(MouseData::LeftButton,
                             MouseData::ButtonDown,
                             0,
                             LOWORD(lParam),
                             HIWORD(lParam));
            }
            break;

        case WM_MBUTTONDOWN:

            if(pNWin != NULL)
            {
                pNWin->mouse(MouseData::MiddleButton,
                             MouseData::ButtonDown,
                             0,
                             LOWORD(lParam),
                             HIWORD(lParam));
            }
            break;

        case WM_RBUTTONDOWN:

            if(pNWin != NULL)
            {
                pNWin->mouse(MouseData::RightButton,
                             MouseData::ButtonDown,
                             0,
                             LOWORD(lParam),
                             HIWORD(lParam));
            }
            break;   

        case WM_LBUTTONUP:

            if(pNWin != NULL)
            {
                pNWin->mouse(MouseData::LeftButton,
                             MouseData::ButtonUp,
                             0,
                             LOWORD(lParam),
                             HIWORD(lParam));
            }
            break;              

        case WM_MBUTTONUP:

            if(pNWin != NULL)
            {
                pNWin->mouse(MouseData::MiddleButton,
                             MouseData::ButtonUp,
                             0,
                             LOWORD(lParam),
                             HIWORD(lParam));
            }
            break;

        case WM_RBUTTONUP:

            if(pNWin != NULL)
            {
                pNWin->mouse(MouseData::RightButton,
                             MouseData::ButtonUp,
                             0,
                             LOWORD(lParam),
                             HIWORD(lParam));
            }
            break;

        case WM_MOUSEMOVE:

            if(pNWin != NULL)
            {
                pNWin->motion(LOWORD(lParam),
                              HIWORD(lParam));
            }
            return DefWindowProc(hwnd, uMsg, wParam, lParam);
            break;
                                    
        case WM_KEYDOWN:

            if((int) wParam == VK_ESCAPE)
            {
                _bRun = false;
            }
            else
            {
#if 0
                fprintf(stderr, "%WM_KEYDOWN : d\n", (int) wParam);
#endif

                ComplexSceneManager::the()->key(
                    0,
                    0,
                    CSMKeyData::ButtonDown,
                    Char8(wParam));
            }
            break;

        case WM_KEYUP:

            if((int) wParam == VK_ESCAPE)
            {
                _bRun = false;
            }
            else
            {
#if 0
                fprintf(stderr, "%WM_KEYUP : %d (%c)\n", 
                        Int32(wParam),
                        Char8(wParam));
#endif

                ComplexSceneManager::the()->key(
                    0,
                    0,
                    CSMKeyData::ButtonUp,
                    Char8(wParam));
            }
            break;
            
        case WM_CHAR:
            fprintf(stderr, "WM_CHAR : %d\n", (int) wParam);
            break;

        case WM_SIZE:
            if(pNWin != NULL)
            {
                pNWin->reshape(LOWORD(lParam), HIWORD(lParam));
            }
            break;
                                    
        case WM_CREATE:
        {
            CREATESTRUCT          *pCStruct;

            pCStruct = (LPCREATESTRUCT)lParam;
            
            CSMNativeWindow UNALIGNED *pWin =
                (CSMNativeWindow UNALIGNED *) pCStruct->lpCreateParams;

            if(pWin != NULL)
            {
                PIXELFORMATDESCRIPTOR  pfd;    
                HDC                    hDC;

                int                   iPixelFormat;
                
                memset(&pfd, 0, sizeof(pfd));
                
                pfd.nSize = sizeof(pfd);
                pfd.nVersion = 1;
                
                pfd.dwFlags = 
                    PFD_DRAW_TO_WINDOW | 
                    PFD_SUPPORT_OPENGL | 
                    PFD_DOUBLEBUFFER;
                
                pfd.iPixelType = PFD_TYPE_RGBA;
                pfd.iLayerType = PFD_MAIN_PLANE;
                pfd.cDepthBits = 16;            
                
                WIN32Window *pOSGWin = pWin->_pWin32Window;
                
                pOSGWin->setHwnd(hwnd);
                
                // init the OSG window  
                hDC = GetDC(hwnd);
                
                iPixelFormat = ChoosePixelFormat(hDC, &pfd);
                
                SetPixelFormat(hDC, iPixelFormat, &pfd);    
                
//            win->setHDC ( hDC );
                
                pOSGWin->init();
                pOSGWin->deactivate();
            }
        }
        break;

        case WM_CLOSE:
            return DefWindowProc(hwnd, uMsg, wParam, lParam);
            break;

        case WM_DESTROY:
            PostQuitMessage(0);
            break;

        default:
            return DefWindowProc(hwnd, uMsg, wParam, lParam);
    }

    return 0;
}