Game Development Community

dev|Pro Game Development Curriculum

guiShadowButtonCtrl

by J. Donavan Stanley · 12/03/2002 (8:26 am) · 5 comments

Download Code File

www.jdonavan.net/shadowbutton.jpg
guiShadowButtonCtrl is a specialized bitmap button control. It draws it's bitmap with alpha channel support allowing all of the typical button state images to be built from one source image. The hover state image contains a "shadow" of the image contained in the source bitmap that is generated from the alpha channel of the source bitmap.

To accomplish the rendering tasks, you (or your art staff) will need to provide the button with a 4-channel bitmap. This is an ARGB bitmap, where the first channel is the alpha channel. I used Photoshop to generate my test images, though I'm sure plenty of other lesser-expensive applications provide alpha-channel support however many of them don't support alpha channels for image formats that Torque supports. To solve this little dilemma I've included a small utility project called "rawtosbi" which will take a raw bitmap with an alpha channel and write it back out with the extension ".sbi" with a minimal header (the width and height). While there's no reason why any image format with an alpha channel wouldn't work with the control, it's only been tested with SBI files.

When you save your source bitmaps as raw files make sure you specify 4 channels, 8 bits depth, interlaced and a header size of 0.

Installation:

BACKUP YOUR SOURCE

Make changes to the following files:
engine\game\main.cc:
In initLibraries() add the following near line 146:
ResourceManager->registerExtension(".sbi", constructBitmapSBI);


engine\gui\guiCanvas.cc:
At the top of the file after the other includes (near line 42):
#include "gui/guiShadowbuttonCtrl.h"
With the other IMPLMENT_CONOBJECT lines (near line 76)
IMPLEMENT_CONOBJECT(GuiShadowButtonCtrl);

dgl\gBitmap.cc
In allocateBitmap (near line 129)
Change:
case RGBA: bytesPerPixel = 4;
To:
case RGBA:
case Raw:
bytesPerPixel = 4;


Add the following function at the end of the file:
ResourceInstance* constructBitmapSBI(Stream &stream)
{
GBitmap *bmp = new GBitmap;
if(bmp->readSBI(stream))
return bmp;
else
{
delete bmp;
return NULL;
}
return NULL;
}



dgl\gBitmap.h
With the other "construct" prototypes (near line 32):
extern ResourceInstance* constructBitmapSBI(Stream& stream);

In the BitmapFormat enum (near line 49):
Change:
Luminance = 7
To:

Luminance = 7,
Raw = 8


With the other "read" prototypes (near line 133):
bool readSBI(Stream& stream); // locatedin bitmapRaw.cc


Add bitmapRaw.cc, guiShadowButtonCtrl.cc and guiShadowButtonCtrl.h to the project.

Do a clean build.

#1
11/27/2002 (11:45 am)
Bleh forgot the domain name on the image here it is:

www.jdonavan.net/shadowbutton.jpg
#2
12/03/2002 (4:46 pm)
It doesn't look like I can download it. :) Any chance it wasn't uploaded or was uploaded improperly?

- Tra'Hari
#3
12/06/2002 (8:00 am)
Hmm Very odd for some reason the GG link isn't working. You can download it from my server at: www.jdonavan.net/guiShadowButtonCtrl.rar
#4
12/08/2002 (9:07 pm)
they use url and /url instead.:)

www.jdonavan.net/guiShadowButtonCtrl.rar
#5
04/09/2004 (11:01 pm)
First I got this error:
\torque\engine\gui\guiShadowButtonCtrl.cc(818): error C2653: 'GuiMouseEventCtrl' : is not a class or namespace name
\torque\engine\gui\guiShadowButtonCtrl.cc(833): error C2653: 'GuiMouseEventCtrl' : is not a class or namespace name

So I tried adding #include "gui/guiMouseEventCtrl.h" to guiShadowButtonCtrl.cc but now it gives me this error:
\torque\engine\gui\guiShadowButtonCtrl.cc(818): error C2352: 'GuiMouseEventCtrl::onMouseMove' : illegal call of non-static member function
\torque\engine\gui\guiShadowButtonCtrl.cc(833): error C2352: 'GuiMouseEventCtrl::onMouseMove' : illegal call of non-static member function

Am I missing another addon that your using? Or maybe something has been deprecated in the last 2 years lol.