The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Classes | Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action > Class Template Reference

Basic template class to generate new items. More...

#include <generator_private.hpp>

Inheritance diagram for gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >:
Inheritance graph

Classes

struct  calculate_order_helper
 
struct  titem
 Definition of an item. More...
 

Public Member Functions

 tgenerator ()
 
 ~tgenerator ()
 
void delete_item (const unsigned index)
 Inherited from tgenerator_. More...
 
void clear ()
 Inherited from tgenerator_. More...
 
void select_item (const unsigned index, const bool select=true)
 Inherited from tgenerator_. More...
 
bool is_selected (const unsigned index) const
 Inherited from tgenerator_. More...
 
void set_item_shown (const unsigned index, const bool show)
 Inherited from tgenerator_. More...
 
virtual bool get_item_shown (const unsigned index) const
 Inherited from tgenerator_. More...
 
unsigned get_item_count () const
 Inherited from tgenerator_. More...
 
unsigned get_selected_item_count () const
 Inherited from tgenerator_. More...
 
int get_selected_item () const
 Inherited from tgenerator_. More...
 
tgriditem (const unsigned index)
 Inherited from tgenerator_. More...
 
const tgriditem (const unsigned index) const
 Inherited from tgenerator_. More...
 
tgriditem_ordered (const unsigned index)
 Inherited from tgenerator_. More...
 
const tgriditem_ordered (const unsigned index) const
 Inherited from tgenerator_. More...
 
tgridcreate_item (const int index, tbuilder_grid_const_ptr list_builder, const string_map &item_data, const std::function< void(twidget &)> &callback)
 Inherited from tgenerator_. More...
 
tgridcreate_item (const int index, tbuilder_grid_const_ptr list_builder, const std::map< std::string, string_map > &item_data, const std::function< void(twidget &)> &callback)
 Inherited from tgenerator_. More...
 
virtual void create_items (const int index, tbuilder_grid_const_ptr list_builder, const std::vector< std::map< std::string, string_map > > &data, const std::function< void(twidget &)> &callback)
 Inherited from tgenerator_. More...
 
virtual void create_items (const int index, tbuilder_grid_const_ptr list_builder, const std::vector< string_map > &data, const std::function< void(twidget &)> &callback)
 Inherited from tgenerator_. More...
 
virtual void layout_initialise (const bool full_initialisation) override
 See twidget::layout_initialise. More...
 
virtual void request_reduce_width (const unsigned maximum_width) override
 See twidget::request_reduce_width. More...
 
virtual void request_reduce_height (const unsigned maximum_height) override
 See twidget::request_reduce_height. More...
 
virtual tpoint calculate_best_size () const override
 See twidget::calculate_best_size. More...
 
virtual void place (const tpoint &origin, const tpoint &size) override
 See twidget::place. More...
 
virtual void set_origin (const tpoint &origin) override
 See twidget::set_origin. More...
 
virtual void set_visible_rectangle (const SDL_Rect &rectangle) override
 See twidget::set_visible_rectangle. More...
 
virtual void impl_draw_children (surface &frame_buffer, int x_offset, int y_offset) override
 See twidget::impl_draw_children. More...
 
virtual void child_populate_dirty_list (twindow &caller, const std::vector< twidget * > &call_stack) override
 See twidget::child_populate_dirty_list. More...
 
virtual twidgetfind_at (const tpoint &coordinate, const bool must_be_active) override
 See twidget::find_at. More...
 
virtual const twidgetfind_at (const tpoint &coordinate, const bool must_be_active) const override
 See twidget::find_at. More...
 
bool disable_click_dismiss () const override
 See twidget::disable_click_dismiss. More...
 
virtual iterator::twalker_create_walker () override
 See twidget::create_walker. More...
 
void handle_key_up_arrow (SDLMod modifier, bool &handled)
 Inherited from tgenerator_. More...
 
void handle_key_down_arrow (SDLMod modifier, bool &handled)
 Inherited from tgenerator_. More...
 
void handle_key_left_arrow (SDLMod modifier, bool &handled)
 Inherited from tgenerator_. More...
 
void handle_key_right_arrow (SDLMod modifier, bool &handled)
 Inherited from tgenerator_. More...
 

Protected Member Functions

void do_select_item (const unsigned index)
 Inherited from tgenerator_. More...
 
void do_deselect_item (const unsigned index)
 Inherited from tgenerator_. More...
 

Private Types

