The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
generator.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2016 by Mark de Wever <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #define GETTEXT_DOMAIN "wesnoth-lib"
16 
18 
19 #include "gui/widgets/window.hpp"
20 #include "wml_exception.hpp"
21 
22 namespace gui2
23 {
24 
25 namespace policy
26 {
27 
28 /***** ***** ***** ***** Minimum selection ***** ***** ***** *****/
29 
30 namespace minimum_selection
31 {
32 
33 void tone::set_item_shown(const unsigned index, const bool show)
34 {
35  if(show && get_selected_item_count() == 0) {
36  do_select_item(index);
37  } else if(!show && is_selected(index)) {
38  do_deselect_item(index);
39 
40  for(unsigned i = 1; i < get_item_count(); ++i) {
41  unsigned new_index = (index + i) % get_item_count();
42  if(get_item_shown(new_index)) {
43  do_select_item(new_index);
44  break;
45  }
46  }
47  }
48 }
49 
50 void tone::create_item(const unsigned index)
51 {
52  if(get_selected_item_count() == 0) {
53  do_select_item(index);
54  }
55 }
56 
57 bool tone::deselect_item(const unsigned index)
58 {
59  if(get_selected_item_count() > 1) {
60  do_deselect_item(index);
61  return true;
62  }
63  return false;
64 }
65 
66 void tone::delete_item(const unsigned index)
67 {
68  /** @todo do_select_item needs to test for shown flag. */
69 
70  if(is_selected(index)) {
71  do_deselect_item(index);
72 
73  if(get_selected_item_count() == 0) {
74 
75  // Are there items left?
76  const unsigned item_count = get_item_count();
77  const unsigned visible_index = get_ordered_index(index);
78  if(item_count > 1) {
79  // Is the last item deselected?
80  if(visible_index == item_count - 1) {
81  // Select the second last.
82  do_select_item(get_item_at_ordered(visible_index - 1));
83  } else {
84  // Select the next item.
85  do_select_item(get_item_at_ordered(visible_index + 1));
86  }
87  }
88  }
89  }
90 }
91 
92 void tnone::set_item_shown(const unsigned index, const bool show)
93 {
94  if(!show && is_selected(index)) {
95  do_deselect_item(index);
96  }
97 }
98 
99 } // namespace minimum_selection
100 
101 /***** ***** ***** ***** Placement ***** ***** ***** *****/
102 
103 namespace placement
104 {
105 
107 {
108 }
109 
110 void thorizontal_list::create_item(const unsigned /*index*/)
111 {
112  if(!placed_) {
113  return;
114  }
115 
116  /** @todo implement. */
117  assert(false);
118 }
119 
121 {
122  // The best size is the sum of the widths and the greatest height.
123  tpoint result(0, 0);
124  for(size_t i = 0; i < get_item_count(); ++i) {
125 
126  const tgrid& grid = item(i);
128  || !get_item_shown(i)) {
129 
130  continue;
131  }
132 
133  const tpoint best_size = grid.get_best_size();
134 
135  result.x += best_size.x;
136 
137  if(best_size.y > result.y) {
138  result.y = best_size.y;
139  }
140  }
141 
142  return result;
143 }
144 
145 void thorizontal_list::place(const tpoint& origin, const tpoint& size)
146 {
147  /*
148  * - Set every item to its best size.
149  * - The origin gets increased with the width of the last item.
150  * - No item should be higher as the size.
151  * - In the end the origin should be the sum or the origin and the wanted
152  * width.
153  */
154 
155  tpoint current_origin = origin;
156  for(size_t i = 0; i < get_item_count(); ++i) {
157 
158  tgrid& grid = item_ordered(i);
161 
162  continue;
163  }
164 
165  tpoint best_size = grid.get_best_size();
166  assert(best_size.y <= size.y);
167  // FIXME should we look at grow factors???
168  best_size.y = size.y;
169 
170  grid.place(current_origin, best_size);
171 
172  current_origin.x += best_size.x;
173  }
174 
175  assert(current_origin.x == origin.x + size.x);
176 }
177 
179 {
180  tpoint current_origin = origin;
181  for(size_t i = 0; i < get_item_count(); ++i) {
182 
183  tgrid& grid = item_ordered(i);
186 
187  continue;
188  }
189 
190  grid.set_origin(current_origin);
191  current_origin.x += grid.get_width();
192  }
193 }
194 
195 void thorizontal_list::set_visible_rectangle(const SDL_Rect& rectangle)
196 {
197  /*
198  * Note for most implementations this function could work only for the
199  * tindependent class it probably fails. Evaluate to make a generic
200  * function in the tgenerator template class and call it from the wanted
201  * placement functions.
202  */
203  for(size_t i = 0; i < get_item_count(); ++i) {
204 
205  tgrid& grid = item_ordered(i);
206  grid.set_visible_rectangle(rectangle);
207  }
208 }
209 
211  const bool must_be_active)
212 {
213  assert(get_window());
214 
215  for(size_t i = 0; i < get_item_count(); ++i) {
216 
217  tgrid& grid = item(i);
219  || !get_item_shown(i)) {
220 
221  continue;
222  }
223 
224  twidget* widget = grid.find_at(coordinate, must_be_active);
225 
226  if(widget) {
227  return widget;
228  }
229  }
230  return nullptr;
231 }
232 
233 const twidget* thorizontal_list::find_at(const tpoint& coordinate,
234  const bool must_be_active) const
235 {
236  assert(get_window());
237 
238  for(size_t i = 0; i < get_item_count(); ++i) {
239 
240  const tgrid& grid = item(i);
242  || !get_item_shown(i)) {
243 
244  continue;
245  }
246 
247  const twidget* widget = grid.find_at(coordinate, must_be_active);
248 
249  if(widget) {
250  return widget;
251  }
252  }
253  return nullptr;
254 }
255 
256 void thorizontal_list::handle_key_left_arrow(SDLMod /*modifier*/, bool& handled)
257 {
258  if(get_selected_item_count() == 0) {
259  return;
260  }
261 
262  // NOTE maybe this should only work if we can select only one item...
263  handled = true;
264 
265  for(int i = get_ordered_index(get_selected_item()) - 1; i >= 0; --i) {
266 
267  // NOTE we check the first widget to be active since grids have no
268  // active flag. This method might not be entirely reliable.
269  tcontrol* control = dynamic_cast<tcontrol*>(item(get_item_at_ordered(i)).widget(0, 0));
270  if(control && control->get_active()) {
272  return;
273  }
274  }
275 }
276 
278  bool& handled)
279 {
280  if(get_selected_item_count() == 0) {
281  return;
282  }
283 
284  // NOTE maybe this should only work if we can select only one item...
285  handled = true;
286 
287  for(size_t i = get_ordered_index(get_selected_item()) + 1; i < get_item_count(); ++i) {
288 
291 
292  continue;
293  }
294 
295  // NOTE we check the first widget to be active since grids have no
296  // active flag. This method might not be entirely reliable.
297  tcontrol* control = dynamic_cast<tcontrol*>(item(get_item_at_ordered(i)).widget(0, 0));
298  if(control && control->get_active()) {
300  return;
301  }
302  }
303 }
304 
306 {
307 }
308 
309 void tvertical_list::create_item(const unsigned /*index*/)
310 {
311  if(!placed_) {
312  return;
313  }
314 
315  /** @todo implement. */
316  assert(false);
317 }
318 
320 {
321  // The best size is the sum of the heights and the greatest width.
322  tpoint result(0, 0);
323  for(size_t i = 0; i < get_item_count(); ++i) {
324 
325  const tgrid& grid = item(i);
327  || !get_item_shown(i)) {
328 
329  continue;
330  }
331 
332  const tpoint best_size = grid.get_best_size();
333 
334  if(best_size.x > result.x) {
335  result.x = best_size.x;
336  }
337 
338  result.y += best_size.y;
339  }
340 
341  return result;
342 }
343 
344 void tvertical_list::place(const tpoint& origin, const tpoint& size)
345 {
346  /*
347  * - Set every item to its best size.
348  * - The origin gets increased with the height of the last item.
349  * - No item should be wider as the size.
350  * - In the end the origin should be the sum or the origin and the wanted
351  * height.
352  */
353 
354  tpoint current_origin = origin;
355  for(size_t i = 0; i < get_item_count(); ++i) {
356 
357  tgrid& grid = item_ordered(i);
360 
361  continue;
362  }
363 
364  tpoint best_size = grid.get_best_size();
365  assert(best_size.x <= size.x);
366  // FIXME should we look at grow factors???
367  best_size.x = size.x;
368 
369  grid.place(current_origin, best_size);
370 
371  current_origin.y += best_size.y;
372  }
373 
374  assert(current_origin.y == origin.y + size.y);
375 }
376 
378 {
379  tpoint current_origin = origin;
380  for(size_t i = 0; i < get_item_count(); ++i) {
381 
382  tgrid& grid = item_ordered(i);
385 
386  continue;
387  }
388 
389  grid.set_origin(current_origin);
390  current_origin.y += grid.get_height();
391  }
392 }
393 
394 void tvertical_list::set_visible_rectangle(const SDL_Rect& rectangle)
395 {
396  /*
397  * Note for most implementations this function could work only for the
398  * tindependent class it probably fails. Evaluate to make a generic
399  * function in the tgenerator template class and call it from the wanted
400  * placement functions.
401  */
402  for(size_t i = 0; i < get_item_count(); ++i) {
403 
404  tgrid& grid = item(i);
405  grid.set_visible_rectangle(rectangle);
406  }
407 }
408 
410  const bool must_be_active)
411 {
412  assert(get_window());
413 
414  for(size_t i = 0; i < get_item_count(); ++i) {
415 
416  tgrid& grid = item(i);
418  || !get_item_shown(i)) {
419 
420  continue;
421  }
422 
423 
424  twidget* widget = grid.find_at(coordinate, must_be_active);
425 
426  if(widget) {
427  return widget;
428  }
429  }
430  return nullptr;
431 }
432 
433 const twidget* tvertical_list::find_at(const tpoint& coordinate,
434  const bool must_be_active) const
435 {
436  assert(get_window());
437 
438  for(size_t i = 0; i < get_item_count(); ++i) {
439 
440  const tgrid& grid = item(i);
442  || !get_item_shown(i)) {
443 
444  continue;
445  }
446 
447  const twidget* widget = grid.find_at(coordinate, must_be_active);
448 
449  if(widget) {
450  return widget;
451  }
452  }
453  return nullptr;
454 }
455 
456 void tvertical_list::handle_key_up_arrow(SDLMod /*modifier*/, bool& handled)
457 {
458  if(get_selected_item_count() == 0) {
459  return;
460  }
461 
462  // NOTE maybe this should only work if we can select only one item...
463  handled = true;
464 
465  for(int i = get_ordered_index(get_selected_item()) - 1; i >= 0; --i) {
466 
467  // NOTE we check the first widget to be active since grids have no
468  // active flag. This method might not be entirely reliable.
469  tcontrol* control = dynamic_cast<tcontrol*>(item_ordered(i).widget(0, 0));
470  if(control && control->get_active()) {
472  return;
473  }
474  }
475 }
476 
477 void tvertical_list::handle_key_down_arrow(SDLMod /*modifier*/, bool& handled)
478 {
479  if(get_selected_item_count() == 0) {
480  return;
481  }
482 
483  // NOTE maybe this should only work if we can select only one item...
484  handled = true;
485 
486  for(size_t i = get_ordered_index(get_selected_item()) + 1; i < get_item_count(); ++i) {
487 
488  // why do we do this check here but not in handle_key_up_arrow?
491 
492  continue;
493  }
494 
495  // NOTE we check the first widget to be active since grids have no
496  // active flag. This method might not be entirely reliable.
497  tcontrol* control = dynamic_cast<tcontrol*>(item_ordered(i).widget(0, 0));
498  if(control && control->get_active()) {
500  return;
501  }
502  }
503 }
504 
505 void tindependent::request_reduce_width(const unsigned maximum_width)
506 {
507  for(size_t i = 0; i < get_item_count(); ++i) {
508 
509  tgrid& grid = item(i);
510  grid.request_reduce_width(maximum_width);
511  }
512 }
513 
514 void tindependent::request_reduce_height(const unsigned maximum_height)
515 {
516  for(size_t i = 0; i < get_item_count(); ++i) {
517 
518  tgrid& grid = item(i);
519  grid.request_reduce_height(maximum_height);
520  }
521 }
522 
524 {
525  /*
526  * The best size is the combination of the greatest width and greatest
527  * height.
528  */
529  tpoint result(0, 0);
530  for(size_t i = 0; i < get_item_count(); ++i) {
531 
532  const tgrid& grid = item(i);
533 
534  const tpoint best_size = grid.get_best_size();
535 
536  if(best_size.x > result.x) {
537  result.x = best_size.x;
538  }
539 
540  if(best_size.y > result.y) {
541  result.y = best_size.y;
542  }
543  }
544 
545  return result;
546 }
547 
548 void tindependent::place(const tpoint& origin, const tpoint& size)
549 {
550  for(size_t i = 0; i < get_item_count(); ++i) {
551 
552  tgrid& grid = item(i);
553  grid.place(origin, size);
554  }
555 }
556 
557 void tindependent::set_origin(const tpoint& origin)
558 {
559  /*
560  * Set the origin for every item.
561  *
562  * @todo evaluate whether setting it only for the visible item is better
563  * and what the consequences are.
564  */
565  for(size_t i = 0; i < get_item_count(); ++i) {
566 
567  tgrid& grid = item(i);
568  grid.set_origin(origin);
569  }
570 }
571 
573  const bool must_be_active)
574 {
575  assert(get_window());
576 
577  const int selected_item = get_selected_item();
578  if(selected_item < 0) {
579  return nullptr;
580  }
581 
582  tgrid& grid = item(selected_item);
583  return grid.find_at(coordinate, must_be_active);
584 }
585 
586 const twidget* tindependent::find_at(const tpoint& coordinate,
587  const bool must_be_active) const
588 {
589  assert(get_window());
590 
591  const int selected_item = get_selected_item();
592  if(selected_item < 0) {
593  return nullptr;
594  }
595 
596  const tgrid& grid = item(selected_item);
597  return grid.find_at(coordinate, must_be_active);
598 }
599 
600 twidget* tindependent::find(const std::string& id, const bool must_be_active)
601 {
602  for(size_t i = 0; i < get_item_count(); ++i) {
603  if(is_selected(i)) {
604  if(twidget* widget = item(i).find(id, must_be_active)) {
605  return widget;
606  }
607  }
608  }
609  return nullptr;
610 }
611 
613  const bool must_be_active) const
614 {
615  for(size_t i = 0; i < get_item_count(); ++i) {
616  if(is_selected(i)) {
617  if(const twidget* widget = item(i).find(id, must_be_active)) {
618 
619  return widget;
620  }
621  }
622  }
623  return nullptr;
624 }
625 
626 void tindependent::set_visible_rectangle(const SDL_Rect& rectangle)
627 {
628  /*
629  * Set the visible rectangle for every item.
630  *
631  * @todo evaluate whether setting it only for the visible item is better
632  * and what the consequences are.
633  */
634  for(size_t i = 0; i < get_item_count(); ++i) {
635 
636  tgrid& grid = item(i);
637  grid.set_visible_rectangle(rectangle);
638  }
639 }
640 
641 } // namespace placement
642 
643 /***** ***** ***** ***** Select action ***** ***** ***** *****/
644 
645 namespace select_action
646 {
647 
648 void tselect::select(tgrid& grid, const bool select)
649 {
650  tselectable_* selectable = dynamic_cast<tselectable_*>(grid.widget(0, 0));
651  assert(selectable);
652 
653  selectable->set_value(select);
654 }
655 
656 void
658  const std::map<std::string /* widget id */, string_map>& data,
659  const std::function<void(twidget&)>& callback)
660 {
661  for(unsigned row = 0; row < grid->get_rows(); ++row) {
662  for(unsigned col = 0; col < grid->get_cols(); ++col) {
663  twidget* widget = grid->widget(row, col);
664  assert(widget);
665 
666  tgrid* child_grid = dynamic_cast<tgrid*>(widget);
667  ttoggle_button* btn = dynamic_cast<ttoggle_button*>(widget);
668  ttoggle_panel* panel = dynamic_cast<ttoggle_panel*>(widget);
669 
670  if(btn) {
671  btn->set_callback_state_change(callback);
672  std::map<std::string, string_map>::const_iterator itor
673  = data.find(btn->id());
674 
675  if(itor == data.end()) {
676  itor = data.find("");
677  }
678  if(itor != data.end()) {
679  btn->set_members(itor->second);
680  }
681  } else if(panel) {
682  panel->set_callback_state_change(callback);
683  panel->set_child_members(data);
684  } else if(child_grid) {
685  init(child_grid, data, callback);
686  } else {
687  VALIDATE(false,
688  "Only toggle buttons and panels are allowed as "
689  "the cells of a list definition.");
690  }
691  }
692  }
693 }
694 
695 void tshow::init(tgrid* grid,
696  const std::map<std::string /* widget id */, string_map>& data,
697  const std::function<void(twidget&)>& callback)
698 {
699  assert(!callback);
700 
701  for(const auto & item : data)
702  {
703  if(item.first.empty()) {
704  for(unsigned row = 0; row < grid->get_rows(); ++row) {
705  for(unsigned col = 0; col < grid->get_cols(); ++col) {
706  if(tcontrol* control
707  = dynamic_cast<tcontrol*>(grid->widget(row, col))) {
708 
709  control->set_members(item.second);
710  }
711  }
712  }
713  } else {
714  tcontrol* control
715  = dynamic_cast<tcontrol*>(grid->find(item.first, false));
716  if(control) {
717  control->set_members(item.second);
718  }
719  }
720  }
721 }
722 
723 } // namespace select_action
724 
725 } // namespace policy
726 
727 /***** ***** ***** ***** Helper macros ***** ***** ***** *****/
728 
729 #ifdef GENERATE_PLACEMENT
730 char compile_assert[0];
731 #else
732 #define GENERATE_PLACEMENT \
733  switch(placement) { \
734  case tgenerator_::horizontal_list: \
735  result = new tgenerator<minimum, \
736  maximum, \
737  policy::placement::thorizontal_list, \
738  select>; \
739  break; \
740  case tgenerator_::vertical_list: \
741  result = new tgenerator<minimum, \
742  maximum, \
743  policy::placement::tvertical_list, \
744  select>; \
745  break; \
746  case tgenerator_::grid: \
747  result = new tgenerator<minimum, \
748  maximum, \
749  policy::placement::tmatrix, \
750  select>; \
751  break; \
752  case tgenerator_::independent: \
753  result = new tgenerator<minimum, \
754  maximum, \
755  policy::placement::tindependent, \
756  select>; \
757  break; \
758  default: \
759  assert(false); \
760  }
761 #endif
762 
763 #ifdef GENERATE_SELECT
764 char compile_assert[0];
765 #else
766 #define GENERATE_SELECT \
767  if(select) { \
768  typedef policy::select_action::tselect select; \
769  GENERATE_PLACEMENT \
770  } else { \
771  typedef policy::select_action::tshow select; \
772  GENERATE_PLACEMENT \
773  }
774 #endif
775 
776 #ifdef GENERATE_MAXIMUM
777 char compile_assert[0];
778 #else
779 #define GENERATE_MAXIMUM \
780  if(has_maximum) { \
781  typedef policy::maximum_selection::tone maximum; \
782  GENERATE_SELECT \
783  } else { \
784  typedef policy::maximum_selection::tinfinite maximum; \
785  GENERATE_SELECT \
786  }
787 #endif
788 
789 #ifdef GENERATE_BODY
790 char compile_assert[0];
791 #else
792 #define GENERATE_BODY \
793  if(has_minimum) { \
794  typedef policy::minimum_selection::tone minimum; \
795  GENERATE_MAXIMUM \
796  } else { \
797  typedef policy::minimum_selection::tnone minimum; \
798  GENERATE_MAXIMUM \
799  }
800 #endif
801 
802 tgenerator_* tgenerator_::build(const bool has_minimum,
803  const bool has_maximum,
804  const tplacement placement,
805  const bool select)
806 {
807  tgenerator_* result = nullptr;
809  return result;
810 }
811 
812 /***** ***** ***** ***** Test code ***** ***** ***** *****/
813 #if 0
814 namespace {
815 
816 void pointer_test()
817 {
818 
820  true, true, tgenerator_::horizontal_list, true);
821 
823  true, false, tgenerator_::horizontal_list, true);
824 
826  false, true, tgenerator_::horizontal_list, true);
827 
829  false, false, tgenerator_::horizontal_list, true);
830 
831  a->clear();
832  b->clear();
833  c->clear();
834  d->clear();
835 
836  delete a;
837  delete b;
838  delete c;
839  delete d;
840 }
841 
842 void direct_test()
843 {
844  tgenerator
845  < policy::minimum_selection::tone
846  , policy::maximum_selection::tone
847  , policy::placement::tvertical_list
848  , policy::select_action::tselect
849  > a;
850 
851  tgenerator
852  < policy::minimum_selection::tone
853  , policy::maximum_selection::tinfinite
854  , policy::placement::tvertical_list
855  , policy::select_action::tselect
856  > b;
857 
858  tgenerator
859  < policy::minimum_selection::tnone
860  , policy::maximum_selection::tone
861  , policy::placement::tvertical_list
862  , policy::select_action::tselect
863  > c;
864 
865  tgenerator
866  < policy::minimum_selection::tnone
867  , policy::maximum_selection::tinfinite
868  , policy::placement::tvertical_list
869  , policy::select_action::tselect
870  > d;
871 
872  a.clear();
873  b.clear();
874  c.clear();
875  d.clear();
876 
877 }
878 
879 } // namespace
880 #endif
881 
882 } // namespace gui2
unsigned get_width() const
Definition: widget.cpp:294
void select(tgrid &grid, const bool select)
Definition: generator.cpp:648
Abstract base class for the generator.
Definition: generator.hpp:41
virtual void select_item(const unsigned index, const bool select)=0
(De)selects an item.
#define SDLMod
Definition: compat.hpp:30
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.
Definition: generator.cpp:505
virtual unsigned get_item_at_ordered(unsigned index_ordered) const =0
virtual void clear()=0
Deletes all items.
const GLfloat * c
Definition: glew.h:12741
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
Base container class.
Definition: grid.hpp:29
virtual int get_selected_item() const =0
Returns the selected item.
This file contains the window object, this object is a top level container which has the event manage...
tvisible::scoped_enum get_visible() const
Definition: widget.cpp:471
void init(tgrid *grid, const std::map< std::string, string_map > &data, const std::function< void(twidget &)> &callback)
Helper function to initialize a grid.
Definition: generator.cpp:657
void handle_key_up_arrow(SDLMod modifier, bool &handled)
Inherited from tgenerator_.
Definition: generator.cpp:456
virtual tgrid & item(const unsigned index)=0
Gets the grid of an item.
unsigned int get_rows() const
Definition: grid.hpp:288
virtual void place(const tpoint &origin, const tpoint &size) override
See twidget::place.
Definition: grid.cpp:435
virtual void set_origin(const tpoint &origin) override
See twidget::set_origin.
Definition: generator.cpp:178
virtual void place(const tpoint &origin, const tpoint &size) override
See twidget::place.
Definition: generator.cpp:344
tplacement
Determines how the items are placed.
Definition: generator.hpp:51
#define d
virtual void set_origin(const tpoint &origin) override
See twidget::set_origin.
Definition: grid.cpp:542
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
Definition: glew.h:1347
tpoint get_best_size() const
Gets the best size for the widget.
Definition: widget.cpp:188
void set_visible_rectangle(const SDL_Rect &rectangle)
See thorizontal_list::set_visible_rectangle().
Definition: generator.cpp:394
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.
Definition: generator.cpp:195
void handle_key_left_arrow(SDLMod modifier, bool &handled)
Inherited from tgenerator_.
Definition: generator.cpp:256
Class for a toggle button.
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
#define GENERATE_BODY
Definition: generator.cpp:792
GLdouble GLdouble GLdouble b
Definition: glew.h:6966
The user set the widget invisible, that means:
Definition: widget.hpp:103
bool placed_
Has the grid already been placed?
virtual void request_reduce_height(const unsigned maximum_height) override
See twidget::request_reduce_height.
Definition: grid.cpp:313
void delete_item(const unsigned index)
Called just before an item is deleted.
Definition: generator.cpp:66
GLuint64EXT * result
Definition: glew.h:10727
virtual twidget * find_at(const tpoint &coordinate, const bool must_be_active) override
See twidget::find_at.
Definition: generator.cpp:572
#define VALIDATE(cond, message)
The macro to use for the validation of WML.
void create_item(const unsigned index)
See thorizontal_list::create_item().
Definition: generator.cpp:309
int y
y coordinate.
Definition: point.hpp:34
virtual unsigned get_item_count() const =0
Returns the number of items.
virtual void set_origin(const tpoint &origin) override
See twidget::set_origin.
Definition: generator.cpp:557
virtual bool is_selected(const unsigned index) const =0
Returns whether the item is selected.
void set_callback_state_change(std::function< void(twidget &)> callback)
Inherited from tselectable_.
virtual bool get_item_shown(const unsigned index) const =0
Returns whether the item is shown.
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:7319
void handle_key_right_arrow(SDLMod modifier, bool &handled)
Inherited from tgenerator_.
Definition: generator.cpp:277
bool deselect_item(const unsigned index)
Called when the users wants to deselect an item.
Definition: generator.cpp:57
virtual twidget * find_at(const tpoint &coordinate, const bool must_be_active) override
See twidget::find_at.
Definition: generator.cpp:210
virtual void request_reduce_width(const unsigned maximum_width) override
See twidget::request_reduce_width.
Definition: grid.cpp:237
virtual void place(const tpoint &origin, const tpoint &size) override
See twidget::place.
Definition: generator.cpp:548
void show(CVideo &video, const std::string &window_id, const t_string &message, const tpoint &mouse)
Shows a tip.
Definition: tip.cpp:133
Small abstract helper class.
Definition: selectable.hpp:32
int x
x coordinate.
Definition: point.hpp:31
virtual void set_visible_rectangle(const SDL_Rect &rectangle) override
See twidget::set_visible_rectangle.
Definition: grid.cpp:560
virtual void place(const tpoint &origin, const tpoint &size) override
See twidget::place.
Definition: generator.cpp:145
void create_item(const unsigned index)
Called when an item is created.
Definition: generator.cpp:110
void init(tgrid *grid, const std::map< std::string, string_map > &data, const std::function< void(twidget &)> &callback)
Helper function to initialize a grid.
Definition: generator.cpp:695
std::map< std::string, tfilter >::iterator itor
Definition: filter.cpp:199
void set_members(const string_map &data)
See tcontrol::set_members.
virtual twidget * find_at(const tpoint &coordinate, const bool must_be_active) override
See twidget::find_at.
Definition: generator.cpp:409
GLuint index
Definition: glew.h:1782
virtual tpoint calculate_best_size() const override
See twidget::calculate_best_size.
Definition: generator.cpp:319
unsigned get_height() const
Definition: widget.cpp:299
virtual unsigned get_ordered_index(unsigned index) const =0
const std::string & id() const
Definition: widget.cpp:109
size_t i
Definition: function.cpp:1057
Holds a 2D point.
Definition: point.hpp:24
static tgenerator_ * build(const bool has_minimum, const bool has_maximum, const tplacement placement, const bool select)
Create a new generator.
Definition: generator.cpp:802
virtual void do_select_item(const unsigned index)=0
Selects a not selected item.
Base class for all visible items.
Definition: control.hpp:34
virtual tpoint calculate_best_size() const override
See twidget::calculate_best_size.
Definition: generator.cpp:523
void set_item_shown(const unsigned index, const bool show)
Called when an item is shown or hidden.
Definition: generator.cpp:33
void set_child_members(const std::map< std::string, string_map > &data)
Sets the members of the child controls.
GLsizeiptr size
Definition: glew.h:1649
virtual tpoint calculate_best_size() const override
See twidget::calculate_best_size.
Definition: generator.cpp:120
void handle_key_down_arrow(SDLMod modifier, bool &handled)
Inherited from tgenerator_.
Definition: generator.cpp:477
GLenum GLenum GLvoid * row
Definition: glew.h:3805
void create_item(const unsigned index)
Called when an item is created.
Definition: generator.cpp:50
virtual void set_members(const string_map &data)
Sets the members of the control.
Definition: control.cpp:99
Base class for all widgets.
Definition: widget.hpp:49
void set_callback_state_change(std::function< void(twidget &)> callback)
Inherited from tselectable_.
#define c
Definition: glew.h:12743
virtual void request_reduce_height(const unsigned maximum_height)
See thorizontal_list::request_reduce_height.
Definition: generator.cpp:514
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.
Definition: grid.cpp:612
const twidget * widget(const unsigned row, const unsigned col) const
Returns the widget in the selected cell.
Definition: grid.hpp:176
virtual tgrid & item_ordered(const unsigned index)=0
Gets the grid of an item.
bool placed_
Has the grid already been placed?
twindow * get_window()
Get the parent window.
Definition: widget.cpp:116
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().
Definition: generator.cpp:626
void set_item_shown(const unsigned index, const bool show)
See minimum_selection::tone::set_item_shown().
Definition: generator.cpp:92
unsigned int get_cols() const
Definition: grid.hpp:294
GLsizei const GLcharARB ** string
Definition: glew.h:4503
virtual twidget * find_at(const tpoint &coordinate, const bool must_be_active) override
See twidget::find_at.
Definition: grid.cpp:599
twidget * find(const std::string &id, const bool must_be_active) override
See twidget::find.
Definition: generator.cpp:600
virtual void set_origin(const tpoint &origin) override
See twidget::set_origin.
Definition: generator.cpp:377