You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
3.6KB

  1. /* DeviceGUI composite Widget
  2. * Copyleft (C) 2002 David Griffiths <dave@pawfal.org>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. #include <FL/Fl.H>
  19. #include <FL/Fl_Group.H>
  20. #include <FL/Fl_Button.H>
  21. #include <FL/Fl_Pixmap.h>
  22. #include <iostream>
  23. #include <vector>
  24. #include <string>
  25. #include "Fl_DragBar.H"
  26. #include <stdio.h>
  27. #ifndef DEVICEGUI
  28. #define DEVICEGUI
  29. #define WIRE_COL0 91
  30. #define WIRE_COL1 FL_GREEN
  31. #define WIRE_COL2 FL_YELLOW
  32. #define WIRE_COL3 FL_BLUE
  33. #define WIRE_COL4 FL_CYAN
  34. using namespace std;
  35. static const int TitleBarHeight = 12;
  36. static const int PortGroupWidth = 12;
  37. static const int PortSize=6;
  38. class Fl_PortButton : public Fl_Button
  39. {
  40. public:
  41. enum Type {INPUT,OUTPUT};
  42. Fl_PortButton(int x, int y, int w, int h, char *n);
  43. virtual ~Fl_PortButton() {};
  44. void SetType(Type s) { m_Type=s; }
  45. virtual int handle(int event);
  46. void Add() { m_ConnectionCount++; }
  47. void Remove() { if (m_ConnectionCount>0) m_ConnectionCount--; }
  48. int GetCount() { return m_ConnectionCount; }
  49. int GetLastButton() { return m_LastButton; }
  50. private:
  51. Type m_Type;
  52. int m_ConnectionCount;
  53. int m_LastButton;
  54. };
  55. struct DeviceGUIInfo
  56. {
  57. int XPos;
  58. int YPos;
  59. int Width;
  60. int Height;
  61. int NumInputs;
  62. int NumOutputs;
  63. vector<string> PortTips;
  64. string Name;
  65. vector<int> PortTypes;
  66. };
  67. class Fl_DeviceGUI : public Fl_Group
  68. {
  69. public:
  70. Fl_DeviceGUI(const DeviceGUIInfo& Info, Fl_Group *PW, Fl_Pixmap *Icon, bool Terminal=false);
  71. virtual int handle(int event);
  72. virtual void draw();
  73. enum PortType {INPUT,OUTPUT};
  74. int GetID() { return m_ID; }
  75. void SetID(int s) { m_ID=s; /*DisplayID(s);*/ }
  76. bool Killed() { return m_DelMe; }
  77. int GetPortX(int n) { return m_PortVec[n]->x()+PortSize/2; }
  78. int GetPortY(int n) { return m_PortVec[n]->y()+PortSize/2; }
  79. // aesthitic, to keep track of number of connections to know whether to
  80. // draw the port as occupied or not.
  81. bool AddConnection(int n);
  82. void RemoveConnection(int n);
  83. bool GetPortValue(int n) { return m_PortVec[n]->value(); }
  84. const DeviceGUIInfo* GetInfo() { return &m_Info; }
  85. Fl_Group* GetPluginWindow() { return m_PluginWindow; }
  86. // automatically called from the constructor, but may be redone at any time.
  87. virtual void Setup(const DeviceGUIInfo& Info, bool FirstTime = false);
  88. virtual void Clear();
  89. int GetPortType(int n) { return m_Info.PortTypes[n]; }
  90. // do we belong to a plugin that is an output?
  91. bool IsTerminal() { return m_IsTerminal; }
  92. protected:
  93. DeviceGUIInfo m_Info;
  94. Fl_DragBar* m_DragBar;
  95. Fl_Group* m_PluginWindow;
  96. Fl_Pixmap* m_Icon;
  97. private:
  98. inline void cb_Port_i(Fl_Button* o, void* v);
  99. static void cb_Port(Fl_Button* o, void* v);
  100. vector<Fl_PortButton*> m_PortVec;
  101. static int Numbers[512];
  102. string m_Name;
  103. int m_ID;
  104. bool m_DelMe;
  105. bool m_IsTerminal;
  106. };
  107. #endif