Removed and repleaced all Nodes delete without a previous close() call. This fixes a possible crash on UIListBox, UITable and UITabWidget.

Fixed UIWindow frame buffer pixel density.
Allow "text-decoration" CSS property.
Fixed a crash on the TextureAtlasEditor.
Added Action::getCurrentProgress().

--HG--
branch : dev
This commit is contained in:
Martín Lucas Golini
2019-11-26 04:21:41 -03:00
parent 634ea7f3cb
commit 246fa4bf80
33 changed files with 134 additions and 78 deletions

View File

@@ -69,9 +69,6 @@ class EE_API TextureAtlasLoader {
~TextureAtlasLoader();
/** In the case that the loader is threaded, to know if the texture atlas was loaded, the main thread must call Update to update the state of the load. And finish the job. */
void update();
/** Loads a texture atlas from its path ( the texture atlas binary is expected, not the texture, the ".eta" file ).
* If the loader is not threaded, it will load the atlas immediately.
* @param TextureAtlasPath The texture atlas path.
@@ -107,7 +104,7 @@ class EE_API TextureAtlasLoader {
/** @return True if the texture atlas is loaded. */
const bool& isLoaded() const;
/** @return True if the texture atlas is loading. */
const bool& isLoading() const;

View File

@@ -126,6 +126,8 @@ class EE_API Interpolation1d {
UintPtr getData() const;
void setData(const UintPtr & data);
Float getCurrentProgress();
protected:
UintPtr mData;
int mType;

View File

@@ -128,6 +128,8 @@ class EE_API Interpolation2d {
UintPtr getData() const;
void setData(const UintPtr & data);
Float getCurrentProgress();
protected:
UintPtr mData;
int mType;

View File

@@ -35,6 +35,8 @@ class EE_API Action {
virtual bool isDone() = 0;
virtual Float getCurrentProgress() = 0;
virtual Action * clone() const;
virtual Action * reverse() const;

View File

@@ -17,6 +17,8 @@ class EE_API ActionInterpolation1d : public Action {
bool isDone() override;
Float getCurrentProgress();
Interpolation1d * getInterpolation();
protected:
mutable Interpolation1d mInterpolation;

View File

@@ -17,6 +17,8 @@ class EE_API ActionInterpolation2d : public Action {
bool isDone() override;
Float getCurrentProgress() override;
Interpolation2d * getInterpolation();
protected:
mutable Interpolation2d mInterpolation;

View File

@@ -10,7 +10,7 @@ namespace EE { namespace Scene { namespace Actions {
class EE_API Delay : public Action {
public:
static Delay * New( const Time& time );
void start() override;
void stop() override;
@@ -19,6 +19,8 @@ class EE_API Delay : public Action {
bool isDone() override;
Float getCurrentProgress() override;
Action * clone() const override;
Action * reverse() const override;
@@ -26,11 +28,11 @@ class EE_API Delay : public Action {
protected:
Clock mClock;
Time mTime;
Delay( const Time& time );
};
}}}
}}}
#endif

View File

@@ -33,6 +33,8 @@ class EE_API MarginMove : public Action {
Action * reverse() const override;
Float getCurrentProgress();
Interpolation1d getInterpolationLeft() const;
void setInterpolationLeft(const Interpolation1d & interpolationLeft);

View File

@@ -25,6 +25,8 @@ class EE_API Sequence : public Action {
bool isDone() override;
Float getCurrentProgress();
Action * clone() const override;
Action * reverse() const override;
@@ -34,11 +36,11 @@ class EE_API Sequence : public Action {
protected:
std::vector<Action*> mSequence;
Uint32 mCurPos;
Sequence( const std::vector<Action*> sequence );
};
}}}
}}}
#endif

View File

@@ -25,6 +25,8 @@ class EE_API Spawn : public Action {
bool isDone() override;
Float getCurrentProgress();
Action * clone() const override;
Action * reverse() const override;
@@ -33,11 +35,11 @@ class EE_API Spawn : public Action {
protected:
std::vector<Action*> mSpawn;
bool mAllDone;
Spawn( const std::vector<Action*> spawn );
};
}}}
}}}
#endif

