From ca16dc6019c7021bcd4120b750ac0e63284c71d6 Mon Sep 17 00:00:00 2001 From: John Haddon Date: Fri, 8 Mar 2024 16:51:55 +0000 Subject: [PATCH] Pointer : Remove use of `IECoreImage::ImagePrimitive` We want to phase ImagePrimitive out over time, and this is a small step in that direction. This does leave us only being able to create ImagePrimitives from filenames, but that is the only constructor we've ever used anyway. If we did want to construct from arbitrary in-memory data, I'm not sure what we'd choose. We wouldn't want to use `QPixmap` because the goal of GafferUI is to entirely hide Qt from the public API. So maybe `OIIO::ImageBuf`? That's for another day though since we don't need it at the moment. --- Changes.md | 4 ++++ include/GafferUI/Pointer.h | 6 ++---- python/GafferUI/_Pointer.py | 2 +- src/GafferUI/Pointer.cpp | 28 ++++----------------------- src/GafferUIModule/PointerBinding.cpp | 8 +------- 5 files changed, 12 insertions(+), 36 deletions(-) diff --git a/Changes.md b/Changes.md index 578615c4774..d6ef0e4d5f4 100644 --- a/Changes.md +++ b/Changes.md @@ -14,11 +14,15 @@ Breaking Changes ---------------- - CyclesOptions : Changed `hairShape` default value to "ribbon", to match Cycles' and Blender's own defaults. +- Pointer : + - Removed `Pointer( const ImagePrimitive * )` constructor. + - Removed `image()` method. API --- - ImageGadget : Removed `textureLoader()` method. +- Pointer : Added `fileName()` method. [^1]: To be omitted from final release notes for 1.4.0.0. diff --git a/include/GafferUI/Pointer.h b/include/GafferUI/Pointer.h index 57c9efb8ecb..cf91589477c 100644 --- a/include/GafferUI/Pointer.h +++ b/include/GafferUI/Pointer.h @@ -56,13 +56,11 @@ class GAFFERUI_API Pointer : public IECore::RefCounted IE_CORE_DECLAREMEMBERPTR( Pointer ) - /// A copy of the image is taken. - explicit Pointer( const IECoreImage::ImagePrimitive *image, const Imath::V2i &hotspot = Imath::V2i( -1 ) ); /// Images are loaded from the paths specified by the /// GAFFERUI_IMAGE_PATHS environment variable. Pointer( const std::string &fileName, const Imath::V2i &hotspot = Imath::V2i( -1 ) ); - const IECoreImage::ImagePrimitive *image() const; + const std::string &fileName() const; const Imath::V2i &hotspot() const; /// Sets the current pointer. Passing null resets the @@ -83,7 +81,7 @@ class GAFFERUI_API Pointer : public IECore::RefCounted private : - IECoreImage::ConstImagePrimitivePtr m_image; + std::string m_fileName; Imath::V2i m_hotspot; }; diff --git a/python/GafferUI/_Pointer.py b/python/GafferUI/_Pointer.py index 01368834993..58b89d4af9d 100644 --- a/python/GafferUI/_Pointer.py +++ b/python/GafferUI/_Pointer.py @@ -55,7 +55,7 @@ def __pointerChanged() : application.restoreOverrideCursor() __cursorOverridden = False else : - pixmap = GafferUI.Image._qtPixmapFromImagePrimitive( pointer.image() ) + pixmap = GafferUI.Image._qtPixmapFromFile( pointer.fileName() ) cursor = QtGui.QCursor( pixmap, pointer.hotspot().x, pointer.hotspot().y ) if __cursorOverridden : application.changeOverrideCursor( cursor ) diff --git a/src/GafferUI/Pointer.cpp b/src/GafferUI/Pointer.cpp index 8daa1871dbb..2985114104f 100644 --- a/src/GafferUI/Pointer.cpp +++ b/src/GafferUI/Pointer.cpp @@ -82,34 +82,14 @@ static Registry ®istry() } // namespace -Pointer::Pointer( const IECoreImage::ImagePrimitive *image, const Imath::V2i &hotspot ) - : m_image( image->copy() ), m_hotspot( hotspot ) -{ -} - Pointer::Pointer( const std::string &fileName, const Imath::V2i &hotspot ) - : m_image( nullptr ), m_hotspot( hotspot ) + : m_fileName( fileName ), m_hotspot( hotspot ) { - static IECore::CachedReaderPtr g_reader; - if( !g_reader ) - { - const char *sp = getenv( "GAFFERUI_IMAGE_PATHS" ); - sp = sp ? sp : ""; - g_reader = new IECore::CachedReader( IECore::SearchPath( sp ) ); - } - - m_image = IECore::runTimeCast( g_reader->read( fileName ) ); - if( !m_image ) - { - throw IECore::Exception( - fmt::format( "File \"{}\" does not contain an image.", fileName ) - ); - } } -const IECoreImage::ImagePrimitive *Pointer::image() const +const std::string &Pointer::fileName() const { - return m_image.get(); + return m_fileName; } const Imath::V2i &Pointer::hotspot() const @@ -125,7 +105,7 @@ void Pointer::setCurrent( ConstPointerPtr pointer ) } if( pointer && g_current && - pointer->image()->isEqualTo( g_current->image() ) && + pointer->fileName() == g_current->fileName() && pointer->hotspot() == g_current->hotspot() ) { diff --git a/src/GafferUIModule/PointerBinding.cpp b/src/GafferUIModule/PointerBinding.cpp index 2dedcb706d0..4a9f366119d 100644 --- a/src/GafferUIModule/PointerBinding.cpp +++ b/src/GafferUIModule/PointerBinding.cpp @@ -51,11 +51,6 @@ using namespace GafferUI; namespace { -IECoreImage::ImagePrimitivePtr image( Pointer *pointer ) -{ - return const_cast( pointer->image() ); -} - PointerPtr getCurrent() { return const_cast( Pointer::getCurrent() ); @@ -66,9 +61,8 @@ PointerPtr getCurrent() void GafferUIModule::bindPointer() { scope s = IECorePython::RefCountedClass( "Pointer" ) - .def( init( ( arg( "image" ), arg( "hotspot" ) = Imath::V2i( -1 ) ) ) ) .def( init( ( arg( "fileName" ), arg( "hotspot" ) = Imath::V2i( -1 ) ) ) ) - .def( "image", &image ) + .def( "fileName", &Pointer::fileName, return_value_policy() ) .def( "hotspot", &Pointer::hotspot, return_value_policy() ) .def( "setCurrent", (void (*)( ConstPointerPtr ))&Pointer::setCurrent ) .def( "setCurrent", (void (*)( const std::string & ))&Pointer::setCurrent )