Exemple #1
0
bool StGLMenu::tryUnClick(const StClickEvent& theEvent,
                          bool&               theIsItemUnclicked) {
    myKeepActive = false;
    bool wasSomeClickedBefore = theIsItemUnclicked;
    bool isSelfClicked = StGLWidget::tryUnClick(theEvent, theIsItemUnclicked);
    bool isSelfItemClicked = !wasSomeClickedBefore && theIsItemUnclicked;
    if(myKeepActive) {
        return isSelfClicked;
    }

    for(StGLWidget* aChild = getChildren()->getStart(); aChild != NULL; aChild = aChild->getNext()) {
        StGLMenuItem* anItem = (StGLMenuItem* )aChild;
        if(anItem->hasSubMenu()
        && anItem->getSubMenu()->myKeepActive) {
            myKeepActive = true;
            return isSelfClicked;
        }
        anItem->setSelected(false);
    }

    if(myIsRootMenu && !isSelfItemClicked) {
        setActive(false); // deactivate root menu
    }

    if(myIsContextual) {
        myRoot->destroyWithDelay(this);
    }

    return isSelfClicked;
}
void StGLSwitchTextured::setVisibility(bool isVisible, bool isForce) {
    // setup opacity
    StGLWidget::setVisibility(isVisible, isForce);
    for(StGLWidget* aChild = getChildren()->getStart(); aChild != NULL; aChild = aChild->getNext()) {
        aChild->setVisibility(isVisible, isForce);
    }
}
Exemple #3
0
void StGLMenu::stglResize() {
    // Since all children should be StGLMenuItem implementing delayed resize,
    // just postpone resize until items will be actually rendered.
    //StGLWidget::stglResize();
    for(StGLWidget* aChild = getChildren()->getStart(); aChild != NULL; aChild = aChild->getNext()) {
        ((StGLMenuItem* )aChild)->changeRectPx();
    }

    StGLContext& aCtx = getContext();

    StArray<StGLVec2> aVertices(4);
    getRectGl(aVertices);
    myVertexBuf.init(aCtx, aVertices);

    if(myToDrawBounds) {
        StRectI_t aRectBnd = getRectPxAbsolute();
        aRectBnd.left()   -= 1;
        aRectBnd.right()  += 1;
        aRectBnd.top()    -= 1;
        aRectBnd.bottom() += 1;
        myRoot->getRectGl(aRectBnd, aVertices);
        myVertexBndBuf.init(aCtx, aVertices);
    }
    myIsResized = false;
}
Exemple #4
0
StGLWidget* StGLRootWidget::setFocus(StGLWidget* theWidget) {
    if(myFocusWidget == theWidget) {
        return myFocusWidget;
    }

    StGLWidget* aPrevWidget = myFocusWidget;
    if(aPrevWidget != NULL) {
        aPrevWidget->myHasFocus = false;
    }

    myFocusWidget = theWidget;
    if(theWidget == NULL) {
        // search for another top widget (prefer widget with greater visibility layer)
        for(StGLWidget* aChild = myChildren.getLast(); aChild != NULL; aChild = aChild->getPrev()) {
            if(aChild->isTopWidget()
            && aPrevWidget != aChild
            && aChild->isVisible()) {
                myFocusWidget = aChild;
                break;
            }
        }
    }

    if(myFocusWidget != NULL) {
        myFocusWidget->myHasFocus = true;
    }
    return aPrevWidget;
}
Exemple #5
0
void StGLMenu::stglUpdateSubmenuLayout() {
    stglInit();
    for(StGLWidget* aChild = getChildren()->getStart(); aChild != NULL; aChild = aChild->getNext()) {
        StGLMenuItem* aMenuItem = (StGLMenuItem* )aChild;
        if(aMenuItem->getSubMenu() != NULL) {
            aMenuItem->getSubMenu()->stglUpdateSubmenuLayout();
        }
    }
}
bool StGLSwitchTextured::stglInit() {
    bool isOK = StGLWidget::stglInit();
    StGLWidget* aChild = getChildren()->getStart();
    if(aChild != NULL) {
        // just upsacle to fit children
        changeRectPx().right()  = getRectPx().left() + aChild->getRectPx().width();
        changeRectPx().bottom() = getRectPx().top()  + aChild->getRectPx().height();
    }
    return isOK;
}
Exemple #7
0
void StGLMenu::setOpacity(const float theOpacity, bool theToSetChildren) {
    bool wasVisible = StGLMenu::isVisible();
    StGLWidget::setOpacity(theOpacity, theToSetChildren);
    if(!StGLMenu::isVisible()
     && wasVisible) {
        for(StGLWidget* aChild = getChildren()->getStart(); aChild != NULL; aChild = aChild->getNext()) {
            ((StGLMenuItem* )aChild)->setSelected(false);
        }
    }
}
Exemple #8
0
bool StGLWidget::isChild(StGLWidget* theWidget,
                         const bool  theIsRecursive) {
    for(StGLWidget* aChild = myChildren.getStart(); aChild != NULL; aChild = aChild->getNext()) {
        if(aChild == theWidget) {
            return true;
        } else if(theIsRecursive
               && aChild->isChild(theWidget, true)) {
            return true;
        }
    }
    return false;
}
Exemple #9
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();
}
Exemple #10
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;
}
Exemple #11
0
void StGLMenu::DeleteWithSubMenus(StGLMenu* theMenu) {
    if(theMenu == NULL) {
        return;
    }
    for(StGLWidget* aChild = theMenu->getChildren()->getStart(); aChild != NULL; aChild = aChild->getNext()) {
        StGLMenuItem* anItem = (StGLMenuItem* )aChild;
        if(anItem->getSubMenu() != NULL) {
            DeleteWithSubMenus(anItem->getSubMenu());
        }
    }
    delete theMenu;
}
bool StGLSwitchTextured::tryUnClick(const StPointD_t& theCursorZo, const int& theMouseBtn, bool& isItemUnclicked) {
    if(!isVisible()) {
        return false; // nothing to see - nothing to click...
    }
    bool isSelfClicked = isClicked(theMouseBtn) && isPointIn(theCursorZo);
    setClicked(theMouseBtn, false);
    if(!isItemUnclicked && isSelfClicked) {
        isItemUnclicked = true;

        int32_t anActiveValue = myTrackValue->getValue();
        StGLRadioButtonTextured* aRadioBtn = NULL;
        for(StGLWidget* aChild = getChildren()->getStart(); aChild != NULL;) {
            /// TODO (Kirill Gavrilov#9) - adding children with another type is not allowed
            ///                            hovewer not protected thus this cast is not thread-safe!
            aRadioBtn = (StGLRadioButtonTextured* )aChild;
            aChild = aChild->getNext();

            if(anActiveValue == aRadioBtn->getValueOn()) {
                // switch to next
                while(aChild != NULL) {
                    aRadioBtn = (StGLRadioButtonTextured* )aChild;
                    if(!mySkipValues.contains(aRadioBtn->getValueOn())) {
                        myTrackValue->setValue(aRadioBtn->getValueOn());
                        break;
                    }
                    aChild = aChild->getNext();
                }
                if(aChild == NULL) {
                    // switch to first
                    aRadioBtn = (StGLRadioButtonTextured* )getChildren()->getStart();
                    myTrackValue->setValue(aRadioBtn->getValueOn());
                }
                break;
            }
        }
        return true;
    }
    return false;
}
void StGLSwitchTextured::stglDraw(unsigned int theView) {
    if(!isVisible()) {
        return;
    }
    int32_t anActiveValue = myTrackValue->getValue();
    StGLRadioButtonTextured* aRadioBtn = NULL;
    for(StGLWidget* aChild = getChildren()->getStart(); aChild != NULL;) {
        /// TODO (Kirill Gavrilov#9) - adding children with another type is not allowed
        ///                            hovewer not protected thus this cast is not thread-safe!
        aRadioBtn = (StGLRadioButtonTextured* )aChild;
        aChild = aChild->getNext();

        // show only active item
        if(anActiveValue == aRadioBtn->getValueOn()) {
            aRadioBtn->stglDraw(theView);
            return;
        }
    }
    // show first item anyway
    StGLWidget* aChild = getChildren()->getStart();
    if(aChild != NULL) {
        aChild->stglDraw(theView);
    }
}
Exemple #14
0
inline void setClickedWithChildren(StGLWidgetList& theList, const int theMouseBtn, bool isClicked) {
    for(StGLWidget* aChild = theList.getStart(); aChild != NULL; aChild = aChild->getNext()) {
        aChild->setClicked(theMouseBtn, isClicked);
        setClickedWithChildren(*aChild->getChildren(), theMouseBtn, isClicked);
    }
}
Exemple #15
0
bool StGLMenu::stglInit() {
    myWidth = 0;
    myIsInitialized = StGLWidget::stglInit();
    if(!myIsInitialized) {
        return false;
    }
    int aMarginLeft = 0;
    for(StGLWidget* aChild = getChildren()->getStart(); aChild != NULL; aChild = aChild->getNext()) {
        StGLMenuItem* anItem = (StGLMenuItem* )aChild;
        aMarginLeft = stMax(aMarginLeft, anItem->getMargins().left);
        int anItemW = anItem->getMargins().left + anItem->computeTextWidth() + anItem->getMargins().right;
        if(myOrient == MENU_HORIZONTAL) {
            anItem->changeRectPx().moveLeftTo(myWidth);
            anItem->changeRectPx().right() = anItem->getRectPx().left() + anItemW;
            anItem->setTextWidth(anItemW - anItem->getMargins().left);
            myWidth += anItemW;
        } else {
            myWidth = stMax(myWidth, anItemW);
        }
        if(anItem->getSubMenu() != NULL) {
            if(myOrient == MENU_HORIZONTAL) {
                anItem->getSubMenu()->changeRectPx().moveTopLeftTo(anItem->getRectPxAbsolute().left(), anItem->getRectPxAbsolute().bottom());
            } else if(myOrient == MENU_VERTICAL
                   || myOrient == MENU_VERTICAL_COMPACT) {
                anItem->getSubMenu()->changeRectPx().moveTopLeftTo(anItem->getRectPxAbsolute().right() - myRoot->scale(10),
                                                                   anItem->getRectPxAbsolute().top());
            }
        }
    }
    StGLWidget* aChildLast = getChildren()->getLast();
    if(aChildLast != NULL) {
        changeRectPx().right()  = getRectPx().left() + aChildLast->getRectPx().right();
        changeRectPx().bottom() = getRectPx().top()  + aChildLast->getRectPx().bottom();
    }
    int aWidth = stMax(myWidthMin, myWidth);
    if(myOrient == MENU_VERTICAL
    || myOrient == MENU_VERTICAL_COMPACT) {
        changeRectPx().right() = getRectPx().left() + aWidth;
        int anItemCount = 0;
        for(StGLWidget* aChild = getChildren()->getStart(); aChild != NULL; aChild = aChild->getNext(), ++anItemCount) {
            StGLMenuItem* anItem = (StGLMenuItem* )aChild;
            anItem->changeRectPx().moveTopTo(anItemCount * myItemHeight);
            anItem->changeRectPx().right() = anItem->getRectPx().left() + aWidth;
            anItem->setTextWidth(aWidth);
            if(anItem->getSubMenu() != NULL) {
                anItem->getSubMenu()->changeRectPx().moveTopLeftTo(getRectPxAbsolute().right() - myRoot->scale(10),
                                                                   anItem->getRectPxAbsolute().top());
            }
        }
        changeRectPx().bottom() = getRectPx().top() + anItemCount * myItemHeight;
    }

    // already initialized?
    if(myVertexBuf.isValid()) {
        // synchronize menu items visibility
        setOpacity(myOpacity, true);
        return true;
    }

    stglResize();
    return myIsInitialized;
}