GuiBitmapButtonCtrl and Torque 1.4
by John Kanalakis · 12/18/2005 (6:47 pm) · 9 comments
I tried using the GuiBitmapButtonCtrl that is packaged as-is with the Torque 1.4.0 source code. I placed the buttons into a .gui file using the built-in game designer, but it didn't seem to work. There might be a number of reasons why this control was not working for me, but this is what I did to get it working properly. Hopefully someone else in the same situation might find it useful.
For starters, I created two rectangle-shaped buttons one in a dark color (normal) and one in a bright color (mouse-over highlite). I saved the files as blue_button.png and blue_button_hl.png, respectively.
I started Torque and pressed F10 to enter the GUI designer. I added the new GuiBitmapButtonCtrl elements from the pull-down menu. I entered the path to the button image, hit the apply button, and set the Profile to GuiBitmapBorderProfile. I saved the file as mainMenuGui.gui and ran the game. Here is the .gui code that's auto-generated.
new GuiBitmapButtonCtrl() {
Profile = "GuiBitmapBorderProfile";
HorizSizing = "right";
VertSizing = "top";
position = "521 152";
Extent = "110 20";
MinExtent = "8 8";
Visible = "0";
Command = "";
text = "Single Player";
groupNum = "-1";
buttonType = "PushButton";
bitmap = "./blue_button.png";
helpTag = "0";
};
Within the game, no button appears, just the word 'Button' where the actual button should be. Checking the console.log file, I see the following errors:
Could not locate texture: control_new/client/ui/blue_button_n
Could not locate texture: control_new/client/ui/blue_button_h
Could not locate texture: control_new/client/ui/blue_button_d
Could not locate texture: control_new/client/ui/blue_button_i
From what I can get out of the documentation, when you specify the file blue_button.png, Torque is supposed to create the following files automatically: blue_button.png_n, blue_button.png_h, blue_button.png_d, and blue_button.png_i. But it wasn't creating them for me.
I went ahead and copied my original blue_button.png file and renamed them to match the missing 4 files. I used my highlite version (blue_button_hl.png) as the source for the blue_button.png_h. When I ran the game, I ended up with a few of these console warning messages.
Warning: (d:\green\engine_source\engine\core\resmanager.cc @ 793) ResourceObject::construct: NULL resource create function.
By adding the following statements to engine\game\main.cc (around line 142), everything started working.
ResourceManager->registerExtension(".png_n", constructBitmapPNG);
ResourceManager->registerExtension(".png_h", constructBitmapPNG);
ResourceManager->registerExtension(".png_d", constructBitmapPNG);
ResourceManager->registerExtension(".png_i", constructBitmapPNG);
I'm not sure if this is the best possible fix, but it's working now and I'm happily moving on to the text development challenge.
John K.
For starters, I created two rectangle-shaped buttons one in a dark color (normal) and one in a bright color (mouse-over highlite). I saved the files as blue_button.png and blue_button_hl.png, respectively.
I started Torque and pressed F10 to enter the GUI designer. I added the new GuiBitmapButtonCtrl elements from the pull-down menu. I entered the path to the button image, hit the apply button, and set the Profile to GuiBitmapBorderProfile. I saved the file as mainMenuGui.gui and ran the game. Here is the .gui code that's auto-generated.
new GuiBitmapButtonCtrl() {
Profile = "GuiBitmapBorderProfile";
HorizSizing = "right";
VertSizing = "top";
position = "521 152";
Extent = "110 20";
MinExtent = "8 8";
Visible = "0";
Command = "";
text = "Single Player";
groupNum = "-1";
buttonType = "PushButton";
bitmap = "./blue_button.png";
helpTag = "0";
};
Within the game, no button appears, just the word 'Button' where the actual button should be. Checking the console.log file, I see the following errors:
Could not locate texture: control_new/client/ui/blue_button_n
Could not locate texture: control_new/client/ui/blue_button_h
Could not locate texture: control_new/client/ui/blue_button_d
Could not locate texture: control_new/client/ui/blue_button_i
From what I can get out of the documentation, when you specify the file blue_button.png, Torque is supposed to create the following files automatically: blue_button.png_n, blue_button.png_h, blue_button.png_d, and blue_button.png_i. But it wasn't creating them for me.
I went ahead and copied my original blue_button.png file and renamed them to match the missing 4 files. I used my highlite version (blue_button_hl.png) as the source for the blue_button.png_h. When I ran the game, I ended up with a few of these console warning messages.
Warning: (d:\green\engine_source\engine\core\resmanager.cc @ 793) ResourceObject::construct: NULL resource create function.
By adding the following statements to engine\game\main.cc (around line 142), everything started working.
ResourceManager->registerExtension(".png_n", constructBitmapPNG);
ResourceManager->registerExtension(".png_h", constructBitmapPNG);
ResourceManager->registerExtension(".png_d", constructBitmapPNG);
ResourceManager->registerExtension(".png_i", constructBitmapPNG);
I'm not sure if this is the best possible fix, but it's working now and I'm happily moving on to the text development challenge.
John K.
About the author
John Kanalakis is the owner of EnvyGames, an independent game development studio in Silicon Valley that produces games and tools for Xbox 360, Windows, and the Web.
#2
I'm sure that you're right. Everything that I've read agrees with you, but I just couldn't get it to work and a deep look at the source code didn't really support that. So, I put together this workaround resource that works for both TGE and TSE. Please let me know if GuiBitmapButtonCtrl works for you without modification.
12/22/2005 (10:19 am)
Owen,I'm sure that you're right. Everything that I've read agrees with you, but I just couldn't get it to work and a deep look at the source code didn't really support that. So, I put together this workaround resource that works for both TGE and TSE. Please let me know if GuiBitmapButtonCtrl works for you without modification.
#3
12/22/2005 (3:43 pm)
You are *not* supposed to be including your extension in the bitmap name. What you do is tell it that your bitmap is called "control_new/client/ui/blue_button" and it will add _n automatically to teh name, and search for it with various extensions... so it would use blue_button_n.png or blue_button_n.jpg if either were there. I have never looked to see which one takes preference but I believe it to be png.
#4
Is this really working for you? I've gone through these exact steps with TGE and TSE with no luck. Like you said, the documentation indicates that the 'blue_button.png_n' should be auto-created, but it doesn't for me. If you have been able to get it working, please let me know, I'd be very interested to find out.
In the meantime, this workaround does work. It's not necessarily the best option, but I'm posting it as a resource in case any others (like me) need to press on with other game development tasks.
12/22/2005 (5:22 pm)
Sebastien,Is this really working for you? I've gone through these exact steps with TGE and TSE with no luck. Like you said, the documentation indicates that the 'blue_button.png_n' should be auto-created, but it doesn't for me. If you have been able to get it working, please let me know, I'd be very interested to find out.
In the meantime, this workaround does work. It's not necessarily the best option, but I'm posting it as a resource in case any others (like me) need to press on with other game development tasks.
#5
The reasion your buttons was not working is because when you select the file you need to remove the .png or .jpg and (if you prelabel your files with _n and so forth remove that from the listing in the UI Editor.)
So example
If your bitmap file was "starter.fps/client/ui/inventory/blue_button_n.png"
In the location box you would put "starter.fps/client/ui/inventory/blue_button"
A propare fix for this would be to go into the c/c++ side of the house and update the control to remove the .png / .jpg and any _n and so forth from the path location before it starts doing it checks. But that is not the way it currectly works so jsut follow what I posted above.
12/22/2005 (8:45 pm)
I just tested this and the default bitmap control is working as it is spose to.The reasion your buttons was not working is because when you select the file you need to remove the .png or .jpg and (if you prelabel your files with _n and so forth remove that from the listing in the UI Editor.)
So example
If your bitmap file was "starter.fps/client/ui/inventory/blue_button_n.png"
In the location box you would put "starter.fps/client/ui/inventory/blue_button"
A propare fix for this would be to go into the c/c++ side of the house and update the control to remove the .png / .jpg and any _n and so forth from the path location before it starts doing it checks. But that is not the way it currectly works so jsut follow what I posted above.
#6
12/23/2005 (6:22 am)
Wow thanks for the thread I was going crazy trying to figure out why it wasn't working. :)
#7
12/24/2005 (3:50 pm)
... I know what the _n and the _h are... but what about the other two?
#8
enum {
NORMAL,
HILIGHT,
DEPRESSED,
INACTIVE
} state = NORMAL;
12/24/2005 (7:47 pm)
Here's the complete list straight from the source code...enum {
NORMAL,
HILIGHT,
DEPRESSED,
INACTIVE
} state = NORMAL;
#9
Torque does not create the images for you...it fully expects you to provide all 4 of the images (one image for each of the 4 states listed above), and as has been mentioned, use just the filepath + stem for the name of the base button, i.e.:
If your button base image is /starter.fps/client/ui/inventory/blue_button (what you enter in the filename field), then you'll need to have the following 4 images in that director:
blue_button_n.xxx (where xxx is jpg or png)
blue_button_i.xxx
blue_button_h.xxx
blue_button_d.xxx
What you need to do:
1) Make all 4 buttons
2) Enter the filepath+stem of the button base (just the blue_button portion here, not the _n.png part).
What Torque does:
1) uses the filepath + stem to search for the appropriate expanded 4 buttons (adds in the _n/i/h/d and the .png/.jpg within the execution memory space).
01/03/2006 (3:47 pm)
To make sure the confusion is cleared up:Torque does not create the images for you...it fully expects you to provide all 4 of the images (one image for each of the 4 states listed above), and as has been mentioned, use just the filepath + stem for the name of the base button, i.e.:
If your button base image is /starter.fps/client/ui/inventory/blue_button (what you enter in the filename field), then you'll need to have the following 4 images in that director:
blue_button_n.xxx (where xxx is jpg or png)
blue_button_i.xxx
blue_button_h.xxx
blue_button_d.xxx
What you need to do:
1) Make all 4 buttons
2) Enter the filepath+stem of the button base (just the blue_button portion here, not the _n.png part).
What Torque does:
1) uses the filepath + stem to search for the appropriate expanded 4 buttons (adds in the _n/i/h/d and the .png/.jpg within the execution memory space).

Torque Owner Owen Ortmayer