shaderNode.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. // fixed extent for all nodes, only height should be changed
  36. setExtent(150, 100);
  37. GuiControlProfile* profile = NULL;
  38. if (Sim::findObject("ToolsGuiDefaultProfile", profile))
  39. setControlProfile(profile);
  40. }
  41. bool ShaderNode::onWake()
  42. {
  43. if (!Parent::onWake())
  44. return false;
  45. return true;
  46. }
  47. void ShaderNode::onSleep()
  48. {
  49. Parent::onSleep();
  50. }
  51. void ShaderNode::initPersistFields()
  52. {
  53. docsURL;
  54. Parent::initPersistFields();
  55. }
  56. bool ShaderNode::onAdd()
  57. {
  58. if (!Parent::onAdd())
  59. return false;
  60. return true;
  61. }
  62. void ShaderNode::onRemove()
  63. {
  64. Parent::onRemove();
  65. }
  66. void ShaderNode::onRender(Point2I offset, const RectI& updateRect)
  67. {
  68. if (!mProfile)
  69. return Parent::onRender(offset, updateRect);
  70. GFXDrawUtil* drawer = GFX->getDrawUtil();
  71. // Get our rect.
  72. RectI winRect;
  73. winRect.point = offset;
  74. winRect.extent = getExtent();
  75. // draw background.
  76. drawer->drawRectFill(winRect, mProfile->mFillColor);
  77. // draw header text.
  78. U32 strWidth = mProfile->mFont->getStrWidth(mTitle.c_str());
  79. Point2I headerPos = Point2I((getExtent().x / 2) - (strWidth / 2), (30 / 2) - (mProfile->mFont->getFontSize() / 2));
  80. drawer->setBitmapModulation(mProfile->mFontColor);
  81. drawer->drawText(mProfile->mFont, headerPos + offset, mTitle);
  82. drawer->clearBitmapModulation();
  83. ColorI border(128, 128, 128, 128);
  84. if (mSelected)
  85. border = ColorI(128, 0, 128, 128);
  86. winRect.inset(1, 1);
  87. drawer->drawRect(winRect, border);
  88. }
  89. void ShaderNode::write(Stream& stream, U32 tabStop, U32 flags)
  90. {
  91. }
  92. void ShaderNode::read(Stream& stream)
  93. {
  94. }