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.

121 lines
3.0KB

  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. OutputPort=-1;
  35. OutputID=-1;
  36. OutputTerminal=false;
  37. InputPort=-1;
  38. InputID=-1;
  39. InputTerminal=false;
  40. DelMe=false;
  41. }
  42. int OutputID;
  43. int OutputPort;
  44. bool OutputTerminal;
  45. int InputID;
  46. int InputPort;
  47. bool InputTerminal;
  48. bool DelMe;
  49. };
  50. class Fl_Canvas : public Fl_Group
  51. {
  52. public:
  53. Fl_Canvas(int x, int y, int w, int h, char *name);
  54. ~Fl_Canvas();
  55. virtual void draw();
  56. virtual int handle(int event);
  57. void PortClicked(Fl_DeviceGUI* Device, int Type, int Port, bool Value);
  58. void Rename(Fl_DeviceGUI* Device);
  59. void SetConnectionCallback(Fl_Callback* s) { cb_Connection=s; }
  60. void SetUnconnectCallback(Fl_Callback* s) { cb_Unconnect=s; }
  61. void SetAddDeviceCallback(Fl_Callback* s) { cb_AddDevice=s; }
  62. void SetRenameCallback(Fl_Callback* s) { cb_Rename=s; }
  63. void ClearConnections(Fl_DeviceGUI* Device);
  64. void RemoveDevice(Fl_DeviceGUI* Device);
  65. void Clear();
  66. void AddPluginName(const string &s, int ID)
  67. { m_PluginNameList.push_back(pair<string,int>(s,ID)); }
  68. GraphSort* GetGraph() { return &m_Graph; }
  69. void Poll();
  70. void ToTop(Fl_DeviceGUI *o);
  71. void ToBot(Fl_DeviceGUI *o);
  72. private:
  73. void DrawWires();
  74. void ClearIncompleteWire();
  75. void DrawIncompleteWire();
  76. bool UserMakingConnection();
  77. Fl_DeviceGUI *FindDevice(int ID);
  78. Fl_Image *m_BG;
  79. char *m_BGData;
  80. void (*cb_Connection)(Fl_Widget*, void*);
  81. void (*cb_Unconnect)(Fl_Widget*, void*);
  82. void (*cb_AddDevice)(Fl_Widget*, void*);
  83. void (*cb_Rename)(Fl_Widget*, void*);
  84. vector<CanvasWire> m_WireVec;
  85. CanvasWire m_IncompleteWire;
  86. bool m_ToolMenu, m_ButtonDown;
  87. int m_x,m_y,m_Selected;
  88. vector< pair<string,int> > m_PluginNameList;
  89. GraphSort m_Graph;
  90. int m_UpdateTimer;
  91. int m_DragX,m_DragY;
  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