Пример #1
0
void setMode() {
    if (ticker)
    {
        ticker->detach();
        ticker = NULL;
    }
    uBit.messageBus.ignore(MICROBIT_ID_GESTURE, MICROBIT_EVT_ANY, onGesture);

    switch(currentMode) {
        case ALWAYS_ON:
            uBit.display.print(lshift);
            uBit.display.setBrightness(255);
            break;
        case CYCLING:
            uBit.display.print(lshift);
            uBit.display.setBrightness(10);
            ticker = new Ticker();
            ticker->attach_us(changeBrightness, 250 * 1000);
            break;
        case TILT:
            uBit.display.setBrightness(255);
            uBit.messageBus.listen(MICROBIT_ID_GESTURE, MICROBIT_EVT_ANY, onGesture);
            onGesture(MicroBitEvent(MICROBIT_ID_GESTURE, uBit.accelerometer.getGesture()));
            break;
    }
}
Пример #2
0
void InputHandler::handleShoveGesture(float _distance) {

    onGesture();

    float angle = -M_PI * _distance / m_view->getHeight();
    m_view->pitch(angle);

}
Пример #3
0
void InputHandler::handlePanGesture(float _startX, float _startY, float _endX, float _endY) {

    onGesture();

    m_view->screenToGroundPlane(_startX, _startY);
    m_view->screenToGroundPlane(_endX, _endY);

    float dx = _startX - _endX;
    float dy = _startY - _endY;

    m_view->translate(dx, dy);

}
Пример #4
0
void InputHandler::handleTapGesture(float _posX, float _posY) {

    onGesture();

    double viewCenterX = 0.5 * m_view->getWidth();
    double viewCenterY = 0.5 * m_view->getHeight();

    m_view->screenToGroundPlane(viewCenterX, viewCenterY);
    m_view->screenToGroundPlane(_posX, _posY);

    m_view->translate((_posX - viewCenterX), (_posY - viewCenterY));

}
Пример #5
0
void InputHandler::handleRotateGesture(float _posX, float _posY, float _radians) {

    onGesture();

    // Get vector from center of rotation to view center
    m_view.screenToGroundPlane(_posX, _posY);
    glm::vec2 offset(_posX, _posY);

    // Rotate vector by gesture rotation and apply difference as translation
    glm::vec2 translation = offset - glm::rotate(offset, _radians);
    m_view.translate(translation.x, translation.y);

    m_view.roll(_radians);

}
Пример #6
0
void InputHandler::handlePinchGesture(float _posX, float _posY, float _scale, float _velocity) {

    onGesture();

    float z = m_view->getZoom();
    static float invLog2 = 1 / log(2);
    m_view->zoom(log(_scale) * invLog2);

    m_view->screenToGroundPlane(_posX, _posY);
    float s = pow(2, m_view->getZoom() - z) - 1;
    m_view->translate(s * _posX, s * _posY);

    // Take the derivative of zoom as a function of scale:
    // z(s) = log2(s) + C
    // z'(s) = s' / s / log(2)
    float vz = _velocity / _scale * invLog2;
    if (std::abs(vz) >= THRESHOLD_START_ZOOM) {
        setVelocity(vz, glm::vec2(0.f));
    }

}
Пример #7
0
void InputHandler::handleFlingGesture(float _posX, float _posY, float _velocityX, float _velocityY) {

    if (glm::length(glm::vec2(_velocityX, _velocityY)) / m_view.pixelScale() <= THRESHOLD_START_PAN) {
        return;
    }

    const static float epsilon = 0.0167f;

    onGesture();

    float startX = _posX;
    float startY = _posY;
    float endX = _posX + epsilon * _velocityX;
    float endY = _posY + epsilon * _velocityY;

    m_view.screenToGroundPlane(startX, startY);
    m_view.screenToGroundPlane(endX, endY);

    float dx = (startX - endX) / epsilon;
    float dy = (startY - endY) / epsilon;

    setVelocity(0.f, glm::vec2(dx, dy));

}
Пример #8
0
MainWindow::MainWindow(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::MainWindowClass)
    , menu(0)
    , menuActive(false)
    , lastPage(0)
    , updateCounter(1)
    , updateInterval(1)
    , gc(this)
    , fifo(qgetenv("VLASOVSOFT_FIFO1"))
    , pt(qgetenv("VLASOVSOFT_FIFO2"))
{      
    ui->setupUi(this);

    QString dataDir = qApp->applicationDirPath() + QDir::toNativeSeparators(QString("/data/"));
    QString cacheDir = dataDir + "cache";
    QString bookmarksDir = dataDir + "bookmarks";
    QString histFile = dataDir + "cr3hist.bmk";
    QString iniFile = dataDir + "cr3.ini";
    QString cssFile = dataDir + "fb2.css";
    QString hyphDir = dataDir + "hyph" + QDir::separator();

    ui->view->setHyphDir(hyphDir);

    ldomDocCache::init(qt2cr(cacheDir), DOC_CACHE_SIZE);

    ui->view->setPropsChangeCallback(this);
    ui->view->loadSettings(iniFile);
    ui->view->loadHistory(histFile);
    ui->view->loadCSS(cssFile);
#if ENABLE_BOOKMARKS_DIR==1
    ui->view->setBookmarksDir(bookmarksDir);
#endif

    ui->view->getDocView()->setBatteryState( ui->view->getBatteryState() );
    ui->view->getDocView()->setCallback(this);

    updateCounter = updateInterval = ui->view->getOptions()->getIntDef(PROP_DISPLAY_FULL_UPDATE_INTERVAL, 1);

    // Fill action list
    aList.push_back(ui->actionEmpty);        // 0
    aList.push_back(ui->actionShowMenu);     // 1
    aList.push_back(ui->actionBack);         // 2
    aList.push_back(ui->actionForward);      // 3
    aList.push_back(ui->actionNextPage);     // 4
    aList.push_back(ui->actionPreviousPage); // 5
    aList.push_back(ui->actionNext10Pages);
    aList.push_back(ui->actionPrevious10Pages);
    aList.push_back(ui->actionNextChapter);
    aList.push_back(ui->actionPreviousChapter);
    aList.push_back(ui->actionFirstPage);
    aList.push_back(ui->actionLastPage);
    aList.push_back(ui->actionPosition);
    aList.push_back(ui->actionOpen);
    aList.push_back(ui->actionClose);
    aList.push_back(ui->actionTOC);
    aList.push_back(ui->actionRecentBooks);
    aList.push_back(ui->actionSettings);
    aList.push_back(ui->actionAddBookmark);
    aList.push_back(ui->actionShowBookmarksList);
    aList.push_back(ui->actionFileProperties);
    aList.push_back(ui->actionScreenRotation);
    aList.push_back(ui->actionFrontlight);
    aList.push_back(ui->actionFrontlightToggle);
    aList.push_back(ui->actionFrontlightPlus);
    aList.push_back(ui->actionFrontlightMinus);   
    aList.push_back(ui->actionZoomIn);
    aList.push_back(ui->actionZoomOut);
    aList.push_back(ui->actionToggleInversion);
    aList.push_back(ui->actionToggleHeader);
    aList.push_back(ui->actionSuspend);
    aList.push_back(ui->actionScreenRotation0);
    aList.push_back(ui->actionScreenRotation90);
    aList.push_back(ui->actionScreenRotation180);
    aList.push_back(ui->actionScreenRotation270);
    aList.push_back(ui->actionScreenRotationPlus90);
    aList.push_back(ui->actionScreenRotationPlus180);
    aList.push_back(ui->actionScreenRotationMinus90);
    aList.push_back(ui->actionDeleteCurrentDocument);
    aList.push_back(ui->actionDictionary);

    PropsRef props( ui->view->getOptions() );
    // use right column for next page by default
    setDefaultTapZoneAction( props,0,2,0,4 );
    setDefaultTapZoneAction( props,0,2,1,4 );
    setDefaultTapZoneAction( props,0,2,2,4 );
    // use left column for previous page by default
    setDefaultTapZoneAction( props,0,0,0,5 );
    setDefaultTapZoneAction( props,0,0,1,5 );
    setDefaultTapZoneAction( props,0,0,2,5 );
    // use center column for menu by default
    setDefaultTapZoneAction( props,0,1,0,1 );
    setDefaultTapZoneAction( props,0,1,1,1 );
    setDefaultTapZoneAction( props,0,1,2,1 );

    ui->view->setOptions(props);

    gc.setRotation( props->getIntDef(PROP_ROTATE_ANGLE, 0) );
    gc.setWeights( QSize(props->getIntDef(PROP_APP_UI_SWIPES_X_WEIGHT, 1), props->getIntDef(PROP_APP_UI_SWIPES_Y_WEIGHT, 1)) );

    QObject::connect( &gc, SIGNAL(sigGesture(QPoint,GesturesController::GestureType)), this, SLOT(onGesture(QPoint,GesturesController::GestureType)) );
    QObject::connect( &pt, SIGNAL(sigPipeMsg(QString)), this, SLOT(pipeMsg(QString)) );

    // set margins
    int top = g_pConfig->readInt("margin_top", 1);
    int bottom = g_pConfig->readInt("margin_bottom", 0);
    int left = g_pConfig->readInt("margin_left", 0);
    int right = g_pConfig->readInt("margin_right", 0);
    if ( top <= 0 ) top = 1; // to handle full/partial updates
    ui->layout->setContentsMargins(left,top,right,bottom);

    writeFifoCommand(fifo, "n+");
}
Пример #9
0
void InputHandler::handleRotateGesture(float _posX, float _posY, float _radians) {

    onGesture();
    m_view->roll(_radians);

}