MT Showcase SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
OperatorComponent.hpp
1 #ifndef OPERATORCOMPONENT_HPP
2 #define OPERATORCOMPONENT_HPP
3 
4 #include "Showcase.hpp"
5 #include "UIComponent.hpp"
6 
7 namespace Showcase
8 {
10  class SHOWCASE_API OperatorInstance : public UIComponentInstance
11  {
12  public:
13  typedef std::weak_ptr<MultiWidgets::Operator> OperatorWeakPtr;
14 
15  OperatorInstance(ComponentPtr comp, MultiWidgets::OperatorPtr instance);
16  virtual ~OperatorInstance();
17 
18  virtual void removeInstance() override;
19 
20  virtual MultiWidgets::OperatorPtr operatorInstance(MultiWidgets::Widget & host,
21  bool immediate = false) override;
22 
23  virtual void propertyReceived(const PropertyKey &key,
24  const PropertyValue &value) override;
25  virtual void propertyLost(const PropertyKey &key,
26  const PropertyValue &value) override;
27 
28  private:
29  OperatorWeakPtr m_instanceOperator;
30  MultiWidgets::OperatorPtr m_strongRef;
31 
32  MultiWidgets::WidgetWeakPtr m_hostWidget;
33  };
34 
36  class SHOWCASE_API OperatorComponent : public UIComponent
37  {
38  public:
39  OperatorComponent(std::function<MultiWidgets::OperatorPtr(void)> create);
40  MultiWidgets::OperatorPtr createOperator();
41 
42  protected:
43  virtual ComponentInstancePtr instanceImpl() override;
44 
45  private:
46  std::function<MultiWidgets::OperatorPtr(void)> m_createFunc;
47  };
48 
49  typedef std::shared_ptr<OperatorComponent> OperatorComponentPtr;
50  typedef std::weak_ptr<OperatorComponent> OperatorComponentWeakPtr;
51 }
52 
53 #define SHOWCASE_OPERATOR_COMPONENT(name, type) \
54 namespace {\
55 Showcase::FactoryRegistrant<Showcase::OperatorComponent> MW_PLUGIN_CONCAT(component, __LINE__) \
56 (name, [] { return std::make_shared<Showcase::OperatorComponent>(\
57  [] { return std::make_shared<type>(); } ); }); \
58 }
59 
60 #endif // OPERATORCOMPONENT_HPP