typedef std::vector< titem * > titems
 The items in the generator. More...
 
typedef std::function< bool(unsigned,
unsigned)> 
torder_func
 

Private Member Functions

virtual void set_order (const torder_func &order) override
 
virtual unsigned get_ordered_index (unsigned index) const
 
virtual unsigned get_item_at_ordered (unsigned index_ordered) const
 
void calculate_order () const
 
void set_item_selected (const unsigned index, const bool selected)
 Sets the selected state of an item. More...
 
template<class T >
void impl_create_items (const int index, tbuilder_grid_const_ptr list_builder, const std::vector< T > &data, const std::function< void(twidget &)> &callback)
 Helper function for create_items(). More...
 
void init (tgrid *grid, const std::map< std::string, string_map > &data, const std::function< void(twidget &)> &callback)
 Helper function to initialize a grid. More...
 

Private Attributes

unsigned selected_item_count_
 The number of selected items. More...
 
int last_selected_item_
 The last item selected. More...
 
titems items_
 
std::vector< size_t > order_
 the elements of order_ are indexes to items_ More...
 
bool order_dirty_
 whether need to recalculate order_dirty_ More...
 
torder_func order_func_
 

Detailed Description

template<class minimum_selection, class maximum_selection, class placement, class select_action>
class gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >

Basic template class to generate new items.

The class is policy based so the behavior can be selected.

Definition at line 590 of file generator_private.hpp.

Member Typedef Documentation

template<class minimum_selection , class maximum_selection , class placement , class select_action >
typedef std::vector<titem*> gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::titems
private

The items in the generator.

Definition at line 1021 of file generator_private.hpp.

template<class minimum_selection , class maximum_selection , class placement , class select_action >
typedef std::function<bool (unsigned, unsigned)> gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::torder_func
private

Definition at line 1029 of file generator_private.hpp.

Constructor & Destructor Documentation

template<class minimum_selection , class maximum_selection , class placement , class select_action >
gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::tgenerator ( )
inline

Definition at line 596 of file generator_private.hpp.

template<class minimum_selection , class maximum_selection , class placement , class select_action >
gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::~tgenerator ( )
inline

Member Function Documentation

template<class minimum_selection , class maximum_selection , class placement , class select_action >
virtual tpoint gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::calculate_best_size ( ) const
inlineoverridevirtual

See twidget::calculate_best_size.

Definition at line 845 of file generator_private.hpp.

template<class minimum_selection , class maximum_selection , class placement , class select_action >
void gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::calculate_order ( ) const
inlineprivate
template<class minimum_selection , class maximum_selection , class placement , class select_action >
virtual void gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::child_populate_dirty_list ( twindow caller,
const std::vector< twidget * > &  call_stack 
)
inlineoverridevirtual
template<class minimum_selection , class maximum_selection , class placement , class select_action >
void gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::clear ( )
inline
template<class minimum_selection , class maximum_selection , class placement , class select_action >
tgrid& gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::create_item ( const int  index,
tbuilder_grid_const_ptr  list_builder,
const string_map item_data,
const std::function< void(twidget &)> &  callback 
)
inline
template<class minimum_selection , class maximum_selection , class placement , class select_action >
tgrid& gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::create_item ( const int  index,
tbuilder_grid_const_ptr  list_builder,
const std::map< std::string, string_map > &  item_data,
const std::function< void(twidget &)> &  callback 
)
inline
template<class minimum_selection , class maximum_selection , class placement , class select_action >
virtual void gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::create_items ( const int  index,
tbuilder_grid_const_ptr  list_builder,
const std::vector< std::map< std::string, string_map > > &  data,
const std::function< void(twidget &)> &  callback 
)
inlinevirtual
template<class minimum_selection , class maximum_selection , class placement , class select_action >
virtual void gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::create_items ( const int  index,
tbuilder_grid_const_ptr  list_builder,
const std::vector< string_map > &  data,
const std::function< void(twidget &)> &  callback 
)
inlinevirtual
template<class minimum_selection , class maximum_selection , class placement , class select_action >
virtual iterator::twalker_* gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::create_walker ( )
inlineoverridevirtual

See twidget::create_walker.

Todo:
Implement properly.

Definition at line 935 of file generator_private.hpp.