View File

@@ -36,6 +36,8 @@ class EE_API Tint : public Action {
Action * reverse() const override;
Float getCurrentProgress();
Interpolation1d getInterpolationR() const;
void setInterpolationR(const Interpolation1d & interpolationR);

View File

@@ -33,25 +33,6 @@ class EE_API TextureAtlasEditor {
bool isEdited() { return mEdited; }
protected:
class UITGEUpdater : public UINode
{
public:
explicit UITGEUpdater( TextureAtlasEditor * TGEditor ) :
UINode(),
mTGEditor( TGEditor )
{
subscribeScheduledUpdate();
}
~UITGEUpdater() {
}
virtual void scheduledUpdate( const Time& ) { mTGEditor->update(); }
protected:
TextureAtlasEditor * mTGEditor;
};
friend class UITGEUpdater;
UIWindow * mUIWindow;
Node * mUIContainer;
UITheme * mTheme;
@@ -68,7 +49,6 @@ class EE_API TextureAtlasEditor {
UIWinMenu * mWinMenu;
UIDropDownList * mTextureFilterList;
TextureAtlasTextureRegionEditor * mTextureRegionEditor;
UITGEUpdater * mTGEU;
bool mEdited;
void windowClose( const Event * Event );

View File

@@ -38,6 +38,8 @@ class EE_API UINodeDrawable : public Drawable {
bool isDone() override;
Float getCurrentProgress();
Action * clone() const override;
Action * reverse() const override;

View File

@@ -40,7 +40,7 @@ std::string Text::styleFlagToString( const Uint32& flags ) {
}
Uint32 Text::stringToStyleFlag( const std::string& str ) {
std::string valStr = str;
std::string valStr = String::trim( str );
String::toLowerInPlace( valStr );
std::vector<std::string> strings = String::split( valStr, '|' );
Uint32 flags = Text::Regular;

View File

@@ -117,11 +117,6 @@ void TextureAtlasLoader::setTextureFilter(const Texture::TextureFilter & texture
}
}
void TextureAtlasLoader::update() {
if ( mRL.isLoaded() && !mLoaded )
createTextureRegions();
}
void TextureAtlasLoader::loadFromStream( IOStream& IOS ) {
mRL.setThreaded( mThreaded );
@@ -158,12 +153,13 @@ void TextureAtlasLoader::loadFromStream( IOStream& IOS ) {
}
}
if ( !mSkipResourceLoad || ( !mSkipResourceLoad && 0 == mRL.getCount() ) ) {
if ( !mSkipResourceLoad ) {
mIsLoading = true;
mRL.load();
if ( !mThreaded || ( !mSkipResourceLoad && 0 == mRL.getCount() ) )
createTextureRegions();
mRL.load( [&]( ResourceLoader * ) {
if ( !mLoaded ) {
createTextureRegions();
}
} );
}
}
}
@@ -215,7 +211,7 @@ TextureAtlas * TextureAtlasLoader::getTextureAtlas() const {
void TextureAtlasLoader::createTextureRegions() {
mIsLoading = false;
bool IsAlreadyLoaded = false;
for ( Uint32 z = 0; z < mTempAtlass.size(); z++ ) {
sTempTexAtlas * tTexAtlas = &mTempAtlass[z];
sTextureHdr * tTexHdr = &tTexAtlas->Texture;

View File

@@ -293,6 +293,10 @@ void Interpolation1d::setData(const UintPtr & data) {
mData = data;
}
Float Interpolation1d::getCurrentProgress() {
return mCurTime >= mActP->t ? 1.f : mCurTime.asMilliseconds() / mActP->t.asMilliseconds();
}
const bool& Interpolation1d::getLoop() const {
return mLoop;
}

View File

@@ -288,6 +288,10 @@ void Interpolation2d::setData(const UintPtr & data)
mData = data;
}
Float Interpolation2d::getCurrentProgress() {
return mCurTime >= mActP->t ? 1.f : mCurTime.asMilliseconds() / mActP->t.asMilliseconds();
}
bool Interpolation2d::getLoop() const {
return mLoop;
}

View File

@@ -36,6 +36,10 @@ bool ActionInterpolation1d::isDone() {
return mInterpolation.ended();
}
Float ActionInterpolation1d::getCurrentProgress() {
return mInterpolation.getCurrentProgress();
}
Interpolation1d * ActionInterpolation1d::getInterpolation() {
return &mInterpolation;
}

View File

@@ -36,6 +36,10 @@ bool ActionInterpolation2d::isDone() {
return mInterpolation.ended();
}
Float ActionInterpolation2d::getCurrentProgress() {
return mInterpolation.getCurrentProgress();
}
Interpolation2d * ActionInterpolation2d::getInterpolation() {
return &mInterpolation;
}

View File

@@ -28,6 +28,10 @@ bool Delay::isDone() {
return mClock.getElapsedTime() >= mTime;
}
Float Delay::getCurrentProgress() {
return !isDone() ? mClock.getElapsedTime().asMilliseconds() / mTime.asMilliseconds() : 1.f;
}
Action *Delay::clone() const {
return New( mTime );
}

View File

@@ -151,4 +151,8 @@ Action * MarginMove::reverse() const {
return NULL;
}
}}}
Float MarginMove::getCurrentProgress() {
return mInterpolationLeft.getCurrentProgress();
}
}}}

