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
4.7KB

  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. #ifndef DEVICEGUI
  19. #define DEVICEGUI
  20. #include <FL/Fl.H>
  21. #include <FL/Fl_Group.H>
  22. #include <FL/Fl_Button.H>
  23. #include <Fl/Fl_Pixmap.H>
  24. #include <Fl/Fl_Menu_Button.H>
  25. #include <Fl/Fl_Box.H>
  26. #include "Fl_DragBar.H"
  27. #include "SpiralGUI.H"
  28. #include <iostream>
  29. #include <vector>
  30. #include <string>
  31. #include <stdio.h>
  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. 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. public:
  71. Fl_DeviceGUI (const DeviceGUIInfo& Info, SpiralGUIType *PW, Fl_Pixmap *Icon, bool Terminal=false);
  72. virtual int handle (int event);
  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. // aesthetic, 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. SpiralGUIType* GetPluginWindow() { return m_PluginWindow; }
  86. string GetName() { return m_Name; }
  87. void SetName (const string &s) { m_Name=s; m_DragBar->label (m_Name.c_str()); }
  88. bool IsMinimised() { return m_Minimised; }
  89. void Minimise();
  90. void Maximise();
  91. // automatically called from the constructor, but may be redone at any time.
  92. virtual void Setup (const DeviceGUIInfo& Info, bool FirstTime = false);
  93. virtual void Clear();
  94. int GetPortType (int n) { return m_Info.PortTypes[n]; }
  95. // do we belong to a plugin that is an output?
  96. bool IsTerminal() { return m_IsTerminal; }
  97. void SetOnDragCallback(void (*cb)(Fl_Widget*, int x,int y, void*), void* data) { m_DragBar->cb_OnDrag = cb; m_DragBar->cb_OnDrag_Data = data; }
  98. void SetOnClickCallback(void (*cb)(Fl_Widget*, int button, int shift_state, void*), void* data) { m_DragBar->cb_OnClick = cb; m_DragBar->cb_OnClick_Data = data; }
  99. static void Kill(Fl_DeviceGUI *device) { if (device) device->m_DelMe = true; }
  100. protected:
  101. DeviceGUIInfo m_Info;
  102. Fl_DragBar* m_DragBar;
  103. SpiralGUIType* m_PluginWindow;
  104. Fl_Pixmap* m_Icon;
  105. Fl_Button* m_IconButton;
  106. Fl_Menu_Button* m_Menu;
  107. private:
  108. void ResizeToPluginWindow (void);
  109. void Resize (int width, int height);
  110. inline void cb_Resize_i (void);
  111. static void cb_Resize (Fl_DeviceGUI *o);
  112. inline void cb_Port_i (Fl_Button* o, void* v);
  113. static void cb_Port (Fl_Button* o, void* v);
  114. inline void cb_Rename_i (Fl_Menu_Button* o, void* v);
  115. static void cb_Rename (Fl_Menu_Button* o, void* v);
  116. inline void cb_Delete_i (Fl_Menu_Button* o, void* v);
  117. static void cb_Delete (Fl_Menu_Button* o, void* v);
  118. vector<Fl_PortButton*> m_PortVec;
  119. static int Numbers[512];
  120. string m_Name;
  121. int m_ID, m_MiniWidth, m_MiniHeight;
  122. bool m_DelMe, m_IsTerminal, m_Minimised;
  123. };
  124. #endif