Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move ui functions to ui component, simplify #944

Merged
merged 5 commits into from
Jun 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions addons/common/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,6 @@ class CfgFunctions {
PATHTO_FNC(compileFinal);
};

class Ui {
PATHTO_FNC(getFov);
PATHTO_FNC(getAspectRatio);
PATHTO_FNC(getUISize);
};

class Broken {
PATHTO_FNC(actionArgument);
};
Expand Down
70 changes: 0 additions & 70 deletions addons/common/fnc_getAspectRatio.sqf

This file was deleted.

49 changes: 0 additions & 49 deletions addons/common/fnc_getFov.sqf

This file was deleted.

54 changes: 0 additions & 54 deletions addons/common/fnc_getUISize.sqf

This file was deleted.

3 changes: 3 additions & 0 deletions addons/ui/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class CfgFunctions {
};
PATHTO_FNC(addPauseMenuOption);
PATHTO_FNC(progressBar);
PATHTO_FNC(getFov);
PATHTO_FNC(getAspectRatio);
PATHTO_FNC(getUISize);
};
};
};
48 changes: 48 additions & 0 deletions addons/ui/fnc_getAspectRatio.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "script_component.hpp"
/* ----------------------------------------------------------------------------
Function: CBA_fnc_getAspectRatio

Description:
Used to determine the Aspect ratio of the screen.

Parameters:
_output - string with one of ["ARRAY","NUMBER","STRING"]

Returns:
array, string or number of screenratio i.e. [16,9] or "16:9" or 1.333 ..

Examples:
(begin example)
_ratio = "STRING" call CBA_fnc_getAspectRatio;
_ratio = "ARRAY" call CBA_fnc_getAspectRatio;
_ratio = "NUMBER" call CBA_fnc_getAspectRatio;
(end)

Author:
commy2
---------------------------------------------------------------------------- */
SCRIPT(getAspectRatio);

#define ASPECT_RATIOS ["1.33", "1.25", "1.78", "1.60", "4.00"]
#define ASPECT_RATIOS_NAMES ["4:3", "5:4", "16:9", "16:10", "12:3"]
#define ASPECT_RATIOS_ARRAYS [[4,3], [5,4], [16,9], [16,10], [12,3]]

params [["_returnType", "STRING", [""]]];

private _aspectRatio = getResolution select 4;

if (_returnType == "NUMBER") exitWith {
_aspectRatio / (4/3) // return
};

_aspectRatio = ASPECT_RATIOS find (_aspectRatio toFixed 2);

if (_returnType == "STRING") exitWith {
ASPECT_RATIOS_NAMES param [_aspectRatio, "error"] // return
};

if (_returnType == "ARRAY") exitWith {
ASPECT_RATIOS_ARRAYS param [_aspectRatio, [-1, -1]] // return
};

nil
35 changes: 35 additions & 0 deletions addons/ui/fnc_getFov.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "script_component.hpp"
/* ----------------------------------------------------------------------------
Function: CBA_fnc_getFov

Description:
Get current camera's vertical field of view in radians and zoom.

Zoom is relative to specified config FOV, defaults to 0.75 (vehicle driver initFov).

Parameters:
(optional) base config fov value corresponding to 1x zoom, defaults to 0.75.

Examples:
(begin example)
private _fieldOfView = [] call CBA_fnc_getFov select 0;
private _zoom = 0.75 call CBA_fnc_getFov select 1;
(end)

Returns:
Array [fov,zoom]

Authors:
q1184 (original code and calculation method)
ceeeb (improved code and new zoom calculation method)
streamlined by commy2
---------------------------------------------------------------------------- */

params [["_baseFOV", 0.75, [0]]];

private _trigRatio = safeZoneW / 2 / ((worldToScreen positionCameraToWorld [10000, 0, 10000] select 0) - 0.5);

[
rad (2 * atan _trigRatio / (getResolution select 4)),
_baseFOV * (safeZoneW / safeZoneH) / _trigRatio
]
45 changes: 45 additions & 0 deletions addons/ui/fnc_getUISize.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "script_component.hpp"
/* ----------------------------------------------------------------------------
Function: CBA_fnc_getUISize

Description:
Used to determine the UI size of the screen.

Parameters:
_output - the desired output format, either "NUMBER" or "STRING".

Returns:
If the desired output format is

"NUMBER": an index into ["verysmall","small","normal","large","verylarge"]
"STRING": one of "verysmall", "small", "normal", "large" or "verylarge"

If an error occurs, the function returns either the number -1 or
the string "error", depending on the desired output format.

Examples:
(begin example)
_uiSize = "STRING" call CBA_fnc_getUISize;
(end)

Author:
commy2
---------------------------------------------------------------------------- */
SCRIPT(getUISize);

#define UI_SCALES [0.47, 0.55, 0.7, 0.85, 1]
#define UI_SCALES_NAMES ["verysmall", "small", "normal", "large", "verylarge"]

params [["_returnType", "STRING", [""]]];

private _uiScale = getResolution select 5;

if (_returnType == "STRING") exitWith {
UI_SCALES_NAMES param [UI_SCALES find _uiScale, "error"] // return
};

if (_returnType == "NUMBER") exitWith {
UI_SCALES find _uiScale // return
};

nil