diff --git a/include/eepp/graphics/ninepatch.hpp b/include/eepp/graphics/ninepatch.hpp index 80ae8d101..595f9fc7f 100644 --- a/include/eepp/graphics/ninepatch.hpp +++ b/include/eepp/graphics/ninepatch.hpp @@ -25,10 +25,13 @@ class EE_API NinePatch : public DrawableResource { static NinePatch* New( const Uint32& TexId, int left, int top, int right, int bottom, const Float& pixelDensity = 1, const std::string& name = "" ); + static NinePatch* New( Texture* tex, int left, int top, int right, int bottom, + const Float& pixelDensity = 1, const std::string& name = "" ); + static NinePatch* New( TextureRegion* textureRegion, int left, int top, int right, int bottom, const std::string& name = "" ); - NinePatch( const Uint32& TexId, int left, int top, int right, int bottom, + NinePatch( Texture* tex, int left, int top, int right, int bottom, const Float& pixelDensity = 1, const std::string& name = "" ); NinePatch( TextureRegion* textureRegion, int left, int top, int right, int bottom, @@ -58,7 +61,7 @@ class EE_API NinePatch : public DrawableResource { Sizef mDestSize; Float mPixelDensity; - void createFromTexture( const Uint32& TexId, int left, int top, int right, int bottom ); + void createFromTexture( Texture* tex, int left, int top, int right, int bottom ); virtual void onAlphaChange(); diff --git a/include/eepp/graphics/sprite.hpp b/include/eepp/graphics/sprite.hpp index 9f30cf332..49bc6cda3 100644 --- a/include/eepp/graphics/sprite.hpp +++ b/include/eepp/graphics/sprite.hpp @@ -201,6 +201,17 @@ class EE_API Sprite : public Drawable { const Vector2i& offset = Vector2i( 0, 0 ), const Rect& TexSector = Rect( 0, 0, 0, 0 ) ); + /** Creates an static sprite (no animation). It creates a new TextureRegion. + * @param tex The texture + * @param DestSize The destination size of the TextureRegion created + * @param offset The offset added to the position of the frame ( the TextureRegion ) + * @param TexSector The texture sector to be rendered ( default all the texture ) + * @return True if success + */ + bool createStatic( Texture* tex, const Sizef& DestSize = Sizef( 0, 0 ), + const Vector2i& offset = Vector2i( 0, 0 ), + const Rect& TexSector = Rect( 0, 0, 0, 0 ) ); + /** Creates an animated sprite * @param SubFramesNum The number of subframes of the sprite */ @@ -217,6 +228,17 @@ class EE_API Sprite : public Drawable { const Vector2i& offset = Vector2i( 0, 0 ), const Rect& TexSector = Rect( 0, 0, 0, 0 ) ); + /** Add a frame to the sprite (on the current sub frame) + * @param tex The texture + * @param DestSize The destination size of the frame + * @param offset The offset added to the position of the frame + * @param TexSector The texture sector to be rendered ( default all the texture ) + * @return The frame position or 0 if fails + */ + unsigned int addFrame( Texture* tex, const Sizef& DestSize = Sizef( 0, 0 ), + const Vector2i& offset = Vector2i( 0, 0 ), + const Rect& TexSector = Rect( 0, 0, 0, 0 ) ); + /** Add a frame to the sprite (on the current sub frame) * @param TextureRegion The TextureRegion used in the frame * @return The frame position or 0 if fails @@ -235,6 +257,20 @@ class EE_API Sprite : public Drawable { bool addFramesByPatternId( const Uint32& TextureRegionId, const std::string& extension, TextureAtlas* SearchInTextureAtlas ); + /** Add a frame on an specific subframe to the sprite + * @param tex The texture + * @param NumFrame The Frame Number + * @param NumSubFrame The Sub Frame Number + * @param DestSize The destination size of the frame + * @param offset The offset added to the x position of the frame + * @param TexSector The texture sector to be rendered ( default all the texture ) + * @return True if success + */ + bool addSubFrame( Texture* tex, const unsigned int& NumFrame, const unsigned int& NumSubFrame, + const Sizef& DestSize = Sizef( 0, 0 ), + const Vector2i& offset = Vector2i( 0, 0 ), + const Rect& TexSector = Rect( 0, 0, 0, 0 ) ); + /** Add a frame on an specific subframe to the sprite * @param TexId The internal Texture Id * @param NumFrame The Frame Number diff --git a/include/eepp/graphics/textureatlas.hpp b/include/eepp/graphics/textureatlas.hpp index 6565b0cd7..4576d511d 100644 --- a/include/eepp/graphics/textureatlas.hpp +++ b/include/eepp/graphics/textureatlas.hpp @@ -58,6 +58,40 @@ class EE_API TextureAtlas : public ResourceManager { TextureRegion* add( const Uint32& TexId, const Rect& SrcRect, const Sizef& DestSize, const Vector2i& Offset, const std::string& Name = "" ); + /** Creates and add to the texture atlas a TextureRegion from a Texture. It will use the full + *Texture as a TextureRegion. + * @param tex The texture + * @param Name The texture name ( if any ) + */ + TextureRegion* add( Texture* tex, const std::string& Name = "" ); + + /** Creates and add to the texture atlas a TextureRegion of the indicated part of the texture. + * @param tex The texture + * @param SrcRect The texture part that will be used as the TextureRegion. + * @param Name The texture name ( if any ) + */ + TextureRegion* add( Texture* tex, const Rect& SrcRect, const std::string& Name = "" ); + + /** Creates and add to the texture atlas a TextureRegion of the indicated part of the texture. + * @param tex The texture + * @param SrcRect The texture part that will be used as the TextureRegion. + * @param DestSize The destination size that the TextureRegion will have when rendered. + * @param Name The texture name ( if any ) + */ + TextureRegion* add( Texture* tex, const Rect& SrcRect, const Sizef& DestSize, + const std::string& Name = "" ); + + /** Creates and add to the texture atlas a TextureRegion of the indicated part of the texture. + * @param tex The texture + * @param SrcRect The texture part that will be used as the TextureRegion. + * @param DestSize The destination size that the TextureRegion will have when rendered. + * @param Offset The offset that will be added to the position passed when any Draw call is + *used. + * @param Name The texture name ( if any ) + */ + TextureRegion* add( Texture* tex, const Rect& SrcRect, const Sizef& DestSize, + const Vector2i& Offset, const std::string& Name = "" ); + /** @return The texture atlas name. */ const std::string& getName() const; diff --git a/include/eepp/graphics/texturefactory.hpp b/include/eepp/graphics/texturefactory.hpp index a4b69306f..03879dd82 100644 --- a/include/eepp/graphics/texturefactory.hpp +++ b/include/eepp/graphics/texturefactory.hpp @@ -28,9 +28,9 @@ class EE_API TextureFactory : protected Mutex { * display them, will convert RGB to DXT1, RGBA to DXT5 ) * @param KeepLocalCopy Keep the array data copy. ( useful if want to reload the texture ) * @param Filename A filename to recognize the texture. - * @return Internal Texture Id + * @return The created texture */ - Uint32 createEmptyTexture( + Texture* createEmptyTexture( const unsigned int& Width, const unsigned int& Height, const unsigned int& Channels = 4, const Color& DefaultColor = Color( 0, 0, 0, 255 ), const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge, @@ -49,14 +49,14 @@ class EE_API TextureFactory : protected Mutex { * @param KeepLocalCopy Keep the array data copy. ( useful if want to reload the texture ) * @param FileName A filename to recognize the texture ( the path in case that was loaded from * outside the texture factory ). - * @return Internal Texture Id + * @return The texture loaded or null if error */ - Uint32 loadFromPixels( const unsigned char* Pixels, const unsigned int& Width, - const unsigned int& Height, const unsigned int& Channels, - const bool& Mipmap = false, - const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge, - const bool& CompressTexture = false, const bool& KeepLocalCopy = false, - const std::string& FileName = std::string( "" ) ); + Texture* loadFromPixels( const unsigned char* Pixels, const unsigned int& Width, + const unsigned int& Height, const unsigned int& Channels, + const bool& Mipmap = false, + const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge, + const bool& CompressTexture = false, const bool& KeepLocalCopy = false, + const std::string& FileName = std::string( "" ) ); /** Load a texture from Pack file * @param Pack Pointer to the pack instance @@ -68,9 +68,9 @@ class EE_API TextureFactory : protected Mutex { * @param KeepLocalCopy Keep the array data copy. ( useful if want to reload the texture ) * @param imageformatConfiguration The specific image format configuration to use when decoding * the image. - * @return Internal Texture Id + * @return The texture loaded or null if error */ - Uint32 loadFromPack( + Texture* loadFromPack( Pack* Pack, const std::string& FilePackPath, const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge, const bool& CompressTexture = false, const bool& KeepLocalCopy = false, @@ -86,9 +86,9 @@ class EE_API TextureFactory : protected Mutex { * @param KeepLocalCopy Keep the array data copy. ( useful if want to reload the texture ) * @param imageformatConfiguration The specific image format configuration to use when decoding * the image. - * @return The internal Texture Id + * @return The texture loaded or null if error */ - Uint32 loadFromMemory( + Texture* loadFromMemory( const unsigned char* ImagePtr, const unsigned int& Size, const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge, const bool& CompressTexture = false, const bool& KeepLocalCopy = false, @@ -103,9 +103,9 @@ class EE_API TextureFactory : protected Mutex { * @param KeepLocalCopy Keep the array data copy. ( useful if want to reload the texture ) * @param imageformatConfiguration The specific image format configuration to use when decoding * the image. - * @return The internal Texture Id + * @return The texture loaded or null if error */ - Uint32 loadFromStream( + Texture* loadFromStream( IOStream& Stream, const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge, const bool& CompressTexture = false, const bool& KeepLocalCopy = false, @@ -120,9 +120,9 @@ class EE_API TextureFactory : protected Mutex { * @param KeepLocalCopy Keep the array data copy. ( useful if want to reload the texture ) * @param imageformatConfiguration The specific image format configuration to use when decoding * the image. - * @return The internal Texture Id + * @return The texture loaded or null if error */ - Uint32 loadFromFile( + Texture* loadFromFile( const std::string& Filepath, const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge, const bool& CompressTexture = false, const bool& KeepLocalCopy = false, diff --git a/include/eepp/graphics/textureregion.hpp b/include/eepp/graphics/textureregion.hpp index fa7040ad3..500ba089e 100644 --- a/include/eepp/graphics/textureregion.hpp +++ b/include/eepp/graphics/textureregion.hpp @@ -24,41 +24,51 @@ class EE_API TextureRegion : public DrawableResource { static TextureRegion* New( const Uint32& TexId, const Rect& srcRect, const Sizef& destSize, const Vector2i& offset, const std::string& name = "" ); + static TextureRegion* New( Texture* tex, const std::string& name = "" ); + + static TextureRegion* New( Texture* tex, const Rect& srcRect, const std::string& name = "" ); + + static TextureRegion* New( Texture* tex, const Rect& srcRect, const Sizef& destSize, + const std::string& name = "" ); + + static TextureRegion* New( Texture* tex, const Rect& srcRect, const Sizef& destSize, + const Vector2i& offset, const std::string& name = "" ); + /** Creates an empty TextureRegion */ TextureRegion(); /** Creates a TextureRegion from a Texture. It will use the full Texture as a TextureRegion. - * @param TexId The texture id + * @param tex The texture * @param name The texture name ( if any ) */ - TextureRegion( const Uint32& TexId, const std::string& name = "" ); + TextureRegion( Texture* tex, const std::string& name = "" ); /** Creates a TextureRegion of the indicated part of the texture. - * @param TexId The texture id + * @param tex The texture * @param srcRect The texture part that will be used as the TextureRegion. * @param name The texture name ( if any ) */ - TextureRegion( const Uint32& TexId, const Rect& srcRect, const std::string& name = "" ); + TextureRegion( Texture* tex, const Rect& srcRect, const std::string& name = "" ); /** Creates a TextureRegion of the indicated part of the texture. - * @param TexId The texture id + * @param tex The texture * @param srcRect The texture part that will be used as the TextureRegion. * @param destSize The destination size that the TextureRegion will have when rendered. * @param name The texture name ( if any ) */ - TextureRegion( const Uint32& TexId, const Rect& srcRect, const Sizef& destSize, + TextureRegion( Texture* tex, const Rect& srcRect, const Sizef& destSize, const std::string& name = "" ); /** Creates a TextureRegion of the indicated part of the texture. - * @param TexId The texture id + * @param tex The texture * @param srcRect The texture part that will be used as the TextureRegion. * @param destSize The destination size that the TextureRegion will have when rendered. * @param offset The offset that will be added to the position passed when any Draw call is *used. * @param name The texture name ( if any ) */ - TextureRegion( const Uint32& TexId, const Rect& srcRect, const Sizef& destSize, - const Vector2i& offset, const std::string& name = "" ); + TextureRegion( Texture* tex, const Rect& srcRect, const Sizef& destSize, const Vector2i& offset, + const std::string& name = "" ); virtual ~TextureRegion(); @@ -92,13 +102,15 @@ class EE_API TextureRegion : public DrawableResource { void draw( const Float& X, const Float& Y, const Color& color = Color::White, const Float& Angle = 0.f, const Vector2f& Scale = Vector2f::One, - const BlendMode& Blend = BlendMode::Alpha(), const RenderMode& Effect = RENDER_NORMAL, + const BlendMode& Blend = BlendMode::Alpha(), + const RenderMode& Effect = RENDER_NORMAL, OriginPoint Center = OriginPoint( OriginPoint::OriginCenter ) ); void draw( const Float& X, const Float& Y, const Float& Angle, const Vector2f& Scale, const Color& Color0 = Color::White, const Color& Color1 = Color::White, const Color& Color2 = Color::White, const Color& Color3 = Color::White, - const BlendMode& Blend = BlendMode::Alpha(), const RenderMode& Effect = RENDER_NORMAL, + const BlendMode& Blend = BlendMode::Alpha(), + const RenderMode& Effect = RENDER_NORMAL, OriginPoint Center = OriginPoint( OriginPoint::OriginCenter ) ); void draw( const Quad2f Q, const Vector2f& offset = Vector2f(), const Float& Angle = 0.f, diff --git a/include/eepp/scene/scenemanager.hpp b/include/eepp/scene/scenemanager.hpp index 37912dba2..194a88d58 100644 --- a/include/eepp/scene/scenemanager.hpp +++ b/include/eepp/scene/scenemanager.hpp @@ -35,7 +35,7 @@ class EE_API SceneManager { void update(); - bool isShootingDown() const; + bool isShuttingDown() const; UISceneNode* getUISceneNode(); @@ -46,7 +46,7 @@ class EE_API SceneManager { protected: Clock mClock; UISceneNode* mUISceneNode; - bool mIsShootingDown; + bool mIsShuttingDown; std::vector mSceneNodes; }; diff --git a/include/eepp/system/process.hpp b/include/eepp/system/process.hpp index ffd3bf2de..3a59b5d1e 100644 --- a/include/eepp/system/process.hpp +++ b/include/eepp/system/process.hpp @@ -192,7 +192,8 @@ class EE_API Process { void startShutdown(); /** Indicates if the process started its shutdown */ - const bool& isShootingDown(); + const bool& isShuttingDown(); + protected: void* mProcess{ nullptr }; bool mShuttingDown{ false }; diff --git a/include/eepp/ui/models/filesystemmodel.hpp b/include/eepp/ui/models/filesystemmodel.hpp index cfe74b699..a3ea53cd8 100644 --- a/include/eepp/ui/models/filesystemmodel.hpp +++ b/include/eepp/ui/models/filesystemmodel.hpp @@ -39,7 +39,7 @@ class EE_API FileSystemModel : public Model { DisplayConfig() {} DisplayConfig( bool sortByName, bool foldersFirst, bool ignoreHidden, - std::vector acceptedExtensions = {}, + const std::vector& acceptedExtensions = {}, std::function fileIsVisibleFn = nullptr ) : sortByName( sortByName ), foldersFirst( foldersFirst ), @@ -145,7 +145,7 @@ class EE_API FileSystemModel : public Model { static std::shared_ptr New( const std::string& rootPath, const Mode& mode = Mode::FilesAndDirectories, - const DisplayConfig displayConfig = DisplayConfig() ); + const DisplayConfig& displayConfig = DisplayConfig() ); const Mode& getMode() const { return mMode; } @@ -200,7 +200,7 @@ class EE_API FileSystemModel : public Model { Node& nodeRef( const ModelIndex& index ) const; FileSystemModel( const std::string& rootPath, const Mode& mode, - const DisplayConfig displayConfig ); + const DisplayConfig& displayConfig ); size_t getFileIndex( Node* parent, const FileInfo& file ); diff --git a/src/eepp/graphics/drawablesearcher.cpp b/src/eepp/graphics/drawablesearcher.cpp index c5fb55b05..710747ad6 100644 --- a/src/eepp/graphics/drawablesearcher.cpp +++ b/src/eepp/graphics/drawablesearcher.cpp @@ -71,7 +71,7 @@ static Drawable* parseDataURI( const std::string& name ) { } } - Uint32 texId = 0; + Texture* tex = nullptr; if ( !format.empty() && ( Image::isImageExtension( "." + format ) || format == "svg+xml" ) ) { Image::FormatConfiguration format; @@ -85,22 +85,21 @@ static Drawable* parseDataURI( const std::string& name ) { ScopedBuffer buffer( bufSize ); int len = Base64::decode( base64Size, &name[fileStart], bufSize, buffer.get() ); if ( len > 0 ) - texId = TextureFactory::instance()->loadFromMemory( + tex = TextureFactory::instance()->loadFromMemory( buffer.get(), len, false, Texture::ClampMode::ClampToEdge, false, false, format ); } else if ( decodingType == "urldecode" ) { int fileStart = formatAndEncSep + 1; std::string decoded( URI::decode( name.substr( fileStart ) ) ); if ( !decoded.empty() ) { - texId = TextureFactory::instance()->loadFromMemory( + tex = TextureFactory::instance()->loadFromMemory( (const unsigned char*)decoded.c_str(), decoded.size(), false, Texture::ClampMode::ClampToEdge, false, false, format ); } } } - if ( texId > 0 ) { - Texture* tex = TextureFactory::instance()->getTexture( texId ); + if ( tex ) { tex->setName( hash ); drawable = tex; } @@ -151,22 +150,20 @@ Drawable* DrawableSearcher::searchByName( const std::string& name, bool firstSea drawable = TextureFactory::instance()->getByName( filePath ); if ( NULL == drawable ) { - Uint32 texId = TextureFactory::instance()->loadFromFile( filePath ); + Texture* tex = TextureFactory::instance()->loadFromFile( filePath ); - if ( texId > 0 ) - drawable = TextureFactory::instance()->getTexture( texId ); + if ( tex ) + drawable = tex; } } else if ( String::startsWith( name, "http://" ) || String::startsWith( name, "https://" ) ) { Texture* texture = TextureFactory::instance()->getByName( name ); if ( NULL == texture && Engine::instance()->isSharedGLContextEnabled() ) { - Uint32 texId = TextureFactory::instance()->createEmptyTexture( + texture = TextureFactory::instance()->createEmptyTexture( 1, 1, 4, Color::Transparent, false, Texture::ClampMode::ClampToEdge, false, false, name ); - texture = TextureFactory::instance()->getTexture( texId ); - Http::getAsync( [=]( const Http&, Http::Request&, Http::Response& response ) { if ( !response.getBody().empty() ) { diff --git a/src/eepp/graphics/fontbmfont.cpp b/src/eepp/graphics/fontbmfont.cpp index 696f93e0b..336f4e49d 100644 --- a/src/eepp/graphics/fontbmfont.cpp +++ b/src/eepp/graphics/fontbmfont.cpp @@ -118,14 +118,14 @@ bool FontBMFont::loadFromStream( IOStream& stream ) { } } - Uint32 texId = TF->loadFromPixels( rgbaImg.getPixelsPtr(), rgbaImg.getWidth(), + Texture* tex = TF->loadFromPixels( rgbaImg.getPixelsPtr(), rgbaImg.getWidth(), rgbaImg.getHeight(), rgbaImg.getChannels() ); - mPages[mFontSize].texture = TF->getTexture( texId ); + mPages[mFontSize].texture = tex; } else { - Uint32 texId = TF->loadFromPixels( img.getPixelsPtr(), img.getWidth(), + Texture* tex = TF->loadFromPixels( img.getPixelsPtr(), img.getWidth(), img.getHeight(), img.getChannels() ); - mPages[mFontSize].texture = TF->getTexture( texId ); + mPages[mFontSize].texture = tex; } if ( NULL != mPages[mFontSize].texture ) { diff --git a/src/eepp/graphics/fontsprite.cpp b/src/eepp/graphics/fontsprite.cpp index 70dd1f30f..67f6e1bfb 100644 --- a/src/eepp/graphics/fontsprite.cpp +++ b/src/eepp/graphics/fontsprite.cpp @@ -140,9 +140,8 @@ bool FontSprite::loadFromStream( IOStream& stream, Color key, Uint32 firstChar, img.createMaskFromColor( Color::Fuchsia, 0 ); - Uint32 texId = TextureFactory::instance()->loadFromPixels( img.getPixelsPtr(), img.getWidth(), + Texture* texture = TextureFactory::instance()->loadFromPixels( img.getPixelsPtr(), img.getWidth(), img.getHeight(), img.getChannels() ); - Texture* texture = TextureFactory::instance()->getTexture( texId ); mPages[mFontSize].texture = texture; if ( NULL != texture ) { texture->setFilter( Texture::Filter::Nearest ); diff --git a/src/eepp/graphics/fonttruetype.cpp b/src/eepp/graphics/fonttruetype.cpp index 3dbda2d76..1e198c6da 100644 --- a/src/eepp/graphics/fonttruetype.cpp +++ b/src/eepp/graphics/fonttruetype.cpp @@ -1177,10 +1177,9 @@ FontTrueType::Page::Page( const Uint32 fontInternalId ) : image.setPixel( x, y, Color( 255, 255, 255, 255 ) ); // Create the texture - Uint32 texId = TextureFactory::instance()->loadFromPixels( + texture = TextureFactory::instance()->loadFromPixels( image.getPixelsPtr(), image.getWidth(), image.getHeight(), image.getChannels(), false, Texture::ClampMode::ClampToEdge, false, true ); - texture = TextureFactory::instance()->getTexture( texId ); texture->setCoordinateType( Texture::CoordinateType::Pixels ); } diff --git a/src/eepp/graphics/framebufferfbo.cpp b/src/eepp/graphics/framebufferfbo.cpp index 9dfb411fe..530beb764 100644 --- a/src/eepp/graphics/framebufferfbo.cpp +++ b/src/eepp/graphics/framebufferfbo.cpp @@ -163,11 +163,11 @@ bool FrameBufferFBO::create( const Uint32& Width, const Uint32& Height, bool Ste } else { if ( NULL == mTexture ) { - Uint32 TexId = TextureFactory::instance()->createEmptyTexture( Width, Height, channels, + Texture* tex = TextureFactory::instance()->createEmptyTexture( Width, Height, channels, Color::Transparent ); - if ( TextureFactory::instance()->existsId( TexId ) ) { - mTexture = TextureFactory::instance()->getTexture( TexId ); + if ( tex ) { + mTexture = tex; } else { Log::error( "FrameBufferFBO::create: failed to create texture" ); return false; @@ -277,7 +277,7 @@ void FrameBufferFBO::draw( const Vector2f& position, const Sizef& size ) { void FrameBufferFBO::draw( Rect src, Rect dst ) { if ( NULL != mTexture ) { - TextureRegion textureRegion( getTexture()->getTextureId(), src ); + TextureRegion textureRegion( getTexture(), src ); Sizei size( dst.getSize() ); textureRegion.setDestSize( Sizef( size.x, size.y ) ); textureRegion.draw( dst.Left, dst.Top, Color::White ); @@ -311,13 +311,13 @@ void FrameBufferFBO::bindFrameBuffer() { GLi->bindFramebuffer( GL_FRAMEBUFFER, mFrameBuffer ); if ( !mDepthBuffer && !mStencilBuffer ) { - const GLenum discards[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT}; + const GLenum discards[] = { GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT }; GLi->discardFramebuffer( GL_FRAMEBUFFER, 2, discards ); } else if ( !mDepthBuffer ) { - const GLenum discards[] = {GL_DEPTH_ATTACHMENT}; + const GLenum discards[] = { GL_DEPTH_ATTACHMENT }; GLi->discardFramebuffer( GL_FRAMEBUFFER, 1, discards ); } else if ( !mStencilBuffer ) { - const GLenum discards[] = {GL_STENCIL_ATTACHMENT}; + const GLenum discards[] = { GL_STENCIL_ATTACHMENT }; GLi->discardFramebuffer( GL_FRAMEBUFFER, 1, discards ); } } diff --git a/src/eepp/graphics/ninepatch.cpp b/src/eepp/graphics/ninepatch.cpp index 77d5ca039..455c4ab96 100644 --- a/src/eepp/graphics/ninepatch.cpp +++ b/src/eepp/graphics/ninepatch.cpp @@ -6,7 +6,8 @@ namespace EE { namespace Graphics { NinePatch* NinePatch::New( const Uint32& TexId, int left, int top, int right, int bottom, const Float& pixelDensity, const std::string& name ) { - return eeNew( NinePatch, ( TexId, left, top, right, bottom, pixelDensity, name ) ); + return eeNew( NinePatch, ( TextureFactory::instance()->getTexture( TexId ), left, top, right, + bottom, pixelDensity, name ) ); } NinePatch* NinePatch::New( TextureRegion* textureRegion, int left, int top, int right, int bottom, @@ -14,7 +15,7 @@ NinePatch* NinePatch::New( TextureRegion* textureRegion, int left, int top, int return eeNew( NinePatch, ( textureRegion, left, top, right, bottom, name ) ); } -NinePatch::NinePatch( const Uint32& TexId, int left, int top, int right, int bottom, +NinePatch::NinePatch( Texture* tex, int left, int top, int right, int bottom, const Float& pixelDensity, const std::string& name ) : DrawableResource( Drawable::NINEPATCH, name ), mRect( left, top, right, bottom ), @@ -22,12 +23,10 @@ NinePatch::NinePatch( const Uint32& TexId, int left, int top, int right, int bot for ( Int32 i = 0; i < SideCount; i++ ) mDrawable[i] = NULL; - Texture* tex = TextureFactory::instance()->getTexture( TexId ); - if ( NULL != tex ) { mSize = tex->getPixelsSize(); - createFromTexture( TexId, left, top, right, bottom ); + createFromTexture( tex, left, top, right, bottom ); } } @@ -48,7 +47,7 @@ NinePatch::NinePatch( TextureRegion* textureRegion, int left, int top, int right mSize = r.getSize(); - createFromTexture( tex->getTextureId(), left, top, right, bottom ); + createFromTexture( tex, left, top, right, bottom ); for ( int i = 0; i < SideCount; i++ ) { TextureRegion* side = static_cast( mDrawable[i] ); @@ -73,8 +72,8 @@ NinePatch::~NinePatch() { } Sizef NinePatch::getSize() { - return Sizef( ( Float )( ( Int32 )( mSize.getWidth() / mPixelDensity ) ), - ( Float )( ( Int32 )( mSize.getHeight() / mPixelDensity ) ) ); + return Sizef( (Float)( (Int32)( mSize.getWidth() / mPixelDensity ) ), + (Float)( (Int32)( mSize.getHeight() / mPixelDensity ) ) ); } Sizef NinePatch::getPixelsSize() { @@ -117,27 +116,27 @@ TextureRegion* NinePatch::getTextureRegion( const int& side ) { return NULL; } -void NinePatch::createFromTexture( const Uint32& TexId, int left, int top, int right, int bottom ) { +void NinePatch::createFromTexture( Texture* tex, int left, int top, int right, int bottom ) { Rect r; r = Rect( 0, top, left, mSize.getHeight() - bottom ); - mDrawable[Left] = TextureRegion::New( TexId, r, r.getSize().asFloat() ); + mDrawable[Left] = TextureRegion::New( tex, r, r.getSize().asFloat() ); r = Rect( mSize.getWidth() - right, top, mSize.getWidth(), mSize.getHeight() - bottom ); - mDrawable[Right] = TextureRegion::New( TexId, r, r.getSize().asFloat() ); + mDrawable[Right] = TextureRegion::New( tex, r, r.getSize().asFloat() ); r = Rect( left, mSize.getHeight() - bottom, mSize.getWidth() - right, mSize.getHeight() ); - mDrawable[Down] = TextureRegion::New( TexId, r, r.getSize().asFloat() ); + mDrawable[Down] = TextureRegion::New( tex, r, r.getSize().asFloat() ); r = Rect( left, 0, mSize.getWidth() - right, top ); - mDrawable[Up] = TextureRegion::New( TexId, r, r.getSize().asFloat() ); + mDrawable[Up] = TextureRegion::New( tex, r, r.getSize().asFloat() ); r = Rect( 0, 0, left, top ); - mDrawable[UpLeft] = TextureRegion::New( TexId, r, r.getSize().asFloat() ); + mDrawable[UpLeft] = TextureRegion::New( tex, r, r.getSize().asFloat() ); r = Rect( mSize.getWidth() - right, 0, mSize.getWidth(), top ); - mDrawable[UpRight] = TextureRegion::New( TexId, r, r.getSize().asFloat() ); + mDrawable[UpRight] = TextureRegion::New( tex, r, r.getSize().asFloat() ); r = Rect( 0, mSize.getHeight() - bottom, left, mSize.getHeight() ); - mDrawable[DownLeft] = TextureRegion::New( TexId, r, r.getSize().asFloat() ); + mDrawable[DownLeft] = TextureRegion::New( tex, r, r.getSize().asFloat() ); r = Rect( mSize.getWidth() - right, mSize.getHeight() - bottom, mSize.getWidth(), mSize.getHeight() ); - mDrawable[DownRight] = TextureRegion::New( TexId, r, r.getSize().asFloat() ); + mDrawable[DownRight] = TextureRegion::New( tex, r, r.getSize().asFloat() ); r = Rect( left, top, mSize.getWidth() - right, mSize.getHeight() - bottom ); - mDrawable[Center] = TextureRegion::New( TexId, r, r.getSize().asFloat() ); + mDrawable[Center] = TextureRegion::New( tex, r, r.getSize().asFloat() ); mRect = Rect( left, top, right, bottom ); diff --git a/src/eepp/graphics/sprite.cpp b/src/eepp/graphics/sprite.cpp index 3cd6549cd..eebdf724e 100644 --- a/src/eepp/graphics/sprite.cpp +++ b/src/eepp/graphics/sprite.cpp @@ -279,12 +279,25 @@ bool Sprite::createStatic( TextureRegion* TextureRegion ) { return true; } -bool Sprite::createStatic( const Uint32& TexId, const Sizef& DestSize, const Vector2i& Offset, +bool Sprite::createStatic( const Uint32& TexId, const Sizef& DestSize, const Vector2i& offset, const Rect& TexSector ) { if ( TextureFactory::instance()->existsId( TexId ) ) { reset(); - addFrame( TexId, DestSize, Offset, TexSector ); + addFrame( TexId, DestSize, offset, TexSector ); + + return true; + } + + return false; +} + +bool Sprite::createStatic( Texture* tex, const Sizef& DestSize, const Vector2i& offset, + const Rect& TexSector ) { + if ( tex ) { + reset(); + + addFrame( tex->getTextureId(), DestSize, offset, TexSector ); return true; } @@ -394,6 +407,25 @@ unsigned int Sprite::addFrame( const Uint32& TexId, const Sizef& DestSize, const return 0; } +unsigned int Sprite::addFrame( Texture* tex, const Sizef& DestSize, const Vector2i& offset, + const Rect& TexSector ) { + unsigned int id = framePos(); + + if ( addSubFrame( tex, id, mCurrentSubFrame, DestSize, offset, TexSector ) ) + return id; + + return 0; +} + +bool Sprite::addSubFrame( Texture* tex, const unsigned int& NumFrame, + const unsigned int& NumSubFrame, const Sizef& DestSize, + const Vector2i& Offset, const Rect& TexSector ) { + if ( tex ) + return addSubFrame( tex->getTextureId(), NumFrame, NumSubFrame, DestSize, Offset, + TexSector ); + return false; +} + bool Sprite::addSubFrame( const Uint32& TexId, const unsigned int& NumFrame, const unsigned int& NumSubFrame, const Sizef& DestSize, const Vector2i& Offset, const Rect& TexSector ) { diff --git a/src/eepp/graphics/textureatlas.cpp b/src/eepp/graphics/textureatlas.cpp index 08fbf82ad..7f4e04b2c 100644 --- a/src/eepp/graphics/textureatlas.cpp +++ b/src/eepp/graphics/textureatlas.cpp @@ -56,6 +56,24 @@ TextureRegion* TextureAtlas::add( const Uint32& TexId, const Rect& SrcRect, cons return add( TextureRegion::New( TexId, SrcRect, DestSize, Offset, Name ) ); } +TextureRegion* TextureAtlas::add( Texture* tex, const std::string& Name ) { + return add( TextureRegion::New( tex, Name ) ); +} + +TextureRegion* TextureAtlas::add( Texture* tex, const Rect& SrcRect, const std::string& Name ) { + return add( TextureRegion::New( tex, SrcRect, Name ) ); +} + +TextureRegion* TextureAtlas::add( Texture* tex, const Rect& SrcRect, const Sizef& DestSize, + const std::string& Name ) { + return add( TextureRegion::New( tex, SrcRect, DestSize, Name ) ); +} + +TextureRegion* TextureAtlas::add( Texture* tex, const Rect& SrcRect, const Sizef& DestSize, + const Vector2i& Offset, const std::string& Name ) { + return add( TextureRegion::New( tex, SrcRect, DestSize, Offset, Name ) ); +} + Uint32 TextureAtlas::getCount() { return ResourceManager::getCount(); } diff --git a/src/eepp/graphics/texturefactory.cpp b/src/eepp/graphics/texturefactory.cpp index aeb77fe6e..1b6a9b8f7 100644 --- a/src/eepp/graphics/texturefactory.cpp +++ b/src/eepp/graphics/texturefactory.cpp @@ -31,38 +31,40 @@ TextureFactory::~TextureFactory() { unloadTextures(); } -Uint32 TextureFactory::createEmptyTexture( const unsigned int& Width, const unsigned int& Height, - const unsigned int& Channels, const Color& DefaultColor, - const bool& Mipmap, const Texture::ClampMode& ClampMode, - const bool& CompressTexture, const bool& KeepLocalCopy, - const std::string& Filename ) { +Texture* TextureFactory::createEmptyTexture( const unsigned int& Width, const unsigned int& Height, + const unsigned int& Channels, + const Color& DefaultColor, const bool& Mipmap, + const Texture::ClampMode& ClampMode, + const bool& CompressTexture, const bool& KeepLocalCopy, + const std::string& Filename ) { Image TmpImg( Width, Height, Channels, DefaultColor ); return loadFromPixels( TmpImg.getPixelsPtr(), Width, Height, Channels, Mipmap, ClampMode, CompressTexture, KeepLocalCopy, Filename ); } -Uint32 TextureFactory::loadFromPixels( const unsigned char* Pixels, const unsigned int& Width, - const unsigned int& Height, const unsigned int& Channels, - const bool& Mipmap, const Texture::ClampMode& ClampMode, - const bool& CompressTexture, const bool& KeepLocalCopy, - const std::string& FileName ) { +Texture* TextureFactory::loadFromPixels( const unsigned char* Pixels, const unsigned int& Width, + const unsigned int& Height, const unsigned int& Channels, + const bool& Mipmap, const Texture::ClampMode& ClampMode, + const bool& CompressTexture, const bool& KeepLocalCopy, + const std::string& FileName ) { TextureLoader myTex( Pixels, Width, Height, Channels, Mipmap, ClampMode, CompressTexture, KeepLocalCopy, FileName ); myTex.load(); - return myTex.getId(); + return myTex.getTexture(); } -Uint32 TextureFactory::loadFromPack( Pack* Pack, const std::string& FilePackPath, - const bool& Mipmap, const Texture::ClampMode& ClampMode, - const bool& CompressTexture, const bool& KeepLocalCopy, - const Image::FormatConfiguration& imageformatConfiguration ) { +Texture* +TextureFactory::loadFromPack( Pack* Pack, const std::string& FilePackPath, const bool& Mipmap, + const Texture::ClampMode& ClampMode, const bool& CompressTexture, + const bool& KeepLocalCopy, + const Image::FormatConfiguration& imageformatConfiguration ) { TextureLoader myTex( Pack, FilePackPath, Mipmap, ClampMode, CompressTexture, KeepLocalCopy ); myTex.setFormatConfiguration( imageformatConfiguration ); myTex.load(); - return myTex.getId(); + return myTex.getTexture(); } -Uint32 +Texture* TextureFactory::loadFromMemory( const unsigned char* ImagePtr, const unsigned int& Size, const bool& Mipmap, const Texture::ClampMode& ClampMode, const bool& CompressTexture, const bool& KeepLocalCopy, @@ -70,10 +72,10 @@ TextureFactory::loadFromMemory( const unsigned char* ImagePtr, const unsigned in TextureLoader myTex( ImagePtr, Size, Mipmap, ClampMode, CompressTexture, KeepLocalCopy ); myTex.setFormatConfiguration( imageformatConfiguration ); myTex.load(); - return myTex.getId(); + return myTex.getTexture(); } -Uint32 +Texture* TextureFactory::loadFromStream( IOStream& Stream, const bool& Mipmap, const Texture::ClampMode& ClampMode, const bool& CompressTexture, const bool& KeepLocalCopy, @@ -81,17 +83,18 @@ TextureFactory::loadFromStream( IOStream& Stream, const bool& Mipmap, TextureLoader myTex( Stream, Mipmap, ClampMode, CompressTexture, KeepLocalCopy ); myTex.setFormatConfiguration( imageformatConfiguration ); myTex.load(); - return myTex.getId(); + return myTex.getTexture(); } -Uint32 TextureFactory::loadFromFile( const std::string& Filepath, const bool& Mipmap, - const Texture::ClampMode& ClampMode, - const bool& CompressTexture, const bool& KeepLocalCopy, - const Image::FormatConfiguration& imageformatConfiguration ) { +Texture* +TextureFactory::loadFromFile( const std::string& Filepath, const bool& Mipmap, + const Texture::ClampMode& ClampMode, const bool& CompressTexture, + const bool& KeepLocalCopy, + const Image::FormatConfiguration& imageformatConfiguration ) { TextureLoader myTex( Filepath, Mipmap, ClampMode, CompressTexture, KeepLocalCopy ); myTex.setFormatConfiguration( imageformatConfiguration ); myTex.load(); - return myTex.getId(); + return myTex.getTexture(); } Uint32 TextureFactory::pushTexture( const std::string& Filepath, const Uint32& TexId, diff --git a/src/eepp/graphics/textureregion.cpp b/src/eepp/graphics/textureregion.cpp index 53eb12de1..96d7922f7 100644 --- a/src/eepp/graphics/textureregion.cpp +++ b/src/eepp/graphics/textureregion.cpp @@ -15,22 +15,43 @@ TextureRegion* TextureRegion::New() { } TextureRegion* TextureRegion::New( const Uint32& TexId, const std::string& name ) { - return eeNew( TextureRegion, ( TexId, name ) ); + return eeNew( TextureRegion, ( TextureFactory::instance()->getTexture( TexId ), name ) ); } TextureRegion* TextureRegion::New( const Uint32& TexId, const Rect& srcRect, const std::string& name ) { - return eeNew( TextureRegion, ( TexId, srcRect, name ) ); + return eeNew( TextureRegion, + ( TextureFactory::instance()->getTexture( TexId ), srcRect, name ) ); } TextureRegion* TextureRegion::New( const Uint32& TexId, const Rect& srcRect, const Sizef& destSize, const std::string& name ) { - return eeNew( TextureRegion, ( TexId, srcRect, destSize, name ) ); + return eeNew( TextureRegion, + ( TextureFactory::instance()->getTexture( TexId ), srcRect, destSize, name ) ); } TextureRegion* TextureRegion::New( const Uint32& TexId, const Rect& srcRect, const Sizef& destSize, const Vector2i& offset, const std::string& name ) { - return eeNew( TextureRegion, ( TexId, srcRect, destSize, offset, name ) ); + return eeNew( TextureRegion, ( TextureFactory::instance()->getTexture( TexId ), srcRect, + destSize, offset, name ) ); +} + +TextureRegion* TextureRegion::New( Texture* tex, const std::string& name ) { + return eeNew( TextureRegion, ( tex, name ) ); +} + +TextureRegion* TextureRegion::New( Texture* tex, const Rect& srcRect, const std::string& name ) { + return eeNew( TextureRegion, ( tex, srcRect, name ) ); +} + +TextureRegion* TextureRegion::New( Texture* tex, const Rect& srcRect, const Sizef& destSize, + const std::string& name ) { + return eeNew( TextureRegion, ( tex, srcRect, destSize, name ) ); +} + +TextureRegion* TextureRegion::New( Texture* tex, const Rect& srcRect, const Sizef& destSize, + const Vector2i& offset, const std::string& name ) { + return eeNew( TextureRegion, ( tex, srcRect, destSize, offset, name ) ); } TextureRegion::TextureRegion() : @@ -44,11 +65,11 @@ TextureRegion::TextureRegion() : mOffset( 0, 0 ), mPixelDensity( 1 ) {} -TextureRegion::TextureRegion( const Uint32& TexId, const std::string& name ) : +TextureRegion::TextureRegion( Texture* tex, const std::string& name ) : DrawableResource( Drawable::TEXTUREREGION, name ), mPixels( NULL ), mAlphaMask( NULL ), - mTexture( TextureFactory::instance()->getTexture( TexId ) ), + mTexture( tex ), mSrcRect( Rect( 0, 0, NULL != mTexture ? mTexture->getImageWidth() : 0, NULL != mTexture ? mTexture->getImageHeight() : 0 ) ), mOriDestSize( PixelDensity::dpToPx( mSrcRect.getSize().asFloat() ) ), @@ -56,36 +77,36 @@ TextureRegion::TextureRegion( const Uint32& TexId, const std::string& name ) : mOffset( 0, 0 ), mPixelDensity( 1 ) {} -TextureRegion::TextureRegion( const Uint32& TexId, const Rect& SrcRect, const std::string& name ) : +TextureRegion::TextureRegion( Texture* tex, const Rect& SrcRect, const std::string& name ) : DrawableResource( Drawable::TEXTUREREGION, name ), mPixels( NULL ), mAlphaMask( NULL ), - mTexture( TextureFactory::instance()->getTexture( TexId ) ), + mTexture( tex ), mSrcRect( SrcRect ), - mOriDestSize( PixelDensity::dpToPx( Sizef( ( Float )( mSrcRect.Right - mSrcRect.Left ), - ( Float )( mSrcRect.Bottom - mSrcRect.Top ) ) ) ), + mOriDestSize( PixelDensity::dpToPx( Sizef( (Float)( mSrcRect.Right - mSrcRect.Left ), + (Float)( mSrcRect.Bottom - mSrcRect.Top ) ) ) ), mDestSize( mOriDestSize ), mOffset( 0, 0 ), mPixelDensity( 1 ) {} -TextureRegion::TextureRegion( const Uint32& TexId, const Rect& SrcRect, const Sizef& DestSize, +TextureRegion::TextureRegion( Texture* tex, const Rect& SrcRect, const Sizef& DestSize, const std::string& name ) : DrawableResource( Drawable::TEXTUREREGION, name ), mPixels( NULL ), mAlphaMask( NULL ), - mTexture( TextureFactory::instance()->getTexture( TexId ) ), + mTexture( tex ), mSrcRect( SrcRect ), mOriDestSize( DestSize ), mDestSize( DestSize ), mOffset( 0, 0 ), mPixelDensity( 1 ) {} -TextureRegion::TextureRegion( const Uint32& TexId, const Rect& SrcRect, const Sizef& DestSize, +TextureRegion::TextureRegion( Texture* tex, const Rect& SrcRect, const Sizef& DestSize, const Vector2i& Offset, const std::string& name ) : DrawableResource( Drawable::TEXTUREREGION, name ), mPixels( NULL ), mAlphaMask( NULL ), - mTexture( TextureFactory::instance()->getTexture( TexId ) ), + mTexture( tex ), mSrcRect( SrcRect ), mOriDestSize( DestSize ), mDestSize( DestSize ), @@ -377,19 +398,19 @@ Sizei TextureRegion::getRealSize() { } Sizef TextureRegion::getSize() { - return Sizef( ( Float )( ( Int32 )( mOriDestSize.getWidth() / mPixelDensity ) ), - ( Float )( ( Int32 )( mOriDestSize.getHeight() / mPixelDensity ) ) ); + return Sizef( (Float)( (Int32)( mOriDestSize.getWidth() / mPixelDensity ) ), + (Float)( (Int32)( mOriDestSize.getHeight() / mPixelDensity ) ) ); } Sizei TextureRegion::getDpSize() { - return Sizei( ( Int32 )( mOriDestSize.getWidth() / mPixelDensity ), - ( Int32 )( mOriDestSize.getHeight() / mPixelDensity ) ); + return Sizei( (Int32)( mOriDestSize.getWidth() / mPixelDensity ), + (Int32)( mOriDestSize.getHeight() / mPixelDensity ) ); } Sizef TextureRegion::getPixelsSize() { return Sizef( - ( Int32 )( mOriDestSize.getWidth() / mPixelDensity * PixelDensity::getPixelDensity() ), - ( Int32 )( mOriDestSize.getHeight() / mPixelDensity * PixelDensity::getPixelDensity() ) ); + (Int32)( mOriDestSize.getWidth() / mPixelDensity * PixelDensity::getPixelDensity() ), + (Int32)( mOriDestSize.getHeight() / mPixelDensity * PixelDensity::getPixelDensity() ) ); } const Uint8* TextureRegion::getPixelsPtr() { diff --git a/src/eepp/scene/node.cpp b/src/eepp/scene/node.cpp index 23a04b78e..f158ef352 100644 --- a/src/eepp/scene/node.cpp +++ b/src/eepp/scene/node.cpp @@ -32,7 +32,7 @@ Node::Node() : mAlpha( 255.f ) {} Node::~Node() { - if ( !SceneManager::instance()->isShootingDown() && NULL != mSceneNode ) { + if ( !SceneManager::instance()->isShuttingDown() && NULL != mSceneNode ) { if ( mSceneNode != this && NULL != mSceneNode->getActionManager() ) mSceneNode->getActionManager()->removeAllActionsFromTarget( this ); diff --git a/src/eepp/scene/scenemanager.cpp b/src/eepp/scene/scenemanager.cpp index 15988bffb..62f997009 100644 --- a/src/eepp/scene/scenemanager.cpp +++ b/src/eepp/scene/scenemanager.cpp @@ -7,10 +7,10 @@ namespace EE { namespace Scene { SINGLETON_DECLARE_IMPLEMENTATION( SceneManager ) -SceneManager::SceneManager() : mUISceneNode( NULL ), mIsShootingDown( false ) {} +SceneManager::SceneManager() : mUISceneNode( NULL ), mIsShuttingDown( false ) {} SceneManager::~SceneManager() { - mIsShootingDown = true; + mIsShuttingDown = true; for ( auto& it : mSceneNodes ) { SceneNode* node = it; @@ -54,8 +54,8 @@ void SceneManager::update() { update( mClock.getElapsedTimeAndReset() ); } -bool SceneManager::isShootingDown() const { - return mIsShootingDown; +bool SceneManager::isShuttingDown() const { + return mIsShuttingDown; } UISceneNode* SceneManager::getUISceneNode() { diff --git a/src/eepp/scene/scenenode.cpp b/src/eepp/scene/scenenode.cpp index cb0ad7e08..101e83235 100644 --- a/src/eepp/scene/scenenode.cpp +++ b/src/eepp/scene/scenenode.cpp @@ -273,8 +273,7 @@ void SceneNode::drawFrameBuffer() { mScreenPos.y + mSize.getHeight() ) ); } else { Rect r = Rect( 0, 0, mSize.getWidth(), mSize.getHeight() ); - TextureRegion textureRegion( mFrameBuffer->getTexture()->getTextureId(), r, - r.getSize().asFloat() ); + TextureRegion textureRegion( mFrameBuffer->getTexture(), r, r.getSize().asFloat() ); textureRegion.draw( mScreenPosi.x, mScreenPosi.y, Color::White, getRotation(), getScale() ); } diff --git a/src/eepp/system/process.cpp b/src/eepp/system/process.cpp index a0b298dd9..e8da3c216 100644 --- a/src/eepp/system/process.cpp +++ b/src/eepp/system/process.cpp @@ -177,7 +177,7 @@ void Process::startShutdown() { mShuttingDown = true; } -const bool& Process::isShootingDown() { +const bool& Process::isShuttingDown() { return mShuttingDown; } diff --git a/src/eepp/ui/models/filesystemmodel.cpp b/src/eepp/ui/models/filesystemmodel.cpp index 8a8052fce..af7ebf8ba 100644 --- a/src/eepp/ui/models/filesystemmodel.cpp +++ b/src/eepp/ui/models/filesystemmodel.cpp @@ -267,12 +267,12 @@ void FileSystemModel::Node::updateMimeType() { std::shared_ptr FileSystemModel::New( const std::string& rootPath, const FileSystemModel::Mode& mode, - const DisplayConfig displayConfig ) { + const DisplayConfig& displayConfig ) { return std::shared_ptr( new FileSystemModel( rootPath, mode, displayConfig ) ); } FileSystemModel::FileSystemModel( const std::string& rootPath, const FileSystemModel::Mode& mode, - const DisplayConfig displayConfig ) : + const DisplayConfig& displayConfig ) : mRootPath( rootPath ), mRealRootPath( FileSystem::getRealPath( rootPath ) ), mMode( mode ), @@ -772,7 +772,7 @@ bool FileSystemModel::handleFileEventLocked( const FileEvent& event ) { std::vector newIndexes = keptSelections[view]; int i = 0; for ( const auto& name : names ) { - size_t row = parent->findChildRowFromName( name, *this ); + Int64 row = parent->findChildRowFromName( name, *this ); if ( row >= 0 ) { newIndexes.emplace_back( this->index( row, prevSelectionsModelIndex[view][i].column(), diff --git a/src/eepp/ui/tools/uicolorpicker.cpp b/src/eepp/ui/tools/uicolorpicker.cpp index 68695942e..cde13c6c9 100644 --- a/src/eepp/ui/tools/uicolorpicker.cpp +++ b/src/eepp/ui/tools/uicolorpicker.cpp @@ -376,10 +376,8 @@ Texture* UIColorPicker::createHueTexture( const Sizef& size ) { } TextureFactory* TF = TextureFactory::instance(); - Uint32 texId = TF->loadFromPixels( image.getPixelsPtr(), image.getWidth(), image.getHeight(), - image.getChannels() ); - - return TF->getTexture( texId ); + return TF->loadFromPixels( image.getPixelsPtr(), image.getWidth(), image.getHeight(), + image.getChannels() ); } Texture* UIColorPicker::createGridTexture() { @@ -396,10 +394,8 @@ Texture* UIColorPicker::createGridTexture() { } TextureFactory* TF = TextureFactory::instance(); - Uint32 texId = TF->loadFromPixels( image.getPixelsPtr(), image.getWidth(), image.getHeight(), - image.getChannels() ); - - return TF->getTexture( texId ); + return TF->loadFromPixels( image.getPixelsPtr(), image.getWidth(), image.getHeight(), + image.getChannels() ); } void UIColorPicker::updateColorPicker() { diff --git a/src/eepp/ui/tools/uiwidgetinspector.cpp b/src/eepp/ui/tools/uiwidgetinspector.cpp index 390209af7..81f06c274 100644 --- a/src/eepp/ui/tools/uiwidgetinspector.cpp +++ b/src/eepp/ui/tools/uiwidgetinspector.cpp @@ -132,13 +132,13 @@ UIWindow* UIWidgetInspector::create( UISceneNode* sceneNode, const Float& menuIc eWinEvent->getNode()->removeEventListener( eWinEvent->getCallbackId() ); } ); uiWin->addEventListener( Event::OnWindowClose, [sceneNode, winRdCb]( const Event* ) { - if ( !SceneManager::instance()->isShootingDown() ) + if ( !SceneManager::instance()->isShuttingDown() ) sceneNode->removeEventListener( winRdCb ); } ); } } ); uiWin->addEventListener( Event::OnWindowClose, [sceneNode, winCb]( const Event* ) { - if ( !SceneManager::instance()->isShootingDown() ) + if ( !SceneManager::instance()->isShuttingDown() ) sceneNode->removeEventListener( winCb ); } ); return uiWin; diff --git a/src/eepp/ui/uicodeeditor.cpp b/src/eepp/ui/uicodeeditor.cpp index dbd2ffa3d..8534b2c27 100644 --- a/src/eepp/ui/uicodeeditor.cpp +++ b/src/eepp/ui/uicodeeditor.cpp @@ -1370,7 +1370,7 @@ void UICodeEditor::checkColorPickerAction() { if ( colorPicker ) colorPicker->getUIWindow()->addEventListener( Event::OnWindowClose, [&]( const Event* ) { - if ( !SceneManager::instance()->isShootingDown() ) + if ( !SceneManager::instance()->isShuttingDown() ) setFocus(); } ); } diff --git a/src/eepp/ui/uidropdownlist.cpp b/src/eepp/ui/uidropdownlist.cpp index 250f9b945..6dec2627f 100644 --- a/src/eepp/ui/uidropdownlist.cpp +++ b/src/eepp/ui/uidropdownlist.cpp @@ -315,7 +315,7 @@ Uint32 UIDropDownList::onKeyDown( const KeyEvent& Event ) { } void UIDropDownList::destroyListBox() { - if ( !SceneManager::instance()->isShootingDown() && NULL != mListBox && + if ( !SceneManager::instance()->isShuttingDown() && NULL != mListBox && mListBox->getParent() != this ) { mListBox->setParent( this ); } diff --git a/src/eepp/ui/uiicon.cpp b/src/eepp/ui/uiicon.cpp index a72dd3d94..2105384ac 100644 --- a/src/eepp/ui/uiicon.cpp +++ b/src/eepp/ui/uiicon.cpp @@ -91,10 +91,10 @@ Drawable* UISVGIcon::getSize( const int& size ) const { } } format.svgScale( size / (Float)eemax( mOriSize.x, mOriSize.y ) ); - Uint32 textId = TextureFactory::instance()->loadFromMemory( + Texture* texture = TextureFactory::instance()->loadFromMemory( (const unsigned char*)&mSVGXml[0], mSVGXml.size(), false, Texture::ClampMode::ClampToEdge, false, false, format ); - Texture* texture = TextureFactory::instance()->getTexture( textId ); + mSVGs[size] = texture; return texture; } diff --git a/src/eepp/ui/uimenubar.cpp b/src/eepp/ui/uimenubar.cpp index 5d9a11ab5..f7f1f4588 100644 --- a/src/eepp/ui/uimenubar.cpp +++ b/src/eepp/ui/uimenubar.cpp @@ -27,7 +27,7 @@ UIMenuBar::~UIMenuBar() { } void UIMenuBar::destroyMenues() { - if ( !SceneManager::instance()->isShootingDown() ) { + if ( !SceneManager::instance()->isShuttingDown() ) { for ( MenuBarList::iterator it = mButtons.begin(); it != mButtons.end(); ++it ) { if ( it->second->getParent() != this ) { // Changing the parent ensures that the menu will be destroyed when the menubar is @@ -292,7 +292,7 @@ bool UIMenuBar::isPopUpMenuChild( Node* node ) { } void UIMenuBar::autoHeight() { - if ( 0 == mMenuHeight && nullptr != getSkin() ) { + if ( 0 == mMenuHeight ) { mMenuHeight = getSkinSize().getHeight(); setSize( getParent()->getSize().getWidth(), mMenuHeight ); updateAnchorsDistances(); diff --git a/src/eepp/ui/uitreeview.cpp b/src/eepp/ui/uitreeview.cpp index 1bb33a0e1..3c55465fc 100644 --- a/src/eepp/ui/uitreeview.cpp +++ b/src/eepp/ui/uitreeview.cpp @@ -52,7 +52,7 @@ void UITreeView::traverseTree( TreeViewCallback callback ) const { std::function traverseIndex = [&]( const ModelIndex& index ) { if ( index.isValid() ) { - auto& metadata = getIndexMetadata( index ); + const auto& metadata = getIndexMetadata( index ); rowIndex++; IterationDecision decision = callback( rowIndex, index, indentLevel, yOffset ); if ( decision == IterationDecision::Break || decision == IterationDecision::Stop ) @@ -237,11 +237,11 @@ UIWidget* UITreeView::updateCell( const int& rowIndex, const ModelIndex& index, bool hasChilds = false; if ( widget->isType( UI_TYPE_TREEVIEW_CELL ) ) { - UITreeViewCell* cell = widget->asType(); + UITreeViewCell* tcell = widget->asType(); UIImage* image = widget->asType()->getImage(); Float minIndent = - !mExpandersAsIcons + !mExpandersAsIcons && mExpandIcon && mContractIcon ? eemax( mExpandIcon->getSize( mExpanderIconSize )->getPixelsSize().getWidth(), mContractIcon->getSize( mExpanderIconSize ) ->getPixelsSize() @@ -250,28 +250,28 @@ UIWidget* UITreeView::updateCell( const int& rowIndex, const ModelIndex& index, : 0; if ( index.column() == (Int64)getModel()->treeColumn() ) - cell->setIndentation( minIndent + getIndentWidth() * indentLevel ); + tcell->setIndentation( minIndent + getIndentWidth() * indentLevel ); hasChilds = getModel()->rowCount( index ) > 0; if ( hasChilds ) { UIIcon* icon = getIndexMetadata( index ).open ? mExpandIcon : mContractIcon; - Drawable* drawable = icon->getSize( mExpanderIconSize ); + Drawable* drawable = icon ? icon->getSize( mExpanderIconSize ) : nullptr; image->setVisible( true ); - image->setPixelsSize( drawable->getPixelsSize() ); + image->setPixelsSize( drawable ? drawable->getPixelsSize() : Sizef( 0, 0 ) ); image->setDrawable( drawable ); if ( !mExpandersAsIcons ) { - cell->setIndentation( cell->getIndentation() - - image->getPixelsSize().getWidth() - - PixelDensity::dpToPx( image->getLayoutMargin().Right ) ); + tcell->setIndentation( tcell->getIndentation() - + image->getPixelsSize().getWidth() - + PixelDensity::dpToPx( image->getLayoutMargin().Right ) ); } } else { image->setVisible( false ); } } - if ( hasChilds && mExpandersAsIcons ) { + if ( hasChilds && mExpandersAsIcons && cell->getIcon() ) { cell->getIcon()->setVisible( false ); return widget; } diff --git a/src/eepp/ui/uiwidget.cpp b/src/eepp/ui/uiwidget.cpp index 70be18076..22b43e3a6 100644 --- a/src/eepp/ui/uiwidget.cpp +++ b/src/eepp/ui/uiwidget.cpp @@ -63,7 +63,7 @@ UIWidget::~UIWidget() { mUISceneNode->getUIEventDispatcher()->getNodeDragging() == this ) mUISceneNode->getUIEventDispatcher()->setNodeDragging( nullptr ); - if ( !SceneManager::instance()->isShootingDown() && NULL != mUISceneNode ) + if ( !SceneManager::instance()->isShuttingDown() && NULL != mUISceneNode ) mUISceneNode->onWidgetDelete( this ); eeSAFE_DELETE( mStyle ); eeSAFE_DELETE( mTooltip ); diff --git a/src/eepp/ui/uiwidgetcreator.cpp b/src/eepp/ui/uiwidgetcreator.cpp index 7fd12fe2a..52da8b134 100644 --- a/src/eepp/ui/uiwidgetcreator.cpp +++ b/src/eepp/ui/uiwidgetcreator.cpp @@ -91,7 +91,7 @@ void UIWidgetCreator::createBaseWidgetList() { registeredWidget["listview"] = UIListView::New; registeredWidget["stackwidget"] = UIStackWidget::New; registeredWidget["console"] = UIConsole::New; - registeredWidget["menu"] = UIMenu::New; + // registeredWidget["menu"] = UIMenu::New; registeredWidget["menucheckbox"] = UIMenuCheckBox::New; registeredWidget["menuradiobutton"] = UIMenuRadioButton::New; registeredWidget["menuseparator"] = UIMenuSeparator::New; diff --git a/src/eepp/ui/uiwindow.cpp b/src/eepp/ui/uiwindow.cpp index 8db95d658..60cb29f65 100644 --- a/src/eepp/ui/uiwindow.cpp +++ b/src/eepp/ui/uiwindow.cpp @@ -94,7 +94,7 @@ UIWindow::UIWindow( UIWindow::WindowBaseContainerType type, const StyleConfig& w } UIWindow::~UIWindow() { - if ( NULL != getUISceneNode() && !SceneManager::instance()->isShootingDown() ) { + if ( NULL != getUISceneNode() && !SceneManager::instance()->isShuttingDown() ) { if ( NULL != mModalNode ) { mModalNode->setEnabled( false ); mModalNode->setVisible( false ); @@ -330,8 +330,7 @@ void UIWindow::drawFrameBuffer() { mScreenPos.y + mSize.getHeight() ) ); } else { Rect r( 0, 0, mSize.getWidth(), mSize.getHeight() ); - TextureRegion textureRegion( mFrameBuffer->getTexture()->getTextureId(), r, - r.getSize().asFloat() ); + TextureRegion textureRegion( mFrameBuffer->getTexture(), r, r.getSize().asFloat() ); textureRegion.draw( mScreenPosi.x, mScreenPosi.y, Color::White, getRotation(), getScale() ); } diff --git a/src/examples/external_shader/external_shader.cpp b/src/examples/external_shader/external_shader.cpp index 9994505c4..670be3e46 100644 --- a/src/examples/external_shader/external_shader.cpp +++ b/src/examples/external_shader/external_shader.cpp @@ -189,7 +189,7 @@ void mainLoop() { GLi->drawArrays( PRIMITIVE_LINES, 0, ParticlesNum ); /// Stop the simulation if the window is not visible - while ( !win->isVisible() ) { + while ( !win->isVisible() && win->isOpen() ) { imp->update(); /// To get the real state of the window you need to update the window input Sys::sleep( Milliseconds( 100 ) ); } diff --git a/src/examples/sprites/sprites.cpp b/src/examples/sprites/sprites.cpp index 909b91663..fd86018e3 100644 --- a/src/examples/sprites/sprites.cpp +++ b/src/examples/sprites/sprites.cpp @@ -101,8 +101,8 @@ EE_MAIN_FUNC int main( int, char*[] ) { FileSystem::changeWorkingDirectory( Sys::getProcessPath() ); // Load the rock texture - Uint32 PlanetId = TextureFactory::instance()->loadFromFile( "assets/sprites/7.png" ); - Uint32 RockId = TextureFactory::instance()->loadFromFile( "assets/sprites/5.png" ); + Texture* PlanetTex = TextureFactory::instance()->loadFromFile( "assets/sprites/7.png" ); + Texture* RockTex = TextureFactory::instance()->loadFromFile( "assets/sprites/5.png" ); // Load a previously generated texture atlas that contains the TextureRegions needed to load // an animated sprite @@ -113,13 +113,13 @@ EE_MAIN_FUNC int main( int, char*[] ) { for ( Int32 my = 0; my < 4; my++ ) { for ( Int32 mx = 0; mx < 8; mx++ ) { // DestSize as 0,0 will use the TextureRegion size - Rock.addFrame( RockId, Sizef( 0, 0 ), Vector2i( 0, 0 ), + Rock.addFrame( RockTex, Sizef( 0, 0 ), Vector2i( 0, 0 ), Rect( mx * 64, my * 64, mx * 64 + 64, my * 64 + 64 ) ); } } // Create a static sprite - Planet.createStatic( PlanetId ); + Planet.createStatic( PlanetTex ); // It will look for a TextureRegion ( in any Texture Atlas loaded, or the GlobalTextureAtlas // ) animation by its name, it will search for "gn00" to "gnXX" to create a new animation diff --git a/src/modules/eterm/src/eterm/terminal/terminaldisplay.cpp b/src/modules/eterm/src/eterm/terminal/terminaldisplay.cpp index 3a6ce66ef..853d38f17 100644 --- a/src/modules/eterm/src/eterm/terminal/terminaldisplay.cpp +++ b/src/modules/eterm/src/eterm/terminal/terminaldisplay.cpp @@ -1678,8 +1678,7 @@ void TerminalDisplay::createFrameBuffer() { void TerminalDisplay::drawFrameBuffer() { if ( mFrameBuffer ) { Rect r( 0, 0, mSize.getWidth(), mSize.getHeight() ); - TextureRegion textureRegion( mFrameBuffer->getTexture()->getTextureId(), r, - r.getSize().asFloat() ); + TextureRegion textureRegion( mFrameBuffer->getTexture(), r, r.getSize().asFloat() ); textureRegion.draw( mPosition.floor().x, mPosition.floor().y ); } } diff --git a/src/modules/maps/src/eepp/maps/tilemap.cpp b/src/modules/maps/src/eepp/maps/tilemap.cpp index b8230ad01..5af687e4d 100644 --- a/src/modules/maps/src/eepp/maps/tilemap.cpp +++ b/src/modules/maps/src/eepp/maps/tilemap.cpp @@ -147,11 +147,9 @@ void TileMap::createEmptyTile() { Img.setPixel( mTileSize.x - 1, y, Col ); } - Uint32 TileTexId = TF->loadFromPixels( - Img.getPixelsPtr(), Img.getWidth(), Img.getHeight(), Img.getChannels(), true, - Texture::ClampMode::ClampToEdge, false, false, tileName ); - - mTileTex = TF->getTexture( TileTexId ); + mTileTex = TF->loadFromPixels( Img.getPixelsPtr(), Img.getWidth(), Img.getHeight(), + Img.getChannels(), true, Texture::ClampMode::ClampToEdge, + false, false, tileName ); } else { mTileTex = Tex; } @@ -394,8 +392,8 @@ void TileMap::clamp() { if ( totSize.y < mViewSize.y ) mOffset.y = 0; - totSize.x = ( Int32 )( ( Float )( mTileSize.x * mSize.x ) * mScale ); - totSize.y = ( Int32 )( ( Float )( mTileSize.y * mSize.y ) * mScale ); + totSize.x = (Int32)( (Float)( mTileSize.x * mSize.x ) * mScale ); + totSize.y = (Int32)( (Float)( mTileSize.y * mSize.y ) * mScale ); if ( -mOffset.x + mViewSize.x > totSize.x ) mOffset.x = -( totSize.x - mViewSize.x ); diff --git a/src/tests/test_all/test.cpp b/src/tests/test_all/test.cpp index 687debf09..f73426f84 100644 --- a/src/tests/test_all/test.cpp +++ b/src/tests/test_all/test.cpp @@ -39,7 +39,7 @@ class UIBlurredWindow : public UIWindow { mFboBlur->resize( mSize.x / fboDiv, mSize.y / fboDiv ); } - TextureRegion textureRegion( curFBO->getTexture()->getTextureId(), + TextureRegion textureRegion( curFBO->getTexture(), Rect( mScreenPos.x, mScreenPos.y, mScreenPos.x + mSize.x, mScreenPos.y + mSize.y ) ); @@ -600,7 +600,8 @@ void EETest::createUI() { createUIThemeTextureAtlas(); - Log::info( "Texture Atlas Loading Time: %4.3f ms.", TE.getElapsedTimeAndReset().asMilliseconds() ); + Log::info( "Texture Atlas Loading Time: %4.3f ms.", + TE.getElapsedTimeAndReset().asMilliseconds() ); mSceneNode = UISceneNode::New(); @@ -1384,11 +1385,11 @@ void EETest::loadTextures() { TNP.resize( 12 ); for ( i = 0; i <= 6; i++ ) { - TN[i] = TF->loadFromFile( MyPath + "sprites/" + String::toString( i + 1 ) + ".png", - ( i + 1 ) == 7 ? true : false, - ( ( i + 1 ) == 4 ) ? Texture::ClampMode::ClampRepeat - : Texture::ClampMode::ClampToEdge ); - TNP[i] = TF->getTexture( TN[i] ); + TNP[i] = TF->loadFromFile( MyPath + "sprites/" + String::toString( i + 1 ) + ".png", + ( i + 1 ) == 7 ? true : false, + ( ( i + 1 ) == 4 ) ? Texture::ClampMode::ClampRepeat + : Texture::ClampMode::ClampToEdge ); + TN[i] = TNP[i]->getTextureId(); } Tiles.resize( 10 ); @@ -1401,7 +1402,8 @@ void EETest::loadTextures() { Tiles[i] = SG->getByName( String::toString( i + 1 ) ); } - Tiles[6] = SG->add( TF->loadFromFile( MyPath + "sprites/objects/1.png" ), "7" ); + Tiles[6] = + SG->add( TF->loadFromFile( MyPath + "sprites/objects/1.png" )->getTextureId(), "7" ); #ifdef EE_GLES Image tImg( MyPath + "sprites/objects/2.png", 4 ); @@ -1453,8 +1455,8 @@ void EETest::loadTextures() { Tex->unlock( false, true ); } - Cursor[0] = TF->loadFromFile( MyPath + "cursors/cursor.tga" ); - CursorP[0] = TF->getTexture( Cursor[0] ); + CursorP[0] = TF->loadFromFile( MyPath + "cursors/cursor.tga" ); + Cursor[0] = CursorP[0]->getTextureId(); CursorManager* CurMan = mWindow->getCursorManager(); CurMan->setVisible( false ); diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index 31c725fbd..afa2fd636 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -143,7 +143,7 @@ void App::saveAllProcess() { } ); dialog->addEventListener( Event::OnWindowClose, [&, editor]( const Event* ) { mTmpDocs.erase( &editor->getDocument() ); - if ( !SceneManager::instance()->isShootingDown() && !mTmpDocs.empty() ) + if ( !SceneManager::instance()->isShuttingDown() && !mTmpDocs.empty() ) saveAllProcess(); } ); return true; @@ -227,7 +227,7 @@ void App::openFileDialog() { loadFileFromPath( file ); } ); dialog->addEventListener( Event::OnWindowClose, [&]( const Event* ) { - if ( mSplitter && mSplitter->getCurWidget() && !SceneManager::instance()->isShootingDown() ) + if ( mSplitter && mSplitter->getCurWidget() && !SceneManager::instance()->isShuttingDown() ) mSplitter->getCurWidget()->setFocus(); } ); dialog->center(); @@ -262,7 +262,7 @@ void App::openFolderDialog() { loadFolder( path ); } ); dialog->addEventListener( Event::OnWindowClose, [&]( const Event* ) { - if ( mSplitter && mSplitter->getCurWidget() && !SceneManager::instance()->isShootingDown() ) + if ( mSplitter && mSplitter->getCurWidget() && !SceneManager::instance()->isShuttingDown() ) mSplitter->getCurWidget()->setFocus(); } ); dialog->center(); @@ -285,7 +285,7 @@ void App::openFontDialog( std::string& fontPath, bool loadingMonoFont ) { dialog->setTitle( i18n( "select_font_file", "Select Font File" ) ); dialog->setCloseShortcut( KEY_ESCAPE ); dialog->addEventListener( Event::OnWindowClose, [&]( const Event* ) { - if ( mSplitter && mSplitter->getCurWidget() && !SceneManager::instance()->isShootingDown() ) + if ( mSplitter && mSplitter->getCurWidget() && !SceneManager::instance()->isShuttingDown() ) mSplitter->getCurWidget()->setFocus(); } ); dialog->addEventListener( Event::OpenFile, [&, loadingMonoFont]( const Event* event ) { @@ -397,7 +397,7 @@ UIFileDialog* App::saveFileDialog( UICodeEditor* editor, bool focusOnClose ) { } ); if ( focusOnClose ) { dialog->addEventListener( Event::OnWindowClose, [&, editor]( const Event* ) { - if ( editor && !SceneManager::instance()->isShootingDown() ) + if ( editor && !SceneManager::instance()->isShuttingDown() ) editor->setFocus(); } ); } @@ -635,14 +635,14 @@ App::~App() { delete mFileWatcher; mFileWatcher = nullptr; } + mPluginManager.reset(); + eeSAFE_DELETE( mSplitter ); + eeSAFE_DELETE( mConsole ); if ( mFileSystemListener ) { delete mFileSystemListener; mFileSystemListener = nullptr; } mDirTree.reset(); - mPluginManager.reset(); - eeSAFE_DELETE( mSplitter ); - eeSAFE_DELETE( mConsole ); } void App::updateRecentFiles() { @@ -890,6 +890,22 @@ void App::aboutEcode() { String msg( ecode::Version::getVersionFullName() + " (codename: \"" + ecode::Version::getCodename() + "\")" ); UIMessageBox* msgBox = UIMessageBox::New( UIMessageBox::OK, msg ); + UIImage* image = UIImage::New(); + image->setParent( msgBox->getContainer()->getFirstChild() ); + auto tf = TextureFactory::instance(); + Texture* tex = tf->getByName( "ecode-logo" ); + if ( tex == nullptr ) { + tex = tf->loadFromFile( mResPath + "icon/ecode.png" ); + if ( tex ) + tex->setName( "ecode-logo" ); + } + image->setDrawable( tex ); + image->setLayoutGravity( UI_NODE_ALIGN_CENTER ); + image->setGravity( UI_NODE_ALIGN_CENTER ); + image->setScaleType( UIScaleType::FitInside ); + image->setLayoutSizePolicy( SizePolicy::Fixed, SizePolicy::Fixed ); + image->setSize( { 128, 128 } ); + image->toBack(); msgBox->setTitle( i18n( "about_ecode", "About ecode..." ) ); msgBox->showWhenReady(); } @@ -1848,13 +1864,10 @@ void App::loadImageFromMedium( const std::string& path, bool isMemory ) { #if EE_PLATFORM != EE_PLATFORM_EMSCRIPTEN || defined( __EMSCRIPTEN_PTHREADS__ ) mThreadPool->run( [this, imageView, loaderView, path, isMemory]() { #endif - Texture* image = isMemory - ? TextureFactory::instance()->getTexture( - TextureFactory::instance()->loadFromMemory( - reinterpret_cast( path.c_str() ), - path.size() ) ) - : TextureFactory::instance()->getTexture( - TextureFactory::instance()->loadFromFile( path ) ); + Texture* image = + isMemory ? TextureFactory::instance()->loadFromMemory( + reinterpret_cast( path.c_str() ), path.size() ) + : TextureFactory::instance()->loadFromFile( path ); if ( mImageLayout->isVisible() ) { imageView->runOnMainThread( [this, imageView, loaderView, image]() { mImageLayout->setFocus(); @@ -3450,7 +3463,9 @@ void App::init( const LogLevel& logLevel, std::string file, const Float& pidelDe #if EE_PLATFORM != EE_PLATFORM_EMSCRIPTEN mFileWatcher = new efsw::FileWatcher(); mFileSystemListener = new FileSystemListener( mSplitter, mFileSystemModel ); + mFileWatcher->addWatch( mPluginsPath, mFileSystemListener ); mFileWatcher->watch(); + mPluginManager->setFileSystemListener( mFileSystemListener ); #endif mNotificationCenter = std::make_unique( diff --git a/src/tools/ecode/filesystemlistener.cpp b/src/tools/ecode/filesystemlistener.cpp index ca31de14e..d5a26e7c4 100644 --- a/src/tools/ecode/filesystemlistener.cpp +++ b/src/tools/ecode/filesystemlistener.cpp @@ -21,8 +21,7 @@ FileSystemListener::FileSystemListener( UICodeEditorSplitter* splitter, std::shared_ptr fileSystemModel ) : mSplitter( splitter ), mFileSystemModel( fileSystemModel ) {} - -static inline bool endsWithSlash(const std::string& dir) { +static inline bool endsWithSlash( const std::string& dir ) { return !dir.empty() && ( dir.back() == '\\' || dir.back() == '/' ); } @@ -70,6 +69,13 @@ void FileSystemListener::handleFileAction( efsw::WatchID, const std::string& dir notifyMove( oldFile, file ); } } + + Lock l( mCbsMutex ); + if ( !mCbs.empty() ) { + auto cbs = mCbs; + for ( const auto& cb : cbs ) + cb.second( event, file ); + } break; } case efsw::Actions::Modified: { @@ -77,6 +83,14 @@ void FileSystemListener::handleFileAction( efsw::WatchID, const std::string& dir file = FileInfo( file.linksTo() ); if ( isFileOpen( file ) ) notifyChange( file ); + + Lock l( mCbsMutex ); + if ( !mCbs.empty() ) { + auto cbs = mCbs; + FileEvent event( (FileSystemEventType)action, dir, filename, oldFilename ); + for ( const auto& cb : cbs ) + cb.second( event, file ); + } } } } @@ -85,6 +99,23 @@ void FileSystemListener::setDirTree( const std::shared_ptr mDirTree = dirTree; } +Uint64 FileSystemListener::addListener( const FileEventFn& fn ) { + Lock l( mCbsMutex ); + Uint64 id = ++mLastId; + mCbs[id] = fn; + return id; +} + +bool FileSystemListener::removeListener( const Uint64& id ) { + Lock l( mCbsMutex ); + auto it = mCbs.find( id ); + if ( it != mCbs.end() ) { + mCbs.erase( it ); + return true; + } + return false; +} + bool FileSystemListener::isFileOpen( const FileInfo& file ) { bool found = false; mSplitter->forEachDocStoppable( [&]( TextDocument& doc ) { diff --git a/src/tools/ecode/filesystemlistener.hpp b/src/tools/ecode/filesystemlistener.hpp index bb6d108b9..5474e69d2 100644 --- a/src/tools/ecode/filesystemlistener.hpp +++ b/src/tools/ecode/filesystemlistener.hpp @@ -2,11 +2,13 @@ #define ECODE_FILESYSTEMLISTENER_HPP #include "projectdirectorytree.hpp" +#include #include #include #include #include #include +#include using namespace EE::System; using namespace EE::UI; @@ -17,6 +19,8 @@ namespace ecode { class FileSystemListener : public efsw::FileWatchListener { public: + typedef std::function FileEventFn; + FileSystemListener( UICodeEditorSplitter* codeSplitter, std::shared_ptr fileSystemModel ); @@ -29,10 +33,17 @@ class FileSystemListener : public efsw::FileWatchListener { void setDirTree( const std::shared_ptr& dirTree ); + Uint64 addListener( const FileEventFn& fn ); + + bool removeListener( const Uint64& id ); + protected: UICodeEditorSplitter* mSplitter; std::shared_ptr mFileSystemModel; std::shared_ptr mDirTree; + std::atomic mLastId{ 0 }; + std::unordered_map mCbs; + Mutex mCbsMutex; bool isFileOpen( const FileInfo& file ); diff --git a/src/tools/ecode/plugins/autocomplete/autocompleteplugin.cpp b/src/tools/ecode/plugins/autocomplete/autocompleteplugin.cpp index f85f1de49..fad34c507 100644 --- a/src/tools/ecode/plugins/autocomplete/autocompleteplugin.cpp +++ b/src/tools/ecode/plugins/autocomplete/autocompleteplugin.cpp @@ -71,19 +71,19 @@ UICodeEditorPlugin* AutoCompletePlugin::New( PluginManager* pluginManager ) { } AutoCompletePlugin::AutoCompletePlugin( PluginManager* pluginManager ) : - mManager( pluginManager ), + Plugin( pluginManager ), mSymbolPattern( "[%a_ñàáâãäåèéêëìíîïòóôõöùúûüýÿÑÀÁÂÃÄÅÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝ][%w_" "ñàáâãäåèéêëìíîïòóôõöùúûüýÿÑÀÁÂÃÄÅÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝ]*" ), - mBoxPadding( PixelDensity::dpToPx( Rectf( 4, 4, 12, 4 ) ) ), - mPool( pluginManager->getThreadPool() ) { + mBoxPadding( PixelDensity::dpToPx( Rectf( 4, 4, 12, 4 ) ) ) { mManager->subscribeMessages( this, [&]( const PluginMessage& msg ) -> PluginRequestHandle { return processResponse( msg ); } ); } AutoCompletePlugin::~AutoCompletePlugin() { - mClosing = true; + mShuttingDown = true; mManager->unsubscribeMessages( this ); + Lock l( mDocMutex ); Lock l2( mLangSymbolsMutex ); Lock l3( mSuggestionsMutex ); @@ -142,7 +142,7 @@ void AutoCompletePlugin::onRegister( UICodeEditor* editor ) { std::string oldLang = event->getOldLang(); std::string newLang = event->getNewLang(); #if AUTO_COMPLETE_THREADED - mPool->run( [&, oldLang, newLang] { + mThreadPool->run( [&, oldLang, newLang] { updateLangCache( oldLang ); updateLangCache( newLang ); } ); @@ -159,7 +159,7 @@ void AutoCompletePlugin::onRegister( UICodeEditor* editor ) { } void AutoCompletePlugin::onUnregister( UICodeEditor* editor ) { - if ( mClosing ) + if ( mShuttingDown ) return; if ( mSuggestionsEditor == editor ) resetSuggestions( editor ); @@ -313,7 +313,7 @@ void AutoCompletePlugin::requestSignatureHelp( UICodeEditor* editor ) { auto doc = editor->getDocumentRef(); mSignatureHelpPosition = editor->getDocumentRef()->getSelection().start(); - mPool->run( [&, editor]() { + mThreadPool->run( [&, editor]() { json data = getURIAndPositionJSON( editor ); mManager->sendRequest( this, PluginMessageType::SignatureHelp, PluginMessageFormat::JSON, &data ); @@ -394,7 +394,7 @@ void AutoCompletePlugin::updateDocCache( TextDocument* doc ) { { Lock l( mDocMutex ); docCache = mDocCache.find( doc ); - if ( docCache == mDocCache.end() || mClosing ) + if ( docCache == mDocCache.end() || mShuttingDown ) return; } @@ -404,7 +404,7 @@ void AutoCompletePlugin::updateDocCache( TextDocument* doc ) { { Lock l( mDocMutex ); docCache = mDocCache.find( doc ); - if ( docCache == mDocCache.end() || mClosing ) + if ( docCache == mDocCache.end() || mShuttingDown ) return; auto& cache = docCache->second; cache.changeId = changeId; @@ -590,7 +590,7 @@ void AutoCompletePlugin::update( UICodeEditor* ) { continue; } #if AUTO_COMPLETE_THREADED - mPool->run( [&, doc] { updateDocCache( doc ); } ); + mThreadPool->run( [&, doc] { updateDocCache( doc ); } ); #else updateDocCache( doc ); #endif @@ -931,7 +931,7 @@ AutoCompletePlugin::SymbolsList AutoCompletePlugin::getDocumentSymbols( TextDocu LuaPattern pattern( mSymbolPattern ); AutoCompletePlugin::SymbolsList symbols; Int64 lc = doc->linesCount(); - if ( lc == 0 || lc > 50000 || mClosing ) + if ( lc == 0 || lc > 50000 || mShuttingDown ) return symbols; std::string current( getPartialSymbol( doc ) ); TextPosition end = doc->getSelection().end(); @@ -948,7 +948,7 @@ AutoCompletePlugin::SymbolsList AutoCompletePlugin::getDocumentSymbols( TextDocu } ) ) symbols.push_back( std::move( matchStr ) ); } - if ( mClosing ) + if ( mShuttingDown ) break; } return symbols; @@ -981,7 +981,7 @@ void AutoCompletePlugin::updateSuggestions( const std::string& symbol, UICodeEdi const auto& symbols = langSuggestions->second; { #if AUTO_COMPLETE_THREADED - mPool->run( + mThreadPool->run( [this, symbol, &symbols, editor] { runUpdateSuggestions( symbol, symbols, editor ); } ); #else runUpdateSuggestions( symbol, symbols, editor ); diff --git a/src/tools/ecode/plugins/autocomplete/autocompleteplugin.hpp b/src/tools/ecode/plugins/autocomplete/autocompleteplugin.hpp index 9cb6bed04..ef9a58aa2 100644 --- a/src/tools/ecode/plugins/autocomplete/autocompleteplugin.hpp +++ b/src/tools/ecode/plugins/autocomplete/autocompleteplugin.hpp @@ -17,7 +17,7 @@ using namespace EE::UI; namespace ecode { -class AutoCompletePlugin : public UICodeEditorPlugin { +class AutoCompletePlugin : public Plugin { public: class Suggestion { public: @@ -58,7 +58,7 @@ class AutoCompletePlugin : public UICodeEditorPlugin { "Auto complete shows the completion popup as you type, so you can fill " "in long words by typing only a few characters.", AutoCompletePlugin::New, - { 0, 2, 0 } }; + { 0, 2, 1 } }; } static UICodeEditorPlugin* New( PluginManager* pluginManager ); @@ -106,10 +106,8 @@ class AutoCompletePlugin : public UICodeEditorPlugin { void setDirty( bool dirty ); protected: - PluginManager* mManager{ nullptr }; std::string mSymbolPattern; Rectf mBoxPadding; - std::shared_ptr mPool; Clock mClock; Mutex mLangSymbolsMutex; Mutex mSuggestionsMutex; @@ -119,7 +117,6 @@ class AutoCompletePlugin : public UICodeEditorPlugin { std::set mDocs; std::unordered_map mEditorDocs; bool mDirty{ false }; - bool mClosing{ false }; bool mReplacing{ false }; bool mSignatureHelpVisible{ false }; struct DocCache { @@ -150,7 +147,7 @@ class AutoCompletePlugin : public UICodeEditorPlugin { Float mRowHeight{ 0 }; Rectf mBoxRect; - AutoCompletePlugin( PluginManager* pluginManager ); + explicit AutoCompletePlugin( PluginManager* pluginManager ); void resetSuggestions( UICodeEditor* editor ); diff --git a/src/tools/ecode/plugins/formatter/formatterplugin.cpp b/src/tools/ecode/plugins/formatter/formatterplugin.cpp index 3f60e1ad7..ad07beb27 100644 --- a/src/tools/ecode/plugins/formatter/formatterplugin.cpp +++ b/src/tools/ecode/plugins/formatter/formatterplugin.cpp @@ -32,23 +32,24 @@ UICodeEditorPlugin* FormatterPlugin::NewSync( PluginManager* pluginManager ) { } FormatterPlugin::FormatterPlugin( PluginManager* pluginManager, bool sync ) : - mManager( pluginManager ), mPool( pluginManager->getThreadPool() ) { + Plugin( pluginManager ) { if ( sync ) { load( pluginManager ); } else { #if FORMATTER_THREADED - mPool->run( [&, pluginManager] { load( pluginManager ); } ); + mThreadPool->run( [&, pluginManager] { load( pluginManager ); } ); #else load( pluginManager ); #endif } mManager->subscribeMessages( this, [&]( const PluginMessage& msg ) -> PluginRequestHandle { - return processResponse( msg ); + return processMessage( msg ); } ); } FormatterPlugin::~FormatterPlugin() { mShuttingDown = true; + unsubscribeFileSystemListener(); if ( mWorkersCount != 0 ) { std::unique_lock lock( mWorkMutex ); @@ -235,6 +236,9 @@ void FormatterPlugin::loadFormatterConfig( const std::string& path, bool updateC } void FormatterPlugin::load( PluginManager* pluginManager ) { + pluginManager->subscribeMessages( this, [&]( const auto& notification ) -> PluginRequestHandle { + return processMessage( notification ); + } ); registerNativeFormatters(); std::vector paths; @@ -260,14 +264,8 @@ void FormatterPlugin::load( PluginManager* pluginManager ) { mReady = !mFormatters.empty(); if ( mReady ) fireReadyCbs(); -} -bool FormatterPlugin::hasFileConfig() { - return !mConfigPath.empty(); -} - -std::string FormatterPlugin::getFileConfigPath() { - return mConfigPath; + subscribeFileSystemListener(); } bool FormatterPlugin::onCreateContextMenu( UICodeEditor* editor, UIPopUpMenu* menu, const Vector2i&, @@ -544,8 +542,10 @@ bool FormatterPlugin::tryRequestCapabilities( const std::shared_ptr& ext ); protected: - PluginManager* mManager{ nullptr }; - std::shared_ptr mPool; std::vector mFormatters; std::unordered_map> mEditors; std::mutex mWorkMutex; @@ -86,15 +78,12 @@ class FormatterPlugin : public UICodeEditorPlugin { std::map> mNativeFormatters; Int32 mWorkersCount{ 0 }; - std::string mConfigPath; std::map mKeyBindings; /* cmd, shortcut */ std::map mIsAutoFormatting; std::map mCapabilities; Mutex mCapabilitiesMutex; bool mAutoFormatOnSave{ false }; - bool mShuttingDown{ false }; - bool mReady{ false }; FormatterPlugin( PluginManager* pluginManager, bool sync ); @@ -118,7 +107,7 @@ class FormatterPlugin : public UICodeEditorPlugin { bool tryRequestCapabilities( const std::shared_ptr& doc ); - PluginRequestHandle processResponse( const PluginMessage& msg ); + PluginRequestHandle processMessage( const PluginMessage& msg ); }; } // namespace ecode diff --git a/src/tools/ecode/plugins/linter/linterplugin.cpp b/src/tools/ecode/plugins/linter/linterplugin.cpp index c648234b4..3123fb55a 100644 --- a/src/tools/ecode/plugins/linter/linterplugin.cpp +++ b/src/tools/ecode/plugins/linter/linterplugin.cpp @@ -31,13 +31,12 @@ UICodeEditorPlugin* LinterPlugin::NewSync( PluginManager* pluginManager ) { return eeNew( LinterPlugin, ( pluginManager, true ) ); } -LinterPlugin::LinterPlugin( PluginManager* pluginManager, bool sync ) : - mManager( pluginManager ), mPool( pluginManager->getThreadPool() ) { +LinterPlugin::LinterPlugin( PluginManager* pluginManager, bool sync ) : Plugin( pluginManager ) { if ( sync ) { load( pluginManager ); } else { #if LINTER_THREADED - mPool->run( [&, pluginManager] { load( pluginManager ); } ); + mThreadPool->run( [&, pluginManager] { load( pluginManager ); } ); #else load( pluginManager ); #endif @@ -47,6 +46,7 @@ LinterPlugin::LinterPlugin( PluginManager* pluginManager, bool sync ) : LinterPlugin::~LinterPlugin() { mShuttingDown = true; mManager->unsubscribeMessages( this ); + unsubscribeFileSystemListener(); if ( mWorkersCount != 0 ) { std::unique_lock lock( mWorkMutex ); @@ -60,14 +60,6 @@ LinterPlugin::~LinterPlugin() { } } -bool LinterPlugin::hasFileConfig() { - return !mConfigPath.empty(); -} - -std::string LinterPlugin::getFileConfigPath() { - return mConfigPath; -} - size_t LinterPlugin::linterFilePatternPosition( const std::vector& patterns ) { for ( size_t i = 0; i < mLinters.size(); ++i ) { for ( const std::string& filePattern : mLinters[i].files ) { @@ -310,6 +302,11 @@ void LinterPlugin::setMatches( TextDocument* doc, const MatchOrigin& origin, } PluginRequestHandle LinterPlugin::processMessage( const PluginMessage& notification ) { + if ( notification.type == PluginMessageType::FileSystemListenerReady ) { + subscribeFileSystemListener(); + return {}; + } + if ( notification.type == PluginMessageType::DiagnosticsCodeAction && notification.format == PluginMessageFormat::JSON && notification.isRequest() ) { PluginIDType id( std::numeric_limits::max() ); @@ -394,16 +391,18 @@ void LinterPlugin::load( PluginManager* pluginManager ) { } if ( paths.empty() ) return; - for ( const auto& path : paths ) { + for ( const auto& tpath : paths ) { try { - loadLinterConfig( path, mConfigPath == path ); + loadLinterConfig( tpath, mConfigPath == tpath ); } catch ( const json::exception& e ) { - Log::error( "Parsing linter \"%s\" failed:\n%s", path.c_str(), e.what() ); + Log::error( "Parsing linter \"%s\" failed:\n%s", tpath.c_str(), e.what() ); } } mReady = !mLinters.empty(); if ( mReady ) fireReadyCbs(); + + subscribeFileSystemListener(); } void LinterPlugin::onRegister( UICodeEditor* editor ) { @@ -474,7 +473,7 @@ void LinterPlugin::update( UICodeEditor* editor ) { if ( it != mDirtyDoc.end() && it->second->getElapsedTime() >= mDelayTime ) { mDirtyDoc.erase( doc.get() ); #if LINTER_THREADED - mPool->run( [&, doc] { lintDoc( doc ); } ); + mThreadPool->run( [&, doc] { lintDoc( doc ); } ); #else lintDoc( doc ); #endif @@ -687,9 +686,9 @@ void LinterPlugin::runLinter( std::shared_ptr doc, const Linter& l bool skip = false; if ( linter.deduplicate && matches.find( line - 1 ) != matches.end() ) { - for ( auto& match : matches[line - 1] ) { - if ( match.range == linterMatch.range ) { - match.text += "\n" + linterMatch.text; + for ( auto& tmatch : matches[line - 1] ) { + if ( tmatch.range == linterMatch.range ) { + tmatch.text += "\n" + linterMatch.text; skip = true; break; } diff --git a/src/tools/ecode/plugins/linter/linterplugin.hpp b/src/tools/ecode/plugins/linter/linterplugin.hpp index 3bbb3765c..3bf71b1e0 100644 --- a/src/tools/ecode/plugins/linter/linterplugin.hpp +++ b/src/tools/ecode/plugins/linter/linterplugin.hpp @@ -48,7 +48,7 @@ struct LinterMatch { std::vector codeActions; }; -class LinterPlugin : public UICodeEditorPlugin { +class LinterPlugin : public Plugin { public: static PluginDefinition Definition() { return { "linter", @@ -56,7 +56,7 @@ class LinterPlugin : public UICodeEditorPlugin { "Use static code analysis tool used to flag programming errors, bugs, " "stylistic errors, and suspicious constructs.", LinterPlugin::New, - { 0, 2, 0 }, + { 0, 2, 1 }, LinterPlugin::NewSync }; } @@ -72,12 +72,6 @@ class LinterPlugin : public UICodeEditorPlugin { std::string getDescription() { return Definition().description; } - bool isReady() const { return mReady; } - - bool hasFileConfig(); - - std::string getFileConfigPath(); - void onRegister( UICodeEditor* ); void onUnregister( UICodeEditor* ); @@ -111,8 +105,6 @@ class LinterPlugin : public UICodeEditorPlugin { Linter getLinterForLang( const std::string& lang, const std::vector& extensions ); protected: - PluginManager* mManager{ nullptr }; - std::shared_ptr mPool; std::vector mLinters; std::unordered_map> mEditors; std::set mDocs; @@ -125,10 +117,7 @@ class LinterPlugin : public UICodeEditorPlugin { std::mutex mWorkMutex; std::condition_variable mWorkerCondition; Int32 mWorkersCount{ 0 }; - std::string mConfigPath; - bool mReady{ false }; - bool mShuttingDown{ false }; bool mHoveringMatch{ false }; bool mEnableLSPDiagnostics{ true }; bool mErrorLens{ true }; diff --git a/src/tools/ecode/plugins/lsp/lspclientplugin.cpp b/src/tools/ecode/plugins/lsp/lspclientplugin.cpp index 3ecd8b7df..5c63d7fcd 100644 --- a/src/tools/ecode/plugins/lsp/lspclientplugin.cpp +++ b/src/tools/ecode/plugins/lsp/lspclientplugin.cpp @@ -117,7 +117,7 @@ UICodeEditorPlugin* LSPClientPlugin::NewSync( PluginManager* pluginManager ) { } LSPClientPlugin::LSPClientPlugin( PluginManager* pluginManager, bool sync ) : - mManager( pluginManager ), mThreadPool( pluginManager->getThreadPool() ) { + Plugin( pluginManager ) { if ( sync ) { load( pluginManager ); } else { @@ -126,8 +126,9 @@ LSPClientPlugin::LSPClientPlugin( PluginManager* pluginManager, bool sync ) : } LSPClientPlugin::~LSPClientPlugin() { - mClosing = true; + mShuttingDown = true; mManager->unsubscribeMessages( this ); + unsubscribeFileSystemListener(); Lock l( mDocMutex ); for ( const auto& editor : mEditors ) { for ( auto& kb : mKeyBindings ) { @@ -575,6 +576,10 @@ PluginRequestHandle LSPClientPlugin::processCancelRequest( const PluginMessage& PluginRequestHandle LSPClientPlugin::processMessage( const PluginMessage& msg ) { switch ( msg.type ) { + case PluginMessageType::FileSystemListenerReady: { + subscribeFileSystemListener(); + break; + } case PluginMessageType::WorkspaceFolderChanged: { mClientManager.didChangeWorkspaceFolders( msg.asJSON()["folder"] ); break; @@ -675,6 +680,8 @@ void LSPClientPlugin::load( PluginManager* pluginManager ) { mDelayedDocs.clear(); if ( mReady ) fireReadyCbs(); + + subscribeFileSystemListener(); } static std::string parseCommand( nlohmann::json cmd ) { @@ -1055,7 +1062,7 @@ void LSPClientPlugin::onUnregister( UICodeEditor* editor ) { editor->getDocument().removeCommand( kb.first ); } - if ( mClosing ) + if ( mShuttingDown ) return; Lock l( mDocMutex ); TextDocument* doc = &editor->getDocument(); @@ -1079,10 +1086,6 @@ void LSPClientPlugin::onUnregister( UICodeEditor* editor ) { mDocs.erase( doc ); } -PluginManager* LSPClientPlugin::getManager() const { - return mManager; -} - bool LSPClientPlugin::onCreateContextMenu( UICodeEditor* editor, UIPopUpMenu* menu, const Vector2i& /*position*/, const Uint32& /*flags*/ ) { auto* server = mClientManager.getOneLSPClientServer( editor ); @@ -1259,12 +1262,4 @@ const LSPClientServerManager& LSPClientPlugin::getClientManager() const { return mClientManager; } -bool LSPClientPlugin::hasFileConfig() { - return !mConfigPath.empty(); -} - -std::string LSPClientPlugin::getFileConfigPath() { - return mConfigPath; -} - } // namespace ecode diff --git a/src/tools/ecode/plugins/lsp/lspclientplugin.hpp b/src/tools/ecode/plugins/lsp/lspclientplugin.hpp index cfd7b0206..942bcf035 100644 --- a/src/tools/ecode/plugins/lsp/lspclientplugin.hpp +++ b/src/tools/ecode/plugins/lsp/lspclientplugin.hpp @@ -21,11 +21,11 @@ namespace ecode { // Implementation of the LSP Client: // https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/ -class LSPClientPlugin : public UICodeEditorPlugin { +class LSPClientPlugin : public Plugin { public: static PluginDefinition Definition() { return { "lspclient", "LSP Client", "Language Server Protocol Client.", - LSPClientPlugin::New, { 0, 2, 0 }, LSPClientPlugin::NewSync }; + LSPClientPlugin::New, { 0, 2, 1 }, LSPClientPlugin::NewSync }; } static UICodeEditorPlugin* New( PluginManager* pluginManager ); @@ -42,16 +42,12 @@ class LSPClientPlugin : public UICodeEditorPlugin { std::string getDescription() { return Definition().description; } - bool isReady() const { return true; } - void onRegister( UICodeEditor* ); void onUnregister( UICodeEditor* ); const std::unordered_map& getEditorDocs() { return mEditorDocs; }; - PluginManager* getManager() const; - virtual bool onCreateContextMenu( UICodeEditor* editor, UIPopUpMenu* menu, const Vector2i& position, const Uint32& flags ); @@ -67,10 +63,6 @@ class LSPClientPlugin : public UICodeEditorPlugin { const LSPClientServerManager& getClientManager() const; - bool hasFileConfig(); - - std::string getFileConfigPath(); - bool processDocumentFormattingResponse( const URI& uri, std::vector edits ); const LSPSymbolInformationList& getDocumentSymbols( TextDocument* doc ); @@ -91,8 +83,6 @@ class LSPClientPlugin : public UICodeEditorPlugin { friend class LSPDocumentClient; friend class LSPClientServer; - PluginManager* mManager{ nullptr }; - std::shared_ptr mThreadPool; Clock mClock; Mutex mDocMutex; Mutex mDocSymbolsMutex; @@ -103,9 +93,6 @@ class LSPClientPlugin : public UICodeEditorPlugin { std::map mDocFlatSymbols; std::unordered_map mEditorDocs; LSPClientServerManager mClientManager; - std::string mConfigPath; - bool mClosing{ false }; - bool mReady{ false }; bool mOldDontAutoHideOnMouseMove{ false }; bool mOldUsingCustomStyling{ false }; bool mSymbolInfoShowing{ false }; diff --git a/src/tools/ecode/plugins/lsp/lspclientserver.cpp b/src/tools/ecode/plugins/lsp/lspclientserver.cpp index 8f77bc46d..fc1f8eb07 100644 --- a/src/tools/ecode/plugins/lsp/lspclientserver.cpp +++ b/src/tools/ecode/plugins/lsp/lspclientserver.cpp @@ -1212,7 +1212,7 @@ bool LSPClientServer::needsAsync() { } bool LSPClientServer::isRunning() { - return mUsingProcess ? ( mProcess.isAlive() && !mProcess.isShootingDown() && + return mUsingProcess ? ( mProcess.isAlive() && !mProcess.isShuttingDown() && ( !mUsingSocket || mSocket != nullptr ) ) : ( mUsingSocket && mSocket != nullptr ); } @@ -1614,7 +1614,7 @@ void LSPClientServer::readStdOut( const char* bytes, size_t n ) { std::string& buffer = mReceive; - while ( ( mUsingProcess && !mProcess.isShootingDown() ) || + while ( ( mUsingProcess && !mProcess.isShuttingDown() ) || ( mUsingSocket && mSocket != nullptr ) ) { auto index = buffer.find( CONTENT_LENGTH_HEADER ); if ( index == std::string::npos ) { diff --git a/src/tools/ecode/plugins/pluginmanager.cpp b/src/tools/ecode/plugins/pluginmanager.cpp index 6f4fa52e0..8f1e7e06b 100644 --- a/src/tools/ecode/plugins/pluginmanager.cpp +++ b/src/tools/ecode/plugins/pluginmanager.cpp @@ -1,4 +1,5 @@ #include "pluginmanager.hpp" +#include "../filesystemlistener.hpp" #include #include #include @@ -56,6 +57,16 @@ bool PluginManager::isEnabled( const std::string& id ) const { return mPluginsEnabled.find( id ) != mPluginsEnabled.end() ? mPluginsEnabled.at( id ) : false; } +bool PluginManager::reload( const std::string& id ) { + if ( isEnabled( id ) ) { + Log::warning( "PluginManager reloading plugin: %s", id.c_str() ); + setEnabled( id, false ); + setEnabled( id, true ); + return true; + } + return false; +} + const std::string& PluginManager::getResourcesPath() const { return mResourcesPath; } @@ -218,6 +229,14 @@ void PluginManager::setSplitter( UICodeEditorSplitter* splitter ) { mSplitter = splitter; } +void PluginManager::setFileSystemListener( FileSystemListener* listener ) { + if ( listener == mFileSystemListener ) + return; + mFileSystemListener = listener; + sendBroadcast( PluginMessageType::FileSystemListenerReady, PluginMessageFormat::Empty, + nullptr ); +} + void PluginManager::sendBroadcast( const PluginMessageType& notification, const PluginMessageFormat& format, void* data ) { if ( mClosing ) @@ -412,4 +431,52 @@ UIWindow* UIPluginManager::New( UISceneNode* sceneNode, PluginManager* manager, return win; } +Plugin::Plugin( PluginManager* manager ) : + mManager( manager ), mThreadPool( manager->getThreadPool() ) {} + +void Plugin::subscribeFileSystemListener() { + if ( mFileSystemListenerCb != 0 || mManager->getFileSystemListener() == nullptr ) + return; + + mConfigFileInfo = FileInfo( mConfigPath ); + + mFileSystemListenerCb = mManager->getFileSystemListener()->addListener( + [this]( const FileEvent& ev, const FileInfo& file ) { + if ( ev.type != FileSystemEventType::Modified ) + return; + if ( !mShuttingDown && file.getFilepath() == mConfigPath && + file.getModificationTime() != mConfigFileInfo.getModificationTime() ) { + mConfigFileInfo = file; + mManager->getFileSystemListener()->removeListener( mFileSystemListenerCb ); + mFileSystemListenerCb = 0; + mManager->reload( getId() ); + } + } ); +} + +void Plugin::unsubscribeFileSystemListener() { + if ( mFileSystemListenerCb != 0 && mManager->getFileSystemListener() ) + mManager->getFileSystemListener()->removeListener( mFileSystemListenerCb ); +} + +bool Plugin::isReady() const { + return mReady; +} + +bool Plugin::isShuttingDown() const { + return mShuttingDown; +} + +bool Plugin::hasFileConfig() { + return !mConfigPath.empty(); +} + +std::string Plugin::getFileConfigPath() { + return mConfigPath; +} + +PluginManager* Plugin::getManager() const { + return mManager; +} + } // namespace ecode diff --git a/src/tools/ecode/plugins/pluginmanager.hpp b/src/tools/ecode/plugins/pluginmanager.hpp index e0b2199f5..301083266 100644 --- a/src/tools/ecode/plugins/pluginmanager.hpp +++ b/src/tools/ecode/plugins/pluginmanager.hpp @@ -3,6 +3,7 @@ #include "../projectsearch.hpp" #include "lsp/lspprotocol.hpp" +#include #include #include #include @@ -22,6 +23,7 @@ using namespace EE::UI::Tools; namespace ecode { class PluginManager; +class FileSystemListener; typedef std::function PluginCreatorFn; @@ -77,10 +79,13 @@ enum class PluginMessageType { TextDocumentSymbol, // Request to the LSP server the document symbols TextDocumentFlattenSymbol, // Request to the LSP server the document symbols flattened DiagnosticsCodeAction, // Request a code action to anyone that can handle it + FileSystemListenerReady, // Broadcast to inform the plugins that the file system listener is + // available Undefined }; enum class PluginMessageFormat { + Empty, JSON, Diagnostics, CodeCompletion, @@ -237,6 +242,8 @@ class PluginManager { bool isEnabled( const std::string& id ) const; + bool reload( const std::string& id ); + const std::string& getResourcesPath() const; const std::string& getPluginsPath() const; @@ -289,6 +296,8 @@ class PluginManager { void unsubscribeMessages( const std::string& uniqueComponentId ); + FileSystemListener* getFileSystemListener() const { return mFileSystemListener; }; + protected: using SubscribedPlugins = std::map>; @@ -301,6 +310,7 @@ class PluginManager { std::map mDefinitions; std::shared_ptr mThreadPool; UICodeEditorSplitter* mSplitter{ nullptr }; + FileSystemListener* mFileSystemListener{ nullptr }; Mutex mSubscribedPluginsMutex; SubscribedPlugins mSubscribedPlugins; bool mClosing{ false }; @@ -308,6 +318,8 @@ class PluginManager { bool hasDefinition( const std::string& id ); void setSplitter( UICodeEditorSplitter* splitter ); + + void setFileSystemListener( FileSystemListener* listener ); }; class PluginsModel : public Model { @@ -348,6 +360,34 @@ class UIPluginManager { std::function loadFileCb ); }; +class Plugin : public UICodeEditorPlugin { + public: + explicit Plugin( PluginManager* manager ); + + void subscribeFileSystemListener(); + + void unsubscribeFileSystemListener(); + + bool isReady() const; + + bool isShuttingDown() const; + + virtual bool hasFileConfig(); + + virtual std::string getFileConfigPath(); + + PluginManager* getManager() const; + + protected: + PluginManager* mManager{ nullptr }; + std::shared_ptr mThreadPool; + Uint64 mFileSystemListenerCb{ 0 }; + std::string mConfigPath; + FileInfo mConfigFileInfo; + bool mReady{ false }; + bool mShuttingDown{ false }; +}; + } // namespace ecode #endif // ECODE_PLUGINMANAGER_HPP diff --git a/src/tools/ecode/projectdirectorytree.cpp b/src/tools/ecode/projectdirectorytree.cpp index f5c295ef0..9eab905db 100644 --- a/src/tools/ecode/projectdirectorytree.cpp +++ b/src/tools/ecode/projectdirectorytree.cpp @@ -21,7 +21,8 @@ ProjectDirectoryTree::ProjectDirectoryTree( const std::string& path, } ProjectDirectoryTree::~ProjectDirectoryTree() { - mApp->getPluginManager()->unsubscribeMessages( "ProjectDirectoryTree" ); + if ( mApp->getPluginManager() ) + mApp->getPluginManager()->unsubscribeMessages( "ProjectDirectoryTree" ); Lock rl( mMatchingMutex ); if ( mRunning ) { mRunning = false; diff --git a/src/tools/ecode/settingsmenu.cpp b/src/tools/ecode/settingsmenu.cpp index 2855d98ad..86e33bc2e 100644 --- a/src/tools/ecode/settingsmenu.cpp +++ b/src/tools/ecode/settingsmenu.cpp @@ -1295,7 +1295,8 @@ UIMenu* SettingsMenu::createHelpMenu() { ->setId( "ecode-source" ); helpMenu->add( i18n( "check_for_updates", "Check for Updates..." ), findIcon( "refresh" ) ) ->setId( "check-for-updates" ); - helpMenu->add( i18n( "about_ecode", "About ecode..." ) )->setId( "about-ecode" ); + helpMenu->add( i18n( "about_ecode", "About ecode..." ), findIcon( "ecode" ) ) + ->setId( "about-ecode" ); helpMenu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { runCommand( event->getNode()->getId() ); } ); diff --git a/src/tools/textureatlaseditor/textureatlaseditor.cpp b/src/tools/textureatlaseditor/textureatlaseditor.cpp index bd698f8ad..9ad0d1a14 100644 --- a/src/tools/textureatlaseditor/textureatlaseditor.cpp +++ b/src/tools/textureatlaseditor/textureatlaseditor.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -25,8 +26,7 @@ bool onCloseRequestCallback( EE::Window::Window* ) { MsgBox = UIMessageBox::New( UIMessageBox::OK_CANCEL, "Do you really want to close the texture atlas editor?\nAll changes will be lost." ); - MsgBox->addEventListener( Event::OnConfirm, - []( const Event* ) { win->close(); } ); + MsgBox->addEventListener( Event::OnConfirm, []( const Event* ) { win->close(); } ); MsgBox->addEventListener( Event::OnClose, []( const Event* ) { MsgBox = NULL; } ); MsgBox->setTitle( "Close Texture Atlas Editor?" ); MsgBox->center(); @@ -60,6 +60,10 @@ void mainLoop() { uiSceneNode->setDrawDebugData( !uiSceneNode->getDrawDebugData() ); } + if ( win->getInput()->isKeyUp( KEY_F12 ) ) { + UIWidgetInspector::create( uiSceneNode, PixelDensity::dpToPx( 16 ) ); + } + SceneManager::instance()->update(); if ( uiSceneNode->invalidated() ) { diff --git a/src/tools/uieditor/uieditor.cpp b/src/tools/uieditor/uieditor.cpp index 9123ec579..2f44730ce 100644 --- a/src/tools/uieditor/uieditor.cpp +++ b/src/tools/uieditor/uieditor.cpp @@ -146,9 +146,12 @@ void App::unloadFonts() { void App::loadImage( std::string path ) { std::string filename( FileSystem::fileRemoveExtension( FileSystem::fileNameFromPath( path ) ) ); - Uint32 texId = TextureFactory::instance()->loadFromFile( path ); - TextureRegion* texRegion = GlobalTextureAtlas::instance()->add( texId, filename ); - mImagesLoaded[texId] = texRegion; + Texture* tex = TextureFactory::instance()->loadFromFile( path ); + if ( tex ) { + Uint32 texId = tex->getTextureId(); + TextureRegion* texRegion = GlobalTextureAtlas::instance()->add( texId, filename ); + mImagesLoaded[texId] = texRegion; + } } FontTrueType* App::loadFont( const std::string& name, std::string fontPath, @@ -1017,7 +1020,7 @@ UIFileDialog* App::saveFileDialog( UICodeEditor* editor, bool focusOnClose ) { } ); if ( focusOnClose ) { dialog->addEventListener( Event::OnWindowClose, [&, editor]( const Event* ) { - if ( editor && !SceneManager::instance()->isShootingDown() ) + if ( editor && !SceneManager::instance()->isShuttingDown() ) editor->setFocus(); } ); } @@ -1487,7 +1490,7 @@ void App::saveAllProcess() { } ); dialog->addEventListener( Event::OnWindowClose, [&, editor]( const Event* ) { mTmpDocs.erase( &editor->getDocument() ); - if ( !SceneManager::instance()->isShootingDown() && !mTmpDocs.empty() ) + if ( !SceneManager::instance()->isShuttingDown() && !mTmpDocs.empty() ) saveAllProcess(); } ); return true;