Last active
April 2, 2016 00:00
-
-
Save jeremyfromearth/67961348ab40fd77af3c07711ea7ad80 to your computer and use it in GitHub Desktop.
Make assets from your Cinder project accessible to html rendered in Awesomium
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "cinder/app/App.h" | |
#include "AssetDataSource.h" | |
using namespace ci; | |
using namespace ci::app; | |
void AssetDataSource::OnRequest(int request_id, const WebString & path) { | |
// load the asset the Cinder way and convert it to a buffer | |
auto asset = loadAsset(toString(path)); | |
auto buffer = asset->getBuffer(); | |
// send the asset as a char string | |
SendResponse(request_id, | |
buffer->getSize(), | |
static_cast<unsigned char *>(buffer->getData()), | |
WSLit("text/data")); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "CinderAwesomium.h" | |
class AssetDataSourceImlp; | |
class AssetDataSource : public Awesomium::DataSource { | |
public: | |
AssetDataSource(){}; | |
virtual ~AssetDataSource(){}; | |
virtual void OnRequest(int request_id, const Awesomium::WebString & path); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using namespace Awesomium; | |
WebCore * core = WebCore::Initialize(WebConfig()); | |
WebSession * session = core->CreateWebSession(WSLit(""), WebPreferences()); | |
session->AddDataSource(WSLit("cinder-app"), new AssetDataSource()); | |
WebView webView = core->CreateWebView(960, 540, session); | |
std::string html = loadString(loadFile(getAssetPath("main.html"))); | |
std::string path("data:text/html," + html); | |
webView->LoadURL(path); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<meta charset="utf-8" /> | |
<title></title> | |
<style> | |
@font-face { | |
font-family: SomeFont; | |
src: url("asset://cinder-app/SomeFont.otf"); | |
} | |
</style> | |
</head> | |
<body> | |
<img src="asset://cinder-app/some-image.jpg" | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment