The Battle for Wesnoth  1.19.4+dev
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

Superclass of the help_menu, which displays the left-hand pane of the GUI1 help browser. More...

#include <menu.hpp>

Inheritance diagram for gui::menu:

Classes

class  imgsel_style
 
struct  item
 
class  style
 

Public Types

enum  ROW_TYPE { NORMAL_ROW , SELECTED_ROW }
 

Public Member Functions

 menu (bool click_selects=false, int max_height=-1, int max_width=-1, 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 (std::size_t id)
 
void move_selection_keeping_viewport (std::size_t id)
 
void reset_selection ()
 
virtual void set_items (const std::vector< indented_menu_item > &items, utils::optional< std::size_t > selected)
 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 () const
 
int get_max_width () const
 
std::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) override
 
- Public Member Functions inherited from gui::scrollarea
 scrollarea (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
const rectlocation () const
 
virtual void set_location (const SDL_Rect &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 queue_redraw ()
 Indicate that the widget should be redrawn. More...
 
void queue_redraw (const rect &)
 Indicate that a specific region of the screen should be redrawn. More...
 
void set_dirty (bool dirty=true)
 
bool dirty () const
 
const std::string & id () const
 
void set_id (const std::string &id)
 
void set_tooltip_string (const std::string &str)
 
virtual void process_tooltip_string (int mousex, int mousey) override
 
virtual void layout () override
 Called by draw_manager to validate layout. More...
 
virtual bool expose (const rect &region) override
 Called by draw_manager when it believes a redraw is necessary. More...
 
virtual rect screen_location () override
 The current draw location of the display, on the screen. More...
 
- Public Member Functions inherited from events::sdl_handler
virtual void handle_window_event (const SDL_Event &)
 
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 ()
 
virtual bool has_joined ()
 
virtual bool has_joined_global ()
 
sdl_handleroperator= (sdl_handler &&)=delete
 Moving would require two instances' context membership to be handled, it's simpler to delete these and require the two instances to be separately constructed / destructed. More...
 
 sdl_handler (sdl_handler &&)=delete
 
- Public Member Functions inherited from gui2::top_level_drawable
virtual void update ()
 Update state and any parameters that may effect layout, or any of the later stages. More...
 
virtual void render ()
 Perform any internal rendering necessary to prepare the drawable. More...
 

Static Public Attributes

static styledefault_style = menu::bluebg_style
 
static imgsel_style bluebg_style
 

Protected Member Functions

virtual void handle_event (const SDL_Event &event) override
 
void set_inner_location (const SDL_Rect &rect) override
 
bool requires_event_focus (const SDL_Event *event=nullptr) const override
 
int widest_row_width () const
 
virtual void draw_row (const std::size_t row_index, const SDL_Rect &rect, ROW_TYPE type)
 
int hit (int x, int y) const
 
bool hit_on_indent_or_icon (std::size_t row_index, int x) const
 Returns true if a mouse-click with the given x-coordinate, and an appropriate y-coordinate would lie within the indent or icon part of the given row. More...
 
void invalidate_row (std::size_t id)
 
void invalidate_row_pos (std::size_t pos)
 
- Protected Member Functions inherited from gui::scrollarea
virtual sdl_handler_vector handler_members ()
 
virtual void update_location (const SDL_Rect &rect)
 
virtual void process_event ()
 
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 (const bool auto_join=true)
 
virtual ~widget ()
 
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)
 
 sdl_handler (const sdl_handler &)
 
sdl_handleroperator= (const sdl_handler &)
 
virtual ~sdl_handler ()
 
- Protected Member Functions inherited from gui2::top_level_drawable
 top_level_drawable ()
 
virtual ~top_level_drawable ()
 
 top_level_drawable (const top_level_drawable &)
 
top_level_drawableoperator= (const top_level_drawable &)
 
 top_level_drawable (top_level_drawable &&)
 
top_level_drawableoperator= (top_level_drawable &&)
 

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

std::size_t max_items_onscreen () const
 
void adjust_viewport_to_selection ()
 
void key_press (SDL_Keycode key)
 
void draw_contents () override
 
SDL_Rect get_item_rect (int item) const
 
SDL_Rect get_item_rect_internal (std::size_t pos) const
 
std::size_t get_item_height_internal (const indented_menu_item &imi) const
 
std::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< indented_menu_item > &imi)
 Set new items to show. More...
 
