wGui - Resources

wGui now has a simpler method for handling resources. The CResourceHandle class (and it's derived classes) is a smart handle, so it automatically keeps track of how many times a resource is in use and can free the resource when it's no longer needed. These classes are contained in wg_resource_handle.h/cpp.

The CBitmapResourceHandle class is specifically designed for bitmaps, and is a wrapper for an SDL_Surface. This surface is automatically freed when the reference count for the bitmap goes to zero.
There is also a CBitmapFileResourceHandle class that takes a file name in it's constructor and will allocate a unique resource ID and load the bitmap into the handle. This simplifies using external resources greatly as the programmer no longer has any need to worry about properly deallocating the bitmap when they're done with it. The unique resource ID can be used to get more handles to the bitmap (as long as the reference count for the handle hasn't hit zero and the bitmap freed), simply by calling CBitmapResourceHandle with the resource ID.

For example:

CBitmapFileResource MyResource("mybitmap.bmp");
TResourceId myBitmapResourceId = MyResource.GetResourceId();
CBitmapResource MyResourceRef(myBitmapResourceId);
// MyResourceRef is the exact same as MyResource

While it isn't enforced, Resource handles are intended to be read only. Keep this in mind as in the future this may be enforced.

The CStringResourceHandle is a class for handling string resources. While this may seem a little foolish, it's actually quite practical since it allows you to put all of the strings for a project in one file, and just refer to them via their resource IDs. This makes localizing the strings to other languages much easier.

wGui internally uses a number of resources as well, which are contained in the CwgBitmapResourceHandle and CwgStringResourceHandle classes. These resources include things like commonly used bitmaps (i.e. arrows, icons, etc). These are contained in wg_resources.h/cpp.

Resource IDs should all be unique. IDs below 1000 are reserved for wGui provided resources. User created resources should use IDs between 1000 and 9999, or should use AUTO_CREATE_RESOURCE_ID. Resources created using AUTO_CREATE_RESOURCE_ID start counting at 10000.