示例#1
0
文件: screen.cpp 项目: yannicklm/bear
/**
 * \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()
示例#2
0
/**
 * \brief Align one box at the bottom of an other one.
 * \param this_box The box to which we will align the other.
 * \param that_old_pos The position from where comes the other box.
 * \param that_new_box (in/out) The box we will align.
 */
void bear::universe::align_bottom::align
( const rectangle_type& this_box, const position_type& that_old_pos,
  rectangle_type& that_new_box ) const
{
  that_new_box.top( this_box.bottom() );
} // align_bottom::align()