Example #1
0
void ofxDatGui::onInternalEventCallback(ofxDatGuiInternalEvent e)
{
// these events are not dispatched out to the main application //
    if (e.type == ofxDatGuiEventType::DROPDOWN_TOGGLED){
        layoutGui();
    }   else if (e.type == ofxDatGuiEventType::GUI_TOGGLED){
        mExpanded ? collapseGui() : expandGui();
    }   else if (e.type == ofxDatGuiEventType::VISIBILITY_CHANGED){
        layoutGui();
    }
}
Example #2
0
void ofxDatGui::moveGui(ofPoint pt)
{
    mPosition.x = pt.x;
    mPosition.y = pt.y;
    mAnchor = ofxDatGuiAnchor::NO_ANCHOR;
    layoutGui();
}
Example #3
0
void ofxDatGui::anchorGui()
{
/*
    ofGetWidth/ofGetHeight returns incorrect values after retina windows are resized in version 0.9.1 & 0.9.2
    https://github.com/openframeworks/openFrameworks/pull/4858
*/
    int multiplier = 1;
    if (ofxDatGuiIsRetina() && ofGetVersionMajor() == 0 && ofGetVersionMinor() == 9 && (ofGetVersionPatch() == 1 || ofGetVersionPatch() == 2)){
        multiplier = 2;
    }
    if (mAnchor == ofxDatGuiAnchor::TOP_LEFT){
        mPosition.y = 0;
        mPosition.x = 0;
    }   else if (mAnchor == ofxDatGuiAnchor::TOP_RIGHT){
        mPosition.y = 0;
        mPosition.x = (ofGetWidth() / multiplier) - mWidth;
    }   else if (mAnchor == ofxDatGuiAnchor::BOTTOM_LEFT){
        mPosition.x = 0;
        mPosition.y = (ofGetHeight() / multiplier) - mHeight;
    }   else if (mAnchor == ofxDatGuiAnchor::BOTTOM_RIGHT){
        mPosition.x = (ofGetWidth() / multiplier) - mWidth;
        mPosition.y = (ofGetHeight() / multiplier) - mHeight;
    }
    layoutGui();
}
Example #4
0
void ofxDatGui::onDropdownEventCallback(ofxDatGuiDropdownEvent e)
{
    if (dropdownEventCallback != nullptr) {
        dropdownEventCallback(e);
    }   else{
        ofxDatGuiLog::write(ofxDatGuiMsg::EVENT_HANDLER_NULL);
    }
// adjust the gui after a dropdown is closed //
    layoutGui();
}
Example #5
0
void ofxDatGui::attachItem(ofxDatGuiComponent* item)
{
    if (mGuiFooter != nullptr){
        items.insert(items.end()-1, item);
    }   else {
        items.push_back( item );
    }
    item->onInternalEvent(this, &ofxDatGui::onInternalEventCallback);
    layoutGui();
}
Example #6
0
ofxDatGuiFooter* ofxDatGui::addFooter()
{
    if (mGuiFooter == nullptr){
        mGuiFooter = new ofxDatGuiFooter();
        items.push_back(mGuiFooter);
        mGuiFooter->onInternalEvent(this, &ofxDatGui::onInternalEventCallback);
        layoutGui();
	}
    return mGuiFooter;
}
Example #7
0
void ofxDatGui::anchorGui()
{
    mPosition.y = 0;
    if (mAnchor == ofxDatGuiAnchor::TOP_LEFT){
        mPosition.x = 0;
    }   else if (mAnchor == ofxDatGuiAnchor::TOP_RIGHT){
        mPosition.x = ofGetWidth() - mWidth;
    }
    layoutGui();
}
Example #8
0
ofxDatGuiHeader* ofxDatGui::addHeader(string label, bool draggable)
{
    if (mGuiHeader == nullptr){
        mGuiHeader = new ofxDatGuiHeader(label, draggable);
        if (items.size() == 0){
            items.push_back(mGuiHeader);
        }   else{
    // always ensure header is at the top of the panel //
            items.insert(items.begin(), mGuiHeader);
        }
        layoutGui();
	}
    return mGuiHeader;
}
Example #9
0
void ofxDatGui::anchorGui()
{
    mPosition.y = 0;
    if (mAnchor == ofxDatGuiAnchor::TOP_LEFT){
        mPosition.x = 0;
    }   else if (mAnchor == ofxDatGuiAnchor::TOP_RIGHT){
        mPosition.x = ofGetWidth() - mWidth;
    /*
        ofGetWidth returns an incorrect value after retina windows are resized in version 0.9.1 & 0.9.2
        https://github.com/openframeworks/openFrameworks/issues/4746
        https://github.com/openframeworks/openFrameworks/pull/4858
    */
        if (ofxDatGuiIsRetina() && ofGetVersionMajor() == 0 && ofGetVersionMinor() == 9 && (ofGetVersionPatch() == 1 || ofGetVersionPatch() == 2)){
            mPosition.x = (ofGetWidth() / 2) - mWidth;
        }
    }
    layoutGui();
}
Example #10
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();
}
Example #11
0
void ofxDatGui::setGuiTemplate()
{
    for (int i=0; i<items.size(); i++) items[i]->setTemplate(mTemplate);
    layoutGui();
    mTemplateChanged = false;
}
Example #12
0
void ofxDatGui::setGuiWidth()
{
    for (int i=0; i<items.size(); i++) items[i]->setWidth(mWidth);
    layoutGui();
    mWidthChanged = false;
}