示例#1
0
bool InputImpl::isMouseButtonPressed(Mouse::Button button)
{
    // Open a connection with the X server
    Display* display = OpenDisplay();

    // we don't care about these but they are required
    ::Window root, child;
    int wx, wy;
    int gx, gy;

    unsigned int buttons = 0;
    XQueryPointer(display, DefaultRootWindow(display), &root, &child, &gx, &gy, &wx, &wy, &buttons);

    // Close the connection with the X server
    CloseDisplay(display);

    switch (button)
    {
        case Mouse::Left:     return buttons & Button1Mask;
        case Mouse::Right:    return buttons & Button3Mask;
        case Mouse::Middle:   return buttons & Button2Mask;
        case Mouse::XButton1: return false; // not supported by X
        case Mouse::XButton2: return false; // not supported by X
        default:              return false;
    }

    return false;
}
示例#2
0
GlxContext::~GlxContext()
{
    // Destroy the context
    if (m_context)
    {
#if defined(GLX_DEBUGGING)
        GlxErrorHandler handler(m_display);
#endif

        if (glXGetCurrentContext() == m_context)
            glXMakeCurrent(m_display, None, NULL);
        glXDestroyContext(m_display, m_context);

#if defined(GLX_DEBUGGING)
        if (glxErrorOccurred)
            err() << "GLX error in GlxContext::~GlxContext()" << std::endl;
#endif
    }

    if (m_pbuffer)
    {
        glXDestroyPbuffer(m_display, m_pbuffer);
    }

    // Destroy the window if we own it
    if (m_window && m_ownsWindow)
    {
        xcb_destroy_window(m_connection, m_window);
        xcb_flush(m_connection);
    }

    // Close the connection with the X server
    CloseDisplay(m_display);
}
示例#3
0
文件: weyes.c 项目: cafiend/Wlib
int main(int argc, char *argv[])
{
    Display *display = NULL;
    char *host = "localhost";
    int port = 9090;


    display = OpenDisplay("localhost", 9090);
    if (display == NULL) {
        fprintf(stderr, "Unable to connect to display %s:%d\n", host, port);
        exit(1);
    }
     
    /* Register Callbacks */
    RegisterCallback(display, ExposeEventType, expose_event, NULL);
    RegisterCallback(display, SetupEventType, setup, NULL);
    RegisterCallback(display, MouseMoveEventType, mouse_move, NULL);
    
    MainLoop(display);
    
    CloseDisplay(display);
    free(eyes);
    free(pupils);
    return 0;
}
示例#4
0
int main( int argc, char **argv )
{
   int i;
	SetSystemLog( SYSLOG_FILE, stdout );
	g.pdi = GetDisplayInterface();
	g.pii = GetImageInterface();
	g.x = 10;
	g.y = 10;
   for( i = 1; i < argc; i++ )
	{
      AddImage( argv[i] );
	}

	while( !g.flags.exit )
		Relinquish(); // hmm what do we have to do here?
	{
		PIMAGE_DISPLAY pdi;
		pdi = g.images;
		while( pdi )
		{
			CloseDisplay( pdi->display );
			UnmakeImageFile( pdi->Loaded );
         pdi = pdi->next;
		}
	}
   return 0;
}
示例#5
0
文件: qte.cpp 项目: Kafay/vlc
/*****************************************************************************
 * CloseVideo: destroy Sys video thread output method
 *****************************************************************************
 * Terminate an output method created by Open
 *****************************************************************************/
static void Close ( vlc_object_t *p_this )
{
    vout_thread_t * p_vout = (vout_thread_t *)p_this;

    msg_Dbg( p_vout, "close" );
    if( p_vout->p_sys->p_event )
    {
        vlc_object_detach( p_vout->p_sys->p_event );

        /* Kill RunQtThread */
        vlc_object_kill( p_vout->p_sys->p_event );
        CloseDisplay(p_vout);

        vlc_thread_join( p_vout->p_sys->p_event );
        vlc_object_release( p_vout->p_sys->p_event );
    }

#ifdef NEED_QTE_MAIN
    msg_Dbg( p_vout, "releasing gui-helper" );
    module_unneed( p_vout, p_vout->p_sys->p_qte_main );
#endif

    if( p_vout->p_sys )
    {
        free( p_vout->p_sys );
        p_vout->p_sys = NULL;
    }
}
示例#6
0
Vector2i InputImpl::getMousePosition(const Window& relativeTo)
{
    WindowHandle handle = relativeTo.getSystemHandle();
    if (handle)
    {
        // Open a connection with the X server
        Display* display = OpenDisplay();

        // we don't care about these but they are required
        ::Window root, child;
        int gx, gy;
        unsigned int buttons;

        int x = 0;
        int y = 0;
        XQueryPointer(display, handle, &root, &child, &gx, &gy, &x, &y, &buttons);

        // Close the connection with the X server
        CloseDisplay(display);

        return Vector2i(x, y);
    }
    else
    {
        return Vector2i();
    }
}
int MicroDisplayControler::FreeRunning(MicroDisplayInit& mdi, BufferStorage& s)
{
	//采集mdi.MaxPics行图像到缓存
	if (MicroDisplayControler::StartGrabbing(mdi) < 0)
	{
		MD_ErrorMessageWait(mdi.fg);
		return -1;
	}
	frameindex_t lastPicNr = 0;
	cv::Mat OriginalImage;
	do{
		lastPicNr = Fg_getLastPicNumberBlockingEx(mdi.fg, lastPicNr + 1, mdi.nCamPort, 100, mdi.pMem0);
		if (lastPicNr < 0){
			int status = 0;
			MD_ErrorMessageWait(mdi.fg);
			Fg_stopAcquireEx(mdi.fg, mdi.nCamPort, mdi.pMem0, 0);
			Fg_FreeMemEx(mdi.fg, mdi.pMem0);
			Fg_FreeGrabber(mdi.fg);
			CloseDisplay(mdi.nId);
			return -1;
		}
		unsigned char *bytePtr = (unsigned char*)Fg_getImagePtrEx(mdi.fg, lastPicNr, 0, mdi.pMem0);
		if (mdi.nId != -1)
			::DrawBuffer(mdi.nId, Fg_getImagePtrEx(mdi.fg, lastPicNr, 0, mdi.pMem0), (int)lastPicNr, "");
		if (mdi.colorType == mdi.GRAY)
			OriginalImage = cv::Mat(mdi.height, mdi.width, CV_8U, bytePtr);
		else
			OriginalImage = cv::Mat(mdi.height, mdi.width, CV_8UC3, bytePtr);
	} while (!s.AddFrame(OriginalImage));
	MicroDisplayControler::EndGrabbing(mdi);
	//功能主循环END
	return 0;
}
示例#8
0
void RenderContextImplGLX::UnreadyContext() {
    if (context) {
        baseContext->SetCurrentTarget(0);
        Trace("Destroying render context.");
        glXDestroyContext(display, context);
        context = 0;
    }
    CloseDisplay();
}
示例#9
0
static void Destroy( vlc_object_t *p_this )
{
    vout_thread_t *p_vout = (vout_thread_t *)p_this;
    vout_sys_t *p_sys = p_vout->p_sys;

    CloseDisplay( p_vout );
    if( p_sys ) free( p_sys );
    p_sys = NULL;
}
示例#10
0
/*****************************************************************************
 * CloseVideo: destroy Sys video thread output method
 *****************************************************************************
 * Terminate an output method created by vout_SDLCreate
 *****************************************************************************/
