ctrlMapScreenToWorld: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Added note about finding the screen coordinates of non-fullscreen map controls.)
m (Text replacement - "<sqf>([^↵][^\/]*↵[^\/]*)<\/sqf>" to "<sqf> $1 </sqf>")
 
(59 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{Command|= Comments
{{RV|type=command
____________________________________________________________________________________________


| arma |= Game name
|game1= arma1
|version1= 1.05


|1.05|= Game version
|game2= arma2
____________________________________________________________________________________________
|version2= 1.00


| Convert screen coordinates in map to world coordinates. |= Description
|game3= arma2oa
____________________________________________________________________________________________
|version3= 1.50


| map '''ctrlMapScreenToWorld''' [x, y] |= Syntax
|game4= tkoh
|version4= 1.00


|p1= map: [[Control]] |= Parameter 1
|game5= arma3
|version5= 0.50


|p2= [x, y]: [[Array]] |= Parameter 2
|gr1= GUI Control - Map


| [[Array]] ([[Position2D]] Format) |= Return value
|descr= Converts map screen coordinates into world coordinates. Unlike [[posScreenToWorld]], this command returns world position is format [x, y], otherwise it is identical to [[posScreenToWorld]].
____________________________________________________________________________________________
 
|x1= <pre>_WorldCoord = _Control ctrlMapScreenToWorld _ScreenCoord</pre> |= Example 1
|x2= <pre>_WorldCoord = _Control ctrlMapScreenToWorld [_x,_y]</pre> |= Example 2


____________________________________________________________________________________________
|s1= control [[ctrlMapScreenToWorld]] [x, y]


| [[ctrlMapWorldToScreen]], [[posScreenToWorld]], [[posWorldToScreen]] |= See also
|p1= control: [[Control]] - map control


|p2= x: [[Number]] - screen X
|p3= y: [[Number]] - screen Y
|r1= [[Array]] - world coordinates in format [[Position#Introduction|Position2D]]
|x1= <sqf>_worldCoord = _control ctrlMapScreenToWorld _ScreenCoord;</sqf>
|x2= <sqf>_worldCoord = _control ctrlMapScreenToWorld [_x, _y];</sqf>
|x3= <sqf>_worldCoord = findDisplay 12 displayCtrl 51 ctrlMapScreenToWorld [0.5, 0.5];</sqf>
|seealso= [[ctrlMapWorldToScreen]] [[posScreenToWorld]] [[posWorldToScreen]] [[findDisplay]] [[displayCtrl]]
}}
}}


<h3 style="display:none">Notes</h3>
<dl class="command_description">
<dl class="command_description">


<!-- Note Section BEGIN -->
<dt><dt>
<dd class="notedate">Posted on 2007-04-06 - 23:41</dd>
<dt class="note">[[User:LowFly|LowFly]]</dt>


<dd class="notedate">Posted on April 6, 2007 - 23:41
<dd class="note">You can get the screen coordinates by the [[User_Interface_Event_Handlers|UI Event Handlers]] onMouseButtonDown, onMouseButtonUp, onMouseButtonClick, onMouseButtonDblClick.
<dt class="note">'''[[User:LowFly|LowFly]]'''<dd class="note">''Notes:''


You can get the screen coordinates by the [[User_Interface_Event_Handlers|UI Event Handlers]] onMouseButtonDown, onMouseButtonUp, onMouseButtonClick, onMouseButtonDblClick. 
The return Array is in 2D, you can use it with all set-position commands.
 
<sqf>
The return Array is in 2-D, you can use it with all set-position commands.
_x = returnArray select 0;
<pre>_x = returnArray select 0;
_y = returnArray select 1;
_y = returnArray select 1;</pre>
</sqf>
</dd>


<dt><dt>
<dd class="notedate">
<dt class="note">[[User:Ceeeb|Ceeeb]]</dt>
<dd class="note">
The command parameters are screen position coordinates, which may not equate to the map control's coordinates. A map control's screen coordinates and size can be found use the [[ctrlPosition]] command. This is an issue when using the Arma 3 in-game map, which is not fullscreen (all previous titles used full screen map controls, so map control coords did equate to screen coords).
</dd>


<dd class="notedate">Posted on December 2, 2009 - 16:10
<dt><dt>
<dt class="note">'''[[User:Besselinksjm|Besselinksjm]]'''<dd class="note">''Notes:''
<dd class="notedate">Posted on 2017-08-28 - 0:05</dd>
<dt class="note">[[User:Icaruk|Icaruk]]</dt>
<dd class="note">
This example creates a RscMapControl and hints you the [x,y] position where you clicked.


In VBS2 1.23 this command does not seem to work properly. Therefore when defining UI Event Handlers ''onMouseButtonClick'' and ''onMouseButtonDblClick'' the functions [[onMapSingleClick]] and [[onDoubleClick (VBS2)]] can be used instead, these already provide access to the world coordinates of the click event.
<sqf>
0 spawn {
disableSerialization;
_map = findDisplay 46 createDisplay "RscCredits" ctrlCreate ["RscMapControl", -1];
_map ctrlSetPosition [0,0,1,1];
_map ctrlCommit 0;


<dd class="notedate">
_map ctrlAddEventHandler ["mouseButtonDown", {
<dt class="note">[[User:Ceeeb|Ceeeb]]<dd class="note">
_ctrl = _this select 0;
The command parameters are screen position coordinates, which may not equate to to the map control's coordinates. A map control's screen coordinates and size can be found use the [[ctrlPosition]] command. This is an issue when using the Arma 3 in-game map, which is not fullscreen (all previous titles used full screen map controls, so map control coords did equate to screen coords).
_x = _this select 2;
_y = _this select 3;


<h3 style="display:none">Bottom Section</h3>
_pos = _ctrl ctrlMapScreenToWorld [_x, _y];
hint format ["pos: %1", _pos];
}];
};
</sqf>
</dd>


[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]
</dl>
[[Category:Scripting Commands ArmA|{{uc:{{PAGENAME}}}}]]
[[Category:Command_Group:_GUI_Control|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands ArmA2|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting_Commands_Take_On_Helicopters|{{uc:{{PAGENAME}}}}]]

Latest revision as of 11:35, 3 September 2024

Hover & click on the images for description

Description

Description:
Converts map screen coordinates into world coordinates. Unlike posScreenToWorld, this command returns world position is format [x, y], otherwise it is identical to posScreenToWorld.
Groups:
GUI Control - Map

Syntax

Syntax:
control ctrlMapScreenToWorld [x, y]
Parameters:
control: Control - map control
x: Number - screen X
y: Number - screen Y
Return Value:
Array - world coordinates in format Position2D

Examples

Example 1:
_worldCoord = _control ctrlMapScreenToWorld _ScreenCoord;
Example 2:
_worldCoord = _control ctrlMapScreenToWorld [_x, _y];
Example 3:
_worldCoord = findDisplay 12 displayCtrl 51 ctrlMapScreenToWorld [0.5, 0.5];

Additional Information

See also:
ctrlMapWorldToScreen posScreenToWorld posWorldToScreen findDisplay displayCtrl

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
Posted on 2007-04-06 - 23:41
LowFly
You can get the screen coordinates by the UI Event Handlers onMouseButtonDown, onMouseButtonUp, onMouseButtonClick, onMouseButtonDblClick. The return Array is in 2D, you can use it with all set-position commands.
_x = returnArray select 0; _y = returnArray select 1;
Ceeeb
The command parameters are screen position coordinates, which may not equate to the map control's coordinates. A map control's screen coordinates and size can be found use the ctrlPosition command. This is an issue when using the Arma 3 in-game map, which is not fullscreen (all previous titles used full screen map controls, so map control coords did equate to screen coords).
Posted on 2017-08-28 - 0:05
Icaruk
This example creates a RscMapControl and hints you the [x,y] position where you clicked.
0 spawn { disableSerialization; _map = findDisplay 46 createDisplay "RscCredits" ctrlCreate ["RscMapControl", -1]; _map ctrlSetPosition [0,0,1,1]; _map ctrlCommit 0; _map ctrlAddEventHandler ["mouseButtonDown", { _ctrl = _this select 0; _x = _this select 2; _y = _this select 3; _pos = _ctrl ctrlMapScreenToWorld [_x, _y]; hint format ["pos: %1", _pos]; }]; };