Game Development Community

Can I change the font for Gui text fields, etc?

by John Klimek · in Torque Game Builder · 02/25/2006 (6:48 am) · 10 replies

Can I change the font for Gui controls such as GuiTextCtrl, etc?

Also, why is it that the screen layout in design-mode never seems to match "run-time mode"? What I mean is that lets say I have an 800x600 gui with logoblack (the GG black logo) as my background. I then place a button (in design-mode) directly above the R in Torque. If I press "F10" to see "run-time mode" the button is no longer above the R, but instead its MUCH further away. Because of this it's nearly impossible to position Gui elements in design-mode because they never end up where you think they will...

Thanks for any help...

#1
02/25/2006 (7:07 am)
All gui controls make use of Profiles. Have a look for the defaultProfiles.cs and customProfiles.cs files in common and your game dir.

You can change the font for the GuiTextCtrl by finding the profle it uses and changing the font setting of the profile. This will change the font for ALL GuiTextCtrls that share that profile though, so you may want to make a new profile just for that one control if you only want to change the font in that one case.

You can also set the colour of the font in the profile. However it is possible to change the font colour without changing profile since soem profiles setup multiple colours that they support, you can then switch between these by embedding \c0 \c1 \c2 etc in your string. Again there should be examples in the profiles file.

As for why your R button moves, you need to look at the horizSizing and vertSizing properties.
#2
02/25/2006 (7:29 am)
Thanks for the reply!

What are horizSizing and vertSizing?

Furthermore, is there any documentation on the Gui editor? (what all of those fields mean, etc...) There seems to be a whole ton of fields and I have no idea what they mean or do... (such as alt command, accelerator, internal name, textid, fudge factor, variable, etc...)
#3
02/25/2006 (12:33 pm)
HorizSizing and vertSizing are used to specify how you want the object to scale and position itself compared to the parent GUI.

I have no idea if you'll be able to see this or not, but here's a resource on what the different values for horiz/vertSizing do.

As for the other commands, there are lots of various documentation bits and pieces that go over the GUI objects, some are probably in TGE-specific places (and therefore unavailable to TGB-only owners), I recommend searching on the GUI object type and finding what you can and can't access, flip around in TDN for GUI-specific stuff, and most importantly, if you're C code savvy, refer to the engine source. That is by far the ultimate keeper of the GUI knowledge. Lots of fantastic little gems hidden away that aren't even in most docs. :)

(and to scan over the other fields you mention to get you started:

Alt command: used in circumstances where the control has more than one method of activation. For example, double-clicking on an item in a textList, or when you press the enter key on a text entry field.

accelerator: this assigns a shortcut key that would activate the control as if you clicked on it. So if you assigned 'enter' to a buttonGui, pressing enter when that gui is active would cause it to trigger as if you clicked on the button with the mouse.

Don't know internal name or textid and can't find them in the engine source either. Might not be default functionality (or new in 1.4 perhaps)

fudgeFactor: a hard offset to add to gui Frames so they can be nudged if they don't exactly align themselves properly when a gui scales

variable: the name of a variable that would be used to set the content of this gui control, if applicable. For example, a guiTextControl would automatically update to whatever the contents of the global variable $titleText if you set the variable value to 'titleText', so you wouldn't have to know every time the title changed and call .setText() on the gui control. Pretty handy.
#4
02/25/2006 (1:01 pm)
Thanks a ton for the help!!
#5
02/25/2006 (1:11 pm)
Errrr... just a few more questions =)

1) The accelerator field: If I have a GuiBitmapCtrl that contains two GuiTextEditCtrls and a GuiButtonCtrl, if I assign "" (how do I do this?) to the GuiButtonCtrl accelerator field, I can press anywhere on my Gui (such as the GuiTextEditCtrls), it will simulate a button press?

2) From what you're saying it sounds like I need to use the "variable" field in order to access the data from my Gui inside of script. My question would then be, how does scope affect accessing that variable? For example, let's say I do Canvas.PushDialog(LoginGui) and then I have a button that calls ConnectToServer(); and reads from text boxes on my gui. If I use Canvas.PopDialog(LoginGui), can I no longer access those Gui text field global variables?

I'm a bit confused because it seems like I would use syntax such as LoginGui.myTextField.Value or something to access data from Gui elements... (assuming they were loaded [eg. Canvas.PushDialog])

Sorry for the confusing questions! I really, really appriciate all of the help!
#6
02/25/2006 (1:36 pm)
1. just put the keyboard key's name in the 'accelerator' field (or put accelerator = ''; in the gui definition in the .gui source file), for the enter key it happens to be 'enter'. Check engine\sim\actionMap.cc for a list of all the names of non alphanumeric keys.

TextEditCtrls are sort of special, in that they override keypresses when the cursor is active inside them. I'm not sure offhand what the exact behavior is, but I'm guessing the accelerator functionality on a gui is suspended while text is being entered. The enter key while the cursor is inside a textEditCtrl will cause the 'altCommand' to be called by default.

2. The variable field basically binds the contents of that gui to a global variable so they stay the same automatically. When one changes, the other updates immediately.

The manual way to interact with a control is to use its method calls, such as LoginGui.myTextField.getValue() and LoginGui.myTextField.setText(). You don't have to use the 'variable' parameter, but it can be very convenient. For example, when you have a global variable $score which you change in a lot of places in your script and you want a game HUD to always show the current score. Setting the GuiTextEditCtrl's 'variable' parameter to 'score' would do all the work for you and prevent the need to put "MyGameHUD.scoreDisplay.setText($score);" every place the $score variable changes.

The Options dialog uses the 'variable' parameter in several places, so check that out for an example.

By the way, controls that are created are always available, whether they're visible via PushDialog or not. So from the moment you define the GUI (be that by exec'ing it in a .gui file, or doing it on-the-fly in script with 'new' calls) you can access the controls and its methods, so scoping doesn't apply. This will be true until you call the object's .delete() method, where the control gets completely obliterated.
#7
02/25/2006 (3:43 pm)
For the TextID field you need to have a look at the TGE language localisation section on TDN. It works really well when you overcome a few subtle hurdles - we now have an English, Dutch and Estonian GUI system selectable at the click of a button and ready to accept more languages as we get the translation files back.
#8
02/25/2006 (6:07 pm)
Also take a look at the GuiMLTextCtrl. It has more control code available for it than a basic text control.
#9
02/25/2006 (10:43 pm)
Ok, I still don't understand horizSizing and vertSizing, but I'll keep fooling around with it until it makes sense...

Until then, I seem to be having a problem (?) accessing my Gui data elements.

It seems like whenever I name a GuiTextEditCtrl, it uses that as it's variable name.

For example,

LoginGui.myTextBox.getValue() -- returns an error (Unable to find object)

However, myTextBox.getValue() WORKS.

The problem is that I don't want tons of global variables (or whatever you'd call that). How can I remove global access and force myself to use LoginGui.myTextBox?

Thanks again for all of your help!
#10
02/25/2006 (10:57 pm)
Generally the structure of the gui obejcts aren't hierarchical by nature. If you create a .gui script using the gui tool and then open the script, the controls will be nested layout-wise but not data-wise.

Because it seems it is the way the gui objects were designed, I've just accepted this approach and never really spent any time attempting to scope them, aside from using a naming convention that does enough to guarantee uniqueness (e.g. "btnCtrl_mainMenuGui_startGame").

Torquescript has the concept of global variables ($whatever) but also almost all objects are global by name by default, unless you don't give them a name, then they're only global by ID. :) So I wouldn't sweat having those hanging out there like that.