Browse Source

Working on WebView, adding script package, etc

Josh Engebretson 10 years ago
parent
commit
dd3a350dba

+ 1 - 0
Build/CIScripts/BuildMac.js

@@ -56,6 +56,7 @@ namespace('build', function() {
       atomicTool + " bind " + bcommon.atomicRoot + " Script/Packages/ToolCore/ MACOSX",
       atomicTool + " bind " + bcommon.atomicRoot + " Script/Packages/ToolCore/ MACOSX",
       atomicTool + " bind " + bcommon.atomicRoot + " Script/Packages/Editor/ MACOSX",
       atomicTool + " bind " + bcommon.atomicRoot + " Script/Packages/Editor/ MACOSX",
       atomicTool + " bind " + bcommon.atomicRoot + " Script/Packages/AtomicNET/ MACOSX",
       atomicTool + " bind " + bcommon.atomicRoot + " Script/Packages/AtomicNET/ MACOSX",
+      atomicTool + " bind " + bcommon.atomicRoot + " Script/Packages/AtomicWebView/ MACOSX",
       "cmake -DATOMIC_DEV_BUILD=0 -G Xcode ../../../../",
       "cmake -DATOMIC_DEV_BUILD=0 -G Xcode ../../../../",
       "xcodebuild -target AtomicEditor -configuration Release -parallelizeTargets -jobs 4"
       "xcodebuild -target AtomicEditor -configuration Release -parallelizeTargets -jobs 4"
     ];
     ];

+ 8 - 0
Script/Packages/WebView/Package.json

@@ -0,0 +1,8 @@
+
+{
+  "name" : "WebView",
+  "namespace" : "Atomic",
+  "dependencies" : ["Script/Packages/Atomic"],
+  "modules" : ["WebView"],
+  "platforms" : ["WINDOWS", "MACOSX"]
+}

+ 6 - 0
Script/Packages/WebView/WebView.json

@@ -0,0 +1,6 @@
+{
+	"name" : "WebView",
+	"includes" : ["<Atomic/Graphics/DebugRenderer.h>"],
+	"sources" : ["Source/AtomicWebView"],
+	"classes" : ["WebBrowserHost", "WebClient", "WebRenderHandler", "WebTexture2D"]
+}

+ 1 - 1
Source/AtomicJS/Javascript/Javascript.h

@@ -40,7 +40,7 @@ public:
     /// Construct.
     /// Construct.
     Javascript(Context* context);
     Javascript(Context* context);
     /// Destruct.
     /// Destruct.
-    ~Javascript();
+    virtual ~Javascript();
 
 
     /// Returns NULL if a VM with name already exists
     /// Returns NULL if a VM with name already exists
     JSVM* InstantiateVM(const String& name);
     JSVM* InstantiateVM(const String& name);

+ 4 - 1
Source/AtomicWebView/CMakeLists.txt

@@ -1,8 +1,11 @@
 include_directories (${CMAKE_SOURCE_DIR}/Source/ThirdParty
 include_directories (${CMAKE_SOURCE_DIR}/Source/ThirdParty
                      ${CMAKE_SOURCE_DIR}/Source/ThirdParty/CEF )
                      ${CMAKE_SOURCE_DIR}/Source/ThirdParty/CEF )
 
 
-
 file (GLOB SOURCE_FILES *.cpp *.h)
 file (GLOB SOURCE_FILES *.cpp *.h)
 
 
