LightWrap++
AC++wrapperfortheLightWave3DSDK
gizmo_handler.h
Go to the documentation of this file.
1 #ifndef LWPP_GIZMO_HANDLER_H
2 #define LWPP_GIZMO_HANDLER_H
3 
4 #if LW_SDK >= 93
5 #include <lwgizmo.h>
7 
8 namespace lwpp
9 {
11 
16  {
17  public:
18  virtual void gzDone () {;}
19  virtual void gzDraw (lwpp::CustomObjAccess &){;}
20  virtual const char * gzHelp ( LWToolEvent *){return "";}
21  virtual bool gzDirty (){return false;}
22  virtual int gzCount (LWToolEvent *){return 0;}
23  virtual int gzHandle (LWToolEvent *, int i, LWDVector pos){return 0;}
24  virtual int gzStart (LWToolEvent *){return 0;}
25  virtual int gzAdjust ( LWToolEvent *, int i){return 0;}
26  virtual bool gzDown ( LWToolEvent *){return false;}
27  virtual void gzMove ( LWToolEvent *){;}
28  virtual void gzUp ( LWToolEvent *){;}
29  virtual void gzEvent ( int code){;}
30  virtual LWXPanelID gzPanel (){return 0;}
31 
32  virtual const LWItemID* gzPickItems (const LWItemID* drawitems){return drawitems;}
33  };
34 
36 
39  template <class T, int maxVersion = 2, int minVersion = 2>
41  {
42  public:
43  GizmoAdaptor(const char *className, const char *name, ServerTagInfo *tags)
44  {
45  LWServer::AddPlugin(className, name, Activate, tags);
46  }
48  static int Activate (int version, GlobalFunc *global, LWInstance inst, void *serverData)
49  {
50  if ( version > maxVersion ) return AFUNC_BADVERSION;
51  if ( version < minVersion ) return AFUNC_BADVERSION;
52  try
53  {
54  UNUSED(serverData);
55  lwpp::SetSuperGlobal(global);
56 
57  LWGizmo *plugin = static_cast<LWGizmo *>(inst);
58  //plugin->instance = inst;
59  plugin->pickItems = GizmoAdaptor::PickItems;
60  if (plugin->gizmo)
61  {
62  plugin->gizmo->done = GizmoAdaptor::Done;
63  plugin->gizmo->draw = GizmoAdaptor::Draw;
64  plugin->gizmo->help = GizmoAdaptor::Help;
65  plugin->gizmo->dirty = GizmoAdaptor::Dirty;
66  plugin->gizmo->count = GizmoAdaptor::Count;
67  plugin->gizmo->handle = GizmoAdaptor::Handle;
68  plugin->gizmo->start = GizmoAdaptor::Start;
69  plugin->gizmo->adjust = GizmoAdaptor::Adjust;
70  plugin->gizmo->down = GizmoAdaptor::Down;
71  plugin->gizmo->move = GizmoAdaptor::Move;
72  plugin->gizmo->up = GizmoAdaptor::Up;
73  plugin->gizmo->event = GizmoAdaptor::Event;
74  plugin->gizmo->panel = GizmoAdaptor::Panel;
75  }
76  return AFUNC_OK;
77  }
78  catch (std::exception &e)
79  {
80  lwpp::LWMessage::Error("An exception occured in GizmoAdaptor::Activate():", e.what());
81  return AFUNC_BADAPP;
82  }
83  }
84  private:
85 
86  static const LWItemID* PickItems (LWInstance instance, const LWItemID* drawitems)
87  {
88  try
89  {
90  T *plugin = (T *) instance;
91  return plugin->gzPickItems(drawitems);
92  }
93  catch (std::exception &e)
94  {
95  lwpp::LWMessage::Error("An exception occured in GizmoAdaptor::PickItems():", e.what());
96  return 0;
97  }
98  }
99 
100  static void Done (LWInstance instance)
101  {
102  try
103  {
104  T *plugin = (T *) instance;
105  plugin->gzDone();
106  }
107  catch (std::exception &e)
108  {
109  lwpp::LWMessage::Error("An exception occured in GizmoAdaptor::Done():", e.what());
110  }
111  }
112 
113  static void Draw (LWInstance instance, LWCustomObjAccess *coa)
114  {
115  try
116  {
117  T *plugin = (T *) instance;
118  plugin->gzDraw(lwpp::CustomObjAccess(coa));
119  }
120  catch (std::exception &e)
121  {
122  lwpp::LWMessage::Error("An exception occured in GizmoAdaptor::Draw():", e.what());
123  }
124  }
125 
126  static const char * Help (LWInstance instance, LWToolEvent *lte)
127  {
128  try
129  {
130  T *plugin = (T *) instance;
131  return plugin->gzHelp(lte);
132  }
133  catch (std::exception &e)
134  {
135  lwpp::LWMessage::Error("An exception occured in GizmoAdaptor::Help():", e.what());
136  return "";
137  }
138  }
139 
140  static int Dirty(LWInstance instance)
141  {
142  try
143  {
144  T *plugin = (T *) instance;
145  return plugin->gzDirty() ? 1 : 0;
146  }
147  catch (std::exception &e)
148  {
149  lwpp::LWMessage::Error("An exception occured in GizmoAdaptor::Dirty():", e.what());
150  return 0;
151  }
152  }
153 
154  static int Count (LWInstance instance, LWToolEvent *lte)
155  {
156  try
157  {
158  T *plugin = (T *) instance;
159  return plugin->gzCount(lte);
160  }
161  catch (std::exception &e)
162  {
163  lwpp::LWMessage::Error("An exception occured in GizmoAdaptor::Count():", e.what());
164  return 0;
165  }
166  }
167 
168  static int Handle (LWInstance instance, LWToolEvent *lte, int i, LWDVector pos)
169  {
170  try
171  {
172  T *plugin = (T *) instance;
173  return plugin->gzHandle(lte, i, pos);
174  }
175  catch (std::exception &e)
176  {
177  lwpp::LWMessage::Error("An exception occured in GizmoAdaptor::Handle():", e.what());
178  return 0;
179  }
180  }
181 
182  static int Start (LWInstance instance, LWToolEvent *lte)
183  {
184  try
185  {
186  T *plugin = (T *) instance;
187  return plugin->gzStart(lte);
188  }
189  catch (std::exception &e)
190  {
191  lwpp::LWMessage::Error("An exception occured in GizmoAdaptor::Start():", e.what());
192  return 0;
193  }
194  }
195 
196  static int Adjust (LWInstance instance, LWToolEvent *lte, int i)
197  {
198  try
199  {
200  T *plugin = (T *) instance;
201  return plugin->gzAdjust(lte, i);
202  }
203  catch (std::exception &e)
204  {
205  lwpp::LWMessage::Error("An exception occured in GizmoAdaptor::Adjust():", e.what());
206  return 0;
207  }
208  }
209 
210  static int Down (LWInstance instance, LWToolEvent *lte)
211  {
212  try
213  {
214  T *plugin = (T *) instance;
215  return plugin->gzDown(lte) ? 1 : 0;
216  }
217  catch (std::exception &e)
218  {
219  lwpp::LWMessage::Error("An exception occured in GizmoAdaptor::Down():", e.what());
220  return 0;
221  }
222  }
223 
224  static void Move (LWInstance instance, LWToolEvent *lte)
225  {
226  try
227  {
228  T *plugin = (T *) instance;
229  plugin->gzMove(lte);
230  }
231  catch (std::exception &e)
232  {
233  lwpp::LWMessage::Error("An exception occured in GizmoAdaptor::Move():", e.what());
234  }
235  }
236 
237  static void Up (LWInstance instance, LWToolEvent *lte)
238  {
239  try
240  {
241  T *plugin = (T *) instance;
242  plugin->gzUp(lte);
243  }
244  catch (std::exception &e)
245  {
246  lwpp::LWMessage::Error("An exception occured in GizmoAdaptor::Up():", e.what());
247  }
248  }
249 
250  static void Event (LWInstance instance, int code)
251  {
252  try
253  {
254  T *plugin = (T *) instance;
255  plugin->gzEvent(code);
256  }
257  catch (std::exception &e)
258  {
259  lwpp::LWMessage::Error("An exception occured in GizmoAdaptor::Event():", e.what());
260  }
261  }
262 
263  static LWXPanelID Panel (LWInstance instance)
264  {
265  try
266  {
267  T *plugin = (T *) instance;
268  return plugin->gzPanel();
269  }
270  catch (std::exception &e)
271  {
272  lwpp::LWMessage::Error("An exception occured in GizmoAdaptor::Panel():", e.what());
273  return 0;
274  }
275  }
276  };
277 
279 
284  {
285  public:
286  virtual void gzDraw (lwpp::CustomObjAccess &){;}
287  virtual const LWItemID* gzPickItems (const LWItemID* drawitems){return drawitems;}
288  };
289 
291 
294  template <class T, int maxVersion = 2, int minVersion = 2>
296  {
297  public:
298  GizmoDrawAdaptor(const char *className, const char *name, ServerTagInfo *tags)
299  {
300  LWServer::AddPlugin(className, name, Activate, tags);
301  }
303  static int Activate (int version, GlobalFunc *global, LWInstance inst, void *serverData)
304  {
305  if ( version > maxVersion ) return AFUNC_BADVERSION;
306  if ( version < minVersion ) return AFUNC_BADVERSION;
307  try
308  {
309  UNUSED(serverData);
310  lwpp::SetSuperGlobal(global);
311 
312  LWGizmo *plugin = static_cast<LWGizmo *>(inst);
313  //plugin->instance = inst;
314  plugin->pickItems = GizmoDrawAdaptor::PickItems;
315  if (plugin->gizmo)
316  {
317  plugin->gizmo->done = 0;
318  plugin->gizmo->draw = GizmoDrawAdaptor::Draw;
319  plugin->gizmo->help = 0;
320  plugin->gizmo->dirty = 0;
321  plugin->gizmo->count = 0;
322  plugin->gizmo->handle = 0;
323  plugin->gizmo->start = 0;
324  plugin->gizmo->adjust = 0;
325  plugin->gizmo->down = 0;
326  plugin->gizmo->move = 0;
327  plugin->gizmo->up = 0;
328  plugin->gizmo->event = 0;
329  plugin->gizmo->panel = 0;
330  }
331  return AFUNC_OK;
332  }
333  catch (std::exception &e)
334  {
335  lwpp::LWMessage::Error("An exception occured in GizmoAdaptor::Activate():", e.what());
336  return AFUNC_BADAPP;
337  }
338  }
339  private:
340 
341  static const LWItemID* PickItems (LWInstance instance, const LWItemID* drawitems)
342  {
343  try
344  {
345  T *plugin = (T *) instance;
346  return plugin->gzPickItems(drawitems);
347  }
348  catch (std::exception &e)
349  {
350  lwpp::LWMessage::Error("An exception occured in GizmoAdaptor::PickItems():", e.what());
351  return 0;
352  }
353  }
354 
355  static void Draw (LWInstance instance, LWCustomObjAccess *coa)
356  {
357  try
358  {
359  T *plugin = (T *) instance;
360  plugin->gzDraw(lwpp::CustomObjAccess(coa));
361  }
362  catch (std::exception &e)
363  {
364  lwpp::LWMessage::Error("An exception occured in GizmoAdaptor::Draw():", e.what());
365  }
366  }
367  };
368 
369 
370  // #define ADD_GIZMO(pluginClass, type, min, max) \
371 
372 
373 } // end lwpp
374 #endif // version check
375 
376 #endif // LWPP_GIZMO_HANDLER_H