Browse Source

- Moved the background color from the Scene to the SceneWindow. This seems more appropriate, especially in a multi-window environment where you want to potentially clear the "camera" view rather than clearing the Scene itself.
- Reverted the Canvas to default to clearing itself.
- The Sandbox now changes the Canvas color and not the SceneWindow.

MelvMay-GG 12 years ago
parent
commit
474d803

+ 27 - 5
engine/source/2d/gui/SceneWindow.cc

@@ -76,6 +76,8 @@ SceneWindow::SceneWindow() :    mpScene(NULL),
                                 mWindowDirty(true),
                                 mWindowDirty(true),
                                 mRenderLayerMask(MASK_ALL),
                                 mRenderLayerMask(MASK_ALL),
                                 mRenderGroupMask(MASK_ALL),
                                 mRenderGroupMask(MASK_ALL),
+                                mBackgroundColor( "Black" ),
+                                mUseBackgroundColor(false),   
                                 mCameraInterpolationMode(SIGMOID),
                                 mCameraInterpolationMode(SIGMOID),
                                 mMaxQueueItems(64),
                                 mMaxQueueItems(64),
                                 mCameraTransitionTime(2.0f),
                                 mCameraTransitionTime(2.0f),
@@ -163,12 +165,16 @@ void SceneWindow::onRemove()
 void SceneWindow::initPersistFields()
 void SceneWindow::initPersistFields()
 {
 {
     // Call Parent.
     // Call Parent.
-   Parent::initPersistFields();
+    Parent::initPersistFields();
 
 
-   // Add Fields.
-   addField( "lockMouse",               TypeBool, Offset(mLockMouse, SceneWindow) );
-   addField( "UseWindowInputEvents",    TypeBool, Offset(mUseWindowInputEvents, SceneWindow) );
-   addField( "UseObjectInputEvents",    TypeBool, Offset(mUseObjectInputEvents, SceneWindow) );
+    // Add Fields.
+    addField( "lockMouse",               TypeBool, Offset(mLockMouse, SceneWindow) );
+    addField( "UseWindowInputEvents",    TypeBool, Offset(mUseWindowInputEvents, SceneWindow) );
+    addField( "UseObjectInputEvents",    TypeBool, Offset(mUseObjectInputEvents, SceneWindow) );
+
+    // Background color.
+    addField("UseBackgroundColor", TypeBool, Offset(mUseBackgroundColor, SceneWindow), &writeUseBackgroundColor, "" );
+    addField("BackgroundColor", TypeColorF, Offset(mBackgroundColor, SceneWindow), &writeBackgroundColor, "" );
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
@@ -1615,6 +1621,22 @@ void SceneWindow::onRender( Point2I offset, const RectI& updateRect )
         &debugStats,
         &debugStats,
         this );
         this );
 
 
+    // Clear the background color if requested.
+    if ( mUseBackgroundColor )
+    {
+        // Enable the scissor.
+        const RectI& clipRect = dglGetClipRect();
+        glEnable(GL_SCISSOR_TEST );
+        glScissor( clipRect.point.x, Platform::getWindowSize().y - (clipRect.point.y + clipRect.extent.y), clipRect.len_x(), clipRect.len_y() );
+
+        // Clear the background.
+        glClearColor( mBackgroundColor.red, mBackgroundColor.green, mBackgroundColor.blue, mBackgroundColor.alpha );
+        glClear(GL_COLOR_BUFFER_BIT);
+
+        // Disable the scissor.
+        glDisable( GL_SCISSOR_TEST );
+    }
+
     // Render View.
     // Render View.
     pScene->sceneRender( &sceneRenderState );
     pScene->sceneRender( &sceneRenderState );
 
 

+ 12 - 0
engine/source/2d/gui/SceneWindow.h

@@ -94,6 +94,10 @@ private:
     Point2F             mPreTickPosition;
     Point2F             mPreTickPosition;
     Point2F             mPostTickPosition;
     Point2F             mPostTickPosition;
 
 
