Browse Source

Support setting WebTexture2D clear color

Josh Engebretson 10 years ago
parent
commit
f04c03fc9e

+ 3 - 4
Source/AtomicEditor/Editors/JSResourceEditor.cpp

@@ -22,6 +22,7 @@
 #include <AtomicWebView/UIWebView.h>
 #include <AtomicWebView/WebClient.h>
 #include <AtomicWebView/WebMessageHandler.h>
+#include <AtomicWebView/WebTexture2D.h>
 
 #include "JSResourceEditor.h"
 
@@ -63,16 +64,14 @@ JSResourceEditor ::JSResourceEditor(Context* context, const String &fullpath, UI
     messageHandler_ = new WebMessageHandler(context_);
     webClient_->AddMessageHandler(messageHandler_);
 
+    webView_->GetWebTexture2D()->SetClearColor(Color(.23f, .23f, .23f, 1));
+
     SubscribeToEvent(webClient_, E_WEBVIEWLOADEND, HANDLER(JSResourceEditor, HandleWebViewLoadEnd));
     SubscribeToEvent(messageHandler_, E_WEBMESSAGE, HANDLER(JSResourceEditor, HandleWebMessage));
 
 
     c->AddChild(webView_->GetInternalWidget());
 
-    // FIXME: Set the size at the end of setup, so all children are updated accordingly
-    // future size changes will be handled automatically
-    IntRect rect = container_->GetContentRoot()->GetRect();
-    rootContentWidget_->SetSize(rect.Width(), rect.Height());
 }
 
 JSResourceEditor::~JSResourceEditor()

+ 10 - 4
Source/AtomicWebView/WebTexture2D.cpp

@@ -290,7 +290,7 @@ private:
 
 };
 
-WebTexture2D::WebTexture2D(Context* context) : WebRenderHandler(context)
+WebTexture2D::WebTexture2D(Context* context) : WebRenderHandler(context), clearColor_(Color::WHITE)
 {
     d_ = new WebTexture2DPrivate(this);
     d_->AddRef();
@@ -329,9 +329,15 @@ void WebTexture2D::SetSize(int width, int height)
     // initialize to white (color should probably be an option)
     if (texture_->SetSize(width, height, Graphics::GetRGBAFormat(), TEXTURE_DYNAMIC))
     {
-        SharedArrayPtr<unsigned char> whitedata(new unsigned char[width * height * 4]);
-        memset(whitedata.Get(), 255, width * height * 4);
-        texture_->SetData(0, 0, 0, width, height, whitedata.Get());
+        SharedArrayPtr<unsigned> cleardata(new unsigned[width * height]);
+        unsigned color = clearColor_.ToUInt();
+        unsigned* ptr = cleardata.Get();
+        for (unsigned i = 0; i < width * height; i++, ptr++)
+        {
+            *ptr = color;
+        }
+
+        texture_->SetData(0, 0, 0, width, height, cleardata.Get());
     }
     else
     {

+ 8 - 0
Source/AtomicWebView/WebTexture2D.h

@@ -32,15 +32,23 @@ public:
     int GetHeight() const;
     /// Get the Texture2D associated with the WebTexture2D
     Texture2D* GetTexture2D() const { return texture_; }
+    /// get the clear color for the WebTexture
+    const Color& GetClearColor() const { return clearColor_; }
+
 
     /// Set the dimensions of the texture
     void SetSize(int width, int height);
 
+    /// Set the clear color for the WebTexture
+    void SetClearColor(const Color& color) { clearColor_ = color; }
+
     /// Get the (internal) CEFRenderHandler
     CefRenderHandler* GetCEFRenderHandler();
 
 private:
 
+    Color clearColor_;
+
     SharedPtr<Texture2D> texture_;
 
     WebTexture2DPrivate* d_;