The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Classes | Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
gui::menu Class Reference

#include <menu.hpp>

Inheritance diagram for gui::menu:
Inheritance graph

Classes

class  basic_sorter
 
class  imgsel_style
 
struct  item
 
class  sorter
 
class  style
 

Public Types

enum  ROW_TYPE { NORMAL_ROW, SELECTED_ROW, HEADING_ROW }
 

Public Member Functions

 menu (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)
 
 ~menu ()
 Default implementation, but defined out-of-line for efficiency reasons. More...
 
int selection () const
 
void move_selection (size_t id)
 
void move_selection_keeping_viewport (size_t id)
 
void reset_selection ()
 
const itemget_item (int index) const
 
const itemget_selected_item () const
 
void change_item (int pos1, int pos2, const std::string &str)
 
virtual void erase_item (size_t index)
 
void set_heading (const std::vector< std::string > &heading)
 
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. More...
 
void set_max_height (const int new_max_height)
 Set a new max height for this menu. More...
 
void set_max_width (const int new_max_width)
 
int get_max_height ()
 
int get_max_width ()
 
size_t number_of_items () const
 
int process ()
 
bool double_clicked ()
 
void set_click_selects (bool value)
 
void set_numeric_keypress_selection (bool value)
 
void scroll (unsigned int pos)
 
void set_sorter (sorter *s)
 
void sort_by (int column)
 
int get_sort_by ()
 
bool get_sort_reversed ()
 
- Public Member Functions inherited from gui::scrollarea
 scrollarea (CVideo &video, bool auto_join=true)
 Create a zone with automatic handling of scrollbar. More...
 
virtual void hide (bool value=true)
 
- Public Member Functions inherited from gui::widget
SDL_Rect const & location () const
 
virtual void set_location (SDL_Rect const &rect)
 
void set_location (int x, int y)
 
void set_width (int w)
 
void set_height (int h)
 
void set_measurements (int w, int h)
 
int width () const
 
int height () const
 
bool focus (const SDL_Event *event)
 
void set_focus (bool focus)
 
bool hidden () const
 
virtual void enable (bool new_val=true)
 
bool enabled () const
 
void set_clip_rect (const SDL_Rect &rect)
 
void set_volatile (bool val=true)
 
void set_dirty (bool dirty=true)
 
bool dirty () const
 
const std::stringid () const
 
void set_id (const std::string &id)
 
void set_help_string (const std::string &str)
 
void set_tooltip_string (const std::string &str)
 
virtual void process_tooltip_string (int mousex, int mousey)
 
- Public Member Functions inherited from events::sdl_handler
virtual void join ()
 
virtual void join (context &c)
 
virtual void join_same (sdl_handler *parent)
 
virtual void leave ()
 
virtual void join_global ()
 
virtual void leave_global ()
 

Static Public Attributes

static styledefault_style = menu::bluebg_style
 
static style simple_style
 
static imgsel_style bluebg_style
 

Protected Member Functions

bool item_ends_with_image (const std::string &item) const
 
virtual void handle_event (const SDL_Event &event)
 
void set_inner_location (const SDL_Rect &rect)
 
bool requires_event_focus (const SDL_Event *event=nullptr) const
 
const std::vector< int > & column_widths () const
 
virtual void draw_row (const size_t row_index, const SDL_Rect &rect, ROW_TYPE type)
 
int hit (int x, int y) const
 
std::pair< int, inthit_cell (int x, int y) const
 
int hit_column (int x) const
 
int hit_heading (int x, int y) const
 
void invalidate_row (size_t id)
 
void invalidate_row_pos (size_t pos)
 
void invalidate_heading ()
 
- Protected Member Functions inherited from gui::scrollarea
virtual sdl_handler_vector handler_members ()
 
virtual void update_location (SDL_Rect const &rect)
 
virtual void process_event ()
 
SDL_Rect inner_location () const
 
unsigned scrollbar_width () const
 
unsigned get_position () const
 
unsigned get_max_position () const
 
void set_position (unsigned pos)
 
void adjust_position (unsigned pos)
 
void move_position (int dep)
 
void set_shown_size (unsigned h)
 
void set_full_size (unsigned h)
 
void set_scroll_rate (unsigned r)
 
bool has_scrollbar () const
 
- Protected Member Functions inherited from gui::widget
 widget (widget const &o)
 
 widget (CVideo &video, const bool auto_join=true)
 
virtual ~widget ()
 
void bg_register (SDL_Rect const &rect)
 