+    /// Background color.
+    ColorF                      mBackgroundColor;
+    bool                        mUseBackgroundColor;
+
     /// Camera Attachment.
     /// Camera Attachment.
     bool                mCameraMounted;
     bool                mCameraMounted;
     SceneObject*        mpMountedTo;
     SceneObject*        mpMountedTo;
@@ -198,6 +202,12 @@ public:
     Vector2 getMousePosition( void );
     Vector2 getMousePosition( void );
     void setMousePosition( const Vector2& mousePosition );
     void setMousePosition( const Vector2& mousePosition );
 
 
+    /// Background color.
+    inline void             setBackgroundColor( const ColorF& backgroundColor ) { mBackgroundColor = backgroundColor; }
+    inline const ColorF&    getBackgroundColor( void ) const            { return mBackgroundColor; }
+    inline void             setUseBackgroundColor( const bool useBackgroundColor ) { mUseBackgroundColor = useBackgroundColor; }
+    inline bool             getUseBackgroundColor( void ) const         { return mUseBackgroundColor; }
+
     /// Input.
     /// Input.
     void setObjectInputEventFilter( const U32 groupMask, const U32 layerMask, const bool useInvisible = false );
     void setObjectInputEventFilter( const U32 groupMask, const U32 layerMask, const bool useInvisible = false );
     void setObjectInputEventGroupFilter( const U32 groupMask );
     void setObjectInputEventGroupFilter( const U32 groupMask );
@@ -317,6 +327,8 @@ protected:
     static bool writeLockMouse( void* obj, StringTableEntry pFieldName ) { return static_cast<SceneWindow*>(obj)->mLockMouse == true; }
     static bool writeLockMouse( void* obj, StringTableEntry pFieldName ) { return static_cast<SceneWindow*>(obj)->mLockMouse == true; }
     static bool writeUseWindowInputEvents( void* obj, StringTableEntry pFieldName ) { return static_cast<SceneWindow*>(obj)->mUseWindowInputEvents == false; }
     static bool writeUseWindowInputEvents( void* obj, StringTableEntry pFieldName ) { return static_cast<SceneWindow*>(obj)->mUseWindowInputEvents == false; }
     static bool writeUseObjectInputEvents( void* obj, StringTableEntry pFieldName ) { return static_cast<SceneWindow*>(obj)->mUseObjectInputEvents == true; }
     static bool writeUseObjectInputEvents( void* obj, StringTableEntry pFieldName ) { return static_cast<SceneWindow*>(obj)->mUseObjectInputEvents == true; }
+    static bool writeBackgroundColor( void* obj, StringTableEntry pFieldName )      { return static_cast<SceneWindow*>(obj)->mUseBackgroundColor == true; }
+    static bool writeUseBackgroundColor( void* obj, StringTableEntry pFieldName )   { return static_cast<SceneWindow*>(obj)->mUseBackgroundColor == true; }
 };
 };
 
 
 #endif // _SCENE_WINDOW_H_
 #endif // _SCENE_WINDOW_H_

+ 120 - 1
engine/source/2d/gui/SceneWindow_ScriptBinding.h

