The Battle for Wesnoth  1.17.12+dev
location_palette.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2022
3  by David White <dave@whitevine.net>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
21 
24 class game_config_view;
25 namespace editor {
26 
27 class editor_toolkit;
28 
29 /**
30  * List of starting locations and location ids. Shows a single-column list, with buttons to add
31  * new items to the list and to jump to that location on the map.
32  */
34 
35 public:
36 
38  editor_toolkit &toolkit);
39 
40 
41  virtual sdl_handler_vector handler_members() override;
42 
43  void set_start_item(std::size_t index) override { items_start_ = index; }
44 
45  std::size_t start_num(void) override { return items_start_; }
46 
47  /** Menu expanding for palette group list */
48  void expand_palette_groups_menu(std::vector<config>& items, int i) override
49  {
50  items.erase(items.begin() + i);
51  }
52 
53  virtual void set_group(std::size_t /*index*/) override {}
54  virtual void next_group() override {}
55  virtual void prev_group() override {}
56  virtual const std::vector<item_group>& get_groups() const override { static const std::vector<item_group> empty; return empty; }
57 
58  /** Called by draw_manager to validate layout before drawing. */
59  virtual void layout() override;
60  /** Called by widget::draw() */
61  virtual void draw_contents() override;
62 
63  /**
64  * Update the size of this widget.
65  *
66  * Use if the size_specs have changed.
67  */
68  void adjust_size(const SDL_Rect& target) override;
69 
70  virtual bool scroll_up() override;
71  virtual bool can_scroll_up() override;
72  virtual bool scroll_down() override;
73  virtual bool can_scroll_down() override;
74 
75  void swap() override {}
76  bool can_swap() { return false; }
77 
78  virtual std::string get_help_string() { return ""; }
79 
80  /** Return the currently selected item. */
81  const std::string& selected_item() const { return selected_item_; }
82 
83  virtual void select_item(const std::string& item_id);
84  virtual std::vector<std::string> action_pressed() const override;
85  void add_item(const std::string& id);
87  void hide(bool hidden) override;
88 
89 private:
90  /** Scroll the editor-palette to the top. */
91  void scroll_top();
92 
93  /** Scroll the editor-palette to the bottom. */
94  void scroll_bottom();
95 
96  virtual bool is_selected_item(const std::string& id);
97 
98  /** Return the number of items in the palette. */
99  std::size_t num_items() override;
100  /**
101  * Return the number of GUI elements that can show items. Some of these may be hidden, if there
102  * are more of them than items to show, or if the palette has been scrolled to the bottom.
103  */
104  std::size_t num_visible_items();
105 protected:
106 
108  // the height of a row, the size of an item including borders.
110 
111 protected:
112  // the current scrolling position
113  std::size_t items_start_;
114 
115 private:
116  std::string selected_item_;
117  std::vector<std::string> items_;
119  std::vector<location_palette_item> buttons_;
120  std::unique_ptr<location_palette_button> button_add_;
121  std::unique_ptr<location_palette_button> button_delete_;
122  std::unique_ptr<location_palette_button> button_goto_;
124 };
125 
126 
127 } //end namespace editor
virtual bool scroll_down() override
Scroll the editor-palette down one step if possible.
void scroll_bottom()
Scroll the editor-palette to the bottom.
std::vector< location_palette_item > buttons_
void expand_palette_groups_menu(std::vector< config > &items, int i) override
Menu expanding for palette group list.
virtual bool can_scroll_up() override
std::vector< events::sdl_handler * > sdl_handler_vector
Definition: events.hpp:187
virtual bool can_scroll_down() override
bool hidden() const
Definition: widget.cpp:162
location_palette(editor_display &gui, const game_config_view &, editor_toolkit &toolkit)
General purpose widgets.
virtual bool is_selected_item(const std::string &id)
const std::vector< std::string > items
std::size_t start_num(void) override
virtual void set_group(std::size_t) override
List of starting locations and location ids.
virtual std::vector< std::string > action_pressed() const override
std::unique_ptr< location_palette_button > button_goto_
virtual const std::vector< item_group > & get_groups() const override
std::size_t num_items() override
Return the number of items in the palette.
void set_start_item(std::size_t index) override
virtual std::string get_help_string()
Manage the empty-palette in the editor.
Definition: action.cpp:30
virtual void prev_group() override
virtual bool scroll_up() override
Scroll the editor-palette up one step if possible.
std::size_t i
Definition: function.cpp:968
void add_item(const std::string &id)
const std::string & selected_item() const
Return the currently selected item.
std::size_t num_visible_items()
Return the number of GUI elements that can show items.
virtual void draw_contents() override
Called by widget::draw()
std::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
Definition: unicode.cpp:72
std::unique_ptr< location_palette_button > button_add_
virtual void next_group() override
void adjust_size(const SDL_Rect &target) override
Update the size of this widget.
virtual void layout() override
Called by draw_manager to validate layout before drawing.
std::unique_ptr< location_palette_button > button_delete_
void scroll_top()
Scroll the editor-palette to the top.
virtual void select_item(const std::string &item_id)
void hide(bool hidden) override
std::vector< std::string > items_
virtual sdl_handler_vector handler_members() override