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.

155 lines
4.3KB

  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 <FL/Fl_Menu_Button.h>
  23. #include <FL/Fl_Box.h>
  24. #include <iostream>
  25. #include <vector>
  26. #include <string>
  27. #include "Fl_DragBar.H"
  28. #include <stdio.h>
  29. #ifndef DEVICEGUI
  30. #define DEVICEGUI
  31. #define WIRE_COL0 91
  32. #define WIRE_COL1 FL_GREEN
  33. #define WIRE_COL2 FL_YELLOW
  34. #define WIRE_COL3 FL_BLUE
  35. #define WIRE_COL4 FL_CYAN
  36. using namespace std;
  37. static const int TitleBarHeight = 12;
  38. static const int PortGroupWidth = 12;
  39. static const int PortSize=6;
  40. class Fl_PortButton : public Fl_Button
  41. {
  42. public:
  43. enum Type {INPUT,OUTPUT};
  44. Fl_PortButton(int x, int y, int w, int h, char *n);
  45. virtual ~Fl_PortButton() {};
  46. void SetType(Type s) { m_Type=s; }
  47. virtual int handle(int event);
  48. void Add() { m_ConnectionCount++; }
  49. void Remove() { if (m_ConnectionCount>0) m_ConnectionCount--; }
  50. int GetCount() { return m_ConnectionCount; }
  51. int GetLastButton() { return m_LastButton; }
  52. private:
  53. Type m_Type;
  54. int m_ConnectionCount;
  55. int m_LastButton;
  56. };
  57. struct DeviceGUIInfo
  58. {
  59. int XPos;
  60. int YPos;
  61. int Width;
  62. int Height;
  63. int NumInputs;
  64. int NumOutputs;
  65. vector<string> PortTips;
  66. string Name;
  67. vector<int> PortTypes;
  68. };
  69. class Fl_DeviceGUI : public Fl_Group
  70. {
  71. public:
  72. Fl_DeviceGUI(const DeviceGUIInfo& Info, Fl_Group *PW, Fl_Pixmap *Icon, bool Terminal=false);
  73. virtual int handle(int event);
  74. enum PortType {INPUT,OUTPUT};
  75. int GetID() { return m_ID; }
  76. void SetID(int s) { m_ID=s; /*DisplayID(s);*/ }
  77. bool Killed() { return m_DelMe; }
  78. int GetPortX(int n) { return m_PortVec[n]->x()+PortSize/2; }
  79. int GetPortY(int n) { return m_PortVec[n]->y()+PortSize/2; }
  80. // aesthetic, to keep track of number of connections to know whether to
  81. // draw the port as occupied or not.
  82. bool AddConnection(int n);
  83. void RemoveConnection(int n);
  84. bool GetPortValue(int n) { return m_PortVec[n]->value(); }
  85. const DeviceGUIInfo* GetInfo() { return &m_Info; }
  86. Fl_Group* GetPluginWindow() { return m_PluginWindow; }
  87. string GetName() { return m_Name; }
  88. void SetName(const string &s) { m_Name=s; m_DragBar->label(m_Name.c_str()); }
  89. bool IsMinimised() { return m_Minimised; }
  90. void Minimise();
  91. void Maximise();
  92. // automatically called from the constructor, but may be redone at any time.
  93. virtual void Setup(const DeviceGUIInfo& Info, bool FirstTime = false);
  94. virtual void Clear();
  95. int GetPortType(int n) { return m_Info.PortTypes[n]; }
  96. // do we belong to a plugin that is an output?
  97. bool IsTerminal() { return m_IsTerminal; }
  98. protected:
  99. DeviceGUIInfo m_Info;
  100. Fl_DragBar* m_DragBar;
  101. Fl_Group* m_PluginWindow;
  102. Fl_Pixmap* m_Icon;
  103. Fl_Button* m_IconButton;
  104. Fl_Menu_Button* m_Menu;
  105. private:
  106. void Resize(int width, int height);
  107. inline void cb_Port_i(Fl_Button* o, void* v);
  108. static void cb_Port(Fl_Button* o, void* v);
  109. inline void cb_Rename_i(Fl_Menu_Button* o, void* v);
  110. static void cb_Rename(Fl_Menu_Button* o, void* v);
  111. inline void cb_Delete_i(Fl_Menu_Button* o, void* v);
  112. static void cb_Delete(Fl_Menu_Button* o, void* v);
  113. vector<Fl_PortButton*> m_PortVec;
  114. static int Numbers[512];
  115. string m_Name;
  116. int m_ID;
  117. bool m_DelMe;
  118. bool m_IsTerminal;
  119. bool m_Minimised;
  120. int m_MiniWidth;
  121. int m_MiniHeight;
  122. };
  123. #endif