nux-1.14.0
|
An layered layout. More...
#include <Nux/LayeredLayout.h>
Public Types | |
enum | InputMode { INPUT_MODE_ACTIVE = 0, INPUT_MODE_COMPOSITE } |
Public Member Functions | |
LayeredLayout (NUX_FILE_LINE_PROTO) | |
void | AddLayer (Area *area, bool expand=true, int x=0, int y=0, int width=0, int height=0) |
Add a layer to the layout. | |
void | UpdateLayer (Area *area, bool expand=true, int x=0, int y=0, int width=0, int height=0) |
Update properties of a layer in the layout. | |
void | RemoveLayer (Area *area) |
Remove a layer. | |
void | SetActiveLayerN (int index_) |
Set the active layer of the layout. | |
int | GetActiveLayerN () |
Get the active layer of the layout. | |
void | SetActiveLayer (Area *area) |
Set the active layer of the layout. | |
Area * | GetActiveLayer () |
Get the active layer of the layout. | |
void | SetPaintAll (bool paint_all) |
Set whether the layout will paint all the layers it contains. Default is false. | |
bool | GetPaintAll () |
Get whether the layout is drawing all the layers it contains. | |
void | SetInputMode (LayeredLayout::InputMode input_mode) |
Sets the input mode of the layout. | |
void | Raise (Area *area, Area *above) |
Raise the paint and input depth of an area. | |
void | Lower (Area *area, Area *below) |
Lower the paint and input depth of an area. | |
void | RaiseTop (Area *area) |
Raises the paint and input depth of area to the top of the layout. | |
void | LowerBottom (Area *area) |
Lowers the paint and input depth of area to the bottom of the layout. | |
LayeredLayout::InputMode | GetInputMode () |
Get which input mode is set on the layout. | |
long | ComputeLayout2 () |
void | GetCompositeList (std::list< Area * > *ViewList) |
void | ProcessDraw (GraphicsEngine &gfx_context, bool force_draw) |
Draw Element. | |
Area * | FindAreaUnderMouse (const Point &mouse_position, NuxEventType event_type) |
void | AddLayout (Layout *layouy, unsigned int stretch_factor=1, MinorDimensionPosition position=eAbove, MinorDimensionSize extend=eFull, float percentage=100.0f) |
void | AddView (Area *view, unsigned int stretch_factor=1, MinorDimensionPosition positioning=eAbove, MinorDimensionSize extend=eFull, float percentage=100.0f) |
void | RemoveChildObject (Area *area) |
void | Clear () |
Protected Member Functions | |
virtual long | DoFocusPrev (IEvent &ievent, long TraverseInfo, long ProcessEventInfo) |
virtual long | DoFocusNext (IEvent &ievent, long TraverseInfo, long ProcessEventInfo) |
virtual bool | FocusFirstChild () |
virtual bool | FocusLastChild () |
virtual Area * | KeyNavIteration (KeyNavDirection direction) |
void | OnLayerGeometryChanged (Area *area, Geometry geo) |
An layered layout.
LayeredLayout works either as a bin layout, showing only one layer at a time, or it works as a composite layout, drawing all children in order (and you are able to modify the order).
The layout also allows two modes of input. In INPUT_MODE_ACTIVE, the layout will only send events to the active layer, even if in composite drawing mode. In INPUT_MODE_COMPOSITE, the layout will send events to all the layers, in the stacking order from top to bottom. This allows creation of complex widgets more easily than implementing the drawing and input modes manually.
Definition at line 41 of file LayeredLayout.h.
void nux::LayeredLayout::AddLayer | ( | Area * | area, |
bool | expand = true , |
||
int | x = 0 , |
||
int | y = 0 , |
||
int | width = 0 , |
||
int | height = 0 |
||
) |
Add a layer to the layout.
This method will add the layer with layout specific options
area | the Area, Layout or View |
expand | area should be expanded to all the available space of the layout. If this is set to false, all the following parameters must be set |
x | the horizontal position of the layer, expand must be false |
y | the vertical position of the layer, expand must be false |
width | the width of the layer inside the layout, expand must be false |
height | the height of the layer inside the layout, expand must be false |
Definition at line 326 of file LayeredLayout.cpp.
References nux::Layout::AddView(), nux::Layout::QueueDraw(), and nux::Area::SetLayoutProperties().
{ LayeredChildProperties *props; // return if the area is NULL NUX_RETURN_IF_NULL(area); // Return if the area already has a parent NUX_RETURN_IF_NOTNULL(area->GetParentObject ()); props = new LayeredChildProperties (expand, x, y, width, height); area->SetLayoutProperties (props); if (!m_active_area) { m_active_area = area; } props->m_vis_it = area->OnVisibleChanged.connect (sigc::mem_fun (this, &LayeredLayout::ChildVisibilityChanged)); if (area->IsLayout ()) Layout::AddLayout (static_cast<Layout *> (area)); else Layout::AddView (area); QueueDraw (); }
Area * nux::LayeredLayout::FindAreaUnderMouse | ( | const Point & | mouse_position, |
NuxEventType | event_type | ||
) | [virtual] |
Return the area under the mouse pointer.
Reimplemented from nux::Layout.
Definition at line 249 of file LayeredLayout.cpp.
References nux::Area::FindAreaUnderMouse(), nux::Area::IsSensitive(), nux::Area::IsVisible(), and nux::Area::TestMousePointerInclusionFilterMouseWheel().
{ if(m_active_area == NULL) return NULL; bool mouse_inside = m_active_area->TestMousePointerInclusionFilterMouseWheel(mouse_position, event_type); if(mouse_inside == false) return NULL; if(m_input_mode == INPUT_MODE_ACTIVE) { if (m_active_area && m_active_area->IsVisible () && m_active_area->IsSensitive ()) return m_active_area->FindAreaUnderMouse(mouse_position, event_type); } else { std::list<Area *>::reverse_iterator it, eit = _layout_element_list.rend (); for (it = _layout_element_list.rbegin (); it != eit; ++it) { Area *area = (*it); if (area->IsVisible () && area->IsSensitive ()) { return m_active_area->FindAreaUnderMouse(mouse_position, event_type); } } } return NULL; }
Area * nux::LayeredLayout::GetActiveLayer | ( | ) |
Get the active layer of the layout.
Returns the the active layer of the layout. This is only useful if input mode is INPUT_MODE_ACTIVE.
Definition at line 475 of file LayeredLayout.cpp.
{
return m_active_area;
}
int nux::LayeredLayout::GetActiveLayerN | ( | ) |
Get the active layer of the layout.
Returns the index of the active layer of the layout. This is only useful if input mode is INPUT_MODE_ACTIVE.
Definition at line 442 of file LayeredLayout.cpp.
{
return m_active_index;
}
LayeredLayout::InputMode nux::LayeredLayout::GetInputMode | ( | ) |
Get which input mode is set on the layout.
Returns the current input mode on the layout.
Definition at line 502 of file LayeredLayout.cpp.
{
return m_input_mode;
}
bool nux::LayeredLayout::GetPaintAll | ( | ) |
Get whether the layout is drawing all the layers it contains.
Returns whether the layout is drawing all the layers it contains. See SetPaintAll.
Definition at line 489 of file LayeredLayout.cpp.
{
return m_paint_all;
}
Lower the paint and input depth of an area.
Lowers the paint and input depth of the area in the layout
area | area to raise |
below | area to lower below |
Definition at line 539 of file LayeredLayout.cpp.
{ std::list<Area *>::iterator it, eit = _layout_element_list.end (); std::list<Area *>::iterator area_it = eit; std::list<Area *>::iterator below_it = eit; NUX_RETURN_IF_NULL(area); NUX_RETURN_IF_NULL(below); for (it = _layout_element_list.begin (); it != eit; ++it) { if (below == (*it)) below_it = it; else if (area == (*it)) area_it = it; } if (area_it == eit) { nuxDebugMsg("[LayeredLayout::Lower] Area %p is not a valid layer", area); return; } if (below_it == eit) { nuxDebugMsg("[LayeredLayout::Lower] Area %p is not a valid layer", below); return; } _layout_element_list.erase (area_it); _layout_element_list.insert (below_it, area); }
void nux::LayeredLayout::LowerBottom | ( | Area * | area | ) |
Lowers the paint and input depth of area to the bottom of the layout.
Area will be drawn below all other layers and will be the last receive events
area | area to lower |
Definition at line 594 of file LayeredLayout.cpp.
{ std::list<Area *>::iterator it, eit = _layout_element_list.end (); std::list<Area *>::iterator area_it = eit; NUX_RETURN_IF_NULL(area); for (it = _layout_element_list.begin (); it != eit; ++it) { if (area == (*it)) area_it = it; } if (area_it == eit) { nuxDebugMsg("[LayeredLayout::LowerBottom] Area %p is not a valid layer", area); return; } _layout_element_list.erase (area_it); _layout_element_list.insert (_layout_element_list.begin (), area); }
void nux::LayeredLayout::ProcessDraw | ( | GraphicsEngine & | GfxContext, |
bool | force_draw | ||
) | [virtual] |
Draw Element.
Draw all elements inside the layout. If force_draw is true then the system requests that all objects redraw themselves completely.
force_draw | |
TraverseInfo | |
ProcessEventInfo |
Reimplemented from nux::Layout.
Definition at line 212 of file LayeredLayout.cpp.
References nux::Area::GetGeometry(), and nux::Area::IsVisible().
{ Geometry base = GetGeometry (); gfx_context.PushClippingRectangle (base); if (m_paint_all) { std::list<Area *>::iterator it, eit = _layout_element_list.end (); t_u32 alpha = 0, src = 0, dest = 0; gfx_context.GetRenderStates ().GetBlend (alpha, src, dest); gfx_context.GetRenderStates ().SetBlend (true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); nux::GetPainter().PaintBackground(gfx_context, base); nux::GetPainter().PushBackgroundStack(); for (it = _layout_element_list.begin (); it != eit; ++it) { if ((*it)->IsVisible ()) PaintOne (static_cast<Area *> (*it), gfx_context, true); } nux::GetPainter().PopBackgroundStack(); gfx_context.GetRenderStates ().SetBlend (alpha, src, dest); m_child_draw_queued = false; } else if (m_active_area && m_active_area->IsVisible ()) { PaintOne (m_active_area, gfx_context, force_draw); } gfx_context.PopClippingRectangle (); _queued_draw = false; }
Raise the paint and input depth of an area.
Raises the paint and input depth of the area in the layout
area | area to raise |
above | area to raise above |
Definition at line 507 of file LayeredLayout.cpp.
{ std::list<Area *>::iterator it, eit = _layout_element_list.end (); std::list<Area *>::iterator area_it = eit; std::list<Area *>::iterator above_it = eit; NUX_RETURN_IF_NULL(area); NUX_RETURN_IF_NULL(above); for (it = _layout_element_list.begin (); it != eit; ++it) { if (above == (*it)) above_it = it; else if (area == (*it)) area_it = it; } if (area_it == eit) { nuxDebugMsg("[LayeredLayout::Raise] Area %p is not a valid layer", area); return; } if (above_it == eit) { nuxDebugMsg("[LayeredLayout::Raise] Area %p is not a valid layer", above); return; } _layout_element_list.erase (area_it); _layout_element_list.insert (++above_it, area); }
void nux::LayeredLayout::RaiseTop | ( | Area * | area | ) |
Raises the paint and input depth of area to the top of the layout.
Area will be drawn above all other layers and will be the first receive events
area | area to raise |
Definition at line 571 of file LayeredLayout.cpp.
{ std::list<Area *>::iterator it, eit = _layout_element_list.end (); std::list<Area *>::iterator area_it = eit; NUX_RETURN_IF_NULL(area); for (it = _layout_element_list.begin (); it != eit; ++it) { if (area == (*it)) area_it = it; } if (area_it == eit) { nuxDebugMsg("[LayeredLayout::RaiseTop] Area %p is not a valid layer", area); return; } _layout_element_list.erase (area_it); _layout_element_list.insert (eit, area); }
void nux::LayeredLayout::RemoveLayer | ( | Area * | area | ) |
Remove a layer.
This method will remove a layer from the layout. It is here for completeness.
Definition at line 367 of file LayeredLayout.cpp.
References nux::Area::GetLayoutProperties(), and nux::Area::SetLayoutProperties().
{ LayeredChildProperties *props; NUX_RETURN_IF_NULL(area); props = dynamic_cast<LayeredChildProperties *>(area->GetLayoutProperties ()); NUX_RETURN_IF_NULL(props); (*props->m_vis_it).disconnect (); area->SetLayoutProperties (NULL); if (m_active_area == area) { std::list<Area *>::iterator it, eit = _layout_element_list.end (); int i = 0; m_active_index = 0; m_active_area = NULL; for (it = _layout_element_list.begin (); it != eit; ++it) { if (*it != area) { m_active_area = static_cast<Area *> (*it); m_active_index = i; break; } i++; } } Layout::RemoveChildObject (area); }
void nux::LayeredLayout::SetActiveLayer | ( | Area * | area | ) |
Set the active layer of the layout.
The active layer will receives input in the input mode is INPUT_MODE_ACTIVE.
area | The area of the layer to make active |
Definition at line 447 of file LayeredLayout.cpp.
References SetActiveLayerN().
{ std::list<Area *>::iterator it, eit = _layout_element_list.end (); int i = 0; for (it = _layout_element_list.begin (); it != eit; ++it) { Area *a = static_cast<Area *> (*it); if (area == a) { SetActiveLayerN (i); return; } i++; } nuxDebugMsg("[LayeredLayout::LowerBottom] Area (%p) is not a child of LayeredLayout (%p)", area, this); }
void nux::LayeredLayout::SetActiveLayerN | ( | int | index_ | ) |
Set the active layer of the layout.
The active layer will receives input in the input mode is INPUT_MODE_ACTIVE.
index_ | The index of the layer to make active |
Definition at line 402 of file LayeredLayout.cpp.
References nux::Layout::QueueDraw(), and nux::View::QueueDraw().
Referenced by SetActiveLayer().
{ std::list<Area *>::iterator it, eit = _layout_element_list.end (); int i = 0; NUX_RETURN_IF_FALSE((t_uint32)index_ < _layout_element_list.size ()); if (index_ == m_active_index) return; m_active_index = index_; m_active_area = NULL; bool is_focused = GetFocused (); for (it = _layout_element_list.begin (); it != eit; ++it) { if (i == m_active_index && !m_active_area) { m_active_area = static_cast<Area *> (*it); } if ((*it)->IsView ()) { static_cast<View *> (*it)->QueueDraw (); if (is_focused) static_cast<View *> (*it)->SetFocused (true); } else if ((*it)->IsLayout ()) { static_cast<Layout *> (*it)->QueueDraw (); if (is_focused) static_cast<Layout *> (*it)->SetFocused (true); } i++; } QueueDraw (); }
void nux::LayeredLayout::SetInputMode | ( | LayeredLayout::InputMode | input_mode | ) |
Sets the input mode of the layout.
The layout is able to operate in two modes. INPUT_MODE_ACTIVE means that the layout will send events only to the active layout. In INPUT_MODE_COMPOSITE, the layout sends events to all the layouts it contains, starting from the topmost down to the bottom. A layer can stop propagation by returning the appropriate value in ProcessEvent. This can be mixed and matched with SetPaintAll depending on what you want to achieve. For instance, having paint all set to true but input_mode set to INPUT_MODE_ACTIVE allows you to create a composite view with one or many backgrounds, but with only one active view.
input_mode | the input mode |
Definition at line 494 of file LayeredLayout.cpp.
{ if (m_input_mode == input_mode) return; m_input_mode = input_mode; }
void nux::LayeredLayout::SetPaintAll | ( | bool | paint_all | ) |
Set whether the layout will paint all the layers it contains. Default is false.
Normally, the layout will only paint the active layer. However, if you are using the layout in INPUT_COMPOSITE, or have just sized and positioned the layers that you'd like them to be drawn so that they they are composited inside the layout, this should be set to true.
paint_all | whether to paint all the layers in the layout |
Definition at line 480 of file LayeredLayout.cpp.
References nux::Layout::QueueDraw().
{ if (m_paint_all == paint_all) return; m_paint_all = paint_all; QueueDraw (); }
void nux::LayeredLayout::UpdateLayer | ( | Area * | area, |
bool | expand = true , |
||
int | x = 0 , |
||
int | y = 0 , |
||
int | width = 0 , |
||
int | height = 0 |
||
) |
Update properties of a layer in the layout.
Allows updating properties of a layer after it has been added to the layout
area | the Area, Layout or View to update |
expand | area should be expanded to all the available space of the layout. If this is set to false, all the following parameters must be set |
x | the horizontal position of the layer, expand must be false |
y | the vertical position of the layer, expand must be false |
width | the width of the layer inside the layout, expand must be false |
height | the height of the layer inside the layout, expand must be false |
Definition at line 353 of file LayeredLayout.cpp.
References nux::Area::GetLayoutProperties(), and nux::Layout::QueueDraw().
{ LayeredChildProperties *props; NUX_RETURN_IF_NULL(area); props = dynamic_cast<LayeredChildProperties *>(area->GetLayoutProperties ()); NUX_RETURN_IF_NULL(props); props->Update (expand, x, y, width, height); QueueDraw (); }