static void Close ( vlc_object_t *p_this )
{
    vout_thread_t * p_vout = (vout_thread_t *)p_this;

    CloseDisplay( p_vout );
    SDL_QuitSubSystem( SDL_INIT_VIDEO );

    free( p_vout->p_sys );
}
示例#11
0
int MicroDisplayControler::FreeRunningFocusing(MicroDisplayInit& mdi)
{
	std::cout << "开始对焦,按1放大,按2缩小,按3退出。\r\n";
	//采集mdi.MaxPics行图像到缓存
	if (MicroDisplayControler::StartGrabbing(mdi) < 0)
	{
		MD_ErrorMessageWait(mdi.fg);
		return -1;
	}
	cv::Mat OriginalImage;
	int resize = mdi.width;
	frameindex_t lastPicNr = 0;
	cv::namedWindow("SHOW", CV_WINDOW_AUTOSIZE);
	int pos = 0;
	int realPos = 0;
	const int maxpos = 80;
	cv::createTrackbar("OFF SET / %", "SHOW", &pos, maxpos);
	do{
		lastPicNr = Fg_getLastPicNumberBlockingEx(mdi.fg, lastPicNr + 1, mdi.nCamPort, 100, mdi.pMem0);
		if (lastPicNr < 0){
			int status = 0;
			MD_ErrorMessageWait(mdi.fg);
			Fg_stopAcquireEx(mdi.fg, mdi.nCamPort, mdi.pMem0, 0);
			Fg_FreeMemEx(mdi.fg, mdi.pMem0);
			Fg_FreeGrabber(mdi.fg);
			CloseDisplay(mdi.nId);

			return 0;
		}
		unsigned char *bytePtr = (unsigned char*)Fg_getImagePtrEx(mdi.fg, lastPicNr, 0, mdi.pMem0);
		//if (mdi.nId != -1)
		//	::DrawBuffer(mdi.nId, Fg_getImagePtrEx(mdi.fg, lastPicNr, 0, mdi.pMem0), (int)lastPicNr, "");
		if (mdi.colorType == mdi.GRAY)
			OriginalImage = cv::Mat(mdi.height, mdi.width, CV_8U, bytePtr);
		else
			OriginalImage = cv::Mat(mdi.height, mdi.width, CV_8UC3, bytePtr);
		if (resize != mdi.width)
			cv::resize(OriginalImage, OriginalImage, cv::Size(resize, mdi.height));
		realPos = resize / 100 * pos;
		cv::Mat ROI = OriginalImage(cv::Rect(realPos, 0, resize - realPos, mdi.height));
		cv::imshow("SHOW", ROI);
		char t = cv::waitKey(20);
		if (t == '3')
			break;
		if (t == '2' && resize > 800)
			resize /= 2;
		if (t == '1' && resize <  mdi.width * 3)
			resize *= 2;

	} while (true);
	MicroDisplayControler::EndGrabbing(mdi);
	cv::destroyAllWindows();
	//功能主循环END
	return 0;
}
VideoMode VideoModeImpl::getDesktopMode()
{
    VideoMode desktopMode;

    // Open a connection with the X server
    Display* display = OpenDisplay();
    if (display)
    {
        // Retrieve the default screen number
        int screen = DefaultScreen(display);

        // Check if the XRandR extension is present
        int version;
        if (XQueryExtension(display, "RANDR", &version, &version, &version))
        {
            // Get the current configuration
            XRRScreenConfiguration* config = XRRGetScreenInfo(display, RootWindow(display, screen));
            if (config)
            {
                // Get the current video mode
                Rotation currentRotation;
                int currentMode = XRRConfigCurrentConfiguration(config, &currentRotation);

                // Get the available screen sizes
                int nbSizes;
                XRRScreenSize* sizes = XRRConfigSizes(config, &nbSizes);
                if (sizes && (nbSizes > 0))
                    desktopMode = VideoMode(sizes[currentMode].width, sizes[currentMode].height, DefaultDepth(display, screen));

                // Free the configuration instance
                XRRFreeScreenConfigInfo(config);
            }
            else
            {
                // Failed to get the screen configuration
                err() << "Failed to retrieve the screen configuration while trying to get the desktop video modes" << std::endl;
            }
        }
        else
        {
            // XRandr extension is not supported : we cannot get the video modes
            err() << "Failed to use the XRandR extension while trying to get the desktop video modes" << std::endl;
        }

        // Close the connection with the X server
        CloseDisplay(display);
    }
    else
    {
        // We couldn't connect to the X server
        err() << "Failed to connect to the X server while trying to get the desktop video modes" << std::endl;
    }

    return desktopMode;
}
示例#13
0
static void Close(vlc_object_t *object)
{
    vout_display_t *vd = (vout_display_t *)object;
    vout_display_sys_t *sys = vd->sys;

    if (sys->pool)
        picture_pool_Delete(sys->pool);

    CloseDisplay(vd);
    free(sys);
}
示例#14
0
void InputImpl::setMousePosition(const Vector2i& position)
{
    // Open a connection with the X server
    Display* display = OpenDisplay();

    XWarpPointer(display, None, DefaultRootWindow(display), 0, 0, 0, 0, position.x, position.y);
    XFlush(display);

    // Close the connection with the X server
    CloseDisplay(display);
}
示例#15
0
void CameraClose()
{
	fastCMOS->stop();

	delete fastCMOS;
	fastCMOS = 0;

	imgClose(session, 0);
	imgClose(ifid, 1);

	CloseDisplay();
}
示例#16
0
void InputImpl::setMousePosition(const Vector2i& position, const Window& relativeTo)
{
    // Open a connection with the X server
    Display* display = OpenDisplay();

    WindowHandle handle = relativeTo.getSystemHandle();
    if (handle)
    {
        XWarpPointer(display, None, handle, 0, 0, 0, 0, position.x, position.y);
        XFlush(display);
    }

    // Close the connection with the X server
    CloseDisplay(display);
}
示例#17
0
文件: qte.cpp 项目: Kafay/vlc
/*****************************************************************************
 * Manage: handle Qte events
 *****************************************************************************
 * This function should be called regularly by video output thread. It manages
 * Qte events and allows window resizing. It returns a non null value on
 * error.
 *****************************************************************************/
