Skip to content

Commit

Permalink
Pointer : Remove use of IECoreImage::ImagePrimitive
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
johnhaddon committed Mar 8, 2024
1 parent 5c059d6 commit ca16dc6
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 36 deletions.
4 changes: 4 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
6 changes: 2 additions & 4 deletions include/GafferUI/Pointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -83,7 +81,7 @@ class GAFFERUI_API Pointer : public IECore::RefCounted

private :

IECoreImage::ConstImagePrimitivePtr m_image;
std::string m_fileName;
Imath::V2i m_hotspot;

};
Expand Down
2 changes: 1 addition & 1 deletion python/GafferUI/_Pointer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
28 changes: 4 additions & 24 deletions src/GafferUI/Pointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,34 +82,14 @@ static Registry &registry()

} // 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<const IECoreImage::ImagePrimitive>( 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
Expand All @@ -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()
)
{
Expand Down
8 changes: 1 addition & 7 deletions src/GafferUIModule/PointerBinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ using namespace GafferUI;
namespace
{

IECoreImage::ImagePrimitivePtr image( Pointer *pointer )
{
return const_cast<IECoreImage::ImagePrimitive *>( pointer->image() );
}

PointerPtr getCurrent()
{
return const_cast<Pointer *>( Pointer::getCurrent() );
Expand All @@ -66,9 +61,8 @@ PointerPtr getCurrent()
void GafferUIModule::bindPointer()
{
scope s = IECorePython::RefCountedClass<Pointer, IECore::RefCounted>( "Pointer" )
.def( init<const IECoreImage::ImagePrimitive *, const Imath::V2i &>( ( arg( "image" ), arg( "hotspot" ) = Imath::V2i( -1 ) ) ) )
.def( init<const std::string &, const Imath::V2i &>( ( arg( "fileName" ), arg( "hotspot" ) = Imath::V2i( -1 ) ) ) )
.def( "image", &image )
.def( "fileName", &Pointer::fileName, return_value_policy<copy_const_reference>() )
.def( "hotspot", &Pointer::hotspot, return_value_policy<copy_const_reference>() )
.def( "setCurrent", (void (*)( ConstPointerPtr ))&Pointer::setCurrent )
.def( "setCurrent", (void (*)( const std::string & ))&Pointer::setCurrent )
Expand Down

0 comments on commit ca16dc6

Please sign in to comment.