Jump to content
Smart Games

Calling a function to calculate coordinates of UI control element on create possible?

Recommended Posts

Hi there,

 

I wrote a function that helps to calculate x,y,w,h of an element for a defined position (for example the center of the screen).

The function is working fine: I took the numbers I displayed with a hint and wrote them manually to the control. That works.

 

But every time I try something like this, it isn't:

 

    class Background_01 : RscText
    {
        colorBackground[] = {1,1,1,1};
        colorText[] = {1,1,1,1};
        text = "blablabla";

        x = [[[0.1,0.2]], ["MAIN_CENTER"]] call JF_fnc_Coordinates select 0;
        y = [[[0.1,0.2]], ["MAIN_CENTER"]] call JF_fnc_Coordinates select 1;
        w = [[[0.1,0.2]], ["MAIN_CENTER"]] call JF_fnc_Coordinates select 2;
        h = [[[0.1,0.2]], ["MAIN_CENTER"]] call JF_fnc_Coordinates select 3;
    };

 

Just as example.

The function is defined under CfgFunctions.

 

Thanks for your help!

 

   

Share this post


Link to post
Share on other sites
6 minutes ago, Smart Games said:

The function is defined under CfgFunctions.

 

Have you tried preinit?

Share this post


Link to post
Share on other sites

You can set/getVariable in uiNameSpace for your controls, but perhaps I didn't understand what you're trying to "calculate".

Share this post


Link to post
Share on other sites

@pierremgiI would like to calculate the x, - and y coordinates, as well as the height and the width, without having to write down the complete calculation each time. I would then save the invoice for a position such as the center of the screen in a function that I can then quickly call up.

 

Share this post


Link to post
Share on other sites

There are ways you can do what you have shown, but... IMHO the easiest is to instead, use the controls onLoad eventHandler that calls a function to set the controls size in script when the ui is shown.

Spoiler

class Background_Center : ctrlStatic {
    colorBackground[] = {1,1,1,1};
    colorText[] = {1,1,1,1};

    x = 0;
    y = 0;
    w = 0;
    h = 0;

  onLoad = "[ _this select 0, [ 0.1, 0.2 ], 'MAIN_CENTER' ] call JF_fnc_setCtrlPosition";
};

fn_setCtrlPosition.sqf


params[ "_ctrl", "_dimension", "_type" ];

private _dim = [ _dimension, _type ] call JF_fnc_Coordinates;

_ctrl ctrlSetPosition _dim;
_ctrl ctrlCommit 0;

fn_Coordinates.sqf - a guess a what your trying to do


params[ "_dimensions", "_type" ];
_dimensions params[ "_width", "_height" ];

private[ "_dim" ];

_dim = switch ( _type ) do {
	case ( "MAIN_CENTER" ) : {
		[
			safeZoneXAbs + ( safeZoneWAbs / 2 ) - ( _width / 2 ),
			safeZoneY + ( safeZoneH / 2 ) - ( _height / 2 ),
			_width, _height
		]
	};
	case ( "TOP_LEFT" ) : {
		[
			safeZoneXAbs,
			safeZoneY,
			_width, _height
		]
	};
	case ( "BOTTOM_RIGHT" ) : {
		[
			safeZoneXAbs + safeZoneWAbs - _width,
			safeZoneY + safeZoneH - _height,
			_width, _height
		]
	};
};

_dim

 

TEST_MISSION showing three different solutions.

  • Like 1

Share this post


Link to post
Share on other sites

This is exactly what I was looking for. Thank You.

 

But I would like to know whether the file extensions .sqc and .gui are particularly.

So far I've always worked with .hpp files. Also the ending .fncs is new to me.

  • Like 1

Share this post


Link to post
Share on other sites

File extensions can be called anything you like, other than sqf if using the functions library to automatically compile files from the class name, and mod configs seem to need to be called config.cpp. All the engine cares about is that they are text files.

The extensions you see are just what I call my files to differentiate between configs, guis and function library definitions etc.

Another reason is to stop confusion on my PC between .hpp c++ header files and Arma configs, so i call them .sqc  instead.( wish mod configs didnt have to be called .cpp , its a royal pain in the arse )

Spoiler

QTTabBar_fileTypes.PNG?raw=1

  • Like 2

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×