Basic Concepts

There's only a few key concepts that you'll need to be familiar with to use Awesomium.

The WebCore

The first of these is the WebCore. The WebCore is the "core" of Awesomium-- it manages the lifetime of all WebViews (more on that later) and maintains useful services like resource caching and network connections.

Generally, you should create an instance of the WebCore at the beginning of your program and then destroy the instance at the end of your program. Here's an example of how to create it:

// Create the WebCore with default parameters
Awesomium::WebCore* myWebCore = new Awesomium::WebCore();

Updating the WebCore

In your main program loop, make sure to call WebCore::update to give it a chance to do some behind-the-scenes work. Here's a psuedo-example:

void updateApplication()
{
    myWebCore->update();
    // do other application stuff
}

The WebView

A WebView is similiar to a "tab" in a browser. You load pages into a WebView, interact with it, and render it on-the-fly to a pixel buffer (e.g., for use in an image/texture/etc). You create WebViews using the WebCore, here's an example:

// Create a new WebView with a width and height of 500px
Awesomium::WebView* myWebView = myWebCore->createWebView(500, 500);

Rendering

You can render a WebView to a pixel buffer using WebView::render. To avoid needless rendering, you should only render a WebView when it is "dirty" (i.e., "needs rendering"). You can check if a WebView is dirty via WebView::isDirty. Here's a quick example:

if(myWebView->isDirty())
{
    const Awesomium::RenderBuffer* myBuffer = myWebView->render();

    // use raw image data in 'myBuffer' for graphics stuff here
}

Injecting mouse input

To interact with the WebView, you'll need to pass it mouse events. Here's some quick examples:

Inject a mouse-movement event to (75, 100) in screen-space

myWebView->injectMouseMove(75, 100);

Inject a left-mouse-button down event

myWebView->injectMouseDown(Awesomium::LEFT_MOUSE_BTN);

Inject a left-mouse-button up event

myWebView->injectMouseUp(Awesomium::LEFT_MOUSE_BTN);

Injecting keyboard input

To inject keyboard events into a WebView, you will need to create a WebKeyboardEvent and pass it to WebView::injectKeyboardEvent. You can either create a WebKeyboardEvent from a platform-specific keyboard event (eg, MSG, WPARAM, LPARAM on Windows) or synthesize one yourself. See "passing keyboard events" for more information.

Managing input focus

Any time you interact with a WebView, you should first make sure the WebView is focused by calling WebView::focus. If you forget to do this, textboxes may not behave correctly (e.g., carets and selection indicators may not display).

Similarly, to remove focus from a WebView, you should call WebView::unfocus.

The WebViewListener

The WebViewListener is a special class that you can use to respond to certain events in a WebView. Simply make your own WebViewListener subclass and then register an instance of it to a certain WebView using WebView::setListener. Here's a psuedo-example:

Create our WebViewListener subclass

class MyWebViewListener : public Awesomium::WebViewListener
{
    // ... All the overriden WebViewListener methods go here
};

Create and instance and register it to a certain WebView

// Create an instance of our MyWebViewListener subclass
MyWebViewListener* myListener = new MyWebViewListener();

// Register the instance as a listener of myWebView
myWebView->setListener(myListener);