Jump to content

  • Log In with Google      Sign In   
  • Create Account






Awesomium both in name and in use

Posted by Little Coding Fox, 14 February 2012 · 1,812 views

game progrmaming Game UI
Backstory

Awesomium is a "google chrome in a lib" library that can be used on pretty much any application to render web pages (including flash and silverlight content), and has a great indie license to boot.

I know there are developers like me who'd rather not write their own native UI code for their games. After writing my own and having little success, and by that I mean that it was overly complex and hard to create and use any new UI elements and also mimicking their behaviour, and having tried several libraries such as libRocket, I helped a friend work on some web design assignments he had for university, (re)-learning HTML and using HTML5/CSS3/jquery for doing all sorts of awesome things.

I already heard of Awesomium and how you could use it combined with games for UIs and such, but considering my lack of HTML skills, I didn't consider it at the time. After I did help my friend, I had some moderate understanding of some fancy CSS3 tricks and was able to compose a UI relatively easy. And after I learned how to use some of Awesomium's most awesome features (no pun intended), I find it to be the very best UI library around.

Some advantages on using Awesomium
  • You can design your UI with HTML5, CSS3, and any javascript library.
  • Writing custom elements is much easier. You don't even have to write pretty much any code in your native language.
  • You can have fancy animations and even pre-made UIs using JS libraries like jquery UI.
  • You can use the awesome open source fonts from Google Web Fonts!
  • Works on the 3 main OSs (Windows, Linux, OSX)
  • It is rather quick and uses the same "multiprocess" scheme that Chrome uses (so if an Awesomium-created process crashes, your game won't crash)
  • You can use their Javascript API to create custom JS objects and then use javascript scripts on your pages to control parts of your game (e.g., I have a custom Core JS object with several methods like LoadHTML which let me "move" between HTML pages instead of doing it manually)
  • In the upcoming 1.7 SDK which will be released in the next month, you will have full support for HTML5, and with it, you can use the <video> tag to show videos and the <audio> tag to have your own sound system without having to resort to other libraries such as FMOD and as such not having to spend too much money
  • You can have in-game web browsers, among other interesting interactions within your game
  • Many other fancy features like custom HTTP headers and resource handling
You may be wondering, why prefer this to libRocket. LibRocket relies on a heavily modified version of HTML/CSS and as such is much harder to work with, even if it has a nicer license.

Some tips while using Awesomium

The biggest challenge while using Awesomium for me was having the UI elements become unselectable when the user drags the mouse around. You might think this to be a minor inconvenient, but I felt that the UI elements should look like actual UI elements instead of just a webpage overlayed on top of the game. If you do a search for how to do this, you'll find various solutions, but for some reason using them wouldn't work very well for me.

However, I ended up writing this very simple CSS class:
.unselectable
{
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
}
And using it like so:
function MakeElementsUnselectable()
{
$("*:not(input)").addClass("unselectable");
}

This javascript function will go through all non-input elements and apply the 'unselectable' class I defined upon all of them. Input elements need to be able to be selectable since otherwise elements such as textboxes will not be editable or show the blinking cursor.

You may be wondering why I have three lines doing the exact same thing. I did that so that it will work on my main browser (Firefox) and also on Awesomium (which uses Webkit). For some reason Awesomium was not accepting -webkit-user-select so I added the 3rd line which is more standard, CSS3-wise.

Another useful bit of code allows us to remove the custom webkit outline that happens around input elements.
input:focus
{
outline: none;
}

There's not much to talk about this part, but this is very useful since e.g., the outline around textboxes will not be shown. Here's an example of how it looks when the outline is shown:
Posted Image
(Taken from http://www.electrictoolbox.com/remove-webkit-border-input-focus/)

The End

And that's pretty much the end for this post. I hope you find it useful. I didn't leave much details on actually implementing Awesomium because it is rather easy to use, even if you use their C API (as I had to, since their project files on Windows were for VS2008 and I was using VS2010).




Thanks for sharing!

I assume the Firefox compatibility is for testing your UI in the browser rather than having to launch the game every time you tweak something?

Are you using it for in-game UI, or just menus?

How have you found the performance? I've heard previously that the rendered web-content can update poorly if you do anything too fancy, but I'm not sure if that's a genuine concern or the result of trying to do something silly.
Oh, and one other quick question -- how does it weigh-in in terms of impact on executable size?

Thanks for sharing!I assume the Firefox compatibility is for testing your UI in the browser rather than having to launch the game every time you tweak something?Are you using it for in-game UI, or just menus?How have you found the performance? I've heard previously that the rendered web-content can update poorly if you do anything too fancy, but I'm not sure if that's a genuine concern or the result of trying to do something silly.


Yes, I'm doing Firefox Compatiblity for testing my UI in the browser. This way I can e.g., position my elements without having to launch the game all the time, as a simple refresh usually works.

I'm using it for both in-game UI and menus, and I found the performance to be at the very least adequate. On an nVidia GT320 PC, my performance ranges from 900 to 1300+ FPS when rendering a webpage with constant JS animation (by constant I mean something changes every 15ms at least), altough nothing else was being rendered at the time so the performance may vary on heavier rendering settings like an actual 3D game, as I'm using it on a 2D game at the moment. Also, since the rendering to a bitmap is actually done on the child Awesomium processes, you won't notice too much of a performance impact except when updating your texture with the new data.

Regarding the Executable Size, if you use their release_packed binaries, it will only give an increase of about 9.40 MB (although these are separate LL/.exe files, so your .exe doesn't actually increase in size much). These extra files might be much larger if you're not using the packed binaries though. For instance, the debug .dll reaches 76MB in size for me. Also, the .exe file I mention in the extra files is simply the Awesomium process, but you may modify your own .exe so that you can use it instead of Awesomium for the Awesomium Processes.

July 2014 »

S M T W T F S
  12345
6789101112
13141516171819
202122 23 242526
2728293031  

Recent Comments

PARTNERS