示例#1
0
void ofxDatGui::update()
{
    if (!mVisible) return;

    if (mAlphaChanged) setGuiAlpha();
    if (mTemplateChanged) setGuiTemplate();
    if (mWidthChanged) setGuiWidth();
    if (mAlignmentChanged) setGuiAlignment();

// first check for focus change //
    if (ofGetMousePressed()){
        bool focusChanged = false;
        ofPoint mouse = ofPoint(ofGetMouseX(), ofGetMouseY());
        for (int i=mGuis.size()-1; i>-1; i--){
            if (mGuis[i]->hitTest(mouse)){
                if (mGuis[i] != mActiveGui){
                    mActiveGui = mGuis[i];
                    focusChanged = true;
            // stick this gui at the end of the array so it is drawn last //
                    std::swap(mGuis[i], mGuis[mGuis.size()-1]);
                }
                break;
            }
        }
    // reassign the draw / update order //
        if (focusChanged) for (int i=0; i<mGuis.size(); i++) mGuis[i]->setAutoDraw(true, i);
    }

    if (!hasFocus() || !mEnabled){
    // update children but ignore mouse & keyboard events //
        for (int i=0; i<items.size(); i++) items[i]->update(true);
    }   else {
        mMoving = false;
    // this gui has focus so let's see if any of its components were interacted with //
        if (mExpanded == false){
            mGuiFooter->update(false);
        }   else{
            int activeItemIndex = -1;
            for (int i=0; i<items.size(); i++) {
                items[i]->update(false);
                if (items[i]->getFocused()) {
                    activeItemIndex = i;
                    if (mGuiHeader != nullptr && mGuiHeader->getPressed()){
                // track that we're moving to force preserve focus //
                        mMoving = true;
                        ofPoint mouse = ofPoint(ofGetMouseX(), ofGetMouseY());
                        moveGui(mouse - mGuiHeader->dragOffset);
                    }
                    break;
                }   else if (items[i]->getIsExpanded()){
                // check if one of its children has focus //
                    for (int j=0; j<items[i]->children.size(); j++) {
                        if (items[i]->children[j]->getFocused()){
                            activeItemIndex = i;
                            break;
                        }
                    }
                    if (activeItemIndex != -1) break;
                }
            }
        // update the remaining components //
            if (activeItemIndex != -1){
                for (int i=activeItemIndex + 1; i<items.size(); i++) {
        //  but tell them to ignore mouse & keyboard events since we're already determined the active component //
                    items[i]->update(true);
                }
            }
        }
    }
    
// empty the trash //
    for (int i=0; i<trash.size(); i++) delete trash[i];
    trash.clear();
}
示例#2
0
void ofxDatGui::update()
{
    if (!mVisible) return;

    if (mAlphaChanged) setGuiAlpha();
    if (mTemplateChanged) setGuiTemplate();
    if (mWidthChanged) setGuiWidth();
    if (mAlignmentChanged) setGuiAlignment();

    // first check for gui focus change //
    if (!mActiveGui->isMoving()) {
        ofPoint mouse = ofPoint(ofGetMouseX(), ofGetMouseY());
        for (auto gui = mGuis.rbegin(); gui != mGuis.rend(); gui++) {
            // ignore guis that are invisible //
            if ((*gui)->getVisible() && (*gui)->hitTest(mouse)) {
                if ((*gui) != mActiveGui) {
                    // let the previous gui process loss of focus
                    mActiveGui->onFocusLost();
                    (*gui)->focus();
                }
                break;
            }
        }
    }

    if (!getFocused() || !mEnabled) {
        // update children but ignore mouse & keyboard events //
        for (int i=0; i<items.size(); i++) items[i]->update(false);
    }   else {
        mMoving = false;
        // this gui has focus so let's see if any of its components were interacted with //
        if (!mExpanded) {
            mGuiFooter->update();
        } else {
            int activeItemIndex = -1;
            for (int i=0; i<items.size(); i++) {
                // only update if the item is visible
                if (items[i]->getVisible()) {
                    items[i]->update();
                    if (items[i]->getFocused()) {
                        activeItemIndex = i;
                        if (mGuiHeader != nullptr && mGuiHeader->getDraggable() && mGuiHeader->getPressed()) {
                            // track that we're moving to force preserve focus //
                            mMoving = true;
                            ofPoint mouse = ofPoint(ofGetMouseX(), ofGetMouseY());
                            moveGui(mouse - mGuiHeader->dragOffset);
                        }
                        break;
                    } else if (items[i]->getIsExpanded()) {
                        // check if one of its children has focus //
                        for (int j = 0; j < items[i]->children.size(); j++) {
                            if (items[i]->children[j]->getFocused()) {
                                activeItemIndex = i;
                                break;
                            }
                        }
                        if (activeItemIndex != -1) break;
                    }
                }
            }
            // update the remaining components //
            if (activeItemIndex != -1) {
                for (int i=activeItemIndex + 1; i<items.size(); i++) {
                    //  but tell them to ignore mouse & keyboard events since we're already determined the active component //
                    items[i]->update(false);
                    if (items[i]->getFocused()) items[i]->setFocused(false);
                }
            }
        }
    }

// empty the trash //
    for (int i=0; i<trash.size(); i++) delete trash[i];
    trash.clear();
}