ctrlCreate: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "<sqf>([^↵][^<]*↵[^<]*)<\/sqf>" to "<sqf> $1 </sqf>")
 
(122 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{Command|Comments=
{{RV|type=command
____________________________________________________________________________________________


| arma3 |Game name=
|game1= arma3
|version1= 1.26


|1.26|Game version=
|gr1= GUI Control
____________________________________________________________________________________________


| Creates a new control in the given display. The control class could be existing class from [[configFile | main config]] or custom class defined in [[missionConfigFile | mission config]] (mission config is searched first). Some of the common controls defined in main config that can be used with this command:
|descr= Creates a new control in the given display.<br>
* <tt>RscText</tt> - simple text box
The control class could be an existing class from the [[configFile | main config]] or a custom class defined in the [[missionConfigFile | mission config]].
* <tt>RscTextMulti</tt> - simple multiline text box
The main config is searched first, if the class does not exist there, the mission config is searched.
* <tt>RscPicture</tt> - simple picture box
Some of the common controls defined in the main config that can be used with this command:
* <tt>RscPictureKeepAspect</tt> - picture box that doesn't stretch picture
<spoiler text="Show list">
* <tt>RscEdit</tt> - input box
{{Feature|informative|This list contains controls which are guaranteed to work with this command. However, controls not listed here should work as well - as long as they are properly defined.}}
* <tt>RscEditMulti</tt> - multiline input box
* <tt>RscEditReadOnly</tt> - input box with [[DialogControls-EditBox | <tt>canModify {{=}} false;</tt>]] (since v1.97)
* <tt>RscEditMultiReadOnly</tt> - multiline input box with [[DialogControls-EditBox | <tt>canModify {{=}} false;</tt>]] (since v1.97)
* <tt>RscTree</tt> - tree view control
* <tt>RscTreeSearch</tt> - searchable tree view control (see Example 4)
* <tt>RscVideo</tt> - picture control with autostart for video texture (see [[BIS_fnc_playVideo]])
* <tt>RscVideoKeepAspect</tt> - picture control for video to keep original video aspect ratio
* <tt>RscButtonMenuBIKI</tt> - shortcut button with url pointing to "https://community.bistudio.com/wiki/" (since v1.97)
* <tt>RscControlsGroup</tt> - default controls group
* <tt>RscControlsGroupNoScrollbars</tt> - controls group without scrollbars
* <tt>RscControlsGroupNoHScrollbars</tt> - controls group without horizontal scrollbar
* <tt>RscControlsGroupNoVScrollbars</tt> - controls group without vertical scrollbar|DESCRIPTION=
____________________________________________________________________________________________


| display '''ctrlCreate''' [class, idc, controlsGroup] |SYNTAX=
{{{!}} class="wikitable" width="100%"
! Class !! Description !! Available since
{{!}}-
{{!}} RscText {{!}}{{!}} simple text box {{!}}{{!}}
{{!}}-
{{!}} RscStructuredText {{!}}{{!}} text box which supports [[Structured Text|structured text]] {{!}}{{!}}
{{!}}-
{{!}} RscTextMulti {{!}}{{!}} simple multiline text box {{!}}{{!}}
{{!}}-
{{!}} RscPicture {{!}}{{!}} simple picture box {{!}}{{!}}
{{!}}-
{{!}} RscPictureKeepAspect {{!}}{{!}} picture box that doesn't stretch picture {{!}}{{!}}
{{!}}-
{{!}} RscEdit {{!}}{{!}} input box {{!}}{{!}}
{{!}}-
{{!}} RscEditMulti {{!}}{{!}} multiline input box {{!}}{{!}}
{{!}}-
{{!}} RscEditReadOnly {{!}}{{!}} input box with [[DialogControls-EditBox | {{hl|c= canModify {{=}} false;}}]] {{!}}{{!}} {{GVI|arma3|1.98}}
{{!}}-
{{!}} RscEditMultiReadOnly {{!}}{{!}} multiline input box with [[DialogControls-EditBox | {{hl|c= canModify {{=}} false;}}]]{{!}}{{!}} {{GVI|arma3|1.98}}
{{!}}-
{{!}} RscTree {{!}}{{!}} tree view control {{!}}{{!}}
{{!}}-
{{!}} RscTreeMulti {{!}}{{!}} multi-select tree view {{!}}{{!}} {{GVI|arma3|2.02}}
{{!}}-
{{!}} RscTreeSearch {{!}}{{!}} searchable tree view control (see Example 4) {{!}}{{!}}
{{!}}-
{{!}} RscVideo {{!}}{{!}} picture control with autostart for video texture (see [[BIS_fnc_playVideo]]) {{!}}{{!}}
{{!}}-
{{!}} RscVideoKeepAspect {{!}}{{!}} picture control for video to keep original video aspect ratio {{!}}{{!}}
{{!}}-
{{!}} RscButtonMenuBIKI {{!}}{{!}} shortcut button with url pointing to "https://community.bistudio.com/wiki/" {{!}}{{!}} {{GVI|arma3|1.98}}
{{!}}-
{{!}} RscControlsGroup {{!}}{{!}} default controls group {{!}}{{!}}
{{!}}-
{{!}} RscControlsGroupNoScrollbars {{!}}{{!}} controls group without scrollbars {{!}}{{!}}
{{!}}-
{{!}} RscControlsGroupNoHScrollbars {{!}}{{!}} controls group without horizontal scrollbar {{!}}{{!}}
{{!}}-
{{!}} RscControlsGroupNoVScrollbars {{!}}{{!}} controls group without vertical scrollbar {{!}}{{!}}
{{!}}}
</spoiler>
{{Feature|important|If you are creating [[CT_MAP]] control dynamically, use [[ctrlMapSetPosition]] to update control position instead of [[ctrlSetPosition]].}}


|p1= display: [[Display]] - Display in which control will be created  |PARAMETER1=
|s1= display [[ctrlCreate]] [class, idc, controlsGroup]


|p2= [class, idc, controlsGroup]: [[Array]] |Parameter2=
|p1= display: [[Display]] - display in which control will be created


|p3= class: [[String]] - Existing classname (see [[ctrlCreate/classnames]]) of the new control (Since Arma 3 v1.69.141213 it is possible to use classes defined in mission config)  |PARAMETER3=
|p2= class: [[String]] or {{GVI|arma3|2.14|size= 0.75}} [[Config]] - existing classname (see [[ctrlCreate/classnames]]) of the new control; {{GVI|arma3|1.70|size= 0.75}} it is possible to use classes defined in mission config


|p4= idc: [[Number]] - IDC of the new control (use -1 if you don't care what it should be) |PARAMETER4=
|p3= idc: [[Number]] - IDC of the new control. Use -1 if not needed
{{Feature|warning|Be careful when setting the IDC to {{hl|-1}} if the GUI also contains a [[CT_LISTNBOX]] since {{hl|idcLeft}} and {{hl|idcRight}} by default have <syntaxhighlight lang="cpp" inline>idc = -1;</syntaxhighlight>.}}


|p5= controlsGroup (Optional): [[Control]] - Creates controls in existing controls group |PARAMETER5=
|p4= controlsGroup: [[Control]] - (Optional, default [[controlNull]]) creates controls in existing controls group


| [[Control]] |RETURNVALUE=
|r1= [[Control]]


|x1= <sqf>_display ctrlCreate ["RscText", 1234];</sqf>


|x1= <code>_display [[ctrlCreate]] ["RscText", 1234];</code>|EXAMPLE1=
|x2= <sqf>
|x2= <code>_map = [[findDisplay]] 46 [[ctrlCreate]] ["RscMapControl", -1];
_map = findDisplay 46 ctrlCreate ["RscMapControl", -1];
_multiLineText = [[findDisplay]] 46 [[ctrlCreate]] ["RscTextMulti", -1];
_multiLineText = findDisplay 46 ctrlCreate ["RscTextMulti", -1];
_multiLineEdit = [[findDisplay]] 46 [[ctrlCreate]] ["RscEditMulti", -1];</code>|EXAMPLE2=
_multiLineEdit = findDisplay 46 ctrlCreate ["RscEditMulti", -1];
|x3= <code>myControl = [[findDisplay]] 0 [[ctrlCreate]] ["RscText", 1234, [[findDisplay]] 0 [[displayCtrl]] 2300];</code>|EXAMPLE3=
</sqf>
|x4= Create Tree View control with search. Available <tt>RscTreeSearch</tt> class is hardcoded to be used with <tt>RscEdit</tt> with idc <tt>645</tt>. Example below demonstrates how to. After tree is generated, try typing something in the top box. <code>[] [[spawn]]
 
|x3= <sqf>myControl = findDisplay 0 ctrlCreate ["RscText", 1234, findDisplay 0 displayCtrl 2300];</sqf>
 
|x4= Create Tree View control with search. Available {{hl|RscTreeSearch}} class is hardcoded to be used with {{hl|RscEdit}} with idc {{hl|645}}.
Example below demonstrates how to. After tree is generated, try typing something in the top box.
<sqf>
0 spawn  
{
{
[[disableSerialization]];
disableSerialization;
 
_display = (if (is3DEN) then {findDisplay 313} else {[] call BIS_fnc_displayMission}) createDisplay "RscDisplayEmpty";
 
_edit = _display ctrlCreate ["RscEdit", 645];
_edit ctrlSetPosition [0,0,1,0.04];
_edit ctrlSetBackgroundColor [0,0,0,1];
_edit ctrlCommit 0;


_display = [[findDisplay]] 46 [[createDisplay]] "RscDisplayEmpty";
_tv = _display ctrlCreate ["RscTreeSearch", -1];
_tv ctrlSetFont "EtelkaMonospacePro";
_edit = _display [[ctrlCreate]] ["RscEdit", 645];
_tv ctrlSetFontHeight 0.03;
_edit [[ctrlSetPosition]] [0,0,1,0.04];
_tv ctrlSetPosition [0,0.06,1,0.94];
_edit [[ctrlSetBackgroundColor]] [0,0,0,1];
_tv ctrlSetBackgroundColor [0,0,0,1];
_edit [[ctrlCommit]] 0;
_tv ctrlCommit 0;
 
_tv = _display [[ctrlCreate]] ["RscTreeSearch", -1];
_classes = "true" configClasses (configFile >> "CfgVehicles");
_tv [[ctrlSetFont]] "EtelkaMonospacePro";  
 
_tv [[ctrlSetFontHeight]] 0.03;  
for "_i" from 0 to 5 do
_tv [[ctrlSetPosition]] [0,0.06,1,0.94];
_tv [[ctrlSetBackgroundColor]] [0,0,0,1];
_tv [[ctrlCommit]] 0;
_classes = "true" [[configClasses]] ([[configFile]] >> "CfgVehicles");
[[for]] "_i" [[from]] 0 [[to]] 5 [[do]]
{
{
_tv [[tvAdd]] <nowiki>[</nowiki>[], [[configName]] [[selectRandom]] _classes];
_tv tvAdd [[], configName selectRandom _classes];
[[for]] "_j" [[from]] 0 [[to]] 5 [[do]] 
for "_j" from 0 to 5 do
{
{
_tv [[tvAdd]] <nowiki>[</nowiki>[_i], [[configName]] [[selectRandom]] _classes];
_tv tvAdd [[_i], configName selectRandom _classes];
[[for]] "_k" [[from]] 0 [[to]] 5 [[do]] 
for "_k" from 0 to 5 do
{
{
_tv [[tvAdd]] <nowiki>[</nowiki>[_i, _j], [[configName]] [[selectRandom]] _classes];
_tv tvAdd [[_i, _j], configName selectRandom _classes];
[[for]] "_n" [[from]] 0 [[to]] 5 [[do]] 
for "_n" from 0 to 5 do
{
{
_tv [[tvAdd]] <nowiki>[</nowiki>[_i, _j, _k], [[configName]] [[selectRandom]] _classes];
_tv tvAdd [[_i, _j, _k], configName selectRandom _classes];
};
};
};
};
};
};
};
};
};</code>
};
{{ Important | This TreeView search built in mechanics is very slow for some reason, you would probably be better off redrawing the whole list each time.}} |EXAMPLE4=
</sqf>
____________________________________________________________________________________________


| [[allControls]], [[allDisplays]], [[controlsGroupCtrl]], [[ctrlDelete]], [[ctrlModel]], [[ctrlSetModel]], [[ctrlPosition]], [[ctrlSetPosition]], [[ctrlClassName]], [[ctrlModelScale]], [[ctrlSetModelScale]], [[ctrlModelDirAndUp]], [[ctrlSetModelDirAndUp]], [[displayParent]] |SEEALSO=
|x5= Create a simple submit edit box and show content in hint:
<sqf>
disableSerialization;
private _display = findDisplay 46 createDisplay "RscDisplayEmpty";
private _ctrlGroup = _display ctrlCreate ["RscControlsGroupNoScrollbars", -1];
private _ctrlBackground = _display ctrlCreate ["RscTextMulti", -1, _ctrlGroup];
IDD_EDIT_BOX = 123;
private _ctrlEdit = _display ctrlCreate ["RscEditMulti", IDD_EDIT_BOX, _ctrlGroup];
private _ctrlButton = _display ctrlCreate ["RscShortcutButton", -1, _ctrlGroup];
_ctrlGroup ctrlSetPosition [0.5, 0.5, 0, 0];
_ctrlGroup ctrlCommit 0;
_ctrlBackground ctrlSetPosition [0, 0, 0.5, 0.5];
_ctrlBackground ctrlSetBackgroundColor [0.5, 0.5, 0.5, 0.9];
_ctrlBackground ctrlSetText "ENTER TEXT:";
_ctrlBackground ctrlEnable false;
_ctrlBackground ctrlCommit 0;
_ctrlEdit ctrlSetPosition [0.01, 0.05, 0.48, 0.34];
_ctrlEdit ctrlSetBackgroundColor [0, 0, 0, 0.5];
_ctrlEdit ctrlCommit 0;
_ctrlButton ctrlSetPosition [0.185, 0.42, 0.13, 0.05];
_ctrlButton ctrlCommit 0;
_ctrlButton ctrlSetText "SUBMIT";
_ctrlButton ctrlAddEventHandler ["ButtonClick",  
{
params ["_ctrl"];
_display = ctrlParent _ctrl;
_text = ctrlText (_display displayCtrl IDD_EDIT_BOX);
if (_text == "") then { _text = "EMPTY" };
hint _text;
_display closeDisplay 1;
}];
ctrlSetFocus _ctrlEdit;
_ctrlGroup ctrlSetPosition [0.25, 0.25, 0.5, 0.5];
_ctrlGroup ctrlCommit 0.1;
playSound "Hint3";
</sqf>


| |MPBEHAVIOUR=  
|x6= <sqf>
____________________________________________________________________________________________
// since {{arma3}} v2.14
}}
findDisplay 46 createDisplay "RscDisplayEmpty" ctrlCreate [configFile >> "RscDisplayBootcampMsgBox" >> "controls" >> "BootcampMessageBox", -1];
</sqf>


<h3 style='display:none'>Notes</h3>
|x7= <sqf>
<dl class='command_description'>
// Creates a vertical slider. Execute in [[Eden Editor]]
<!-- Note Section BEGIN -->
private _display = findDisplay 313 createDisplay "RscDisplayEmpty";
private _ctrlSlider = _display ctrlCreate ["ctrlSliderV", -1];


<!-- Note Section END -->
_ctrlSlider ctrlSetPosition
</dl>
[
  0.5 - 0.5 * pixelGrid * pixelW * 10,
  0.5 - 0.5 * pixelGrid * pixelH * 40,
  0.5 * pixelGrid * pixelW * 20,
  0.5 * pixelGrid * pixelH * 80
];


<h3 style='display:none'>Bottom Section</h3>
_ctrlSlider ctrlCommit 0;
[[Category:Arma_3:_New_Scripting_Commands_List|{{uc:{{PAGENAME}}}}]]
</sqf>
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]
[[Category:Command_Group:_GUI_Control|{{uc:{{PAGENAME}}}}]]


 
|seealso= [[ctrlMapSetPosition]] [[allControls]] [[allDisplays]] [[controlsGroupCtrl]] [[ctrlDelete]] [[ctrlModel]] [[ctrlSetModel]] [[ctrlPosition]] [[ctrlSetPosition]] [[ctrlClassName]] [[ctrlModelScale]] [[ctrlSetModelScale]] [[ctrlModelDirAndUp]] [[ctrlSetModelDirAndUp]] [[displayParent]]
<!-- CONTINUE Notes -->
}}
<!-- DISCONTINUE Notes -->
 
