Example #1
0
        bool Place(Content<_T> content)
        {
            Sort();

            for( Coord::List::iterator itor = topLefts.begin(); itor != topLefts.end(); itor++ )
            {
                content.coord = *itor;

                if( Fits( content ) )
                {
                    Use( content );
                    topLefts.erase( itor );
                    return true;
                }
            }

            return false; // yvt: BitmapAtlasGenerator doesn't support rotated contents.

            // EXPERIMENTAL - TRY ROTATED?
        //    content.Rotate();
        //    for(Coord::List::iterator itor = topLefts.begin(); itor != topLefts.end(); itor++)
        //    {
        //        content.coord = *itor;

        //        if( Fits( content ) )
        //        {
        //            Use( content );
        //            topLefts.erase( itor );
        //            return true;
        //        }
        //    }
        //    ////////////////////////////////

        //    return false;
        }
Example #2
0
 bool Use(const Content<_T> &content) {
  
   const Size  &size = content.size;
   const Coord &coord = content.coord;
   
   topLefts.push_front	( Coord( coord.x + size.w, coord.y          ) );
   topLefts.push_back	( Coord( coord.x         , coord.y + size.h ) );
   
   contentVector.push_back( content );
   
   needToSort = true;
   
   return true;
 }
Example #3
0
 Canvas(int w, int h)
   : needToSort(false),
     w(w),
     h(h)
 {  
   topLefts.push_back( Coord(0,0) );
 }
Example #4
0
 void Sort() {
   
   if(!needToSort)
     return;
 
   topLefts.sort(TopToBottomLeftToRightSort());
   
   needToSort = false;
 }
Example #5
0
  bool Place(Content<_T> content) {
     
    Sort();
    
    for( Coord::List::iterator itor = topLefts.begin(); itor != topLefts.end(); itor++ ) {
      
      content.coord = *itor;
      
      if( Fits( content ) ) {
	
	Use( content );
	topLefts.erase( itor );
	return true;
      }
    }
    
    // EXPERIMENTAL - TRY ROTATED?
    content.Rotate();
    for( Coord::List::iterator itor = topLefts.begin(); itor != topLefts.end(); itor++ ) {
      
      content.coord = *itor;
      
      if( Fits( content ) ) {
	
	Use( content );
	topLefts.erase( itor );
	return true;
      }
    }
    ////////////////////////////////
    
    
    return false;
  }