mrShaderButtonHandler Class Reference
 
 
 
mrShaderButtonHandler Class Reference

This reference page is linked to from the following overview topics: Mental Ray Classes.


#include <mrShaderButtonHandler.h>

Inheritance diagram for mrShaderButtonHandler:
DADMgr InterfaceServer MaxHeapOperators

Public Member Functions

  mrShaderButtonHandler (unsigned int applyTypes, int ctrlID)
virtual  ~mrShaderButtonHandler ()
void  OnInitDialog (HWND hDialog)
void  OnCommand ()
void  OnClose ()
void  Update ()
void  Enable (bool enable)
virtual SClass_ID  GetDragType (HWND hwnd, POINT p)
virtual ReferenceTarget GetInstance (HWND hwnd, POINT p, SClass_ID type)
virtual BOOL  OkToDrop (ReferenceTarget *dropThis, HWND hfrom, HWND hto, POINT p, SClass_ID type, BOOL isNew=FALSE)
virtual int  SlotOwner ()
virtual void  Drop (ReferenceTarget *dropThis, HWND hwnd, POINT p, SClass_ID type, DADMgr *srcMgr=NULL, BOOL bSrcClone=FALSE)
virtual BOOL  AutoTooltip ()

Protected Member Functions

virtual void  SetShader (Texmap *shader)=0
virtual Texmap GetShader ()=0
virtual const MCHAR *  GetNoneString ()=0

Constructor & Destructor Documentation

mrShaderButtonHandler ( unsigned int  applyTypes,
int  ctrlID 
)
: m_shaderFilter(applyTypes, TYPE_MAX_TYPE, true),
  m_ctrlID(ctrlID),
  m_dialogHWnd(NULL)
{

}
~mrShaderButtonHandler ( ) [virtual]
                                              {

}

Member Function Documentation

void OnInitDialog ( HWND  hDialog )
                                                     {

        m_dialogHWnd = hDialog;

        DbgAssert(m_dialogHWnd != NULL);

        HWND ctrlHWnd = GetDlgItem(m_dialogHWnd, m_ctrlID);
        ICustButton* custButton = GetICustButton(ctrlHWnd);
        if(custButton != NULL) {
                custButton->SetDADMgr(this);
                ReleaseICustButton(custButton);
        }
        else {
                DbgAssert(false);
        }

        Update();
}
void OnCommand ( )
                                      {

        DbgAssert(m_dialogHWnd != NULL);

        // Add the filter
        IMtlBrowserFilter_Manager* filterManager = Get_IMtlBrowserFilter_Manager();
        if(filterManager != NULL) {
                filterManager->AddFilter(m_shaderFilter);
        }

        // Browse for a texmap
        BOOL newMat;
        BOOL cancel;
        MtlBase* mtlBase = GetCOREInterface()->DoMaterialBrowseDlg(m_dialogHWnd, (BROWSE_MAPSONLY | BROWSE_INCNONE), newMat, cancel);
        if(!cancel) {
                DbgAssert((mtlBase == NULL) || ((mtlBase->SuperClassID() == TEXMAP_CLASS_ID)));

                Texmap* texmap = static_cast<Texmap*>(mtlBase);
                SetShader(texmap);
        
                Update();
        }

        if(filterManager != NULL) {
                filterManager->RemoveFilter(m_shaderFilter);
        }
}
void OnClose ( )
                                    {

        DbgAssert(m_dialogHWnd != NULL);
        m_dialogHWnd = NULL;
}
void Update ( )
                                   {

        DbgAssert(m_dialogHWnd != NULL);

        HWND ctrlHWnd = GetDlgItem(m_dialogHWnd, m_ctrlID);
        ICustButton* custButton = GetICustButton(ctrlHWnd);
        if(custButton != NULL) {

                MSTR text;
                Texmap* shader = GetShader();
                if(shader != NULL)
                        text = shader->GetFullName();
                else
                        text = GetNoneString();

                custButton->SetText(text.data());
                
                ReleaseICustButton(custButton);
        }
        else {
                DbgAssert(false);
        }
}
void Enable ( bool  enable )
                                              {

        DbgAssert(m_dialogHWnd != NULL);

        HWND ctrlHWnd = GetDlgItem(m_dialogHWnd, m_ctrlID);
        ICustButton* custButton = GetICustButton(ctrlHWnd);
        if(custButton != NULL) {
                custButton->Enable(enable);
                ReleaseICustButton(custButton);
        }
        else {
                DbgAssert(false);
        }
}
SClass_ID GetDragType ( HWND  hwnd,
POINT  p 
) [virtual]
Remarks:
This method is called on the item that supports drag and drop to see what (if anything) can be dragged from the point p. This method returns a super class id to indicate the type of item that can be dragged away. If it does not support anything being dragged from the specified point a SClass_ID of 0 should be returned.
Parameters:
HWND hwnd