static int Manage( vout_thread_t *p_vout )
{
//    msg_Dbg( p_vout, "Manage" );

    /* Fullscreen change */
    if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
    {
        p_vout->b_fullscreen = ! p_vout->b_fullscreen;

//        p_vout->p_sys->b_cursor_autohidden = 0;
//        SDL_ShowCursor( p_vout->p_sys->b_cursor &&
//                        ! p_vout->p_sys->b_cursor_autohidden );

        p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
        p_vout->i_changes |= VOUT_SIZE_CHANGE;
    }

    /*
     * Size change
     */
    if( p_vout->i_changes & VOUT_SIZE_CHANGE )
    {
        msg_Dbg( p_vout, "video display resized (%dx%d)",
                 p_vout->p_sys->i_width, p_vout->p_sys->i_height );

        CloseDisplay( p_vout );
        OpenDisplay( p_vout );

        /* We don't need to signal the vout thread about the size change if
         * we can handle rescaling ourselves */
        p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
    }

    /* Pointer change */
//    if( ! p_vout->p_sys->b_cursor_autohidden &&
//        ( mdate() - p_vout->p_sys->i_lastmoved >
//            p_vout->p_sys->i_mouse_hide_timeout ) )
//    {
//        /* Hide the mouse automatically */
//        p_vout->p_sys->b_cursor_autohidden = 1;
//        SDL_ShowCursor( 0 );
//    }
//
//    if( !vlc_object_alive (p_vout->p_libvlc) )
//        p_vout->p_sys->bRunning = FALSE;

    return 0;
}
示例#18
0
void CImage::Close()
{
    if (!gnDecoderThreadId || GetCurrentThreadId() == gnDecoderThreadId)
    {
        CloseImage();
    }

    CloseDisplay();

    // Удалить указатели на страницы
    if (mp_Pages)
    {
        delete mp_Pages;
        mp_Pages = NULL;
    }
}
示例#19
0
/**
 * Terminate an output method created by Open
 */
