LightWrap++
AC++wrapperfortheLightWave3DSDK
xpanel.h
Go to the documentation of this file.
1 
5 #ifndef LWPP_XPANEL_H
6 #define LWPP_XPANEL_H
7 #include <lwxpanel.h>
8 #include <lwpp/global.h>
9 
10 namespace lwpp
11 {
13  #define LW_COLOUR(red, green, blue) (0x01000000 | (red<<16) | (blue<<8) | green)
14 
16  class XPanelFuncs : public GlobalBase<LWXPanelFuncs>
17  {
18  public:
20  {
21  ;
22  }
23  static LWXPanelID Create (int type, LWXPanelControl *ctrlDesc = 0)
24  {
25  return globPtr->create(type, ctrlDesc);
26  }
27  void Destroy (LWXPanelID lwxpanel)
28  {
29  if (lwxpanel) globPtr->destroy(lwxpanel);
30  }
31  static void Describe(LWXPanelID lwxpanel, LWXPanelDataDesc *ddesc, LWXPanelGetFunc *getf = 0, LWXPanelSetFunc *setf = 0)
32  {
33  globPtr->describe(lwxpanel, ddesc, getf, setf);
34  }
35  static void Hint(LWXPanelID lwxpanel,LWXPanelHint *hint, unsigned long ctl = 0)
36  {
37  globPtr->hint(lwxpanel, ctl, hint);
38  }
39  static int Post(LWXPanelID lwxpanel)
40  {
41 #ifdef _DEBUG
42  lwpp::dostream dout;
43  std::hex(dout);
44  dout << "Opening XPanel: " << lwxpanel << " (Post)\n";
45 #endif
46  return globPtr->post(lwxpanel);
47  }
48  static int Open(LWXPanelID lwxpanel)
49  {
50  return globPtr->open(lwxpanel);
51  }
52  static void ViewInst(LWXPanelID lwxpanel,void *inst)
53  {
54  globPtr->viewInst(lwxpanel, inst);
55  }
56  static void ViewRefresh(LWXPanelID lwxpanel)
57  {
58  globPtr->viewRefresh(lwxpanel);
59  }
60  // user data
62 
67  static void *getUserData(LWXPanelID lwxpanel,unsigned long id = 0)
68  {
69  return globPtr->getData(lwxpanel, id);
70  }
72 
77  static void setUserData(LWXPanelID lwxpanel, void *data, unsigned long id = 0)
78  {
79  globPtr->setData(lwxpanel, id, data);
80  }
81 
82  // Forms
83  static void *formGet(LWXPanelID lwxpanel,unsigned long id)
84  {
85  return globPtr->formGet(lwxpanel, id);
86  }
87  static char *getFormString (LWXPanelID lwxpanel,unsigned long id)
88  {
89  return (char *) formGet(lwxpanel, id);
90  }
91  static int getFormInt (LWXPanelID lwxpanel,unsigned long id)
92  {
93  return *((int *) formGet(lwxpanel, id));
94  }
95  static float getFormFloat (LWXPanelID lwxpanel,unsigned long id)
96  {
97  return *((float *) formGet(lwxpanel, id));
98  }
99  static void formSet(LWXPanelID lwxpanel,unsigned long id, void* data)
100  {
101  globPtr->formSet(lwxpanel, id, data);
102  }
103  static void setForm(LWXPanelID lwxpanel,unsigned long id, long data)
104  {
105  formSet(lwxpanel, id, &data);
106  }
107  static void setForm(LWXPanelID lwxpanel,unsigned long id, float data)
108  {
109  formSet(lwxpanel, id, &data);
110  }
111  static void setForm(LWXPanelID lwxpanel,unsigned long id, char *data)
112  {
113  formSet(lwxpanel, id, (void *)data);
114  }
115  static void setForm(LWXPanelID lwxpanel,unsigned long id, const char *data)
116  {
117  formSet(lwxpanel, id, (void *)data);
118  }
119  static int getVersion()
120  {
121  return globPtr->version;
122  }
123  static LWXPDrawFuncs *getDrawFuncs()
124  {
125  return globPtr->drawf;
126  }
127  };
128 
130  {
131  protected:
132  LWXPDrAreaID mAreaId;
133  LWXPDrawFuncs *mDrawFuncs;
135  public:
136  XPDrawArea(LWXPDrAreaID _id, int w, int h)
137  : mAreaId(_id), mWidth(w), mHeight(h)
138  {
139  XPanelFuncs xpf;
140  mDrawFuncs = xpf.getDrawFuncs();
141  }
142  XPDrawArea(LWXPDrAreaID _id, LWXPDrawFuncs *_df, int w, int h)
143  : mAreaId(_id), mDrawFuncs(_df), mWidth(w), mHeight(h)
144  {
145  ;
146  }
147 
148  int getWidth() const {return mWidth;}
149  int getHeight() const {return mHeight;}
150 
151  void drawPixel (int c, int x, int y ) const
152  {
153  mDrawFuncs->drawPixel(mAreaId, c, x, y);
154  }
155  void drawPixel (int r, int g, int b, int x, int y ) const
156  {
157  mDrawFuncs->drawRGBPixel(mAreaId, r, g, b, x, y);
158  }
159  void drawPixel (float r, float g, float b, int x, int y ) const
160  {
161  mDrawFuncs->drawRGBPixel(mAreaId, (int)(r * 255.0f), (int)(g * 255.0f), (int)(b * 255.0f), x, y);
162  }
163  void drawLine (int c, int x, int y, int x2, int y2 ) const
164  {
165  mDrawFuncs->drawLine(mAreaId, c, x, y, x2, y2);
166  }
167  void drawBox (int c, int x, int y, int w, int h ) const
168  {
169  mDrawFuncs->drawBox(mAreaId, c, x, y, w, h);
170  }
171  void drawBox (int r, int g, int b, int x, int y, int w, int h ) const
172  {
173  mDrawFuncs->drawRGBBox(mAreaId, r, g, b, x, y, w, h);
174  }
175  void clear (int r, int g, int b) const
176  {
177  drawBox(r, g, b, 0, 0, getWidth(), getHeight());
178  }
179  void clear (int c) const
180  {
181  drawBox(c, 0, 0, getWidth(), getHeight());
182  }
183  void drawBorder (int indent, int x, int y, int w, int h ) const
184  {
185  mDrawFuncs->drawBorder(mAreaId, indent, x, y, w, h);
186  }
187 
188  int textWidth (const char *s ) const
189  {
190  return mDrawFuncs->textWidth(mAreaId, const_cast<char *>(s));
191  }
192  int textHeight (const char *s ) const
193  {
194  return mDrawFuncs->textHeight(mAreaId, const_cast<char *>(s));
195  }
196  void drawText (const char *s, int c, int x, int y) const
197  {
198  mDrawFuncs->drawText(mAreaId, const_cast<char *>(s), c, x, y);
199  }
200  LWXPDrAreaID getID() {return mAreaId;}
201  };
202 
203 
205  class XPanel : protected XPanelFuncs
206  {
207  private:
208  LWXPanelID lwxpanel;
209  bool destroy_on_exit;
210  protected:
211  void formSet(unsigned int id, void* data)
212  {
213  globPtr->formSet(lwxpanel, id, data);
214  }
215  void *formGet(unsigned int id)
216  {
217  return globPtr->formGet(lwxpanel, id);
218  }
219  public:
220  void Create (int type, LWXPanelControl *ctrlDesc = NULL, bool auto_close = true)
221  {
222  lwxpanel = globPtr->create(type, ctrlDesc);
223  destroy_on_exit = auto_close;
224  }
225  void Destroy ()
226  {
227  if (lwxpanel) globPtr->destroy(lwxpanel);
228  lwxpanel = 0;
229  }
231 
234  XPanel(LWXPanelID panID = 0, bool auto_close = false) : lwxpanel(panID), destroy_on_exit(auto_close)
235  {
236  ;
237  }
239 
242  XPanel(int type, LWXPanelControl *ctrlDesc, bool auto_close = true) : lwxpanel(0), destroy_on_exit(auto_close)
243  {
244  Create(type, ctrlDesc, auto_close);
245  }
247  {
248  if (destroy_on_exit) Destroy();
249  }
250  void DestroyOnExit(bool doIt)
251  {
252  destroy_on_exit = doIt;
253  }
254  bool isValid()
255  {
256  return (lwxpanel != 0);
257  }
258  void Describe(LWXPanelDataDesc *ddesc, LWXPanelGetFunc *getf = 0, LWXPanelSetFunc *setf = 0)
259  {
260  if (lwxpanel) globPtr->describe(lwxpanel, ddesc, getf, setf);
261  }
262  void Hint(LWXPanelHint *hint, unsigned int ctl = 0)
263  {
264  if (lwxpanel) globPtr->hint(lwxpanel, ctl, hint);
265  }
266  LWXPanelID getID() const
267  {
268  return lwxpanel;
269  }
270  void setID(LWXPanelID id)
271  {
272  lwxpanel = id;
273  }
274  int Post()
275  {
276 #ifdef _DEBUG
277  lwpp::dostream dout;
278  std::hex(dout);
279  dout << "Opening XPanel: " << lwxpanel << " (Post)\n";
280 #endif
281  return globPtr->post(lwxpanel);
282  }
283  int Open()
284  {
285  return globPtr->open(lwxpanel);
286  }
287  void ViewInst(void *inst)
288  {
289  globPtr->viewInst(lwxpanel, inst);
290  }
291  void ViewRefresh()
292  {
293  globPtr->viewRefresh(lwxpanel);
294  }
295  static void ViewRefresh(LWXPanelID panel)
296  {
297  globPtr->viewRefresh(panel);
298  }
299  void setAutoDestroy(bool close)
300  {
301  destroy_on_exit = close;
302  }
303  // user data
304  void *getUserData(unsigned int id = 0)
305  {
306  return globPtr->getData(lwxpanel, id);
307  }
308  template <typename T>
309  T getUserData(unsigned int id = 0)
310  {
311  return static_cast<T >(globPtr->getData(lwxpanel, id));
312  }
313 
314  void setUserData(void *data, unsigned int id = 0)
315  {
316  globPtr->setData(lwxpanel, id, data);
317  }
318 
319  // Forms
320 
321  inline void getForm (unsigned int id, void *&d)
322  {
323  d = formGet(id);
324  }
325  inline void getForm (unsigned int id, char *&d)
326  {
327  d = (char *) formGet(id);
328  }
329  inline void getForm (unsigned int id, std::string &d)
330  {
331  d = (char *) formGet(id);
332  }
333  inline void getForm (unsigned int id, int &d)
334  {
335  int *i = (int *) formGet(id);
336  d = *i;
337  }
338  inline void getForm (unsigned int id, unsigned int &d)
339  {
340  d = *((unsigned int *) formGet(id));
341  }
342  inline void getForm (unsigned int id, bool &d)
343  {
344  int l = *((int *) formGet(id));
345  d = (l != 0);
346  }
347  inline void getForm (unsigned int id, float &d)
348  {
349  d = *((float *) formGet(id));
350  }
351  inline void getForm (unsigned int id, double &d)
352  {
353  d = *((double *) formGet(id));
354  }
355  // Set
356  void setForm(unsigned long id, void *data)
357  {
358  formSet(id, data);
359  }
360  void setForm(unsigned long id, bool data)
361  {
362  long l = static_cast<long>(data);
363  formSet(id, &l);
364  }
365  void setForm(unsigned long id, int data)
366  {
367  formSet(id, &data);
368  }
369  void setForm(unsigned long id, unsigned int data)
370  {
371  formSet(id, &data);
372  }
373  void setForm(unsigned long id, float data)
374  {
375  formSet(id, &data);
376  }
377  void setForm(unsigned long id, double data)
378  {
379  formSet(id, &data);
380  }
381  void setForm(unsigned long id, char *data)
382  {
383  formSet(id, (void *)data);
384  }
385  void setForm(unsigned long id, const char *data)
386  {
387  formSet(id, (void *)data);
388  }
389  void setForm(unsigned long id, std::string data)
390  {
391  formSet(id, (void *)data.c_str());
392  }
393 
394  static int getVersion()
395  {
396  return globPtr->version;
397  }
398  static LWXPDrawFuncs *getDrawFuncs()
399  {
400  return globPtr->drawf;
401  }
402  };
403 
406  {
407  public:
409  virtual void *DataGet(unsigned int vid ) = 0;
411  virtual LWXPRefreshCode DataSet(unsigned int vid, void *value) = 0;
412  };
413 
414  // Template functions for callbacks
415 
416  template <typename T>
417  void LWXPanelBtnClickFunc (LWXPanelID panel, int cid)
418  {
419  lwpp::XPanel xpan(panel);
420  T *plugin = xpan.getUserData<T>(cid);
421  return plugin->ButtonClick(cid);
422  }
423 }
424 #endif // LWPP_XPANEL_H