Ejemplo n.º 1
0
void StGLScrollArea::stglResize() {
    StGLWidget* aContent = myChildren.getStart();
    StGLContext& aCtx = getContext();
    if(!isScrollable()
    && aContent != NULL
    && aContent->getRectPx().top() < 0
    && aContent->getCorner().v == ST_VCORNER_TOP) {
        const int aDelta = -aContent->getRectPx().top();
        aContent->changeRectPx().top()    += aDelta;
        aContent->changeRectPx().bottom() += aDelta;
    }

    if(isScrollable()
    && aContent != NULL) {
        const int    aSizeY       = stMax(getRectPx().height(), 1);
        const int    aContSizeY   = aContent->getRectPx().height();
        const double aScaleY      = double(aSizeY) / double(aContSizeY);
        const int    aScrollSizeY = stMax(int(aScaleY * (double )aSizeY), myRoot->scale(4));
        const double aPosY        = double(-aContent->getRectPx().top()) / double(aContSizeY - aSizeY);

        StArray<StGLVec2> aVertices(4);
        StRectI_t aRectPx = getRectPxAbsolute();
        aRectPx.left()   =  aRectPx.right() - myRoot->scale(2);
        aRectPx.top()    += int(aPosY * double(aSizeY - aScrollSizeY));
        aRectPx.bottom() =  aRectPx.top() + aScrollSizeY;

        myRoot->getRectGl(aRectPx, aVertices);
        myBarVertBuf.init(aCtx, aVertices);
    } else {
        myBarVertBuf.release(aCtx);
    }

    StGLWidget::stglResize();
}
Ejemplo n.º 2
0
bool StGLScrollArea::doScroll(const int  theDelta,
                              const bool theIsFling) {
    if(!theIsFling) {
        myDragYDelta = 0.0;
        myFlingTimer.stop();
    }
    if(!isScrollable()) {
        return false;
    }

    StGLWidget* aContent = myChildren.getStart();
    const int aMinLim = 0;
    const int aMaxLim = getRectPx().height() - aContent->getRectPx().height();
    const int aTopOld = aContent->getRectPx().top();
    const int aTopNew = stMax(stMin(aMinLim, aTopOld + theDelta), aMaxLim);
    const int aDelta  = aTopNew - aTopOld;
    if(aDelta == 0) {
        if(theIsFling) {
            myFlingTimer.stop();
        }
        return false;
    }

    aContent->changeRectPx().top()    += aDelta;
    aContent->changeRectPx().bottom() += aDelta;

    if(myIsLeftClick) {
        if(!theIsFling) {
            myDragYCumul += aDelta;
            if(std::abs(myDragYCumul) > myRoot->getClickThreshold()
            && !myHasDragged) {
                setClickedWithChildren(myChildren, ST_MOUSE_LEFT, false);
                myHasDragged = true;
            }
        } else {
            myDragYCumul = 0;
        }
    }

    myIsResized = true;
    return true;
}