The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
location_palette.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2017 by David White <dave@whitevine.net>
3  Part of the Battle for Wesnoth Project http://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 
25 
26 namespace editor {
27 
28 class editor_toolkit;
29 
31 
32 public:
33 
34  location_palette(editor_display &gui, const config& /*cfg*/,
35  editor_toolkit &toolkit);
36 
37 
38  virtual sdl_handler_vector handler_members() override;
39 
40  void set_start_item(size_t index) override { items_start_ = index; }
41 
42  size_t start_num(void) override { return items_start_; }
43 
44  /** Menu expanding for palette group list */
45  void expand_palette_groups_menu(std::vector<config>& items, int i) override
46  {
47  items.erase(items.begin() + i);
48  }
49 
50  virtual void set_group(size_t /*index*/) override {}
51  virtual void next_group() override {}
52  virtual void prev_group() override {}
53  virtual const std::vector<item_group>& get_groups() const override { static const std::vector<item_group> empty; return empty; }
54 
55  virtual void draw() override {
56  widget::draw();
57  }
58  virtual void draw_contents() override;
59 
60  /**
61  * Update the size of this widget.
62  *
63  * Use if the size_specs have changed.
64  */
65  void adjust_size(const SDL_Rect& target) override;
66 
67  virtual bool scroll_up() override;
68  virtual bool can_scroll_up() override;
69  virtual bool scroll_down() override;
70  virtual bool can_scroll_down() override;
71 
72  void swap() override {}
73  bool can_swap() { return false; }
74 
75  virtual std::string get_help_string() { return ""; }
76 
77  /** Return the currently selected item. */
78  const std::string& selected_item() const { return selected_item_; }
79 
80  virtual void select_item(const std::string& item_id);
81  virtual std::vector<std::string> action_pressed() const override;
82  void add_item(const std::string& id);
84  void hide(bool hidden) override;
85 
86 private:
87 
88  /** Scroll the editor-palette to the top. */
89  void scroll_top();
90 
91  /** Scroll the editor-palette to the bottom. */
92  void scroll_bottom();
93 
94  virtual bool is_selected_item(const std::string& id);
95 
96  /** Return the number of items in the palette. */
97  int num_items() override;
98  /** Return the maximum number of items shown at the same time. */
99  int num_visible_items();
100 protected:
101 
103  // the heigh of a row, the size of an item including borders.
105 
106 private:
107  unsigned int palette_y_;
108  unsigned int palette_x_;
109 
110 protected:
111  //the current scrolling position
113 
114 private:
116  std::vector<std::string> items_;
118  boost::ptr_vector<location_palette_item> buttons_;
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_;
124 };
125 
126 
127 } //end namespace editor
128 
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.
std::vector< char_t > string
size_t index(const utf8::string &str, const size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
Definition: unicode.cpp:71
virtual bool can_scroll_up() override
void set_start_item(size_t index) override
std::vector< events::sdl_handler * > sdl_handler_vector
Definition: events.hpp:176
virtual bool can_scroll_down() override
boost::ptr_vector< location_palette_item > buttons_
General purpose widgets.
virtual bool is_selected_item(const std::string &id)
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
const std::string & selected_item() const
Return the currently selected item.
bool hidden() const
Definition: widget.cpp:196
virtual const std::vector< item_group > & get_groups() const 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.
void add_item(const std::string &id)
virtual void draw_contents() override
size_t i
Definition: function.cpp:933
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)
virtual void set_group(size_t) override
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:93
int num_items() override
Return the number of items in the palette.
void hide(bool hidden) override
size_t start_num(void) override
std::vector< std::string > items_
virtual sdl_handler_vector handler_members() override