00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "xrb_widgetstack.hpp"
00012
00013 #include "xrb_screen.hpp"
00014
00015 namespace Xrb
00016 {
00017
00018 Bool2 WidgetStack::ContentsMinSizeEnabled () const
00019 {
00020 UpdateContentsSizeProperties();
00021 return m_contents_size_properties.m_min_size_enabled;
00022 }
00023
00024 ScreenCoordVector2 WidgetStack::ContentsMinSize () const
00025 {
00026 UpdateContentsSizeProperties();
00027 return m_contents_size_properties.m_min_size;
00028 }
00029
00030 Bool2 WidgetStack::ContentsMaxSizeEnabled () const
00031 {
00032 UpdateContentsSizeProperties();
00033 return m_contents_size_properties.m_max_size_enabled;
00034 }
00035
00036 ScreenCoordVector2 WidgetStack::ContentsMaxSize () const
00037 {
00038 UpdateContentsSizeProperties();
00039 return m_contents_size_properties.m_max_size;
00040 }
00041
00042 void WidgetStack::SetSizePropertyEnabled (
00043 SizeProperties::Property const property,
00044 Uint32 const component,
00045 bool const value)
00046 {
00047 ASSERT1(component <= 1);
00048 if (property == SizeProperties::MIN)
00049 m_preferred_size_properties.m_min_size_enabled[component] = value;
00050 else
00051 m_preferred_size_properties.m_max_size_enabled[component] = value;
00052 ContainerWidget::SetSizePropertyEnabled(property, component, value, true);
00053 CalculateMinAndMaxSizePropertiesFromContents();
00054
00055 }
00056
00057 void WidgetStack::SetSizePropertyEnabled (
00058 SizeProperties::Property const property,
00059 Bool2 const &value)
00060 {
00061 if (property == SizeProperties::MIN)
00062 m_preferred_size_properties.m_min_size_enabled = value;
00063 else
00064 m_preferred_size_properties.m_max_size_enabled = value;
00065 ContainerWidget::SetSizePropertyEnabled(property, value, true);
00066 CalculateMinAndMaxSizePropertiesFromContents();
00067
00068 }
00069
00070 void WidgetStack::SetSizeProperty (
00071 SizeProperties::Property const property,
00072 Uint32 const component,
00073 ScreenCoord const value)
00074 {
00075 ASSERT1(component <= 1);
00076 ASSERT1(value >= 0);
00077 if (property == SizeProperties::MIN)
00078 m_preferred_size_properties.m_min_size[component] = value;
00079 else
00080 m_preferred_size_properties.m_max_size[component] = value;
00081 ContainerWidget::SetSizeProperty(property, component, value, true);
00082 CalculateMinAndMaxSizePropertiesFromContents();
00083
00084 }
00085
00086 void WidgetStack::SetSizeProperty (
00087 SizeProperties::Property const property,
00088 ScreenCoordVector2 const &value)
00089 {
00090 ASSERT1(value[Dim::X] >= 0);
00091 ASSERT1(value[Dim::Y] >= 0);
00092 if (property == SizeProperties::MIN)
00093 m_preferred_size_properties.m_min_size = value;
00094 else
00095 m_preferred_size_properties.m_max_size = value;
00096 ContainerWidget::SetSizeProperty(property, value, true);
00097 CalculateMinAndMaxSizePropertiesFromContents();
00098
00099 }
00100
00101 ScreenCoordVector2 WidgetStack::Resize (ScreenCoordVector2 const &size)
00102 {
00103 ContainerWidget::Resize(size);
00104
00105
00106 if (ChildResizeBlockerCount() == 0)
00107 {
00108 ResizeAndRepositionChildWidgets();
00109 }
00110 else
00111 IndicateChildResizeWasBlocked();
00112
00113 return Size();
00114 }
00115
00116 void WidgetStack::AttachChild (Widget *const child)
00117 {
00118
00119 ContainerWidget::AttachChild(child);
00120
00121
00122 DirtyContentsSizeProperties();
00123
00124 if (ChildResizeBlockerCount() == 0)
00125 {
00126
00127 CalculateMinAndMaxSizePropertiesFromContents();
00128
00129 Resize(Size());
00130
00131
00132 }
00133 else
00134 IndicateChildResizeWasBlocked();
00135 }
00136
00137 void WidgetStack::DetachChild (Widget *const child)
00138 {
00139
00140 ContainerWidget::DetachChild(child);
00141
00142
00143 DirtyContentsSizeProperties();
00144
00145 if (ChildResizeBlockerCount() == 0)
00146 {
00147
00148 CalculateMinAndMaxSizePropertiesFromContents();
00149
00150 Resize(Size());
00151
00152
00153 }
00154 else
00155 IndicateChildResizeWasBlocked();
00156 }
00157
00158 void WidgetStack::ChildSizePropertiesChanged (Widget *const child)
00159 {
00160
00161
00162 DirtyContentsSizeProperties();
00163
00164 if (ChildResizeBlockerCount() == 0)
00165 {
00166
00167 CalculateMinAndMaxSizePropertiesFromContents();
00168
00169 Resize(Size());
00170
00171
00172 }
00173 else
00174 IndicateChildResizeWasBlocked();
00175 }
00176
00177 void WidgetStack::UpdateRenderBackground ()
00178 {
00179 SetRenderBackground(NULL);
00180 }
00181
00182 void WidgetStack::ResizeAndRepositionChildWidgets ()
00183 {
00184 ScreenCoordVector2 positional_offset;
00185
00186 for (Uint32 i = 0; i < m_child_vector.size(); ++i)
00187 {
00188 Widget *child = m_child_vector[i];
00189 ASSERT1(child != NULL);
00190
00191
00192 if (child->IsHidden())
00193 continue;
00194
00195
00196 if (child->IsModal())
00197 continue;
00198
00199
00200 child->Resize(Size());
00201
00202
00203
00204 ScreenCoordVector2 extra_space(Size() - child->Size());
00205 ASSERT1(extra_space[Dim::X] >= 0 &&
00206 extra_space[Dim::Y] >= 0);
00207
00208
00209
00210 child->MoveTo(Position() + extra_space / 2);
00211 }
00212 }
00213
00214 void WidgetStack::DirtyContentsSizeProperties ()
00215 {
00216 m_contents_size_properties_need_update = true;
00217 }
00218
00219 void WidgetStack::UpdateContentsSizeProperties () const
00220 {
00221
00222 if (!m_contents_size_properties_need_update)
00223 return;
00224
00225 m_contents_size_properties_need_update = false;
00226
00227
00228 m_contents_size_properties.m_min_size_enabled = Bool2(false, false);
00229 m_contents_size_properties.m_min_size = ScreenCoordVector2::ms_zero;
00230
00231
00232 m_contents_size_properties.m_max_size_enabled = Bool2(false, false);
00233 m_contents_size_properties.m_max_size =
00234 ScreenCoordVector2(
00235 SizeProperties::DefaultMaxSizeComponent(),
00236 SizeProperties::DefaultMaxSizeComponent());
00237
00238
00239 for (Uint32 i = 0; i < m_child_vector.size(); ++i)
00240 {
00241 Widget const *child = m_child_vector[i];
00242 ASSERT1(child != NULL);
00243
00244
00245 if (child->IsHidden())
00246 continue;
00247
00248
00249 if (child->IsModal())
00250 continue;
00251
00252
00253 for (Uint8 d = 0; d < 2; ++d)
00254 {
00255
00256
00257 if (child->MinSizeEnabled()[d])
00258 {
00259 m_contents_size_properties.m_min_size_enabled[d] = true;
00260 m_contents_size_properties.m_min_size[d] =
00261 Max(child->MinSize()[d],
00262 m_contents_size_properties.m_min_size[d]);
00263 }
00264
00265
00266
00267 if (child->MaxSizeEnabled()[d])
00268 {
00269 m_contents_size_properties.m_max_size_enabled[d] = true;
00270 m_contents_size_properties.m_max_size[d] =
00271 Min(child->MaxSize()[d],
00272 m_contents_size_properties.m_max_size[d]);
00273 }
00274 }
00275 }
00276 }
00277
00278 }