コード例 #1
0
    virtual bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
    {
        int x = ea.getX(), y = ea.getY(), width = ea.getWindowWidth(), height = ea.getWindowHeight();
        if ( ea.getMouseYOrientation()==osgGA::GUIEventAdapter::Y_INCREASING_UPWARDS )
            y = ea.getWindowHeight() - y;
        
        if ( !CEGUI::System::getSingletonPtr() )
            return false;

        CEGUI::GUIContext& context = CEGUI::System::getSingleton().getDefaultGUIContext();

        switch ( ea.getEventType() )
        {
		case osgGA::GUIEventAdapter::KEYDOWN:
			context.injectKeyDown(key_conv(ea.getKey()));
			context.injectChar(char_conv(ea.getKey()));
			// return key_conv(ea.getKey()) != CEGUI::Key::Unknown;
			break;
		case osgGA::GUIEventAdapter::KEYUP:
			context.injectKeyUp(key_conv(ea.getKey()));
			// return key_conv(ea.getKey()) != CEGUI::Key::Unknown;
			break;
        case osgGA::GUIEventAdapter::PUSH:
            context.injectMousePosition( x, y );
            context.injectMouseButtonDown(convertMouseButton(ea.getButton()));
            break;
        case osgGA::GUIEventAdapter::RELEASE:
            context.injectMousePosition(x, y);
            context.injectMouseButtonUp(convertMouseButton(ea.getButton()));
            break;
        case osgGA::GUIEventAdapter::SCROLL:
            if ( ea.getScrollingMotion()==osgGA::GUIEventAdapter::SCROLL_DOWN )
                context.injectMouseWheelChange(-1);
            else if ( ea.getScrollingMotion()==osgGA::GUIEventAdapter::SCROLL_UP )
                context.injectMouseWheelChange(+1);
            break;
        case osgGA::GUIEventAdapter::DRAG:
        case osgGA::GUIEventAdapter::MOVE:
            context.injectMousePosition(x, y);
            break;
        case osgGA::GUIEventAdapter::RESIZE:
            if ( _camera.valid() )
            {
                _camera->setProjectionMatrix( osg::Matrixd::ortho2D(0.0, width, 0.0, height) );
                _camera->setViewport( 0.0, 0.0, width, height );
            }
            break;
        default:
            return false;
        }

        CEGUI::Window* rootWindow = context.getRootWindow();
        if ( rootWindow )
        {
            CEGUI::Window* anyWindow = rootWindow->getChildAtPosition( CEGUI::Vector2f(x, y) );
            if ( anyWindow ) return true;
        }
        return false;
    }
コード例 #2
0
static int PlatformProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
    switch (message) {
        case MSG_CREATE:
            {
                if (!hmWnd)
                    hmWnd = hWnd;

                unsigned char* pdr = 0;
                int w,h,p;
                RECT r;
                key_down = FALSE;
                GetClientRect(hWnd, &r);
#if RGB555
            sdc = CreateMemDC(width, height, 16, MEMDC_FLAG_SWSURFACE, 0x7C00, 0x3E0, 0x1F, 0x8000);    
#else
            sdc = CreateMemDC(width, height, 16, MEMDC_FLAG_SWSURFACE, 0xF800, 0x7E0, 0x1F, 0x00);    
#endif
                pdr = LockDC(sdc, &r, &w, &h, &p);
                UnlockDC(sdc);
#if RGB555
                fmt = COLOR_FORMAT_RGB555;
#else
                fmt = COLOR_FORMAT_RGB565;
#endif
                ps_initialize();

                canvas = ps_canvas_create_with_data(pdr, fmt, w, h, p);
                context = ps_context_create(canvas, 0);
                on_init(context, width, height);    
            }
            break;
        case MSG_TIMER:
            on_timer();
            break;
        case MSG_PAINT:
            {
                HDC hdc = BeginPaint(hWnd);
                on_draw(context);
                BitBlt(sdc, 0, 0, width, height, hdc, 0, 0, 0);
                EndPaint(hWnd, hdc);
            }
            return 0;
        case MSG_ERASEBKGND:
            return 0;
        case MSG_LBUTTONDOWN:
            {
                key_down = TRUE;
                on_mouse_event(LEFT_BUTTON_DOWN, key_conv(wParam), LOSWORD(lParam), HISWORD(lParam));
            }
            break;
        case MSG_LBUTTONUP:
            {
                key_down = FALSE;
                on_mouse_event(LEFT_BUTTON_UP, key_conv(wParam), LOSWORD(lParam), HISWORD(lParam));
            }
            break;
        case MSG_MOUSEMOVE:
            {
                DWORD k = key_conv(wParam);
                if (key_down)
                    k |= EVT_LBUTTON;
                on_mouse_event(MOUSE_MOVE, k, LOSWORD(lParam), HISWORD(lParam));
            }
            break;
        case MSG_KEYDOWN:
            on_key_event(KEY_EVENT_DOWN, get_virtual_key(wParam));
            break;
        case MSG_KEYUP:
            on_key_event(KEY_EVENT_UP, get_virtual_key(wParam));
            break;
        case MSG_SIZECHANGED:
            {
                RECT r;
                int w,h,p;
                unsigned char* pdr = 0;
                ps_canvas* old_canvas = 0;
                RECT* rc = (RECT*)lParam;
                width = RECTWP(rc);
                height = RECTHP(rc);
                if (sdc)
                    DeleteMemDC(sdc);

                if (width < 1)
                    width = 1;
                if (height < 1)
                    height = 1;
#if RGB555
            sdc = CreateMemDC(width, height, 16, MEMDC_FLAG_SWSURFACE, 0x7C00, 0x3E0, 0x1F, 0x8000);    
#else
            sdc = CreateMemDC(width, height, 16, MEMDC_FLAG_SWSURFACE, 0xF800, 0x7E0, 0x1F, 0x00);    
#endif
                GetClientRect(hWnd, &r);
                pdr = LockDC(sdc, &r, &w, &h, &p);
                UnlockDC(sdc);
                canvas = ps_canvas_create_with_data(pdr, fmt, w, h, p);
                old_canvas = ps_context_set_canvas(context, canvas);
                ps_canvas_unref(old_canvas);
                on_size(width, height);
            }
            break;
        case MSG_CLOSE:
            on_term(context);
            ps_context_unref(context);
            ps_canvas_unref(canvas);
            ps_shutdown();
            DeleteMemDC(sdc);
            DestroyMainWindow (hWnd);
            PostQuitMessage (hWnd);
            return 0;
    }
    return DefaultMainWinProc(hWnd, message, wParam, lParam);
}