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.

162 lines
6.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCETICE project - Copyright 2009 by Lucio Asnaghi.
  4. JUCETICE is based around the JUCE library - "Jules' Utility Class Extensions"
  5. Copyright 2007 by Julian Storer.
  6. ------------------------------------------------------------------------------
  7. JUCE and JUCETICE can be redistributed and/or modified under the terms of
  8. the GNU General Public License, as published by the Free Software Foundation;
  9. either version 2 of the License, or (at your option) any later version.
  10. JUCE and JUCETICE are distributed in the hope that they will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with JUCE and JUCETICE; if not, visit www.gnu.org/licenses or write to
  16. Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  17. Boston, MA 02111-1307 USA
  18. ==============================================================================
  19. */
  20. #ifndef __JUCETICE_GRAPHCONNECTORCOMPONENT_HEADER__
  21. #define __JUCETICE_GRAPHCONNECTORCOMPONENT_HEADER__
  22. class GraphNodeComponent;
  23. class GraphLinkComponent;
  24. //==============================================================================
  25. class GraphConnectorComponent : public Component
  26. {
  27. public:
  28. //==============================================================================
  29. /** Connector constructor */
  30. GraphConnectorComponent (GraphNodeComponent* parentGraph,
  31. const int connectorType = 0);
  32. /** Destructor */
  33. ~GraphConnectorComponent ();
  34. //==============================================================================
  35. /** Return the unique identifier for this connector
  36. This unique identify the connector in its node, so different node
  37. connectors can have the same id.
  38. */
  39. int getConnectorID () const { return connectorID; }
  40. /** Set the unique identifier for this connector */
  41. void setConnectorID (const int newID) { connectorID = newID; }
  42. //==============================================================================
  43. /** Returns the connector type
  44. Different connector types represent different kind of connections available
  45. so a connector of a type can't be connected to one of another type.
  46. */
  47. int getType () const { return connectorType; }
  48. /** Change the connector type. */
  49. void setType (const int newType) { connectorType = newType; }
  50. //==============================================================================
  51. /** Returns the connector type */
  52. virtual bool isInput () const = 0;
  53. //==============================================================================
  54. virtual void getLinkedConnectors (Array<GraphConnectorComponent*>& links) = 0;
  55. virtual bool canConnectFrom (GraphLinkComponent* link) { return false; }
  56. virtual bool canConnectTo (GraphLinkComponent* link) { return false; }
  57. virtual void updatePosition();
  58. //==============================================================================
  59. void setRelativePosition (const int x, const int y);
  60. //==============================================================================
  61. bool connectTo (GraphLinkComponent* link);
  62. bool connectFrom (GraphLinkComponent* link);
  63. void notifyGraphChanged ();
  64. //==============================================================================
  65. void addLink (GraphLinkComponent* newLink);
  66. void removeLink (GraphLinkComponent* newLink);
  67. void removeLinkWith (GraphConnectorComponent* connector, const bool notifyListeners = true);
  68. void removeLinkWith (GraphNodeComponent* node, const bool notifyListeners = true);
  69. void destroyAllLinks (const bool notifyListeners = true);
  70. //==============================================================================
  71. GraphNodeComponent* getParentGraphComponent () const { return parentGraph; }
  72. //==============================================================================
  73. /** @internal */
  74. void connectionDragEnter();
  75. /** @internal */
  76. void connectionDragExit();
  77. /** @internal */
  78. void mouseDown (const MouseEvent& e);
  79. /** @internal */
  80. void paint (Graphics& g);
  81. //==============================================================================
  82. juce_UseDebuggingNewOperator
  83. protected:
  84. GraphNodeComponent* parentGraph;
  85. int relativePositionX, relativePositionY;
  86. OwnedArray<GraphLinkComponent> links;
  87. GraphLinkComponent* newLink;
  88. GraphConnectorComponent* currentlyDraggingOver;
  89. // Colour normalColour, selectedColour;
  90. int connectorID, connectorType;
  91. bool connectionDraggedOver;
  92. bool leftToRight;
  93. };
  94. //==============================================================================
  95. class GraphConnectorComponentInput : public GraphConnectorComponent
  96. {
  97. public:
  98. GraphConnectorComponentInput (GraphNodeComponent* parentGraph_,
  99. const int connectorType_);
  100. bool isInput () const { return true; }
  101. bool canConnectFrom (GraphLinkComponent* link);
  102. void getLinkedConnectors (Array<GraphConnectorComponent*>& links);
  103. void updatePosition();
  104. void mouseDrag(const MouseEvent& e);
  105. void mouseUp(const MouseEvent& e);
  106. };
  107. //==============================================================================
  108. class GraphConnectorComponentOutput : public GraphConnectorComponent
  109. {
  110. public:
  111. GraphConnectorComponentOutput (GraphNodeComponent* parentGraph_,
  112. const int connectorType_);
  113. bool isInput () const { return false; }
  114. virtual bool canConnectTo (GraphLinkComponent* link);
  115. virtual void getLinkedConnectors (Array<GraphConnectorComponent*>& links);
  116. virtual void updatePosition();
  117. void mouseDrag(const MouseEvent& e);
  118. void mouseUp(const MouseEvent& e);
  119. };
  120. #endif