//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- 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]); }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void Rendering::calculateOverlayItemLayoutForSchemeAndCorner(OverlayItemRectMap* itemRectMap, OverlayItem::LayoutScheme layoutScheme, OverlayItem::AnchorCorner anchorCorner) { CVF_ASSERT(layoutScheme == OverlayItem::HORIZONTAL || layoutScheme == OverlayItem::VERTICAL); const int border = 3; const Vec2i vpSize = Vec2i(static_cast<int>(m_camera->viewport()->width()), static_cast<int>(m_camera->viewport()->height())); const Vec2i vpPos = Vec2i(m_camera->viewport()->x(), m_camera->viewport()->y()); Vec2i cursor(0,0); switch (anchorCorner) { case OverlayItem::TOP_LEFT: cursor.set(border, vpSize.y() - border); break; case OverlayItem::TOP_RIGHT: cursor.set(vpSize.x() - border, vpSize.y() - border); break; case OverlayItem::BOTTOM_LEFT: cursor.set(border, border); break; case OverlayItem::BOTTOM_RIGHT: cursor.set(vpSize.x() - border, border); break; default: cursor.set(border,border); } cursor += vpPos; // Adjust starting cursor position based on other already placed items in this anchor corner // The assumption here is that for each corner, the horizontal layout has already been added to the map if (layoutScheme == OverlayItem::VERTICAL) { OverlayItemRectMap::iterator it; for (it = itemRectMap->begin(); it != itemRectMap->end(); ++it) { const OverlayItem* placedItem = it->first; const Recti placedItemRect = it->second; if (placedItem->anchorCorner() == anchorCorner && placedItemRect.contains(cursor)) { if (anchorCorner == OverlayItem::BOTTOM_LEFT || anchorCorner == OverlayItem::BOTTOM_RIGHT) { cursor.y() += placedItemRect.height() + border; } else { cursor.y() -= placedItemRect.height() + border; } } } } const size_t numOverlayItems = m_overlayItems.size(); for (size_t i = 0; i < numOverlayItems; i++) { OverlayItem* item = m_overlayItems.at(i); if ((item->anchorCorner() == anchorCorner) && (item->layoutScheme() == layoutScheme)) { // Find this position and size Vec2i position = cursor; Vec2ui size = item->sizeHint(); if ((anchorCorner == OverlayItem::TOP_RIGHT) || (anchorCorner == OverlayItem::BOTTOM_RIGHT)) { position.x() -= size.x(); } if ((anchorCorner == OverlayItem::TOP_LEFT) || (anchorCorner == OverlayItem::TOP_RIGHT)) { position.y() -= size.y(); } // Store the position in the map Recti rect(position.x(), position.y(), static_cast<int>(size.x()), static_cast<int>(size.y())); (*itemRectMap)[item] = rect; // Find next position, moving the cursor if (layoutScheme == OverlayItem::HORIZONTAL) { if ((anchorCorner == OverlayItem::TOP_LEFT) || (anchorCorner == OverlayItem::BOTTOM_LEFT)) { cursor.x() += (size.x() + border); } else { cursor.x() -= (size.x() + border); } } else if (layoutScheme == OverlayItem::VERTICAL) { if ((anchorCorner == OverlayItem::BOTTOM_LEFT) || (anchorCorner == OverlayItem::BOTTOM_RIGHT)) { cursor.y() += (size.y() + border); } else { cursor.y() -= (size.y() + border); } } else { CVF_FAIL_MSG("Unhandled OverlayItem::LayoutDirection"); } } } }