Game Development Community

dev|Pro Game Development Curriculum

GuiBitmapButtonCtrl Tutorial

by Tim Newell · 02/01/2002 (9:03 am) · 25 comments

Download Code File

GuiBitmapButtonCtrl Tutorial

This tutorial will help you add a new gui control that you can create bitmap based buttons with. It requires 1 script change (for sound when mouse is over) and aside from adding the new .cc and .h file it only contains 2 changes in 1 existing .cc file. All of its properties are set from within the GUI editor. (Bitmap, Highlight Bitmap, and command)

First download the attached zip from above and add guiBitmapButtonCtrl.cc and guiBitmapButtonCtrl.h to your /engine/gui/ directory. Next open your ide and add them both to your project.

This script step is optional and used if you want sound.
Next open fps/client/ui/defaultGameProfiles.cs and add the following code to the end of it:

new GuiControlProfile ("BitmapButtonProfile")
{
   opaque = false;
   border = false;
   soundButtonOver = "AudioButtonOver";
   
};

Now open /engine/gui/guiCanvas.cc and add the following line at the top with the rest of the #include statements:

#include "gui/guiBitmapButtonCtrl.h"

Now go down just a little bit and add the following line with the rest of the IMPLEMENT_CONOBJECT statements:

IMPLEMENT_CONOBJECT(GuiBitmapButtonCtrl);

Now recompile the engine.

Now all you need to do is create 2 bitmaps for every bitmap button one for normal mode and one for highlight mode (when the mouse is over it). Simply open the Gui Editor and set all the fields needed - Profile to BitmapButtonProfile (if you added the script change), Bitmap, Highlight Bitmap and command (which it will perform on clicked).

That is it! Have fun!

-Tim aka Spock
Page «Previous 1 2
#1
02/01/2002 (10:23 pm)
Thanks Tim! You just saved me a lot of work :)
#2
02/07/2002 (5:51 pm)
If you put the IMPLEMENT_CONOBJECT after the #includes in the file in the Zip, it works just as well, and you don't have to modify Canvas.
#3
02/10/2002 (12:37 am)
Yeah I figured...since Torque does it in Canvas with every other gui object I figured Id stick with its standard.
#4
02/16/2002 (12:18 pm)
I seem to have a problem with this, all seems to work ok (can create buttons in the GUI Editor fine), but any saved .gui files that have the button in it won't compile to .dso's (thus don't work) anymore. I miss something stupid?

Edit : Fixed now, Thanks loads Tim.
#5
02/17/2002 (6:11 am)
Yep, I'ge got the same problem as Gareth... if the new Control is in the mainMenuGui.cs, it won't compile... :-( Any ideas??
#6
02/19/2002 (7:54 pm)
I fixed the problem.....sorry about it. The space in Highlight Bitmap was the problem....it seems that it worked fine till I deleted my dso file and after that it would not work anymore. Just update your code with the new code in the zip.

-Tim aka Spock
#7
02/20/2002 (9:15 am)
Cool!! Now it works great - time to work on our GUI now... ;-)Thanx for the tut!!
#8
02/20/2002 (10:14 am)
I'm afraid I'm still having problems :(
If I remember correctly this control worked fine for me in release 1.1.0, but I recently upgraded to 1.1.1 and I can't get it to work at all. I've downloaded the zip file and replaced the files with the ones in the engine\gui directory. In the GUI editor, the Highlight Bitmap field is now listed as "HighlightBitmap" (no space) so it would appear the changes compiled OK. Sadly when I restart my program after saving, the changes I made are not shown on the interface. I have tried jpg, png, and bmp files and none of them work (although they all show up in the editor).
What could I be doing wrong?
Thanks
#9
02/20/2002 (10:25 am)
Err, I had the same problem, but in my case the only problem was that the .cs file was write protected (because I copied all files out of my CVS root) :-) Did you check that?
#10
02/20/2002 (10:51 am)
Thanks Stefan! As soon as I read your post I knew that was it. I had done exactly that to make the control work with 1.1.0, I just forgot to make the gui files writeable again since I downloaded 1.1.1.

Thanks again. :)
#11
02/20/2002 (5:15 pm)
I turn the readonly checkout option off in the CVS and it prevents problems like that. I hate having to change the permissions of all the files.

-Tim aka Spock
#12
03/15/2002 (10:45 am)
Thanks, this was really usefull
:)
#13
03/21/2002 (4:50 pm)
Ok, I must have missed something. I can't seem to aadd sounds. I'll look into it but I can't find the calls in the script to make sounds for button ove and button press. Do they exsist or shall I try to make them?
#14
05/03/2002 (2:09 pm)
well i must be doing somthing wrong ..

i open the guieditor .. add a new menu (guiTSctrl) then to that i try to add the new button .. but when i hit new control i see nothing new listed ... so i hit guibutton ... in the properties on this new button i can click profiles and see the new BitmapButtonProfile so i select that but i dont see any changes from a normal button ... i have hit apply and save after each step and even re-started torque a few times ( just to get it to re-compile the dso's ) ....

am i missing somthing? where do i put the file names for the images? .. i did a clean build in vc6 and i see the new obj's the new source fils created and they wer linked in fine so i figure my new exe is correct.


edit: i cant spell :-)
#15
05/03/2002 (4:12 pm)
ok i figured it out ... dumb read only flag on the exe file
#16
08/11/2002 (3:07 pm)
Excellent. Just what I needed.
Great work!
#17
12/02/2002 (8:41 pm)
I have four of these buttons now - and sometimes the fourth button comes up in 'mouseover' mode. Has anyone else seen that happen?
#18
01/19/2003 (3:59 pm)
Just uploaded a new zip file which has a bug fix that was involved with image swapping in realtime.

Keith: no I havent seen that problem with the stuff Im doing.

-Tim aka Spock
#19
09/10/2003 (9:12 pm)
To get the sound to work I had to fiddle with the profile. It was not finding the profile information for "BitmapButtonProfile" or "GuiBitmapButtonProfile" ...

You need to open fps/client/ui/defaultGameProfiles.cs and add the following code to the end of it:

new GuiControlProfile ("GuiBitmapButtonProfile")
{
   opaque = false;
   border = false;
   soundButtonOver = "AudioButtonOver";   
};


You have to use "GuiBitmapButtonProfile" and you need to create the profile before you start placing buttons or they will use the the "GuiDefaultProfile" and the sounds wont work. "BitmapButtonProfile" wont work either, its not the correct classname.

Viola... sound should work... if you are on windows you may need to place OpenAL32.dll in the working directory of your game exe along with the other dlls
#20
08/25/2004 (10:52 pm)
I don't know why but when I add the new control I only have one place for a bitmap "Bitmap" and when I try to load a bitmap nothing happens... ::this may be a dumb question but what is ide
Page «Previous 1 2