About Me




Flash Games

Cellular Automata

Mittens Massacre





Shear is currently a work in progress. At this point, over 85% of the widgets are completed.


Shear is an in-game GUI library written in C++. Shear leverages my rendering and input layer called Pulse. Pulse is a multiplatform (Windows and Linux, with Mac planned) rendering (DirectX and OpenGL) and input layer. Shear integrates with a Lua state to create, modify and set callbacks in the UI state.

Technical Features

  • Written in highly idiomatic modern C++
    • Uses wrapped STL where appropriate
    • Uses Boost where STL is deficient
  • 22 unique widgets, supported by ~16,000 lines of code
  • Supports generic widget templates and inheritance from any format (JSON/XML/Lua/etc)
  • Scalable UI canvas for any resolution
  • Flexible and expressive anchoring system
  • Supports streaming textures
  • Supports any TTF font files, generating bitmap fonts automatically
  • Decoupling: Widgets have no idea that a Lua state even exists

Usage examples

This section shows off some basic examples of creating a widget through Lua and the results.


A frame is the basic building block of all widgets. As shown below, creating a frame is quite trivial.

However, nothing would be visible yet, as the frame has no size, no anchors and no background.

Now a simple frame exists in the center of the screen. It's a bit boring though, so let's add some color and a border to it.

A frame by itself is not too impressive, but it serves as a container, anchor, and building block. A more advanced example builds from this.

Status Bar

The status bar is now complete, but there is currently no way to interact with it. Even more importantly, it's not showing the status of anything! To solve this, I'll create a slider widget that will change the value of the status bar.


(The slider looks much better if you have some artistic talent to make thumb textures and backgrounds)

Now the slider is fully functioning, but the status bar needs to be connected. When a user mouses down on the slider and drags, the status bar should immediately update to the new value. This is easily done using a script event.

Now, when the slider's value changes the script is triggered and the status bar's value is immediately updated. Additionally, it's easy to change the color of the status bar or other effects depending on the new value.


This section examines how to connect a status bar widget to display something more useful: the hitpoints of a player. The easiest way is to register and trigger event with Shear. First, take the status bar and register if for the health change event, which I'll call "PlayerHealthUpdate".

Now the event needs to triggered from C++. This is done using the Event Interface, which is one of the public interfaces Shear provides. The FireEvent method sends an event to all widget listeners. FireEvent is an overloaded templated method that supports up to 20 parameters of standard Lua types and defined custom types through ADL.

Shear immediately sends the event to all listeners, and in turn the status bar updates its value to show the player's new health.

Advanced Usage

The previous examples have only touched on three of the twenty-two widgets that Shear supports. For more advanced usage please see one of my other projects: VisualWoWSim

Code Samples

Click 'show source' to view a code sample from LuaBindingUtils.cpp. This class provides functions to register and manipulate widgets through Lua.

This function shows the way Shear binds a widget to Lua that allows for later retrieval and type-checking.

This function shows the reverse of the previous example: retrieving the C++ widget from a Lua. (In the actual code, this function is wrapped in a templated function that does more defined casts.)

This sample is from the Frame class. Frame is one of the most complex widgets in Shear and serves as a base for eighteen other widgets. I have simplified the implementation by breaking the logic into seperate components. This helps internal encaspulation and enforces the Principle of least access between the various internal logic units.


Library: Not yet available

Visual Studio 2010 Solution: Not yet available, use svn

SVN: http://svn.danwellman.com/shear/trunk (Note: Requires a Lua implementation and DirectX August 2009 SDK or later to compile)