@@ -850,7 +850,126 @@ ConsoleMethod(SceneWindow, getRenderGroupMask, S32, 2, 2, "() - Gets the group m
               "@returns The bit mask corresponding to the groups which are to be rendered")
               "@returns The bit mask corresponding to the groups which are to be rendered")
 {
 {
    return object->getRenderGroupMask();
    return object->getRenderGroupMask();
-} 
+}
+
+//-----------------------------------------------------------------------------
+
+ConsoleMethod(SceneWindow, setBackgroundColor, void, 3, 6,  "(float red, float green, float blue, [float alpha = 1.0]) or ( stockColorName )  - Sets the background color for the scene."
+                                                            "@param red The red value.\n"
+                                                            "@param green The green value.\n"
+                                                            "@param blue The blue value.\n"
+                                                            "@param alpha The alpha value.\n"
+                                                            "@return No return Value.")
+{
+    // The colors.
+    F32 red;
+    F32 green;
+    F32 blue;
+    F32 alpha = 1.0f;
+
+    // Space separated.
+    if (argc == 3)
+    {
+        // Grab the element count.
+        const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
+
+        // Has a single argument been specified?
+        if ( elementCount == 1 )
+        {
+            object->setDataField( StringTable->insert("BackgroundColor"), NULL, argv[2] );
+            return;
+        }
+
+        // ("R G B [A]")
+        if ((elementCount == 3) || (elementCount == 4))
+        {
+            // Extract the color.
+            red   = dAtof(Utility::mGetStringElement(argv[2], 0));
+            green = dAtof(Utility::mGetStringElement(argv[2], 1));
+            blue  = dAtof(Utility::mGetStringElement(argv[2], 2));
+
+            // Grab the alpha if it's there.
+            if (elementCount > 3)
+                alpha = dAtof(Utility::mGetStringElement(argv[2], 3));
+        }
+
+        // Invalid.
+        else
+        {
+            Con::warnf("SceneWindow::setBackgroundColor() - Invalid Number of parameters!");
+            return;
+        }
+    }
+
+    // (R, G, B)
+    else if (argc >= 5)
+    {
+        red   = dAtof(argv[2]);
+        green = dAtof(argv[3]);
+        blue  = dAtof(argv[4]);
+
+        // Grab the alpha if it's there.
+        if (argc > 5)
+            alpha = dAtof(argv[5]);
+    }
+
+    // Invalid.
+    else
+    {
+        Con::warnf("SceneWindow::setBackgroundColor() - Invalid Number of parameters!");
+        return;
+    }
+
+    // Set background color.
+    object->setBackgroundColor(ColorF(red, green, blue, alpha) );
+}
+
+//-----------------------------------------------------------------------------
+
+ConsoleMethod(SceneWindow, getBackgroundColor, const char*, 2, 2,   "Gets the background color for the scene.\n"
+                                                                    "@return (float red / float green / float blue / float alpha) The background color for the scene.")
+{
+    // Get the background color.
+    const ColorF& color = object->getBackgroundColor();
+
+    // Fetch color name.
+    StringTableEntry colorName = StockColor::name( color );
+
+    // Return the color name if it's valid.
+    if ( colorName != StringTable->EmptyString )
+        return colorName;
+
+    // Create Returnable Buffer.
+    char* pBuffer = Con::getReturnBuffer(64);
+
+    // Format Buffer.
+    dSprintf(pBuffer, 64, "%g %g %g %g", color.red, color.green, color.blue, color.alpha );
+
+    // Return buffer.
+    return pBuffer;
+}
+
+//-----------------------------------------------------------------------------
+
+ConsoleMethod(SceneWindow, setUseBackgroundColor, void, 3, 3,   "Sets whether to use the scene background color or not.\n"
+                                                                "@param useBackgroundColor Whether to use the scene background color or not.\n"
+                                                                "@return No return value." )
+{
+    // Fetch flag.
+    const bool useBackgroundColor = dAtob(argv[2]);
+
+    // Set the flag.
+    object->setUseBackgroundColor( useBackgroundColor );
+}
+
+//-----------------------------------------------------------------------------
+
+ConsoleMethod(SceneWindow, getUseBackgroundColor, bool, 2, 2,   "Gets whether the scene background color is in use or not.\n"
+                                                                "@return Whether the scene background color is in use or not." )
+{
+    // Get the flag.
+    return object->getUseBackgroundColor();
+}
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 
 

+ 0 - 24
engine/source/2d/scene/Scene.cc

@@ -167,10 +167,6 @@ Scene::Scene() :
     /// Window rendering.
     /// Window rendering.
     mpCurrentRenderWindow(NULL),
     mpCurrentRenderWindow(NULL),
     
     
-    /// Background color.
-    mBackgroundColor( 0.0f, 0.0f, 0.0f, 0.0f ),
-    mUseBackgroundColor(false),   
-
     /// Miscellaneous.
     /// Miscellaneous.
     mIsEditorScene(0),
     mIsEditorScene(0),
     mUpdateCallback(false),
     mUpdateCallback(false),
