shaderNode.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "platform/platform.h"
  23. #include "gui/shaderEditor/nodes/shaderNode.h"
  24. #include "gui/core/guiCanvas.h"
  25. IMPLEMENT_CONOBJECT(GuiShaderNode);
  26. ConsoleDocClass(GuiShaderNode,
  27. "@brief Base class for all nodes to derive from.\n\n"
  28. "Editor use only.\n\n"
  29. "@internal"
  30. );
  31. GuiShaderNode::GuiShaderNode()
  32. {
  33. VECTOR_SET_ASSOCIATION(mInputNodes);
  34. VECTOR_SET_ASSOCIATION(mOutputNodes);
  35. mTitle = "Default Node";
  36. mSelected = false;
  37. mNodeType = NodeTypes::Default;
  38. GuiControlProfile* profile = NULL;
  39. if (Sim::findObject("GuiShaderEditorProfile", profile))
  40. setControlProfile(profile);
  41. mInputNodes.push_back(new NodeInput("RGBA", DataDimensions::Dynamic));
  42. mInputNodes.push_back(new NodeInput("RGBA", DataDimensions::Dynamic));
  43. mInputNodes.push_back(new NodeInput("RGBA", DataDimensions::Dynamic));
  44. mInputNodes.push_back(new NodeInput("RGBA", DataDimensions::Dynamic));
  45. mOutputNodes.push_back(new NodeOutput("RGBA", DataDimensions::Dynamic));
  46. mOutputNodes.push_back(new NodeOutput("RGBA", DataDimensions::Dynamic));
  47. mOutputNodes.push_back(new NodeOutput("RGBA", DataDimensions::Dynamic));
  48. mOutputNodes.push_back(new NodeOutput("RGBA", DataDimensions::Dynamic));
  49. // fixed extent for all nodes, only height should be changed
  50. setExtent(210, 35);
  51. mPrevNodeSize = -1;
  52. }
  53. bool GuiShaderNode::onWake()
  54. {
  55. if (!Parent::onWake())
  56. return false;
  57. return true;
  58. }
  59. void GuiShaderNode::onSleep()
  60. {
  61. Parent::onSleep();
  62. }
  63. void GuiShaderNode::initPersistFields()
  64. {
  65. docsURL;
  66. Parent::initPersistFields();
  67. }
  68. bool GuiShaderNode::onAdd()
  69. {
  70. if (!Parent::onAdd())
  71. return false;
  72. return true;
  73. }
  74. void GuiShaderNode::onRemove()
  75. {
  76. Parent::onRemove();
  77. }
  78. void GuiShaderNode::renderNode(Point2I offset, const RectI& updateRect, const S32 nodeSize)
  79. {
  80. if (!mProfile)
  81. return Parent::onRender(offset, updateRect);
  82. GFXDrawUtil* drawer = GFX->getDrawUtil();
  83. // draw background.
  84. // Get our rect.
  85. RectI winRect;
  86. winRect.point = offset;
  87. winRect.extent = getExtent();
  88. drawer->drawRectFill(winRect, mProfile->mFillColor);
  89. // draw header
  90. ColorI header(50, 50, 50, 128);
  91. switch (mNodeType)
  92. {
  93. case NodeTypes::Default:
  94. header = ColorI(128, 50, 128, 128);
  95. break;
  96. case NodeTypes::Uniform:
  97. header = ColorI(50, 100, 128, 128);
  98. break;
  99. case NodeTypes::Input:
  100. header = ColorI(128, 100, 50, 128);
  101. break;
  102. case NodeTypes::Output:
  103. header = ColorI(50, 100, 50, 128);
  104. break;
  105. case NodeTypes::TextureSampler:
  106. header = ColorI(50, 50, 128, 128);
  107. break;
  108. case NodeTypes::MathOperation:
  109. header = ColorI(128, 0, 128, 128);
  110. break;
  111. case NodeTypes::Procedural:
  112. header = ColorI(128, 100, 0, 128);
  113. break;
  114. case NodeTypes::Generator:
  115. header = ColorI(0, 100, 128, 128);
  116. break;
  117. default:
  118. header = ColorI(128, 0, 0, 128);
  119. break;
  120. }
  121. RectI headRect;
  122. U32 headerSize = 30;
  123. headRect.point = offset;
  124. headRect.extent = Point2I(getExtent().x, headerSize);
  125. drawer->drawRectFill(headRect, header);
  126. // draw header text.
  127. U32 strWidth = mProfile->mFont->getStrWidth(mTitle.c_str());
  128. Point2I headerPos = Point2I((getExtent().x / 2) - (strWidth / 2), (headerSize / 2) - (mProfile->mFont->getFontSize() / 2));
  129. drawer->setBitmapModulation(mProfile->mFontColor);
  130. drawer->drawText(mProfile->mFont, headerPos + offset, mTitle);
  131. drawer->clearBitmapModulation();
  132. ColorI border = mProfile->mBorderColor;
  133. if (mSelected)
  134. border = mProfile->mBorderColorSEL;
  135. drawer->drawRect(winRect, border);
  136. if (mInputNodes.size() > 0 || mOutputNodes.size() > 0)
  137. {
  138. U32 textPadX = nodeSize, textPadY = mProfile->mFont->getFontSize() + (nodeSize / 2);
  139. Point2I slotPos(textPadX, headerSize + (nodeSize / 2));
  140. drawer->setBitmapModulation(mProfile->mFontColor);
  141. for (NodeInput* input : mInputNodes)
  142. {
  143. drawer->drawText(mProfile->mFont, slotPos + offset, input->name);
  144. if (input->pos == Point2I::Zero || mPrevNodeSize != nodeSize)
  145. input->pos = Point2I(-(nodeSize / 2), slotPos.y + ((mProfile->mFont->getFontSize() / 2) - (nodeSize / 2)));
  146. slotPos.y += textPadY;
  147. }
  148. U32 inputY = slotPos.y;
  149. slotPos = Point2I(getExtent().x, headerSize + (nodeSize / 2));
  150. for (NodeOutput* output : mOutputNodes)
  151. {
  152. strWidth = mProfile->mFont->getStrWidth(output->name.c_str());
  153. slotPos.x = getExtent().x - strWidth - textPadX;
  154. drawer->drawText(mProfile->mFont, slotPos + offset, output->name);
  155. if (output->pos == Point2I::Zero || mPrevNodeSize != nodeSize)
  156. output->pos = Point2I(getExtent().x - (nodeSize / 2) - 1 , slotPos.y + ((mProfile->mFont->getFontSize() / 2) - (nodeSize / 2)));
  157. slotPos.y += textPadY;
  158. }
  159. drawer->clearBitmapModulation();
  160. U32 outputY = slotPos.y;
  161. if (getExtent().y < slotPos.y || mPrevNodeSize != nodeSize)
  162. setExtent(Point2I(getExtent().x, mMax(inputY, outputY)));
  163. mPrevNodeSize = nodeSize;
  164. }
  165. }
  166. void GuiShaderNode::write(Stream& stream, U32 tabStop, U32 flags)
  167. {
  168. }
  169. void GuiShaderNode::read(Stream& stream)
  170. {
  171. }