I tried implementing the IMaxIcon interface.
But I'm not sure I'm doing it right.
I added my code below.
I create a managed ImageList and used its Handle properties for the implementation of the IMaxIcon properties.
The GetLocalizedImage function is just a wrapper that get the images from the resources. I created four icons, in PNG format with a transparent background. Two of these are the large 24x24 normal and disabled icons and the other are the small 16x16 icons.
What is not clear for me is on how to implement the following:
IBaseInterface IInterfaceServer.GetInterface(IInterface_ID id)
bool IEquatable<IInterfaceServer>.Equals(IInterfaceServer other)
IntPtr INativeObject.Handle
When I add this class in my ActionItem as the icon and that I try to customize the user interface to add them as tool bar, I get the following warning:
System.InvalidCastException: Impossible d'effectuer un cast d'un objet de type 'JigSaw_MaxTools.JigSawMaxIcon' en type 'Autodesk.Max.IImplementable'.
A Autodesk.Max.Wrappers.MaxIcon.__ConvertToUnmanaged(IMaxIcon managed)
A Autodesk.Max.Wrappers.ManagedWrapperActionItem.GetIcon(ManagedWrapperActionItem* )
It is probably due to the three functions mentioned above that I did not implement... Sorry for the french. It says that it cannot cast my JigSawMaxIcon instance to a IImplementable.
Can anyone help me ?
public class JigSawMaxIcon : IMaxIcon
{
//Constructors
public JigSawMaxIcon(string p_LargeIconName, string p_LargeDisabledIconName, string p_SmallIconName, string p_SmallDisabledIconName)
{
m_LargeImageList = new ImageList();
m_LargeImageList.Images.Add(JigSaw_Resources.GetLocalizedImage(typeof(JigSawToolsPlugin).Assembly, p_LargeIconName, "JigSaw_MaxTools.Resources"));
m_LargeImageList.Images.Add(JigSaw_Resources.GetLocalizedImage(typeof(JigSawToolsPlugin).Assembly, p_LargeDisabledIconName, "JigSaw_MaxTools.Resources"));
m_SmallImageList = new ImageList();
m_SmallImageList.Images.Add(JigSaw_Resources.GetLocalizedImage(typeof(JigSawToolsPlugin).Assembly, p_SmallIconName, "JigSaw_MaxTools.Resources"));
m_SmallImageList.Images.Add(JigSaw_Resources.GetLocalizedImage(typeof(JigSawToolsPlugin).Assembly, p_SmallDisabledIconName, "JigSaw_MaxTools.Resources"));
}
//Implement the IMaxIcon interface
IntPtr IMaxIcon.DefaultImageList
{
get
{
return m_LargeImageList.Handle;
}
}
int IMaxIcon.GetLargeImageIndex(bool enabledVersion, System.Drawing.Color backgroundColor)
{
if (enabledVersion)
{
return 0;
}
else
{
return 1;
}
}
int IMaxIcon.GetSmallImageIndex(bool enabledVersion, System.Drawing.Color backgroundColor)
{
if (enabledVersion)
{
return 0;
}
else
{
return 1;
}
}
IntPtr IMaxIcon.LargeImageList
{
get
{
return m_LargeImageList.Handle;
}
}
IntPtr IMaxIcon.SmallImageList
{
get
{
return m_SmallImageList.Handle;
}
}
bool IMaxIcon.UsesAlphaMask
{
get { return false; }
}
IBaseInterface IInterfaceServer.GetInterface(IInterface_ID id)
{
//?
return null;
}
bool IEquatable<IInterfaceServer>.Equals(IInterfaceServer other)
{
//?
return false;
}
void IDisposable.Dispose()
{
m_LargeImageList.Dispose();
m_SmallImageList.Dispose();
}
IntPtr INativeObject.Handle
{
//?
get
{
return IntPtr.Zero;
}
}
//Members
ImageList m_LargeImageList;
ImageList m_SmallImageList;
}