void bg_restore () const
 
void bg_restore (SDL_Rect const &rect) const
 
void bg_update ()
 
void bg_cancel ()
 
CVideovideo () const
 
const SDL_Rect * clip_rect () const
 
virtual sdl_handler_vector member_handlers ()
 
virtual void handle_window_event (SDL_Event const &event)
 
bool mouse_locked () const
 
void aquire_mouse_lock ()
 
void free_mouse_lock ()
 
- Protected Member Functions inherited from events::sdl_handler
 sdl_handler (const bool auto_join=true)
 
virtual ~sdl_handler ()
 

Protected Attributes

stylestyle_
 
bool silent_
 
- Protected Attributes inherited from gui::widget
bool focus_
 

Private Types

enum  SELECTION_MOVE_VIEWPORT { MOVE_VIEWPORT, NO_MOVE_VIEWPORT }
 

Private Member Functions

size_t max_items_onscreen () const
 
size_t heading_height () const
 
void adjust_viewport_to_selection ()
 
void key_press (SDLKey key)
 
void create_help_strings ()
 
void process_help_string (int mousex, int mousey)
 
void column_widths_item (const std::vector< std::string > &row, std::vector< int > &widths) const
 
void clear_item (int item)
 
void draw_contents ()
 
void draw ()
 
SDL_Rect get_item_rect (int item) const
 
SDL_Rect get_item_rect_internal (size_t pos) const
 
size_t get_item_height_internal (const std::vector< std::string > &item) const
 
size_t get_item_height (int item) const
 
int items_start () const
 
int items_end () const
 
int items_height () const
 
void update_scrollbar_grip_height ()
 
void fill_items (const std::vector< std::string > &items, bool strip_spaces)
 Set new items to show. More...
 
void do_sort ()
 
void recalculate_pos ()
 
void assert_pos ()
 
void update_size ()
 
void set_selection_pos (size_t pos, bool silent=false, SELECTION_MOVE_VIEWPORT move_viewport=MOVE_VIEWPORT)
 
void move_selection_to (size_t id, bool silent=false, SELECTION_MOVE_VIEWPORT move_viewport=MOVE_VIEWPORT)
 
void move_selection_up (size_t dep)
 
void move_selection_down (size_t dep)
 

Private Attributes

int max_height_
 
int max_width_
 
int max_items_
 
int item_height_
 
std::vector< itemitems_
 
std::vector< size_t > item_pos_
 
std::vector< std::stringheading_
 
int heading_height_
 
std::pair< int, intcur_help_
 
int help_string_
 
std::vector< intcolumn_widths_
 
size_t selected_
 
bool click_selects_
 
bool out_
 
bool previous_button_
 
bool show_result_
 
bool double_clicked_
 
std::map< int, SDL_Rect > itemRects_
 
bool num_selects_
 variable which determines whether a numeric keypress should select an item on the dialog More...
 
bool ignore_next_doubleclick_
 
bool last_was_doubleclick_
 
bool use_ellipsis_
 
const sortersorter_
 
int sortby_
 
bool sortreversed_
 
int highlight_heading_
 
std::set< intinvalid_
 

Friends

class style
 
class imgsel_style
 

Detailed Description

Definition at line 28 of file menu.hpp.

Member Enumeration Documentation

Enumerator
NORMAL_ROW 
SELECTED_ROW 
HEADING_ROW 

Definition at line 32 of file menu.hpp.

Enumerator
MOVE_VIEWPORT 
NO_MOVE_VIEWPORT 

Definition at line 326 of file menu.hpp.

Constructor & Destructor Documentation

