Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
sizetochild.c
Go to the documentation of this file.
1 class SizeToChild extends ScriptedWidgetEventHandler
2 {
3  reference string m_ChildName;
4  reference float m_HorizontalOffset;
5  reference float m_VerticalOffset;
6  reference bool m_ResizeHorizontal;
7  reference bool m_ResizeVertical;
8 
9  protected Widget m_Root;
10  protected Widget m_Child;
11 
12  protected static bool m_IgnoredBool;
13 
15  {
16  m_Root = w;
17 
18  m_Child = m_Root.FindAnyWidget( m_ChildName );
19  if ( m_Child )
20  {
21  ResizeParentToChild();
22  }
23  }
24 
25  bool ResizeParentToChild()
26  {
27  return ResizeParentToChild( m_IgnoredBool, -1, true );
28  }
29 
30  bool ResizeParentToChild( out bool changed_size, int limit = -1, bool immedUpdate = true )
31  {
32  float x, y, o_x, o_y, new_x, new_y;
33  if ( m_Child )
34  {
35  m_Child.Update();
36  m_Child.GetScreenSize( x, y );
37  m_Root.GetScreenSize( new_x, new_y );
38  m_Root.GetSize( o_x, o_y );
39 
40  bool changed = false;
41  bool hit_limit = false;
42 
43  if ( m_ResizeHorizontal && ( x > new_x + 0.01 || x < new_x - 0.01 ) )
44  {
45  new_x = x + m_HorizontalOffset;
46  changed = true;
47  }
48  else
49  new_x = o_x;
50 
51  if ( m_ResizeVertical && ( y > new_y + 0.01 || y < new_y - 0.01 ) )
52  {
53  new_y = y + m_VerticalOffset;
54  changed = true;
55  }
56  else
57  new_y = o_y;
58 
59  if ( limit > 0 && new_y > limit )
60  {
61  new_y = limit;
62  hit_limit = true;
63  }
64 
65  if ( changed )
66  {
67  m_Root.SetSize( new_x, new_y, immedUpdate );
68  }
69 
70  changed_size = changed;
71  return hit_limit;
72  }
73  else
74  {
75  m_Child = m_Root.FindAnyWidget( m_ChildName );
76  if ( !m_Child )
77  {
78  Print( "Error in size to child, " + m_Root.GetName() + " has no child named " + m_ChildName );
79  }
80  }
81 
82  return false;
83  }
84 }
85 
86 class SizeToParent extends ScriptedWidgetEventHandler
87 {
88  reference bool m_ResizeHorizontal;
89  reference bool m_ResizeVertical;
90 
91  protected Widget m_Root;
92  protected Widget m_Parent;
93 
95  {
96  m_Root = w;
97 
98  if ( m_ResizeHorizontal )
99  m_Root.ClearFlags( WidgetFlags.HEXACTSIZE );
100  if ( m_ResizeVertical )
101  m_Root.ClearFlags( WidgetFlags.VEXACTSIZE );
102 
103  m_Parent = m_Root.GetParent();
104 
105  Refresh();
106  }
107 
108  void Refresh()
109  {
110  float x, y, o_x, o_y, new_x, new_y;
111  m_Parent.Update();
112  m_Parent.GetScreenSize( x, y );
113  m_Root.GetScreenSize( new_x, new_y );
114  m_Root.GetSize( o_x, o_y );
115 
116  bool changed = false;
117 
118  if ( m_ResizeHorizontal && x != new_x )
119  {
120  new_x = x;
121  changed = true;
122  }
123  else
124  new_x = o_x;
125 
126  if ( m_ResizeVertical && y != new_y )
127  {
128  new_y = y;
129  changed = true;
130  }
131  else
132  new_y = o_y;
133 
134  if ( changed )
135  m_Root.SetSize( new_x, new_y );
136  }
137 }
OnWidgetScriptInit
void OnWidgetScriptInit(Widget w)
Definition: sizetochild.c:94
m_ResizeHorizontal
class SizeToChild extends ScriptedWidgetEventHandler m_ResizeHorizontal
y
Icon y
Print
proto void Print(void var)
Prints content of variable to console/log.
m_Parent
protected Widget m_Parent
Definition: sizetochild.c:92
Refresh
void Refresh()
Definition: sizetochild.c:108
m_ResizeVertical
reference bool m_ResizeVertical
Definition: sizetochild.c:89
x
Icon x
WidgetFlags
WidgetFlags
Definition: enwidgets.c:57
Widget
Definition: enwidgets.c:189
m_Root
protected Widget m_Root
Definition: sizetochild.c:91
ScriptedWidgetEventHandler
map: item x vector(index, width, height)
Definition: enwidgets.c:650