Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_WidgetHighlightUIComponent.c
Go to the documentation of this file.
1 class SCR_WidgetHighlightUIComponent: ScriptedWidgetComponent
2 {
3  protected Widget m_HighlightWidget;
4 
12  static Widget CreateHighlight(Widget widget, ResourceName layout, Widget parent = null)
13  {
14  if (!widget)
15  {
16  Print("Cannot create highlight, widget not found!", LogLevel.WARNING);
17  return null;
18  }
19 
20  /*
21  Create the highlight in Workspace, not where target widget is.
22  It's because we don't know which layout slot is used, and not all of them would be compatible (e.g., horizontal slot).
23  Furthermore, highlight widget can be an outline *outside* of the area, and modifying target's clipping could be dangerous.
24  */
25  WorkspaceWidget workspace = GetGame().GetWorkspace();
26  if (!parent)
27  parent = workspace;
29  highlight.m_HighlightWidget = workspace.CreateWidgets(layout, parent);
30  widget.AddHandler(highlight);
31  return highlight.m_HighlightWidget;
32  }
40  static Widget CreateHighlight(string widgetName, ResourceName layout, Widget parent = null)
41  {
42  Widget widget = GetGame().GetWorkspace().FindAnyWidget(widgetName);
43  if (!widget)
44  {
45  Print(string.Format("Cannot create highlight, widget '%1' not found!", widgetName), LogLevel.WARNING);
46  return null;
47  }
48  return CreateHighlight(widget, layout, parent);
49  }
50 
51  protected void Update(Widget w)
52  {
53  //--- Exit if the parent was meanwhile deleted (e.g., when the menu is closed)
54  if (!m_HighlightWidget || !w.GetParent())
55  {
56  HandlerDeattached(w);
57  return;
58  }
59 
60  WorkspaceWidget workspace = GetGame().GetWorkspace();
61 
62  //--- Set position
63  float posX, posY, posW, posH;
64  w.GetScreenPos(posX, posY);
65  w.GetScreenSize(posW, posH);
66  FrameSlot.SetPos(m_HighlightWidget, workspace.DPIUnscale(posX), workspace.DPIUnscale(posY));
67  FrameSlot.SetSize(m_HighlightWidget, workspace.DPIUnscale(posW), workspace.DPIUnscale(posH));
68 
69  //--- Set visibility
70  bool isVisible = true;
71  while (w)
72  {
73  if (!w.IsVisible() || w.GetOpacity() == 0)
74  {
75  isVisible = false;
76  break;
77  }
78  w = w.GetParent();
79  }
80  m_HighlightWidget.SetVisible(isVisible);
81  }
82  override void HandlerAttached(Widget w)
83  {
84  Update(w);
85  if (GetGame().GetCallqueue())
86  GetGame().GetCallqueue().CallLater(Update, 1, true, w);
87  }
88  override void HandlerDeattached(Widget w)
89  {
90  if (GetGame())
91  {
92  if (GetGame().GetCallqueue())
93  GetGame().GetCallqueue().Remove(Update);
94  }
95 
96  if (m_HighlightWidget)
97  m_HighlightWidget.RemoveFromHierarchy();
98  }
99 };
GetCallqueue
ScriptCallQueue GetCallqueue()
Definition: game.c:225
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
layout
UI layouts HUD CampaignMP CampaignMainHUD layout
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:20
SCR_WidgetHighlightUIComponent
Definition: SCR_WidgetHighlightUIComponent.c:1