shaderNode.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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(ShaderNode);
  26. ConsoleDocClass(ShaderNode,
  27. "@brief Base class for all nodes to derive from.\n\n"
  28. "Editor use only.\n\n"
  29. "@internal"
  30. );
  31. ShaderNode::ShaderNode()
  32. {
  33. mTitle = "Default Node";
  34. mSelected = false;
  35. mNodeType = NodeTypes::Uniform;
  36. // fixed extent for all nodes, only height should be changed
  37. setExtent(210, 100);
  38. GuiControlProfile* profile = NULL;
  39. if (Sim::findObject("ToolsGuiDefaultProfile", profile))
  40. setControlProfile(profile);
  41. }
  42. bool ShaderNode::onWake()
  43. {
  44. if (!Parent::onWake())
  45. return false;
  46. return true;
  47. }
  48. void ShaderNode::onSleep()
  49. {
  50. Parent::onSleep();
  51. }
  52. void ShaderNode::initPersistFields()
  53. {
  54. docsURL;
  55. Parent::initPersistFields();
  56. }
  57. bool ShaderNode::onAdd()
  58. {
  59. if (!Parent::onAdd())
  60. return false;
  61. return true;
  62. }
  63. void ShaderNode::onRemove()
  64. {
  65. Parent::onRemove();
  66. }
  67. void ShaderNode::onRender(Point2I offset, const RectI& updateRect)
  68. {
  69. if (!mProfile)
  70. return Parent::onRender(offset, updateRect);
  71. GFXDrawUtil* drawer = GFX->getDrawUtil();
  72. // draw background.
  73. // Get our rect.
  74. RectI winRect;
  75. winRect.point = offset;
  76. winRect.extent = getExtent();
  77. drawer->drawRectFill(winRect, mProfile->mFillColor);
  78. // draw header
  79. RectI headRect;
  80. headRect.point = offset;
  81. headRect.extent = Point2I(getExtent().x, 30);
  82. ColorI header(50, 50, 50, 128);
  83. switch (mNodeType)
  84. {
  85. case NodeTypes::Default:
  86. header = ColorI(128, 50, 128, 128);
  87. break;
  88. case NodeTypes::Uniform:
  89. header = ColorI(50, 100, 128, 128);
  90. break;
  91. case NodeTypes::Input:
  92. header = ColorI(128, 100, 50, 128);
  93. break;
  94. case NodeTypes::Output:
  95. header = ColorI(50, 100, 50, 128);
  96. break;
  97. case NodeTypes::TextureSampler:
  98. header = ColorI(50, 50, 128, 128);
  99. break;
  100. case NodeTypes::MathOperation:
  101. header = ColorI(128, 0, 128, 128);
  102. break;
  103. case NodeTypes::Procedural:
  104. header = ColorI(128, 100, 0, 128);
  105. break;
  106. case NodeTypes::Generator:
  107. header = ColorI(0, 100, 128, 128);
  108. break;
  109. default:
  110. header = ColorI(128, 0, 0, 128);
  111. break;
  112. }
  113. drawer->drawRectFill(headRect, header);
  114. // draw header text.
  115. U32 strWidth = mProfile->mFont->getStrWidth(mTitle.c_str());
  116. Point2I headerPos = Point2I((getExtent().x / 2) - (strWidth / 2), (30 / 2) - (mProfile->mFont->getFontSize() / 2));
  117. drawer->setBitmapModulation(mProfile->mFontColor);
  118. drawer->drawText(mProfile->mFont, headerPos + offset, mTitle);
  119. drawer->clearBitmapModulation();
  120. ColorI border(128, 128, 128, 128);
  121. if (mSelected)
  122. border = ColorI(128, 0, 128, 255);
  123. drawer->drawRect(winRect, border);
  124. }
  125. void ShaderNode::write(Stream& stream, U32 tabStop, U32 flags)
  126. {
  127. }
  128. void ShaderNode::read(Stream& stream)
  129. {
  130. }