The Battle for Wesnoth  1.15.0-dev
location_palette.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2018 by David White <dave@whitevine.net>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #pragma once
16 
20 
21 #include <boost/ptr_container/ptr_vector.hpp>
22 
24 
25 namespace editor {
26 
27 class editor_toolkit;
28 
30 
31 public:
32 
33  location_palette(editor_display &gui, const config& /*cfg*/,
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  boost::ptr_vector<location_palette_item> buttons_;
118 #if 0
119  std::unique_ptr<location_palette_button> button_add_;
120  std::unique_ptr<location_palette_button> button_delete_;
121  std::unique_ptr<location_palette_button> button_goto_;
122 #endif
124 };
125 
126 
127 } //end namespace editor
virtual bool scroll_down() override
Scroll the editor-palette down one step if possible.
location_palette(editor_display &gui, const config &, editor_toolkit &toolkit)
void scroll_bottom()
Scroll the editor-palette to the bottom.
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:167
virtual bool can_scroll_down() override
bool hidden() const
Definition: widget.cpp:191
boost::ptr_vector< location_palette_item > buttons_
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
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:29
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:933
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:71
virtual void next_group() override
void adjust_size(const SDL_Rect &target) override
Update the size of this widget.
void scroll_top()
Scroll the editor-palette to the top.
virtual void select_item(const std::string &item_id)
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:68
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