rendertarget.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #ifdef GAME_TEMPLATE
  2. [EditorAttribute("box", "GameLib/Scripted", "Render target", "-0.25 -0.25 -0.25", "0.25 0.25 0.25", "255 0 0 255")]
  3. class RenderTargetClass
  4. {
  5. }
  6. RenderTargetClass RenderTargetSource;
  7. class RenderTarget: GenericEntity
  8. {
  9. [Attribute("0", "slider", "Camera index", "0 31 1")]
  10. int CameraIndex;
  11. [Attribute("0", "editbox", "Position X <0, 1>")]
  12. float X;
  13. [Attribute("0", "editbox", "Position Y <0, 1>")]
  14. float Y;
  15. [Attribute("1", "editbox", "Render target width <0, 1>")]
  16. float Width;
  17. [Attribute("1", "editbox", "Render target height <0, 1>")]
  18. float Height;
  19. [Attribute("-1", "editbox", "Sort index (the lesser the more important)")]
  20. int Sort;
  21. [Attribute("0", "combobox", "Autoinit", "", { ParamEnum("No", "0"), ParamEnum("Yes", "1") } )]
  22. int AutoInit;
  23. [Attribute("0", "combobox", "Forcing creation of render target for camera #0 in Workbench", "", { ParamEnum("No", "0"), ParamEnum("Yes", "1") } )]
  24. bool ForceCreation;
  25. bool m_Show = true; // when autoinit, wait with showing the render target after all entities are created (EOnInit)
  26. ref RenderTargetWidget m_RenderWidget;
  27. void RenderTarget(IEntitySource src, IEntity parent)
  28. {
  29. SetFlags(EntityFlags.ACTIVE, false);
  30. if (AutoInit)
  31. {
  32. m_Show = false;
  33. SetEventMask(EntityEvent.INIT);
  34. Init();
  35. }
  36. }
  37. void ~RenderTarget()
  38. {
  39. delete m_RenderWidget;
  40. }
  41. void Init()
  42. {
  43. #ifdef WORKBENCH // Workbench is using its own renderer for main camera, it is not using render target widget.
  44. if (!ForceCreation && CameraIndex == 0)
  45. return;
  46. #endif
  47. int screenW, screenH;
  48. GetScreenSize(screenW, screenH);
  49. int posX = (float)(screenW * X);
  50. int posY = (float)(screenH * Y);
  51. int widthPix = (float)(screenW * Width);
  52. int heightPix = (float)(screenH * Height);
  53. if (Class.CastTo(m_RenderWidget, GetGame().GetWorkspace().CreateWidget(RenderTargetWidgetTypeID, posX, posY, widthPix, heightPix, WidgetFlags.VISIBLE | WidgetFlags.HEXACTSIZE | WidgetFlags.VEXACTSIZE | WidgetFlags.HEXACTPOS | WidgetFlags.VEXACTPOS, 0xffffffff, Sort)))
  54. {
  55. m_RenderWidget.Show(m_Show);
  56. SetWidgetWorld(m_RenderWidget, GetGame().GetWorldEntity(), CameraIndex);
  57. }
  58. }
  59. override void EOnInit(IEntity other, int extra) //!EntityEvent.INIT
  60. {
  61. if (m_RenderWidget)
  62. {
  63. m_Show = true;
  64. m_RenderWidget.Show(m_Show);
  65. }
  66. }
  67. }
  68. #endif