src/Screens/ModelEditorScreen.cpp
// draw a single 3D model viewer
draw a single 3D model viewer
draw a single 3D model viewer
bool draw3DViewer(
            ModelEditorScreen::Impl& impl,
            UiModelViewer& viewer,
            char const* name) {
        bool isOpen = true;
        ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {0.0f, 0.0f});
        bool shown = ImGui::Begin(name, &isOpen, ImGuiWindowFlags_MenuBar);
        ImGui::PopStyleVar();
        if (!isOpen) {
            ImGui::End();
            return false;
        }
        if (!shown) {
            ImGui::End();
            return true;
        }
        auto resp = viewer.draw(impl.st->editedModel.getUiModel());
        ImGui::End();
        if (resp.isMousedOver && resp.hovertestResult != impl.st->getHovered()) {
            impl.st->setHovered(resp.hovertestResult);
        }
        if (resp.isMousedOver && resp.isLeftClicked) {
            impl.st->setSelected(resp.hovertestResult);
        }
        if (resp.isMousedOver && resp.hovertestResult) {
            drawComponentHoverTooltip(*resp.hovertestResult, resp.mouse3DLocation);
        }
        {
            char buf[128];
            std::snprintf(buf, sizeof(buf), "%s_contextmenu", name);
            if (resp.isMousedOver && resp.hovertestResult && ImGui::IsMouseReleased(ImGuiMouseButton_Right)) {
                impl.st->setSelected(resp.hovertestResult);
                ImGui::OpenPopup(buf);
            }
            if (impl.st->editedModel.hasSelected() && ImGui::BeginPopup(buf)) {
                draw3DViewerContextMenu(impl, *impl.st->getSelected());
                ImGui::EndPopup();
            }
        }
        return true;
    }
bool draw3DViewer ( ModelEditorScreen :: Impl & impl , UiModelViewer & viewer , char const * name ) { bool isOpen = true ; ImGui :: PushStyleVar ( ImGuiStyleVar_WindowPadding , { 0.0f , 0.0f } ) ; bool shown = ImGui :: Begin ( name , & isOpen , ImGuiWindowFlags_MenuBar ) ; ImGui :: PopStyleVar ( ) ; if ( ! isOpen ) { ImGui :: End ( ) ; return false ; } if ( ! shown ) { ImGui :: End ( ) ; return true ; } auto resp = viewer . draw ( impl . st -> editedModel . getUiModel ( ) ) ; ImGui :: End ( ) ; if ( resp . isMousedOver && resp . hovertestResult != impl . st -> getHovered ( ) ) { impl . st -> setHovered ( resp . hovertestResult ) ; } if ( resp . isMousedOver && resp . isLeftClicked ) { impl . st -> setSelected ( resp . hovertestResult ) ; } if ( resp . isMousedOver && resp . hovertestResult ) { drawComponentHoverTooltip ( * resp . hovertestResult , resp . mouse3DLocation ) ; } { char buf [ 128 ] ; std :: snprintf ( buf , sizeof ( buf ) , " " , name ) ; if ( resp . isMousedOver && resp . hovertestResult && ImGui :: IsMouseReleased ( ImGuiMouseButton_Right ) ) { impl . st -> setSelected ( resp . hovertestResult ) ; ImGui :: OpenPopup ( buf ) ; } if ( impl . st -> editedModel . hasSelected ( ) && ImGui :: BeginPopup ( buf ) ) { draw3DViewerContextMenu ( impl , * impl . st -> getSelected ( ) ) ; ImGui :: EndPopup ( ) ; } } return true ; }
draw a single 3D model viewer
draw a single 3D model viewer
// update hover // if left-clicked, update selection // if hovered, draw hover tooltip // if right-clicked, draw context menu