gui::menu::menu ( 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 at line 195 of file menu.cpp.

References default_style, fill_items(), gui::menu::style::init(), and style_.

gui::menu::~menu ( )

Default implementation, but defined out-of-line for efficiency reasons.

Definition at line 216 of file menu.cpp.

Member Function Documentation

void gui::menu::adjust_viewport_to_selection ( )
private

Definition at line 519 of file menu.cpp.

References gui::scrollarea::adjust_position(), click_selects_, and selected_.

Referenced by erase_item(), set_items(), and set_selection_pos().

void gui::menu::assert_pos ( )
private

Definition at line 307 of file menu.cpp.

References item_pos_, and items_.

Referenced by erase_item(), and recalculate_pos().

void gui::menu::change_item ( int  pos1,
int  pos2,
const std::string str 
)

Definition at line 395 of file menu.cpp.

References item_pos_, items_, and gui::widget::set_dirty().

void gui::menu::clear_item ( int  item)
private

Definition at line 931 of file menu.cpp.

References gui::widget::bg_restore(), and get_item_rect().

Referenced by erase_item().

const std::vector< int > & gui::menu::column_widths ( ) const
protected

Definition at line 919 of file menu.cpp.

References column_widths_, column_widths_item(), heading_, and items_.

Referenced by draw_row(), hit_column(), and update_size().

void gui::menu::column_widths_item ( const std::vector< std::string > &  row,
std::vector< int > &  widths 
) const
private
void gui::menu::create_help_strings ( )
private

Definition at line 316 of file menu.cpp.

References gui2::event::find(), HELP_STRING_SEPARATOR, i, mp_ui_alerts::items, items_, and utils::split().

Referenced by fill_items().

void gui::menu::do_sort ( )
private
bool gui::menu::double_clicked ( )

Definition at line 749 of file menu.cpp.

References double_clicked_.

Referenced by mp::ui::handle_event(), gui::dialog::process(), and mp::create::process_event().

void gui::menu::draw ( )
privatevirtual
void gui::menu::draw_contents ( )
privatevirtual
void gui::menu::draw_row ( const size_t  row_index,
const SDL_Rect &  rect,
ROW_TYPE  type 
)
protectedvirtual
void gui::menu::erase_item ( size_t  index)
virtual
void gui::menu::fill_items ( const std::vector< std::string > &  items,
bool  strip_spaces 
)
private

Set new items to show.

If strip_spaces is false, spaces will remain at the item edges.

Definition at line 220 of file menu.cpp.

References COLUMN_SEPARATOR, create_help_strings(), DEFAULT_ITEM, do_sort(), heading_, HEADING_PREFIX, gui::widget::id(), item_pos_, items_, itor, utils::quoted_split(), selected_, sortby_, and update_size().

Referenced by menu(), and set_items().

const menu::item & gui::menu::get_item ( int  index) const

Definition at line 385 of file menu.cpp.

References items_.

size_t gui::menu::get_item_height ( int  item) const
private

Definition at line 1279 of file menu.cpp.

References get_item_height_internal(), item_height_, and items_.

Referenced by get_item_rect_internal(), and max_items_onscreen().

size_t gui::menu::get_item_height_internal ( const std::vector< std::string > &  item) const
private

Definition at line 1259 of file menu.cpp.

References i, gui::menu::style::item_size(), and style_.

Referenced by get_item_height(), and heading_height().

SDL_Rect gui::menu::get_item_rect ( int  item) const
private

Definition at line 1210 of file menu.cpp.

References get_item_rect_internal(), and item_pos_.

Referenced by clear_item(), draw(), draw_contents(), hit(), and update_size().

SDL_Rect gui::menu::get_item_rect_internal ( size_t  pos) const
private
int gui::menu::get_max_height ( )
inline

Definition at line 202 of file menu.hpp.

References max_height_.

int gui::menu::get_max_width ( )
inline

Definition at line 203 of file menu.hpp.

References max_width_.

Referenced by gui::file_menu::display_current_files().

const menu::item & gui::menu::get_selected_item ( ) const

Definition at line 390 of file menu.cpp.

References items_, and selection().

int gui::menu::get_sort_by ( )
inline

Definition at line 220 of file menu.hpp.

References sortby_.

bool gui::menu::get_sort_reversed ( )
inline

Definition at line 221 of file menu.hpp.

References sortreversed_.

void gui::menu::handle_event ( const SDL_Event &  event)
protectedvirtual
size_t gui::menu::heading_height ( ) const
private
int gui::menu::hit ( int  x,
int  y 
) const
protected
std::pair< int, int > gui::menu::hit_cell ( int  x,
int  y 
) const
protected

Definition at line 1184 of file menu.cpp.

References hit(), and hit_column().

int gui::menu::hit_column ( int  x) const
protected

Definition at line 1172 of file menu.cpp.

References column_widths(), and gui::widget::location().

Referenced by hit_cell(), hit_heading(), and process_help_string().

int gui::menu::hit_heading ( int  x,
int  y 
) const
protected

Definition at line 1199 of file menu.cpp.

References heading_height(), hit_column(), and gui::scrollarea::inner_location().

Referenced by handle_event().

void gui::menu::invalidate_heading ( )
protected

Definition at line 1340 of file menu.cpp.

References invalid_.

Referenced by handle_event().

void gui::menu::invalidate_row ( size_t  id)
protected

Definition at line 1322 of file menu.cpp.

References invalid_, and items_.

Referenced by invalidate_row_pos().

void gui::menu::invalidate_row_pos ( size_t  pos)
protected
bool gui::menu::item_ends_with_image ( const std::string item) const
protected

Definition at line 912 of file menu.cpp.

References IMAGE_PREFIX, IMG_TEXT_SEPARATOR, and pos.

Referenced by column_widths_item().

int gui::menu::items_end ( ) const
private
int gui::menu::items_height ( ) const
private
int gui::menu::items_start ( ) const
private
void gui::menu::key_press ( SDLKey  key)
private
size_t gui::menu::max_items_onscreen ( ) const
private
void gui::menu::move_selection ( size_t  id)
void gui::menu::move_selection_down ( size_t  dep)
private

Definition at line 552 of file menu.cpp.

References items_, selected_, and set_selection_pos().

Referenced by key_press().

void gui::menu::move_selection_keeping_viewport ( size_t  id)

Definition at line 575 of file menu.cpp.

References item_pos_, NO_MOVE_VIEWPORT, and set_selection_pos().

Referenced by mp::ui::set_user_menu_items().

void gui::menu::move_selection_to ( size_t  id,
bool  silent = false,
SELECTION_MOVE_VIEWPORT  move_viewport = MOVE_VIEWPORT 
)
private

Definition at line 559 of file menu.cpp.

References item_pos_, and set_selection_pos().

Referenced by do_sort(), and handle_event().

void gui::menu::move_selection_up ( size_t  dep)
private

Definition at line 547 of file menu.cpp.

References selected_, and set_selection_pos().

Referenced by key_press().

size_t gui::menu::number_of_items ( ) const
inline

Definition at line 205 of file menu.hpp.

References items_.

Referenced by mp::create::layout_children(), and mp::create::update_mod_menu().

int gui::menu::process ( )

Definition at line 739 of file menu.cpp.

References selected_, and show_result_.

Referenced by gui::dialog::process().

void gui::menu::process_help_string ( int  mousex,
int  mousey 
)
privatevirtual
void gui::menu::recalculate_pos ( )
private

Definition at line 298 of file menu.cpp.

References assert_pos(), i, item_pos_, and items_.

Referenced by do_sort().

bool gui::menu::requires_event_focus ( const SDL_Event *  event = nullptr) const
protectedvirtual
void gui::menu::reset_selection ( )

Definition at line 582 of file menu.cpp.

References set_selection_pos().

void gui::menu::scroll ( unsigned int  pos)
virtual

Implements gui::scrollarea.

Definition at line 766 of file menu.cpp.

References itemRects_, and gui::widget::set_dirty().

int gui::menu::selection ( ) const
void gui::menu::set_click_selects ( bool  value)

Definition at line 756 of file menu.cpp.

References click_selects_.

void gui::menu::set_heading ( const std::vector< std::string > &  heading)

Definition at line 435 of file menu.cpp.

References column_widths_, heading_, itemRects_, max_items_, and gui::widget::set_dirty().

void gui::menu::set_inner_location ( const SDL_Rect &  rect)
protectedvirtual

Implements gui::scrollarea.

Definition at line 378 of file menu.cpp.

References gui::widget::bg_register(), itemRects_, and update_scrollbar_grip_height().

void gui::menu::set_items ( const std::vector< std::string > &  items,
bool  strip_spaces = true,
bool  keep_viewport = false 
)
virtual
void gui::menu::set_max_height ( const int  new_max_height)

Set a new max height for this menu.

Note that this does not take effect immediately, only after certain operations that clear everything, such as set_items().

Definition at line 477 of file menu.cpp.

References itemRects_, max_height_, max_items_, and update_size().

Referenced by help::help_browser::adjust_layout(), dialogs::file_dialog::file_dialog(), mp::wait::layout_children(), mp::create::layout_children(), mp::ui::layout_children(), and gui::dialog::update_widget_positions().

void gui::menu::set_max_width ( const int  new_max_width)
void gui::menu::set_numeric_keypress_selection ( bool  value)
void gui::menu::set_selection_pos ( size_t  pos,
bool  silent = false,
SELECTION_MOVE_VIEWPORT  move_viewport = MOVE_VIEWPORT 
)
private
void gui::menu::set_sorter ( sorter s)

Definition at line 772 of file menu.cpp.

References sort_by(), sortby_, sorter_, and sortreversed_.

void gui::menu::sort_by ( int  column)
void gui::menu::update_scrollbar_grip_height ( )
private
void gui::menu::update_size ( )
private

Friends And Related Function Documentation

friend class imgsel_style
friend

Definition at line 115 of file menu.hpp.

friend class style
friend

Definition at line 114 of file menu.hpp.

Member Data Documentation

menu::imgsel_style gui::menu::bluebg_style
static

Definition at line 118 of file menu.hpp.

Referenced by dialogs::recall_dialog(), and dialogs::recruit_dialog().

bool gui::menu::click_selects_
private
std::vector<int> gui::menu::column_widths_
mutableprivate

Definition at line 269 of file menu.hpp.

Referenced by column_widths(), set_heading(), set_items(), and set_max_width().

std::pair<int,int> gui::menu::cur_help_
private

Definition at line 266 of file menu.hpp.

Referenced by process_help_string().

menu::style & gui::menu::default_style = menu::bluebg_style
static

Definition at line 116 of file menu.hpp.

Referenced by menu(), and gui::dialog::set_menu().

bool gui::menu::double_clicked_
private

Definition at line 279 of file menu.hpp.

Referenced by double_clicked(), and handle_event().

std::vector<std::string> gui::menu::heading_
private

Definition at line 260 of file menu.hpp.

Referenced by column_widths(), draw_row(), fill_items(), heading_height(), and set_heading().

int gui::menu::heading_height_
mutableprivate

Definition at line 261 of file menu.hpp.

Referenced by heading_height().

int gui::menu::help_string_
private

Definition at line 267 of file menu.hpp.

Referenced by process_help_string().

int gui::menu::highlight_heading_
private

Definition at line 315 of file menu.hpp.

Referenced by draw_row(), and handle_event().

bool gui::menu::ignore_next_doubleclick_
private

Definition at line 306 of file menu.hpp.

Referenced by handle_event().

std::set<int> gui::menu::invalid_
private

Definition at line 332 of file menu.hpp.

Referenced by draw(), invalidate_heading(), and invalidate_row().

int gui::menu::item_height_
mutableprivate

Definition at line 252 of file menu.hpp.

Referenced by get_item_height(), and set_items().

std::vector<size_t> gui::menu::item_pos_
private
std::map<int,SDL_Rect> gui::menu::itemRects_
mutableprivate
std::vector<item> gui::menu::items_
private
bool gui::menu::last_was_doubleclick_
private

Definition at line 307 of file menu.hpp.

Referenced by handle_event().

int gui::menu::max_height_
private
int gui::menu::max_items_
mutableprivate

Definition at line 252 of file menu.hpp.

Referenced by max_items_onscreen(), set_heading(), set_items(), and set_max_height().

int gui::menu::max_width_
private

Definition at line 251 of file menu.hpp.

Referenced by draw_row(), get_max_width(), set_max_width(), and update_size().

bool gui::menu::num_selects_
private

variable which determines whether a numeric keypress should select an item on the dialog

Definition at line 302 of file menu.hpp.

Referenced by key_press(), requires_event_focus(), and set_numeric_keypress_selection().

bool gui::menu::out_
private

Definition at line 273 of file menu.hpp.

Referenced by draw(), draw_contents(), and handle_event().

bool gui::menu::previous_button_
private

Definition at line 274 of file menu.hpp.

size_t gui::menu::selected_
private
bool gui::menu::show_result_
private

Definition at line 277 of file menu.hpp.

Referenced by handle_event(), and process().

bool gui::menu::silent_
protected

Definition at line 233 of file menu.hpp.

Referenced by handle_event(), help::help_menu::help_menu(), and set_selection_pos().

menu::style gui::menu::simple_style
static

Definition at line 117 of file menu.hpp.

Referenced by gui::dialog::get_empty_menu().

int gui::menu::sortby_
private

Definition at line 313 of file menu.hpp.

Referenced by do_sort(), draw_row(), fill_items(), get_sort_by(), set_sorter(), and sort_by().

const sorter* gui::menu::sorter_
private

Definition at line 312 of file menu.hpp.

Referenced by do_sort(), handle_event(), and set_sorter().

bool gui::menu::sortreversed_
private

Definition at line 314 of file menu.hpp.

Referenced by do_sort(), draw_row(), get_sort_reversed(), set_sorter(), and sort_by().

style* gui::menu::style_
protected
bool gui::menu::use_ellipsis_
private

Definition at line 310 of file menu.hpp.

Referenced by draw_row(), and update_size().


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