Using Text Window GUI without Display

Started by Billbis, Wed 11/03/2015 23:13:38

Previous topic - Next topic

Billbis

Hi there,

I am trying to display a small text that will stay on screen in a non blocking way as far as the player is onto a given region (not that hard).
For aesthetic reasons, I want to use my magnificent Text Window Gui I just created and who gives marvel results with Display functions.
I am a bit lost about how using text window gui without calling the high level Display functions. I am trying to do something like this:

Code: ags
void enterRegion(String text,  int x,  int y) {
    // gTextWindow.Text = text; <- this do note seems to exist at the moment.
    gTextWindow.SetPosition(x, y);
    gTextWindow.Visible=true;
}

Is that possible?
(using AGS 3.4.0.x, for that matter)
Thanks!

monkey0506

The best solution I can think of that would definitely work would be to create an overlay yourself.

You can use GetTextWidth and GetTextHeight to determine the actual size you need for your text area, then pad it out for your borders. Then you would call DynamicSprite.Create with the appropriate size. Using that DynamicSprite, call GetDrawingSurface and draw your text area background, the text, and the borders. Then call Release on the surface, Overlay.CreateGraphical using the DynamicSprite's Graphic, and finally call Delete on your DynamicSprite. Of course, this would all best be wrapped up in a nice helper function that would return the resulting Overlay.

Billbis

I was afraid of that...
Thanks for the tip Monkey! I'll consider doing that, or shifting to a normal GUI with label (I am quite lazy, and it is a MAGS project so I have other things to rush first).
Drawing the borders does sound painful to code to me, with to many for loops inside each others, but if I have time I'll give it a try.

monkey0506

Drawing the borders should be relatively simple. I've never actually used a the Text Window feature of AGS, but assuming the corner sprites and the border sprites all have the same dimensions then it should be as simple as:

1) Calculate the text width (GetTextWidth), add any padding, and add 2x the width of your border sprites - this yields the area_width.
2) Calculate the text height (based on text width) (GetTextHeight), add any padding and add 2x the height of your border sprites - this yields the area_height.
3) Let max_x equal (area_width - sprite_width); let max_y equal (area_height - sprite_height).
4) Draw the corner sprites ((0, 0); (max_x, 0); (0, max_y); (max_x, max_y)).
5) In a loop from sprite_width to (max_x - sprite_width), incrementing by sprite_width, draw the top and bottom borders ((x, 0) and (x, max_y)).
6) In a loop from sprite_height to (max_y - sprite_height), incrementing by sprite_height, draw the left and right borders ((0, y) and (max_x, y)).

There's no need to use nested loops at all. In fact, it might even prove more useful to simply draw the background once, keep that stored in a separate DynamicSprite, and then draw the text onto a copy of that sprite instead. The copy (with text) would be deleted after you've created the Overlay, so you would only need to clean up the one background sprite when you're finished using it. You could easily handle that when the player leaves the region (and recreate it on-the-fly as needed - e.g., set the pointer to null when you're not using it, create a new one if the pointer is null and you need it).

Monsieur OUXX

For someone like Monkey, creating a text control using low-level graphical routines is easy, but not for everyone ;)

I'd recommend sticking to your original idea and using a GUI. You can output your custom text into labels or into a listbox. Listboxes are cool: if you hide the scrollbars and "unselect" the latest entry (so that it has the same color as the other lines), the player won't see it's a listbox. You'll still need to write a small text-wrap function to split your text into lines, but you'd need to do that anyway. There is one such function somewhere around the forums (written by monkey himself ;-)), so you don't even need to think too hard.

 

Billbis

I will have definitely went with Monkey's solution if it was not for a MAGS projects (or if I had no work, or no family, or if I wasn't so lazy).
I am very ashamed to say that for the moment, I have made 4 normal GUIs with different width, and choosing the appropriate one in function of text length. It does the trick for the moment. And when it won't, I'll add a fifth one. :=

SMF spam blocked by CleanTalk