Skip to content

Commit

Permalink
NexusVR updates
Browse files Browse the repository at this point in the history
-RenderHandler replaced by BrowserHandler. Adds support for
CefDownloadHandler callbacks, considering this as a catch-all cef
callback forwarder.
-Added DownloadFile( url ) to BluEye
-Added Zoom functionality for BluEye
-Added Multicast delegates for download progress updates
-CEF bind updated to 2556 for fullscreen API support, but current build
will work with older build.
  • Loading branch information
getnamo committed Jan 24, 2016
1 parent 0a1c761 commit 34101fe
Show file tree
Hide file tree
Showing 8 changed files with 299 additions and 101 deletions.
8 changes: 0 additions & 8 deletions .gitignore

This file was deleted.

7 changes: 4 additions & 3 deletions BLUI.uplugin
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

"FriendlyName": "BLUI",
"Version": 3,
"VersionName": "3.1",
"EngineVersion": 1579795,
"VersionName": "3.1.1",
"EngineVersion": "4.9+",
"Description": "Chrome powered HTML UI and HUD for Unreal Engine 4",
"Category": "UI",
"CreatedBy": "Aaron M. Shea",
Expand All @@ -25,5 +25,6 @@
"LoadingPhase": "PreDefault",
"BlacklistPlatforms": [ "HTML5", "Android", "iOS" ]
}
]
],
"CanContainContent" : true
}
93 changes: 77 additions & 16 deletions Source/Blu/Private/BluEye.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
UBluEye::UBluEye(const class FObjectInitializer& PCIP)
: Super(PCIP)
{
Texture = nullptr;

Width = 800;
Height = 600;
Expand All @@ -11,17 +12,18 @@ UBluEye::UBluEye(const class FObjectInitializer& PCIP)

}

