Set TextureFilter to Texture Atlas.

--HG--
branch : dev-2.1
This commit is contained in:
Martín Lucas Golini
2018-01-26 02:25:53 -03:00
parent d4e5d84631
commit 3bb3475238
9 changed files with 137 additions and 63 deletions

View File

@@ -5,6 +5,8 @@
namespace EE { namespace Graphics { namespace Private {
#pragma pack(push, 1)
#define HDR_NAME_SIZE 64
typedef struct sTextureRegionHdrSN {
@@ -43,7 +45,8 @@ typedef struct sTextureAtlasHdrSN {
Int32 Height;
Uint32 PixelBorder;
Uint32 Flags;
char Reserved[16];
char TextureFilter;
char Reserved[15];
} sTextureAtlasHdr;
#define HDR_TEXTURE_ATLAS_ALLOW_FLIPPING ( 1 << 0 )
@@ -53,6 +56,8 @@ typedef struct sTextureAtlasHdrSN {
#define EE_TEXTURE_ATLAS_MAGIC ( ( 'E' << 0 ) | ( 'E' << 8 ) | ( 'T' << 16 ) | ( 'A' << 24 ) )
#define EE_TEXTURE_ATLAS_EXTENSION ".eta"
#pragma pack(pop)
}}}
#endif

View File

@@ -122,6 +122,10 @@ class EE_API TextureAtlasLoader {
/** Sets a load notification callback. */
void setLoadCallback( GLLoadCallback LoadCallback );
sTextureAtlasHdr getTextureAtlasHeader();
void setTextureFilter( const Texture::TextureFilter& textureFilter );
protected:
ResourceLoader mRL;
std::string mTextureAtlasPath;
@@ -132,7 +136,7 @@ class EE_API TextureAtlasLoader {
bool mIsLoading;
TextureAtlas * mTextureAtlas;
GLLoadCallback mLoadCallback;
std::vector<Texture*> mTexuresLoaded;
std::vector<Texture*> mTexturesLoaded;
typedef struct sTempTexAtlasS {
sTextureHdr Texture;

View File

@@ -35,6 +35,7 @@
#include <eepp/graphics/base.hpp>
#include <eepp/graphics/packerhelper.hpp>
#include <eepp/graphics/image.hpp>
#include <eepp/graphics/texture.hpp>
#include <eepp/graphics/pixeldensity.hpp>
namespace EE { namespace Graphics {
@@ -55,11 +56,12 @@ class EE_API TexturePacker {
* @param MaxWidth The maximum width that the texture atlas will use.
* @param MaxHeight The maximum height that the texture atlas will use.
* @param PixelDensity Indicates the device pixel density that represents the resources that will the packer pack.
* @param textureFilter Indicates with texture filter should be used when the texture of the atlas is loaded
* @param ForcePowOfTwo Indicates that if the max with and height must be adjusted to fit a power of two texture.
* @param PixelBorder Indicates how many pixels will be added to separate one image to another in the texture atlas. Usefull to avoid artifacts when rendered scaled TextureRegions. Use at least 1 pixel to separate images if you will scale any TextureRegion.
* @param AllowFlipping Indicates if the images can be flipped inside the texture atlas. This is not compatible with eepp ( since it can't flip the textures back to the original orientation ). So avoid it for eepp.
*/
TexturePacker( const Uint32& MaxWidth, const Uint32& MaxHeight, const EE_PIXEL_DENSITY& PixelDensity = PD_MDPI, const bool& ForcePowOfTwo = true, const Uint32& PixelBorder = 0, const bool& AllowFlipping = false );
TexturePacker( const Uint32& MaxWidth, const Uint32& MaxHeight, const EE_PIXEL_DENSITY& PixelDensity = PD_MDPI, const bool& ForcePowOfTwo = true, const Uint32& PixelBorder = 0, const Texture::TextureFilter& textureFilter = Texture::TextureFilter::Linear, const bool& AllowFlipping = false );
~TexturePacker();
@@ -92,11 +94,12 @@ class EE_API TexturePacker {
* @param MaxWidth The maximum width that the texture atlas will use.
* @param MaxHeight The maximum height that the texture atlas will use.
* @param PixelDensity Indicates the device pixel density that represents the resources that will the packer pack.
* @param ForcePowOfTwo Indicates that if the max with and height must be adjusted to fit a power of two texture.
* @param textureFilter Indicates with texture filter should be used when the texture of the atlas is loaded
* @param PixelBorder Indicates how many pixels will be added to separate one image to another in the texture atlas. Usefull to avoid artifacts when rendered scaled TextureRegions. Use at least 1 pixel to separate images if you will scale any TextureRegion.
* @param ForcePowOfTwo Indicates that if the max with and height must be adjusted to fit a power of two texture.
* @param AllowFlipping Indicates if the images can be flipped inside the texture atlas. This is not compatible with eepp ( since it can't flip the textures back to the original orientation ). So avoid it for eepp.
*/
void setOptions( const Uint32& MaxWidth, const Uint32& MaxHeight, const EE_PIXEL_DENSITY& PixelDensity = PD_MDPI, const bool& ForcePowOfTwo = true, const Uint32& PixelBorder = 0, const bool& AllowFlipping = false );
void setOptions( const Uint32& MaxWidth, const Uint32& MaxHeight, const EE_PIXEL_DENSITY& PixelDensity = PD_MDPI, const bool& ForcePowOfTwo = true, const Uint32& PixelBorder = 0, const Texture::TextureFilter& textureFilter = Texture::TextureFilter::Linear, const bool& AllowFlipping = false );
/** @return The texture atlas to generate width. */
const Int32& getWidth() const;
@@ -131,8 +134,9 @@ class EE_API TexturePacker {
bool mForcePowOfTwo;
Int32 mPixelBorder;
EE_PIXEL_DENSITY mPixelDensity;
Texture::TextureFilter mTextureFilter;
bool mSaveExtensions;
Image::SaveType mFormat;
Image::SaveType mFormat;
TexturePacker * getChild() const;

View File

@@ -5,6 +5,7 @@
#include <eepp/ui/uiwindow.hpp>
#include <eepp/ui/uispinbox.hpp>
#include <eepp/ui/uilistbox.hpp>
#include <eepp/ui/uidropdownlist.hpp>
#include <eepp/ui/uiwinmenu.hpp>
#include <eepp/graphics/texturepacker.hpp>
#include <eepp/graphics/textureatlasloader.hpp>
@@ -52,6 +53,7 @@ class EE_API TextureAtlasEditor {
UISpinBox * mSpinDestH;
UIListBox * mTextureRegionList;
UIWinMenu * mWinMenu;
UIDropDownList * mTextureFilterList;
TextureAtlasTextureRegionEditor * mTextureRegionEditor;
UITGEUpdater * mTGEU;
@@ -89,6 +91,8 @@ class EE_API TextureAtlasEditor {
void onHBOffset( const UIEvent * Event );
void onTextureFilterChange( const UIEvent * Event );
void onTextureAtlasLoaded( TextureAtlasLoader * TGLoader );
void update();

View File

@@ -83,6 +83,21 @@ void TextureAtlasLoader::setLoadCallback( GLLoadCallback LoadCallback ) {
mLoadCallback = LoadCallback;
}
sTextureAtlasHdr TextureAtlasLoader::getTextureAtlasHeader() {
return mTexGrHdr;
}
void TextureAtlasLoader::setTextureFilter(const Texture::TextureFilter & textureFilter) {
mTexGrHdr.TextureFilter = (char)textureFilter;
size_t count = getTextureAtlas()->getTexturesCount() == 0;
if ( count > 0 ) {
for ( size_t i = 0; i < count; i++ )
getTextureAtlas()->getTexture( i )->setFilter( textureFilter );
}
}
void TextureAtlasLoader::update() {
mRL.update();
@@ -196,7 +211,7 @@ void TextureAtlasLoader::createTextureRegions() {
Texture * tTex = TextureFactory::instance()->getByName( path );
if ( NULL != tTex )
mTexuresLoaded.push_back( tTex );
mTexturesLoaded.push_back( tTex );
// Create the Texture Atlas with the name of the real texture, not the Childs ( example load 1.png and not 1_ch1.png )
if ( 0 == z ) {
@@ -250,8 +265,11 @@ void TextureAtlasLoader::createTextureRegions() {
}
}
if ( NULL != mTextureAtlas && mTexuresLoaded.size() ) {
mTextureAtlas->setTextures( mTexuresLoaded );
if ( NULL != mTextureAtlas && mTexturesLoaded.size() ) {
for ( size_t i = 0; i < mTexturesLoaded.size(); i++ )
mTexturesLoaded[i]->setFilter( (Texture::TextureFilter)mTexGrHdr.TextureFilter );
mTextureAtlas->setTextures( mTexturesLoaded );
}
mLoaded = true;
@@ -278,12 +296,12 @@ const bool& TextureAtlasLoader::isLoading() const {
}
Texture * TextureAtlasLoader::getTexture( const Uint32& texnum ) const {
eeASSERT( texnum < mTexuresLoaded.size() );
return mTexuresLoaded[ texnum ];
eeASSERT( texnum < mTexturesLoaded.size() );
return mTexturesLoaded[ texnum ];
}
Uint32 TextureAtlasLoader::getTexturesLoadedCount() {
return mTexuresLoaded.size();
return mTexturesLoaded.size();
}
bool TextureAtlasLoader::updateTextureAtlas() {
@@ -414,7 +432,7 @@ bool TextureAtlasLoader::updateTextureAtlas( std::string TextureAtlasPath, std::
std::string tapath( FileSystem::fileRemoveExtension( TextureAtlasPath ) + "." + Image::saveTypeToExtension( mTexGrHdr.Format ) );
if ( 2 == NeedUpdate ) {
TexturePacker tp( mTexGrHdr.Width, mTexGrHdr.Height, pixelDensity, 0 != ( mTexGrHdr.Flags & HDR_TEXTURE_ATLAS_POW_OF_TWO ), mTexGrHdr.PixelBorder, mTexGrHdr.Flags & HDR_TEXTURE_ATLAS_ALLOW_FLIPPING );
TexturePacker tp( mTexGrHdr.Width, mTexGrHdr.Height, pixelDensity, 0 != ( mTexGrHdr.Flags & HDR_TEXTURE_ATLAS_POW_OF_TWO ), mTexGrHdr.PixelBorder, (Texture::TextureFilter)mTexGrHdr.TextureFilter, mTexGrHdr.Flags & HDR_TEXTURE_ATLAS_ALLOW_FLIPPING );
tp.addTexturesPath( ImagesPath );

View File

@@ -9,7 +9,7 @@
namespace EE { namespace Graphics {
TexturePacker::TexturePacker( const Uint32& MaxWidth, const Uint32& MaxHeight, const EE_PIXEL_DENSITY& PixelDensity, const bool& ForcePowOfTwo, const Uint32& PixelBorder, const bool& AllowFlipping ) :
TexturePacker::TexturePacker(const Uint32& MaxWidth, const Uint32& MaxHeight, const EE_PIXEL_DENSITY& PixelDensity, const bool& ForcePowOfTwo, const Uint32& PixelBorder, const Texture::TextureFilter& textureFilter, const bool& AllowFlipping ) :
mTotalArea(0),
mFreeList(NULL),
mWidth(128),
@@ -22,9 +22,13 @@ TexturePacker::TexturePacker( const Uint32& MaxWidth, const Uint32& MaxHeight, c
mParent(NULL),
mPlacedCount(0),
mForcePowOfTwo(true),
mPixelBorder(0)
mPixelBorder(0),
mPixelDensity(PixelDensity),
mTextureFilter(textureFilter),
mSaveExtensions(false),
mFormat(Image::SaveType::SAVE_TYPE_PNG)
{
setOptions( MaxWidth, MaxHeight, PixelDensity, ForcePowOfTwo, PixelBorder, AllowFlipping );
setOptions( MaxWidth, MaxHeight, PixelDensity, ForcePowOfTwo, PixelBorder, textureFilter, AllowFlipping );
}
TexturePacker::TexturePacker() :
@@ -41,9 +45,12 @@ TexturePacker::TexturePacker() :
mParent(NULL),
mPlacedCount(0),
mForcePowOfTwo(true),
mPixelBorder(0)
{
}
mPixelBorder(0),
mPixelDensity(PD_MDPI),
mTextureFilter(Texture::TextureFilter::Linear),
mSaveExtensions(false),
mFormat(Image::SaveType::SAVE_TYPE_PNG)
{}
TexturePacker::~TexturePacker()
{
@@ -108,7 +115,7 @@ Uint32 TexturePacker::getAtlasNumChannels() {
return maxChannels;
}
void TexturePacker::setOptions( const Uint32& MaxWidth, const Uint32& MaxHeight, const EE_PIXEL_DENSITY& PixelDensity, const bool& ForcePowOfTwo, const Uint32& PixelBorder, const bool& AllowFlipping ) {
void TexturePacker::setOptions( const Uint32& MaxWidth, const Uint32& MaxHeight, const EE_PIXEL_DENSITY& PixelDensity, const bool& ForcePowOfTwo, const Uint32& PixelBorder, const Texture::TextureFilter& textureFilter, const bool& AllowFlipping ) {
if ( !mTextures.size() ) { // only can change the dimensions before adding any texture
mMaxSize.x = MaxWidth;
mMaxSize.y = MaxHeight;
@@ -123,6 +130,7 @@ void TexturePacker::setOptions( const Uint32& MaxWidth, const Uint32& MaxHeight,
mAllowFlipping = AllowFlipping;
mPixelBorder = PixelBorder;
mPixelDensity = PixelDensity;
mTextureFilter = textureFilter;
}
}
@@ -370,7 +378,7 @@ void TexturePacker::insertTexture( TexturePackerTex * t, TexturePackerNode * bes
}
void TexturePacker::createChild() {
mChild = eeNew( TexturePacker, ( mWidth, mHeight, mPixelDensity, mForcePowOfTwo, mPixelBorder, mAllowFlipping ) );
mChild = eeNew( TexturePacker, ( mWidth, mHeight, mPixelDensity, mForcePowOfTwo, mPixelBorder, mTextureFilter, mAllowFlipping ) );
std::list<TexturePackerTex*>::iterator it;
std::list< std::list<TexturePackerTex*>::iterator > remove;
@@ -652,8 +660,10 @@ void TexturePacker::saveTextureRegions() {
TexGrHdr.Height = mHeight;
TexGrHdr.PixelBorder = mPixelBorder;
TexGrHdr.Flags = 0;
TexGrHdr.TextureFilter = mTextureFilter;
memset( TexGrHdr.Reserved, 0, 16 );
int reservedSize = eeARRAY_SIZE(TexGrHdr.Reserved);
memset( TexGrHdr.Reserved, 0, reservedSize );
if ( mAllowFlipping )
TexGrHdr.Flags |= HDR_TEXTURE_ATLAS_ALLOW_FLIPPING;

View File

@@ -64,7 +64,12 @@ TextureAtlasEditor::TextureAtlasEditor( UIWindow * AttatchTo, const TGEditorClos
" <TextureAtlasTextureRegionEditor layout_width='match_parent' layout_height='match_parent' layout_weight='1' "
" flags='clip' backgroundColor='#00000032' borderWidth='1' borderColor='#000000FF' />"
" <LinearLayout orientation='vertical' layout_width='205dp' layout_height='match_parent' layout_marginLeft='8dp' layout_marginRight='8dp'>"
" <TextView text='TextureRegion List:' fontStyle='shadow' layout_marginTop='4dp' layout_marginBottom='8dp' />"
" <TextView text='Texture Filter:' fontStyle='shadow' layout_marginTop='4dp' layout_marginBottom='4dp' />"
" <DropDownList id='textureFilter' layout_width='match_parent' layout_height='wrap_content' layout_gravity='center_vertical' selectedText='Linear'>"
" <item>Linear</item>"
" <item>Nearest</item>"
" </DropDownList>"
" <TextView text='TextureRegion List:' fontStyle='shadow' layout_marginTop='8dp' layout_marginBottom='8dp' />"
" <ListBox id='TextureRegionList' layout_width='match_parent' layout_height='144dp' />"
" <TextView text='Current TextureRegion:' fontStyle='shadow' layout_marginTop='16dp' layout_marginBottom='16dp' />"
" <LinearLayout orientation='horizontal' layout_width='match_parent' layout_height='wrap_content'>"
@@ -116,6 +121,9 @@ TextureAtlasEditor::TextureAtlasEditor( UIWindow * AttatchTo, const TGEditorClos
mUIContainer->bind( "destH", mSpinDestH );
mSpinDestH->addEventListener( UIEvent::OnValueChange, cb::Make1( this, &TextureAtlasEditor::onDestHChange ) );
mUIContainer->bind( "textureFilter", mTextureFilterList );
mTextureFilterList->addEventListener( UIEvent::OnItemSelected, cb::Make1( this, &TextureAtlasEditor::onTextureFilterChange ) );
mUIContainer->find<UIPushButton>( "resetDest" )->addEventListener( UIEvent::MouseClick, cb::Make1( this, &TextureAtlasEditor::onResetDestSize ) );
mUIContainer->find<UIPushButton>( "resetOff" )->addEventListener( UIEvent::MouseClick, cb::Make1( this, &TextureAtlasEditor::onResetOffset ) );
@@ -256,6 +264,15 @@ void TextureAtlasEditor::fileMenuClick( const UIEvent * Event ) {
}
}
void TextureAtlasEditor::onTextureFilterChange( const UIEvent * Event ) {
if ( NULL == mTextureAtlasLoader || NULL == mTextureAtlasLoader->getTextureAtlas() || !mTextureAtlasLoader->isLoaded() )
return;
Texture::TextureFilter textureFilter = mTextureFilterList->getText() == "Nearest" ? Texture::TextureFilter::Nearest : Texture::TextureFilter::Linear;
mTextureAtlasLoader->setTextureFilter( textureFilter );
}
void TextureAtlasEditor::onTextureAtlasCreate( TexturePacker * TexPacker ) {
eeSAFE_DELETE( mTexturePacker );
mTexturePacker = TexPacker;
@@ -269,6 +286,8 @@ void TextureAtlasEditor::onTextureAtlasCreate( TexturePacker * TexPacker ) {
void TextureAtlasEditor::updateControls() {
if ( NULL != mTextureAtlasLoader && mTextureAtlasLoader->isLoaded() ) {
mTextureFilterList->getListBox()->setSelected( mTextureAtlasLoader->getTextureAtlasHeader().TextureFilter );
fillTextureRegionList();
}
}

View File

@@ -18,8 +18,8 @@ TextureAtlasNew::TextureAtlasNew( TGCreateCb NewTGCb ) :
return;
mUIWindow = UIWindow::New();
mUIWindow->setSizeWithDecoration( 378, 283 )
->setMinWindowSize( 378, 283 )
mUIWindow->setSizeWithDecoration( 378, 303 )
->setMinWindowSize( 378, 303 )
->setWinFlags( UI_WIN_CLOSE_BUTTON | UI_WIN_USE_DEFAULT_BUTTONS_ACTIONS | UI_WIN_SHARE_ALPHA_WITH_CHILDS | UI_WIN_MODAL );
mUIWindow->addEventListener( UIEvent::OnWindowClose, cb::Make1( this, &TextureAtlasNew::windowClose ) );
@@ -27,39 +27,46 @@ TextureAtlasNew::TextureAtlasNew( TGCreateCb NewTGCb ) :
std::string layout =
"<LinearLayout id='container' layout_width='match_parent' layout_height='wrap_content' layout_marginLeft='8dp' layout_marginRight='8dp' layout_marginTop='8dp'>"
" <LinearLayout layout_width='match_parent' layout_height='wrap_content' orientation='horizontal' layout_marginBottom='8dp'>"
" <TextView layout_width='match_parent' layout_weight='0.7' layout_height='wrap_content' layout_gravity='center_vertical' text='Save File Format:' />"
" <DropDownList id='saveType' layout_width='match_parent' layout_weight='0.3' layout_height='wrap_content' layout_gravity='center_vertical' selectedText='PNG'>"
" <item>TGA</item>"
" <item>BMP</item>"
" <item>PNG</item>"
" <item>DDS</item>"
" <item>JPG</item>"
" </DropDownList>"
" </LinearLayout>"
" <LinearLayout layout_width='match_parent' layout_height='wrap_content' orientation='horizontal' layout_marginBottom='8dp'>"
" <TextView layout_width='match_parent' layout_weight='0.7' layout_height='wrap_content' layout_gravity='center_vertical' text='Max. Texture Atlas Width:' />"
" <ComboBox id='maxTAWidth' layout_width='match_parent' layout_weight='0.3' layout_height='wrap_content' layout_gravity='center_vertical' onlyNumbers='true' />"
" </LinearLayout>"
" <LinearLayout layout_width='match_parent' layout_height='wrap_content' orientation='horizontal' layout_marginBottom='8dp'>"
" <TextView layout_width='match_parent' layout_weight='0.7' layout_height='wrap_content' layout_gravity='center_vertical' text='Max. Texture Atlas Height:' />"
" <ComboBox id='maxTAHeight' layout_width='match_parent' layout_weight='0.3' layout_height='wrap_content' layout_gravity='center_vertical' onlyNumbers='true' />"
" </LinearLayout>"
" <LinearLayout layout_width='match_parent' layout_height='wrap_content' orientation='horizontal' layout_marginBottom='8dp'>"
" <TextView layout_width='match_parent' layout_weight='0.7' layout_height='wrap_content' layout_gravity='center_vertical' text='Space between sub textures (pixels):' />"
" <SpinBox id='pixelSpace' layout_width='match_parent' layout_weight='0.3' layout_height='wrap_content' layout_gravity='center_vertical' />"
" </LinearLayout>"
" <LinearLayout layout_width='match_parent' layout_height='wrap_content' orientation='horizontal' layout_marginBottom='8dp'>"
" <TextView layout_width='match_parent' layout_weight='0.7' layout_height='wrap_content' layout_gravity='center_vertical' text='Pixel Density:' />"
" <DropDownList id='pixelDensity' layout_width='match_parent' layout_weight='0.3' layout_height='wrap_content' layout_gravity='center_vertical' selectedText='MDPI'>"
" <item>MDPI</item>"
" <item>HDPI</item>"
" <item>XHDPI</item>"
" <item>XXHDPI</item>"
" <item>XXXHDPI</item>"
" </DropDownList>"
" </LinearLayout>"
" <TextView layout_width='match_parent' layout_height='wrap_content' layout_gravity='center_vertical' text='TextureAtlas Folder Path:' />"
" <LinearLayout layout_width='match_parent' layout_height='wrap_content' orientation='horizontal' layout_marginBottom='8dp'>"
" <TextView layout_width='match_parent' layout_weight='0.7' layout_height='wrap_content' layout_gravity='center_vertical' text='Save File Format:' />"
" <DropDownList id='saveType' layout_width='match_parent' layout_weight='0.3' layout_height='wrap_content' layout_gravity='center_vertical' selectedText='PNG'>"
" <item>TGA</item>"
" <item>BMP</item>"
" <item>PNG</item>"
" <item>DDS</item>"
" <item>JPG</item>"
" </DropDownList>"
" </LinearLayout>"
" <LinearLayout layout_width='match_parent' layout_height='wrap_content' orientation='horizontal' layout_marginBottom='8dp'>"
" <TextView layout_width='match_parent' layout_weight='0.7' layout_height='wrap_content' layout_gravity='center_vertical' text='Max. Texture Atlas Width:' />"
" <ComboBox id='maxTAWidth' layout_width='match_parent' layout_weight='0.3' layout_height='wrap_content' layout_gravity='center_vertical' onlyNumbers='true' />"
" </LinearLayout>"
" <LinearLayout layout_width='match_parent' layout_height='wrap_content' orientation='horizontal' layout_marginBottom='8dp'>"
" <TextView layout_width='match_parent' layout_weight='0.7' layout_height='wrap_content' layout_gravity='center_vertical' text='Max. Texture Atlas Height:' />"
" <ComboBox id='maxTAHeight' layout_width='match_parent' layout_weight='0.3' layout_height='wrap_content' layout_gravity='center_vertical' onlyNumbers='true' />"
" </LinearLayout>"
" <LinearLayout layout_width='match_parent' layout_height='wrap_content' orientation='horizontal' layout_marginBottom='8dp'>"
" <TextView layout_width='match_parent' layout_weight='0.7' layout_height='wrap_content' layout_gravity='center_vertical' text='Space between sub textures (pixels):' />"
" <SpinBox id='pixelSpace' layout_width='match_parent' layout_weight='0.3' layout_height='wrap_content' layout_gravity='center_vertical' />"
" </LinearLayout>"
" <LinearLayout layout_width='match_parent' layout_height='wrap_content' orientation='horizontal' layout_marginBottom='8dp'>"
" <TextView layout_width='match_parent' layout_weight='0.7' layout_height='wrap_content' layout_gravity='center_vertical' text='Pixel Density:' />"
" <DropDownList id='pixelDensity' layout_width='match_parent' layout_weight='0.3' layout_height='wrap_content' layout_gravity='center_vertical' selectedText='MDPI'>"
" <item>MDPI</item>"
" <item>HDPI</item>"
" <item>XHDPI</item>"
" <item>XXHDPI</item>"
" <item>XXXHDPI</item>"
" </DropDownList>"
" </LinearLayout>"
" <LinearLayout layout_width='match_parent' layout_height='wrap_content' orientation='horizontal' layout_marginBottom='8dp'>"
" <TextView layout_width='match_parent' layout_weight='0.7' layout_height='wrap_content' layout_gravity='center_vertical' text='Save File Format:' />"
" <DropDownList id='textureFilter' layout_width='match_parent' layout_weight='0.3' layout_height='wrap_content' layout_gravity='center_vertical' selectedText='Linear'>"
" <item>Linear</item>"
" <item>Nearest</item>"
" </DropDownList>"
" </LinearLayout>"
" <TextView layout_width='match_parent' layout_height='wrap_content' layout_gravity='center_vertical' text='TextureAtlas Folder Path:' />"
" <LinearLayout layout_width='match_parent' layout_height='wrap_content' orientation='horizontal' layout_marginBottom='8dp'>"
" <TextInput id='pathInput' layout_width='match_parent' layout_height='match_parent' layout_weight='1' allowEditing='false' />"
" <PushButton id='openPath' layout_width='32dp' layout_height='wrap_content' text='...' />"
@@ -79,6 +86,7 @@ TextureAtlasNew::TextureAtlasNew( TGCreateCb NewTGCb ) :
mUIWindow->bind( "pixelDensity", mPixelDensity );
mUIWindow->bind( "pathInput", mTGPath );
mUIWindow->bind( "openPath", mSetPathButton ) ;
mUIWindow->bind( "textureFilter", mTextureFilter );
std::vector<String> Sizes;
@@ -144,13 +152,14 @@ void TextureAtlasNew::textureAtlasSave( const UIEvent * Event ) {
bool Res1 = String::fromString<Int32>( w, mComboWidth->getText() );
bool Res2 = String::fromString<Int32>( h, mComboHeight->getText() );
b = static_cast<Int32>( mPixelSpace->getValue() );
Texture::TextureFilter textureFilter = mTextureFilter->getText() == "Nearest" ? Texture::TextureFilter::Nearest : Texture::TextureFilter::Linear;
if ( Res1 && Res2 ) {
Graphics::TexturePacker * TexturePacker = eeNew( Graphics::TexturePacker, ( w, h, PixelDensity::fromString( mPixelDensity->getText() ), false, b ) );
TexturePacker * texturePacker = eeNew( TexturePacker, ( w, h, PixelDensity::fromString( mPixelDensity->getText() ), false, b, textureFilter ) );
TexturePacker->addTexturesPath( mTGPath->getText() );
texturePacker->addTexturesPath( mTGPath->getText() );
TexturePacker->packTextures();
texturePacker->packTextures();
std::string ext = FileSystem::fileExtension( FPath, true );
@@ -164,10 +173,10 @@ void TextureAtlasNew::textureAtlasSave( const UIEvent * Event ) {
FPath += "." + ext;
}
TexturePacker->save( FPath, static_cast<Image::SaveType> ( mSaveFileType->getListBox()->getItemSelectedIndex() ) );
texturePacker->save( FPath, static_cast<Image::SaveType> ( mSaveFileType->getListBox()->getItemSelectedIndex() ) );
if ( mNewTGCb.IsSet() )
mNewTGCb( TexturePacker );
mNewTGCb( texturePacker );
mUIWindow->closeWindow();
}

View File

@@ -28,6 +28,7 @@ class EE_API TextureAtlasNew {
UIPushButton * mSetPathButton;
UIDropDownList * mSaveFileType;
UIDropDownList * mPixelDensity;
UIDropDownList * mTextureFilter;
void windowClose( const UIEvent * Event );