/** * \brief Subtract a rectangle \a b from a rectangle \a a. * \param a The target. * \param b The rectangle to remove in \a a. * \param boxes The subparts of \a a after the subtraction. */ void bear::visual::screen::subtract ( const rectangle_type& a, const rectangle_type& b, rectangle_list& result ) const { if ( !a.intersects(b) ) result.push_front(a); else { const rectangle_type inter = a.intersection(b); if ( (inter.width() <= 8) || (inter.height() <= 8) ) result.push_front(a); else { if ( a.left() != inter.left() ) result.push_front ( rectangle_type( a.left(), a.bottom(), inter.left(), a.top() ) ); if ( a.top() != inter.top() ) result.push_front ( rectangle_type ( inter.left(), inter.top(), inter.right(), a.top() ) ); if ( a.right() != inter.right() ) result.push_front ( rectangle_type ( inter.right(), a.bottom(), a.right(), a.top() ) ); if ( a.bottom() != inter.bottom() ) result.push_front ( rectangle_type ( inter.left(), a.bottom(), inter.right(), inter.bottom() ) ); } } } // screen::subtract()
/** * \brief Get the part of the sprite that is fully opaque. * \param r A fully opaque part of the sprite. */ void bear::visual::sprite::set_opaque_rectangle( const rectangle_type& r ) { CLAW_PRECOND( r.width() >= 0 ); CLAW_PRECOND( r.height() >= 0 ); m_opaque_rectangle = r; } // sprite::set_opaque_rectangle()
/** * \brief Tell if a rectangle intersects a rectangle from a list. * \param r The rectangle to check. * \param boxes The boxes to compare to. */ bool bear::visual::screen::intersects_any ( const rectangle_type& r, const rectangle_list& boxes ) const { bool result=false; rectangle_list::const_iterator it; for (it=boxes.begin(); !result && (it!=boxes.end()); ++it) if ( r.intersects(*it) ) { const rectangle_type inter = r.intersection(*it); result = (inter.width() > 0) && (inter.height() > 0); } return result; } // screen::intersects_any()
/** * \brief Split a scene element to only keep its visible parts and update the * screen cover. * \param e The element that will be rendered. * \param output The parts of \a e to render. * \param boxes The cover of the screen. */ void bear::visual::screen::split ( const scene_element& e, scene_element_list& output, rectangle_list& boxes ) const { e.burst(boxes, output); const rectangle_type r( e.get_opaque_box() ); const double opaque_box_min_size(0); if ( (r.width() > opaque_box_min_size) && (r.height() > opaque_box_min_size) ) { rectangle_list input_boxes; rectangle_list::const_iterator it; std::swap( input_boxes, boxes ); for ( it=input_boxes.begin(); it!=input_boxes.end(); ++it ) subtract( *it, r, boxes ); } } // screen::split()