15 #define GETTEXT_DOMAIN "wesnoth-lib"
30 namespace minimum_selection
80 if(visible_index == item_count - 1) {
135 result.
x += best_size.
x;
137 if(best_size.
y > result.
y) {
138 result.
y = best_size.
y;
155 tpoint current_origin = origin;
166 assert(best_size.
y <= size.
y);
168 best_size.
y = size.
y;
170 grid.
place(current_origin, best_size);
172 current_origin.
x += best_size.
x;
175 assert(current_origin.
x == origin.
x + size.
x);
180 tpoint current_origin = origin;
211 const bool must_be_active)
234 const bool must_be_active)
const
334 if(best_size.
x > result.
x) {
335 result.
x = best_size.
x;
338 result.
y += best_size.
y;
354 tpoint current_origin = origin;
365 assert(best_size.
x <= size.
x);
367 best_size.
x = size.
x;
369 grid.
place(current_origin, best_size);
371 current_origin.
y += best_size.
y;
374 assert(current_origin.
y == origin.
y + size.
y);
379 tpoint current_origin = origin;
410 const bool must_be_active)
434 const bool must_be_active)
const
536 if(best_size.
x > result.
x) {
537 result.
x = best_size.
x;
540 if(best_size.
y > result.
y) {
541 result.
y = best_size.
y;
553 grid.
place(origin, size);
573 const bool must_be_active)
578 if(selected_item < 0) {
583 return grid.
find_at(coordinate, must_be_active);
587 const bool must_be_active)
const
592 if(selected_item < 0) {
597 return grid.
find_at(coordinate, must_be_active);
613 const bool must_be_active)
const
645 namespace select_action
658 const std::map<std::string /* widget id */, string_map>&
data,
659 const std::function<
void(
twidget&)>& callback)
662 for(
unsigned col = 0; col < grid->
get_cols(); ++col) {
666 tgrid* child_grid =
dynamic_cast<tgrid*
>(widget);
672 std::map<std::string, string_map>::const_iterator
itor
673 = data.find(btn->
id());
675 if(itor == data.end()) {
676 itor = data.find(
"");
678 if(itor != data.end()) {
684 }
else if(child_grid) {
685 init(child_grid, data, callback);
688 "Only toggle buttons and panels are allowed as "
689 "the cells of a list definition.");
696 const std::map<std::string /* widget id */, string_map>& data,
697 const std::function<
void(
twidget&)>& callback)
701 for(
const auto &
item : data)
703 if(
item.first.empty()) {
705 for(
unsigned col = 0; col < grid->
get_cols(); ++col) {
707 = dynamic_cast<tcontrol*>(grid->
widget(
row, col))) {
709 control->set_members(
item.second);
729 #ifdef GENERATE_PLACEMENT
730 char compile_assert[0];
732 #define GENERATE_PLACEMENT \
733 switch(placement) { \
734 case tgenerator_::horizontal_list: \
735 result = new tgenerator<minimum, \
737 policy::placement::thorizontal_list, \
740 case tgenerator_::vertical_list: \
741 result = new tgenerator<minimum, \
743 policy::placement::tvertical_list, \
746 case tgenerator_::grid: \
747 result = new tgenerator<minimum, \
749 policy::placement::tmatrix, \
752 case tgenerator_::independent: \
753 result = new tgenerator<minimum, \
755 policy::placement::tindependent, \
763 #ifdef GENERATE_SELECT
764 char compile_assert[0];
766 #define GENERATE_SELECT \
768 typedef policy::select_action::tselect select; \
771 typedef policy::select_action::tshow select; \
776 #ifdef GENERATE_MAXIMUM
777 char compile_assert[0];
779 #define GENERATE_MAXIMUM \
781 typedef policy::maximum_selection::tone maximum; \
784 typedef policy::maximum_selection::tinfinite maximum; \
790 char compile_assert[0];
792 #define GENERATE_BODY \
794 typedef policy::minimum_selection::tone minimum; \
797 typedef policy::minimum_selection::tnone minimum; \
803 const bool has_maximum,
845 < policy::minimum_selection::tone
846 , policy::maximum_selection::tone
847 , policy::placement::tvertical_list
848 , policy::select_action::tselect
852 < policy::minimum_selection::tone
853 , policy::maximum_selection::tinfinite
854 , policy::placement::tvertical_list
855 , policy::select_action::tselect
859 < policy::minimum_selection::tnone
860 , policy::maximum_selection::tone
861 , policy::placement::tvertical_list
862 , policy::select_action::tselect
866 < policy::minimum_selection::tnone
867 , policy::maximum_selection::tinfinite
868 , policy::placement::tvertical_list
869 , policy::select_action::tselect
void select(tgrid &grid, const bool select)
Abstract base class for the generator.
virtual void select_item(const unsigned index, const bool select)=0
(De)selects an item.
virtual unsigned get_selected_item_count() const =0
Returns the number of selected items.
virtual void request_reduce_width(const unsigned maximum_width) override
See twidget::request_reduce_width.
virtual unsigned get_item_at_ordered(unsigned index_ordered) const =0
virtual void clear()=0
Deletes all items.
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
virtual int get_selected_item() const =0
Returns the selected item.
void init(tgrid *grid, const std::map< std::string, string_map > &data, const std::function< void(twidget &)> &callback)
Helper function to initialize a grid.
void handle_key_up_arrow(SDLMod modifier, bool &handled)
Inherited from tgenerator_.
virtual tgrid & item(const unsigned index)=0
Gets the grid of an item.
unsigned int get_rows() const
virtual void place(const tpoint &origin, const tpoint &size) override
See twidget::place.
virtual void set_origin(const tpoint &origin) override
See twidget::set_origin.
virtual void place(const tpoint &origin, const tpoint &size) override
See twidget::place.
tplacement
Determines how the items are placed.
virtual void set_origin(const tpoint &origin) override
See twidget::set_origin.
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
void set_visible_rectangle(const SDL_Rect &rectangle)
See thorizontal_list::set_visible_rectangle().
virtual void set_value(const unsigned)=0
Select the control.
void set_visible_rectangle(const SDL_Rect &rectangle)
Sets the visible rectangle of the generator.
void handle_key_left_arrow(SDLMod modifier, bool &handled)
Inherited from tgenerator_.
A class inherited from ttext_box that displays its input as stars.
GLdouble GLdouble GLdouble b
bool placed_
Has the grid already been placed?
virtual void request_reduce_height(const unsigned maximum_height) override
See twidget::request_reduce_height.
void delete_item(const unsigned index)
Called just before an item is deleted.
virtual twidget * find_at(const tpoint &coordinate, const bool must_be_active) override
See twidget::find_at.
#define VALIDATE(cond, message)
The macro to use for the validation of WML.
void create_item(const unsigned index)
See thorizontal_list::create_item().
virtual unsigned get_item_count() const =0
Returns the number of items.
virtual void set_origin(const tpoint &origin) override
See twidget::set_origin.
virtual bool is_selected(const unsigned index) const =0
Returns whether the item is selected.
virtual bool get_item_shown(const unsigned index) const =0
Returns whether the item is shown.
GLboolean GLboolean GLboolean GLboolean a
void handle_key_right_arrow(SDLMod modifier, bool &handled)
Inherited from tgenerator_.
bool deselect_item(const unsigned index)
Called when the users wants to deselect an item.
virtual twidget * find_at(const tpoint &coordinate, const bool must_be_active) override
See twidget::find_at.
virtual void request_reduce_width(const unsigned maximum_width) override
See twidget::request_reduce_width.
virtual void place(const tpoint &origin, const tpoint &size) override
See twidget::place.
void show(CVideo &video, const std::string &window_id, const t_string &message, const tpoint &mouse)
Shows a tip.
Small abstract helper class.
virtual void set_visible_rectangle(const SDL_Rect &rectangle) override
See twidget::set_visible_rectangle.
virtual void place(const tpoint &origin, const tpoint &size) override
See twidget::place.
void create_item(const unsigned index)
Called when an item is created.
void init(tgrid *grid, const std::map< std::string, string_map > &data, const std::function< void(twidget &)> &callback)
Helper function to initialize a grid.
std::map< std::string, tfilter >::iterator itor
virtual twidget * find_at(const tpoint &coordinate, const bool must_be_active) override
See twidget::find_at.
virtual tpoint calculate_best_size() const override
See twidget::calculate_best_size.
virtual unsigned get_ordered_index(unsigned index) const =0
static tgenerator_ * build(const bool has_minimum, const bool has_maximum, const tplacement placement, const bool select)
Create a new generator.
virtual void do_select_item(const unsigned index)=0
Selects a not selected item.
Base class for all visible items.
virtual tpoint calculate_best_size() const override
See twidget::calculate_best_size.
void set_item_shown(const unsigned index, const bool show)
Called when an item is shown or hidden.
void set_child_members(const std::map< std::string, string_map > &data)
Sets the members of the child controls.
virtual tpoint calculate_best_size() const override
See twidget::calculate_best_size.
void handle_key_down_arrow(SDLMod modifier, bool &handled)
Inherited from tgenerator_.
GLenum GLenum GLvoid * row
void create_item(const unsigned index)
Called when an item is created.
virtual void set_members(const string_map &data)
Sets the members of the control.
void set_callback_state_change(std::function< void(twidget &)> callback)
Inherited from tselectable_.
virtual void request_reduce_height(const unsigned maximum_height)
See thorizontal_list::request_reduce_height.
virtual void do_deselect_item(const unsigned index)=0
Deselects a selected item.
twidget * find(const std::string &id, const bool must_be_active) override
See twidget::find.
const twidget * widget(const unsigned row, const unsigned col) const
Returns the widget in the selected cell.
virtual tgrid & item_ordered(const unsigned index)=0
Gets the grid of an item.
bool placed_
Has the grid already been placed?
Class for a toggle button.
virtual bool get_active() const =0
Gets the active state of the control.
void set_visible_rectangle(const SDL_Rect &rectangle)
See thorizontal_list::set_visible_rectangle().
void set_item_shown(const unsigned index, const bool show)
See minimum_selection::tone::set_item_shown().
unsigned int get_cols() const
GLsizei const GLcharARB ** string
virtual twidget * find_at(const tpoint &coordinate, const bool must_be_active) override
See twidget::find_at.
twidget * find(const std::string &id, const bool must_be_active) override
See twidget::find.
virtual void set_origin(const tpoint &origin) override
See twidget::set_origin.