void UBluEye::init(UObject* WorldContextObject)
void UBluEye::init()
{

/**
* We don't want this running in editor unless it's PIE
* If we don't check this, CEF will spawn infinit processes with widget components
**/
const UWorld* world = GEngine->GetWorldFromContextObject(WorldContextObject);
/**
* We don't want this running in editor unless it's PIE
* If we don't check this, CEF will spawn infinit processes with widget components
**/
Texture = nullptr;

if (GEngine)
{
if (!world->IsGameWorld() && !world->IsPlayInEditor())
if (GEngine->IsEditor() && !GWorld->IsPlayInEditor())
{
UE_LOG(LogBlu, Log, TEXT("Notice: not playing - Component Will Not Initialize"));
return;
Expand All @@ -38,7 +40,7 @@ void UBluEye::init(UObject* WorldContextObject)
info.SetAsWindowless(0, bIsTransparent);

renderer = new RenderHandler(Width, Height, this);
g_handler = new BrowserClient(renderer);
g_handler = new BrowserClient(renderer, this);
browser = CefBrowserHost::CreateBrowserSync(info, g_handler.get(), "about:blank", browserSettings, NULL);

// Setup JS event emitter
Expand All @@ -60,6 +62,8 @@ void UBluEye::ResetTexture()
// Here we init the texture to its initial state
DestroyTexture();

Texture = nullptr;

// init the new Texture2D
Texture = UTexture2D::CreateTransient(Width, Height, PF_B8G8R8A8);
Texture->AddToRoot();
Expand Down Expand Up @@ -97,7 +101,8 @@ void UBluEye::TextureUpdate(const void *buffer, FUpdateTextureRegion2D *updateRe
return;
}

if (Texture && Texture->Resource)
//todo: remove debug address hack
if (Texture && (int64)Texture != 0xdddddddddddddddd && Texture->IsValidLowLevel() && Texture->Resource)
{

if (buffer == nullptr)
Expand Down Expand Up @@ -198,11 +203,38 @@ void UBluEye::LoadURL(const FString& newURL)

}

bool UBluEye::IsBrowserLoading()
FString UBluEye::GetCurrentURL()
{
return FString(browser->GetMainFrame()->GetURL().c_str());
}

return browser->IsLoading();
void UBluEye::SetZoom(const float scale /*= 1*/)
{
browser->GetHost()->SetZoomLevel(scale);
}

float UBluEye::GetZoom()
{
return browser->GetHost()->GetZoomLevel();
}

void UBluEye::Test()
{
/*CefRefPtr<CefNavigationEntryVisitor> visitor;
browser->GetHost->GetNavigationEntries(visitor, false);*/

//for (auto in visitor)
}

void UBluEye::DownloadFile(const FString& fileUrl)
{
browser->GetHost()->StartDownload(*fileUrl);
//Todo: ensure downloading works in some way, shape or form?
}

bool UBluEye::IsBrowserLoading()
{
return browser->IsLoading();
}

void UBluEye::ReloadBrowser(bool IgnoreCache)
Expand Down Expand Up @@ -239,8 +271,6 @@ void UBluEye::NavForward()

UTexture2D* UBluEye::ResizeBrowser(const int32 NewWidth, const int32 NewHeight)
{
// Do we even have a texture to try and resize?
verifyf(Texture, TEXT("Can't resize when there isn't a texture. Did you forget to call init?"));

// Disable the web view while we resize
bEnabled = false;
Expand All @@ -253,8 +283,9 @@ UTexture2D* UBluEye::ResizeBrowser(const int32 NewWidth, const int32 NewHeight)
renderer->Width = NewWidth;
renderer->Height = NewHeight;

// We need to reset the texture
ResetTexture();
Texture = UTexture2D::CreateTransient(Width, Height, PF_B8G8R8A8);
Texture->AddToRoot();
Texture->UpdateResource();

// Let the browser's host know we resized it
browser->GetHost()->WasResized();
Expand All @@ -268,6 +299,32 @@ UTexture2D* UBluEye::ResizeBrowser(const int32 NewWidth, const int32 NewHeight)

}

UTexture2D* UBluEye::CropWindow(const int32 Y, const int32 X, const int32 NewWidth, const int32 NewHeight)
{
// Disable the web view while we resize
bEnabled = false;


// Set our new Width and Height
Width = NewWidth;
Height = NewHeight;

// Update our render handler
renderer->Width = NewWidth;
renderer->Height = NewHeight;

Texture = UTexture2D::CreateTransient(Width, Height, PF_B8G8R8A8);
Texture->AddToRoot();
Texture->UpdateResource();

// Now we can keep going
bEnabled = true;

UE_LOG(LogBlu, Log, TEXT("BluEye was cropped!"))

return Texture;
}

void UBluEye::TriggerMouseMove(const FVector2D& pos, const float scale)
{

Expand Down Expand Up @@ -459,7 +516,11 @@ void UBluEye::processKeyMods(FInputEvent InKey)

UTexture2D* UBluEye::GetTexture() const
{
verifyf(Texture, TEXT("There is no texture to return! Did you forget to call init?"));
if (!Texture)
{
return UTexture2D::CreateTransient(Width, Height);
}

return Texture;
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Blu/Private/BluPrivatePCH.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ DECLARE_LOG_CATEGORY_EXTERN(LogBlu, Log, All);
// Blu Classes
#include "BluManager.h"
#include "BluEye.h"
#include "RenderHandler.h"
#include "BrowserHandler.h"
#include "BluJsonObj.h"
#include "BluBlueprintFunctionLibrary.h"
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,58 @@ bool BrowserClient::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, CefP

}


//The path slashes have to be reversed to work with CEF
FString ReversePathSlashes(FString forwardPath)
{
return forwardPath.Replace(TEXT("/"), TEXT("\\"));
}
FString UtilityBLUIDownloadsFolder()
{
return ReversePathSlashes(FPaths::ConvertRelativePathToFull(FPaths::GameDir() + "Plugins/BLUI/Downloads/"));
}


void BrowserClient::SetEventEmitter(FScriptEvent* emitter)
{
this->event_emitter = emitter;
}
}

void BrowserClient::OnBeforeDownload(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefDownloadItem> download_item,
const CefString & suggested_name,
CefRefPtr<CefBeforeDownloadCallback> callback)
{
UNREFERENCED_PARAMETER(browser);
UNREFERENCED_PARAMETER(download_item);

//We use this concatenation method to mix c_str with regular FString and then convert the result back to c_str
FString downloadPath = UtilityBLUIDownloadsFolder() + FString(suggested_name.c_str());

callback->Continue(*downloadPath, false); //don't show the download dialog, just go for it

UE_LOG(LogClass, Log, TEXT("Downloading file for path %s"), *downloadPath);
}

void BrowserClient::OnDownloadUpdated(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefDownloadItem> download_item,
CefRefPtr<CefDownloadItemCallback> callback)
{
int percentage = download_item->GetPercentComplete();
FString url = FString(download_item->GetFullPath().c_str());

UE_LOG(LogClass, Log, TEXT("Download %s Updated: %d"), *url , percentage);

blu->DownloadUpdated.Broadcast(url, percentage);

if (percentage == 100 && download_item->IsComplete()) {
UE_LOG(LogClass, Log, TEXT("Download %s Complete"), *url);
blu->DownloadComplete.Broadcast(url);
}

//Example download cancel/pause etc, we just have to hijack this
//callback->Cancel();
}

42 changes: 39 additions & 3 deletions Source/Blu/Public/BluEye.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,31 @@ enum EBluSpecialKeys
scrolllockkey = 145 UMETA(DisplayName = "Scroll Lock")
};

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FDownloadCompleteSignature, FString, url);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FDownloadUpdatedSignature, FString, url, float, percentage);
//DECLARE_DYNAMIC_MULTICAST_DELEGATE(FDownloadComplete);