void update_size ()
 
void set_selection_pos (std::size_t pos, bool silent=false, SELECTION_MOVE_VIEWPORT move_viewport=MOVE_VIEWPORT)
 
void move_selection_to (std::size_t id, bool silent=false, SELECTION_MOVE_VIEWPORT move_viewport=MOVE_VIEWPORT)
 
void move_selection_up (std::size_t dep)
 
void move_selection_down (std::size_t dep)
 

Private Attributes

int max_height_
 
int max_width_
 
int max_items_
 
int item_height_
 
std::vector< itemitems_
 
std::vector< std::size_t > item_pos_
 
utils::optional< int > widest_row_width_
 Cached return value of widest_row_width(), calculated on demand when calling that function. More...
 
std::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_
 
std::set< int > invalid_
 

Friends

class style
 
class imgsel_style
 

Detailed Description

Superclass of the help_menu, which displays the left-hand pane of the GUI1 help browser.

Historically a more generic class, but now only used for that singular purpose.

Definition at line 45 of file menu.hpp.

Member Enumeration Documentation

◆ ROW_TYPE

Enumerator
NORMAL_ROW 
SELECTED_ROW 

Definition at line 49 of file menu.hpp.

◆ SELECTION_MOVE_VIEWPORT

Enumerator
MOVE_VIEWPORT 
NO_MOVE_VIEWPORT 

Definition at line 251 of file menu.hpp.

Constructor & Destructor Documentation

◆ menu()

gui::menu::menu ( bool  click_selects = false,
int  max_height = -1,
int  max_width = -1,
style menu_style = nullptr,
const bool  auto_join = true 
)

Definition at line 43 of file menu.cpp.

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

◆ ~menu()

gui::menu::~menu ( )

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

Definition at line 59 of file menu.cpp.

Member Function Documentation

◆ adjust_viewport_to_selection()

void gui::menu::adjust_viewport_to_selection ( )
private

Definition at line 199 of file menu.cpp.

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

Referenced by set_items(), and set_selection_pos().

◆ double_clicked()

bool gui::menu::double_clicked ( )

Definition at line 415 of file menu.cpp.

References double_clicked_.

◆ draw_contents()

void gui::menu::draw_contents ( )
overrideprivatevirtual

Reimplemented from gui::widget.

Definition at line 578 of file menu.cpp.

References gui::menu::style::draw_row(), get_item_rect(), i, item_pos_, NORMAL_ROW, out_, selected_, SELECTED_ROW, and style_.

◆ draw_row()

void gui::menu::draw_row ( const std::size_t  row_index,
const SDL_Rect &  rect,
ROW_TYPE  type 
)
protectedvirtual

◆ fill_items()

void gui::menu::fill_items ( const std::vector< indented_menu_item > &  imi)
private

Set new items to show.

Definition at line 63 of file menu.cpp.

References item_pos_, items_, and update_size().

Referenced by menu(), and set_items().

◆ get_item_height()

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

◆ get_item_height_internal()

std::size_t gui::menu::get_item_height_internal ( const indented_menu_item imi) const
private

Definition at line 649 of file menu.cpp.

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

Referenced by get_item_height().

◆ get_item_rect()

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

Definition at line 600 of file menu.cpp.

References get_item_rect_internal(), and item_pos_.

Referenced by draw_contents(), hit(), invalidate_row(), and update_size().

◆ get_item_rect_internal()

SDL_Rect gui::menu::get_item_rect_internal ( std::size_t  pos) const
private

◆ get_max_height()

int gui::menu::get_max_height ( ) const
inline

Definition at line 147 of file menu.hpp.

References max_height_.

◆ get_max_width()

int gui::menu::get_max_width ( ) const
inline

Definition at line 148 of file menu.hpp.

References max_width_.

◆ handle_event()

