/*! Wait for a click from one of the mouse button and get the position of the clicked image point. \param ip [out] : The coordinates of the clicked image point. \param blocking [in] : true for a blocking behaviour waiting a mouse button click, false for a non blocking behaviour. \return - true if a button was clicked. This is always the case if blocking is set to \e true. - false if no button was clicked. This can occur if blocking is set to \e false. */ bool vpDisplayGTK::getClick(vpImagePoint &ip, bool blocking) { bool ret = false; if (displayHasBeenInitialized) { double u, v ; do { GdkEvent *ev = NULL; while ((ev = gdk_event_get())!=NULL){ if (ev->any.window == widget->window && ev->type == GDK_BUTTON_PRESS) { u = ((GdkEventButton *)ev)->x ; v = ((GdkEventButton *)ev)->y ; ip.set_u( u ); ip.set_v( v ); ret = true ; } gdk_event_free(ev) ; } if (blocking){ flushDisplay(); vpTime::wait(100); } } while ( ret == false && blocking == true); } else { vpERROR_TRACE("GTK not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "GTK not initialized")) ; } return ret ; }
MockClient::MockClient() : display(wl_display_connect(0)) , compositor(0) , output(0) , registry(0) { if (!display) qFatal("MockClient(): wl_display_connect() failed"); registry = wl_display_get_registry(display); wl_registry_add_listener(registry, ®istryListener, this); fd = wl_display_get_fd(display); QSocketNotifier *readNotifier = new QSocketNotifier(fd, QSocketNotifier::Read, this); connect(readNotifier, SIGNAL(activated(int)), this, SLOT(readEvents())); QAbstractEventDispatcher *dispatcher = QGuiApplicationPrivate::eventDispatcher; connect(dispatcher, SIGNAL(awake()), this, SLOT(flushDisplay())); QElapsedTimer timeout; timeout.start(); do { QCoreApplication::processEvents(); } while (!(compositor && output) && timeout.elapsed() < 1000); if (!compositor || !output) qFatal("MockClient(): failed to receive globals from display"); }
/*! Wait for a click from one of the mouse button. \param blocking [in] : Blocking behavior. - When set to true, this method waits until a mouse button is pressed and then returns always true. - When set to false, returns true only if a mouse button is pressed, otherwise returns false. \return - true if a button was clicked. This is always the case if blocking is set to \e true. - false if no button was clicked. This can occur if blocking is set to \e false. */ bool vpDisplayGTK::getClick(bool blocking) { bool ret = false; if (displayHasBeenInitialized) { // flushDisplay() ; //int cpt =0; do { GdkEvent *ev = NULL; while ((ev = gdk_event_get())!=NULL){ //cpt++; // printf("event %d type %d on window %p My window %p\n", //cpt, ev->type, ev->any.window, widget->window); if (ev->any.window == widget->window && ev->type == GDK_BUTTON_PRESS){ ret = true ; //printf("Click detection\n"); } gdk_event_free(ev) ; } if (blocking){ flushDisplay(); vpTime::wait(100); } } while ( ret == false && blocking == true); } else { vpERROR_TRACE("GTK not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "GTK not initialized")) ; } return ret; }
/*! Get a keyboard event. \param blocking [in] : Blocking behavior. - When set to true, this method waits until a key is pressed and then returns always true. - When set to false, returns true only if a key is pressed, otherwise returns false. \param string [out]: If possible, an ISO Latin-1 character corresponding to the keyboard key. \return - true if a key was pressed. This is always the case if blocking is set to \e true. - false if no key was pressed. This can occur if blocking is set to \e false. */ bool vpDisplayOpenCV::getKeyboardEvent(char *string, bool blocking) { int key_pressed; int delay; if (displayHasBeenInitialized) { flushDisplay() ; if (blocking) delay = 0; else delay = 10; key_pressed = cvWaitKey(delay); if (key_pressed == -1) return false; else { //std::cout << "Key pressed: \"" << key_pressed << "\"" << std::endl; sprintf(string, "%c", key_pressed); } return true; } else { vpERROR_TRACE("OpenCV not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized")) ; } //return false; // Never reached after throw() }
/*! Wait for a click from one of the mouse button. \param blocking [in] : Blocking behavior. - When set to true, this method waits until a mouse button is pressed and then returns always true. - When set to false, returns true only if a mouse button is pressed, otherwise returns false. \return - true if a button was clicked. This is always the case if blocking is set to \e true. - false if no button was clicked. This can occur if blocking is set to \e false. */ bool vpDisplayOpenCV::getClick(bool blocking) { bool ret = false; if (displayHasBeenInitialized) { flushDisplay() ; if (blocking){ lbuttondown = false; mbuttondown = false; rbuttondown = false; } do { if (lbuttondown){ ret = true ; lbuttondown = false; } if (mbuttondown){ ret = true ; mbuttondown = false; } if (rbuttondown){ ret = true ; rbuttondown = false; } if (blocking) cvWaitKey(10); } while ( ret == false && blocking == true); } else { vpERROR_TRACE("OpenCV not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized")) ; } return ret; }
/*! Wait for a click from one of the mouse button and get the position of the clicked image point. \param ip [out] : The coordinates of the clicked image point. \param blocking [in] : true for a blocking behaviour waiting a mouse button click, false for a non blocking behaviour. \return - true if a button was clicked. This is always the case if blocking is set to \e true. - false if no button was clicked. This can occur if blocking is set to \e false. */ bool vpDisplayOpenCV::getClick(vpImagePoint &ip, bool blocking) { bool ret = false; if (displayHasBeenInitialized) { flushDisplay() ; double u, v; if (blocking){ lbuttondown = false; mbuttondown = false; rbuttondown = false; } do { if (lbuttondown){ ret = true ; u = (unsigned int)x_lbuttondown; v = (unsigned int)y_lbuttondown; ip.set_u( u ); ip.set_v( v ); lbuttondown = false; } if (mbuttondown){ ret = true ; u = (unsigned int)x_mbuttondown; v = (unsigned int)y_mbuttondown; ip.set_u( u ); ip.set_v( v ); mbuttondown = false; } if (rbuttondown){ ret = true ; u = (unsigned int)x_rbuttondown; v = (unsigned int)y_rbuttondown; ip.set_u( u ); ip.set_v( v ); rbuttondown = false; } if (blocking) cvWaitKey(10); } while ( ret == false && blocking == true); } else { vpERROR_TRACE("OpenCV not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized")) ; } return ret ; }
/*! Wait for a mouse button click release and get the position of the image point were the click release occurs. The button used to click is also set. Same method as getClick(unsigned int&, unsigned int&, vpMouseButton::vpMouseButtonType &, bool). \param ip [out] : Position of the clicked image point. \param button [in] : Button used to click. \param blocking [in] : true for a blocking behaviour waiting a mouse button click, false for a non blocking behaviour. \return - true if a button was clicked. This is always the case if blocking is set to \e true. - false if no button was clicked. This can occur if blocking is set to \e false. \sa getClick(vpImagePoint &, vpMouseButton::vpMouseButtonType &, bool) */ bool vpDisplayGTK::getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType& button, bool blocking) { bool ret = false; if ( displayHasBeenInitialized ) { //flushDisplay() ; double u, v ; do { GdkEvent *ev = NULL; while ((ev = gdk_event_get())!=NULL){ if ( ev->any.window == widget->window && ev->type == GDK_BUTTON_RELEASE) { u = ((GdkEventButton *)ev)->x ; v = ((GdkEventButton *)ev)->y ; ip.set_u( u ); ip.set_v( v ); switch ( ( int ) ( ( GdkEventButton * ) ev )->button ) { case 1: button = vpMouseButton::button1; break; case 2: button = vpMouseButton::button2; break; case 3: button = vpMouseButton::button3; break; } ret = true ; } gdk_event_free(ev) ; } if (blocking){ flushDisplay(); vpTime::wait(100); } } while ( ret == false && blocking == true); } else { vpERROR_TRACE ( "GTK not initialized " ) ; throw ( vpDisplayException ( vpDisplayException::notInitializedError, "GTK not initialized" ) ) ; } return ret; }
/*! Get a keyboard event. \param blocking [in] : Blocking behavior. - When set to true, this method waits until a key is pressed and then returns always true. - When set to false, returns true only if a key is pressed, otherwise returns false. \return - true if a key was pressed. This is always the case if blocking is set to \e true. - false if no key was pressed. This can occur if blocking is set to \e false. */ bool vpDisplayOpenCV::getKeyboardEvent(bool blocking) { int key_pressed; int delay; if (displayHasBeenInitialized) { flushDisplay() ; if (blocking) delay = 0; else delay = 10; key_pressed = cvWaitKey(delay); if (key_pressed == -1) return false; return true; } else { vpERROR_TRACE("OpenCV not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized")) ; } //return false; // Never reached after throw() }
void drawGrid(CONTEXT context) { flushDisplay(); contextNewPass(context); //Draw the top of the display uint offset = LENGTH_BORDER + LENGTH_NODE / 2 - WIDTH_ROAD_EXTERNAL / 2, internalSpace = WIDTH_ROAD_EXTERNAL; for(byte i = 0; i < NB_SLOTS_BORDER - 1; ++i) { printSpace(offset); printWideVerticalRoad(context, "\u2551"); contextJumpNewLine(context); putc('\n', stdout); } offset -= 2 * CAR_WIDTH + 1; //Add the line at the top of printSpace(offset); fputs(COLOR_BORDER "_____" , stdout); printWideVerticalRoad(context, "\u2569"); contextJumpNewLine(context); puts(COLOR_BORDER "_____" ); //Top horizontal line printSpace(--offset); fputs(COLOR_BORDER"/ ", stdout); printHorizontalRoad(context, 11, false); contextJumpNewLine(context); puts(COLOR_BORDER" \\"); //Empty space between the two top lines printSpace(--offset); printf(COLOR_BORDER"/"COLOR_CAR" %c "COLOR_SEPARATOR, getCarReadableGlyph(context)); printChar("\u2501\u2501\u2501", 6); printf(COLOR_CAR" %c "COLOR_BORDER"\\""\n", getCarReadableGlyph(context)); contextJumpNewLine(context); //Internal line printSpace(--offset); printf(COLOR_BORDER"/ "COLOR_CAR"%c "COLOR_SEPARATOR"/ ", getCarReadableGlyph(context)); printHorizontalRoad(context, 9, false); printf(COLOR_SEPARATOR" \\"COLOR_CAR" %c "COLOR_BORDER"\\\n", getCarReadableGlyph(context)); contextJumpNewLine(context); //First oblique portion printSpace(--offset); printOblique45Road(context); printChar(COLOR_BORDER"¯", --internalSpace); printOblique135Road(context); contextJumpNewLine(context); putc('\n', stdout); for(byte i = 0; i < 3; ++i) { printSpace(--offset); printOblique45Road(context); internalSpace += 2; printSpace(internalSpace); printOblique135Road(context); contextJumpNewLine(context); putc('\n', stdout); } printChar(COLOR_BORDER"_", --offset); printf(COLOR_BORDER"/"COLOR_CAR" %c "COLOR_SEPARATOR"\u2502"COLOR_CAR" %c "COLOR_BORDER"\u2502", getCarReadableGlyph(context), getCarReadableGlyph(context)); printSpace(internalSpace); printf(COLOR_BORDER"\u2502"COLOR_CAR" %c "COLOR_SEPARATOR"\u2502"COLOR_CAR" %c "COLOR_BORDER"\\", getCarReadableGlyph(context), getCarReadableGlyph(context)); printChar(COLOR_BORDER"_", offset); contextJumpNewLine(context); fputs("\n"COLOR_SEPARATOR, stdout); //Top two lines for(byte i = 0; i < 2; ++i) { printHorizontalRoad(context, NB_SLOTS_BORDER + 1, true); printf(COLOR_SEPARATOR" \u2502"COLOR_CAR" %c "COLOR_BORDER"\u2502", getCarReadableGlyph(context)); printSpace(internalSpace); printf("\u2502"COLOR_CAR" %c "COLOR_SEPARATOR"\u2502 ", getCarReadableGlyph(context)); printHorizontalRoad(context, NB_SLOTS_BORDER + 1, true); contextJumpNewLine(context); putc('\n', stdout); } //Separator fputs(COLOR_SEPARATOR, stdout); printChar("\u2550\u2550\u2550", offset / 3); printf("\u2563 "COLOR_CAR"%c "COLOR_SEPARATOR"\u2502"COLOR_CAR" %c "COLOR_BORDER"\u2502", getCarReadableGlyph(context), getCarReadableGlyph(context)); printSpace(internalSpace); printf(COLOR_BORDER"\u2502"COLOR_CAR" %c "COLOR_SEPARATOR"\u2502"COLOR_CAR" %c "COLOR_SEPARATOR"\u2560", getCarReadableGlyph(context), getCarReadableGlyph(context)); printChar("\u2550\u2550\u2550", offset / 3); contextJumpNewLine(context); putc('\n', stdout); //Last two lines for(byte i = 0; i < 2; ++i) { printHorizontalRoad(context, NB_SLOTS_BORDER + 1, true); printf(COLOR_SEPARATOR" \u2502"COLOR_CAR" %c "COLOR_BORDER"\u2502", getCarReadableGlyph(context)); printSpace(internalSpace); printf("\u2502"COLOR_CAR" %c "COLOR_SEPARATOR"\u2502 ", getCarReadableGlyph(context)); printHorizontalRoad(context, NB_SLOTS_BORDER + 1, true); contextJumpNewLine(context); putc('\n', stdout); } //Starting to close the area printChar(COLOR_BORDER"¯", offset); printf(COLOR_BORDER"\\"COLOR_CAR" %c "COLOR_SEPARATOR"\u2502"COLOR_CAR" %c "COLOR_BORDER"\u2502", getCarReadableGlyph(context), getCarReadableGlyph(context)); printSpace(internalSpace); printf(COLOR_BORDER"\u2502"COLOR_CAR" %c "COLOR_SEPARATOR"\u2502"COLOR_CAR" %c "COLOR_BORDER"/", getCarReadableGlyph(context), getCarReadableGlyph(context)); printChar(COLOR_BORDER"¯", offset); contextJumpNewLine(context); putc('\n', stdout); for(byte i = 0; i < 3; ++i) { printSpace(++offset); printOblique135Road(context); printSpace(internalSpace); internalSpace -= 2; printOblique45Road(context); contextJumpNewLine(context); putc('\n', stdout); } //Last oblique portion printSpace(++offset); printOblique135Road(context); printChar(COLOR_BORDER "_" , internalSpace++); printOblique45Road(context); contextJumpNewLine(context); putc('\n', stdout); //Internal line printSpace(++offset); printf(COLOR_BORDER"\\ "COLOR_CAR"%c "COLOR_SEPARATOR"\\ ", getCarReadableGlyph(context)); printHorizontalRoad(context, 9, false); printf(COLOR_SEPARATOR" /"COLOR_CAR" %c "COLOR_BORDER"/\n", getCarReadableGlyph(context)); contextJumpNewLine(context); //Empty space between the two top lines printSpace(++offset); printf(COLOR_BORDER"\\"COLOR_CAR" %c "COLOR_SEPARATOR, getCarReadableGlyph(context)); printChar("\u2501\u2501\u2501", 6); printf(COLOR_CAR" %c "COLOR_BORDER"/""\n", getCarReadableGlyph(context)); contextJumpNewLine(context); //Top horizontal line printSpace(++offset); fputs(COLOR_BORDER"\\ ", stdout); printHorizontalRoad(context, 11, false); contextJumpNewLine(context); puts(COLOR_BORDER" /"); //Add the line at the top of printSpace(++offset); fputs(COLOR_BORDER"¯¯¯¯¯", stdout); printWideVerticalRoad(context, "\u2566"); contextJumpNewLine(context); puts(COLOR_BORDER"¯¯¯¯¯"); offset += 2 * CAR_WIDTH + 1; for(byte i = 0; i < NB_SLOTS_BORDER - 1; ++i) { printSpace(offset); printWideVerticalRoad(context, "\u2551"); contextJumpNewLine(context); putc('\n', stdout); } }
wl_surface *MockClient::createSurface() { flushDisplay(); return wl_compositor_create_surface(compositor); }