// RnWidgetExample.h : Declaration of the CRnWidgetExample

/**
Widget example shows how to create widget node, how to use tool manager listeners, using object picking and render attributes override mechanism
to change object render attributes.

To try the example, Drag & Drop WidgetExample object into /Widgets/Tools. Then drop some objects into scene and type. 

Widgets.ReplaceWidget('{5C9008D4-B6B3-4359-9E63-18D2FC228A6E}','/Widgets/Tools/WidgetExample','Default','','')

into command prompt. Hover with mouse around scene and pick objects using lclick. Example will render red wireframe of the object below
cursor and will display message box with object name when you lclick on it. Try to object with skeleton to see object picking translation mechanism.

Rclick to stop the example and show NAV widget.

*/
#pragma once
#include "resource.h"       // main symbols

// IRnWidgetExample
[
	object,
	uuid("D6057C1A-CD8F-4b75-A8A6-13FB1F1E9D2F"),
	helpstring("IRnWidgetExample Interface"),
	pointer_default(unique)
]
__interface IRnWidgetExample : IUnknown
{
};


// CRnWidgetExample

class ATL_NO_VTABLE CRnWidgetExample : 
    public CComObjectRootEx<CComGlobalsThreadModel>,
	public IRsUnknownNode,
	public IRsWidgetComponent,
	public IRsWidgetTool,
	public IRsToolManagerListener,
	public IRnWidgetExample
{
public:
	CRnWidgetExample();

    BEGIN_COM_MAP(CRnWidgetExample)
        COM_INTERFACE_ENTRY(IRnWidgetExample)
        COM_INTERFACE_ENTRY(IRsWidgetTool)
        COM_INTERFACE_ENTRY(IRsUnknownNode)
		COM_INTERFACE_ENTRY(IRsWidgetComponent)
		COM_INTERFACE_ENTRY(IRsToolManagerListener)
        COM_INTERFACE_ENTRY2(IUnknown, IRsUnknownNode)
        COM_INTERFACE_ENTRY2(IRsObject, IRsUnknownNode)
        COM_INTERFACE_ENTRY_AGGREGATE(DEF_GUIDNAME(IRsBaseNode), m_spUnkAgg.p)
        COM_INTERFACE_ENTRY_AGGREGATE_BLIND(m_spUnkAgg.p)    // Just for safety, the speed is slower only for unknown interfaces
    END_COM_MAP()

    DECLARE_GET_CONTROLLING_UNKNOWN()
	DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct();
	
	void FinalRelease() 
	{
        m_spUnkAgg.Release();
	}

public:


    // IRsUnknownNode
    STDMETHOD(OnGetValue)(CONID con_id, IRsDataCache* pDataCache, VARIANT* pVtData, RtBool* pHandled);
    STDMETHOD(OnSetValue)(CONID con_id, IRsDataCache* pDataCache, VARIANT* pvtData, RtBool* pHandled);
    STDMETHOD(OnDefaultValue)(CONID con_id, VARIANT* pVtData, RtBool* pHandled);
    STDMETHOD(OnInvalidate)(CONID con_id, RtBool* pHandled);
    STDMETHOD(OnInitialize)(void);
    STDMETHOD(OnLoadDefault)(void);
    STDMETHOD(OnDestroy)(void);

	//IRsWidgetTool
	STDMETHOD(WidgetToolActivate)(IRcUndoRedoGroup *pUndoRedo);
	STDMETHOD(WidgetToolDeactivate)();
	STDMETHOD(WidgetToolUpdate)(RtWidgetToolEvent *pEvent);
	STDMETHOD(WidgetToolSetup)(RtWidgetToolEvent *pEvent);


	//IRsWidgetComponent
	STDMETHOD(EnumRequiredNodes)(IRsNodeEnumerator *ppEnum) {return E_NOTIMPL;};
	STDMETHOD(EnumConnectedNodes)(IRsNodeEnumerator *ppEnum)  {return E_NOTIMPL;};
	STDMETHOD(SetActiveWidget)(IRsBaseNode *pWidget);
	STDMETHOD(IsActive)(RtBool *pbActive)  {return E_NOTIMPL;};
	STDMETHOD(SetTemplateNode)(IRsBaseNode *pNode) {return E_NOTIMPL;};

	//IRsToolManagerListener
	STDMETHOD(ProcessToolMngMessage)(RtToolMsgId msgId,VARIANT *vParam);

    // IRsObject
    RS_DECLARE_IRS_OBJECT(IRnWidgetExample, L"Widget SDK example")


private:
	HRESULT Deactivate();
	HRESULT Activate();
	HRESULT ProcessMouseMove(RtMouseEvent *pEvent,IRsNode *pViewNode);

	HRESULT RemoveHighLightPreview(IRsNode *pNode);
	HRESULT SetHighLightPreview(IRsNode *pNode);

    CComPtr<IUnknown> m_spUnkAgg;    
	CComPtr<IRsNode> m_spLastPickedObj;

	int m_last_position_x;
	int m_last_position_y;
};
