Browse Source

Merge pull request #88 from capnlove/ExplicitCell_GetWidth

Added ImageAsset.getExplicitCellWidth and ImageAsset.getExplicitCellHeight
Simon Love 12 years ago
parent
commit
7a4f9710fd

+ 27 - 0
engine/source/2d/assets/ImageAsset.cc

@@ -550,6 +550,33 @@ void ImageAsset::setCellHeight( const S32 cellheight )
     refreshAsset();
     refreshAsset();
 }
 }
 
 
+S32 ImageAsset::getExplicitCellWidth(const S32 cellIndex)
+{
+	if ( !getExplicitMode() )
+    {
+        // No, so warn.
+        Con::warnf( "ImageAsset() - Cannot perform explicit cell operation when not in explicit mode." );
+        return (0);
+    }
+    
+    ImageAsset::FrameArea::PixelArea thisCell = mExplicitFrames.at(cellIndex);
+    return(thisCell.mPixelWidth);
+
+}
+
+S32 ImageAsset::getExplicitCellHeight(const S32 cellIndex)
+{
+	if ( !getExplicitMode() )
+    {
+        // No, so warn.
+        Con::warnf( "ImageAsset() - Cannot perform explicit cell operation when not in explicit mode." );
+        return (0);
+	}
+	
+    ImageAsset::FrameArea::PixelArea thisCell = mExplicitFrames.at(cellIndex);
+    return(thisCell.mPixelHeight);
+
+}
 //------------------------------------------------------------------------------
 //------------------------------------------------------------------------------
 
 
 bool ImageAsset::clearExplicitCells( void )
 bool ImageAsset::clearExplicitCells( void )

+ 2 - 0
engine/source/2d/assets/ImageAsset.h

@@ -202,9 +202,11 @@ public:
 
 
     void                    setCellWidth( const S32 cellWidth );
     void                    setCellWidth( const S32 cellWidth );
     inline S32              getCellWidth( void ) const						{ return mCellWidth; }
     inline S32              getCellWidth( void ) const						{ return mCellWidth; }
+    S32                     getExplicitCellWidth(const S32 cellIndex);
 
 
     void                    setCellHeight( const S32 cellheight );
     void                    setCellHeight( const S32 cellheight );
     S32                     getCellHeight( void) const						{ return mCellHeight; }
     S32                     getCellHeight( void) const						{ return mCellHeight; }
+    S32                     getExplicitCellHeight(const S32 cellIndex);
 
 
     inline TextureHandle&   getImageTexture( void )                         { return mImageTextureHandle; }
     inline TextureHandle&   getImageTexture( void )                         { return mImageTextureHandle; }
     inline S32              getImageWidth( void ) const                     { return mImageTextureHandle.getWidth(); }
     inline S32              getImageWidth( void ) const                     { return mImageTextureHandle.getWidth(); }

+ 18 - 0
engine/source/2d/assets/ImageAsset_ScriptBinding.h

@@ -207,6 +207,24 @@ ConsoleMethod(ImageAsset, getCellWidth, S32, 2, 2,            "() Gets the CELL
     return object->getCellWidth();
     return object->getCellWidth();
 }
 }
 
 
+ConsoleMethod(ImageAsset, getExplicitCellWidth, S32, 3,3, "(CellIndex) Gets the CELL width in Explicit Mode.\n"
+                                                                        "@return the specified CELL width.")
+{
+	    // Fetch cell index.
+    const S32 cellIndex = dAtoi( argv[2] );
+
+    return(object->getExplicitCellWidth(cellIndex));
+}
+
+ConsoleMethod(ImageAsset, getExplicitCellHeight, S32, 3,3, "(CellIndex) Gets the CELL height in Explicit Mode.\n"
+                                                                        "@return the specified CELL height.")
+{
+	    // Fetch cell index.
+    const S32 cellIndex = dAtoi( argv[2] );
+
+    return(object->getExplicitCellHeight(cellIndex));
+
+}
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 
 
 ConsoleMethod(ImageAsset, setCellHeight, void, 3, 3,          "(Height) Sets the CELL height.\n"
 ConsoleMethod(ImageAsset, setCellHeight, void, 3, 3,          "(Height) Sets the CELL height.\n"