void gui::menu::handle_event ( const SDL_Event &  event)
overrideprotectedvirtual

◆ hit()

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

◆ hit_on_indent_or_icon()

bool gui::menu::hit_on_indent_or_icon ( std::size_t  row_index,
int  x 
) const
protected

Returns true if a mouse-click with the given x-coordinate, and an appropriate y-coordinate would lie within the indent or icon part of the given row.

The unusual combination of arguments fit with this being called when handling a mouse event, where we already know which row was selected, and are just inquiring a bit more about the details of that row.

Definition at line 519 of file menu.cpp.

References current_language_rtl(), gui::scrollarea::inner_location(), gui::menu::style::item_size(), items_, style_, w, and gui::scrollarea::x.

◆ invalidate_row()

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

Definition at line 670 of file menu.cpp.

References get_item_rect(), items_, and gui::widget::queue_redraw().

Referenced by invalidate_row_pos().

◆ invalidate_row_pos()

void gui::menu::invalidate_row_pos ( std::size_t  pos)
protected

Definition at line 679 of file menu.cpp.

References invalidate_row(), and items_.

Referenced by handle_event(), and set_selection_pos().

◆ items_end()

int gui::menu::items_end ( ) const
private

◆ items_height()

int gui::menu::items_height ( ) const
private

◆ items_start()

int gui::menu::items_start ( ) const
private

◆ key_press()

void gui::menu::key_press ( SDL_Keycode  key)
private

◆ max_items_onscreen()

std::size_t gui::menu::max_items_onscreen ( ) const
private

◆ move_selection()

void gui::menu::move_selection ( std::size_t  id)

Definition at line 247 of file menu.cpp.

References item_pos_, MOVE_VIEWPORT, and set_selection_pos().

◆ move_selection_down()

void gui::menu::move_selection_down ( std::size_t  dep)
private

Definition at line 232 of file menu.cpp.

References items_, selected_, and set_selection_pos().

Referenced by key_press().

◆ move_selection_keeping_viewport()

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

Definition at line 255 of file menu.cpp.

References item_pos_, NO_MOVE_VIEWPORT, and set_selection_pos().

◆ move_selection_to()

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

Definition at line 239 of file menu.cpp.

References item_pos_, and set_selection_pos().

Referenced by handle_event().

◆ move_selection_up()

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

Definition at line 227 of file menu.cpp.

References selected_, and set_selection_pos().

Referenced by key_press().

◆ number_of_items()

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

Definition at line 150 of file menu.hpp.

References items_.

◆ process()

int gui::menu::process ( )

Definition at line 405 of file menu.cpp.

References selected_, and show_result_.

◆ requires_event_focus()

bool gui::menu::requires_event_focus ( const SDL_Event *  event = nullptr) const
overrideprotectedvirtual

◆ reset_selection()

void gui::menu::reset_selection ( )

Definition at line 262 of file menu.cpp.

References set_selection_pos().

◆ scroll()

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

Implements gui::scrollarea.

Definition at line 432 of file menu.cpp.

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

◆ selection()

int gui::menu::selection ( ) const

Definition at line 106 of file menu.cpp.

References items_, and selected_.

◆ set_click_selects()

void gui::menu::set_click_selects ( bool  value)

Definition at line 422 of file menu.cpp.

References click_selects_.

◆ set_inner_location()

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

Implements gui::scrollarea.

Definition at line 115 of file menu.cpp.

References itemRects_, and update_scrollbar_grip_height().

◆ set_items()

void gui::menu::set_items ( const std::vector< indented_menu_item > &  items,
utils::optional< std::size_t >  selected 
)
virtual

Set new items to show and redraw/recalculate everything.

The menu tries to keep the selection at the same position as it were before the items were set.

Definition at line 121 of file menu.cpp.

References adjust_viewport_to_selection(), fill_items(), gui::scrollarea::get_max_position(), gui::scrollarea::get_position(), gui::scrollarea::has_scrollbar(), item_height_, item_pos_, itemRects_, items_, max_items_, gui::widget::queue_redraw(), game_config::images::selected, selected_, gui::scrollarea::set_position(), update_scrollbar_grip_height(), and widest_row_width_.

