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.

120 lines
2.9KB

  1. /* Canvas 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_Group.h>
  19. #include <FL/Fl_Output.h>
  20. #include <FL/Fl_Image.h>
  21. #include <vector>
  22. #include <string>
  23. #include "../../GraphSort.h"
  24. #ifndef CANVAS_WIDGET
  25. #define CANVAS_WIDGET
  26. using namespace std;
  27. class Fl_DeviceGUI;
  28. class CanvasWire
  29. {
  30. public:
  31. CanvasWire() { Clear(); }
  32. void Clear()
  33. {
  34. OutputChild=-1;
  35. OutputPort=-1;
  36. OutputID=-1;
  37. OutputTerminal=false;
  38. InputChild=-1;
  39. InputPort=-1;
  40. InputID=-1;
  41. InputTerminal=false;
  42. DelMe=false;
  43. }
  44. int OutputID;
  45. int OutputChild;
  46. int OutputPort;
  47. bool OutputTerminal;
  48. int InputID;
  49. int InputChild;
  50. int InputPort;
  51. bool InputTerminal;
  52. bool DelMe;
  53. };
  54. class Fl_Canvas : public Fl_Group
  55. {
  56. public:
  57. Fl_Canvas(int x, int y, int w, int h, char *name);
  58. ~Fl_Canvas();
  59. virtual void draw();
  60. virtual int handle(int event);
  61. void PortClicked(Fl_DeviceGUI* Device, int Type, int Port, bool Value);
  62. void Rename(Fl_DeviceGUI* Device);
  63. void SetConnectionCallback(Fl_Callback* s) { cb_Connection=s; }
  64. void SetUnconnectCallback(Fl_Callback* s) { cb_Unconnect=s; }
  65. void SetAddDeviceCallback(Fl_Callback* s) { cb_AddDevice=s; }
  66. void SetRenameCallback(Fl_Callback* s) { cb_Rename=s; }
  67. void ClearConnections(Fl_DeviceGUI* Device);
  68. void RemoveDevice(Fl_DeviceGUI* Device);
  69. void Clear();
  70. void AddPluginName(const string &s, int ID)
  71. { m_PluginNameList.push_back(pair<string,int>(s,ID)); }
  72. GraphSort* GetGraph() { return &m_Graph; }
  73. void Poll();
  74. private:
  75. void DrawWires();
  76. void ClearIncompleteWire();
  77. void DrawIncompleteWire();
  78. bool UserMakingConnection();
  79. Fl_Image *m_BG;
  80. char *m_BGData;
  81. void (*cb_Connection)(Fl_Widget*, void*);
  82. void (*cb_Unconnect)(Fl_Widget*, void*);
  83. void (*cb_AddDevice)(Fl_Widget*, void*);
  84. void (*cb_Rename)(Fl_Widget*, void*);
  85. vector<CanvasWire> m_WireVec;
  86. CanvasWire m_IncompleteWire;
  87. bool m_ToolMenu, m_ButtonDown;
  88. int m_x,m_y,m_Selected;
  89. vector< pair<string,int> > m_PluginNameList;
  90. GraphSort m_Graph;
  91. int m_UpdateTimer;
  92. friend istream &operator>>(istream &s, Fl_Canvas &o);
  93. friend ostream &operator<<(ostream &s, Fl_Canvas &o);
  94. };
  95. istream &operator>>(istream &s, Fl_Canvas &o);
  96. ostream &operator<<(ostream &s, Fl_Canvas &o);
  97. #endif