Buttons with Custom Bitmap Borders
by Gary Haussmann · 08/07/2005 (1:11 am) · 6 comments
Download Code File
The bitmap border button is a simple gui control that lets you make push buttons with customized borders. The BitmapButton control also lets you make customized pushbuttons, but you have to create and maintain four bitmaps for every single button you use, which is overkill if you just want some fancy looking "OK" and "Cancel" buttons.
The bitmap border button constructs the border by tiling together parts of a bitmap, very similar to the way that the bitmap border control works. There are some sample bitmaps in this resource that you can use as a guideline; basically, you split the bitmap into parts that represent the four sides and four corners of the buttons, in active/inactive/highlighted states. That's 24 parts total you have to build. The easiest way I've found is to create a blank button as you would like it to appear on the screen and then cut that button up into the eight parts you need.
Adding the controls to the engine is easy, but you also have to add a GUI control profile that describes
which bitmap to use for your button borders.
Instructions to add the GuiBitmapBorderButtonCtrl class to your copy of TGE 1.3:
1. Copy the files:
GuiBitmapBorderButtonCtrl.cc
GuiBitmapBorderButtonCtrl.h
to your engine/gui directory, and add those two files to your project, then rebuild it.
2. To use the new control, you'll need some bitmaps and also a new profile. To add blue and orange
buttons to the TGE 1.3 SDK, copy these files into starter.fps/client/ui:
customProfiles.cs (replacing your current one)
blueBorderButton.png
orangeBorderButton.png
3. Now you should be able to create a GuiBitmapBorderButton from the
GUI editor. It works pretty much like a normal text pushbutton, except that
any profile you used needs to specify the bitmap used for drawing the border.
Look at the profiles at the end of customProfiles.cs to see how to set this
value. It is the bitmap field of the profile:
As a further example, I have included a copy of mainMenuGui.gui which already
has some modified buttons in it; just dump it into your client/scripts/ui directory
on top of the current one and run torque to see the changes.
The bitmap border button is a simple gui control that lets you make push buttons with customized borders. The BitmapButton control also lets you make customized pushbuttons, but you have to create and maintain four bitmaps for every single button you use, which is overkill if you just want some fancy looking "OK" and "Cancel" buttons.
The bitmap border button constructs the border by tiling together parts of a bitmap, very similar to the way that the bitmap border control works. There are some sample bitmaps in this resource that you can use as a guideline; basically, you split the bitmap into parts that represent the four sides and four corners of the buttons, in active/inactive/highlighted states. That's 24 parts total you have to build. The easiest way I've found is to create a blank button as you would like it to appear on the screen and then cut that button up into the eight parts you need.
Adding the controls to the engine is easy, but you also have to add a GUI control profile that describes
which bitmap to use for your button borders.
Instructions to add the GuiBitmapBorderButtonCtrl class to your copy of TGE 1.3:
1. Copy the files:
GuiBitmapBorderButtonCtrl.cc
GuiBitmapBorderButtonCtrl.h
to your engine/gui directory, and add those two files to your project, then rebuild it.
2. To use the new control, you'll need some bitmaps and also a new profile. To add blue and orange
buttons to the TGE 1.3 SDK, copy these files into starter.fps/client/ui:
customProfiles.cs (replacing your current one)
blueBorderButton.png
orangeBorderButton.png
3. Now you should be able to create a GuiBitmapBorderButton from the
GUI editor. It works pretty much like a normal text pushbutton, except that
any profile you used needs to specify the bitmap used for drawing the border.
Look at the profiles at the end of customProfiles.cs to see how to set this
value. It is the bitmap field of the profile:
new GuiControlProfile (GuiBitmapBorderButtonTextProfile)
{
opaque = true;
border = 2;
fillColor = "0 0 255";
fillColorHL = "15 89 255";
fillColorNA = "15 89 128";
fontColor = "200 200 120";
fontColorHL = "255 255 255";
fontType = "Arial Bold Italic";
fontSize = 16;
bitmap = "./blueBorderButton";
textOffset = "6 6";
hasBitmapArray = true;
justify = "center";
};As a further example, I have included a copy of mainMenuGui.gui which already
has some modified buttons in it; just dump it into your client/scripts/ui directory
on top of the current one and run torque to see the changes.
About the author
#2
08/07/2005 (6:50 pm)
Try again, should be fixed.
#3
08/08/2005 (4:56 am)
:) I am definately putting this one to use. Thanks a lot.
#4
08/08/2005 (5:48 am)
The arrays are uneven in the bitmap, is this intentional? It distorts the image but I bet you got a reason so I'm curious :)
#5
That's because I am lazy and just took a button I already had made (with button maker) and
cut it up into the parts needed by the code. You can use any sizes you want, with the caveat that
it will stretch the left/right/top/bottom parts to fit the button size, just like the GuiBitmapBorderCtrl.
08/08/2005 (2:59 pm)
Stefan, are you talking about the sizes of the various parts (left, right, topleft, etc.) being a different size?That's because I am lazy and just took a button I already had made (with button maker) and
cut it up into the parts needed by the code. You can use any sizes you want, with the caveat that
it will stretch the left/right/top/bottom parts to fit the button size, just like the GuiBitmapBorderCtrl.
#6
08/09/2005 (4:40 am)
Yeah Gary, that's what I was wondering about. Thanks for the info, I'll take a look. 
Torque Owner David Tan