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.

117 lines
2.8KB

  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 SetConnectionCallback(Fl_Callback* s) { cb_Connection=s; }
  63. void SetUnconnectCallback(Fl_Callback* s) { cb_Unconnect=s; }
  64. void SetAddDeviceCallback(Fl_Callback* s) { cb_AddDevice=s; }
  65. void ClearConnections(Fl_DeviceGUI* Device);
  66. void RemoveDevice(Fl_DeviceGUI* Device);
  67. void Clear();
  68. void AddPluginName(const string &s, int ID)
  69. { m_PluginNameList.push_back(pair<string,int>(s,ID)); }
  70. GraphSort* GetGraph() { return &m_Graph; }
  71. void Poll();
  72. private:
  73. void DrawWires();
  74. void ClearIncompleteWire();
  75. void DrawIncompleteWire();
  76. bool UserMakingConnection();
  77. Fl_Image *m_BG;
  78. char *m_BGData;
  79. void (*cb_Connection)(Fl_Widget*, void*);
  80. void (*cb_Unconnect)(Fl_Widget*, void*);
  81. void (*cb_AddDevice)(Fl_Widget*, void*);
  82. vector<CanvasWire> m_WireVec;
  83. CanvasWire m_IncompleteWire;
  84. bool m_ToolMenu, m_ButtonDown;
  85. int m_x,m_y,m_Selected;
  86. vector< pair<string,int> > m_PluginNameList;
  87. GraphSort m_Graph;
  88. int m_UpdateTimer;
  89. friend istream &operator>>(istream &s, Fl_Canvas &o);
  90. friend ostream &operator<<(ostream &s, Fl_Canvas &o);
  91. };
  92. istream &operator>>(istream &s, Fl_Canvas &o);
  93. ostream &operator<<(ostream &s, Fl_Canvas &o);
  94. #endif