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; }
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; }
Canvas(int w, int h) : needToSort(false), w(w), h(h) { topLefts.push_back( Coord(0,0) ); }
void Sort() { if(!needToSort) return; topLefts.sort(TopToBottomLeftToRightSort()); needToSort = false; }
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; }