The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
multimenu.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2015 - 2016 by Boldizsár Lipka <[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 #ifndef WIDGETS_MULTIMENU_HPP_INCLUDED
16 #define WIDGETS_MULTIMENU_HPP_INCLUDED
17 
18 #include "menu.hpp"
19 
20 namespace gui {
21 
22  /**
23  * A widget that additionally to the normal menu contents also displays a
24  * checkbox in each row. An item is considered 'active' if its checkbox is checked,
25  * 'inactive' otherwise.
26  */
27  class multimenu : public menu {
28  public:
29  multimenu(CVideo& video, const std::vector<std::string>& items,
30  bool click_selects=false, int max_height=-1, int max_width=-1,
31  const sorter* sorter_obj=nullptr, style *menu_style=nullptr, const bool auto_join=true);
32 
33 
34  void set_active(size_t index, bool active=true);
35 
36  /**
37  * Tells if an item is activated.
38  *
39  * @param index the item's index
40  * @return true if the item is active, false if not
41  */
42  bool is_active(size_t index) const { return active_items_[index]; }
43 
44  /**
45  * Tell each items status
46  *
47  * @return a vector of bools. The n-th item is active if the vector's n-th item is true
48  */
49  const std::vector<bool> &active_items() const { return active_items_; }
50 
51  virtual void erase_item(size_t index);
52  virtual void set_items(const std::vector<std::string>& items, bool strip_spaces=true,
53  bool keep_viewport=false);
54 
55  /**
56  * Returns the item last activated/deactivated. Items changed via set_active
57  * don't count, Invoking this function will set the last changed index to -1.
58  *
59  * @return the item's index, or -1 if no item was changed since the last
60  * invokation
61  */
62  int last_changed();
63 
64  protected:
65  virtual void draw_row(const size_t row_index, const SDL_Rect& rect, ROW_TYPE type);
66  virtual void handle_event(const SDL_Event& event);
67 
68  /**
69  * Determine which checkbox was hit by a mouse click.
70  *
71  * @param x the x coordinate of the click
72  * @param y the y coordinate of the click
73  * @return the row whose checkbox was clicked on, or -1 if the click didn't hit a checkbox
74  */
75  int hit_checkbox(int x, int y) const;
76 
77  private:
78  std::vector<bool> active_items_;
80  };
81 }
82 
83 #endif
virtual void draw_row(const size_t row_index, const SDL_Rect &rect, ROW_TYPE type)
Definition: multimenu.cpp:25
A widget that additionally to the normal menu contents also displays a checkbox in each row...
Definition: multimenu.hpp:27
std::vector< bool > active_items_
Definition: multimenu.hpp:78
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1221
Definition: video.hpp:58
ROW_TYPE
Definition: menu.hpp:32
CVideo & video() const
Definition: widget.hpp:83
General purpose widgets.
bool is_active(size_t index) const
Tells if an item is activated.
Definition: multimenu.hpp:42
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1220
const std::vector< std::string > items
virtual void erase_item(size_t index)
Definition: multimenu.cpp:57
virtual void set_items(const std::vector< std::string > &items, bool strip_spaces=true, bool keep_viewport=false)
Set new items to show and redraw/recalculate everything.
Definition: multimenu.cpp:63
GLuint index
Definition: glew.h:1782
GLint GLint GLint GLint GLint x
Definition: glew.h:1220
multimenu(CVideo &video, const std::vector< std::string > &items, bool click_selects=false, int max_height=-1, int max_width=-1, const sorter *sorter_obj=nullptr, style *menu_style=nullptr, const bool auto_join=true)
Definition: multimenu.cpp:20
int hit_checkbox(int x, int y) const
Determine which checkbox was hit by a mouse click.
Definition: multimenu.cpp:52
void set_active(size_t index, bool active=true)
Definition: multimenu.cpp:70
cl_event event
Definition: glew.h:3070
virtual void handle_event(const SDL_Event &event)
Definition: multimenu.cpp:39
int last_changed()
Returns the item last activated/deactivated.
Definition: multimenu.cpp:75
const std::vector< bool > & active_items() const
Tell each items status.
Definition: multimenu.hpp:49