static void Close(vlc_object_t *object)
{
    vout_display_t *vd = (vout_display_t *)object;
    vout_display_sys_t *sys = vd->sys;

    if (sys->pool)
        picture_pool_Delete(sys->pool);
    if (!sys->is_hw_accel && sys->picture)
        picture_Release(sys->picture);

    CloseDisplay(vd);

    if (sys->is_tty)
        TtyExit(vd);

    free(sys);
}
示例#20
0
Vector2i InputImpl::getMousePosition()
{
    // Open a connection with the X server
    Display* display = OpenDisplay();

    // we don't care about these but they are required
    ::Window root, child;
    int x, y;
    unsigned int buttons;

    int gx = 0;
    int gy = 0;
    XQueryPointer(display, DefaultRootWindow(display), &root, &child, &gx, &gy, &x, &y, &buttons);

    // Close the connection with the X server
    CloseDisplay(display);

    return Vector2i(gx, gy);
}
示例#21
0
GlxContext::~GlxContext()
{
    // Destroy the context
    if (m_context)
    {
        if (glXGetCurrentContext() == m_context)
            glXMakeCurrent(m_display, None, NULL);
        glXDestroyContext(m_display, m_context);
    }
    
    // Destroy the window if we own it
    if (m_window && m_ownsWindow)
    {
        XDestroyWindow(m_display, m_window);
        XFlush(m_display);
    }

    // Close the connection with the X server
    CloseDisplay(m_display);
}
示例#22
0
int show_images(Fg_Struct *fg, int *nr, int num_imgs, int w, int h)
{
#if SHOW_DISP
	int i;
	int disp;
	unsigned long *img;

	disp = CreateDisplay(8, w, h);
	SetBufferWidth(disp, w, h);
	for(i = 0; i < num_imgs; i++) {
		if(nr[i] > FG_OK) {
			img = Fg_getImagePtr(fg, nr[i], PORT_A);
			DrawBuffer(disp, img, nr[i], "SimpleTiming");
			Sleep(PAUSE);
		}
	}
	CloseDisplay(disp);
#endif
	return FG_OK;
}
示例#23
0
void CameraConfigure()
{
	CloseDisplay();

	int w = 600, h= 600;

	fastCMOS->setFramerate(10);
	int fps=  fastCMOS->getFramerate().fps;

	ROI rfit = fastCMOS->setROI(ROI(w,h));
	ROI roi = fastCMOS->getROI();
	fastCMOS->setup(50);
	fastCMOS->start();
	//IMAQBuffer* buf = fastCMOS->snap();

	int mode = fastCMOS->getMode();
	
	InitDisplay(w,h);

//	IMAQBuffer* buf = fastCMOS->snap();
	

//	void *buf = fastCMOS->getLastFrame();
}
示例#24
0
文件: omapfb.c 项目: Kafay/vlc
/*****************************************************************************
 * Destroy: destroy omapfb video thread output method
 *****************************************************************************
 * Terminate an output method created by Create
 *****************************************************************************/
