alignment of label in a gui from script

Started by fanton, Sat 15/05/2004 15:42:07

Previous topic - Next topic

fanton

is there any way one can change the alignment of label inside a gui from the script? i have made a indy-like label using a non-click-able transparent gui wich has one label with @overhotspot@ and in my repeatedly execute i have a script that tells that gui to follow the mouse. thank you Alynn.  but, when i go near the edge of the screen the text goes OUTSIDE of the visible area. i can change the posision of the gui, but then the text will look awfull. if i have a 100 px gui, and the text takes up only 50px, when i change the position of the gui, the text will have a 50px space between it and the cursor.

Ex: ^ = cursor | = edge ..=empty space
           |
Barell..|...........
    ^    |

becomes
                      |
Barrell............|
                    ^|

I have looked trough the manual and there is no such functions available and there is no such thing as a SetGuiLabelAlignment, but there is a SetGuiLabelPosition and a SetGuilabel... (i forgot). only two of them for label. i can use GetObjectsomethingsomething but is just to return a boolean or a int number.

I tried to make this myself. I know that the whol game uses 320x240 even at 800x600. At least i like it that way. Therefore changing resolution should not affect the way it behaves. I know that each letter takes an amout of pixels "n." I need to get what is the name of the hotspot and move the label accordingly.

Now, how would I get the hotspot's name? ??? I am a beginner, but I am able to work around some things.

PS (offtopic) the AGS script language looks like C language. (NOT C++ with overloads >> or :: etc) but with dot operator (join) mouse.x that is a struct, right? deftype struct mouse { int x, y; } ;D  ::)

Scorpiorus

#1
Right idea, you can retrieve the name of whatever is under the mouse cursor with a GetLocationName (int x, int y, string buffer) function:

global repeatedly execute:

string locationName;
StrCopy(locationName, "");
GetLocationName(mouse.x, mouse.y, locationName);
SetLabelText (<GUI>, <LABEL>, locationName);

// getting location name length:
int locationWidth = GetTextWidth(locationName, <font>);

// adjusting GUI position accordingly:
int offset = 0;

if (mouse.x + locationWidth > 320) offset = locationWidth;

SetGUIPosition(<GUI>, mouse.x - offset, mouse.y);


QuoteI tried to make this myself. I know that the whol game uses 320x240 even at 800x600. At least i like it that way.
Btw, at 800x600 the viewport resolution is 400x300 (twice as little).
Just for reference:
Ã,  ResolutionÃ,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã, viewport
at 320x200, 640x400 ---> 320x200
at 320x240, 640x480 ---> 320x240
at 400x300, 800x600 ---> 400x300


QuotePS (offtopic) the AGS script language looks like C language. (NOT C++ with overloads >> or :: etc) but with dot operator (join) mouse.x that is a struct, right? deftype struct mouse { int x, y; }
Yeah, AGS is similar to C and you can have structs but it's unofficial unsupported feature because you must not declare a string within the struct:

struct MOUSE {
Ã,  int x, y;
Ã,  string text;
};

MOUSE myMouse; // declaring a var of MOUSE type

It is important because AGS compiler won't say that something is wrong but a data corruption may occur.

btw, no need for typedef :)

fanton

thanks very much. now its a bit easier to make my label look acceptable.

hm. but i wonder. since on 800x600 the viewport is 400x300, would it make a diffrence if i script the game for a viewport of 320x240? or do i need a

if ResolutionIs = ???... i don't know the function, if there is one or the variable name. but i think i have to add something similar when working with the viewport.

anyway. i will show you the complete script when i am done. it will add lables indy-style to the game. i am trying to make a game without menus ;D

i don't know how to get around the inventory. i will probably add a pop-up gui.

Scorpiorus

#3
Quote from: avatar on Sun 16/05/2004 03:09:58hm. but i wonder. since on 800x600 the viewport is 400x300, would it make a diffrence if i script the game for a viewport of 320x240? or do i need a

if ResolutionIs = ???... i don't know the function, if there is one or the variable name. but i think i have to add something similar when working with the viewport.
Reasonable question. You see, if you made a game for, to say, 640x480 then the only resolutions available from the game setup are 640x480 and 320x240, and they use the same viewport resolution (320x240). Similarly, if it's built for 800x600, setup allows only 800x600 and 400x300 (again both use 400x300). But if you decide to change the resolution in mid-design then yes you'll may encounter a problem regarding of changing the viewport resolution as well. There are no means in AGS 2.6 SP1 to report current viewport width and height but the next version (2.61) will feature new variables: system.viewport_width and system.viewport_height, thus you can make your script portable for any resolutions available, for instance:

if (mouse.x + locationWidth > system.viewport_width) offset = locationWidth;

fanton

i would ask to add something alse for scripting.

SetLabelTextAlignment (int GUI, int OBJECT, LEFT|CENTER|RIGHT)

one might think it is not very useful. but if you be using a gui to put the text inside you might need it to play around with the text instead of having it forever in one position.

now. thank god i don't need to play around with the viewports. my game will be 640 x 480 because my graphics designer wants something than looks nice (he draws nice backgrounds :P) and i want something fast. 800 x 600 gets slow with loads of effects.

but thank you for the information. thanks very much. i've been doing noting yesterday but here i go again today. thank you.  ::)

there are a couple of small functions missing from ags but one can get around them. when i need something that is not there, i will then see which ones. but ags is pretty fine  ;)

i would strongly strongly suggest double-clicks for both left and right mouse buttons.

again, thank you for the information

Scorpiorus

Quote from: avatar on Sun 16/05/2004 15:09:51
i would ask to add something alse for scripting.

SetLabelTextAlignment (int GUI, int OBJECT, LEFT|CENTER|RIGHT)
Yes, a function like that one would be useful. A workaround is to make three GUIs (or one GUI and three labels) - each label having a certain alignment and display a text on one label or another.

Quotei would strongly strongly suggest double-clicks for both left and right mouse buttons.
It's not there because it can be workarounded as you know :)

SMF spam blocked by CleanTalk