diff --git a/addons/common/CfgFunctions.hpp b/addons/common/CfgFunctions.hpp index d6ad244bd..2db4ebd3c 100644 --- a/addons/common/CfgFunctions.hpp +++ b/addons/common/CfgFunctions.hpp @@ -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); }; diff --git a/addons/common/fnc_getAspectRatio.sqf b/addons/common/fnc_getAspectRatio.sqf deleted file mode 100644 index 05cda5740..000000000 --- a/addons/common/fnc_getAspectRatio.sqf +++ /dev/null @@ -1,70 +0,0 @@ -#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: - Deadfast @ Skypechat 090909, inspired and made CBA compliant by Vigilante ----------------------------------------------------------------------------- */ -SCRIPT(getAspectRatio); - -private _output = toUpper _this; -private _aspectStr = ""; -private _aspectArr = []; -private _return = 0; -private _ratio = (round ((safeZoneW / safeZoneH) * 1000)) / 1000; - -switch (_ratio) do { - case 1: { - _aspectStr = "4:3"; - _aspectArr = [4,3]; - }; - case 1.333: { - _aspectStr = "16:9"; - _aspectArr = [16,9]; - }; - case 1.334: { - _aspectStr = "16:9"; - _aspectArr = [16,9]; - }; - case 1.2: { - _aspectStr = "16:10"; - _aspectArr = [16,10]; - }; - case 0.937: { - _aspectStr = "5:4"; - _aspectArr = [5,4]; - }; - case 0.938: { - _aspectStr = "5:4"; - _aspectArr = [5,4]; - }; - case 1.001: { - _aspectStr = "12:3"; - _aspectArr = [12,3]; - }; - default { - hint str _ratio; - }; -}; - -if (_output == "ARRAY") then {_return = _aspectArr;}; -if (_output == "STRING") then {_return = _aspectStr;}; -if (_output == "NUMBER") then {_return = _ratio;}; - -_return; \ No newline at end of file diff --git a/addons/common/fnc_getFov.sqf b/addons/common/fnc_getFov.sqf deleted file mode 100644 index e9502770e..000000000 --- a/addons/common/fnc_getFov.sqf +++ /dev/null @@ -1,49 +0,0 @@ -#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.7 (vehicle driver initFov). - -Parameters: - (optional) base config fov value corresponding to 1x zoom, defaults to 0.7. - -Examples: - (begin example) - _fovarray = call CBA_fnc_getFov - - _fovarray = 0.75 call CBA_fnc_getFov - (end) - -Returns: - Array [fov,zoom] - -Authors: - q1184 (original code and calculation method) - ceeeb (improved code and new zoom calculation method) - ----------------------------------------------------------------------------- */ - -#define __dist 10000 -#define __xOff 5000 - -private _zoomRef = if (IS_SCALAR(_this)) then {_this} else {0.75}; - -private _widthReal = safeZoneW / 2; -private _safeZoneAspectRatio = (safeZoneW / safeZoneH); -private _screenAspectRatio = _safeZoneAspectRatio * (4 / 3); - -private _pos = positionCameraToWorld [__xOff, 0, __dist]; -private _xPos = (worldToScreen _pos) select 0; -private _deltaX = _xPos - 0.5; - -private _trigRatio = ((_widthReal * __xOff) / (__dist * _deltaX)); -private _fovH = 2 * atan _trigRatio; -private _fovV = _fovH / _screenAspectRatio; -private _fovVRads = _fovV * pi / 180; -private _configFov = _trigRatio / _safeZoneAspectRatio; -private _zoom = _zoomRef / _configFov; - -[_fovVRads, _zoom] diff --git a/addons/common/fnc_getUISize.sqf b/addons/common/fnc_getUISize.sqf deleted file mode 100644 index 6f192dc04..000000000 --- a/addons/common/fnc_getUISize.sqf +++ /dev/null @@ -1,54 +0,0 @@ -#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"] - "STRING" : one of "verysmall", "small", "normal" or "large" - - 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: - Written by Deadfast and made CBA compliant by Vigilante ----------------------------------------------------------------------------- */ -SCRIPT(getUISize); - -#define C_4to3 [1.818, 1.429, 1.176, 1] -#define C_16to9 [2.424, 1.905, 1.569, 1.333] -#define C_16to10 [2.182, 1.714, 1.412, 1.2] -#define C_12to3 [1.821, 1.430, 1.178, 1.001] -#define ERROR {[-1, "error"] select (_output == "STRING")} - -params ["_output"]; - -private _ratio = "STRING" call CBA_fnc_getAspectRatio; -if (_ratio isEqualTo "") exitWith ERROR; - -private _aspIndex = ["4:3", "5:4", "16:9", "16:10", "12:3"] find _ratio; -if (_aspIndex == -1) exitWith ERROR; - -private _sizes = [C_4to3, C_4to3, C_16to9, C_16to10, C_12to3] select _aspIndex; - -private _index = _sizes find ((round (safeZoneW * 1000)) / 1000); - -if (_index == -1) exitWith ERROR; - -if (_output == "STRING") then { - ["verysmall", "small", "normal", "large"] select _index; -} else { - _index; -} \ No newline at end of file diff --git a/addons/ui/CfgFunctions.hpp b/addons/ui/CfgFunctions.hpp index dbd309a30..74053df9a 100644 --- a/addons/ui/CfgFunctions.hpp +++ b/addons/ui/CfgFunctions.hpp @@ -19,6 +19,9 @@ class CfgFunctions { }; PATHTO_FNC(addPauseMenuOption); PATHTO_FNC(progressBar); + PATHTO_FNC(getFov); + PATHTO_FNC(getAspectRatio); + PATHTO_FNC(getUISize); }; }; }; diff --git a/addons/ui/fnc_getAspectRatio.sqf b/addons/ui/fnc_getAspectRatio.sqf new file mode 100644 index 000000000..deb216f5f --- /dev/null +++ b/addons/ui/fnc_getAspectRatio.sqf @@ -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 diff --git a/addons/ui/fnc_getFov.sqf b/addons/ui/fnc_getFov.sqf new file mode 100644 index 000000000..4f3747f08 --- /dev/null +++ b/addons/ui/fnc_getFov.sqf @@ -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 +] diff --git a/addons/ui/fnc_getUISize.sqf b/addons/ui/fnc_getUISize.sqf new file mode 100644 index 000000000..4ec495616 --- /dev/null +++ b/addons/ui/fnc_getUISize.sqf @@ -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