@@ -393,10 +389,6 @@ void Scene::initPersistFields()
     addField("VelocityIterations", TypeS32, Offset(mVelocityIterations, Scene), &writeVelocityIterations, "" );
     addField("VelocityIterations", TypeS32, Offset(mVelocityIterations, Scene), &writeVelocityIterations, "" );
     addField("PositionIterations", TypeS32, Offset(mPositionIterations, Scene), &writePositionIterations, "" );
     addField("PositionIterations", TypeS32, Offset(mPositionIterations, Scene), &writePositionIterations, "" );
 
 
-    // Background color.
-    addField("UseBackgroundColor", TypeBool, Offset(mUseBackgroundColor, Scene), &writeUseBackgroundColor, "" );
-    addField("BackgroundColor", TypeColorF, Offset(mBackgroundColor, Scene), &writeBackgroundColor, "" );
-
     // Layer sort modes.
     // Layer sort modes.
     char buffer[64];
     char buffer[64];
     for ( U32 n = 0; n < MAX_LAYERS_SUPPORTED; n++ )
     for ( U32 n = 0; n < MAX_LAYERS_SUPPORTED; n++ )
@@ -1078,22 +1070,6 @@ void Scene::sceneRender( const SceneRenderState* pSceneRenderState )
     // Set batch renderer wireframe mode.
     // Set batch renderer wireframe mode.
     mBatchRenderer.setWireframeMode( getDebugMask() & SCENE_DEBUG_WIREFRAME_RENDER );
     mBatchRenderer.setWireframeMode( getDebugMask() & SCENE_DEBUG_WIREFRAME_RENDER );
 
 
-    // Clear the background color if requested.
-    if ( mUseBackgroundColor )
-    {
-        // Enable the scissor.
-        const RectI& clipRect = dglGetClipRect();
-        glEnable(GL_SCISSOR_TEST );
-        glScissor( clipRect.point.x, Platform::getWindowSize().y - (clipRect.point.y + clipRect.extent.y), clipRect.len_x(), clipRect.len_y() );
-
-        // Clear the background.
-        glClearColor( mBackgroundColor.red, mBackgroundColor.green, mBackgroundColor.blue, mBackgroundColor.alpha );
-        glClear(GL_COLOR_BUFFER_BIT);
-
-        // Disable the scissor.
-        glDisable( GL_SCISSOR_TEST );
-    }
-
     // Debug Profiling.
     // Debug Profiling.
     PROFILE_START(Scene_RenderSceneVisibleQuery);
     PROFILE_START(Scene_RenderSceneVisibleQuery);
 
 

+ 0 - 12
engine/source/2d/scene/Scene.h

@@ -242,10 +242,6 @@ private:
     /// Window rendering.
     /// Window rendering.
     SceneWindow*                mpCurrentRenderWindow;
     SceneWindow*                mpCurrentRenderWindow;
 
 
-    /// Background color.
-    ColorF                      mBackgroundColor;
-    bool                        mUseBackgroundColor;
-
     /// Window attachments.
     /// Window attachments.
     SimSet                      mAttachedSceneWindows;
     SimSet                      mAttachedSceneWindows;
 
 
@@ -334,12 +330,6 @@ public:
     inline void             setPositionIterations( const S32 iterations ) { mPositionIterations = iterations; }
     inline void             setPositionIterations( const S32 iterations ) { mPositionIterations = iterations; }
     inline S32              getPositionIterations( void ) const         { return mPositionIterations; }
     inline S32              getPositionIterations( void ) const         { return mPositionIterations; }
 
 
-    /// Background color.
-    inline void             setBackgroundColor( const ColorF& backgroundColor ) { mBackgroundColor = backgroundColor; }
-    inline const ColorF&    getBackgroundColor( void ) const            { return mBackgroundColor; }
-    inline void             setUseBackgroundColor( const bool useBackgroundColor ) { mUseBackgroundColor = useBackgroundColor; }
-    inline bool             getUseBackgroundColor( void ) const         { return mUseBackgroundColor; }
-
     /// Scene occupancy.
     /// Scene occupancy.
     void                    clearScene( bool deleteObjects = true );
     void                    clearScene( bool deleteObjects = true );
     void                    addToScene( SceneObject* pSceneObject );
     void                    addToScene( SceneObject* pSceneObject );
