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

    // check if we need to update components //
    for (int i=0; i<items.size(); i++) {
        if (mAlphaChanged) items[i]->setOpacity(mAlpha);
        if (mThemeChanged) items[i]->setTheme(mTheme);
        if (mWidthChanged) items[i]->setWidth(mWidth, mLabelWidth);
        if (mAlignmentChanged) items[i]->setLabelAlignment(mAlignment);
    }
   if (mThemeChanged || mWidthChanged) layoutGui();

    mTheme = nullptr;
    mAlphaChanged = false;
    mWidthChanged = false;
    mThemeChanged = false;
    mAlignmentChanged = false;
    
    // check for gui focus change //
    if (ofGetMousePressed() && mActiveGui->mMoving == false){
        ofPoint mouse = ofPoint(ofGetMouseX(), ofGetMouseY());
        for (int i=mGuis.size()-1; i>-1; i--){
        // ignore guis that are invisible //
            if (mGuis[i]->getVisible() && mGuis[i]->hitTest(mouse)){
                if (mGuis[i] != mActiveGui) mGuis[i]->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;
        mMouseDown = false;
    // this gui has focus so let's see if any of its components were interacted with //
        if (mExpanded == false){
            mGuiFooter->update();
            mMouseDown = mGuiFooter->getMouseDown();
        }   else{
            bool hitComponent = false;
            for (int i=0; i<items.size(); i++) {
                if (hitComponent == false){
                    items[i]->update(true);
                    if (items[i]->getFocused()) {
                        hitComponent = true;
                        mMouseDown = items[i]->getMouseDown();
                        if (mGuiHeader != nullptr && mGuiHeader->getDraggable() && mGuiHeader->getFocused()){
                    // track that we're moving to force preserve focus //
                            mMoving = true;
                            ofPoint mouse = ofPoint(ofGetMouseX(), ofGetMouseY());
                            moveGui(mouse - mGuiHeader->getDragOffset());
                        }
                    }   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()){
                                hitComponent = true;
                                mMouseDown = items[i]->children[j]->getMouseDown();
                                break;
                            }
                        }
                    }
                }   else{
            // update component but ignore mouse & keyboard events //
                    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();
}
Exemple #2
0
void ofxDatGui::setPosition(int x, int y)
{
    moveGui(ofPoint(x, y));
}
Exemple #3
0
void ofxDatGui::setOrigin(int x, int y)
{
    moveGui(ofPoint(x, y));
}
Exemple #4
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();
}
Exemple #5
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();
}