The Battle for Wesnoth  1.17.0-dev
location_palette.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2021
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 
30 
31 public:
32 
34  editor_toolkit &toolkit);
35 
36 
37  virtual sdl_handler_vector handler_members() override;
38 
39  void set_start_item(std::size_t index) override { items_start_ = index; }
40 
41  std::size_t start_num(void) override { return items_start_; }
42 
43  /** Menu expanding for palette group list */
44  void expand_palette_groups_menu(std::vector<config>& items, int i) override
45  {
46  items.erase(items.begin() + i);
47  }
48 
49  virtual void set_group(std::size_t /*index*/) override {}
50  virtual void next_group() override {}
51  virtual void prev_group() override {}
52  virtual const std::vector<item_group>& get_groups() const override { static const std::vector<item_group> empty; return empty; }
53 
54  virtual void draw() override {
55  widget::draw();
56  }
57  virtual void draw_contents() override;
58 
59  /**
60  * Update the size of this widget.
61  *
62  * Use if the size_specs have changed.
63  */
64  void adjust_size(const SDL_Rect& target) override;
65 
66  virtual bool scroll_up() override;
67  virtual bool can_scroll_up() override;
68  virtual bool scroll_down() override;
69  virtual bool can_scroll_down() override;
70 
71  void swap() override {}
72  bool can_swap() { return false; }
73 
74  virtual std::string get_help_string() { return ""; }
75 
76  /** Return the currently selected item. */
77  const std::string& selected_item() const { return selected_item_; }
78 
79  virtual void select_item(const std::string& item_id);
80  virtual std::vector<std::string> action_pressed() const override;
81  void add_item(const std::string& id);
83  void hide(bool hidden) override;
84 
85 private:
86 
87  /** Scroll the editor-palette to the top. */
88  void scroll_top();
89 
90  /** Scroll the editor-palette to the bottom. */
91  void scroll_bottom();
92 
93  virtual bool is_selected_item(const std::string& id);
94 
95  /** Return the number of items in the palette. */
96  int num_items() override;
97  /** Return the maximum number of items shown at the same time. */
98  int num_visible_items();
99 protected:
100 
102  // the height of a row, the size of an item including borders.
104 
105 private:
106  unsigned int palette_y_;
107  unsigned int palette_x_;
108 
109 protected:
110  //the current scrolling position
112 
113 private:
114  std::string selected_item_;
115  std::vector<std::string> items_;
117  std::vector<location_palette_item> buttons_;
118  std::unique_ptr<location_palette_button> button_add_;
119  std::unique_ptr<location_palette_button> button_delete_;
120  std::unique_ptr<location_palette_button> button_goto_;
123 };
124 
125 
126 } //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:190
virtual bool can_scroll_down() override
bool hidden() const
Definition: widget.cpp:188
location_palette(editor_display &gui, const game_config_view &, editor_toolkit &toolkit)
General purpose widgets.
virtual bool is_selected_item(const std::string &id)
std::size_t start_num(void) override
virtual void set_group(std::size_t) override
const std::vector< std::string > items
virtual std::vector< std::string > action_pressed() const override
std::unique_ptr< location_palette_button > button_goto_
virtual void draw() override
virtual const std::vector< item_group > & get_groups() const override
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
int num_visible_items()
Return the maximum number of items shown at the same time.
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:967
void add_item(const std::string &id)
const std::string & selected_item() const
Return the currently selected item.
virtual void draw_contents() override
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.
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)
int num_items() override
Return the number of items in the palette.
void hide(bool hidden) override
std::vector< std::string > items_
virtual sdl_handler_vector handler_members() override