LightWrap++
AC++wrapperfortheLightWave3DSDK
panel.h
Go to the documentation of this file.
1 
4 #ifndef LWPP_PANEL_H
5 #define LWPP_PANEL_H
6 
7 #include <lwpp/global.h>
8 #include <lwpanel.h>
9 #include <lwpp/math.h>
10 
12 #define LWRGB(red, green, blue) (0x01000000 | (red<<16) | (blue<<8) | green)
13 
14 namespace lwpp
15 {
16 
17 
18  namespace lw10
19  {
20  // API 21
21  typedef enum { /* Tags to get/set panel attributes */
28  } pTag;
29  typedef enum { /* Tags to get/set panel attributes */
34  CTL_PANEL, CTL_PANFUN, /* use these 2 to get your panelID and functions! */
35  CTL_RANGEMIN, CTL_RANGEMAX, /* get/set slider range params API 10 and later */
36  CTL_ACTIVATE, /* set only, to actvate/enter string controls API 10 and later */
37  CTL_MOUSEBUTTON /* get the mouse button pressed, read only API 20 and later */
38  } cTag;
39  typedef enum { /* Tags to get mouse buttons for controls */
41  } mBut;
42  typedef void (*LWPanResizeHook)(LWPanelID, void *, int w, int h);
43  #define PAN_SETCONFIGTAG(pfunc,pan,tag) ( ival.intv.value=tag, (*pfunc->set)(pan, PAN_CONFIGTAG, (void *)&ival.intv.value) )
44  } // namespace lw10
45 
47 
53  {
54  LWValue val;
55 
56  void _reset()
57  {
58  if (val.type == LWT_STRING)
59  {
60  delete [] val.str.buf;
61  }
62  }
63  public:
66  {
67  _reset();
68  }
70  {
71  }
75  LWDynaValue(std::string s, int len = 0)
76  {
77  val.type = LWT_STRING;
78  len = Max<int>(len, (int)s.length() + 1);
79  if (len < 2) len = 2048; // use a large buffer just in case
80  val.str.buf = new char[len];
81  strcpy(val.str.buf, s.c_str());
82  val.str.bufLen = len;
83  }
86  LWDynaValue(int i)
87  {
88  val.type = LWT_INTEGER;
89  val.intv.value = i;
90  }
93  LWDynaValue(unsigned int i)
94  {
95  val.type = LWT_INTEGER;
96  val.intv.value = i;
97  }
100  LWDynaValue(double d)
101  {
102  val.type = LWT_FLOAT;
103  val.flt.value = d;
104  }
109  LWDynaValue(int i, int j, int k)
110  {
111  val.type = LWT_VINT;
112  val.ivec.val[0] = i;
113  val.ivec.val[1] = j;
114  val.ivec.val[2] = k;
115  }
119  LWDynaValue(int v[3])
120  {
121  val.type = LWT_VINT;
122  val.ivec.val[0] = v[0];
123  val.ivec.val[1] = v[1];
124  val.ivec.val[2] = v[2];
125  }
130  LWDynaValue(double i, double j, double k)
131  {
132  val.type = LWT_VFLOAT;
133  val.fvec.val[0] = i;
134  val.fvec.val[1] = j;
135  val.fvec.val[2] = k;
136  }
140  LWDynaValue(double v[3])
141  {
142  val.type = LWT_VFLOAT;
143  val.fvec.val[0] = v[0];
144  val.fvec.val[1] = v[1];
145  val.fvec.val[2] = v[2];
146  }
150  LWDynaValue(float v[3])
151  {
152  val.type = LWT_VFLOAT;
153  val.fvec.val[0] = v[0];
154  val.fvec.val[1] = v[1];
155  val.fvec.val[2] = v[2];
156  }
159  LWDynaValue(void *p)
160  {
161  val.type = LWT_POINTER;
162  val.ptr.ptr = p;
163  }
164  void setType (int type)
165  {
166  val.type = type;
167  }
170  void getValue(int &i) const
171  {
172  i = val.intv.value;
173  }
176  void getValue(double &d) const
177  {
178  d = val.flt.value; }
179 
184  void getValue(int &i, int &j, int &k) const
185  {
186  i = val.ivec.val[0];
187  j = val.ivec.val[1];
188  k = val.ivec.val[2];
189  }
190  void getValue(int v[]) const
191  {
192  v[0] = val.ivec.val[0];
193  v[1] = val.ivec.val[1];
194  v[2] = val.ivec.val[2];
195  }
200  void getValue(double &i, double &j, double &k) const
201  {
202  i = val.fvec.val[0];
203  j = val.fvec.val[1];
204  k = val.fvec.val[2];
205  }
208  void getValue(void *&p) const
209  {
210  p = val.ptr.ptr;
211  }
214  void getValue(std::string &s) const
215  {
216  s = val.str.buf;
217  }
220  LWValue *get() {return &val;}
221  };
222 
226  {
227  LWPanelID pan;
228  DrawFuncs *df;
229  public:
231  LWDrawFuncs(DrawFuncs *_df = 0, LWPanelID _pan = 0) : df(_df), pan(_pan) {;}
233  void drawPixel(int c, int x,int y) const
234  {
235  df->drawPixel(pan, c, x, y);
236  }
238  void drawPixel(int r,int g,int b,int x,int y) const
239  {
240  df->drawRGBPixel(pan, r, g, b, x, y);
241  }
243  void drawLine(int c, int x1, int y1, int x2, int y2) const
244  {
245  df->drawLine(pan, c, x1, y1, x2, y2);
246  }
247  void drawLine(int r, int g, int b, int x1, int y1, int x2, int y2) const
248  {
249  drawBox(r, g, b, x1, y1, x2 - x1, y2 - y1);
250  }
252  void drawBox(int c, int x, int y, int w, int h) const
253  {
254  df->drawBox(pan, c, x, y, w, h);
255  }
256  void drawWireBox(int c, int x, int y, int w, int h) const
257  {
258  h -= 1; w -= 1;
259  drawLine(c, x , y , x+w, y);
260  drawLine(c, x+w, y , x+w, y+h);
261  drawLine(c, x+w, y+h, x , y+h);
262  drawLine(c, x , y+h, x , y);
263  }
265  void drawBox(int r, int g, int b, int x, int y, int w, int h) const
266  {
267  df->drawRGBBox(pan, r, g, b, x, y, w, h);
268  }
269 
271  int textWidth(const std::string s) const
272  {
273  return df->textWidth(pan, const_cast<char *>(s.c_str()));
274  }
276  int textWidth(const std::ostringstream &s) const
277  {
278  return df->textWidth(pan, const_cast<char *>(s.str().c_str()));
279  }
280 
282  void drawText(const std::string s, int c, int x, int y) const
283  {
284  df->drawText(pan, const_cast<char *>(s.c_str()), c, x, y);
285  }
287  void drawText(const std::ostringstream &s, int c, int x, int y) const
288  {
289  df->drawText(pan, const_cast<char *>(s.str().c_str()), c, x, y);
290  }
291  void drawBorder(int indent, int x,int y,int w,int h = 0) const
292  {
293  df->drawBorder(pan, indent, x, y, w, h);
294  }
296  /*
297  int width, height;
298  int pixX, pixY;
299  int maxColors, depth;
300  int textHeight;
301  int textAscent;
302  */
303  const LWDisplayMetrics *displayMetrics() const
304  {
305  return df->dispMetrics();
306  }
307  };
308 
310 
311  template <typename T>
313  {
314  public:
316  static void cb_Event(LWControlID id, void *userdata);
318  static void cb_Draw(LWControlID id, void *userdata, DrMode mode);
320  static int cb_Count(void *userdata);
322  static char *cb_Name(void *userdata, int index);
324  static char *cb_MultiListName(void *userdata, int index, int column);
326  static int cb_MultiListColumnWidth(void *userdata, int index);
328  static void *cb_TreeChild(void *userdata, void *node, int i);
330  static int cb_TreeCount(void *userdata, void *node);
332  static char *cb_TreeInfo(void *userdata, void *node, int *flags);
334  static void cb_TreeMove(void *userdata, void *node, void *parent, int i);
335  };
336 
342  {
343  private:
344  LWControl *control;
345  bool ghosted;
346  protected:
350  void get (cTag tag, LWValue *val) { control->get(control, tag, val); }
354  void set (cTag tag, LWValue *val) { control->set(control, tag, val); }
355  public:
358  PanelControl (LWControlID ctl = 0)
359  : ghosted(false)
360  {
361  SetControl (ctl);
362  }
364  : ghosted(ctl.ghosted)
365  {
366  SetControl (ctl.control);
367  }
369  {
370  if (this != &from)
371  {
372  control = from.control;
373  ghosted = from.ghosted;
374  }
375  return *this;
376  }
379  void SetControl(LWControlID ctl)
380  {
381  control = static_cast<LWControl *>(ctl);
382  }
384  LWControlID getID() const
385  {
386  return (void *) control;
387  }
389  LWControl *getControl()
390  {
391  return control;
392  }
394  void operator=(LWControlID ctl)
395  {
396  SetControl(ctl);
397  }
399  void operator=(LWControl *ctl)
400  {
401  control = ctl;
402  }
404  bool operator==(const LWControlID ctl)
405  {
406  return (control == static_cast<LWControl *>(ctl));
407  }
409  bool operator==(const PanelControl ctl)
410  {
411  return (getID() == ctl.getID());
412  }
413  bool operator<(const PanelControl ctl) const
414  {
415  return (getID() < ctl.getID());
416  }
418  bool operator==(const LWControl *ctl)
419  {
420  return (control == ctl);
421  }
423  bool isValid() const
424  {
425  return (control != 0);
426  }
427 
430  void Draw(DrMode mode = DR_RENDER)
431  {
432  if (control) control->draw(control, mode);
433  }
435  void Erase()
436  {
437  Draw(DR_ERASE);
438  }
440  void Redraw()
441  {
442  Draw (DR_REFRESH);
443  }
444  void Refresh()
445  {
446  Draw (DR_REFRESH);
447  }
451  void Ghost(bool render = true)
452  {
453  ghosted = true;
454  if (render) Render();
455  }
456  void UnGhost(bool render = true)
457  {
458  ghosted = false;
459  if (render) Render();
460  }
462  void Render()
463  {
464  Draw();
465  if (ghosted)
466  {
467  Draw(DR_GHOST);
468  }
469  }
470  bool isGhosted() const
471  {
472  return ghosted;
473  }
474 
478  template<typename T>
479  void Set (T val, cTag tag = CTL_VALUE)
480  {
481  LWDynaValue dval(val);
482  set(tag, dval.get());
483  }
487  template<typename T>
488  void Get (T &val, cTag tag = CTL_VALUE)
489  {
490  LWDynaValue dval(val);
491  get(tag, dval.get());
492  dval.getValue(val);
493  }
496  int GetInt(cTag tag = CTL_VALUE)
497  {
498  int v;
499  Get (v, tag);
500  return v;
501  }
502  void GetVec(int &a, int &b, int &c)
503  {
504  LWDynaValue dval;
505  dval.setType(LWT_VINT);
506  get(CTL_VALUE, dval.get());
507  dval.getValue(a,b,c);
508  }
509  void GetVec(int v[])
510  {
511  LWDynaValue dval;
512  dval.setType(LWT_VINT);
513  get(CTL_VALUE, dval.get());
514  dval.getValue(v);
515  }
518  bool GetBool(cTag tag = CTL_VALUE)
519  {
520  return (GetInt(tag) != 0);
521  }
523 
527  {
528  LWValue ival = {LWT_POINTER};
529  get(tag, &ival);
530  return ival.ptr.ptr;
531  }
533  double GetFloat()
534  {
535  LWValue fval = {LWT_FLOAT};
536  get(CTL_VALUE, &fval);
537  return fval.flt.value;
538  }
539 
541  int RangeMin() {return GetInt(CTL_RANGEMIN);}
542  int RangeMax() {return GetInt(CTL_RANGEMAX);}
543 
544  void RangeMin(int m) {return Set(m, CTL_RANGEMIN);}
545  void RangeMax(int m) {return Set(m, CTL_RANGEMAX);}
546 
547 
552 
553  // control positioning
555  int X() {return GetInt(CTL_X);}
557  int Y() {return GetInt(CTL_Y);}
559  int W() {return GetInt(CTL_W);}
561  int H() {return GetInt(CTL_H);}
563  int LW() {return GetInt(CTL_LABELWIDTH);}
565  int HotX() {return GetInt(CTL_HOTX);}
567  int HotY() {return GetInt(CTL_HOTY);}
569  int HotW() {return GetInt(CTL_HOTW);}
571  int HotH() {return GetInt(CTL_HOTH);}
573  int MouseX() {return GetInt(CTL_MOUSEX);}
575  int MouseY() {return GetInt(CTL_MOUSEY);}
576 #if LWPP_PANELS_API_VERSION > 19
577 
578  lw10::mBut getMouseButton()
579  {
580  return static_cast<lw10::mBut>(GetInt(static_cast<cTag>(lw10::CTL_MOUSEBUTTON)));
581  }
582 #endif
583 
584  // @}
586  LWPanelID PanelID()
587  {
588  return static_cast<LWPanelID>(GetPointer(CTL_PANEL));
589  }
591  LWPanelFuncs *PanelFuncs()
592  {
593  return static_cast<LWPanelFuncs *>(GetPointer(CTL_PANFUN));
594  }
598  void Move(int x, int y) { Set(x, CTL_X); Set(y, CTL_Y); }
602  void MoveRightOf(PanelControl &ref, int space = 0) {
603  MoveX(ref.X() + ref.W() + space);
604  MoveY(ref.Y());
605  }
609  void MoveLeftOf(PanelControl &ref, int space = 0) {
610  MoveX(ref.X() - W() - space);
611  MoveY(ref.Y());
612  }
616  void MoveBelow(PanelControl &ref, int space = 0) {
617  MoveX(ref.X());
618  MoveY(ref.Y() + ref.H() + space);
619  }
621  MoveX(ref.X() + 6);
622  MoveY(ref.Y() + ref.H());
623  }
626  void LeftAlign(PanelControl &ref, int nudge = 0) {
627  MoveX(ref.X() + nudge);
628  }
631  void RightAlign(PanelControl &ref, int nudge = 0) {
632  MoveX(ref.X() + ref.W() - W() + nudge);
633  }
636  void MoveX(int x) { Set(x, CTL_X);}
639  void MoveY(int y) { Set(y, CTL_Y);}
643  void setSize(int w, int h) {setWidth(w); setHeight(h);}
646  void setWidth(int w) { Set(w, CTL_W);}
649  void setHeight(int h) { Set(h, CTL_H);}
650 
654  void SetUserDraw(LWCtlDrawHook d)
655  {
656  Set(reinterpret_cast<void *>(d), CTL_USERDRAW);
657  }
664  void SetUserData(void *d)
665  {
666  Set(d, CTL_USERDATA);
667  }
669  void *GetUserData()
670  {
671  return GetPointer(CTL_USERDATA);
672  }
675  template <typename T> void SetEventCallback()
676  {
677  Set<void *>((void *)PanelControlAdaptor<T>::cb_Event, CTL_USEREVENT);
678  }
681  template <typename T> void SetDrawCallback()
682  {
683  Set<void *>((void *)PanelControlAdaptor<T>::cb_Draw, CTL_USERDRAW);
684  }
686  {
687  initListBox();
688  }
689  void initListBox()
690  {
691  SetUserData(control);
692  }
693 
694  };
695 
700  {
701  public:
705  virtual void controlEvent(PanelControl& ) {;}
709  virtual void controlDraw(PanelControl& , DrMode ) {;}
710  };
711 
716  {
717  public:
719 
722  virtual int controlCount(PanelControl& control) = 0;
724  /*
725  * @param control reference to the control
726  * @param index A 0 based integer used to find the name of the item
727  */
728  virtual const char* controlName(PanelControl& control, int index) = 0;
729  };
730 
732 
737  {
738  public:
740 
746  virtual const char* controlMultiListName(PanelControl& control, int index, int column) = 0;
748 
753  virtual int controlMultiListColumnWidth(PanelControl& control, int index) = 0;
754  };
755 
764  {
765  int m_flags;
766  public:
767  PanelTreeNode() : m_flags(0) {;}
768  virtual ~PanelTreeNode() {;}
770  virtual PanelTreeNode *getChild(int ) {return 0;}
772  virtual int getChildCount() {return 0;}
774  virtual const char *getName() = 0;
776  virtual const char *getInfo(int *flags)
777  {
778  if (*flags)
779  {
780  m_flags = *flags;
781  }
782  else
783  {
784  *flags = m_flags;
785  }
786  return getName();
787  }
788  };
789 
800  {
801  public:
806  virtual PanelTreeNode* controlTreeGetRoot(lwpp::PanelControl& control) = 0;
812  virtual PanelTreeNode* controlTreeChild(PanelControl& control, PanelTreeNode *node, int i)
813  {
814  if (node) return node->getChild(i);
815  return controlTreeGetRoot(control)->getChild(i);
816  }
821  virtual int controlTreeCount(PanelControl& control, PanelTreeNode *node)
822  {
823  if (node) return node->getChildCount();
824  return controlTreeGetRoot(control)->getChildCount();
825  }
833  virtual const char* controlTreeInfo(PanelControl& control, PanelTreeNode *node, int *flags)
834  {
835  if (node) return node->getInfo(flags);
836  return controlTreeGetRoot(control)->getInfo(flags);
837  }
848  virtual void controlTreeMove(PanelControl& , PanelTreeNode *, PanelTreeNode *, int ) {;}
849  };
850 
857  class LWPanel : public GlobalBase<LWPanelFuncs>
858  {
859  private:
860  LWPanelID id;
861  bool close_on_destroy;
862  std::string title;
863  protected:
865  /*
866  * @param tag One of the pTag defined in lwpanel.h (line 175).
867  * @param *data is the panel attribute cast as a void *
868  */
869  void get (pTag tag, void *data) const { globPtr->get(id, tag, data);}
870 
872 
876  void set (pTag tag, void *data) { globPtr->set(id, tag, data);}
877 
879 
891  LWControl *addControl (const char *type, LWPanControlDesc *desc, const char *label)
892  {
893  return globPtr->addControl(id, const_cast<char *>(type), desc, const_cast<char *>(label));
894  }
895  public:
898  : id(0),
899  close_on_destroy(false)
900  {
901  ;
902  }
904 
907  LWPanel (const std::string _title)
908  : close_on_destroy(true),
909  title(_title)
910  {
911  if (!available()) return; // in the case LWPanels aren't available - i.e. LWSN
912  id = globPtr->create(const_cast<char *>(title.c_str()), globPtr);
913  }
915 
918  LWPanel (LWPanelID pan_id)
919  : id(pan_id),
920  close_on_destroy(false)
921  {
922  ;
923  }
926  {
927  if (!available()) return; // in the case LWPanels aren't available - i.e. LWSN
928  if (close_on_destroy)
929  {
930  globPtr->destroy(id);
931  id = 0;
932  }
933  }
935  LWPanel &operator=(const LWPanel &from)
936  {
937  if (&from != this)
938  {
939  id = from.id;
940  close_on_destroy = false;
941  title = from.title;
942  }
943  return *this;
944  }
946  /*
947  * @param _title a std:string with the title for the panel
948  * @param _close_on_destroy a bool value indicating if the panel is closed when the plugin is destroyed???
949  */
950  void Create (const std::string _title, bool _close_on_destroy = true)
951  {
952  title = _title;
953  close_on_destroy = _close_on_destroy;
954  id = globPtr->create(const_cast<char *>(title.c_str()), globPtr);
955  }
956 
958  LWPanelID GetID() const { return id; }
959 
961 
965  int Open (int flags)
966  {
967  return globPtr->open(id, flags);
968  }
973  int Post (int flags = 0)
974  {
975  return globPtr->open(id, PANF_BLOCKING | PANF_CANCEL | PANF_FRAME | flags);
976  }
978  void Close() {globPtr->close(id);}
979  void ClearID() {id = 0;}
981  void Recreate ()
982  {
983  if (id)
984  {
985  Close();
986  globPtr->destroy(id);
987  id = 0;
988  }
989  id = globPtr->create(const_cast<char *>(title.c_str()), globPtr);
990  }
993  void Recreate (const std::string _title)
994  {
995  if (id)
996  {
997  Close();
998  globPtr->destroy(id);
999  id = 0;
1000  }
1001  Create(_title);
1002  }
1010  int Handle (int block) { return globPtr->open(id, block); }
1011 
1016  void Draw(DrMode mode = DR_REFRESH) { globPtr->draw(id, mode); }
1017 
1019  LWControl *nextControl(LWControlID *ctl){ return globPtr->nextControl(id, ctl);}
1024 
1026  {
1027  return LWDrawFuncs(globPtr->drawFuncs, id);
1028  }
1029 
1030  // Draw functions
1032  void DrawLine(int color, int x1, int y1, int x2, int y2)
1033  {
1034  globPtr->drawFuncs->drawLine(id, color, x1, y1, x2, y2);
1035  }
1037  void DrawBorder(int indent, int x,int y,int w,int h = 0) const
1038  {
1039  globPtr->drawFuncs->drawBorder(id, indent, x, y, w, h);
1040  }
1041 
1044  {
1045  int width = GetWidth();
1046  int height = GetHeight();
1047  DrawLine(LWP_WHITE, width-18, height-2, width-2,height-18 );
1048  DrawLine(LWP_WHITE, width-14, height-2, width-2,height-14 );
1049  DrawLine(LWP_WHITE, width-10, height-2, width-2,height-10 );
1050  DrawLine(LWP_WHITE, width-6, height-2, width-2,height-6 );
1051 
1052  DrawLine(LWP_BLACK, width-17, height-2, width-2,height-17 );
1053  DrawLine(LWP_BLACK, width-13, height-2, width-2,height-13 );
1054  DrawLine(LWP_BLACK, width-9, height-2, width-2,height-9 );
1055  DrawLine(LWP_BLACK, width-5, height-2, width-2,height-5 );
1056  }
1058 
1060  void *user_data() {return globPtr->user_data;}
1061 
1063  GlobalFunc *globalFun() {return globPtr->globalFun;}
1068 
1069 
1081  LWControl *AddChoice (const char *title, const char **items, bool orientation)
1082  {
1083  LWPanControlDesc desc;
1084  desc.type = LWT_CHOICE;
1085  desc.choice.vertical = orientation ? MX_HCHOICE : MX_VCHOICE;
1086  desc.choice.items=items;
1087  return addControl("ChoiceControl", &desc, title);
1088  }
1100  LWControl *AddPopUp (const char *title, const char **items, int width = 0)
1101  {
1102  LWPanControlDesc desc;
1103  desc.type = LWT_CHOICE;
1104  desc.choice.vertical=width;
1105  desc.choice.items=items;
1106  return addControl("PopupControl", &desc, title);
1107  }
1115  LWControl *AddFloat (const char *title, LWType type = LWT_FLOAT)
1116  {
1117  LWPanControlDesc desc;
1118  desc.type = type;
1119  return addControl("FloatControl", &desc, title);
1120  }
1127  LWControl *AddDistance (const char *title) { return AddFloat(title, LWT_DISTANCE); }
1134  LWControl *AddFloatInfo (const char *title)
1135  {
1136  LWPanControlDesc desc;
1137  desc.type = LWT_FLOAT;
1138  return addControl("FloatInfoControl", &desc, title);
1139  }
1147  LWControl *AddFloatVector (const char *title, LWType type = LWT_VFLOAT)
1148  {
1149  LWPanControlDesc desc;
1150  desc.type = type;
1151  return addControl("FVecControl", &desc, title);
1152  }
1159  LWControl *AddDistanceVector (const char *title) {return AddFloatVector(title, LWT_VDIST);}
1166  LWControl *AddFloatVectorInfo (const char *title)
1167  {
1168  LWPanControlDesc desc;
1169  desc.type = LWT_VFLOAT;
1170  return addControl("FVecInfoControl", &desc, title);
1171  }
1173 
1179  LWControl *AddItem (const char *title, LWItemType type, int width = 0)
1180  {
1181  LWPanControlDesc desc;
1182  desc.type=LWT_LWITEM;
1183  desc.lwitem.global=reinterpret_cast<void *>(lwpp::SuperGlobal);
1184  desc.lwitem.itemType=type;
1185  desc.lwitem.list=NULL;
1186  desc.lwitem.count=0;
1187  desc.lwitem.width=width;
1188  return addControl("LWListControl", &desc, title);
1189  }
1198  LWControl *AddPickItem (const char *title, LWItemType type, int width)
1199  {
1200  LWPanControlDesc desc;
1201  desc.type=LWT_LWITEM;
1202  desc.lwitem.global=reinterpret_cast<void *>(lwpp::SuperGlobal);
1203  desc.lwitem.itemType=type;
1204  desc.lwitem.list=NULL;
1205  desc.lwitem.count=0;
1206  desc.lwitem.width=width;
1207  return addControl("LWPickListControl", &desc, title);
1208  }
1216  LWControl *AddButton (const char *title, int width = 0)
1217  {
1218  LWPanControlDesc desc;
1219  desc.type=LWT_INTEGER;
1220  if (width != 0)
1221  {
1222  desc.type=LWT_AREA;
1223  desc.area.width=width;
1224  desc.area.height=0;
1225  }
1226  return addControl("ButtonControl", &desc, title);
1227  }
1235  LWControl *AddBoolean (const char *title, int width = 0)
1236  {
1237  LWPanControlDesc desc;
1238  desc.type=LWT_BOOLEAN;
1239  desc.area.width=width;
1240  desc.area.height=0;
1241  return addControl("BoolControl", &desc, title);
1242  }
1250  LWControl *AddBoolButton (const char *title, int width = 0)
1251  {
1252  LWPanControlDesc desc;
1253  desc.type= (width == 0 ) ? LWT_BOOLEAN : LWT_AREA; // is this actually correct in the SDK macros?
1254  desc.area.width=width;
1255  desc.area.height=0;
1256  return addControl("BoolButtonControl", &desc, title);
1257  }
1258 
1266  LWControl *AddInteger (const char *title, int width = 0)
1267  {
1268  width;
1269  LWPanControlDesc desc;
1270  desc.type= LWT_INTEGER;
1271  return addControl("NumControl", &desc, title);
1272  }
1280  LWControl *AddIntegerInfo (const char *title, int width = 0)
1281  {
1282  width;
1283  LWPanControlDesc desc;
1284  desc.type= LWT_INTEGER;
1285  return addControl("NumInfoControl", &desc, title);
1286  }
1287 
1298  LWControl *AddSlider (const char *title, int min, int max, int width, const char *type = "SliderControl")
1299  {
1300  LWPanControlDesc desc;
1301  desc.type=LWT_RANGE;
1302  desc.range.width=width;
1303  desc.range.min=min;
1304  desc.range.max=max;
1305  return addControl(type, &desc, title);
1306  }
1316  LWControl *AddVerticalSlider (const char *title, int min, int max, int width)
1317  {
1318  return AddSlider(title, min, max, width, "VSlideControl");
1319  }
1329  LWControl *AddHorizontalSlider (const char *title, int min, int max, int width)
1330  {
1331  return AddSlider(title, min, max, width, "HSlideControl");
1332  }
1342  LWControl *AddUnboundSlider (const char *title, int min, int max, int width)
1343  {
1344  return AddSlider(title, min, max, width, "UnboundSlideControl");
1345  }
1355  LWControl *AddMiniSlider (const char *title, int min, int max, int width)
1356  {
1357  return AddSlider(title, min, max, width, "MiniSliderControl");
1358  }
1359 
1367  LWControl *AddVector (const char *title, const char *type = "VecControl")
1368  {
1369  LWPanControlDesc desc;
1370  desc.type = LWT_VINT;
1371  return addControl(type, &desc, title);
1372  }
1379  LWControl *AddVectorInfo (const char *title) { return AddVector(title,"VecInfoControl"); }
1386  LWControl *AddRGB (const char *title) { return AddVector(title,"RGBControl"); }
1393  LWControl *AddMiniRGB (const char *title) { return AddVector(title,"MiniRGBControl"); }
1400  LWControl *AddMiniHSV (const char *title) { return AddVector(title,"MiniHSVControl"); }
1407  LWControl *AddRGBVector (const char *title) { return AddVector(title,"RGBVecControl"); }
1416  LWControl *AddString (const char *title, int width, const char *type = "EditControl")
1417  {
1418  LWPanControlDesc desc;
1419  desc.type = LWT_STRING;
1420  desc.string.width=width;
1421  return addControl(type, &desc, title);
1422  }
1430  LWControl *AddStringInfo (const char *title, int width) { return AddString(title, width, "InfoControl"); }
1439  LWControl *AddFile (const char *title, int width) { return AddString(title, width, "FileControl");}
1447  LWControl *AddFileButton (const char *title, int width) { return AddString(title, width, "FileButtonControl");}
1456  LWControl *AddLoad (const char *title, int width) { return AddString(title, width, "LoadControl");}
1464  LWControl *AddLoadButton (const char *title, int width) {return AddString(title, width, "LoadButtonControl");}
1473  LWControl *AddSave (const char *title, int width) { return AddString(title, width, "SaveControl");}
1481  LWControl *AddSaveButton (const char *title, int width) {return AddString(title, width, "SaveButtonControl");}
1490  LWControl *AddDir (const char *title, int width){return AddString(title, width, "DirControl");}
1498  LWControl *AddDirButton (const char *title, int width){return AddString(title, width, "DirButtonControl");}
1507  LWControl *AddText (const char *title, const char**text)
1508  {
1509  LWPanControlDesc desc;
1510  desc.type = LWT_TEXT;
1511  desc.text.text=text;
1512  return addControl("TextControl", &desc, title);
1513  }
1523  LWControl *AddArea (const char *title, int width, int height, const char *type = "AreaControl")
1524  {
1525  LWPanControlDesc desc;
1526  desc.type = LWT_AREA;
1527  desc.area.width=width;
1528  desc.area.height=height;
1529  return addControl(type, &desc, title);
1530  }
1539  LWControl *AddOpenGL (const char *title, int width, int height) {return AddArea(title, width, height, "OpenGLControl");}
1549  LWControl *AddCanvas (const char *title, int width, int height) {return AddArea(title, width, height, "CanvasControl");}
1559  LWControl *AddDragButton (const char *title, int width, int height){return AddArea(title, width, height, "DragButtonControl");}
1566  LWControl *AddVDragButton (const char *title){return AddArea(title, 0, -1, "DragButtonControl");}
1573  LWControl *AddHDragButton (const char *title){return AddArea(title, -1, 0, "DragButtonControl");}
1582  LWControl *AddDragArea (const char *title, int width, int height){return AddArea(title, width, height, "DragAreaControl");}
1592  LWControl *AddBorder (const char *title, int width, int height){return AddArea(title, width, height, "BorderControl");}
1601  LWControl *AddChannel (const char *title, int width, int height){return AddArea(title, width, height, "ChannelControl");}
1611  LWControl *AddPalette (const char *title, int width, int height)
1612  {
1613  LWPanControlDesc desc;
1614  desc.type = LWT_RANGE;
1615  desc.area.width=width;
1616  desc.area.height=height;
1617  return addControl("PaletteControl", &desc, title);
1618  }
1625  LWControl *AddPercent (const char *title)
1626  {
1627  LWPanControlDesc desc;
1628  desc.type = LWT_RANGE;
1629  desc.range.min=0;
1630  desc.range.max=100;
1631  return addControl("PercentControl", &desc, title);
1632  }
1640  LWControl *AddAngle (const char *title)
1641  {
1642  LWPanControlDesc desc;
1643  desc.type = LWT_RANGE;
1644  desc.range.min=0;
1645  desc.range.max=360;
1646  return addControl("AngleControl", &desc, title);
1647  }
1676  LWControl *AddCustomPopup (const char *title, int width, int (*count)(void *), char *(*name)(void *, int))
1677  {
1678  LWPanControlDesc desc;
1679  desc.type = LWT_POPUP;
1680  desc.popup.width=width;
1681  desc.popup.nameFn=name;
1682  desc.popup.countFn=count;
1683  return addControl("CustomPopupControl", &desc, title);
1684  }
1711  template<typename T>
1712  LWControl *AddCustomPopup (const char *title, int width)
1713  {
1714  LWPanControlDesc desc;
1715  desc.type = LWT_POPUP;
1716  desc.popup.width=width;
1717  desc.popup.nameFn=PanelControlAdaptor<T>::cb_Name;
1718  desc.popup.countFn=PanelControlAdaptor<T>::cb_Count;
1719  PanelControl control = addControl("CustomPopupControl", &desc, title);
1720  control.SetUserData(control.getControl());
1721  return control.getControl();
1722  }
1734  LWControl *AddPopdown (const char *title, const char **items)
1735  {
1736  LWPanControlDesc desc;
1737  desc.type = LWT_CHOICE;
1738  desc.choice.vertical=MX_POPUP;
1739  desc.choice.items=items;
1740  return addControl("PopDownControl", &desc, title);
1741  }
1751  LWControl *AddTabs (const char *title, const char **items)
1752  {
1753  LWPanControlDesc desc;
1754  desc.type = LWT_CHOICE;
1755  desc.choice.vertical=MX_HCHOICE;
1756  desc.choice.items=items;
1757  return addControl("TabChoiceControl", &desc, title);
1758  }
1863  LWControl *AddXPanel (const char *title, LWXPanelID xp)
1864  {
1865  LWPanControlDesc desc;
1866  desc.type = LWT_XPANEL;
1867  desc.xpanel.xpan=xp;
1868  return addControl("XPanelControl", &desc, title);
1869  }
1870 
1901  LWControl *AddListbox (const std::string &title, int width, int (*count)(void *), char *(*name)(void *, int), int items, int topVisible = 0)
1902  {
1903  LWPanControlDesc desc;
1904  desc.type = LWT_POPUP;
1905  desc.listbox.width=width;
1906  desc.listbox.nameFn=name;
1907  desc.listbox.countFn=count;
1908  desc.listbox.visItems=items;
1909  desc.listbox.top = topVisible;
1910  return addControl("ListBoxControl", &desc, title.c_str());
1911  }
1925 
1928 
1931 
2026  template<typename T>
2027  LWControl *AddListbox (const std::string &title, int width, int items, int topVisible = 0)
2028  {
2029  LWPanControlDesc desc;
2030  desc.type = LWT_POPUP;
2031  desc.listbox.width=width;
2032  desc.listbox.nameFn=PanelControlAdaptor<T>::cb_Name;
2033  desc.listbox.countFn=PanelControlAdaptor<T>::cb_Count;
2034  desc.listbox.visItems=items;
2035  desc.listbox.top = topVisible;
2036  PanelControl control = addControl("ListBoxControl", &desc, title.c_str());
2037  control.SetUserData(control.getControl());
2038  return control.getControl();
2039  }
2040  template<typename T>
2041  void AddListbox (PanelControl &control, const std::string &title, int width, int items, int topVisible = 0)
2042  {
2043  LWPanControlDesc desc;
2044  desc.type = LWT_POPUP;
2045  desc.listbox.width=width;
2046  desc.listbox.nameFn=PanelControlAdaptor<T>::cb_Name;
2047  desc.listbox.countFn=PanelControlAdaptor<T>::cb_Count;
2048  desc.listbox.visItems=items;
2049  desc.listbox.top = topVisible;
2050  control = addControl("ListBoxControl", &desc, title.c_str());
2051  control.SetUserData(control.getControl());
2052  }
2053  template<typename T>
2054  void AddListbox (PanelControl &control, int width, int items, int topVisible = 0)
2055  {
2056  LWPanControlDesc desc;
2057  desc.type = LWT_POPUP;
2058  desc.listbox.width=width;
2059  desc.listbox.nameFn=PanelControlAdaptor<T>::cb_Name;
2060  desc.listbox.countFn=PanelControlAdaptor<T>::cb_Count;
2061  desc.listbox.visItems=items;
2062  desc.listbox.top = topVisible;
2063  control = addControl("ListBoxControl", &desc, 0);
2064  control.SetUserData(control.getControl());
2065  return control.getControl();
2066  }
2075  template<typename T>
2076  LWControl *AddListbox (int width, int items, int topVisible = 0)
2077  {
2078  LWPanControlDesc desc;
2079  desc.type = LWT_POPUP;
2080  desc.listbox.width=width;
2081  desc.listbox.nameFn=PanelControlAdaptor<T>::cb_Name;
2082  desc.listbox.countFn=PanelControlAdaptor<T>::cb_Count;
2083  desc.listbox.visItems=items;
2084  desc.listbox.top = topVisible;
2085  PanelControl control = addControl("ListBoxControl", &desc, 0);
2086  control.SetUserData(control.getControl());
2087  return control.getControl();
2088  }
2089 
2103 
2106 
2109 
2112 
2115 
2275  LWControl *AddMultiListbox (const char *title, int width, int items, int topVisible,
2276  int (*count)(void *),
2277  char *(*name)(void *, int, int),
2278  int (*colwidth)(void *, int i))
2279  {
2280  LWPanControlDesc desc;
2281  desc.type = LWT_MLIST;
2282  desc.multiList.width=width;
2283  desc.multiList.nameFn=name;
2284  desc.multiList.countFn=count;
2285  desc.multiList.visItems = items;
2286  desc.multiList.top = topVisible;
2287  desc.multiList.colWidth=colwidth;
2288  return addControl("MultiListBoxControl", &desc, title);
2289  }
2290 
2292 
2307 
2309 
2312 
2315 
2459  template<typename T>
2460  LWControl *AddMultiListbox (const char *title, int width, int items, int topVisible = 0)
2461  {
2462  LWPanControlDesc desc;
2463  desc.type = LWT_MLIST;
2464  desc.multiList.width=width;
2465  desc.multiList.visItems=items;
2466  desc.multiList.top=topVisible;
2467  desc.multiList.nameFn=PanelControlAdaptor<T>::cb_MultiListName;
2468  desc.multiList.countFn=PanelControlAdaptor<T>::cb_Count;
2469  desc.multiList.colWidth=PanelControlAdaptor<T>::cb_MultiListColumnWidth;
2470  PanelControl control = addControl("MultiListBoxControl", &desc, title);
2471  control.SetUserData(control.getControl());
2472  return control.getControl();
2473  }
2474 
2475  template<typename T>
2476  void AddMultiListbox (PanelControl &control, const char *title, int width, int items, int topVisible = 0)
2477  {
2478  LWPanControlDesc desc;
2479  desc.type = LWT_MLIST;
2480  desc.multiList.width=width;
2481  desc.multiList.visItems=items;
2482  desc.multiList.top=topVisible;
2483  desc.multiList.nameFn=PanelControlAdaptor<T>::cb_MultiListName;
2484  desc.multiList.countFn=PanelControlAdaptor<T>::cb_Count;
2485  desc.multiList.colWidth=PanelControlAdaptor<T>::cb_MultiListColumnWidth;
2486  control = addControl("MultiListBoxControl", &desc, title);
2487  control.SetUserData(control.getControl());
2488  }
2489 
2490 
2492  template<typename T>
2493  LWControl *AddTree (const char *title, int width, int height)
2494  {
2495  LWPanControlDesc desc;
2496  desc.type = LWT_TREE;
2497  desc.tree.width=width;
2498  desc.tree.height=height;
2499  desc.tree.infoFn=PanelControlAdaptor<T>::cb_TreeInfo;
2500  desc.tree.countFn=PanelControlAdaptor<T>::cb_TreeCount;
2501  desc.tree.leafFn=PanelControlAdaptor<T>::cb_TreeChild;
2502  desc.tree.moveFn=0;
2503  PanelControl control = addControl("TreeControl", &desc, title);
2504  control.SetUserData(control.getControl());
2505  return control.getControl();
2506  }
2508  LWControl *AddTree (const char *title, int width, int height,
2509  int (*count)(void *data, void *node),
2510  void *(*leaf)(void *data, void *node, int i),
2511  char *(*info)(void *data, void *node, int *nodeFlags),
2512  void (*move)(void *data, void *node, void *parentNode, int i) = 0
2513  )
2514  {
2515  LWPanControlDesc desc;
2516  desc.type = LWT_TREE;
2517  desc.tree.width=width;
2518  desc.tree.height=height;
2519  desc.tree.infoFn=info;
2520  desc.tree.countFn=count;
2521  desc.tree.leafFn=leaf;
2522  desc.tree.moveFn=move;
2523  return addControl("TreeControl", &desc, title);
2524  }
2526  // Set
2527  void Set (void *p, pTag tag)
2528  {
2529  set(tag, p);
2530  }
2531  void Set (int i, pTag tag)
2532  {
2533  set(tag, &i);
2534  }
2535 
2536  // Get any integer tag
2537  int GetInt(pTag tag) const
2538  {
2539  int i;
2540  get(tag, &i);
2541  return i;
2542  }
2543  // Get any pointer
2544  void *GetPointer(pTag tag)
2545  {
2546  LWValue pval;
2547  get(tag, &pval);
2548  return pval.ptr.ptr;
2549  }
2550  void Set(pTag tag, void *p)
2551  {
2552  set(tag, p);
2553  }
2555  int GetWidth() const {return GetInt(PAN_W);}
2557  void SetWidth(int w){Set(w, PAN_W);}
2559  int GetHeight() const {return GetInt(PAN_H);}
2561  void SetHeight(int h){Set(h, PAN_H);}
2565  void SetUserData (void *d){set(PAN_USERDATA, d);}
2567  void ToFront() {Set(1, PAN_TO_FRONT);}
2568  void SetTitle(std::string &s) {Set(const_cast<char*>(s.c_str()), PAN_TITLE);}
2570  void *GetUserData ()
2571  {
2572  void *ud;
2573  get(PAN_USERDATA, &ud);
2574  return ud;
2575  }
2576  void SetUserDraw (LWPanDrawHook d){set(PAN_USERDRAW, reinterpret_cast<void*>(d));}
2577  void SetUserKeys (LWPanKeyHook d) {set(PAN_USERKEYS, reinterpret_cast<void*>(d));}
2578  void SetUserKeyUp (LWPanKeyHook d) {set(PAN_USERKEYUPS, reinterpret_cast<void*>(d));}
2579  void SetUserActivate (LWPanHook d) {set(PAN_USERACTIVATE, reinterpret_cast<void*>(d));}
2580  void SetUserOpen (LWPanHook d) {set(PAN_USEROPEN, reinterpret_cast<void*>(d));}
2581  void SetUserClose (LWPanHook d) {set(PAN_USERCLOSE, reinterpret_cast<void*>(d));}
2582  void SetUserMouseMove (LWPanMouseHook d) {set(PAN_MOUSEMOVE, reinterpret_cast<void*>(d));}
2583  void SetUserMouseButton (LWPanMouseHook d) {set(PAN_MOUSEBUTTON, reinterpret_cast<void*>(d));}
2584 
2585  template <typename T>
2586  void SetCallbacks(T *host)
2587  {
2588  SetUserData(host);
2589  SetUserDraw(cb_PanDraw<T>);
2590  SetUserMouseButton(cb_PanMouseButton<T>);
2591  SetUserMouseMove(cb_PanMouseMove<T>);
2592  SetUserActivate(cb_PanActivate<T>);
2593  SetUserOpen(cb_PanOpen<T>);
2594  SetUserClose(cb_PanClose<T>);
2595  SetUserKeys(cb_PanKeyDown<T>);
2596  SetUserKeyUp(cb_PanKeyUp<T>);
2597  }
2598 
2599  // static callbacks
2601  template<typename T> static void cb_PanDraw(LWPanelID id, void *userdata, DrMode DrawMode)
2602  {
2603  if (T *instance = static_cast<T *>(userdata))
2604  {
2605  instance->panelDraw(LWPanel(id), DrawMode);
2606  }
2607  }
2608 
2610  template<typename T> static void cb_PanActivate(LWPanelID id, void *userdata);
2611 
2613  template<typename T> static void cb_PanOpen(LWPanelID id, void *userdata);
2614 
2616  template<typename T> static void cb_PanClose(LWPanelID id, void *userdata);
2617 
2619  template<typename T> static int cb_PanKeyDown (LWPanelID id, void *userdata, LWDualKey key);
2620 
2622  template<typename T> static int cb_PanKeyUp (LWPanelID id, void *userdata, LWDualKey key);
2623 
2625  template<typename T> static void cb_PanMouseButton (LWPanelID id, void *userdata, int qualifiers, int x, int y);
2626 
2628  template<typename T> static void cb_PanMouseMove (LWPanelID id, void *userdata, int qualifiers, int x, int y);
2629 
2630  template<typename T> static void cb_PanResize (LWPanelID id, void *userdata, int w, int h);
2631  };
2632 
2634  class LWRaster : public GlobalBase<LWRasterFuncs>
2635  {
2636  LWRasterID id;
2637  int lastX, lastY;
2638  public:
2639  LWRaster(int w, int h, int flags = 0) : id(0)
2640  {
2641  create(w, h, flags);
2642  }
2643  LWRaster() : id(0)
2644  {
2645  ;
2646  }
2648  {
2649  if (id)
2650  {
2651  globPtr->destroy(id);
2652  id = 0;
2653  }
2654  }
2655  void create(int w, int h, int flags = 0)
2656  {
2657  if (id) globPtr->destroy(id);
2658  id = globPtr->create(w, h, flags);
2659  }
2660  void drawPixel(int c, int x, int y)
2661  {
2662  globPtr->drawPixel(id, c, x, y);
2663  }
2664  void drawPixel(int r, int g, int b, int x, int y)
2665  {
2666  globPtr->drawRGBPixel(id, r, g, b, x, y);
2667  }
2668  void moveTo(int x, int y)
2669  {
2670  lastX = x; lastY = y;
2671  }
2672  void drawTo(int c, int x, int y)
2673  {
2674  drawLine(c, lastX, lastY, x, y);
2675  moveTo(x,y);
2676  }
2677  void drawLine(int c, int x1, int y1, int x2, int y2)
2678  {
2679  globPtr->drawLine(id, c, x1, y1, x2, y2);
2680  }
2681  void drawBox(int c, int x, int y, int w, int h)
2682  {
2683  globPtr->drawBox(id, c, x, y, w, h);
2684  }
2685  void drawBox(int r, int g, int b, int x, int y, int w, int h)
2686  {
2687  globPtr->drawRGBBox(id, r, g, b, x, y, w, h);
2688  }
2689 
2690  void drawRoundBox(int c, int x, int y, int w, int h, int bevel = 2);
2691  void drawBoxOutline(int c, int x, int y, int w, int h);
2692  void fillRoundBox(int c, int x, int y, int w, int h, int bevel = 2);
2693 
2694  void eraseBox(int x, int y, int w, int h)
2695  {
2696  globPtr->eraseBox(id, x, y, w, h);
2697  }
2698  void drawBorder(int indent, int x, int y, int w, int h = 0)
2699  {
2700  globPtr->drawBorder(id, indent, x, y, w, h);
2701  }
2702  void drawText(std::string s, int c, int x, int y)
2703  {
2704  globPtr->drawText(id, const_cast<char *>(s.c_str()), c, x, y);
2705  }
2706  void blitPanel(int srcx, int srcy, LWPanelID pan, int destx, int desty, int w, int h)
2707  {
2708  globPtr->blitPanel(id, srcx, srcy, pan, destx, desty, w, h);
2709  }
2710  void blitPanel(int srcx, int srcy, LWPanel &pan, int destx, int desty, int w, int h)
2711  {
2712  blitPanel(srcx, srcy, pan.GetID(), destx, desty, w, h);
2713  }
2714  void blitRaster(LWRasterID raster, int srcx, int srcy, int destx, int desty, int w, int h)
2715  {
2716  globPtr->blitRaster(id, srcx, srcy, raster, destx, desty, w, h);
2717  }
2718  void blitRaster(LWRaster &raster, int srcx, int srcy, int destx, int desty, int w, int h)
2719  {
2720  blitRaster(raster.id, srcx, srcy, destx, desty, w, h);
2721  }
2722  };
2723 
2727  {
2728  friend class LWPanel;
2729  public:
2731  virtual void panelDraw(const LWPanel&, DrMode ) {;}
2733  virtual void panelActivate(const LWPanel&) {;}
2735  virtual void panelOpen(const LWPanel&) {;}
2737  virtual void panelClose(const LWPanel&) {;}
2739  virtual int panelKeyDown(const LWPanel&, LWDualKey ) {return 0;}
2741  virtual int panelKeyUp(const LWPanel&, LWDualKey ) {return 0;}
2743  virtual void panelMouseButton(const LWPanel&, int , int, int) {;}
2745  virtual void panelMouseMove(const LWPanel&, int , int, int) {;}
2746  };
2747 
2749  template<typename T>
2751  {
2752  if (control.isValid())
2753  {
2754  LWPanel panel(control.PanelID());
2755  return static_cast<T *>(panel.GetUserData());
2756  }
2757  return 0;
2758  }
2759 
2760  // Callbacks for Panel controls
2762  template <typename T>
2763  void PanelControlAdaptor<T>::cb_Event(LWControlID id, void *)
2764  {
2765  PanelControl control(id);
2766  if (T *eventHandler = getEventHandler<T>(control))
2767  {
2768  eventHandler->controlEvent(control);
2769  }
2770  }
2772  template <typename T>
2773  void PanelControlAdaptor<T>::cb_Draw(LWControlID id, void *, DrMode mode)
2774  {
2775  PanelControl control(id);
2776  if (T *eventHandler = getEventHandler<T>(control))
2777  {
2778  eventHandler->controlDraw(control, mode);
2779  }
2780  }
2782  template <typename T>
2784  {
2785  PanelControl control(static_cast<LWControlID>(userdata));
2786  if (T *eventHandler = getEventHandler<T>(control))
2787  {
2788  return eventHandler->controlCount(control);
2789  }
2790  return 0;
2791  }
2793  template <typename T>
2794  char *PanelControlAdaptor<T>::cb_Name(void *userdata, int index)
2795  {
2796  PanelControl control(static_cast<LWControlID>(userdata));
2797  if (T *eventHandler = getEventHandler<T>(control))
2798  {
2799  return const_cast<char *>(eventHandler->controlName(control, index));
2800  }
2801  return const_cast<char *>("");
2802  }
2804  template <typename T>
2805  char *PanelControlAdaptor<T>::cb_MultiListName(void *userdata, int index, int column)
2806  {
2807  PanelControl control(static_cast<LWControlID>(userdata));
2808  if (T *eventHandler = getEventHandler<T>(control))
2809  {
2810  return const_cast<char *>(eventHandler->controlMultiListName(control, index, column));
2811  }
2812  return const_cast<char *>("");
2813  }
2815  template <typename T>
2817  {
2818  PanelControl control(static_cast<LWControlID>(userdata));
2819  if (T *eventHandler = getEventHandler<T>(control))
2820  {
2821  return eventHandler->controlMultiListColumnWidth(control, index);
2822  }
2823  return 0;
2824  }
2826  template <typename T>
2827  void *PanelControlAdaptor<T>::cb_TreeChild(void *userdata, void *node, int i)
2828  {
2829  PanelControl control(static_cast<LWControlID>(userdata));
2830  if (T *eventHandler = getEventHandler<T>(control))
2831  {
2832  return eventHandler->controlTreeChild(control, (PanelTreeNode *)node, i);
2833  }
2834  return 0;
2835  }
2837  template <typename T>
2838  int PanelControlAdaptor<T>::cb_TreeCount(void *userdata, void *node)
2839  {
2840  PanelControl control(static_cast<LWControlID>(userdata));
2841  if (T *eventHandler = getEventHandler<T>(control))
2842  {
2843  return eventHandler->controlTreeCount(control, (PanelTreeNode *)node);
2844  }
2845  return 0;
2846  }
2848  template <typename T>
2849  char *PanelControlAdaptor<T>::cb_TreeInfo(void *userdata, void *node, int *flags)
2850  {
2851  PanelControl control(static_cast<LWControlID>(userdata));
2852  if (T *eventHandler = getEventHandler<T>(control))
2853  {
2854  return const_cast<char *>(eventHandler->controlTreeInfo(control, (PanelTreeNode *)node, flags));
2855  }
2856  return const_cast<char *>("");
2857  }
2859  template <typename T>
2860  void PanelControlAdaptor<T>::cb_TreeMove(void *userdata, void *node, void *parent, int i)
2861  {
2862  PanelControl control(static_cast<LWControlID>(userdata));
2863  if (T *eventHandler = getEventHandler<T>(control))
2864  {
2865  eventHandler->controlTreeMove(control, (PanelTreeNode *)node, parent, i);
2866  }
2867  }
2868 
2869  /*
2870  * Panel Callbacks
2871  */
2872 
2873 
2875  template<typename T>
2876  void LWPanel::cb_PanActivate(LWPanelID id, void *userdata)
2877  {
2878  if (T *instance = static_cast<T *>(userdata))
2879  {
2880  instance->panelActivate(LWPanel(id));
2881  }
2882  }
2884  template<typename T>
2885  void LWPanel::cb_PanOpen(LWPanelID id, void *userdata)
2886  {
2887  if (T *instance = static_cast<T *>(userdata))
2888  {
2889  instance->panelOpen(LWPanel(id));
2890  }
2891  }
2893  template<typename T>
2894  void LWPanel::cb_PanClose(LWPanelID id, void *userdata)
2895  {
2896  if (T *instance = static_cast<T *>(userdata))
2897  {
2898  instance->panelClose(LWPanel(id));
2899  }
2900  }
2902  template<typename T>
2903  int LWPanel::cb_PanKeyDown (LWPanelID id, void *userdata, LWDualKey key)
2904  {
2905  if (T *instance = static_cast<T *>(userdata))
2906  {
2907  return instance->panelKeyDown(LWPanel(id), key);
2908  }
2909  return 0; // The keypress has not been processed
2910  }
2912  template<typename T>
2913  int LWPanel::cb_PanKeyUp (LWPanelID id, void *userdata, LWDualKey key)
2914  {
2915  if (T *instance = static_cast<T *>(userdata))
2916  {
2917  return instance->panelKeyUp(LWPanel(id),key);
2918  }
2919  return 0; // The keypress has not been processed
2920  }
2921 
2923  template<typename T>
2924  void LWPanel::cb_PanMouseButton (LWPanelID id, void *userdata, int qualifiers, int x, int y)
2925  {
2926  if (T *instance = static_cast<T *>(userdata))
2927  {
2928  return instance->panelMouseButton(LWPanel(id), qualifiers, x, y);
2929  }
2930  }
2932  template<typename T>
2933  void LWPanel::cb_PanMouseMove (LWPanelID id, void *userdata, int qualifiers, int x, int y)
2934  {
2935  if (T *instance = static_cast<T *>(userdata))
2936  {
2937  instance->panelMouseMove(LWPanel(id), qualifiers, x, y);
2938  }
2939  }
2940 
2942  template<typename T>
2943  void LWPanel::cb_PanResize (LWPanelID id, void *userdata, int w, int h)
2944  {
2945  if (T *instance = static_cast<T *>(userdata))
2946  {
2947  instance->panelResize(LWPanel(id), w, h);
2948  }
2949  }
2950 
2951 
2955 
2956 
2957  class AboutPanel : private LWPanel
2958  {
2959  private:
2960  const unsigned char *image;
2961  int width;
2962  int height;
2963  LWRaster mRaster;
2964  PanelControl canvas;
2965  void draw(LWControlID control, DrMode drawmode);
2966  public:
2967  AboutPanel(const std::string title, const char**message, const unsigned char *_image = 0, int w = 0, int h = 0);
2968  ~AboutPanel();
2969  void Open();
2970  static void UserDraw( LWControlID control, void *userdata, DrMode drawmode );
2971  };
2972 
2975  class LogPanel : private LWPanel, protected LWPanelListCallBacks, public std::vector<std::string>
2976  {
2977  PanelControl listbox;
2978  int w, h;
2979  public:
2980  virtual int controlCount(PanelControl&);
2981  virtual const char* controlName(PanelControl&, int index);
2982  public:
2983  LogPanel(const std::string &title, int width = 600, int height = 20)
2984  : LWPanel (title), w(width), h(height)
2985  {;}
2986  void Open(const std::string &name);
2987  };
2988 
2991  {
2992  int mQualifier;
2993  public:
2994  Qualifier(const int qual)
2995  : mQualifier(qual)
2996  {}
2997  bool isRightClick() const {return RCLICK(mQualifier);}
2998  bool isLeftClick() const {return LCLICK(mQualifier);}
2999  bool isMiddleClick() const {return MCLICK(mQualifier);}
3000  bool isMouseDown() const {return (mQualifier & MOUSE_DOWN) == MOUSE_DOWN;}
3001  bool isCtrl() const {return (mQualifier & IQ_CTRL) == IQ_CTRL;}
3002  bool isShift() const {return (mQualifier & IQ_SHIFT) == IQ_SHIFT;}
3003  bool isAlt() const {return (mQualifier & IQ_ALT) == IQ_ALT;}
3004  bool isConstrain() const {return (mQualifier & IQ_CONSTRAIN) == IQ_CONSTRAIN;}
3005  bool isAdjust() const {return (mQualifier & IQ_ADJUST) == IQ_ADJUST;}
3006  };
3007 
3008 } // namespace lwpp
3009 
3010 #endif // LWPP_PANEL_H