template<class minimum_selection , class maximum_selection , class placement , class select_action >
void gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::delete_item ( const unsigned  index)
inline
template<class minimum_selection , class maximum_selection , class placement , class select_action >
bool gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::disable_click_dismiss ( ) const
inlineoverride
template<class minimum_selection , class maximum_selection , class placement , class select_action >
void gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::do_deselect_item ( const unsigned  index)
inlineprotected
template<class minimum_selection , class maximum_selection , class placement , class select_action >
void gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::do_select_item ( const unsigned  index)
inlineprotected
template<class minimum_selection , class maximum_selection , class placement , class select_action >
virtual twidget* gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::find_at ( const tpoint coordinate,
const bool  must_be_active 
)
inlineoverridevirtual

See twidget::find_at.

Definition at line 905 of file generator_private.hpp.

template<class minimum_selection , class maximum_selection , class placement , class select_action >
virtual const twidget* gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::find_at ( const tpoint coordinate,
const bool  must_be_active 
) const
inlineoverridevirtual

See twidget::find_at.

Definition at line 912 of file generator_private.hpp.

template<class minimum_selection , class maximum_selection , class placement , class select_action >
virtual unsigned gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::get_item_at_ordered ( unsigned  index_ordered) const
inlineprivatevirtual
template<class minimum_selection , class maximum_selection , class placement , class select_action >
unsigned gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::get_item_count ( ) const
inline
template<class minimum_selection , class maximum_selection , class placement , class select_action >
virtual bool gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::get_item_shown ( const unsigned  index) const
inlinevirtual
template<class minimum_selection , class maximum_selection , class placement , class select_action >
virtual unsigned gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::get_ordered_index ( unsigned  index) const
inlineprivatevirtual
template<class minimum_selection , class maximum_selection , class placement , class select_action >
int gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::get_selected_item ( ) const
inline
template<class minimum_selection , class maximum_selection , class placement , class select_action >
unsigned gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::get_selected_item_count ( ) const
inline
template<class minimum_selection , class maximum_selection , class placement , class select_action >
void gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::handle_key_down_arrow ( SDLMod  modifier,
bool &  handled 
)
inline

Inherited from tgenerator_.

Definition at line 949 of file generator_private.hpp.

template<class minimum_selection , class maximum_selection , class placement , class select_action >
void gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::handle_key_left_arrow ( SDLMod  modifier,
bool &  handled 
)
inline

Inherited from tgenerator_.

Definition at line 955 of file generator_private.hpp.

template<class minimum_selection , class maximum_selection , class placement , class select_action >
void gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::handle_key_right_arrow ( SDLMod  modifier,
bool &  handled 
)
inline

Inherited from tgenerator_.

Definition at line 961 of file generator_private.hpp.

template<class minimum_selection , class maximum_selection , class placement , class select_action >
void gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::handle_key_up_arrow ( SDLMod  modifier,
bool &  handled 
)
inline

Inherited from tgenerator_.

Definition at line 943 of file generator_private.hpp.

template<class minimum_selection , class maximum_selection , class placement , class select_action >
template<class T >
void gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::impl_create_items ( const int  index,
tbuilder_grid_const_ptr  list_builder,
const std::vector< T > &  data,
const std::function< void(twidget &)> &  callback 
)
inlineprivate

Helper function for create_items().

Template Parameters
TType of the data, this should be one of the valid parameters for create_item().
Parameters
indexThe item before which to add the new item, 0 == begin, -1 == end.
list_builderA grid builder that's will build the contents of the new item.
dataThe data to initialize the parameters of the new item.
callbackThe callback function to call when an item in the grid is (de)selected.

Definition at line 1123 of file generator_private.hpp.

References gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::create_item(), and i.

Referenced by gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::create_items().

template<class minimum_selection , class maximum_selection , class placement , class select_action >
virtual void gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::impl_draw_children ( surface frame_buffer,
int  x_offset,
int  y_offset 
)
inlineoverridevirtual
template<class minimum_selection , class maximum_selection , class placement , class select_action >
void gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::init ( tgrid grid,
const std::map< std::string, string_map > &  data,
const std::function< void(twidget &)> &  callback 
)
inlineprivate

Helper function to initialize a grid.

The actual part is implemented in select_action, see those implementations for more information.

Parameters
gridThe grid to initialize.
dataThe data to initialize the parameters of the new item.
callbackThe callback function to call when an item in the grid is (de)selected.

Definition at line 1150 of file generator_private.hpp.

References ai::registry::init(), and gui2::twidget::set_parent().

Referenced by gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::create_item().