+file (GLOB JAVASCRIPT_BINDINGS_SOURCE ${CMAKE_SOURCE_DIR}/Artifacts/Build/Source/Generated/${JAVASCRIPT_BINDINGS_PLATFORM}/Javascript/Packages/WebView/*.cpp)
+
+set (SOURCE_FILES ${SOURCE_FILES} ${JAVASCRIPT_BINDINGS_SOURCE} )
+
 add_library(AtomicWebView ${SOURCE_FILES})
 add_library(AtomicWebView ${SOURCE_FILES})
 
 

+ 14 - 0
Source/AtomicWebView/WebBrowserHost.cpp

@@ -8,6 +8,7 @@
 #include <Atomic/Core/ProcessUtils.h>
 #include <Atomic/Core/ProcessUtils.h>
 #include <Atomic/IO/Log.h>
 #include <Atomic/IO/Log.h>
 
 
+#include "WebClient.h"
 #include "WebBrowserHost.h"
 #include "WebBrowserHost.h"
 
 
 class SimpleApp : public CefApp,
 class SimpleApp : public CefApp,
@@ -76,4 +77,17 @@ WebBrowserHost::~WebBrowserHost()
 
 
 }
 }
 
 
+bool WebBrowserHost::CreateBrowser(WebClient* webClient)
+{
+    CefWindowInfo windowInfo;
+    CefBrowserSettings browserSettings;
+
+    CefBrowserHost::CreateBrowser(windowInfo, (CefClient*) webClient->d_,
+                                  "http://www.atomicgameengine.com", browserSettings, nullptr);
+
+    return true;
+}
+
+
+
 }
 }

+ 5 - 1
Source/AtomicWebView/WebBrowserHost.h

@@ -6,6 +6,8 @@
 namespace Atomic
 namespace Atomic
 {
 {
 
 
+class WebClient;
+
 class ATOMIC_API WebBrowserHost : public Object
 class ATOMIC_API WebBrowserHost : public Object
 {
 {
     OBJECT(WebBrowserHost);
     OBJECT(WebBrowserHost);
@@ -14,7 +16,9 @@ public:
     /// Construct.
     /// Construct.
     WebBrowserHost(Context* context);
     WebBrowserHost(Context* context);
     /// Destruct.
     /// Destruct.
-    ~WebBrowserHost();
+    virtual ~WebBrowserHost();
+
+    bool CreateBrowser(WebClient* webClient);
 
 
 private:
 private:
 
 

+ 28 - 1
Source/AtomicWebView/WebClient.cpp

@@ -1,18 +1,45 @@
 
 
+#include <ThirdParty/CEF/include/cef_client.h>
+
 #include "WebClient.h"
 #include "WebClient.h"
 
 
 namespace Atomic
 namespace Atomic
 {
 {
 
 
+class WebClientPrivate : public CefClient
+{
+    friend class WebClient;
+
+public:
+
+    WebClientPrivate(WebClient* client)
+    {
+
+        webClient_ = client;
+    }
+
+    IMPLEMENT_REFCOUNTING(WebClientPrivate)
+
+private:
+
+    WeakPtr<WebClient> webClient_;
+
+};
+
 
 
 WebClient::WebClient(Context* context) : Object(context)
 WebClient::WebClient(Context* context) : Object(context)
 {
 {
-
+    d_ = new WebClientPrivate(this);
 }
 }
 
 
 WebClient::~WebClient()
 WebClient::~WebClient()
 {
 {
+    d_->Release();
+}
 
 
+void WebClient::SetWebRenderHandler(WebRenderHandler* handler)
+{
+    renderHandler_ = handler;
 }
 }
 
 
 
 

+ 14 - 12
Source/AtomicWebView/WebClient.h

@@ -1,33 +1,35 @@
 
 
-#include <ThirdParty/CEF/include/cef_client.h>
 #include <Atomic/Core/Object.h>
 #include <Atomic/Core/Object.h>
-
-#include "WebRenderer.h"
+#include "WebRenderHandler.h"
 
 
 #pragma once
 #pragma once
 
 
 namespace Atomic
 namespace Atomic
 {
 {
 
 
-class ATOMIC_API WebClient : public Object, public CefClient
+class WebClientPrivate;
+
+class ATOMIC_API WebClient : public Object
 {
 {
-    OBJECT(WebClient);
+    friend class WebBrowserHost;
+    friend class WebClientPrivate;
+
+    OBJECT(WebClient)
 
 
 public:
 public:
     /// Construct.
     /// Construct.
     WebClient(Context* context);
     WebClient(Context* context);
-    /// Destruct.
-    ~WebClient();
 
 
-    // CEF3
-    virtual CefRefPtr<CefRenderHandler> GetRenderHandler() {
-      return renderer_.Get();
-    }
+    /// Destruct.
+    virtual ~WebClient();
 
 
+    void SetWebRenderHandler(WebRenderHandler* handler);
 
 
 private:
 private:
 
 
-    SharedPtr<WebRenderer> renderer_;
+    SharedPtr<WebRenderHandler> renderHandler_;
+
+    WebClientPrivate* d_;
 
 
 };
 };
 
 

+ 3 - 3
Source/AtomicWebView/WebRenderer.cpp → Source/AtomicWebView/WebRenderHandler.cpp

@@ -3,17 +3,17 @@
 #include <Atomic/Graphics/Graphics.h>
 #include <Atomic/Graphics/Graphics.h>
 #include <Atomic/Graphics/Technique.h>
 #include <Atomic/Graphics/Technique.h>
 
 
-#include "WebRenderer.h"
+#include "WebRenderHandler.h"
 
 
 namespace Atomic
 namespace Atomic
 {
 {
 
 
 
 
-WebRenderer::WebRenderer(Context* context) : Object (context)
+WebRenderHandler::WebRenderHandler(Context* context) : Object (context)
 {
 {
 }
 }
 
 
-WebRenderer::~WebRenderer()
+WebRenderHandler::~WebRenderHandler()
 {
 {
 
 
 }
 }

+ 44 - 0
Source/AtomicWebView/WebRenderHandler.h

@@ -0,0 +1,44 @@
+
+#include <Atomic/Graphics/Texture2D.h>
+#include <Atomic/Graphics/Material.h>
+
+#pragma once
+
+namespace Atomic
+{
+
+class ATOMIC_API WebRenderHandler : public Object
+{
+    OBJECT(WebRenderHandler);
+
+public:
+
+    /// Construct.
+    WebRenderHandler(Context* context);
+    /// Destruct.
+    virtual ~WebRenderHandler();
+
+    virtual void SetCurrentWidth(unsigned width) = 0;
+    virtual void SetCurrentHeight(unsigned height) = 0;
+
+    virtual void SetMaxWidth(unsigned width) = 0;
+    virtual void SetMaxHeight(unsigned height) = 0;
+
+    unsigned GetCurrentWidth() const { return currentWidth_; }
+    unsigned GetCurrentHeight() const { return currentHeight_; }
+
+    unsigned GetMaxWidth() const { return maxWidth_; }
+    unsigned GetMaxHeight() const { return maxHeight_; }
+
+private:
+
+    unsigned currentWidth_;
+    unsigned currentHeight_;
+
+    unsigned maxHeight_;
+    unsigned maxWidth_;
+
+
+};
+
+}

+ 0 - 27
Source/AtomicWebView/WebRenderer.h

@@ -1,27 +0,0 @@
-#include <ThirdParty/CEF/include/cef_client.h>
-
-#include <Atomic/Graphics/Texture2D.h>
-#include <Atomic/Graphics/Material.h>
-
-#pragma once
-
-namespace Atomic
-{
-
-class ATOMIC_API WebRenderer : public Object, public CefRenderHandler
-{
-    OBJECT(WebRenderer);
-
-public:
-
-    /// Construct.
-    WebRenderer(Context* context);
-    /// Destruct.
-    ~WebRenderer();
-
-private:
-
-
-};
-
-}

+ 55 - 2
Source/AtomicWebView/WebTexture2D.cpp

@@ -1,3 +1,4 @@
+#include <ThirdParty/CEF/include/cef_render_handler.h>
 
 
 #include <Atomic/Resource/ResourceCache.h>
 #include <Atomic/Resource/ResourceCache.h>
 #include <Atomic/Graphics/Graphics.h>
 #include <Atomic/Graphics/Graphics.h>
@@ -8,9 +9,41 @@
 namespace Atomic
 namespace Atomic
 {
 {
 
 
+class WebTexture2DPrivate : public CefRenderHandler
+{
+    friend class WebTexture2D;
+
+public:
+
+    IMPLEMENT_REFCOUNTING(WebTexture2DPrivate)
+
+    WebTexture2DPrivate(WebTexture2D* webTexture2D)
+    {
+        webTexture2D_ = webTexture2D;
+    }
+
+    bool GetViewRect(CefRefPtr<CefBrowser> browser, CefRect &rect) OVERRIDE
+    {
+        rect = CefRect(0, 0, webTexture2D_->GetCurrentWidth(), webTexture2D_->GetCurrentHeight());
+        return true;
+    }
+
+    void OnPaint(CefRefPtr<CefBrowser> browser, PaintElementType type, const RectList &dirtyRects,
+                           const void *buffer, int width, int height) OVERRIDE
+    {
+        webTexture2D_->texture_->SetData(0, 0, 0, width, height, buffer);
+    }
+
+private:
 
 
-WebTexture2D::WebTexture2D(Context* context, int width, int height) : WebRenderer(context)
+    WeakPtr<WebTexture2D> webTexture2D_;
+
+};
+
+WebTexture2D::WebTexture2D(Context* context, int width, int height) : WebRenderHandler(context)
 {
 {
+    d_ = new WebTexture2DPrivate(this);
+
     ResourceCache* cache = GetSubsystem<ResourceCache>();
     ResourceCache* cache = GetSubsystem<ResourceCache>();
 
 
     texture_ = new Texture2D(context_);
     texture_ = new Texture2D(context_);
@@ -23,10 +56,30 @@ WebTexture2D::WebTexture2D(Context* context, int width, int height) : WebRendere
     material_->SetTexture(TU_DIFFUSE, texture_);
     material_->SetTexture(TU_DIFFUSE, texture_);
 }
 }
 
 
-WebTexture2D::~WebTexture2D()
+void WebTexture2D::SetCurrentWidth(unsigned width)
 {
 {
 
 
 }
 }
 
 
+void WebTexture2D::SetCurrentHeight(unsigned height)
+{
+
+}
+
+void WebTexture2D::SetMaxWidth(unsigned width)
+{
+
+}
+
+void WebTexture2D::SetMaxHeight(unsigned height)
+{
+
+}
+
+WebTexture2D::~WebTexture2D()
+{
+    d_->Release();
+}
+
 
 
 }
 }

+ 15 - 3
Source/AtomicWebView/WebTexture2D.h

@@ -2,15 +2,19 @@
 #include <Atomic/Graphics/Texture2D.h>
 #include <Atomic/Graphics/Texture2D.h>
 #include <Atomic/Graphics/Material.h>
 #include <Atomic/Graphics/Material.h>
 
 
-#include "WebRenderer.h"
+#include "WebRenderHandler.h"
 
 
 #pragma once
 #pragma once
 
 
 namespace Atomic
 namespace Atomic
 {
 {
 
 
-class ATOMIC_API WebTexture2D : public WebRenderer
+class WebTexture2DPrivate;
+
+class ATOMIC_API WebTexture2D : public WebRenderHandler
 {
 {
+    friend class WebTexture2DPrivate;
+
     OBJECT(WebTexture2D);
     OBJECT(WebTexture2D);
 
 
 public:
 public:
@@ -18,13 +22,21 @@ public:
     /// Construct.
     /// Construct.
     WebTexture2D(Context* context, int width = 1024, int height = 1024);
     WebTexture2D(Context* context, int width = 1024, int height = 1024);
     /// Destruct.
     /// Destruct.
-    ~WebTexture2D();
+    virtual ~WebTexture2D();
+
+    virtual void SetCurrentWidth(unsigned width);
+    virtual void SetCurrentHeight(unsigned height);
+
+    virtual void SetMaxWidth(unsigned width);
+    virtual void SetMaxHeight(unsigned height);
 
 
 private:
 private:
 
 
     SharedPtr<Texture2D> texture_;
     SharedPtr<Texture2D> texture_;
     SharedPtr<Material> material_;
     SharedPtr<Material> material_;
 
 
+    WebTexture2DPrivate* d_;
+
 };
 };
 
 
 }
 }