* limitations under the License.
*
*/
+#include <algorithm>
#include <dali/dali.h>
+/** Controls the output of application logging. */
+//#define DEBUG_PRINT_GRID_DIAGNOSTICS
+
namespace Dali
{
namespace Demo
{
-namespace
-{
-const bool DEBUG_PRINT_GRID_DIAGNOSTICS = false;
-
-inline unsigned min( unsigned a, unsigned b )
-{
- return a < b ? a : b;
-}
-
-inline unsigned max( unsigned a, unsigned b )
-{
- return a > b ? a : b;
-}
-
-}
-
/**
* @brief A 2D grid of booleans, settable and gettable via integer (x,y) coordinates.
* */
*/
GridFlags( unsigned width, unsigned height ) : mCells( width * height ), mWidth( width ), mHeight( height ), mHighestUsedRow( 0 )
{
- if( DEBUG_PRINT_GRID_DIAGNOSTICS )
- {
+#ifdef DEBUG_PRINT_GRID_DIAGNOSTICS
fprintf(stderr, "Grid created with dimensions: (%u, %u).\n", mWidth, mHeight );
- }
+#endif
}
void Set( const unsigned x, const unsigned y )
{
const unsigned index = CellIndex( x, y );
mCells[index] += 1u; ///< += To allow a debug check of the number of times a cell is set.
- mHighestUsedRow = max( mHighestUsedRow, y );
+ mHighestUsedRow = std::max( mHighestUsedRow, y );
}
bool Get( unsigned x, unsigned y ) const
{
const unsigned regionWidth = (region.x + 0.5f);
const unsigned regionHeight = (region.y + 0.5f);
- if( DEBUG_PRINT_GRID_DIAGNOSTICS )
- {
+#ifdef DEBUG_PRINT_GRID_DIAGNOSTICS
fprintf( stderr, "Allocation requested for region (%u, %u). Result: ", regionWidth, regionHeight );
- }
+#endif
unsigned bestRegionWidth = 0;
unsigned bestRegionHeight = 0;
unsigned bestCellX = 0;
{
// Look for clear grid cells under the desired region:
- const unsigned clampedRegionHeight = min( regionHeight, mHeight - y);
- const unsigned clampedRegionWidth = min( regionWidth, mWidth - x);
+ const unsigned clampedRegionHeight = std::min( regionHeight, mHeight - y);
+ const unsigned clampedRegionWidth = std::min( regionWidth, mWidth - x);
const unsigned regionLimitY = y + clampedRegionHeight;
const unsigned regionLimitX = x + clampedRegionWidth;
if( bestRegionWidth == 0 || bestRegionHeight == 0 )
{
- if( DEBUG_PRINT_GRID_DIAGNOSTICS )
- {
+#ifdef DEBUG_PRINT_GRID_DIAGNOSTICS
fputs( "false.\n", stderr );
- }
+#endif
return false;
}
// Allocate the found region:
- if( DEBUG_PRINT_GRID_DIAGNOSTICS )
- {
+#ifdef DEBUG_PRINT_GRID_DIAGNOSTICS
fprintf( stderr, " - bestCellX = %u, bestCellY = %u, bestRegionWidth = %u, bestRegionHeight = %u - ", bestCellX, bestCellY, bestRegionWidth, bestRegionHeight );
- }
+#endif
for( unsigned y = bestCellY; y < bestCellY + bestRegionHeight; ++y )
{
for( unsigned x = bestCellX; x < bestCellX + bestRegionWidth; ++x )
outCellX = bestCellX;
outCellY = bestCellY;
outRegion = Vector2( bestRegionWidth, bestRegionHeight );
- if( DEBUG_PRINT_GRID_DIAGNOSTICS )
- {
+#ifdef DEBUG_PRINT_GRID_DIAGNOSTICS
fputs( "true.\n", stderr );
- }
+#endif
return true;
}
{
/** Controls the output of application logging. */
-const bool DEBUG_PRINT_DIAGNOSTICS = false;
+//#define DEBUG_PRINT_DIAGNOSTICS;
const char* BACKGROUND_IMAGE( DALI_IMAGE_DIR "background-4.jpg" );
const char* TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" );
*/
Image CreateImage(const std::string& filename, unsigned int width, unsigned int height, ImageAttributes::ScalingMode scalingMode )
{
- if( DEBUG_PRINT_DIAGNOSTICS )
- {
+#ifdef DEBUG_PRINT_DIAGNOSTICS
fprintf( stderr, "CreateImage(%s, %u, %u, scalingMode=%u)\n", filename.c_str(), width, height, unsigned( scalingMode ) );
- }
+#endif
ImageAttributes attributes;
attributes.SetSize( width, height );
bool allocated = grid.AllocateRegion( config->dimensions, cellX, cellY, imageGridDims );
if( !allocated )
{
- if( DEBUG_PRINT_DIAGNOSTICS )
- {
+#ifdef DEBUG_PRINT_DIAGNOSTICS
fprintf( stderr, "Failed to allocate image in grid with dims (%f, %f) and path: %s.\n", config->dimensions.x, config->dimensions.y, config->path );
- }
+#endif
continue;
}