static void Destroy( vlc_object_t *p_this )
{
    vout_thread_t *p_vout = (vout_thread_t *)p_this;

    CloseDisplay( p_vout );

    if( p_vout->p_sys->b_embed )
    {
        vout_ReleaseWindow( p_vout->p_sys->owner_window );
        if( p_vout->b_fullscreen )
            XDestroyWindow( p_vout->p_sys->p_display, p_vout->p_sys->window );
        XCloseDisplay( p_vout->p_sys->p_display );
    }

#ifdef HAVE_OSSO
    if ( p_vout->p_sys->p_octx != NULL ) {
        msg_Dbg( p_vout, "Deinitializing osso context" );
        osso_deinitialize( p_vout->p_sys->p_octx );
    }
#endif

    /* Destroy structure */
    free( p_vout->p_sys );
}
示例#25
0
bool InputImpl::isKeyPressed(Keyboard::Key key)
{
    // Get the corresponding X11 keysym
    KeySym keysym = 0;
    switch (key)
    {
    case Keyboard::LShift:
        keysym = XK_Shift_L;
        break;
    case Keyboard::RShift:
        keysym = XK_Shift_R;
        break;
    case Keyboard::LControl:
        keysym = XK_Control_L;
        break;
    case Keyboard::RControl:
        keysym = XK_Control_R;
        break;
    case Keyboard::LAlt:
        keysym = XK_Alt_L;
        break;
    case Keyboard::RAlt:
        keysym = XK_Alt_R;
        break;
    case Keyboard::LSystem:
        keysym = XK_Super_L;
        break;
    case Keyboard::RSystem:
        keysym = XK_Super_R;
        break;
    case Keyboard::Menu:
        keysym = XK_Menu;
        break;
    case Keyboard::Escape:
        keysym = XK_Escape;
        break;
    case Keyboard::SemiColon:
        keysym = XK_semicolon;
        break;
    case Keyboard::Slash:
        keysym = XK_slash;
        break;
    case Keyboard::Equal:
        keysym = XK_equal;
        break;
    case Keyboard::Dash:
        keysym = XK_minus;
        break;
    case Keyboard::LBracket:
        keysym = XK_bracketleft;
        break;
    case Keyboard::RBracket:
        keysym = XK_bracketright;
        break;
    case Keyboard::Comma:
        keysym = XK_comma;
        break;
    case Keyboard::Period:
        keysym = XK_period;
        break;
    case Keyboard::Quote:
        keysym = XK_apostrophe;
        break;
    case Keyboard::BackSlash:
        keysym = XK_backslash;
        break;
    case Keyboard::Tilde:
        keysym = XK_grave;
        break;
    case Keyboard::Space:
        keysym = XK_space;
        break;
    case Keyboard::Return:
        keysym = XK_Return;
        break;
    case Keyboard::BackSpace:
        keysym = XK_BackSpace;
        break;
    case Keyboard::Tab:
        keysym = XK_Tab;
        break;
    case Keyboard::PageUp:
        keysym = XK_Prior;
        break;
    case Keyboard::PageDown:
        keysym = XK_Next;
        break;
    case Keyboard::End:
        keysym = XK_End;
        break;
    case Keyboard::Home:
        keysym = XK_Home;
        break;
    case Keyboard::Insert:
        keysym = XK_Insert;
        break;
    case Keyboard::Delete:
        keysym = XK_Delete;
        break;
    case Keyboard::Add:
        keysym = XK_KP_Add;
        break;
    case Keyboard::Subtract:
        keysym = XK_KP_Subtract;
        break;
    case Keyboard::Multiply:
        keysym = XK_KP_Multiply;
        break;
    case Keyboard::Divide:
        keysym = XK_KP_Divide;
        break;
    case Keyboard::Pause:
        keysym = XK_Pause;
        break;
    case Keyboard::F1:
        keysym = XK_F1;
        break;
    case Keyboard::F2:
        keysym = XK_F2;
        break;
    case Keyboard::F3:
        keysym = XK_F3;
        break;
    case Keyboard::F4:
        keysym = XK_F4;
        break;
    case Keyboard::F5:
        keysym = XK_F5;
        break;
    case Keyboard::F6:
        keysym = XK_F6;
        break;
    case Keyboard::F7:
        keysym = XK_F7;
        break;
    case Keyboard::F8:
        keysym = XK_F8;
        break;
    case Keyboard::F9:
        keysym = XK_F9;
        break;
    case Keyboard::F10:
        keysym = XK_F10;
        break;
    case Keyboard::F11:
        keysym = XK_F11;
        break;
    case Keyboard::F12:
        keysym = XK_F12;
        break;
    case Keyboard::F13:
        keysym = XK_F13;
        break;
    case Keyboard::F14:
        keysym = XK_F14;
        break;
    case Keyboard::F15:
        keysym = XK_F15;
        break;
    case Keyboard::Left:
        keysym = XK_Left;
        break;
    case Keyboard::Right:
        keysym = XK_Right;
        break;
    case Keyboard::Up:
        keysym = XK_Up;
        break;
    case Keyboard::Down:
        keysym = XK_Down;
        break;
    case Keyboard::Numpad0:
        keysym = XK_KP_Insert;
        break;
    case Keyboard::Numpad1:
        keysym = XK_KP_End;
        break;
    case Keyboard::Numpad2:
        keysym = XK_KP_Down;
        break;
    case Keyboard::Numpad3:
        keysym = XK_KP_Page_Down;
        break;
    case Keyboard::Numpad4:
        keysym = XK_KP_Left;
        break;
    case Keyboard::Numpad5:
        keysym = XK_KP_Begin;
        break;
    case Keyboard::Numpad6:
        keysym = XK_KP_Right;
        break;
    case Keyboard::Numpad7:
        keysym = XK_KP_Home;
        break;
    case Keyboard::Numpad8:
        keysym = XK_KP_Up;
        break;
    case Keyboard::Numpad9:
        keysym = XK_KP_Page_Up;
        break;
    case Keyboard::A:
        keysym = XK_a;
        break;
    case Keyboard::B:
        keysym = XK_b;
        break;
    case Keyboard::C:
        keysym = XK_c;
        break;
    case Keyboard::D:
        keysym = XK_d;
        break;
    case Keyboard::E:
        keysym = XK_e;
        break;
    case Keyboard::F:
        keysym = XK_f;
        break;
    case Keyboard::G:
        keysym = XK_g;
        break;
    case Keyboard::H:
        keysym = XK_h;
        break;
    case Keyboard::I:
        keysym = XK_i;
        break;
    case Keyboard::J:
        keysym = XK_j;
        break;
    case Keyboard::K:
        keysym = XK_k;
        break;
    case Keyboard::L:
        keysym = XK_l;
        break;
    case Keyboard::M:
        keysym = XK_m;
        break;
    case Keyboard::N:
        keysym = XK_n;
        break;
    case Keyboard::O:
        keysym = XK_o;
        break;
    case Keyboard::P:
        keysym = XK_p;
        break;
    case Keyboard::Q:
        keysym = XK_q;
        break;
    case Keyboard::R:
        keysym = XK_r;
        break;
    case Keyboard::S:
        keysym = XK_s;
        break;
    case Keyboard::T:
        keysym = XK_t;
        break;
    case Keyboard::U:
        keysym = XK_u;
        break;
    case Keyboard::V:
        keysym = XK_v;
        break;
    case Keyboard::W:
        keysym = XK_w;
        break;
    case Keyboard::X:
        keysym = XK_x;
        break;
    case Keyboard::Y:
        keysym = XK_y;
        break;
    case Keyboard::Z:
        keysym = XK_z;
        break;
    case Keyboard::Num0:
        keysym = XK_0;
        break;
    case Keyboard::Num1:
        keysym = XK_1;
        break;
    case Keyboard::Num2:
        keysym = XK_2;
        break;
    case Keyboard::Num3:
        keysym = XK_3;
        break;
    case Keyboard::Num4:
        keysym = XK_4;
        break;
    case Keyboard::Num5:
        keysym = XK_5;
        break;
    case Keyboard::Num6:
        keysym = XK_6;
        break;
    case Keyboard::Num7:
        keysym = XK_7;
        break;
    case Keyboard::Num8:
        keysym = XK_8;
        break;
    case Keyboard::Num9:
        keysym = XK_9;
        break;
    default:
        keysym = 0;
        break;
    }

    // Sanity checks
    if (key < 0 || key >= sf::Keyboard::KeyCount)
        return false;

    // Open a connection with the X server
    Display* display = OpenDisplay();

    // Convert to keycode
    xcb_keycode_t keycode = XKeysymToKeycode(display, keysym);

    CloseDisplay(display);

    ScopedXcbPtr<xcb_generic_error_t> error(NULL);

    // Open a connection with the X server
    xcb_connection_t* connection = OpenConnection();

    // Get the whole keyboard state
    ScopedXcbPtr<xcb_query_keymap_reply_t> keymap(
        xcb_query_keymap_reply(
            connection,
            xcb_query_keymap(connection),
            &error
        )
    );

    // Close the connection with the X server
    CloseConnection(connection);

    if (error)
    {
        err() << "Failed to query keymap" << std::endl;

        return false;
    }

    // Check our keycode
    return (keymap->keys[keycode / 8] & (1 << (keycode % 8))) != 0;
}
std::vector<VideoMode> VideoModeImpl::getFullscreenModes()
{
    std::vector<VideoMode> modes;

    // Open a connection with the X server
    Display* display = OpenDisplay();
    if (display)
    {
        // Retrieve the default screen number
        int screen = DefaultScreen(display);

        // Check if the XRandR extension is present
        int version;
        if (XQueryExtension(display, "RANDR", &version, &version, &version))
        {
            // Get the current configuration
            XRRScreenConfiguration* config = XRRGetScreenInfo(display, RootWindow(display, screen));
            if (config)
            {
                // Get the available screen sizes
                int nbSizes;
                XRRScreenSize* sizes = XRRConfigSizes(config, &nbSizes);
                if (sizes && (nbSizes > 0))
                {
                    // Get the list of supported depths
                    int nbDepths = 0;
                    int* depths = XListDepths(display, screen, &nbDepths);
                    if (depths && (nbDepths > 0))
                    {
                        // Combine depths and sizes to fill the array of supported modes
                        for (int i = 0; i < nbDepths; ++i)
                        {
                            for (int j = 0; j < nbSizes; ++j)
                            {
                                // Convert to VideoMode
                                VideoMode mode(sizes[j].width, sizes[j].height, depths[i]);
            
                                // Add it only if it is not already in the array
                                if (std::find(modes.begin(), modes.end(), mode) == modes.end())
                                    modes.push_back(mode);
                            }
                        }

                        // Free the array of depths
                        XFree(depths);
                    }
                }

                // Free the configuration instance
                XRRFreeScreenConfigInfo(config);
            }
            else
            {
                // Failed to get the screen configuration
                err() << "Failed to retrieve the screen configuration while trying to get the supported video modes" << std::endl;
            }
        }
        else
        {
            // XRandr extension is not supported : we cannot get the video modes
            err() << "Failed to use the XRandR extension while trying to get the supported video modes" << std::endl;
        }

        // Close the connection with the X server
        CloseDisplay(display);
    }
    else
    {
        // We couldn't connect to the X server
        err() << "Failed to connect to the X server while trying to get the supported video modes" << std::endl;
    }

    return modes;
}
示例#27
0
文件: CursorImpl.cpp 项目: Ceylo/SFML
CursorImpl::~CursorImpl()
{
    release();

    CloseDisplay(m_display);
}
示例#28
0
文件: Demo.cpp 项目: quocble/cubes
int main( int argc, char * argv[] )
{	
	printf( "networked physics demo\n" );

    bool shadows = true;
    bool playback = false;
    bool video = false;

    for ( int i = 1; i < argc; ++i )
    {
        if ( strcmp( argv[i], "playback" ) == 0 )
        {
            printf( "playback\n" );
            playback = true;
        }
        else if ( strcmp( argv[i], "video" ) == 0 )
        {
            printf( "video\n" );
            video = true;
        }
    }

	net::InitializeSockets();
	while ( !net::IsInitialized() )
	{
		printf( "error: failed to initialize sockets\n" );
		net::ShutdownSockets();
		return 1;
	}

#ifndef PROFILE
	
	int displayWidth, displayHeight;
	GetDisplayResolution( displayWidth, displayHeight );

    #ifdef LETTERBOX
    displayWidth = 1280;
    displayHeight = 800;
    #endif

	printf( "display resolution is %d x %d\n", displayWidth, displayHeight );

	HideMouseCursor();
	
	if ( !OpenDisplay( "Networked Physics", displayWidth, displayHeight ) )
	{
		printf( "error: failed to open display" );
		return 1;
	}
	
#endif

	int currentDemo = 0;
	Demo * demo = CreateDemo( 0 );
	assert( demo );
	demo->InitializeWorld();
    renderInterface = new render::Interface( displayWidth, displayHeight );	
    #ifndef PROFILE
	demo->SetRenderInterface( renderInterface );
    #endif

	uint32_t frame = 0;

    // create 2 pixel buffer objects, you need to delete them when program exits.
    // glBufferDataARB with NULL pointer reserves only memory space.
    const int NumPBOs = 2;
    GLuint pboIds[NumPBOs];
    int index = 0;
    const int dataSize = displayWidth * displayHeight * 3;
    if ( video )
    {
        glGenBuffersARB( NumPBOs, pboIds );
        for ( int i = 0; i < NumPBOs; ++i )
        {
            glBindBufferARB( GL_PIXEL_UNPACK_BUFFER_ARB, pboIds[i] );
            glBufferDataARB( GL_PIXEL_UNPACK_BUFFER_ARB, dataSize, 0, GL_STREAM_DRAW_ARB );
        }
        glBindBufferARB( GL_PIXEL_UNPACK_BUFFER_ARB, 0 );
    }

    // record input to a file
    // read it back in playback mode for recording video
    FILE * inputFile = fopen( "output/recordedInputs", playback ? "rb" : "wb" );
    if ( !inputFile )
    {
        printf( "failed to open input file\n" );
        return 1;
    }

    bool quit = false;
	while ( !quit )
	{
		#ifdef PROFILE
		printf( "profiling frame %d\n", frame );
		#endif
		
		platform::Input input;
        
        if ( !playback )
        {
            input = platform::Input::Sample();
            fwrite( &input, sizeof( platform::Input ), 1, inputFile );
            fflush( inputFile );
        }
        else
        {
            const int size = sizeof( platform::Input );
            if ( !fread( &input, size, 1, inputFile ) )
                quit = true;
        }

		#ifdef PROFILE
		if ( frame > 500 )
			input.left = frame % 2;
		else if ( frame > 100 && ( frame % 5 ) == 0 )
			input.left  = true;
		input.z = true;
		#endif
		
		if ( input.alt )
		{
			int demoIndex = -1;
			
			if ( input.one )
				demoIndex = 0;
				
			if ( input.two )
				demoIndex = 1;
				
			if ( input.three )
				demoIndex = 2;
				
			if ( input.four )
				demoIndex = 3;
				
			if ( input.five )
				demoIndex = 4;
				
			if ( input.six )
				demoIndex = 5;
				
			if ( input.seven )
				demoIndex = 6;
				
			if ( input.eight )
				demoIndex = 7;
				
			if ( input.nine )
				demoIndex = 8;
				
			if ( input.zero )
				demoIndex = 9;

			static bool enterDownLastFrame = false;
			if ( input.enter && !enterDownLastFrame )
				shadows = !shadows;
			enterDownLastFrame = input.enter;
				
			if ( demoIndex != -1 )
			{
				Demo * newDemo = CreateDemo( demoIndex );
				if ( newDemo )
				{
					#ifndef PROFILE
                    renderInterface->ClearScreen();
                    #ifdef LETTERBOX
                    renderInterface->LetterBox( 80 );
                    #endif
					UpdateDisplay( 1 );
					#endif
                    
					delete demo;
					demo = newDemo;
					assert( demo );
					demo->InitializeWorld();
					#ifndef PROFILE
					demo->SetRenderInterface( renderInterface );
					#endif
					currentDemo = demoIndex;
				}
			}
		}
		
		static bool escapeDownLastFrame = false;		
		if ( input.escape && !escapeDownLastFrame )
		{
            #ifndef PROFILE
            renderInterface->ClearScreen();
            #ifdef LETTERBOX
            renderInterface->LetterBox( 80 );
            #endif
            UpdateDisplay( 1 );
            #endif

			delete demo;
			demo = CreateDemo( currentDemo );
			assert( demo );
			demo->InitializeWorld();
			#ifndef PROFILE
			demo->SetRenderInterface( renderInterface );
			#endif
		}
		escapeDownLastFrame = input.escape;
		
		demo->ProcessInput( !input.alt ? input : platform::Input() );

		demo->Update( DeltaTime );

        if ( video )
        {
            // "index" is used to read pixels from framebuffer to a PBO
            // "nextIndex" is used to update pixels in the other PBO
            index = ( index + 1 ) % NumPBOs;
            int prevIndex = ( index + NumPBOs - 1 ) % NumPBOs;

            // set the target framebuffer to read
            glReadBuffer( GL_FRONT );

            // read pixels from framebuffer to PBO
            // glReadPixels() should return immediately.
            glBindBufferARB( GL_PIXEL_PACK_BUFFER_ARB, pboIds[index] );
            glReadPixels( 0, 0, displayWidth, displayHeight, GL_BGR, GL_UNSIGNED_BYTE, 0 );
            if ( frame > (unsigned) NumPBOs )
            {
                // map the PBO to process its data by CPU
                glBindBufferARB( GL_PIXEL_PACK_BUFFER_ARB, pboIds[prevIndex] );
                GLubyte * ptr = (GLubyte*) glMapBufferARB( GL_PIXEL_PACK_BUFFER_ARB,
                                                           GL_READ_ONLY_ARB );
                if ( ptr )
                {
                    char filename[256];
                    sprintf( filename, "output/frame-%05d.tga", frame - NumPBOs );
                    #ifdef LETTERBOX
                    WriteTGA( filename, displayWidth, displayHeight - 80, ptr + displayWidth * 3 * 40 );
                    #else
                    WriteTGA( filename, displayWidth, displayHeight, ptr );
                    #endif
                    glUnmapBufferARB( GL_PIXEL_PACK_BUFFER_ARB );
                }
            }

            // back to conventional pixel operation
            glBindBufferARB( GL_PIXEL_PACK_BUFFER_ARB, 0 );
        }

        demo->WaitForSim();
		
		#ifndef PROFILE

    		demo->Render( DeltaTime, shadows );

            #ifdef LETTERBOX
            renderInterface->LetterBox( 80 );
            #endif

            UpdateDisplay( video ? 0 : 1 );
        
		#endif

		frame ++;
	}

    #ifndef PROFILE
	CloseDisplay();
    #endif

	delete demo;
    delete renderInterface;

	printf( "shutdown\n" );
	
	net::ShutdownSockets();

	return 0;
}
示例#29
0
/*****************************************************************************
 * Manage: handle Sys events
 *****************************************************************************
 * This function should be called regularly by video output thread. It returns
 * a non null value if an error occurred.
 *****************************************************************************/
