The Battle for Wesnoth  1.19.0-dev
location_palette.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2024
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 
20 
23 class game_config_view;
24 namespace editor {
25 
26 class editor_toolkit;
27 
28 /**
29  * List of starting locations and location ids. Shows a single-column list, with buttons to add
30  * new items to the list and to jump to that location on the map.
31  */
33 
34 public:
35 
37  editor_toolkit &toolkit);
38 
39 
40  virtual sdl_handler_vector handler_members() override;
41 
42  void set_start_item(std::size_t index) override { items_start_ = index; }
43 
44  std::size_t start_num(void) override { return items_start_; }
45 
46  /** Menu expanding for palette group list */
47  void expand_palette_groups_menu(std::vector<config>& items, int i) override
48  {
49  items.erase(items.begin() + i);
50  }
51 
52  virtual void set_group(std::size_t /*index*/) override {}
53  virtual void next_group() override {}
54  virtual void prev_group() override {}
55  virtual const std::vector<item_group>& get_groups() const override { static const std::vector<item_group> empty; return empty; }
56 
57  /** Called by draw_manager to validate layout before drawing. */
58  virtual void layout() override;
59  /** Called by widget::draw() */
60  virtual void draw_contents() override;
61 
62  /**
63  * Update the size of this widget.
64  *
65  * Use if the size_specs have changed.
66  */
67  void adjust_size(const SDL_Rect& target) override;
68 
69  virtual bool scroll_up() override;
70  virtual bool can_scroll_up() override;
71  virtual bool scroll_down() override;
72  virtual bool can_scroll_down() override;
73 
74  void swap() override {}
75  bool can_swap() { return false; }
76 
77  virtual std::string get_help_string() { return ""; }
78 
79  /** Return the currently selected item. */
80  const std::string& selected_item() const { return selected_item_; }
81 
82  virtual void select_item(const std::string& item_id);
83  virtual std::vector<std::string> action_pressed() const override;
84  void add_item(const std::string& id);
86  void hide(bool hidden) override;
87 
88 private:
89  /** Scroll the editor-palette to the top. */
90  void scroll_top();
91 
92  virtual bool is_selected_item(const std::string& id);
93 
94  /** Return the number of items in the palette. */
95  std::size_t num_items() override;
96  /**
97  * Return the number of GUI elements that can show items. Some of these may be hidden, if there
98  * are more of them than items to show, or if the palette has been scrolled to the bottom.
99  */
100  std::size_t num_visible_items();
101 protected:
102 
104  // the height of a row, the size of an item including borders.
106 
107 protected:
108  // the current scrolling position
109  std::size_t items_start_;
110 
111 private:
112  std::string selected_item_;
113  std::vector<std::string> items_;
115  std::vector<location_palette_item> buttons_;
116  std::unique_ptr<location_palette_button> button_add_;
117  std::unique_ptr<location_palette_button> button_delete_;
118  std::unique_ptr<location_palette_button> button_goto_;
120 };
121 
122 
123 } //end namespace editor
List of starting locations and location ids.
virtual bool can_scroll_down() override
std::unique_ptr< location_palette_button > button_goto_
void adjust_size(const SDL_Rect &target) override
Update the size of this widget.
std::vector< std::string > items_
virtual bool scroll_up() override
Scroll the editor-palette up one step if possible.
void scroll_top()
Scroll the editor-palette to the top.
virtual void layout() override
Called by draw_manager to validate layout before drawing.
void hide(bool hidden) override
void set_start_item(std::size_t index) override
std::vector< location_palette_item > buttons_
std::size_t num_items() override
Return the number of items in the palette.
const std::string & selected_item() const
Return the currently selected item.
virtual bool can_scroll_up() override
virtual void next_group() override
location_palette(editor_display &gui, const game_config_view &, editor_toolkit &toolkit)
std::size_t start_num(void) override
virtual void draw_contents() override
Called by widget::draw()
virtual void prev_group() override
void add_item(const std::string &id)
virtual bool is_selected_item(const std::string &id)
virtual const std::vector< item_group > & get_groups() const override
std::unique_ptr< location_palette_button > button_add_
virtual sdl_handler_vector handler_members() override
virtual std::vector< std::string > action_pressed() const override
std::size_t num_visible_items()
Return the number of GUI elements that can show items.
virtual void set_group(std::size_t) override
void expand_palette_groups_menu(std::vector< config > &items, int i) override
Menu expanding for palette group list.
virtual void select_item(const std::string &item_id)
virtual bool scroll_down() override
Scroll the editor-palette down one step if possible.
std::unique_ptr< location_palette_button > button_delete_
virtual std::string get_help_string()
A class grating read only view to a vector of config objects, viewed as one config with all children ...
bool hidden() const
Definition: widget.cpp:161
std::vector< events::sdl_handler * > sdl_handler_vector
Definition: events.hpp:190
std::size_t i
Definition: function.cpp:968
Manage the empty-palette in the editor.
Definition: action.cpp:31
General purpose widgets.
const std::vector< std::string > items
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:70