Ejemplo n.º 1
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void Rendering::renderOverlayItems(OpenGLContext* oglContext, bool useSoftwareRendering)
{
    OverlayItemRectMap itemRectMap;
    calculateOverlayItemLayout(&itemRectMap);
    
    // Must setup a scissor to limit the overlay items to the current viewport, as they might setup a local viewport (e.g. navigation cube)
    GLboolean scissorWasOn = glIsEnabled(GL_SCISSOR_TEST);
    int scissorBox[4] = {0, 0, -1, -1};
    glGetIntegerv(GL_SCISSOR_BOX, scissorBox);
    glScissor(static_cast<GLsizei>(m_camera->viewport()->x()), static_cast<GLsizei>(m_camera->viewport()->y()), static_cast<GLsizei>(m_camera->viewport()->width()), static_cast<GLsizei>(m_camera->viewport()->height()));
    glEnable(GL_SCISSOR_TEST);


    const size_t numOverlayItems = m_overlayItems.size();
    for (size_t i = 0; i < numOverlayItems; i++)
    {
        OverlayItem* item = m_overlayItems.at(i);

        Vec2i pos(0, 0);
        Vec2ui size(0, 0);

        if (item->layoutScheme() == OverlayItem::FIXED_POSITION)
        {
            pos = item->fixedPosition();
            size = item->sizeHint();
        }
        else
        {
            // Item should be laid out already - grab its pos/size from the layout map
            OverlayItemRectMap::iterator it = itemRectMap.find(item);
            if (it != itemRectMap.end())
            {
                Recti rect = it->second;
                pos = rect.min();
                size.set(static_cast<uint>(rect.width()), static_cast<uint>(rect.height()));
            }
        }

        if (!size.isZero())
        {
            if (useSoftwareRendering)
            {
                item->renderSoftware(oglContext, pos, size);
            }
            else
            {
                item->render(oglContext, pos, size);
            }
        }
    }


    // Restore scissor settings
    if (!scissorWasOn) glDisable(GL_SCISSOR_TEST);
    glScissor(scissorBox[0], scissorBox[1], scissorBox[2], scissorBox[3]); 
}
Ejemplo n.º 2
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
cvf::Recti Rendering::overlayItemRect(OverlayItem* item)
{
    OverlayItemRectMap itemRectMap;
    calculateOverlayItemLayout(&itemRectMap);
    
    OverlayItemRectMap::iterator it = itemRectMap.find(item);
    if (it != itemRectMap.end())
    {
        return it->second;
    }

    return cvf::Recti();
}
Ejemplo n.º 3
0
//--------------------------------------------------------------------------------------------------
/// Get the the overlay item (if any) at the given cursor position
//--------------------------------------------------------------------------------------------------
OverlayItem* Rendering::overlayItemFromWindowCoordinates(int x, int y)
{
    OverlayItemRectMap itemRectMap;
    calculateOverlayItemLayout(&itemRectMap);

    const size_t numOverlayItems = m_overlayItems.size();
    for (size_t i = 0; i < numOverlayItems; i++)
    {
        OverlayItem* item = m_overlayItems.at(i);
        OverlayItemRectMap::iterator it = itemRectMap.find(item);
        if (it != itemRectMap.end())
        {
            Recti rect = it->second;
            if (item->pick(x, y, rect.min(), Vec2ui(static_cast<cvf::uint>(rect.width()), static_cast<cvf::uint>(rect.height()))))
            {
                return item;
            }
        }
    }

    return NULL;
}