Browse Source

Better focus, browser creation, sizing, etc

Josh Engebretson 10 years ago
parent
commit
102702d56c

+ 30 - 12
Source/AtomicWebView/UIWebView.cpp

@@ -60,6 +60,31 @@ public:
         data[32] = 0; data[33] = color; data[34] = 0; data[35] = 1;
         data[32] = 0; data[33] = color; data[34] = 0; data[35] = 1;
     }
     }
 
 
+    void OnProcess()
+    {
+        TBWidget::OnProcess();
+
+        if (webView_.Null())
+            return;
+
+        if (!browserCreated_)
+        {
+            browserCreated_ = true;
+            TBRect rect = GetRect();
+            webView_->webClient_->CreateBrowser(webView_->initialURL_, rect.w, rect.h);
+        }
+
+    }
+
+    void OnResized(int oldW, int oldH)
+    {
+        if (webView_.Null())
+            return;
+
+        TBRect rect = GetRect();
+        webView_->webClient_->SetSize(rect.w, rect.h);
+    }
+
     void OnPaint(const PaintProps &paint_props)
     void OnPaint(const PaintProps &paint_props)
     {
     {
         if (webView_.Null())
         if (webView_.Null())
@@ -69,22 +94,10 @@ public:
         rect.x = rect.y = 0;
         rect.x = rect.y = 0;
         ConvertToRoot(rect.x, rect.y);
         ConvertToRoot(rect.x, rect.y);
 
 
-        IntRect size = webView_->GetRect();
-
         float* data = &vertexData_[0];
         float* data = &vertexData_[0];
 
 
         UI* ui = webView_->GetSubsystem<UI>();
         UI* ui = webView_->GetSubsystem<UI>();
 
 
-        if (!browserCreated_)
-        {
-            browserCreated_ = true;
-            webView_->webClient_->CreateBrowser(webView_->initialURL_, rect.w, rect.h);
-            // start focused
-            webView_->webClient_->SendFocusEvent(true);
-        }
-
-        webView_->webClient_->SetSize(rect.w, rect.h);
-
         float color;
         float color;
         float fopacity = GetOpacity() * ui->GetRenderer()->GetOpacity();
         float fopacity = GetOpacity() * ui->GetRenderer()->GetOpacity();
         unsigned char opacity = (unsigned char) (fopacity* 255.0f);
         unsigned char opacity = (unsigned char) (fopacity* 255.0f);
@@ -311,6 +324,11 @@ bool UIWebView::OnEvent(const TBWidgetEvent &ev)
     return UIWidget::OnEvent(ev);
     return UIWidget::OnEvent(ev);
 }
 }
 
 
+void UIWebView::OnFocusChanged(bool focused)
+{
+    webClient_->SendFocusEvent(focused);
+}
+
 WebTexture2D* UIWebView::GetWebTexture2D() const
 WebTexture2D* UIWebView::GetWebTexture2D() const
 {
 {
     return webTexture_;
     return webTexture_;

+ 3 - 0
Source/AtomicWebView/UIWebView.h

@@ -53,8 +53,11 @@ public:
 protected:
 protected:
 
 
     bool OnEvent(const tb::TBWidgetEvent &ev);
     bool OnEvent(const tb::TBWidgetEvent &ev);
+    void OnFocusChanged(bool focused);
     bool HandleKeyEvent(const tb::TBWidgetEvent &ev, bool keyDown);
     bool HandleKeyEvent(const tb::TBWidgetEvent &ev, bool keyDown);
 
 
+
+
 private:
 private:
 
 
     void HandleKeyDown(StringHash eventType, VariantMap& eventData);
     void HandleKeyDown(StringHash eventType, VariantMap& eventData);

+ 11 - 1
Source/AtomicWebView/WebTexture2D.cpp

@@ -326,7 +326,17 @@ void WebTexture2D::SetSize(int width, int height)
     if (width == texture_->GetWidth() && height == texture_->GetHeight())
     if (width == texture_->GetWidth() && height == texture_->GetHeight())
         return;
         return;
 
 
-    texture_->SetSize(width, height, Graphics::GetRGBAFormat(), TEXTURE_DYNAMIC);
+    // 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());
+    }
+    else
+    {
+        LOGERRORF("Unable to set WebTexture2D size to %i x %i", width, height);
+    }
 
 
 }
 }