<!-- CONTINUE Notes -->
<dl class="command_description">
<dd class="notedate">Posted on September 16, 2019 - 07:09 (UTC)</dd>
<dt class="note">[[User:R3vo|R3vo]]</dt>
<dd class="note">
Regarding search speed in example 4:
The search is incredible slow if items are only added to the first level. As soon as multiple levels are added, the search becomes faster.<br>Therefore it's not recommended to use a TreeView control as listbox just to have access to the engine driven incremental search.
</dd>
</dl>
<!-- DISCONTINUE Notes -->

Latest revision as of 19:43, 3 September 2024

Hover & click on the images for description

Description

Description:
Creates a new control in the given display.
The control class could be an existing class from the main config or a custom class defined in the mission config. The main config is searched first, if the class does not exist there, the mission config is searched. Some of the common controls defined in the main config that can be used with this command:
This list contains controls which are guaranteed to work with this command. However, controls not listed here should work as well - as long as they are properly defined.
Class Description Available since
RscText simple text box
RscStructuredText text box which supports structured text
RscTextMulti simple multiline text box
RscPicture simple picture box
RscPictureKeepAspect picture box that doesn't stretch picture
RscEdit input box
RscEditMulti multiline input box
RscEditReadOnly input box with canModify = false; Arma 3 logo black.png1.98
RscEditMultiReadOnly multiline input box with canModify = false; Arma 3 logo black.png1.98
RscTree tree view control
RscTreeMulti multi-select tree view Arma 3 logo black.png2.02
RscTreeSearch searchable tree view control (see Example 4)
RscVideo picture control with autostart for video texture (see BIS_fnc_playVideo)
RscVideoKeepAspect picture control for video to keep original video aspect ratio
RscButtonMenuBIKI shortcut button with url pointing to "https://community.bistudio.com/wiki/" Arma 3 logo black.png1.98
RscControlsGroup default controls group
RscControlsGroupNoScrollbars controls group without scrollbars
RscControlsGroupNoHScrollbars controls group without horizontal scrollbar
RscControlsGroupNoVScrollbars controls group without vertical scrollbar
↑ Back to spoiler's top
If you are creating CT_MAP control dynamically, use ctrlMapSetPosition to update control position instead of ctrlSetPosition.
Groups:
GUI Control

