|
@@ -183,11 +183,6 @@ SceneObject::SceneObject() :
|
|
/// Camera mounting.
|
|
/// Camera mounting.
|
|
mpAttachedCamera(NULL),
|
|
mpAttachedCamera(NULL),
|
|
|
|
|
|
- /// GUI attachment.
|
|
|
|
- mAttachedGuiSizeControl(false),
|
|
|
|
- mpAttachedGui(NULL),
|
|
|
|
- mpAttachedGuiSceneWindow(NULL),
|
|
|
|
-
|
|
|
|
/// Safe deletion.
|
|
/// Safe deletion.
|
|
mBeingSafeDeleted(false),
|
|
mBeingSafeDeleted(false),
|
|
mSafeDeleteReady(true),
|
|
mSafeDeleteReady(true),
|
|
@@ -206,6 +201,7 @@ SceneObject::SceneObject() :
|
|
VECTOR_SET_ASSOCIATION( mDestroyNotifyList );
|
|
VECTOR_SET_ASSOCIATION( mDestroyNotifyList );
|
|
VECTOR_SET_ASSOCIATION( mCollisionFixtureDefs );
|
|
VECTOR_SET_ASSOCIATION( mCollisionFixtureDefs );
|
|
VECTOR_SET_ASSOCIATION( mCollisionFixtures );
|
|
VECTOR_SET_ASSOCIATION( mCollisionFixtures );
|
|
|
|
+ VECTOR_SET_ASSOCIATION( mAttachedCtrls );
|
|
|
|
|
|
// Assign scene-object index.
|
|
// Assign scene-object index.
|
|
mSerialId = ++sSceneObjectMasterSerialId;
|
|
mSerialId = ++sSceneObjectMasterSerialId;
|
|
@@ -368,8 +364,8 @@ bool SceneObject::onAdd()
|
|
|
|
|
|
void SceneObject::onRemove()
|
|
void SceneObject::onRemove()
|
|
{
|
|
{
|
|
- // Detach Any GUI Control.
|
|
|
|
- detachGui();
|
|
|
|
|
|
+ // Detach all GUI Control.
|
|
|
|
+ detachAllGuiControls();
|
|
|
|
|
|
// Remove from Scene.
|
|
// Remove from Scene.
|
|
if ( getScene() )
|
|
if ( getScene() )
|
|
@@ -627,7 +623,7 @@ void SceneObject::integrateObject( const F32 totalTime, const F32 elapsedTime, D
|
|
}
|
|
}
|
|
|
|
|
|
// Update Any Attached GUI.
|
|
// Update Any Attached GUI.
|
|
- if ( mpAttachedGui && mpAttachedGuiSceneWindow )
|
|
|
|
|
|
+ if ( mAttachedCtrls.size() )
|
|
{
|
|
{
|
|
updateAttachedGui();
|
|
updateAttachedGui();
|
|
}
|
|
}
|
|
@@ -761,7 +757,7 @@ void SceneObject::interpolateObject( const F32 timeDelta )
|
|
}
|
|
}
|
|
|
|
|
|
// Update Any Attached GUI.
|
|
// Update Any Attached GUI.
|
|
- if ( mpAttachedGui && mpAttachedGuiSceneWindow )
|
|
|
|
|
|
+ if ( mAttachedCtrls.size() )
|
|
{
|
|
{
|
|
updateAttachedGui();
|
|
updateAttachedGui();
|
|
}
|
|
}
|
|
@@ -2776,119 +2772,162 @@ void SceneObject::onInputEvent( StringTableEntry name, const GuiEvent& event, co
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
-void SceneObject::attachGui( GuiControl* pGuiControl, SceneWindow* pSceneWindow, const bool sizeControl )
|
|
|
|
|
|
+void SceneObject::attachGui(GuiControl* pGuiControl, SceneWindow* pSceneWindow, const bool sizeControl, const Vector2 offset)
|
|
{
|
|
{
|
|
- // Attach Gui Control.
|
|
|
|
- mpAttachedGui = pGuiControl;
|
|
|
|
-
|
|
|
|
- // Attach SceneWindow.
|
|
|
|
- mpAttachedGuiSceneWindow = pSceneWindow;
|
|
|
|
-
|
|
|
|
- // Set Size Gui Flag.
|
|
|
|
- mAttachedGuiSizeControl = sizeControl;
|
|
|
|
|
|
+ // Attach GUI control.
|
|
|
|
+ SceneObjectAttachedGUI attachedGui;
|
|
|
|
+ attachedGui.mpAttachedCtrl = pGuiControl;
|
|
|
|
+ attachedGui.mpAttachedSceneWindow = pSceneWindow;
|
|
|
|
+ attachedGui.mAutoSize = sizeControl;
|
|
|
|
+ attachedGui.mAttachedOffset = offset;
|
|
|
|
|
|
- // Register Gui Control/Window References.
|
|
|
|
- mpAttachedGui->registerReference( (SimObject**)&mpAttachedGui );
|
|
|
|
- mpAttachedGuiSceneWindow->registerReference( (SimObject**)&mpAttachedGuiSceneWindow );
|
|
|
|
|
|
+ // Register GUI control & window references.
|
|
|
|
+ attachedGui.mpAttachedCtrl->registerReference((SimObject**)&attachedGui.mpAttachedCtrl);
|
|
|
|
+ attachedGui.mpAttachedSceneWindow->registerReference((SimObject**)&attachedGui.mpAttachedSceneWindow);
|
|
|
|
|
|
- // Check/Adjust Parentage.
|
|
|
|
- if ( mpAttachedGui->getParent() != mpAttachedGuiSceneWindow )
|
|
|
|
|
|
+ // Check & adjust GUI parentage.
|
|
|
|
+ if (attachedGui.mpAttachedCtrl->getParent() != attachedGui.mpAttachedSceneWindow)
|
|
{
|
|
{
|
|
- // Warn.
|
|
|
|
- // Remove GuiControl from existing parent (if it has one).
|
|
|
|
- if ( mpAttachedGui->getParent() )
|
|
|
|
|
|
+ // Warn user & remove the GuiControl from the existing parent (if it has one).
|
|
|
|
+ if (attachedGui.mpAttachedCtrl->getParent())
|
|
{
|
|
{
|
|
- mpAttachedGui->getParent()->removeObject( mpAttachedGui );
|
|
|
|
|
|
+ Con::warnf("Warning: SceneObject::attachGui - GuiControl already has a parent GuiWindow!");
|
|
|
|
+ attachedGui.mpAttachedCtrl->getParent()->removeObject(attachedGui.mpAttachedCtrl);
|
|
}
|
|
}
|
|
|
|
|
|
- // Add it to the scene-window.
|
|
|
|
- mpAttachedGuiSceneWindow->addObject( mpAttachedGui );
|
|
|
|
|
|
+ // Add the GuiControl to the scene window.
|
|
|
|
+ attachedGui.mpAttachedSceneWindow->addObject(attachedGui.mpAttachedCtrl);
|
|
}
|
|
}
|
|
-
|
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
+ mAttachedCtrls.push_back(attachedGui);
|
|
|
|
+}
|
|
//-----------------------------------------------------------------------------
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
-void SceneObject::detachGui( void )
|
|
|
|
|
|
+void SceneObject::detachGui(void)
|
|
{
|
|
{
|
|
- // Unregister Gui Control Reference.
|
|
|
|
- if ( mpAttachedGui )
|
|
|
|
|
|
+ // Remove the last attached GUI.
|
|
|
|
+ if (mAttachedCtrls.size() > 0)
|
|
{
|
|
{
|
|
- // [neo, 5/7/2007 - #2997]
|
|
|
|
- // Changed to UNregisterReference was registerReference which would crash later
|
|
|
|
- mpAttachedGui->unregisterReference( (SimObject**)&mpAttachedGui );
|
|
|
|
- mpAttachedGui = NULL;
|
|
|
|
|
|
+ mAttachedCtrls.last().mpAttachedCtrl->unregisterReference((SimObject**)&mAttachedCtrls.last().mpAttachedCtrl);
|
|
|
|
+ mAttachedCtrls.last().mpAttachedSceneWindow->unregisterReference((SimObject**)&mAttachedCtrls.last().mpAttachedSceneWindow);
|
|
|
|
+
|
|
|
|
+ mAttachedCtrls.pop_back();
|
|
}
|
|
}
|
|
|
|
+}
|
|
|
|
|
|
- // Unregister Gui Control Reference.
|
|
|
|
- if ( mpAttachedGuiSceneWindow )
|
|
|
|
|
|
+void SceneObject::detachGui(GuiControl* pGuiControl)
|
|
|
|
+{
|
|
|
|
+ Vector<SceneObjectAttachedGUI>::iterator i;
|
|
|
|
+ for (i = mAttachedCtrls.begin(); i != mAttachedCtrls.end(); i++)
|
|
{
|
|
{
|
|
- mpAttachedGuiSceneWindow->registerReference( (SimObject**)&mpAttachedGuiSceneWindow );
|
|
|
|
- mpAttachedGuiSceneWindow = NULL;
|
|
|
|
|
|
+ if (i->mpAttachedCtrl == pGuiControl)
|
|
|
|
+ {
|
|
|
|
+ // Remove the attached GuiControl.
|
|
|
|
+ i->mpAttachedCtrl->unregisterReference((SimObject**)&i->mpAttachedCtrl);
|
|
|
|
+ i->mpAttachedSceneWindow->unregisterReference((SimObject**)&i->mpAttachedSceneWindow);
|
|
|
|
+
|
|
|
|
+ mAttachedCtrls.pop_back();
|
|
|
|
+
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // Warn user that no GuiControls were found.
|
|
|
|
+ Con::warnf("Warning: SceneObject::detachGui() - The GuiControl was not found!");
|
|
}
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
-void SceneObject::updateAttachedGui( void )
|
|
|
|
|
|
+void SceneObject::detachAllGuiControls(void)
|
|
|
|
+{
|
|
|
|
+ Vector<SceneObjectAttachedGUI>::iterator i;
|
|
|
|
+ for (i = mAttachedCtrls.begin(); i != mAttachedCtrls.end(); i++)
|
|
|
|
+ {
|
|
|
|
+ // Remove the attached GuiControl.
|
|
|
|
+ i->mpAttachedCtrl->unregisterReference((SimObject**)&i->mpAttachedCtrl);
|
|
|
|
+ i->mpAttachedSceneWindow->unregisterReference((SimObject**)&i->mpAttachedSceneWindow);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Clear all references to the attached GuiControls.
|
|
|
|
+ mAttachedCtrls.clear();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
|
+void SceneObject::updateAttachedGui(void)
|
|
{
|
|
{
|
|
// Debug Profiling.
|
|
// Debug Profiling.
|
|
PROFILE_SCOPE(SceneObject_updateAttachedGui);
|
|
PROFILE_SCOPE(SceneObject_updateAttachedGui);
|
|
|
|
|
|
- // Finish if either Gui Control or Window is invalid.
|
|
|
|
- if ( !mpAttachedGui || !mpAttachedGuiSceneWindow )
|
|
|
|
|
|
+ // Early-out if no GUIs are attached.
|
|
|
|
+ if (mAttachedCtrls.size() == 0)
|
|
return;
|
|
return;
|
|
|
|
|
|
- // Ignore if we're not in the scene that the scene-window is attached to.
|
|
|
|
- if ( getScene() != mpAttachedGuiSceneWindow->getScene() )
|
|
|
|
|
|
+ Vector<SceneObjectAttachedGUI>::iterator i;
|
|
|
|
+ for (i = mAttachedCtrls.begin(); i != mAttachedCtrls.end(); i++)
|
|
{
|
|
{
|
|
- // Warn.
|
|
|
|
- Con::warnf("SceneObject::updateAttachedGui() - SceneWindow is not attached to my Scene!");
|
|
|
|
- // Detach from GUI Control.
|
|
|
|
- detachGui();
|
|
|
|
- // Finish Here.
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
|
|
+ // Ignore if we're not in the scene that the GUI is attached to.
|
|
|
|
+ if (getScene() != i->mpAttachedSceneWindow->getScene())
|
|
|
|
+ {
|
|
|
|
+ // Warn.
|
|
|
|
+ Con::warnf("Warning: SceneObject::updateAttachedGui() - SceneWindow is not attached to the Scene!");
|
|
|
|
|
|
- // Calculate the GUI Controls' dimensions.
|
|
|
|
- Point2I topLeftI, extentI;
|
|
|
|
|
|
+ // Detach the control.
|
|
|
|
+ detachGui(i->mpAttachedCtrl);
|
|
|
|
|
|
- // Size Control?
|
|
|
|
- if ( mAttachedGuiSizeControl )
|
|
|
|
- {
|
|
|
|
- // Yes, so fetch Clip Rectangle; this forms the area we want to fix the Gui-Control to.
|
|
|
|
- const RectF objAABB = getAABBRectangle();
|
|
|
|
- // Fetch Top-Left.
|
|
|
|
- Vector2 upperLeft = Vector2( objAABB.point.x, objAABB.point.y + objAABB.extent.y );
|
|
|
|
- Vector2 lowerRight = Vector2( objAABB.point.x + objAABB.extent.x, objAABB.point.y );
|
|
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
|
|
- // Convert Scene to Window Coordinates.
|
|
|
|
- mpAttachedGuiSceneWindow->sceneToWindowPoint( upperLeft, upperLeft );
|
|
|
|
- mpAttachedGuiSceneWindow->sceneToWindowPoint( lowerRight, lowerRight );
|
|
|
|
- // Convert Control Dimensions.
|
|
|
|
- topLeftI.set( S32(upperLeft.x), S32(upperLeft.y) );
|
|
|
|
- extentI.set( S32(lowerRight.x-upperLeft.x), S32(lowerRight.y-upperLeft.y) );
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- // No, so center GUI-Control on objects position but don't resize it.
|
|
|
|
|
|
+ // Calculate the GUI Controls' dimensions.
|
|
|
|
+ Point2I topLeftI, extentI;
|
|
|
|
|
|
- // Calculate Position from World Clip.
|
|
|
|
- const RectF clipRectangle = getAABBRectangle();
|
|
|
|
- // Calculate center position.
|
|
|
|
- const Vector2 centerPosition = clipRectangle.point + Vector2(clipRectangle.len_x()*0.5f, clipRectangle.len_y()*0.5f);
|
|
|
|
|
|
+ // Size Control?
|
|
|
|
+ if (i->mAutoSize)
|
|
|
|
+ {
|
|
|
|
+ // Yes, so fetch Clip Rectangle; this forms the area we want to fix the Gui-Control to.
|
|
|
|
+ const RectF objAABB = getAABBRectangle();
|
|
|
|
+ // Fetch Top-Left.
|
|
|
|
+ Vector2 upperLeft = Vector2(objAABB.point.x, objAABB.point.y + objAABB.extent.y);
|
|
|
|
+ Vector2 lowerRight = Vector2(objAABB.point.x + objAABB.extent.x, objAABB.point.y);
|
|
|
|
+
|
|
|
|
+ // Convert Scene to Window Coordinates.
|
|
|
|
+ i->mpAttachedSceneWindow->sceneToWindowPoint(upperLeft, upperLeft);
|
|
|
|
+ i->mpAttachedSceneWindow->sceneToWindowPoint(lowerRight, lowerRight);
|
|
|
|
+
|
|
|
|
+ // Convert Control Dimensions.
|
|
|
|
+ topLeftI.set(S32(upperLeft.x), S32(upperLeft.y));
|
|
|
|
+ extentI.set(S32(lowerRight.x - upperLeft.x), S32(lowerRight.y - upperLeft.y));
|
|
|
|
+
|
|
|
|
+ // Add offset
|
|
|
|
+ topLeftI.x += static_cast<S32>(i->mAttachedOffset.x);
|
|
|
|
+ topLeftI.y += static_cast<S32>(i->mAttachedOffset.y);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ // No, so center GUI-Control on objects position but don't resize it.
|
|
|
|
|
|
- // Convert Scene to Window Coordinates.
|
|
|
|
- Vector2 positionI;
|
|
|
|
- mpAttachedGuiSceneWindow->sceneToWindowPoint( centerPosition, positionI );
|
|
|
|
- // Fetch Control Extents (which don't change here).
|
|
|
|
- extentI = mpAttachedGui->getExtent();
|
|
|
|
- // Calculate new top-left.
|
|
|
|
- topLeftI.set( S32(positionI.x-extentI.x/2), S32(positionI.y-extentI.y/2) );
|
|
|
|
- }
|
|
|
|
|
|
+ // Calculate Position from World Clip.
|
|
|
|
+ const RectF clipRectangle = getAABBRectangle();
|
|
|
|
+ // Calculate center position.
|
|
|
|
+ const Vector2 centerPosition = clipRectangle.point + Vector2(clipRectangle.len_x()*0.5f, clipRectangle.len_y()*0.5f);
|
|
|
|
+
|
|
|
|
+ // Convert Scene to Window Coordinates.
|
|
|
|
+ Vector2 positionI;
|
|
|
|
+ i->mpAttachedSceneWindow->sceneToWindowPoint(centerPosition, positionI);
|
|
|
|
|
|
- // Set Control Dimensions.
|
|
|
|
- mpAttachedGui->resize( topLeftI, extentI );
|
|
|
|
|
|
+ // Fetch Control Extents (which don't change here).
|
|
|
|
+ extentI = i->mpAttachedCtrl->getExtent();
|
|
|
|
+
|
|
|
|
+ // Calculate new top-left.
|
|
|
|
+ topLeftI.set(S32(positionI.x - extentI.x / 2), S32(positionI.y - extentI.y / 2));
|
|
|
|
+
|
|
|
|
+ // Add offset
|
|
|
|
+ topLeftI.x += static_cast<S32>(i->mAttachedOffset.x);
|
|
|
|
+ topLeftI.y += static_cast<S32>(i->mAttachedOffset.y);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Set Control Dimensions.
|
|
|
|
+ i->mpAttachedCtrl->resize(topLeftI, extentI);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
//-----------------------------------------------------------------------------
|