File size: 2,321 Bytes
24b81cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifdef GAME_TEMPLATE

[EditorAttribute("box", "GameLib/Scripted", "Render target", "-0.25 -0.25 -0.25", "0.25 0.25 0.25", "255 0 0 255")]
class RenderTargetClass
{

}

RenderTargetClass RenderTargetSource;

class RenderTarget: GenericEntity
{
	[Attribute("0", "slider", "Camera index", "0 31 1")]
	int CameraIndex;
	[Attribute("0", "editbox", "Position X <0, 1>")]
	float X;
	[Attribute("0", "editbox", "Position Y <0, 1>")]
	float Y;
	[Attribute("1", "editbox", "Render target width <0, 1>")]
	float Width;
	[Attribute("1", "editbox", "Render target height <0, 1>")]
	float Height;
	[Attribute("-1", "editbox", "Sort index (the lesser the more important)")]
	int Sort;
	[Attribute("0", "combobox", "Autoinit", "", { ParamEnum("No", "0"), ParamEnum("Yes", "1") } )]
	int AutoInit;
	[Attribute("0", "combobox", "Forcing creation of render target for camera #0 in Workbench", "", { ParamEnum("No", "0"), ParamEnum("Yes", "1") } )]
	bool ForceCreation;
	bool m_Show = true; // when autoinit, wait with showing the render target after all entities are created (EOnInit)
	ref RenderTargetWidget m_RenderWidget;
	
	void RenderTarget(IEntitySource src, IEntity parent)
	{
		SetFlags(EntityFlags.ACTIVE, false);

		if (AutoInit)
		{
			m_Show = false;
			SetEventMask(EntityEvent.INIT);
			Init();
		}
	}

	void ~RenderTarget()
	{
		delete m_RenderWidget;
	}
	
	void Init()
	{
		#ifdef WORKBENCH // Workbench is using its own renderer for main camera, it is not using render target widget.
			if (!ForceCreation && CameraIndex == 0)
				return;
		#endif

		int screenW, screenH;
		GetScreenSize(screenW, screenH);

		int posX = (float)(screenW * X);
		int posY = (float)(screenH * Y);
		int widthPix = (float)(screenW * Width);
		int heightPix = (float)(screenH * Height);
		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)))
		{	
			m_RenderWidget.Show(m_Show);	
			SetWidgetWorld(m_RenderWidget, GetGame().GetWorldEntity(), CameraIndex);
		}
	}
	override void EOnInit(IEntity other, int extra) //!EntityEvent.INIT
	{
		if (m_RenderWidget)
		{
			m_Show = true;
			m_RenderWidget.Show(m_Show);
		}
	}
}

#endif