static int Manage( vout_thread_t *p_vout )
{
    SDL_Event event;                                            /* SDL event */
    vlc_value_t val;
    unsigned int i_width, i_height, i_x, i_y;

    /* Process events */
    while( SDL_PollEvent(&event) )
    {
        switch( event.type )
        {
        case SDL_VIDEORESIZE:                          /* Resizing of window */
            /* Update dimensions */
            p_vout->i_changes |= VOUT_SIZE_CHANGE;
            p_vout->i_window_width = p_vout->p_sys->i_width = event.resize.w;
            p_vout->i_window_height = p_vout->p_sys->i_height = event.resize.h;
            break;

        case SDL_MOUSEMOTION:
            vout_PlacePicture( p_vout, p_vout->p_sys->i_width,
                               p_vout->p_sys->i_height,
                               &i_x, &i_y, &i_width, &i_height );

            val.i_int = ( event.motion.x - i_x )
                         * p_vout->render.i_width / i_width;
            var_Set( p_vout, "mouse-x", val );
            val.i_int = ( event.motion.y - i_y )
                         * p_vout->render.i_height / i_height;
            var_Set( p_vout, "mouse-y", val );

            val.b_bool = VLC_TRUE;
            var_Set( p_vout, "mouse-moved", val );

            if( p_vout->p_sys->b_cursor &&
                (abs(event.motion.xrel) > 2 || abs(event.motion.yrel) > 2) )
            {
                if( p_vout->p_sys->b_cursor_autohidden )
                {
                    p_vout->p_sys->b_cursor_autohidden = 0;
                    SDL_ShowCursor( 1 );
                }
                else
                {
                    p_vout->p_sys->i_lastmoved = mdate();
                }
            }
            break;

        case SDL_MOUSEBUTTONUP:
            switch( event.button.button )
            {
            case SDL_BUTTON_LEFT:
                val.b_bool = VLC_TRUE;
                var_Set( p_vout, "mouse-clicked", val );
                break;

            case SDL_BUTTON_RIGHT:
                {
                    intf_thread_t *p_intf;
                    p_intf = vlc_object_find( p_vout, VLC_OBJECT_INTF,
                                                      FIND_ANYWHERE );
                    if( p_intf )
                    {
                        p_intf->b_menu_change = 1;
                        vlc_object_release( p_intf );
                    }
                }
                break;
            }
            break;

        case SDL_MOUSEBUTTONDOWN:
            switch( event.button.button )
            {
            case SDL_BUTTON_LEFT:
                /* In this part we will eventually manage
                 * clicks for DVD navigation for instance. */

                /* detect double-clicks */
                if( ( mdate() - p_vout->p_sys->i_lastpressed ) < 300000 )
                    p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;

                p_vout->p_sys->i_lastpressed = mdate();
                break;

            case 4:
                break;

            case 5:
                break;
            }
            break;

        case SDL_QUIT:
            p_vout->p_vlc->b_die = 1;
            break;

        case SDL_KEYDOWN:                             /* if a key is pressed */

            switch( event.key.keysym.sym )
            {
            case SDLK_ESCAPE:
                if( p_vout->b_fullscreen )
                {
                    p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
                }
                else
                {
                    p_vout->p_vlc->b_die = 1;
                }
                break;

            case SDLK_q:                                             /* quit */
                p_vout->p_vlc->b_die = 1;
                break;

            case SDLK_f:                             /* switch to fullscreen */
                p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
                break;

            case SDLK_c:                                 /* toggle grayscale */
                p_vout->b_grayscale = ! p_vout->b_grayscale;
                p_vout->i_changes |= VOUT_GRAYSCALE_CHANGE;
                break;

            case SDLK_i:                                      /* toggle info */
                p_vout->b_info = ! p_vout->b_info;
                p_vout->i_changes |= VOUT_INFO_CHANGE;
                break;

            case SDLK_s:                                   /* toggle scaling */
                p_vout->b_scale = ! p_vout->b_scale;
                p_vout->i_changes |= VOUT_SCALE_CHANGE;
                break;

            case SDLK_SPACE:                             /* toggle interface */
                p_vout->b_interface = ! p_vout->b_interface;
                p_vout->i_changes |= VOUT_INTF_CHANGE;
                break;

            case SDLK_MENU:
                {
                    intf_thread_t *p_intf;
                    p_intf = vlc_object_find( p_vout, VLC_OBJECT_INTF,
                                                      FIND_ANYWHERE );
                    if( p_intf != NULL )
                    {
                        p_intf->b_menu_change = 1;
                        vlc_object_release( p_intf );
                    }
                }
                break;

            case SDLK_LEFT:
                break;

            case SDLK_RIGHT:
                break;

            case SDLK_UP:
                break;

            case SDLK_DOWN:
                break;

            case SDLK_b:
                {
                    audio_volume_t i_volume;
                    if ( !aout_VolumeDown( p_vout, 1, &i_volume ) )
                    {
                        msg_Dbg( p_vout, "audio volume is now %d", i_volume );
                    }
                    else
                    {
                        msg_Dbg( p_vout, "audio volume: operation not supported" );
                    }
                }
                break;

            case SDLK_n:
                {
                    audio_volume_t i_volume;
                    if ( !aout_VolumeUp( p_vout, 1, &i_volume ) )
                    {
                        msg_Dbg( p_vout, "audio volume is now %d", i_volume );
                    }
                    else
                    {
                        msg_Dbg( p_vout, "audio volume: operation not supported" );
                    }
                }
                break;

             default:
                break;
            }
            break;

        default:
            break;
        }
    }

    /* Fullscreen change */
    if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
    {
        p_vout->b_fullscreen = ! p_vout->b_fullscreen;

        p_vout->p_sys->b_cursor_autohidden = 0;
        SDL_ShowCursor( p_vout->p_sys->b_cursor &&
                        ! p_vout->p_sys->b_cursor_autohidden );

        p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
        p_vout->i_changes |= VOUT_SIZE_CHANGE;
    }

    /*
     * Size change
     */
    if( p_vout->i_changes & VOUT_SIZE_CHANGE )
    {
        msg_Dbg( p_vout, "video display resized (%dx%d)",
                 p_vout->p_sys->i_width, p_vout->p_sys->i_height );

        CloseDisplay( p_vout );
        OpenDisplay( p_vout );

        /* We don't need to signal the vout thread about the size change if
         * we can handle rescaling ourselves */
        if( p_vout->p_sys->p_overlay != NULL )
            p_vout->i_changes &= ~VOUT_SIZE_CHANGE;

    }

    /* Pointer change */
    if( ! p_vout->p_sys->b_cursor_autohidden &&
        ( mdate() - p_vout->p_sys->i_lastmoved > 2000000 ) )
    {
        /* Hide the mouse automatically */
        p_vout->p_sys->b_cursor_autohidden = 1;
        SDL_ShowCursor( 0 );
    }

    return VLC_SUCCESS;
}
示例#30
0
void DestroyEditor( PEDITOR pe )
{
	DestroyTransform( pe->TView );
	CloseDisplay( pe->hVideo );
	Release( pe );
}