View File

@@ -70,6 +70,10 @@ bool Sequence::isDone() {
return mCurPos == mSequence.size() - 1 && mSequence[ mCurPos ]->isDone();
}
Float Sequence::getCurrentProgress() {
return mCurPos / static_cast<Float>( mSequence.size() );
}
Action * Sequence::clone() const {
return Sequence::New( mSequence );
}
@@ -96,4 +100,4 @@ Sequence::Sequence( const std::vector<Action*> sequence ) :
mCurPos( 0 )
{}
}}}
}}}

View File

@@ -75,6 +75,16 @@ bool Spawn::isDone() {
return mAllDone;
}
Float Spawn::getCurrentProgress() {
Float min = 1.f;
for ( size_t i = 0; i < mSpawn.size(); i++ ) {
min = eemin( min, mSpawn[ i ]->getCurrentProgress() );
}
return min;
}
Action * Spawn::clone() const {
return Spawn::New( mSpawn );
}
@@ -101,4 +111,4 @@ Spawn::Spawn( const std::vector<Action*> spawn ) :
mAllDone( false )
{}
}}}
}}}

View File

@@ -119,6 +119,10 @@ Action * Tint::reverse() const {
return NULL;
}
Float Tint::getCurrentProgress() {
return mInterpolationR.getCurrentProgress();
}
void Tint::onUpdate( const Time& ) {
if ( NULL != mNode && mNode->isWidget() ) {
UIWidget * widget = static_cast<UIWidget*>( mNode );

View File

@@ -150,9 +150,6 @@ TextureAtlasEditor::TextureAtlasEditor( UIWindow * attachTo, const TGEditorClose
mUIContainer->addEventListener( Event::OnClose, cb::Make1( this, &TextureAtlasEditor::windowClose ) );
mUIContainer->find<UINode>("texture_atlas_editor_root")->setThemeSkin( mTheme, "winback" );
}
mTGEU = eeNew( UITGEUpdater, ( this ) );
mTGEU->setParent( mUIContainer );
}
TextureAtlasEditor::~TextureAtlasEditor() {
@@ -300,7 +297,8 @@ void TextureAtlasEditor::onTextureAtlasCreate( TexturePacker * TexPacker ) {
std::string FPath( FileSystem::fileRemoveExtension( mTexturePacker->getFilepath() + EE_TEXTURE_ATLAS_EXTENSION ) );
mTextureAtlasLoader = TextureAtlasLoader::New( FPath, true, cb::Make1( this, &TextureAtlasEditor::onTextureAtlasLoaded ) );
bool threaded = mUIWindow->getSceneNode()->getWindow()->isThreadedGLContext();
mTextureAtlasLoader = TextureAtlasLoader::New( FPath, threaded, cb::Make1( this, &TextureAtlasEditor::onTextureAtlasLoaded ) );
}
void TextureAtlasEditor::updateControls() {
@@ -386,25 +384,20 @@ void TextureAtlasEditor::onTextureRegionChange( const Event * Event ) {
}
}
void TextureAtlasEditor::update() {
if ( NULL != mTextureAtlasLoader && !mTextureAtlasLoader->isLoaded() ) {
mTextureAtlasLoader->update();
}
}
void TextureAtlasEditor::openTextureAtlas( const Event * Event ) {
eeSAFE_DELETE( mTextureAtlasLoader );
bool threaded = true;
#if EE_PLATFORM == EE_PLATFORM_EMSCRIPTEN
threaded = false;
#endif
bool threaded = mUIWindow->getSceneNode()->getWindow()->isThreadedGLContext();
mTextureAtlasLoader = TextureAtlasLoader::New( Event->getNode()->asType<UICommonDialog>()->getFullPath(), threaded, cb::Make1( this, &TextureAtlasEditor::onTextureAtlasLoaded ) );
}
void TextureAtlasEditor::onTextureAtlasLoaded( TextureAtlasLoader * ) {
if ( NULL != mTextureAtlasLoader && mTextureAtlasLoader->isLoaded() ) {
updateControls();
void TextureAtlasEditor::onTextureAtlasLoaded( TextureAtlasLoader * textureAtlasLoader ) {
mTextureAtlasLoader = textureAtlasLoader;
if ( mTextureAtlasLoader->isLoaded() ) {
mUIContainer->runOnMainThread( [&] {
updateControls();
} );
}
}

View File

@@ -233,8 +233,11 @@ void UIListBox::removeListBoxItems( std::vector<Uint32> ItemsIndex ) {
if ( !erase ) {
ItemsCpy.push_back( mItems[i] );
mTexts.push_back( mItems[i]->getText() );
} else {
eeSAFE_DELETE( mItems[i] ); // doesn't call to mItems[i]->Close(); because is not checking for close.
} else if ( NULL != mItems[i] ) {
mItems[i]->close();
mItems[i]->setVisible( false );
mItems[i]->setEnabled( false );
mItems[i] = NULL;
}
}
@@ -563,8 +566,11 @@ void UIListBox::updateScroll( bool fromScrollChange ) {
}
mVisibleLast = i;
} else {
eeSAFE_DELETE( mItems[i] );
} else if ( NULL != mItems[i] ) {
mItems[i]->close();
mItems[i]->setVisible( false );
mItems[i]->setEnabled( false );
mItems[i] = NULL;
item = NULL;
}
@@ -611,7 +617,10 @@ void UIListBox::updateScroll( bool fromScrollChange ) {
mVisibleLast = i;
} else {
eeSAFE_DELETE( mItems[i] );
mItems[i]->close();
mItems[i]->setVisible( false );
mItems[i]->setEnabled( false );
mItems[i] = NULL;
item = NULL;
}

View File

@@ -524,6 +524,10 @@ bool UINodeDrawable::MoveAction::isDone() {
return mElapsed.asMicroseconds() >= mDuration.asMicroseconds();
}
Float UINodeDrawable::MoveAction::getCurrentProgress() {
return mElapsed.asMilliseconds() / mDuration.asMilliseconds();
}
void UINodeDrawable::MoveAction::onStart() {
UINode * node = mNode->asType<UINode>();
LayerDrawable * layer = node->getBackground()->getLayer(0);

View File

@@ -383,8 +383,11 @@ void UITable::remove( std::vector<Uint32> ItemsIndex ) {
if ( !erase ) {
ItemsCpy.push_back( mItems[i] );
} else {
eeSAFE_DELETE( mItems[i] ); // doesn't call to mItems[i]->Close(); because is not checking for close.
} else if ( NULL != mItems[i] ) {
mItems[i]->close();
mItems[i]->setVisible( false );
mItems[i]->setEnabled( false );
mItems[i] = NULL;
}
}

View File

@@ -385,7 +385,10 @@ void UITabWidget::remove( const Uint32& Index ) {
mTabSelected->getControlOwned()->setEnabled( false );
}
eeSAFE_DELETE( mTabs[ Index ] );
mTabs[ Index ]->close();
mTabs[ Index ]->setVisible( false );
mTabs[ Index ]->setEnabled( false );
mTabs[ Index ] = NULL;
mTabs.erase( mTabs.begin() + Index );
@@ -417,7 +420,11 @@ void UITabWidget::remove( UITab * Tab ) {
void UITabWidget::removeAll() {
for ( Uint32 i = 0; i < mTabs.size(); i++ ) {
eeSAFE_DELETE( mTabs[ i ] );
if ( NULL != mTabs[ i ] ) {
mTabs[ i ]->close();
mTabs[ i ]->setVisible( false );
mTabs[ i ]->setEnabled( false );
}
}
mTabs.clear();

View File

@@ -617,7 +617,8 @@ bool UITextView::setAttribute( const NodeAttribute& attribute, const Uint32& sta
SAVE_NORMAL_STATE_ATTR( String::format( "%dpx", getCharacterSize() ) );
setCharacterSize( attribute.asDpDimensionI() );
} else if ( "font-style" == name || "textstyle" == name || "fontstyle" == name ) {
} else if ( "font-style" == name || "textstyle" == name || "fontstyle" == name ||
"text-decoration" == name || "textdecoration" == name ) {
Uint32 flags = attribute.asFontStyle();
SAVE_NORMAL_STATE_ATTR( Text::styleFlagToString( getFontStyle() ) );

View File

@@ -293,7 +293,8 @@ void UIWindow::drawFrameBuffer() {
if ( mFrameBuffer->hasColorBuffer() ) {
mFrameBuffer->draw( Rect( 0, 0, mSize.getWidth(), mSize.getHeight() ), Rect( mScreenPos.x, mScreenPos.y, mScreenPos.x + mSize.getWidth(), mScreenPos.y + mSize.getHeight() ) );
} else {
TextureRegion textureRegion( mFrameBuffer->getTexture()->getTextureId(), Rect( 0, 0, mSize.getWidth(), mSize.getHeight() ) );
Rect r( 0, 0, mSize.getWidth(), mSize.getHeight() );
TextureRegion textureRegion( mFrameBuffer->getTexture()->getTextureId(), r, r.getSize().asFloat() );
textureRegion.draw( mScreenPosi.x, mScreenPosi.y, Color::White, getRotation(), getScale() );
}
}

View File

@@ -183,6 +183,7 @@ bool WindowSDL::create( WindowSettings Settings, ContextSettings Context ) {
}
#else
mGLContext = SDL_GL_CreateContext( mSDLWindow );
mWindow.ContextConfig.SharedGLContext = false;
#endif
if ( NULL == mGLContext

View File

@@ -42,7 +42,7 @@ EE_MAIN_FUNC int main (int argc, char * argv []) {
Display * currentDisplay = Engine::instance()->getDisplayManager()->getDisplayIndex(0);
Float pixelDensity = PixelDensity::toFloat( currentDisplay->getPixelDensity() );
win = Engine::instance()->createWindow( WindowSettings( 1280, 720, "eepp - Texture Atlas Editor", WindowStyle::Default, WindowBackend::Default, 32, "assets/icon/ee.png", pixelDensity ), ContextSettings( true, GLv_default, true, 24, 1, 0, false ) );
win = Engine::instance()->createWindow( WindowSettings( 1280, 720, "eepp - Texture Atlas Editor", WindowStyle::Default, WindowBackend::Default, 32, "assets/icon/ee.png", pixelDensity ), ContextSettings( true, GLv_default, true, 24, 1, 0, true ) );
if ( win->isOpen() ) {
PixelDensity::setPixelDensity( eemax( win->getScale(), pixelDensity ) );