Computer Science Canada

Help With Making Custom GUI

Author:  Danjen [ Sun May 25, 2008 9:12 pm ]
Post subject:  Help With Making Custom GUI

Okay, so I'm trying to make an RPG in turing and I want pretty much everything made custom, to create the illusion of professional quality. Smile
Specifically, what I'm going for is like pop up windows that can contain text (or not). If you've ever played a Final Fantasy game, you should know exactly what I'm aiming for.

I am having two specific issues with this, the first one being that I am not sure of the best way to close the window when it is finished. Yes, I can have it close have a certain period or when a user inputs the 'okay' key, but I'm not sure HOW to do this, especially since this will be a class. Secondly, I have tried without much success to make the text scroll down to the next line as it types, an effect seen in applications like notepad or wordpad.

Here is what I have so far:
Turing:
%unit
View.Set ("offscreenonly,graphics:801;601,nobuttonbar")
class Gui
    export DrawWindow, DrawTextBox

    %%16 and 24 are special scaling factors. Best not to change them
    %%once windows are in place, though easily modifiable before that.
    const font := Font.New ("Courier New:16")
    const xmod : int := Font.Width ("W", font) + 3
    const ymod : int := 24 %24
    const b_ : int := 4 %%Change this to affect all border sizes!

    const BorderColor : int := grey
    const WindowColor : int := brightblue

    proc DrawFont (text_ : string, x_, y_ : int)
        Font.Draw (text_, x_ + 2, y_ - 1, font, black)
        Font.Draw (text_, x_, y_, font, white)
    end DrawFont

    proc DrawWindow (x1_, y1_, xsize_, ysize_ : int)
        assert xsize_ > -1
        assert ysize_ > -1
        const xpad : int := (xsize_ + 1) * xmod
        const ypad : int := (ysize_ + 1) * ymod
        Draw.Box (x1_, y1_, x1_ + xpad, y1_ + ypad, black) %%Outline
        Draw.FillBox (x1_ + 1, y1_ + 1, x1_ + xpad - 1, y1_ + ypad - 1, BorderColor) %%Border
        Draw.Box (x1_ + b_ + 1, y1_ + b_ + 1, x1_ + xpad - b_ - 1, y1_ + ypad - b_ - 1, black) %%Inline
        Draw.FillBox (x1_ + b_ + 2, y1_ + b_ + 2, x1_ + xpad - b_ - 2, y1_ + ypad - b_ - 2, WindowColor) %%Fill
        Draw.Line (x1_ + xpad - 1, y1_ + 1, x1_ + xpad - 1, y1_ + ypad - 1, white) %%Outer R Hilight
        Draw.Line (x1_ + 1, y1_ + ypad - 1, x1_ + xpad - 1, y1_ + ypad - 1, white) %%Outer U Hilight
        Draw.Line (x1_ + xpad - b_ - 2, y1_ + b_ + 2, x1_ + xpad - b_ - 2, y1_ + ypad - b_ - 2, blue) %%Inner R Shadow
        Draw.Line (x1_ + b_ + 2, y1_ + ypad - b_ - 2, x1_ + xpad - b_ - 2, y1_ + ypad - b_ - 2, blue) %%Inner U Shadow
    end DrawWindow

    proc DrawTextBox (text : string, x1_, y1_, xsize_, ysize_ : int)
        DrawWindow (x1_, y1_, xsize_, ysize_)
        const xpad : int := (xsize_ + 1) * xmod
        const ypad : int := (ysize_ + 1) * ymod
        const width : int := (xpad - b_ - 2) - (b_ + 2)
        const height : int := (ypad - b_ - 2) - (b_ + 2)

        for i : 1 .. length (text)
            DrawFont (text (1 .. i), x1_ + (xpad - width) + b_ + 1, y1_ + (ypad - height) + b_ + 1)
            delay (50)
            View.Update
        end for

    end DrawTextBox
end Gui

var Message : pointer to Gui
new Gui, Message
Gui (Message).DrawWindow (0, 0, 32, 3)
Gui (Message).DrawWindow (528, 0, 16, 3)
Gui (Message).DrawTextBox ("Filler filler filler filler filler filler", 294, 252, 20, 2)

Author:  SNIPERDUDE [ Mon May 26, 2008 6:44 am ]
Post subject:  RE:Help With Making Custom GUI

have a global boolean variable that determines whether it is visible or not - every time the user dismisses the thing it will be false, every time the text changes reset the variable.

That's pretty much what I did in mine.

For the other problem - try a text wrap.
so determine the length of the string (Font.Width) and make sure it fits.
Got through it word by word in a loop checking this, whatever doesn't fit becomes a new line.

Just an idea - when I did something like this - I used a custom made Tokenizer (used in java I believe) to help with the breaking down of the string.

Author:  Danjen [ Mon May 26, 2008 7:24 pm ]
Post subject:  RE:Help With Making Custom GUI

The only problem I have with the boolean method is that it would be a global variable and not inclusive to the class itself. Ultimately, I'm trying to make a general case so that I can use this in any number of engines.

Author:  SNIPERDUDE [ Tue May 27, 2008 6:29 am ]
Post subject:  RE:Help With Making Custom GUI

hmmm, the boolean var is an array, and you work with an Index?

ex:

Gui (Message).DrawTextBox (1, "Filler filler filler filler filler filler", 294, 252, 20, 2)

* the first number in the parameters is an index number...


: