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