LightWrap++
AC++wrapperfortheLightWave3DSDK
layouttool_handler.h
Go to the documentation of this file.
1 #ifndef LAYOUTTOOL_H
2 #define LAYOUTTOOL_H
3 
4 #include <lwpp/plugin_handler.h>
6 
7 #include <lwlaytool.h>
8 
9 namespace lwpp
10 {
12 
17  {
18  public:
20  LayoutToolHandler(void *g, void *context, LWError *err) : InstanceHandler(g, context, err, LWLAYOUTTOOL_CLASS)
21  {
22  ;
23  }
25  virtual ~LayoutToolHandler() {;}
26 
28  virtual void done ()
29  {
30  ;
31  }
32 
34 
37  virtual void draw (LWCustomObjAccess *co_access)
38  {
39  ;
40  }
42 
45  virtual const char *help (LWToolEvent *lwtool_event)
46  {
47  return "";
48  }
50  virtual int dirty ()
51  {
52  return 0;
53  }
55 
58  virtual int count (LWToolEvent *lwtool_event)
59  {
60  return 1;
61  }
63 
68  int handle (LWToolEvent *lwtool_event, int i, LWDVector handle_pos)
69  {
70  return 0;
71  }
73 
76  int start (LWToolEvent *lwtool_event)
77  {
78  return 0;
79  }
81 
87  virtual int adjust (LWToolEvent *lwtool_event, int i)
88  {
89  return 0;
90  }
92 
97  int down (LWToolEvent *lwtool_event)
98  {
99  return 0;
100  }
102  /*
103  * @param lwtool_event The event to the handle.
104  */
105  virtual void move (LWToolEvent *lwtool_event)
106  {
107  ;
108  }
110  /*
111  * @param inst A pointer to your user data. This will be passed to each of the tool callbacks.
112  * @param lwtool_event The event to the handle.
113  */
114  void up (LWToolEvent *lwtool_event)
115  {
116  ;
117  }
119  /*
120  * @param inst A pointer to your user data. This will be passed to each of the tool callbacks.
121  * @param code The event to the handle.
122  */
123  virtual void event (int code)
124  {
125  ;
126  }
128  /*
129  * @param inst A pointer to your user data. This will be passed to each of the tool callbacks.
130  */
131  virtual LWXPanelID panel ()
132  {
133  return 0;
134  }
135 
136  };
137 
138 
140 
143  template <class T>
145  {
146  public:
147 
148  LayoutToolAdaptor(const char *name, ServerTagInfo *tags)
149  {
150  LWServer::AddPlugin(LWLAYOUTTOOL_CLASS, name, Activate, tags);
151  }
153  static int Activate (int version, GlobalFunc *global, LWInstance inst, void *serverData)
154  {
155  UNUSED(serverData);
156  try
157  {
158  if ( version != LWLAYOUTTOOL_VERSION ) return AFUNC_BADVERSION;
159  lwpp::SetSuperGlobal(global);
160  LWLayoutTool *plugin = static_cast<LWLayoutTool *>(inst);
161 
162  InstanceAdaptor<T>::Activate(static_cast<LWInstanceFuncs *>(plugin->instance));
163  if (plugin->tool)
164  {
165  // Set the callback function for done
166  plugin->tool->done = Done;
167  }
168 
169  return AFUNC_OK;
170  }
171  catch (std::exception &e)
172  {
173  lwpp::LWMessage::Error("An exception occured in LayoutToolAdaptor::Activate():", e.what());
174  return AFUNC_BADAPP;
175  }
176  }
177  private:
178  // Every callback needs to be wrapped like this
179  // Make sure the function signature matches the one expected _exactly_ except for adding "static"
180  static void Done (LWInstance instance)
181  {
182  try
183  {
184  T *plugin = (T *) instance;
185  plugin->done();
186  }
187  catch (std::exception &e)
188  {
189  lwpp::LWMessage::Error("An exception occured in LayoutToolAdaptor::Done():", e.what());
190  }
191  }
192 
193  }; // end LayoutToolAdaptor
194 
195 
196 } // end namespace
197 
198 
199 #endif // LAYTOOL_H