◆ set_max_height()

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 150 of file menu.cpp.

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

◆ set_max_width()

void gui::menu::set_max_width ( const int  new_max_width)

Definition at line 158 of file menu.cpp.

References itemRects_, max_width_, update_size(), and widest_row_width_.

◆ set_numeric_keypress_selection()

void gui::menu::set_numeric_keypress_selection ( bool  value)

Definition at line 427 of file menu.cpp.

References num_selects_.

◆ set_selection_pos()

void gui::menu::set_selection_pos ( std::size_t  pos,
bool  silent = false,
SELECTION_MOVE_VIEWPORT  move_viewport = MOVE_VIEWPORT 
)
private

◆ update_scrollbar_grip_height()

void gui::menu::update_scrollbar_grip_height ( )
private

◆ update_size()

void gui::menu::update_size ( )
private

◆ widest_row_width()

int gui::menu::widest_row_width ( ) const
protected

Friends And Related Function Documentation

◆ imgsel_style

friend class imgsel_style
friend

Definition at line 105 of file menu.hpp.

◆ style

friend class style
friend

Definition at line 104 of file menu.hpp.

Member Data Documentation

◆ bluebg_style

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

Definition at line 107 of file menu.hpp.

Referenced by video::deinit().

◆ click_selects_

bool gui::menu::click_selects_
private

◆ default_style

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

Definition at line 106 of file menu.hpp.

Referenced by menu().

◆ double_clicked_

bool gui::menu::double_clicked_
private

Definition at line 214 of file menu.hpp.

Referenced by double_clicked(), and handle_event().

◆ ignore_next_doubleclick_

bool gui::menu::ignore_next_doubleclick_
private

Definition at line 239 of file menu.hpp.

Referenced by handle_event().

◆ invalid_

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

Definition at line 257 of file menu.hpp.

◆ item_height_

int gui::menu::item_height_
private

Definition at line 193 of file menu.hpp.

Referenced by get_item_height(), and set_items().

◆ item_pos_

std::vector<std::size_t> gui::menu::item_pos_
private

◆ itemRects_

std::map<int,SDL_Rect> gui::menu::itemRects_
mutableprivate

◆ items_

std::vector<item> gui::menu::items_
private

◆ last_was_doubleclick_

bool gui::menu::last_was_doubleclick_
private

Definition at line 240 of file menu.hpp.

Referenced by handle_event().

◆ max_height_

int gui::menu::max_height_
private

Definition at line 192 of file menu.hpp.

Referenced by get_max_height(), max_items_onscreen(), set_max_height(), and update_size().

◆ max_items_

int gui::menu::max_items_
mutableprivate

Definition at line 193 of file menu.hpp.

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

◆ max_width_

int gui::menu::max_width_
private

Definition at line 192 of file menu.hpp.

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

◆ num_selects_

bool gui::menu::num_selects_
private

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

Definition at line 235 of file menu.hpp.

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

◆ out_

bool gui::menu::out_
private

Definition at line 208 of file menu.hpp.

Referenced by draw_contents(), and handle_event().

◆ previous_button_

bool gui::menu::previous_button_
private

Definition at line 209 of file menu.hpp.

◆ selected_

std::size_t gui::menu::selected_
private

◆ show_result_

bool gui::menu::show_result_
private

Definition at line 212 of file menu.hpp.

Referenced by handle_event(), and process().

◆ silent_

bool gui::menu::silent_
protected

Definition at line 171 of file menu.hpp.

Referenced by handle_event(), and set_selection_pos().

◆ style_

style* gui::menu::style_
protected

◆ use_ellipsis_

bool gui::menu::use_ellipsis_
private

Definition at line 243 of file menu.hpp.

Referenced by update_size().

◆ widest_row_width_

utils::optional<int> gui::menu::widest_row_width_
mutableprivate

Cached return value of widest_row_width(), calculated on demand when calling that function.

Definition at line 204 of file menu.hpp.

Referenced by set_items(), set_max_width(), and widest_row_width().


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