UCLASS(ClassGroup = Blu, Blueprintable)
class BLU_API UBluEye : public UObject
{

GENERATED_BODY()

UBluEye(const class FObjectInitializer& PCIP);

public:

//Event delegates
UPROPERTY(BlueprintAssignable, Category = "Blu Browser Events")
FDownloadCompleteSignature DownloadComplete;

UPROPERTY(BlueprintAssignable, Category = "Blu Browser Events")
FDownloadUpdatedSignature DownloadUpdated;

//GENERATED_UCLASS_BODY()

/** Initialize function, should be called after properties are set */
UFUNCTION(BlueprintCallable, Category = "Blu", meta = (WorldContext = "WorldContextObject"))
void init(UObject* WorldContextObject);
UFUNCTION(BlueprintCallable, Category = "Blu")
void init();

/** The default URL this UI component will load */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Blu")
Expand Down Expand Up @@ -120,6 +130,26 @@ class BLU_API UBluEye : public UObject
UFUNCTION(BlueprintCallable, Category = "Blu")
void LoadURL(const FString& newURL);

/** Get the currently loaded URL */
UFUNCTION(BlueprintPure, Category = "Blu")
FString GetCurrentURL();

/** Trigger Zoom */
UFUNCTION(BlueprintCallable, Category = "Blu")
void SetZoom(const float scale = 1);

/** Get our zoom level */
UFUNCTION(BlueprintPure, Category = "Blu")
float GetZoom();

//Not ready yet
//UFUNCTION(BlueprintCallable, Category = "Blu Test")
void Test();

/** Download a file */
UFUNCTION(BlueprintCallable, Category = "Blu")
void DownloadFile(const FString& fileUrl);

/** Trigger a LEFT click in the browser via a Vector2D */
UFUNCTION(BlueprintCallable, Category = "Blu")
void TriggerLeftClick(const FVector2D& pos, const float scale = 1);
Expand Down Expand Up @@ -221,6 +251,10 @@ class BLU_API UBluEye : public UObject
UFUNCTION(BlueprintCallable, Category = "Blu")
UTexture2D* ResizeBrowser(const int32 NewWidth, const int32 NewHeight);

//This cropping function doesn't work atm
//UFUNCTION(BlueprintCallable, Category = "Blu")
UTexture2D* CropWindow(const int32 Y, const int32 X, const int32 NewWidth, const int32 NewHeight);

CefRefPtr<CefBrowser> browser;

void TextureUpdate(const void* buffer, FUpdateTextureRegion2D * updateRegions, uint32 regionCount);
Expand All @@ -244,7 +278,9 @@ class BLU_API UBluEye : public UObject
void processKeyMods(FInputEvent InKey);

// Store UI state in this UTexture2D
UPROPERTY()
UTexture2D* Texture;

UMaterialInstanceDynamic* MaterialInstance;

CefMouseEvent mouse_event;
Expand Down
Loading

0 comments on commit 34101fe

Please sign in to comment.