The source window handle

POINT p

The screen point (relative to the window upper left as 0,0).

Implements DADMgr.

                                                               {

        return TEXMAP_CLASS_ID;
}
ReferenceTarget * GetInstance ( HWND  hwnd,
POINT  p,
SClass_ID  type 
) [virtual]
Remarks:
Return a pointer to the drag source.
Parameters:
HWND hwnd

The source window where the mouse down occurred.

POINT p

The point to drag from (position within hwnd).

SClass_ID type

The super class ID of the item to create.

Implements DADMgr.

                                                                                      {

        if(type == TEXMAP_CLASS_ID) {
                Texmap* shader = GetShader();
                return shader;
        }
        else {
                return NULL;
        }
}
BOOL OkToDrop ( ReferenceTarget dropThis,
HWND  hfrom,
HWND  hto,
POINT  p,
SClass_ID  type,
BOOL  isNew = FALSE 
) [virtual]
Remarks:
This method is called on potential dropee to see if can accept the specified type at the specified point.
Parameters:
ReferenceTarget *dropThis

A pointer to the item to check.

HWND hfrom

The window handle of the source.

HWND hto

The window handle of the destination.

POINT p

The point to check.

SClass_ID type

The super class ID of dropThis.

BOOL isNew = FALSE

TRUE if the item is a new instance; otherwise FALSE.
Returns:
TRUE if the specified item can be dropped; otherwise FALSE.

Implements DADMgr.

                                                                                                                         {

        if(type == TEXMAP_CLASS_ID) {

                Texmap* texmap = static_cast<Texmap*>(dropThis);
                if(texmap == NULL) {
                        return TRUE;
                }
                else {
                        return m_shaderFilter.Include(*texmap, 0);
                }
        }

        return FALSE;
}
int SlotOwner ( ) [virtual]
Remarks:
Returns a predefined value to indicate the source of the drag.
Returns:
One of the following values:

OWNER_MEDIT_SAMPLE

From a materials editor sample slot.

OWNER_NODE

From a node in the scene.

OWNER_MTL_TEX

From a button in a material or texture.

OWNER_SCENE

From a button in a light, modifier, atmospheric effect, etc.

OWNER_BROWSE_NEW

From the browser in the new category.

OWNER_BROWSE_LIB

From the browser in the library category.

OWNER_BROWSE_MEDIT

From the browser in the materials editor category.

OWNER_BROWSE_SCENE

From the browser in the scene category. OWNER_MATERIAL_EXPLORER

From the material explorer.
Default Implementation:
{ return OWNER_MTL_TEX; }

Reimplemented from DADMgr.

                                     {

        return OWNER_SCENE;
}
void Drop ( ReferenceTarget dropThis,
HWND  hwnd,
POINT  p,
SClass_ID  type,
DADMgr srcMgr = NULL,
BOOL  bSrcClone = FALSE 
) [virtual]
Remarks:
This is the method called to actually process the drop operation. This routine is called on the target with the pointer returned by the source's GetInstance(), or possibly a clone of it as the dropThis.
Parameters:
ReferenceTarget *dropThis

A pointer to the item to drop.

HWND hwnd

The destination window handle (where the mouse was released).

POINT p

The destination point (within hwnd).

SClass_ID type

The type of object being dropped -- the super class ID of dropThis.

DADMgr* srcMgr

The source DADMgr pointer. NULL by default.

BOOL bSrcClone

TRUE if the dropThis is a clone of the drag source object, FALSE otherwise. FALSE by default

Implements DADMgr.

                                                                                                             {

        DbgAssert(OkToDrop(dropThis, NULL, hwnd, p, type, FALSE));
        if((dropThis == NULL) || (dropThis->SuperClassID() == TEXMAP_CLASS_ID)) {
                Texmap* texmap = static_cast<Texmap*>(dropThis);
                SetShader(texmap);

                Update();
        }
}
BOOL AutoTooltip ( ) [virtual]
Remarks:
If this method returns TRUE, then Custom Buttons that use this DAD Manager will automatically support a tooltip that matches the button text. Note that this method will only show a tooltip when the button text is too long and thus exceeds the button size.
Default Implementation:
{ return FALSE; }

Reimplemented from DADMgr.

                                        {

        return TRUE;
}
virtual void SetShader ( Texmap shader ) [protected, pure virtual]
virtual Texmap* GetShader ( ) [protected, pure virtual]
virtual const MCHAR* GetNoneString ( ) [protected, pure virtual]