@@ -676,8 +666,6 @@ protected:
     static bool writeGravity( void* obj, StringTableEntry pFieldName )              { return Vector2(static_cast<Scene*>(obj)->getGravity()).notEqual( Vector2::getZero() ); }
     static bool writeGravity( void* obj, StringTableEntry pFieldName )              { return Vector2(static_cast<Scene*>(obj)->getGravity()).notEqual( Vector2::getZero() ); }
     static bool writeVelocityIterations( void* obj, StringTableEntry pFieldName )   { return static_cast<Scene*>(obj)->getVelocityIterations() != 8; }
     static bool writeVelocityIterations( void* obj, StringTableEntry pFieldName )   { return static_cast<Scene*>(obj)->getVelocityIterations() != 8; }
     static bool writePositionIterations( void* obj, StringTableEntry pFieldName )   { return static_cast<Scene*>(obj)->getPositionIterations() != 3; }
     static bool writePositionIterations( void* obj, StringTableEntry pFieldName )   { return static_cast<Scene*>(obj)->getPositionIterations() != 3; }
-    static bool writeBackgroundColor( void* obj, StringTableEntry pFieldName )      { return static_cast<Scene*>(obj)->mUseBackgroundColor; }
-    static bool writeUseBackgroundColor( void* obj, StringTableEntry pFieldName )   { return static_cast<Scene*>(obj)->mUseBackgroundColor; }
 
 
     static bool writeLayerSortMode( void* obj, StringTableEntry pFieldName )
     static bool writeLayerSortMode( void* obj, StringTableEntry pFieldName )
     {
     {

+ 0 - 119
engine/source/2d/scene/Scene_ScriptBinding.h

@@ -100,125 +100,6 @@ ConsoleMethod(Scene, getPositionIterations, S32, 2, 2,  "() Gets the number of p
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 
 
-ConsoleMethod(Scene, setBackgroundColor, void, 3, 6,   "(float red, float green, float blue, [float alpha = 1.0]) or ( stockColorName )  - Sets the background color for the scene."
-                                                        "@param red The red value.\n"
-                                                        "@param green The green value.\n"
-                                                        "@param blue The blue value.\n"
-                                                        "@param alpha The alpha value.\n"
-                                                        "@return No return Value.")
-{
-    // The colors.
-    F32 red;
-    F32 green;
-    F32 blue;
-    F32 alpha = 1.0f;
-
-    // Space separated.
-    if (argc == 3)
-    {
-        // Grab the element count.
-        const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
-
-        // Has a single argument been specified?
-        if ( elementCount == 1 )
-        {
-            object->setDataField( StringTable->insert("BackgroundColor"), NULL, argv[2] );
-            return;
-        }
-
-        // ("R G B [A]")
-        if ((elementCount == 3) || (elementCount == 4))
-        {
-            // Extract the color.
-            red   = dAtof(Utility::mGetStringElement(argv[2], 0));
-            green = dAtof(Utility::mGetStringElement(argv[2], 1));
-            blue  = dAtof(Utility::mGetStringElement(argv[2], 2));
-
-            // Grab the alpha if it's there.
-            if (elementCount > 3)
-                alpha = dAtof(Utility::mGetStringElement(argv[2], 3));
-        }
-
-        // Invalid.
-        else
-        {
-            Con::warnf("Scene::setBackgroundColor() - Invalid Number of parameters!");
-            return;
-        }
-    }
-
-    // (R, G, B)
-    else if (argc >= 5)
-    {
-        red   = dAtof(argv[2]);
-        green = dAtof(argv[3]);
-        blue  = dAtof(argv[4]);
-
-        // Grab the alpha if it's there.
-        if (argc > 5)
-            alpha = dAtof(argv[5]);
-    }
-
-    // Invalid.
-    else
-    {
-        Con::warnf("Scene::setBackgroundColor() - Invalid Number of parameters!");
-        return;
-    }
-
-    // Set background color.
-    object->setBackgroundColor(ColorF(red, green, blue, alpha) );
-}
-
-//-----------------------------------------------------------------------------
-
-ConsoleMethod(Scene, getBackgroundColor, const char*, 2, 2, "Gets the background color for the scene.\n"
-                                                                "@return (float red / float green / float blue / float alpha) The background color for the scene.")
-{
-    // Get the background color.
-    const ColorF& color = object->getBackgroundColor();
-
-    // Fetch color name.
-    StringTableEntry colorName = StockColor::name( color );
-
-    // Return the color name if it's valid.
-    if ( colorName != StringTable->EmptyString )
-        return colorName;
-
-    // Create Returnable Buffer.
-    char* pBuffer = Con::getReturnBuffer(64);
-
-    // Format Buffer.
-    dSprintf(pBuffer, 64, "%g %g %g %g", color.red, color.green, color.blue, color.alpha );
-
-    // Return buffer.
-    return pBuffer;
-}
-
-//-----------------------------------------------------------------------------
-
-ConsoleMethod(Scene, setUseBackgroundColor, void, 3, 3, "Sets whether to use the scene background color or not.\n"
-                                                        "@param useBackgroundColor Whether to use the scene background color or not.\n"
-                                                        "@return No return value." )
-{
-    // Fetch flag.
-    const bool useBackgroundColor = dAtob(argv[2]);
-
-    // Set the flag.
-    object->setUseBackgroundColor( useBackgroundColor );
-}
-
-//-----------------------------------------------------------------------------
-
-ConsoleMethod(Scene, getUseBackgroundColor, bool, 2, 2, "Gets whether the scene background color is in use or not.\n"
-                                                        "@return Whether the scene background color is in use or not." )
-{
-    // Get the flag.
-    return object->getUseBackgroundColor();
-}
-
-//-----------------------------------------------------------------------------
-
 ConsoleMethod(Scene, add, void, 3, 3,   "(sceneObject) Add the SceneObject to the scene.\n"
 ConsoleMethod(Scene, add, void, 3, 3,   "(sceneObject) Add the SceneObject to the scene.\n"
                                         "@param sceneObject The SceneObject to add to the scene.\n"
                                         "@param sceneObject The SceneObject to add to the scene.\n"
                                         "@return No return value.")
                                         "@return No return value.")

+ 1 - 1
modules/AppCore/1/main.cs

@@ -33,7 +33,7 @@ function AppCore::create( %this )
     
     
     // Set the canvas color
     // Set the canvas color
     Canvas.BackgroundColor = "CornflowerBlue";
     Canvas.BackgroundColor = "CornflowerBlue";
-    Canvas.UseBackgroundColor = false;
+    Canvas.UseBackgroundColor = true;
     
     
     // Initialize audio
     // Initialize audio
     initializeOpenAL();
     initializeOpenAL();

+ 4 - 4
modules/Sandbox/1/scripts/toolbox.cs

@@ -222,8 +222,8 @@ function BackgroundColorSelectList::onSelect(%this)
         return;
         return;
             
             
     // Set the scene color.
     // Set the scene color.
-    SandboxScene.BackgroundColor = getStockColorName($activeBackgroundColor);
-    SandboxScene.UseBackgroundColor = true;
+    Canvas.BackgroundColor = getStockColorName($activeBackgroundColor);
+    Canvas.UseBackgroundColor = true;
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
@@ -296,8 +296,8 @@ function updateToolboxOptions()
         return;
         return;
         
         
     // Set the scene color.
     // Set the scene color.
-    SandboxScene.BackgroundColor = getStockColorName($activeBackgroundColor);
-    SandboxScene.UseBackgroundColor = true;        
+    Canvas.BackgroundColor = getStockColorName($activeBackgroundColor);
+    Canvas.UseBackgroundColor = true;        
        
        
     // Set option.
     // Set option.
     if ( $pref::Sandbox::metricsOption )
     if ( $pref::Sandbox::metricsOption )