void tst_QMediaPlaylistNavigator::testSurroundingItemsChangedSignal() { QMediaNetworkPlaylistProvider playlist; QMediaPlaylistNavigator navigator(&playlist); navigator.setPlaybackMode(QMediaPlaylist::Random); QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Random); QCOMPARE(navigator.currentIndex(), -1); //Creating a QSignalSpy object for surroundingItemsChanged()signal QSignalSpy spy(&navigator,SIGNAL(surroundingItemsChanged())); QVERIFY(spy.count() == 0); //Adding the media to the playlist playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///1")))); QVERIFY(spy.count() == 1); //set the play back mode to sequential navigator.setPlaybackMode(QMediaPlaylist::Sequential); QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Sequential); QVERIFY(spy.count() == 2); //Point to the next index navigator.next(); QVERIFY(spy.count() == 3); }
void tst_QMediaPlaylistNavigator::testActivatedSignal() { QMediaNetworkPlaylistProvider playlist; QMediaPlaylistNavigator navigator(&playlist); navigator.setPlaybackMode(QMediaPlaylist::Random); QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Random); QCOMPARE(navigator.currentIndex(), -1); //Creating a QSignalSpy object for surroundingItemsChanged()signal QSignalSpy spy(&navigator,SIGNAL(activated(QMediaContent))); QVERIFY(spy.count() == 0); //Adding the media to the playlist playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///1")))); playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///2")))); playlist.shuffle(); //Point to the next index navigator.next(); QVERIFY(spy.count() == 1); //Jump to 0th item navigator.jump(0); QVERIFY(spy.count() == 2); //move to previous item navigator.previous(); QVERIFY(spy.count() == 3); }
void tst_QMediaPlaylistNavigator::testPreviousIndex() { QMediaNetworkPlaylistProvider playlist; QMediaPlaylistNavigator navigator(&playlist); navigator.setPlaybackMode(QMediaPlaylist::Random); QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Random); QCOMPARE(navigator.currentIndex(), -1); //Adding the media to the playlist playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///1")))); playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///2")))); playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///3")))); playlist.shuffle(); //Currently it is not pointing to any index QCOMPARE(navigator.currentIndex(), -1); //pointing to next index navigator.next(); int pos1 = navigator.currentIndex(); navigator.next(); int pos2 = navigator.currentIndex(); navigator.next(); int pos3 = navigator.currentIndex(); QCOMPARE(navigator.previousIndex(1), pos2); QCOMPARE(navigator.previousIndex(2), pos1); navigator.next(); QCOMPARE(navigator.previousIndex(1), pos3); }
void tst_QMediaPlaylistNavigator::testCurrentIndexChangedSignal() { QMediaNetworkPlaylistProvider playlist; QMediaPlaylistNavigator navigator(&playlist); navigator.setPlaybackMode(QMediaPlaylist::Random); QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Random); QCOMPARE(navigator.currentIndex(), -1); //Creating a QSignalSpy object for currentIndexChanged() signal QSignalSpy spy(&navigator,SIGNAL(currentIndexChanged(int))); QVERIFY(spy.count() == 0); //Adding the media to the playlist playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///1")))); playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///2")))); playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///3")))); //Currently it is not pointing to any index QCOMPARE(navigator.currentIndex(), -1); navigator.next(); QVERIFY(spy.count() == 1); int pos1 = navigator.currentIndex(); //Pointing to the next index navigator.next(); QVERIFY(navigator.previousIndex(1) == pos1); QVERIFY(spy.count() == 2); }
void tst_QMediaPlaylistNavigator::currentItemInLoop() { QMediaNetworkPlaylistProvider playlist; QMediaPlaylistNavigator navigator(&playlist); navigator.setPlaybackMode(QMediaPlaylist::CurrentItemInLoop); QCOMPARE(navigator.playbackMode(), QMediaPlaylist::CurrentItemInLoop); QCOMPARE(navigator.currentIndex(), -1); playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///1")))); playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///2")))); playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///3")))); QCOMPARE(navigator.currentIndex(), -1); navigator.next(); QCOMPARE(navigator.currentIndex(), -1); navigator.jump(1); navigator.next(); QCOMPARE(navigator.currentIndex(), 1); navigator.next(); QCOMPARE(navigator.currentIndex(), 1); navigator.previous(); QCOMPARE(navigator.currentIndex(), 1); navigator.previous(); QCOMPARE(navigator.currentIndex(), 1); }
//! [0] int main(int argc, char *argv[]) { QApplication app(argc, argv); Q_INIT_RESOURCE(padnavigator); PadNavigator navigator(QSize(3, 3)); navigator.show(); return app.exec(); }
void tst_QMediaPlaylistNavigator::construction() { QMediaNetworkPlaylistProvider playlist; QCOMPARE(playlist.mediaCount(), 0); QMediaPlaylistNavigator navigator(&playlist); QVERIFY(navigator.currentItem().isNull()); QCOMPARE(navigator.currentIndex(), -1); }
int main(int argc,char** argv) { ros::init(argc,argv,"pick_place_demo_node"); ros::NodeHandle nh; ROS_INFO_STREAM(ros::this_node::getName()<<": Creating navigator"); RobotPickPlaceNavigator navigator(RobotPickPlaceNavigator::SETUP_SPHERE_PICK_PLACE); ROS_INFO_STREAM(ros::this_node::getName()<<": Navigator started"); navigator.run(); return 0; }
int main(int argc,char** argv) { ros::init(argc,argv,"automated_pick_place_node"); ros::NodeHandle nh; ROS_INFO_STREAM(ros::this_node::getName()<<": Creating navigator"); RobotNavigator::Ptr navigator(new AutomatedPickerRobotNavigator()); ROS_INFO_STREAM(ros::this_node::getName()<<": Navigator started"); navigator->run(); return 0; }
void tst_QMediaPlaylistNavigator::linearPlayback() { QMediaNetworkPlaylistProvider playlist; QMediaPlaylistNavigator navigator(&playlist); navigator.setPlaybackMode(QMediaPlaylist::Sequential); navigator.jump(0); QVERIFY(navigator.currentItem().isNull()); QCOMPARE(navigator.currentIndex(), -1); QMediaContent content1(QUrl(QLatin1String("file:///1"))); playlist.addMedia(content1); navigator.jump(0); QVERIFY(!navigator.currentItem().isNull()); QCOMPARE(navigator.currentIndex(), 0); QCOMPARE(navigator.currentItem(), content1); QCOMPARE(navigator.nextItem(), QMediaContent()); QCOMPARE(navigator.nextItem(2), QMediaContent()); QCOMPARE(navigator.previousItem(), QMediaContent()); QCOMPARE(navigator.previousItem(2), QMediaContent()); QMediaContent content2(QUrl(QLatin1String("file:///2"))); playlist.addMedia(content2); QCOMPARE(navigator.currentIndex(), 0); QCOMPARE(navigator.currentItem(), content1); QCOMPARE(navigator.nextItem(), content2); QCOMPARE(navigator.nextItem(2), QMediaContent()); QCOMPARE(navigator.previousItem(), QMediaContent()); QCOMPARE(navigator.previousItem(2), QMediaContent()); navigator.jump(1); QCOMPARE(navigator.currentIndex(), 1); QCOMPARE(navigator.currentItem(), content2); QCOMPARE(navigator.nextItem(), QMediaContent()); QCOMPARE(navigator.nextItem(2), QMediaContent()); QCOMPARE(navigator.previousItem(), content1); QCOMPARE(navigator.previousItem(2), QMediaContent()); navigator.jump(0); navigator.next(); QCOMPARE(navigator.currentIndex(), 1); navigator.next(); QCOMPARE(navigator.currentIndex(), -1); navigator.next();//jump to the first item QCOMPARE(navigator.currentIndex(), 0); navigator.previous(); QCOMPARE(navigator.currentIndex(), -1); navigator.previous();//jump to the last item QCOMPARE(navigator.currentIndex(), 1); }
//! [0] int main(int argc, char *argv[]) { QApplication app(argc, argv); Q_INIT_RESOURCE(padnavigator); PadNavigator navigator(QSize(3, 3)); #if defined(Q_OS_SYMBIAN) navigator.showMaximized(); #else navigator.show(); #endif return app.exec(); }
void tst_QMediaPlaylistNavigator::randomPlayback() { QMediaNetworkPlaylistProvider playlist; QMediaPlaylistNavigator navigator(&playlist); navigator.setPlaybackMode(QMediaPlaylist::Random); QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Random); QCOMPARE(navigator.currentIndex(), -1); playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///1")))); playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///2")))); playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///3")))); playlist.shuffle(); QCOMPARE(navigator.currentIndex(), -1); navigator.next(); int pos1 = navigator.currentIndex(); navigator.next(); int pos2 = navigator.currentIndex(); navigator.next(); int pos3 = navigator.currentIndex(); QVERIFY(pos1 != -1); QVERIFY(pos2 != -1); QVERIFY(pos3 != -1); navigator.previous(); QCOMPARE(navigator.currentIndex(), pos2); navigator.next(); QCOMPARE(navigator.currentIndex(), pos3); navigator.next(); int pos4 = navigator.currentIndex(); navigator.previous(); QCOMPARE(navigator.currentIndex(), pos3); navigator.previous(); QCOMPARE(navigator.currentIndex(), pos2); navigator.previous(); QCOMPARE(navigator.currentIndex(), pos1); navigator.previous(); int pos0 = navigator.currentIndex(); QVERIFY(pos0 != -1); navigator.next(); navigator.next(); navigator.next(); navigator.next(); QCOMPARE(navigator.currentIndex(), pos4); }
void tst_QMediaPlaylistNavigator::loopPlayback() { QMediaNetworkPlaylistProvider playlist; QMediaPlaylistNavigator navigator(&playlist); navigator.setPlaybackMode(QMediaPlaylist::Loop); navigator.jump(0); QVERIFY(navigator.currentItem().isNull()); QCOMPARE(navigator.currentIndex(), -1); QMediaContent content1(QUrl(QLatin1String("file:///1"))); playlist.addMedia(content1); navigator.jump(0); QVERIFY(!navigator.currentItem().isNull()); QCOMPARE(navigator.currentIndex(), 0); QCOMPARE(navigator.currentItem(), content1); QCOMPARE(navigator.nextItem(), content1); QCOMPARE(navigator.nextItem(2), content1); QCOMPARE(navigator.previousItem(), content1); QCOMPARE(navigator.previousItem(2), content1); QMediaContent content2(QUrl(QLatin1String("file:///2"))); playlist.addMedia(content2); QCOMPARE(navigator.currentIndex(), 0); QCOMPARE(navigator.currentItem(), content1); QCOMPARE(navigator.nextItem(), content2); QCOMPARE(navigator.nextItem(2), content1); //loop over end of the list QCOMPARE(navigator.previousItem(), content2); QCOMPARE(navigator.previousItem(2), content1); navigator.jump(1); QCOMPARE(navigator.currentIndex(), 1); QCOMPARE(navigator.currentItem(), content2); QCOMPARE(navigator.nextItem(), content1); QCOMPARE(navigator.nextItem(2), content2); QCOMPARE(navigator.previousItem(), content1); QCOMPARE(navigator.previousItem(2), content2); navigator.jump(0); navigator.next(); QCOMPARE(navigator.currentIndex(), 1); navigator.next(); QCOMPARE(navigator.currentIndex(), 0); navigator.previous(); QCOMPARE(navigator.currentIndex(), 1); navigator.previous(); QCOMPARE(navigator.currentIndex(), 0); }
void tst_QMediaPlaylistNavigator::setPlaylist() { QMediaPlaylistNavigator navigator(0); QVERIFY(navigator.playlist() != 0); QCOMPARE(navigator.playlist()->mediaCount(), 0); QCOMPARE(navigator.playlist()->media(0), QMediaContent()); QVERIFY(navigator.playlist()->isReadOnly() ); QMediaNetworkPlaylistProvider playlist; QCOMPARE(playlist.mediaCount(), 0); navigator.setPlaylist(&playlist); QCOMPARE(navigator.playlist(), (QMediaPlaylistProvider*)&playlist); QCOMPARE(navigator.playlist()->mediaCount(), 0); QVERIFY(!navigator.playlist()->isReadOnly() ); }
void tst_QMediaPlaylistNavigator::testItemAt() { QMediaNetworkPlaylistProvider playlist; QMediaPlaylistNavigator navigator(&playlist); navigator.setPlaybackMode(QMediaPlaylist::Random); QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Random); QCOMPARE(navigator.currentIndex(), -1); //Adding the media to the playlist QMediaContent content = QMediaContent(QUrl(QLatin1String("file:///1"))); playlist.addMedia(content); //Currently it is not pointing to any index , Returns Null mediacontent QCOMPARE(navigator.currentIndex(), -1); QCOMPARE(navigator.itemAt(navigator.currentIndex()),QMediaContent()); navigator.next(); //Points to the added media int pos1 = navigator.currentIndex(); QCOMPARE(content,navigator.itemAt(pos1)); }
void CKJVPassageNavigator::CalcPassage() { assert(!m_pBibleDatabase.isNull()); m_tagPassage.relIndex() = m_pBibleDatabase->calcRelIndex(m_nWord, m_nVerse, m_nChapter, m_nBook, (!m_tagStartRef.relIndex().isSet() ? m_nTestament : 0), m_tagStartRef.relIndex(), (!m_tagStartRef.relIndex().isSet() ? false : ui.chkboxReverse->isChecked())); ui.editResolved->setText(m_pBibleDatabase->PassageReferenceText(passage().relIndex())); CPhraseEditNavigator navigator(m_pBibleDatabase, *m_pEditVersePreview); setDirectReference(m_tagPassage.relIndex()); CRelIndex ndxWord(m_tagPassage.relIndex()); CRelIndex ndxVerse(ndxWord); ndxVerse.setWord(0); CRelIndex ndxChapter(ndxVerse); ndxChapter.setVerse(0); CRelIndex ndxBook(ndxChapter); ndxBook.setChapter(0); QTextCursor txtCursor; switch (m_nRefType) { case NRTE_WORD: navigator.setDocumentToVerse(ndxWord, defaultDocumentToVerseFlags | CPhraseNavigator::TRO_ScriptureBrowser); navigator.doHighlighting(CSearchResultHighlighter(m_tagPassage)); break; case NRTE_VERSE: navigator.setDocumentToVerse(ndxVerse, defaultDocumentToVerseFlags | CPhraseNavigator::TRO_ScriptureBrowser); break; case NRTE_CHAPTER: navigator.setDocumentToChapter(ndxChapter, CPhraseNavigator::TRO_Colophons | CPhraseNavigator::TRO_Superscriptions | CPhraseNavigator::TRO_Subtitles | CPhraseNavigator::TRO_Category | CPhraseNavigator::TRO_SuppressPrePostChapters | CPhraseNavigator::TRO_ScriptureBrowser); txtCursor = m_pEditVersePreview->textCursor(); txtCursor.movePosition(QTextCursor::Start); m_pEditVersePreview->setTextCursor(txtCursor); break; case NRTE_BOOK: navigator.setDocumentToBookInfo(ndxBook, defaultDocumentToBookInfoFlags | CPhraseNavigator::TRO_ScriptureBrowser); break; } }
/** * Main loop. */ int main(void) { int32_t lastSpeedCalc = 0; int32_t lastDebug = 0; int32_t lastDebug2 = 0; // initalize all modules initAll(); // enable interrupts (i.e timers start from here) sei(); // The LOOP while(1) { // read serial port readCommand(); // communication.c // apply speed calculation and run odometer if (uptime() >= lastSpeedCalc + SPEED_CALC_PERIOD) { lastSpeedCalc += SPEED_CALC_PERIOD; calculateSpeeds(); // motors.c if (pidOn) { runPID(); // motors.c } //if (debug1) printSpeed(CPUCHAR); runOdometer(); // odometer.c navigator(); } // read sensors and apply position correction positionCorrection(); // odometer.c // print debug loop 2 if (uptime() >= (lastDebug2 + 20)) { lastDebug2 = uptime(); if (debug6) printf("%d, %d\r\n", p_LsensVal, p_RsensVal); } // print debug if ((debugPeriod) && uptime() >= (lastDebug + debugPeriod)) { lastDebug += debugPeriod; //if (debug1) printf(">21%02x\r", speed0 >> 4); //if (debug1) printf(">21%04x\r>22%04x\r", readADC(0), readADC(1)); //if (debug2) printf("%ld\t%ld\r\n", timer, timer20); //if (debug2) printf_P(PSTR("%d\t%d\r\n"), p_L, p_R); if (debug3) printf_P(PSTR("%d, %d / %d, %d / %d, %d / %u, %u\r\n"), p_Ltrans, p_Lrel, p_Rtrans, p_Rrel, p_Lerr, p_Rerr, posCorrLeftFailed, posCorrRightFailed); //if (debug4) printf_P(PSTR("%ld\t%ld\r\n"), ticks0, ticks1); //if (debug5) printSpeed(CPUCHAR); //if (debug5) printf_P(PSTR("%d\t%d\r\n"), speed0, speed1); //if (debug6) printf_P(PSTR("%d\t%d\r\n"), accel0, accel1); if (debug7) printf_P(PSTR("%u\t%u\r\n"), power0, power1); // debug for GUI printTicks(CPUCHAR); printSpeed(CPUCHAR); printAccel(CPUCHAR); printAbsDist(CPUCHAR); printRelDist(CPUCHAR); printSensors(CPUCHAR); } } while(1); }
bool ViewNavigationDelegate::JumpToNearestElement(EA::WebKit::JumpDirection direction, bool scrollIfElementNotFound) { // Note by Arpit Baldeva: // We have a problem here. mpModalInputClient object is supposed to be used for Modal input only however the only class using this object // is html SELECT element(implemented as a popup). But in reality, html SELECT element is NOT modal. So it is little ill-conceived. // For example, in all the browsers, if you scroll the mouse wheel on the frame, the SELECT element disappears and the actual frame scrolls. // For any modal input needs on a web page, the users are advised to use the Z-layer technique with Javascript/CSS - http://jqueryui.com/demos/dialog/#modal-confirmation. // The problem we want to solve here is have the SELECT element respond to the controller input correctly(select element one by one). // But the button event information is lost by the time we are in the EA::WebKit::View. For the foreseeable future, there is no candidate // other than html SELECT element which is implemented as a modal popup inside EAWebKit. So inside EA::WebKit::View, we create a dummy // button event from the Jump direction and make SELECT respond to it. If any other object starts using the modal input, this would need to be // revisited. But then, we'll need to solve a plethora of issues. So we do minimum work here to not break other things. IOverlayInputClient* pOverlayInputClient = mView->GetOverlayInputClient(); bool handledByOverlayInputClient = false; if(pOverlayInputClient) { EA::WebKit::ButtonEvent btnEvent; switch(direction) { /* case EA::WebKit::JumpLeft: { btnEvent.mID = EA::WebKit::kButton0; handledByOverlayInputClient = pOverlayInputClient->OnButtonEvent(btnEvent); } */ case EA::WebKit::JumpUp: { btnEvent.mID = EA::WebKit::kButton1; handledByOverlayInputClient = pOverlayInputClient->OnButtonEvent(btnEvent); break; } /* case EA::WebKit::JumpRight: { btnEvent.mID = EA::WebKit::kButton2; handledByOverlayInputClient = pOverlayInputClient->OnButtonEvent(btnEvent); } */ case EA::WebKit::JumpDown: { btnEvent.mID = EA::WebKit::kButton3; handledByOverlayInputClient = pOverlayInputClient->OnButtonEvent(btnEvent); break; } default: // We don't return and allow any other button press to go to the main View. At the same time, we make the SELECT element lose focus. { pOverlayInputClient->OnFocusChangeEvent(false); break; } } } if(handledByOverlayInputClient) return true; int lastX, lastY; mView->GetCursorPosition(lastX, lastY); // Following is a shortcut to drive navigation from a page. switch (direction) { case EA::WebKit::JumpRight: if (GetFixedString(mCachedNavigationRightId)->compare("")) { if (!GetFixedString(mCachedNavigationRightId)->compare("ignore")) { return false; } if (JumpToId(GetFixedString(mCachedNavigationRightId)->c_str())) { return true; } } break; case EA::WebKit::JumpDown: if (GetFixedString(mCachedNavigationDownId)->compare("")) { if (!GetFixedString(mCachedNavigationDownId)->compare("ignore")) { return false; } if (JumpToId(GetFixedString(mCachedNavigationDownId)->c_str())) { return true; } } break; case EA::WebKit::JumpLeft: if (GetFixedString(mCachedNavigationLeftId)->compare("")) { if (!GetFixedString(mCachedNavigationLeftId)->compare("ignore")) { return false; } if (JumpToId(GetFixedString(mCachedNavigationLeftId)->c_str())) { return true; } } break; case EA::WebKit::JumpUp: if (GetFixedString(mCachedNavigationUpId)->compare("")) { if (!GetFixedString(mCachedNavigationUpId)->compare("ignore")) { return false; } if (JumpToId(GetFixedString(mCachedNavigationUpId)->c_str())) { return true; } } break; default: EAW_FAIL_MSG("Should not have got here\n"); } // Iterate over all the frames and find the closest element in any of all the frames. WebCore::Frame* pFrame = mView->GetFrame(); float currentRadialDistance = FLT_MAX; // A high value to start with so that the max distance between any two elements in the surface is under it. WebCore::Node* currentBestNode = NULL; while(pFrame) { WebCore::Document* document = pFrame->document(); EAW_ASSERT(document); if(document) { WebCore::FrameView* pFrameView = document->view(); WebCore::IntPoint scrollOffset; if(pFrameView) { scrollOffset.setX(pFrameView->scrollOffset().width()); scrollOffset.setY(pFrameView->scrollOffset().height()); } // We figure out the start position(It is center of the currently hovered element almost all the time but can be slightly different // due to scroll sometimes). mCentreX = lastX + scrollOffset.x(); mCentreY = lastY + scrollOffset.y(); DocumentNavigator navigator(mView, document, direction, WebCore::IntPoint(mCentreX, mCentreY), mBestNodeX, mBestNodeY, mBestNodeWidth, mBestNodeHeight, mJumpNavigationParams.mNavigationTheta, mJumpNavigationParams.mStrictAxesCheck, currentRadialDistance); navigator.FindBestNode(document); if(navigator.GetBestNode()) { currentBestNode = navigator.GetBestNode(); currentRadialDistance = navigator.GetBestNodeRadialDistance(); } } pFrame = pFrame->tree()->traverseNext(); } bool foundSomething = false; if (currentBestNode) //We found the node to navigate. Move the cursor and we are done. { foundSomething = true; MoveMouseCursorToNode(currentBestNode, false); } else if(scrollIfElementNotFound)// Node is not found. { // Based on the intended direction of movement, scroll so that some newer elements are visible. int cursorPosBeforeScrollX, cursorPosBeforeScrollY; mView->GetCursorPosition(cursorPosBeforeScrollX, cursorPosBeforeScrollY); switch(direction) { case EA::WebKit::JumpDown: { ScrollOnJump(true, -120, mJumpNavigationParams.mNumLinesToAutoScroll); break; } case EA::WebKit::JumpUp: { ScrollOnJump(true, 120, mJumpNavigationParams.mNumLinesToAutoScroll); break; } case EA::WebKit::JumpRight: { ScrollOnJump(false, -120, mJumpNavigationParams.mNumLinesToAutoScroll); break; } case EA::WebKit::JumpLeft: { ScrollOnJump(false, 120, mJumpNavigationParams.mNumLinesToAutoScroll); break; } default: { EAW_ASSERT_MSG(false, "Should not reach here\n"); } } // We move the mouse cursor back to the location where the last best node was found. This is so that we don't end up with the cursor being in no man's land. While that may work // for ordinary sites, it may not work well with customized pages that leverage CSS to visually indicate current position rather than a cursor graphic. // We don't call MoveMouseCursorToNode() with last cached node as there are edge cases where we may be holding an invalid node. Using a cached frame and checking against the // current valid frames safeguards against that. WebCore::IntSize scrollOffset; WebCore::Frame* pFrame1 = mView->GetFrame(); while(pFrame1) { if(pFrame1 == mBestNodeFrame)//Find the frame where last best node existed. { if(pFrame1->view()) { scrollOffset = pFrame1->view()->scrollOffset();//We read scroll offset here as it could have changed in the switch statement above. break; } } pFrame1 = pFrame1->tree()->traverseNext(); } int targetcursorPosAfterScrollX, targetcursorPosAfterScrollY; targetcursorPosAfterScrollX = mBestNodeX + mBestNodeWidth / 2 - scrollOffset.width(); targetcursorPosAfterScrollY = mBestNodeY + mBestNodeHeight/ 2 - scrollOffset.height(); EA::WebKit::MouseMoveEvent moveEvent; memset( &moveEvent, 0, sizeof(moveEvent) ); const int cursorInset = 5;// Make cursor stay inside 5 pixels from boundaries. No known issues but added this as a safety measure so that we do not lose cursor ever. int width = mView->GetSize().mWidth; int height = mView->GetSize().mHeight; moveEvent.mX = Clamp( cursorInset, targetcursorPosAfterScrollX, width - cursorInset ); moveEvent.mY = Clamp( cursorInset, targetcursorPosAfterScrollY, height - cursorInset ); mView->OnMouseMoveEvent(moveEvent); // We intentionally don't call JumpToNearestElement(direction, false) here to avoid recursion. We do it in the overloaded function above. } return foundSomething; }
int main(int argc, char** argv) { try { int cudaDevice; std::string lsystemFile; int screenWidth; int screenHeight; CmdOptions cmdOptions(argc, argv); cmdOptions.read("device", cudaDevice, 0); cmdOptions.read<std::string>("lsystemFile", lsystemFile, ""); cmdOptions.read("screenWidth", screenWidth, DEFAULT_SCREEN_WIDTH); cmdOptions.read("screenHeight", screenHeight, DEFAULT_SCREEN_HEIGHT); if (lsystemFile == "") { printUsage(); exit(EXIT_FAILURE); } Framework::GLWindow window("LSystem", screenWidth, screenHeight, true, false); if (gl3wInit()) { throw std::runtime_error("gl3wInit() failed"); } cudaDeviceProp deviceProperties; cudaGetDeviceProperties(&deviceProperties, cudaDevice); cudaSetDevice(cudaDevice); LSystem lsystem(lsystemFile); /********************************/ /* CENTER L-SYSTEM ON SCREEN */ /********************************/ float width = lsystem.getBounds().extents().x; float height = lsystem.getBounds().extents().y; float screenDiagonal = sqrt(pow(width, 2) + pow(height, 2) + 1); float distance = min((screenDiagonal / 2.0f) / tan(HALF_FOV_RAD), ZFAR); float aspectRatio = screenWidth / (float)screenHeight; math::float3 cameraCenter(lsystem.getBounds().center().x, lsystem.getBounds().center().y, -distance); math::float3 cameraForward = cameraCenter + math::float3(0, 0, -1); math::float3 cameraUp(0, 1, 0); ////////////////////////////////////////////////////////////////////////// SimpleCamera camera(FOV_RAD, aspectRatio, ZNEAR, ZFAR, cameraCenter, cameraForward, cameraUp); LSystemRenderer renderer(window, lsystem, camera); window.attach(&renderer); FirstPersonCameraNavigator navigator(&camera); LSystemInputHandler inputHandler(renderer, navigator); window.attach(static_cast<Framework::MouseInputHandler*>(&inputHandler)); window.attach(static_cast<Framework::KeyboardInputHandler*>(&inputHandler)); Framework::run(renderer, &inputHandler); return 0; } catch (std::exception& e) { std::cout << "Error: " << e.what() << std::endl; } catch (...) { std::cout << "Unknown error" << std::endl; } // DEBUG: system("pause"); return -1; }
int main(int argc, char** argv) { try { int cudaDevice; int treeDepth; int screenWidth; int screenHeight; CmdOptions cmdOptions(argc, argv); cmdOptions.read("device", cudaDevice, 0); cmdOptions.read("treeDepth", treeDepth, 0); cmdOptions.read("screenWidth", screenWidth, DEFAULT_SCREEN_WIDTH); cmdOptions.read("screenHeight", screenHeight, DEFAULT_SCREEN_HEIGHT); if (treeDepth < 1) { printUsage(); exit(EXIT_FAILURE); } Framework::GLWindow window("SimpleWorkQueue", screenWidth, screenHeight, true, false); if (gl3wInit()) { throw std::runtime_error("gl3wInit() failed"); } cudaDeviceProp deviceProperties; cudaGetDeviceProperties(&deviceProperties, cudaDevice); cudaSetDevice(cudaDevice); Tree tree; tree.setDepth((unsigned int)treeDepth); SimpleCamera camera(FOV_RAD, screenWidth / (float)screenHeight, ZNEAR, ZFAR); TreeRenderer renderer(window, camera, tree); window.attach(&renderer); FirstPersonCameraNavigator navigator(&camera); centerTreeOnCamera(navigator, tree); InputHandler inputHandler(renderer, navigator, camera, tree); window.attach(static_cast<Framework::MouseInputHandler*>(&inputHandler)); window.attach(static_cast<Framework::KeyboardInputHandler*>(&inputHandler)); Framework::run(renderer, &inputHandler); return 0; } catch (std::exception& e) { std::cout << "Error: " << e.what() << std::endl; } catch (...) { std::cout << "Unknown error" << std::endl; } // DEBUG: system("pause"); return -1; }