template<class minimum_selection , class maximum_selection , class placement , class select_action >
bool gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::is_selected ( const unsigned  index) const
inline
template<class minimum_selection , class maximum_selection , class placement , class select_action >
tgrid& gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::item ( const unsigned  index)
inline
template<class minimum_selection , class maximum_selection , class placement , class select_action >
const tgrid& gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::item ( const unsigned  index) const
inline
template<class minimum_selection , class maximum_selection , class placement , class select_action >
tgrid& gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::item_ordered ( const unsigned  index)
inline
template<class minimum_selection , class maximum_selection , class placement , class select_action >
const tgrid& gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::item_ordered ( const unsigned  index) const
inline
template<class minimum_selection , class maximum_selection , class placement , class select_action >
virtual void gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::layout_initialise ( const bool  full_initialisation)
inlineoverridevirtual
template<class minimum_selection , class maximum_selection , class placement , class select_action >
virtual void gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::place ( const tpoint origin,
const tpoint size 
)
inlineoverridevirtual

See twidget::place.

Definition at line 851 of file generator_private.hpp.

References gui2::twidget::place().

template<class minimum_selection , class maximum_selection , class placement , class select_action >
virtual void gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::request_reduce_height ( const unsigned  maximum_height)
inlineoverridevirtual

See twidget::request_reduce_height.

Definition at line 839 of file generator_private.hpp.

template<class minimum_selection , class maximum_selection , class placement , class select_action >
virtual void gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::request_reduce_width ( const unsigned  maximum_width)
inlineoverridevirtual

See twidget::request_reduce_width.

Definition at line 833 of file generator_private.hpp.

template<class minimum_selection , class maximum_selection , class placement , class select_action >
void gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::select_item ( const unsigned  index,
const bool  select = true 
)
inline
template<class minimum_selection , class maximum_selection , class placement , class select_action >
void gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::set_item_selected ( const unsigned  index,
const bool  selected 
)
inlineprivate

Sets the selected state of an item.

Parameters
indexThe item to modify.
selectedSelect or deselect.

Definition at line 1099 of file generator_private.hpp.

References preferences::grid().

Referenced by gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::do_deselect_item(), and gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::do_select_item().

template<class minimum_selection , class maximum_selection , class placement , class select_action >
void gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::set_item_shown ( const unsigned  index,
const bool  show 
)
inline
template<class minimum_selection , class maximum_selection , class placement , class select_action >
virtual void gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::set_order ( const torder_func order)
inlineoverrideprivatevirtual

Definition at line 1033 of file generator_private.hpp.

template<class minimum_selection , class maximum_selection , class placement , class select_action >
virtual void gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::set_origin ( const tpoint origin)
inlineoverridevirtual

See twidget::set_origin.

Definition at line 860 of file generator_private.hpp.

References gui2::twidget::set_origin().

template<class minimum_selection , class maximum_selection , class placement , class select_action >
virtual void gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::set_visible_rectangle ( const SDL_Rect &  rectangle)
inlineoverridevirtual

See twidget::set_visible_rectangle.

Definition at line 869 of file generator_private.hpp.

Member Data Documentation

template<class minimum_selection , class maximum_selection , class placement , class select_action >
titems gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::items_
private

Definition at line 1022 of file generator_private.hpp.

Referenced by gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::child_populate_dirty_list(), gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::clear(), gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::create_item(), gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::delete_item(), gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::disable_click_dismiss(), gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::do_deselect_item(), gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::do_select_item(), gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::get_item_count(), gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::get_item_shown(), gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::get_selected_item(), gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::impl_draw_children(), gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::is_selected(), gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::item(), gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::item_ordered(), gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::layout_initialise(), gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::select_item(), and gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::set_item_shown().

template<class minimum_selection , class maximum_selection , class placement , class select_action >
int gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::last_selected_item_
private
template<class minimum_selection , class maximum_selection , class placement , class select_action >
std::vector<size_t> gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::order_
mutableprivate
template<class minimum_selection , class maximum_selection , class placement , class select_action >
bool gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::order_dirty_
mutableprivate
template<class minimum_selection , class maximum_selection , class placement , class select_action >
torder_func gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::order_func_
private

Definition at line 1030 of file generator_private.hpp.

template<class minimum_selection , class maximum_selection , class placement , class select_action >
unsigned gui2::tgenerator< minimum_selection, maximum_selection, placement, select_action >::selected_item_count_
private

The documentation for this class was generated from the following file: