Game Development Community

Adjusting the size of a gui window

by David Taylor · in Torque Game Builder · 08/02/2006 (10:32 am) · 12 replies

I have a gui window that I made in the gui builder, but I can't adjust the size of it. What I mean by that, is I adjust the size from its 800x600 default to 400x200, and then save it, but when I load it up again, it's gone back to 800x600. Even adjusting it via code doesn't seem to work.

ConversationGui.setText("Look Through The Window");
ConversationGui.setExtent(400, 200);

The first line successfully alters the heading on the window to the sentence. The second line doesn't give me any errors, but the window is still 800x600. Any idea what I'm doing wrong here?

#1
08/02/2006 (10:51 am)
Are you confusing it with resolution? The GUI extent might be set correctly at 400x200, but you also need to check your camera settings, and the game resoultion. They are all independant.

I think most of the demos for example, have the camera set to 100x75. Obviously this is the same regardless of the fact of whether the games runs at 640x480 or 1600x1200.
#2
08/02/2006 (3:31 pm)
The base gui will be stretched to your canvas extents. The extent is to set the relative size of the gui which determines how it behaves when it is resized. If you need something to be 400x200 on the screen, you should put it inside an empty gui control that takes up the whole screen, then position it inside that control at your desired size.
#3
08/02/2006 (10:24 pm)
Or, if you want to add the window:

Do not .add to the canvas:

Canvas.add(ConversationGui);

In fact, add it to the current gui.

Canvas.getContent().add(ConversationGui);
OR
TheNameOfTheGui.add(ConversationGui);

Hope that helps! :)

-- Ricky
#4
08/03/2006 (1:25 am)
Thanks, guys. I've used Ben's approach, and it works fine. :)
#5
08/14/2006 (5:48 am)
Hi guys. The same problem as the first post happened when I made a guibuttonctrl, and so I set it up once again by Ben's method, which means it now fits in at the correct size.

However, I can't change the text on the button using this new method. I called setText on the parent gui control, and it doesn't recognise the command. Is there a way to access the child, (in this case, the button), in order to call setText on it?

If not, I need to find another way whereby my button remains the correct size, and where I can also change the text.
#6
08/14/2006 (7:37 am)
Call setText on the object by name. Say your parent guiControl is called "overlayWindow" and the 400x200 box is called "dialogueOne" then you can just use dialogueOne.setText("blahblahblah");
#7
08/14/2006 (7:09 pm)
Thanks, Ben. Once again, that does the trick. :)
#8
08/17/2006 (1:09 am)
And the saga continues, lol...

Okay, I've got my window and buttons loading, and they all have their own unique text titles, etc.

Now I want to add a sprite image onto one part of the window. I've got the image, and it draws to the screen, but it gets hidden under the window. I think it has something to do with layers, but I've varied the layers of the sprite from 0 to 31 with no change. Is there a way to do this?
#9
08/17/2006 (1:57 am)
You might want to check this out: HERE
#10
08/17/2006 (3:49 am)
Cheers, Scott. That was ideal. :)
#11
08/17/2006 (9:18 am)
I have changed the hierarchy of the buttons I've used. I initially had the guiwindowctrl as its own gui, and each guibuttonctrl as its own gui, but when I pushed them all onto the canvas, I could only click on the last one that was pushed. So I put all the guibuttonctrls into the same gui as the one with the guiwindowctrl. (Hope this makes sense.)

Now that I've done this, all of the buttons are clickable when I run the program, but I can't seem to be able to change the text of the guibuttonctrls, despite naming them and calling setText. The four buttons are named OptionOne, OptionTwo, OptionThree and OptionFour. The code I am using, (which DID work when the guibuttonctrls were mostly unclickable and in their own guis), is here:

%file = new FileObject();
    if(%file.openForRead(%fileName))
    {
        %x=1;
        while(!%file.isEof())
        {
            %line = %file.readLine();
            echo("line" @ %x @ " = " @ %line);
            if(%x == 1)
            {
                OptionOne.setText(%line);
            }
            else if(%x == 2)
            {
                OptionTwo.setText(%line);
            }
            else if(%x == 3)
            {
                OptionThree.setText(%line);
            }
            else if(%x == 4)
            {
                OptionFour.setText(%line);
            }
            %x++;
        }
    }
    else
    {
        error("CANNOT OPEN FOR READ");
    }
    %file.close();
    %file.delete();

To clarify, my gui that this is in reference to consists of a GuiCtrl, a GuiWindowCtrl, a t2dSceneWindow and four GuiButtonCtrls. The Window and scene window are both named, and I can adjust them with similar code, including identical setText code for naming the window.

Any ideas?
#12
08/20/2006 (4:46 am)
Okay, I managed to figure this out. I had to create another guicontrol within the same gui that ocupied the area taken up by the four buttons. That enabled the above code to work. Huzzah!