Syntax

Syntax:
display ctrlCreate [class, idc, controlsGroup]
Parameters:
display: Display - display in which control will be created
class: String or Arma 3 logo black.png2.14 Config - existing classname (see ctrlCreate/classnames) of the new control; Arma 3 logo black.png1.70 it is possible to use classes defined in mission config
idc: Number - IDC of the new control. Use -1 if not needed
Be careful when setting the IDC to -1 if the GUI also contains a CT_LISTNBOX since idcLeft and idcRight by default have idc = -1;.
controlsGroup: Control - (Optional, default controlNull) creates controls in existing controls group
Return Value:
Control

Examples

Example 1:
_display ctrlCreate ["RscText", 1234];
Example 2:
_map = findDisplay 46 ctrlCreate ["RscMapControl", -1]; _multiLineText = findDisplay 46 ctrlCreate ["RscTextMulti", -1]; _multiLineEdit = findDisplay 46 ctrlCreate ["RscEditMulti", -1];
Example 3:
myControl = findDisplay 0 ctrlCreate ["RscText", 1234, findDisplay 0 displayCtrl 2300];
Example 4:
Create Tree View control with search. Available RscTreeSearch class is hardcoded to be used with RscEdit with idc 645. Example below demonstrates how to. After tree is generated, try typing something in the top box.
0 spawn { disableSerialization; _display = (if (is3DEN) then {findDisplay 313} else {[] call BIS_fnc_displayMission}) createDisplay "RscDisplayEmpty"; _edit = _display ctrlCreate ["RscEdit", 645]; _edit ctrlSetPosition [0,0,1,0.04]; _edit ctrlSetBackgroundColor [0,0,0,1]; _edit ctrlCommit 0; _tv = _display ctrlCreate ["RscTreeSearch", -1]; _tv ctrlSetFont "EtelkaMonospacePro"; _tv ctrlSetFontHeight 0.03; _tv ctrlSetPosition [0,0.06,1,0.94]; _tv ctrlSetBackgroundColor [0,0,0,1]; _tv ctrlCommit 0; _classes = "true" configClasses (configFile >> "CfgVehicles"); for "_i" from 0 to 5 do { _tv tvAdd [[], configName selectRandom _classes]; for "_j" from 0 to 5 do { _tv tvAdd [[_i], configName selectRandom _classes]; for "_k" from 0 to 5 do { _tv tvAdd [[_i, _j], configName selectRandom _classes]; for "_n" from 0 to 5 do { _tv tvAdd [[_i, _j, _k], configName selectRandom _classes]; }; }; }; }; };
Example 5:
Create a simple submit edit box and show content in hint:
disableSerialization; private _display = findDisplay 46 createDisplay "RscDisplayEmpty"; private _ctrlGroup = _display ctrlCreate ["RscControlsGroupNoScrollbars", -1]; private _ctrlBackground = _display ctrlCreate ["RscTextMulti", -1, _ctrlGroup]; IDD_EDIT_BOX = 123; private _ctrlEdit = _display ctrlCreate ["RscEditMulti", IDD_EDIT_BOX, _ctrlGroup]; private _ctrlButton = _display ctrlCreate ["RscShortcutButton", -1, _ctrlGroup]; _ctrlGroup ctrlSetPosition [0.5, 0.5, 0, 0]; _ctrlGroup ctrlCommit 0; _ctrlBackground ctrlSetPosition [0, 0, 0.5, 0.5]; _ctrlBackground ctrlSetBackgroundColor [0.5, 0.5, 0.5, 0.9]; _ctrlBackground ctrlSetText "ENTER TEXT:"; _ctrlBackground ctrlEnable false; _ctrlBackground ctrlCommit 0; _ctrlEdit ctrlSetPosition [0.01, 0.05, 0.48, 0.34]; _ctrlEdit ctrlSetBackgroundColor [0, 0, 0, 0.5]; _ctrlEdit ctrlCommit 0; _ctrlButton ctrlSetPosition [0.185, 0.42, 0.13, 0.05]; _ctrlButton ctrlCommit 0; _ctrlButton ctrlSetText "SUBMIT"; _ctrlButton ctrlAddEventHandler ["ButtonClick", { params ["_ctrl"]; _display = ctrlParent _ctrl; _text = ctrlText (_display displayCtrl IDD_EDIT_BOX); if (_text == "") then { _text = "EMPTY" }; hint _text; _display closeDisplay 1; }]; ctrlSetFocus _ctrlEdit; _ctrlGroup ctrlSetPosition [0.25, 0.25, 0.5, 0.5]; _ctrlGroup ctrlCommit 0.1; playSound "Hint3";
Example 6:
// since Arma 3 v2.14 findDisplay 46 createDisplay "RscDisplayEmpty" ctrlCreate [configFile >> "RscDisplayBootcampMsgBox" >> "controls" >> "BootcampMessageBox", -1];
Example 7:
// Creates a vertical slider. Execute in Eden Editor private _display = findDisplay 313 createDisplay "RscDisplayEmpty"; private _ctrlSlider = _display ctrlCreate ["ctrlSliderV", -1]; _ctrlSlider ctrlSetPosition [ 0.5 - 0.5 * pixelGrid * pixelW * 10, 0.5 - 0.5 * pixelGrid * pixelH * 40, 0.5 * pixelGrid * pixelW * 20, 0.5 * pixelGrid * pixelH * 80 ]; _ctrlSlider ctrlCommit 0;

Additional Information

See also:
ctrlMapSetPosition allControls allDisplays controlsGroupCtrl ctrlDelete ctrlModel ctrlSetModel ctrlPosition ctrlSetPosition ctrlClassName ctrlModelScale ctrlSetModelScale ctrlModelDirAndUp ctrlSetModelDirAndUp displayParent

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