Linux multi-monitor fullscreen support
[ryzomcore.git] / ryzom / client / src / interface_v3 / group_in_scene.cpp
blob6bfbe7518e4acf56dae2826914290d75ee91cfd2
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010-2016 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "stdpch.h"
27 #include "group_in_scene.h"
28 #include "interface_manager.h"
29 #include "nel/gui/view_renderer.h"
30 #include "nel/misc/xml_auto_ptr.h"
32 using namespace std;
33 using namespace NLMISC;
35 extern CMatrix MainSceneViewMatrix;
36 extern CMatrix InvMainSceneViewMatrix;
39 // ***************************************************************************
40 const float CGroupInScene::NearDrawClip= 1.f;
43 // ***************************************************************************
44 NLMISC_REGISTER_OBJECT(CViewBase, CGroupInScene, std::string, "in_scene");
46 REGISTER_UI_CLASS(CGroupInScene)
48 CGroupInScene::CGroupInScene(const TCtorParam &param)
49 : CInterfaceGroup(param)
51 // Group in scene must update each frame
52 _NeedFrameUpdatePos= true;
54 _OffsetX = 0;
55 _OffsetY = 0;
57 Scale= 1;
58 _UserScale= false;
60 _ZBias= 0.f;
62 Position= CVector::Null;
64 _ProjCenter= CVector::Null;
65 _IsGroupInScene = true;
68 // ***************************************************************************
69 CGroupInScene::~CGroupInScene()
73 // ***************************************************************************
74 void CGroupInScene::computeWindowPos(sint32 &newX, sint32 &newY, CVector &newProjCenter)
76 // don't change X/Y by default
77 newX= _X;
78 newY= _Y;
79 newProjCenter.x= float(_X) - _OffsetX;
80 newProjCenter.y= float(_Y) - _OffsetY;
82 if(getActive())
84 CViewRenderer &pVR = *CViewRenderer::getInstance();
85 nlassert(isValidDouble(Position.x) && isValidDouble(Position.y) && isValidDouble(Position.z));
86 CVector tmp = MainSceneViewMatrix * Position;
87 if (tmp.y>=0.001)
89 tmp = pVR.getFrustum().projectZ (tmp);
91 // Get the width and height
92 uint32 width, height;
93 CViewRenderer::getInstance()->getScreenSize(width, height);
94 tmp.x *= width;
95 tmp.y *= height;
97 // position without offset, in float
98 newProjCenter.x= tmp.x;
99 newProjCenter.y= tmp.y;
101 // Set the current Z
102 newProjCenter.z = -tmp.z;
103 _DepthForZSort= newProjCenter.z;
104 // Add ZBias (only if won't be clipped)
105 if(newProjCenter.z > NearDrawClip)
107 newProjCenter.z+= getZBias();
108 const float zthreshold= 0.01f;
109 newProjCenter.z= max(newProjCenter.z, pVR.getFrustum().Near+zthreshold);
110 newProjCenter.z= max(newProjCenter.z, NearDrawClip + zthreshold);
113 // Set the position
114 newX = (sint)floor (tmp.x+0.5f) + _OffsetX;
115 newY = (sint)floor (tmp.y+0.5f) + _OffsetY;
117 else
119 _DepthForZSort= newProjCenter.z = tmp.y;
122 else
124 _DepthForZSort= newProjCenter.z = -1.f;
127 nlassert (isValidDouble (newProjCenter.z));
130 // ***************************************************************************
131 void CGroupInScene::updateCoords()
133 // Get the x and the y
134 computeWindowPos(_X, _Y, _ProjCenter);
136 CInterfaceGroup::updateCoords();
139 // ***************************************************************************
140 void CGroupInScene::onFrameUpdateWindowPos (sint dx, sint dy)
142 // I am the root group, so I decide of the new window position.
143 sint32 newX, newY;
144 computeWindowPos(newX, newY, _ProjCenter);
146 dx= newX - _X;
147 dy= newY - _Y;
149 // Change the X and Y only here
150 _X= newX;
151 _Y= newY;
153 // CInterfaceGroup::onFrameUpdateWindowPos will apply the delta on XReal / YReal
154 CInterfaceGroup::onFrameUpdateWindowPos(dx, dy);
157 // ***************************************************************************
158 void CGroupInScene::draw()
160 H_AUTO( RZ_Interface_CGroupInScene_draw )
162 if (_ProjCenter.z > NearDrawClip)
164 CViewRenderer &pVR = *CViewRenderer::getInstance();
166 // Set the current Z, and projCenter / scale
167 if(_UserScale)
168 pVR.setInterfaceDepth (_ProjCenter, Scale);
169 else
170 pVR.setInterfaceDepth (_ProjCenter, 1);
172 CInterfaceGroup::draw();
176 // ***************************************************************************
178 bool CGroupInScene::parse (xmlNodePtr cur, CInterfaceGroup *parent)
180 if (!CInterfaceGroup::parse (cur, parent))
181 return false;
183 CXMLAutoPtr ptr;
185 _OffsetX = 0;
186 ptr = xmlGetProp (cur, (xmlChar*)"in_scene_offset_x");
187 if (ptr)
188 fromString((const char*)ptr, _OffsetX);
189 _OffsetY = 0;
190 ptr = xmlGetProp (cur, (xmlChar*)"in_scene_offset_y");
191 if (ptr)
192 fromString((const char*)ptr, _OffsetY);
193 _UserScale= false;
194 ptr = xmlGetProp (cur, (xmlChar*)"user_scale");
195 if (ptr)
196 _UserScale= convertBool(ptr);
198 return true;
201 // ***************************************************************************
202 void CGroupInScene::setUserScale(bool swd)
204 _UserScale= swd;
207 // ***************************************************************************
208 void CGroupInScene::serial(NLMISC::IStream &f)
210 CInterfaceGroup::serial(f);
211 f.serial(_OffsetX);
212 f.serial(_OffsetY);
213 f.serial(_UserScale);